From 1ea6c4b59d0baed6c2b26c3b29802b9237404644 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Sun, 21 Feb 2021 11:27:04 +0000 Subject: [PATCH] Added more conditions --- .../ecoarmor/conditions/Conditions.java | 16 +++- .../ConditionAboveHealthPercent.java | 80 +++++++++++++++++++ .../conditions/ConditionAboveXPLevel.java | 44 ++++++++++ .../conditions/ConditionAboveY.java | 44 ++++++++++ .../ConditionBelowHealthPercent.java | 80 +++++++++++++++++++ .../conditions/ConditionBelowXPLevel.java | 44 ++++++++++ .../conditions/ConditionInWater.java | 45 +++++++++++ .../conditions/ConditionInWorld.java | 54 +++++++++++++ .../src/main/resources/sets/young.yml | 2 +- 9 files changed, 407 insertions(+), 2 deletions(-) create mode 100644 eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionAboveHealthPercent.java create mode 100644 eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionAboveXPLevel.java create mode 100644 eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionAboveY.java create mode 100644 eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionBelowHealthPercent.java create mode 100644 eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionBelowXPLevel.java create mode 100644 eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionInWater.java create mode 100644 eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionInWorld.java diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/Conditions.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/Conditions.java index 0d22f0d..6080636 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/Conditions.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/Conditions.java @@ -3,7 +3,14 @@ package com.willfp.ecoarmor.conditions; import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap; import com.google.common.collect.ImmutableList; +import com.willfp.ecoarmor.conditions.conditions.ConditionAboveHealthPercent; +import com.willfp.ecoarmor.conditions.conditions.ConditionAboveXPLevel; +import com.willfp.ecoarmor.conditions.conditions.ConditionAboveY; +import com.willfp.ecoarmor.conditions.conditions.ConditionBelowHealthPercent; +import com.willfp.ecoarmor.conditions.conditions.ConditionBelowXPLevel; import com.willfp.ecoarmor.conditions.conditions.ConditionBelowY; +import com.willfp.ecoarmor.conditions.conditions.ConditionInWater; +import com.willfp.ecoarmor.conditions.conditions.ConditionInWorld; import lombok.experimental.UtilityClass; import org.jetbrains.annotations.NotNull; @@ -18,9 +25,16 @@ public class Conditions { private static final BiMap> BY_NAME = HashBiMap.create(); public static final Condition BELOW_Y = new ConditionBelowY(); + public static final Condition ABOVE_Y = new ConditionAboveY(); + public static final Condition ABOVE_HEALTH_PERCENT = new ConditionAboveHealthPercent(); + public static final Condition BELOW_HEALTH_PERCENT = new ConditionBelowHealthPercent(); + public static final Condition IN_WATER = new ConditionInWater(); + public static final Condition IN_WORLD = new ConditionInWorld(); + public static final Condition ABOVE_XP_LEVEL = new ConditionAboveXPLevel(); + public static final Condition BELOW_XP_LEVEL = new ConditionBelowXPLevel(); /** - * Get condition matching name. + * Get condition matching name.s * * @param name The name to query. * @return The matching condition, or null if not found. diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionAboveHealthPercent.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionAboveHealthPercent.java new file mode 100644 index 0000000..69e3927 --- /dev/null +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionAboveHealthPercent.java @@ -0,0 +1,80 @@ +package com.willfp.ecoarmor.conditions.conditions; + +import com.willfp.ecoarmor.conditions.Condition; +import com.willfp.ecoarmor.sets.ArmorSet; +import com.willfp.ecoarmor.sets.util.ArmorUtils; +import org.bukkit.attribute.Attribute; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.entity.EntityRegainHealthEvent; +import org.jetbrains.annotations.NotNull; + +public class ConditionAboveHealthPercent extends Condition { + public ConditionAboveHealthPercent() { + super("above-health-percent", Double.class); + } + + @EventHandler + public void listener(@NotNull final EntityRegainHealthEvent event) { + if (!(event.getEntity() instanceof Player)) { + return; + } + + Player player = (Player) event.getEntity(); + + ArmorSet set = ArmorUtils.getSetOnPlayer(player); + + if (set == null) { + return; + } + + Double value = set.getConditionValue(this); + + if (value == null) { + return; + } + + if (isMet(player, value)) { + set.getEffects().keySet().forEach(effect -> effect.enable(player, value)); + } else { + set.getEffects().keySet().forEach(effect -> effect.disable(player)); + } + } + + @EventHandler + public void listener(@NotNull final EntityDamageEvent event) { + if (!(event.getEntity() instanceof Player)) { + return; + } + + Player player = (Player) event.getEntity(); + + ArmorSet set = ArmorUtils.getSetOnPlayer(player); + + if (set == null) { + return; + } + + Double value = set.getConditionValue(this); + + if (value == null) { + return; + } + + if (isMet(player, value)) { + set.getEffects().keySet().forEach(effect -> effect.enable(player, value)); + } else { + set.getEffects().keySet().forEach(effect -> effect.disable(player)); + } + } + + @Override + public boolean isConditionMet(@NotNull final Player player, + @NotNull final Double value) { + double maxHealth = player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue(); + double health = player.getHealth(); + + return (health / maxHealth) * 100 >= value; + } +} diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionAboveXPLevel.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionAboveXPLevel.java new file mode 100644 index 0000000..204b512 --- /dev/null +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionAboveXPLevel.java @@ -0,0 +1,44 @@ +package com.willfp.ecoarmor.conditions.conditions; + +import com.willfp.ecoarmor.conditions.Condition; +import com.willfp.ecoarmor.sets.ArmorSet; +import com.willfp.ecoarmor.sets.util.ArmorUtils; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerExpChangeEvent; +import org.jetbrains.annotations.NotNull; + +public class ConditionAboveXPLevel extends Condition { + public ConditionAboveXPLevel() { + super("above-xp-level", Integer.class); + } + + @EventHandler + public void listener(@NotNull final PlayerExpChangeEvent event) { + Player player = event.getPlayer(); + + ArmorSet set = ArmorUtils.getSetOnPlayer(player); + + if (set == null) { + return; + } + + Integer value = set.getConditionValue(this); + + if (value == null) { + return; + } + + if (isMet(player, value)) { + set.getEffects().keySet().forEach(effect -> effect.enable(player, value)); + } else { + set.getEffects().keySet().forEach(effect -> effect.disable(player)); + } + } + + @Override + public boolean isConditionMet(@NotNull final Player player, + @NotNull final Integer value) { + return player.getLevel() >= value; + } +} diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionAboveY.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionAboveY.java new file mode 100644 index 0000000..2ca31f1 --- /dev/null +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionAboveY.java @@ -0,0 +1,44 @@ +package com.willfp.ecoarmor.conditions.conditions; + +import com.willfp.ecoarmor.conditions.Condition; +import com.willfp.ecoarmor.sets.ArmorSet; +import com.willfp.ecoarmor.sets.util.ArmorUtils; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerMoveEvent; +import org.jetbrains.annotations.NotNull; + +public class ConditionAboveY extends Condition { + public ConditionAboveY() { + super("above-y", Double.class); + } + + @EventHandler + public void listener(@NotNull final PlayerMoveEvent event) { + Player player = event.getPlayer(); + + ArmorSet set = ArmorUtils.getSetOnPlayer(player); + + if (set == null) { + return; + } + + Double value = set.getConditionValue(this); + + if (value == null) { + return; + } + + if (isMet(player, value)) { + set.getEffects().keySet().forEach(effect -> effect.enable(player, value)); + } else { + set.getEffects().keySet().forEach(effect -> effect.disable(player)); + } + } + + @Override + public boolean isConditionMet(@NotNull final Player player, + @NotNull final Double value) { + return player.getLocation().getY() >= value; + } +} diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionBelowHealthPercent.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionBelowHealthPercent.java new file mode 100644 index 0000000..1b52519 --- /dev/null +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionBelowHealthPercent.java @@ -0,0 +1,80 @@ +package com.willfp.ecoarmor.conditions.conditions; + +import com.willfp.ecoarmor.conditions.Condition; +import com.willfp.ecoarmor.sets.ArmorSet; +import com.willfp.ecoarmor.sets.util.ArmorUtils; +import org.bukkit.attribute.Attribute; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.event.entity.EntityRegainHealthEvent; +import org.jetbrains.annotations.NotNull; + +public class ConditionBelowHealthPercent extends Condition { + public ConditionBelowHealthPercent() { + super("below-health-percent", Double.class); + } + + @EventHandler + public void listener(@NotNull final EntityRegainHealthEvent event) { + if (!(event.getEntity() instanceof Player)) { + return; + } + + Player player = (Player) event.getEntity(); + + ArmorSet set = ArmorUtils.getSetOnPlayer(player); + + if (set == null) { + return; + } + + Double value = set.getConditionValue(this); + + if (value == null) { + return; + } + + if (isMet(player, value)) { + set.getEffects().keySet().forEach(effect -> effect.enable(player, value)); + } else { + set.getEffects().keySet().forEach(effect -> effect.disable(player)); + } + } + + @EventHandler + public void listener(@NotNull final EntityDamageEvent event) { + if (!(event.getEntity() instanceof Player)) { + return; + } + + Player player = (Player) event.getEntity(); + + ArmorSet set = ArmorUtils.getSetOnPlayer(player); + + if (set == null) { + return; + } + + Double value = set.getConditionValue(this); + + if (value == null) { + return; + } + + if (isMet(player, value)) { + set.getEffects().keySet().forEach(effect -> effect.enable(player, value)); + } else { + set.getEffects().keySet().forEach(effect -> effect.disable(player)); + } + } + + @Override + public boolean isConditionMet(@NotNull final Player player, + @NotNull final Double value) { + double maxHealth = player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue(); + double health = player.getHealth(); + + return (health / maxHealth) * 100 < value; + } +} diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionBelowXPLevel.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionBelowXPLevel.java new file mode 100644 index 0000000..0d69799 --- /dev/null +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionBelowXPLevel.java @@ -0,0 +1,44 @@ +package com.willfp.ecoarmor.conditions.conditions; + +import com.willfp.ecoarmor.conditions.Condition; +import com.willfp.ecoarmor.sets.ArmorSet; +import com.willfp.ecoarmor.sets.util.ArmorUtils; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerExpChangeEvent; +import org.jetbrains.annotations.NotNull; + +public class ConditionBelowXPLevel extends Condition { + public ConditionBelowXPLevel() { + super("below-xp-level", Integer.class); + } + + @EventHandler + public void listener(@NotNull final PlayerExpChangeEvent event) { + Player player = event.getPlayer(); + + ArmorSet set = ArmorUtils.getSetOnPlayer(player); + + if (set == null) { + return; + } + + Integer value = set.getConditionValue(this); + + if (value == null) { + return; + } + + if (isMet(player, value)) { + set.getEffects().keySet().forEach(effect -> effect.enable(player, value)); + } else { + set.getEffects().keySet().forEach(effect -> effect.disable(player)); + } + } + + @Override + public boolean isConditionMet(@NotNull final Player player, + @NotNull final Integer value) { + return player.getLevel() < value; + } +} diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionInWater.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionInWater.java new file mode 100644 index 0000000..f87bf38 --- /dev/null +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionInWater.java @@ -0,0 +1,45 @@ +package com.willfp.ecoarmor.conditions.conditions; + +import com.willfp.ecoarmor.conditions.Condition; +import com.willfp.ecoarmor.sets.ArmorSet; +import com.willfp.ecoarmor.sets.util.ArmorUtils; +import org.bukkit.Material; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerMoveEvent; +import org.jetbrains.annotations.NotNull; + +public class ConditionInWater extends Condition { + public ConditionInWater() { + super("in-water", Boolean.class); + } + + @EventHandler + public void listener(@NotNull final PlayerMoveEvent event) { + Player player = event.getPlayer(); + + ArmorSet set = ArmorUtils.getSetOnPlayer(player); + + if (set == null) { + return; + } + + Boolean value = set.getConditionValue(this); + + if (value == null) { + return; + } + + if (isMet(player, value)) { + set.getEffects().keySet().forEach(effect -> effect.enable(player, value)); + } else { + set.getEffects().keySet().forEach(effect -> effect.disable(player)); + } + } + + @Override + public boolean isConditionMet(@NotNull final Player player, + @NotNull final Boolean value) { + return (player.getLocation().getBlock().getType() == Material.WATER) == value; + } +} diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionInWorld.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionInWorld.java new file mode 100644 index 0000000..42b920f --- /dev/null +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionInWorld.java @@ -0,0 +1,54 @@ +package com.willfp.ecoarmor.conditions.conditions; + +import com.willfp.ecoarmor.conditions.Condition; +import com.willfp.ecoarmor.sets.ArmorSet; +import com.willfp.ecoarmor.sets.util.ArmorUtils; +import org.bukkit.World; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerMoveEvent; +import org.jetbrains.annotations.NotNull; + +import java.util.Arrays; +import java.util.List; + +public class ConditionInWorld extends Condition { + public ConditionInWorld() { + super("in-world", String.class); + } + + @EventHandler + public void listener(@NotNull final PlayerMoveEvent event) { + Player player = event.getPlayer(); + + ArmorSet set = ArmorUtils.getSetOnPlayer(player); + + if (set == null) { + return; + } + + String value = set.getConditionValue(this); + + if (value == null) { + return; + } + + if (isMet(player, value)) { + set.getEffects().keySet().forEach(effect -> effect.enable(player, value)); + } else { + set.getEffects().keySet().forEach(effect -> effect.disable(player)); + } + } + + @Override + public boolean isConditionMet(@NotNull final Player player, + @NotNull final String value) { + List worldNames = Arrays.asList(value.toLowerCase().split(" ")); + World world = player.getLocation().getWorld(); + if (world == null) { + return false; + } + + return worldNames.contains(world.getName().toLowerCase()); + } +} diff --git a/eco-core/core-plugin/src/main/resources/sets/young.yml b/eco-core/core-plugin/src/main/resources/sets/young.yml index fe99704..712be0f 100644 --- a/eco-core/core-plugin/src/main/resources/sets/young.yml +++ b/eco-core/core-plugin/src/main/resources/sets/young.yml @@ -1,6 +1,6 @@ enabled: true conditions: - - "below-y: 40" + - "above-health-percent: 50" set-bonus: - "speed-multiplier: 1.25" advanced-set-bonus: