From 595db1134b98ba9ce81a6f9d0c855fa1f5895c63 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Thu, 18 Nov 2021 13:48:59 +0000 Subject: [PATCH] Began libreforge change --- build.gradle | 11 +- .../com/willfp/ecoarmor/EcoArmorPlugin.java | 22 ++- .../ecoarmor/commands/CommandEditor.java | 12 +- .../willfp/ecoarmor/conditions/Condition.java | 102 ------------ .../ecoarmor/conditions/Conditions.java | 74 --------- .../ConditionAboveHealthPercent.java | 79 --------- .../ConditionAboveHungerPercent.java | 47 ------ .../conditions/ConditionAboveXPLevel.java | 44 ----- .../conditions/ConditionAboveY.java | 22 --- .../ConditionBelowHealthPercent.java | 79 --------- .../ConditionBelowHungerPercent.java | 47 ------ .../conditions/ConditionBelowXPLevel.java | 44 ----- .../conditions/ConditionBelowY.java | 22 --- .../conditions/ConditionHasPermission.java | 39 ----- .../conditions/ConditionInBiome.java | 28 ---- .../conditions/ConditionInWater.java | 23 --- .../conditions/ConditionInWorld.java | 32 ---- .../conditions/ConditionIsSneaking.java | 46 ------ .../util/MovementConditionListener.java | 62 ------- .../com/willfp/ecoarmor/effects/Effect.java | 154 ------------------ .../com/willfp/ecoarmor/effects/Effects.java | 86 ---------- .../effects/AttackSpeedMultiplier.java | 39 ----- .../ecoarmor/effects/effects/BonusHearts.java | 47 ------ .../effects/effects/BossDamageMultiplier.java | 54 ------ .../effects/effects/BowDamageMultiplier.java | 37 ----- .../effects/effects/DamageMultiplier.java | 42 ----- .../effects/DamageTakenMultiplier.java | 28 ---- .../effects/effects/DurabilityMultiplier.java | 29 ---- .../ecoarmor/effects/effects/EvadeChance.java | 33 ---- .../effects/effects/ExperienceMultiplier.java | 24 --- .../effects/effects/FallDamageMultiplier.java | 32 ---- .../ecoarmor/effects/effects/Flight.java | 28 ---- .../effects/effects/HungerLossMultiplier.java | 43 ----- .../effects/effects/KnockbackMultiplier.java | 39 ----- .../effects/MeleeDamageMultiplier.java | 28 ---- .../effects/RegenerationMultiplier.java | 28 ---- .../effects/effects/SpeedMultiplier.java | 39 ----- .../ecoarmor/effects/effects/Telekinesis.java | 22 --- .../effects/TridentDamageMultiplier.java | 37 ----- .../ecoarmor/effects/effects/WarpChance.java | 60 ------- .../ecoarmor/effects/util/EffectWatcher.java | 89 ---------- .../com/willfp/ecoarmor/sets/ArmorSet.java | 86 +++------- .../willfp/ecoarmor/sets/util/ArmorUtils.java | 24 --- 43 files changed, 46 insertions(+), 1917 deletions(-) delete mode 100644 eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/Condition.java delete mode 100644 eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/Conditions.java delete mode 100644 eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionAboveHealthPercent.java delete mode 100644 eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionAboveHungerPercent.java delete mode 100644 eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionAboveXPLevel.java delete mode 100644 eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionAboveY.java delete mode 100644 eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionBelowHealthPercent.java delete mode 100644 eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionBelowHungerPercent.java delete mode 100644 eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionBelowXPLevel.java delete mode 100644 eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionBelowY.java delete mode 100644 eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionHasPermission.java delete mode 100644 eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionInBiome.java delete mode 100644 eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionInWater.java delete mode 100644 eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionInWorld.java delete mode 100644 eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionIsSneaking.java delete mode 100644 eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/util/MovementConditionListener.java delete mode 100644 eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/Effect.java delete mode 100644 eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/Effects.java delete mode 100644 eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/AttackSpeedMultiplier.java delete mode 100644 eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/BonusHearts.java delete mode 100644 eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/BossDamageMultiplier.java delete mode 100644 eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/BowDamageMultiplier.java delete mode 100644 eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/DamageMultiplier.java delete mode 100644 eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/DamageTakenMultiplier.java delete mode 100644 eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/DurabilityMultiplier.java delete mode 100644 eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/EvadeChance.java delete mode 100644 eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/ExperienceMultiplier.java delete mode 100644 eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/FallDamageMultiplier.java delete mode 100644 eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/Flight.java delete mode 100644 eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/HungerLossMultiplier.java delete mode 100644 eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/KnockbackMultiplier.java delete mode 100644 eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/MeleeDamageMultiplier.java delete mode 100644 eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/RegenerationMultiplier.java delete mode 100644 eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/SpeedMultiplier.java delete mode 100644 eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/Telekinesis.java delete mode 100644 eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/TridentDamageMultiplier.java delete mode 100644 eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/WarpChance.java delete mode 100644 eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/util/EffectWatcher.java diff --git a/build.gradle b/build.gradle index cdf0de8..14acb13 100644 --- a/build.gradle +++ b/build.gradle @@ -45,10 +45,15 @@ allprojects { onlyIf { !sourceSets.main.allSource.files.isEmpty() } } - dependencies { - compileOnly 'com.willfp:eco:6.8.1' + shadowJar { + relocate('com.willfp.libreforge', 'com.willfp.ecoarmor.libreforge') + } - compileOnly 'org.jetbrains:annotations:19.0.0' + dependencies { + compileOnly 'com.willfp:eco:6.13.10' + compileOnly 'com.willfp:libreforge:0.1.2' + + compileOnly 'org.jetbrains:annotations:23.0.0' compileOnly 'org.projectlombok:lombok:1.18.20' annotationProcessor 'org.projectlombok:lombok:1.18.20' diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/EcoArmorPlugin.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/EcoArmorPlugin.java index 5cf09e9..1c1009b 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/EcoArmorPlugin.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/EcoArmorPlugin.java @@ -3,14 +3,10 @@ package com.willfp.ecoarmor; import com.willfp.eco.core.EcoPlugin; import com.willfp.eco.core.command.impl.PluginCommand; import com.willfp.eco.core.display.DisplayModule; +import com.willfp.eco.core.integrations.IntegrationLoader; import com.willfp.ecoarmor.commands.CommandEcoarmor; -import com.willfp.ecoarmor.conditions.Conditions; -import com.willfp.ecoarmor.conditions.util.MovementConditionListener; import com.willfp.ecoarmor.config.EcoArmorJson; import com.willfp.ecoarmor.display.ArmorDisplay; -import com.willfp.ecoarmor.effects.Effect; -import com.willfp.ecoarmor.effects.Effects; -import com.willfp.ecoarmor.effects.util.EffectWatcher; import com.willfp.ecoarmor.sets.ArmorSets; import com.willfp.ecoarmor.sets.util.EffectiveDurabilityListener; import com.willfp.ecoarmor.sets.util.PreventSkullPlaceListener; @@ -18,6 +14,7 @@ import com.willfp.ecoarmor.upgrades.Tiers; import com.willfp.ecoarmor.upgrades.listeners.AdvancementShardListener; import com.willfp.ecoarmor.upgrades.listeners.CrystalListener; import com.willfp.ecoarmor.util.DiscoverRecipeListener; +import com.willfp.libreforge.api.LibReforge; import lombok.Getter; import org.bukkit.event.Listener; import org.jetbrains.annotations.Nullable; @@ -47,21 +44,19 @@ public class EcoArmorPlugin extends EcoPlugin { instance = this; this.ecoArmorJson = new EcoArmorJson(this); + + LibReforge.init(this); } @Override protected void handleEnable() { - Effects.values().stream().filter(Effect::isEnabled).forEach(effect -> this.getEventManager().registerListener(effect)); - Conditions.values().forEach(condition -> this.getEventManager().registerListener(condition)); + LibReforge.enable(this); } @Override protected void handleReload() { - Effects.values().forEach(effect -> this.getEventManager().unregisterListener(effect)); - Effects.values().stream().filter(Effect::isEnabled).forEach(effect -> this.getEventManager().registerListener(effect)); this.getLogger().info(Tiers.values().size() + " Tiers Loaded"); this.getLogger().info(ArmorSets.values().size() + " Sets Loaded"); - this.getScheduler().runTimer((Runnable) Conditions.HAS_PERMISSION, 100, 100); } @Override @@ -78,12 +73,15 @@ public class EcoArmorPlugin extends EcoPlugin { new AdvancementShardListener(this), new EffectiveDurabilityListener(this), new DiscoverRecipeListener(this), - new EffectWatcher(this), - new MovementConditionListener(this), new PreventSkullPlaceListener() ); } + @Override + protected List loadIntegrationLoaders() { + return LibReforge.getIntegrationLoaders(); + } + @Override protected @Nullable DisplayModule createDisplayModule() { return new ArmorDisplay(this); diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/commands/CommandEditor.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/commands/CommandEditor.java index edf338d..538c427 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/commands/CommandEditor.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/commands/CommandEditor.java @@ -7,10 +7,10 @@ import com.willfp.eco.core.config.interfaces.JSONConfig; import com.willfp.eco.core.web.Paste; import com.willfp.eco.util.StringUtils; import com.willfp.ecoarmor.EcoArmorPlugin; -import com.willfp.ecoarmor.conditions.Condition; -import com.willfp.ecoarmor.conditions.Conditions; -import com.willfp.ecoarmor.effects.Effect; -import com.willfp.ecoarmor.effects.Effects; +import com.willfp.libreforge.api.conditions.Condition; +import com.willfp.libreforge.api.conditions.Conditions; +import com.willfp.libreforge.api.effects.Effect; +import com.willfp.libreforge.api.effects.Effects; import org.bukkit.NamespacedKey; import org.bukkit.enchantments.Enchantment; import org.bukkit.potion.PotionEffectType; @@ -44,10 +44,10 @@ public class CommandEditor extends Subcommand { List potionEffects = Arrays.stream(PotionEffectType.values()).map(PotionEffectType::getName).collect(Collectors.toList()); meta.put("potion-effects", potionEffects); - List effects = Effects.values().stream().map(Effect::getName).collect(Collectors.toList()); + List effects = Effects.INSTANCE.values().stream().map(Effect::getId).collect(Collectors.toList()); meta.put("effects", effects); - List conditions = Conditions.values().stream().map(Condition::getName).collect(Collectors.toList()); + List conditions = Conditions.INSTANCE.values().stream().map(Condition::getId).collect(Collectors.toList()); meta.put("conditions", conditions); config.set("meta", meta); diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/Condition.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/Condition.java deleted file mode 100644 index cf105fa..0000000 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/Condition.java +++ /dev/null @@ -1,102 +0,0 @@ -package com.willfp.ecoarmor.conditions; - -import com.willfp.ecoarmor.EcoArmorPlugin; -import com.willfp.ecoarmor.effects.Effect; -import com.willfp.ecoarmor.sets.ArmorSet; -import com.willfp.ecoarmor.sets.util.ArmorUtils; -import lombok.AccessLevel; -import lombok.Getter; -import org.bukkit.entity.Player; -import org.bukkit.event.Listener; -import org.bukkit.potion.PotionEffect; -import org.jetbrains.annotations.NotNull; - -public abstract class Condition implements Listener { - /** - * Instance of EcoArmor. - */ - @Getter(AccessLevel.PROTECTED) - private final EcoArmorPlugin plugin = EcoArmorPlugin.getInstance(); - - /** - * The name of the effect. - */ - @Getter - private final String name; - - /** - * The class of the config getter type. - */ - @Getter - private final Class typeClass; - - /** - * Create a new condition. - * - * @param name The condition name. - * @param typeClass The class of the config type. - */ - protected Condition(@NotNull final String name, - @NotNull final Class typeClass) { - this.name = name; - this.typeClass = typeClass; - - Conditions.addNewCondition(this); - } - - /** - * Get if condition is met for a player. - * - * @param player The player. - * @param value The value of the condition. - * @return If met. - */ - public final boolean isMet(@NotNull final Player player, - @NotNull final Object value) { - return isConditionMet(player, typeClass.cast(value)); - } - - protected abstract boolean isConditionMet(@NotNull Player player, - @NotNull T value); - - public final void evaluateEffects(@NotNull final Player player, - @NotNull final Object value, - @NotNull final ArmorSet set) { - this.getPlugin().getScheduler().runLater(() -> { - if (isMet(player, value)) { - for (Effect effect : set.getEffects().keySet()) { - Object strength = set.getEffectStrength(effect); - - if (ArmorUtils.isWearingAdvanced(player)) { - Object advancedStrength = set.getAdvancedEffectStrength(effect); - if (advancedStrength != null) { - strength = advancedStrength; - } - } - - if (strength != null) { - effect.enable(player, strength); - } - } - - set.getPotionEffects().forEach((potionEffectType, integer) -> { - player.addPotionEffect(new PotionEffect(potionEffectType, 0x6ffffff, integer - 1, false, false, true)); - }); - - if (ArmorUtils.isWearingAdvanced(player)) { - set.getAdvancedPotionEffects().forEach((potionEffectType, integer) -> { - player.addPotionEffect(new PotionEffect(potionEffectType, 0x6ffffff, integer - 1, false, false, true)); - }); - } - } else { - set.getEffects().keySet().forEach(effect -> effect.disable(player)); - - for (PotionEffect effect : player.getActivePotionEffects()) { - if (effect.getDuration() >= 0x5ffffff && effect.getDuration() <= 0x6ffffff) { - player.removePotionEffect(effect.getType()); - } - } - } - }, 1); - } -} 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 deleted file mode 100644 index ebd5973..0000000 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/Conditions.java +++ /dev/null @@ -1,74 +0,0 @@ -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.ConditionAboveHungerPercent; -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.ConditionBelowHungerPercent; -import com.willfp.ecoarmor.conditions.conditions.ConditionBelowXPLevel; -import com.willfp.ecoarmor.conditions.conditions.ConditionBelowY; -import com.willfp.ecoarmor.conditions.conditions.ConditionHasPermission; -import com.willfp.ecoarmor.conditions.conditions.ConditionInBiome; -import com.willfp.ecoarmor.conditions.conditions.ConditionInWater; -import com.willfp.ecoarmor.conditions.conditions.ConditionInWorld; -import com.willfp.ecoarmor.conditions.conditions.ConditionIsSneaking; -import lombok.experimental.UtilityClass; -import org.jetbrains.annotations.NotNull; - -import java.util.List; - -@UtilityClass -@SuppressWarnings("unused") -public class Conditions { - /** - * All registered effects. - */ - 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(); - public static final Condition ABOVE_HUNGER_PERCENT = new ConditionAboveHungerPercent(); - public static final Condition BELOW_HUNGER_PERCENT = new ConditionBelowHungerPercent(); - public static final Condition IN_BIOME = new ConditionInBiome(); - public static final Condition HAS_PERMISSION = new ConditionHasPermission(); - public static final Condition IS_SNEAKING = new ConditionIsSneaking(); - - /** - * Get condition matching name.s - * - * @param name The name to query. - * @return The matching condition, or null if not found. - */ - public static Condition getByName(@NotNull final String name) { - return BY_NAME.get(name); - } - - /** - * List of all registered conditions. - * - * @return The conditions. - */ - public static List> values() { - return ImmutableList.copyOf(BY_NAME.values()); - } - - /** - * Add new condition to EcoArmor. - * - * @param condition The condition to add. - */ - public static void addNewCondition(@NotNull final Condition condition) { - BY_NAME.remove(condition.getName()); - BY_NAME.put(condition.getName(), condition); - } -} 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 deleted file mode 100644 index 290c577..0000000 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionAboveHealthPercent.java +++ /dev/null @@ -1,79 +0,0 @@ -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.EventPriority; -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( - priority = EventPriority.MONITOR, - ignoreCancelled = true - ) - 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; - } - - evaluateEffects(player, value, set); - } - - @EventHandler( - priority = EventPriority.MONITOR, - ignoreCancelled = true - ) - 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; - } - - evaluateEffects(player, value, set); - } - - @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/ConditionAboveHungerPercent.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionAboveHungerPercent.java deleted file mode 100644 index 7a5585d..0000000 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionAboveHungerPercent.java +++ /dev/null @@ -1,47 +0,0 @@ -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.EventPriority; -import org.bukkit.event.entity.FoodLevelChangeEvent; -import org.jetbrains.annotations.NotNull; - -public class ConditionAboveHungerPercent extends Condition { - public ConditionAboveHungerPercent() { - super("above-hunger-percent", Double.class); - } - - @EventHandler( - priority = EventPriority.MONITOR, - ignoreCancelled = true - ) - public void listener(@NotNull final FoodLevelChangeEvent event) { - Player player = (Player) event.getEntity(); - - ArmorSet set = ArmorUtils.getSetOnPlayer(player); - - if (set == null) { - return; - } - - Double value = set.getConditionValue(this); - - if (value == null) { - return; - } - - evaluateEffects(player, value, set); - } - - @Override - public boolean isConditionMet(@NotNull final Player player, - @NotNull final Double value) { - double maxFood = 20; - double food = player.getFoodLevel(); - - return (food / maxFood) * 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 deleted file mode 100644 index 2dbe30e..0000000 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionAboveXPLevel.java +++ /dev/null @@ -1,44 +0,0 @@ -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.EventPriority; -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( - priority = EventPriority.MONITOR, - ignoreCancelled = true - ) - 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; - } - - evaluateEffects(player, value, set); - } - - @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 deleted file mode 100644 index 56e7998..0000000 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionAboveY.java +++ /dev/null @@ -1,22 +0,0 @@ -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.EventPriority; -import org.bukkit.event.player.PlayerMoveEvent; -import org.jetbrains.annotations.NotNull; - -public class ConditionAboveY extends Condition { - public ConditionAboveY() { - super("above-y", Double.class); - } - - @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 deleted file mode 100644 index 3b22e9a..0000000 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionBelowHealthPercent.java +++ /dev/null @@ -1,79 +0,0 @@ -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.EventPriority; -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( - priority = EventPriority.MONITOR, - ignoreCancelled = true - ) - 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; - } - - evaluateEffects(player, value, set); - } - - @EventHandler( - priority = EventPriority.MONITOR, - ignoreCancelled = true - ) - 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; - } - - evaluateEffects(player, value, set); - } - - @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/ConditionBelowHungerPercent.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionBelowHungerPercent.java deleted file mode 100644 index 933cdab..0000000 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionBelowHungerPercent.java +++ /dev/null @@ -1,47 +0,0 @@ -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.EventPriority; -import org.bukkit.event.entity.FoodLevelChangeEvent; -import org.jetbrains.annotations.NotNull; - -public class ConditionBelowHungerPercent extends Condition { - public ConditionBelowHungerPercent() { - super("below-hunger-percent", Double.class); - } - - @EventHandler( - priority = EventPriority.MONITOR, - ignoreCancelled = true - ) - public void listener(@NotNull final FoodLevelChangeEvent event) { - Player player = (Player) event.getEntity(); - - ArmorSet set = ArmorUtils.getSetOnPlayer(player); - - if (set == null) { - return; - } - - Double value = set.getConditionValue(this); - - if (value == null) { - return; - } - - evaluateEffects(player, value, set); - } - - @Override - public boolean isConditionMet(@NotNull final Player player, - @NotNull final Double value) { - double maxFood = 20; - double food = player.getFoodLevel(); - - return (food / maxFood) * 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 deleted file mode 100644 index eb0eaf2..0000000 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionBelowXPLevel.java +++ /dev/null @@ -1,44 +0,0 @@ -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.EventPriority; -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( - priority = EventPriority.MONITOR, - ignoreCancelled = true - ) - 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; - } - - evaluateEffects(player, value, set); - } - - @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/ConditionBelowY.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionBelowY.java deleted file mode 100644 index e39d88a..0000000 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionBelowY.java +++ /dev/null @@ -1,22 +0,0 @@ -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.EventPriority; -import org.bukkit.event.player.PlayerMoveEvent; -import org.jetbrains.annotations.NotNull; - -public class ConditionBelowY extends Condition { - public ConditionBelowY() { - super("below-y", Double.class); - } - - @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/ConditionHasPermission.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionHasPermission.java deleted file mode 100644 index 5581a23..0000000 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionHasPermission.java +++ /dev/null @@ -1,39 +0,0 @@ -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.Bukkit; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; - -public class ConditionHasPermission extends Condition implements Runnable { - public ConditionHasPermission() { - super("has-permission", String.class); - } - - @Override - public void run() { - for (Player player : Bukkit.getOnlinePlayers()) { - ArmorSet set = ArmorUtils.getSetOnPlayer(player); - - if (set == null) { - return; - } - - String value = set.getConditionValue(this); - - if (value == null) { - return; - } - - evaluateEffects(player, value, set); - } - } - - @Override - public boolean isConditionMet(@NotNull final Player player, - @NotNull final String value) { - return player.hasPermission(value); - } -} diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionInBiome.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionInBiome.java deleted file mode 100644 index c673d45..0000000 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionInBiome.java +++ /dev/null @@ -1,28 +0,0 @@ -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.block.Biome; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.event.player.PlayerMoveEvent; -import org.jetbrains.annotations.NotNull; - -import java.util.Arrays; -import java.util.List; - -public class ConditionInBiome extends Condition { - public ConditionInBiome() { - super("in-biome", String.class); - } - - @Override - public boolean isConditionMet(@NotNull final Player player, - @NotNull final String value) { - List biomeNames = Arrays.asList(value.toLowerCase().split(" ")); - Biome biome = player.getLocation().getWorld().getBiome(player.getLocation().getBlockX(), player.getLocation().getBlockY(), player.getLocation().getBlockZ()); - return biomeNames.contains(biome.name().toLowerCase()); - } -} 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 deleted file mode 100644 index 9dc8c17..0000000 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionInWater.java +++ /dev/null @@ -1,23 +0,0 @@ -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.EventPriority; -import org.bukkit.event.player.PlayerMoveEvent; -import org.jetbrains.annotations.NotNull; - -public class ConditionInWater extends Condition { - public ConditionInWater() { - super("in-water", Boolean.class); - } - - @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 deleted file mode 100644 index 78e86e9..0000000 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionInWorld.java +++ /dev/null @@ -1,32 +0,0 @@ -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.EventPriority; -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); - } - - @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/java/com/willfp/ecoarmor/conditions/conditions/ConditionIsSneaking.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionIsSneaking.java deleted file mode 100644 index 9ba48ae..0000000 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/conditions/ConditionIsSneaking.java +++ /dev/null @@ -1,46 +0,0 @@ -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.EventPriority; -import org.bukkit.event.player.PlayerMoveEvent; -import org.bukkit.event.player.PlayerToggleSneakEvent; -import org.jetbrains.annotations.NotNull; - -public class ConditionIsSneaking extends Condition { - public ConditionIsSneaking() { - super("is-sneaking", Boolean.class); - } - - @EventHandler( - priority = EventPriority.MONITOR, - ignoreCancelled = true - ) - public void listener(@NotNull final PlayerToggleSneakEvent event) { - Player player = event.getPlayer(); - - ArmorSet set = ArmorUtils.getSetOnPlayer(player); - - if (set == null) { - return; - } - - Boolean value = set.getConditionValue(this); - - if (value == null) { - return; - } - - evaluateEffects(player, value, set); - } - - @Override - public boolean isConditionMet(@NotNull final Player player, - @NotNull final Boolean value) { - return player.isSneaking(); - } -} diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/util/MovementConditionListener.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/util/MovementConditionListener.java deleted file mode 100644 index 8ae438b..0000000 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/conditions/util/MovementConditionListener.java +++ /dev/null @@ -1,62 +0,0 @@ -package com.willfp.ecoarmor.conditions.util; - -import com.google.common.collect.ImmutableBiMap; -import com.google.common.collect.ImmutableSet; -import com.willfp.eco.core.PluginDependent; -import com.willfp.ecoarmor.EcoArmorPlugin; -import com.willfp.ecoarmor.conditions.Condition; -import com.willfp.ecoarmor.conditions.Conditions; -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.EventPriority; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerMoveEvent; -import org.jetbrains.annotations.NotNull; - -import java.net.http.WebSocket; -import java.util.Set; - -public class MovementConditionListener extends PluginDependent implements Listener { - /** - * Pass an {@link EcoArmorPlugin} in order to interface with it. - * - * @param plugin The plugin to manage. - */ - public MovementConditionListener(@NotNull EcoArmorPlugin plugin) { - super(plugin); - } - - private static final Set> CONDITIONS = ImmutableSet.of( - Conditions.ABOVE_Y, - Conditions.IN_BIOME, - Conditions.BELOW_Y, - Conditions.IN_WATER, - Conditions.IN_WORLD - ); - - @EventHandler( - priority = EventPriority.MONITOR, - ignoreCancelled = true - ) - public void listener(@NotNull final PlayerMoveEvent event) { - Player player = event.getPlayer(); - - ArmorSet set = ArmorUtils.getSetOnPlayer(player); - - if (set == null) { - return; - } - - for (Condition condition : CONDITIONS) { - Object value = set.getConditionValue(condition); - - if (value == null) { - continue; - } - - condition.evaluateEffects(player, value, set); - } - } -} diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/Effect.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/Effect.java deleted file mode 100644 index 515f239..0000000 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/Effect.java +++ /dev/null @@ -1,154 +0,0 @@ -package com.willfp.ecoarmor.effects; - -import com.willfp.ecoarmor.EcoArmorPlugin; -import lombok.AccessLevel; -import lombok.Getter; -import org.bukkit.entity.Player; -import org.bukkit.event.Listener; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; -import java.util.UUID; -import java.util.function.Consumer; - -public abstract class Effect implements Listener { - /** - * Instance of EcoArmor. - */ - @Getter(AccessLevel.PROTECTED) - private final EcoArmorPlugin plugin = EcoArmorPlugin.getInstance(); - - /** - * The name of the effect. - */ - @Getter - private final String name; - - /** - * UUID of the effect, used in attribute modifiers. - */ - @Getter - private final UUID uuid; - - /** - * If the effect is enabled. - */ - @Getter - private boolean enabled; - - /** - * The class of the config getter type. - */ - @Getter - private final Class typeClass; - - /** - * Players that the effect is currently enabled for. - */ - private final Map enabledPlayers = new HashMap<>(); - - /** - * Create a new effect. - * - * @param name The effect name. - * @param typeClass The class of the config type. - */ - protected Effect(@NotNull final String name, - @NotNull final Class typeClass) { - this.name = name; - this.typeClass = typeClass; - this.uuid = UUID.nameUUIDFromBytes(name.getBytes()); - - update(); - Effects.addNewEffect(this); - } - - /** - * Get the effect strength for a player. - * - * @param player The player. - * @return The strength. - */ - @Nullable - public final T getStrengthForPlayer(@NotNull final Player player) { - return enabledPlayers.get(player.getUniqueId()); - } - - /** - * Apply effect if enabled for a player. - * - * @param player The player. - * @param consumer The effect function. - */ - public void applyIfEnabled(@NotNull final Player player, - @NotNull final Consumer consumer) { - T strength = getStrengthForPlayer(player); - if (strength == null) { - return; - } else { - consumer.accept(strength); - } - } - - /** - * Enable the effect for a player. - * - * @param player The player. - * @param value The strength. - */ - public final void enable(@NotNull final Player player, - @NotNull final Object value) { - if (!this.isEnabled()) { - return; - } - - if (enabledPlayers.containsKey(player.getUniqueId())) { - return; - } - - Object val; - - if (value instanceof Double && typeClass.equals(Integer.class)) { - val = (int) Math.round((double) value); - } else { - val = value; - } - - enabledPlayers.put(player.getUniqueId(), typeClass.cast(val)); - - this.onEnable(player); - } - - /** - * Disable the effect for a player. - * - * @param player The player. - */ - public final void disable(@NotNull final Player player) { - if (!this.isEnabled()) { - return; - } - - enabledPlayers.remove(player.getUniqueId()); - - this.onDisable(player); - } - - protected void onEnable(@NotNull final Player player) { - // Empty by default - } - - protected void onDisable(@NotNull final Player player) { - // Empty by default - } - - /** - * Update if the effect is enabled. - */ - public void update() { - enabled = this.getPlugin().getConfigYml().getBool("effects." + name + ".enabled"); - } -} diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/Effects.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/Effects.java deleted file mode 100644 index 327d65f..0000000 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/Effects.java +++ /dev/null @@ -1,86 +0,0 @@ -package com.willfp.ecoarmor.effects; - -import com.google.common.collect.BiMap; -import com.google.common.collect.HashBiMap; -import com.google.common.collect.ImmutableList; -import com.willfp.ecoarmor.effects.effects.AttackSpeedMultiplier; -import com.willfp.ecoarmor.effects.effects.BonusHearts; -import com.willfp.ecoarmor.effects.effects.BossDamageMultiplier; -import com.willfp.ecoarmor.effects.effects.BowDamageMultiplier; -import com.willfp.ecoarmor.effects.effects.DamageMultiplier; -import com.willfp.ecoarmor.effects.effects.DamageTakenMultiplier; -import com.willfp.ecoarmor.effects.effects.EvadeChance; -import com.willfp.ecoarmor.effects.effects.ExperienceMultiplier; -import com.willfp.ecoarmor.effects.effects.FallDamageMultiplier; -import com.willfp.ecoarmor.effects.effects.Flight; -import com.willfp.ecoarmor.effects.effects.HungerLossMultiplier; -import com.willfp.ecoarmor.effects.effects.KnockbackMultiplier; -import com.willfp.ecoarmor.effects.effects.MeleeDamageMultiplier; -import com.willfp.ecoarmor.effects.effects.RegenerationMultiplier; -import com.willfp.ecoarmor.effects.effects.SpeedMultiplier; -import com.willfp.ecoarmor.effects.effects.Telekinesis; -import com.willfp.ecoarmor.effects.effects.TridentDamageMultiplier; -import com.willfp.ecoarmor.effects.effects.WarpChance; -import lombok.experimental.UtilityClass; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.List; - -@UtilityClass -@SuppressWarnings("unused") -public class Effects { - /** - * All registered effects. - */ - private static final BiMap> BY_NAME = HashBiMap.create(); - - public static final Effect BOW_DAMAGE_MULTIPLIER = new BowDamageMultiplier(); - public static final Effect DAMAGE_MULTIPLIER = new DamageMultiplier(); - public static final Effect DAMAGE_TAKEN_MULTIPLIER = new DamageTakenMultiplier(); - public static final Effect EVADE_CHANCE = new EvadeChance(); - public static final Effect FALL_DAMAGE_MULTIPLIER = new FallDamageMultiplier(); - public static final Effect MELEE_DAMAGE_MULTIPLIER = new MeleeDamageMultiplier(); - public static final Effect TRIDENT_DAMAGE_MULTIPLIER = new TridentDamageMultiplier(); - public static final Effect BONUS_HEARTS = new BonusHearts(); - public static final Effect SPEED_MULTIPLIER = new SpeedMultiplier(); - public static final Effect EXPERIENCE_MULTIPLIER = new ExperienceMultiplier(); - public static final Effect REGENERATION_MULTIPLIER = new RegenerationMultiplier(); - public static final Effect WARP_CHANCE = new WarpChance(); - public static final Effect ATTACK_SPEED_MULTIPLIER = new AttackSpeedMultiplier(); - public static final Effect FLIGHT = new Flight(); - public static final Effect HUNGER_LOSS_MULTIPLIER = new HungerLossMultiplier(); - public static final Effect BOSS_DAMAGE_MULTIPLIER = new BossDamageMultiplier(); - public static final Effect KNOCKBACK_MULTIPLIER = new KnockbackMultiplier(); - public static final Effect TELEKINESIS = new Telekinesis(); - - /** - * Get effect matching name. - * - * @param name The name to query. - * @return The matching effect, or null if not found. - */ - @Nullable - public static Effect getByName(@NotNull final String name) { - return BY_NAME.get(name); - } - - /** - * List of all registered effects. - * - * @return The effects. - */ - public static List> values() { - return ImmutableList.copyOf(BY_NAME.values()); - } - - /** - * Add new effect to EcoArmor. - * - * @param effect The effect to add. - */ - public static void addNewEffect(@NotNull final Effect effect) { - BY_NAME.remove(effect.getName()); - BY_NAME.put(effect.getName(), effect); - } -} diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/AttackSpeedMultiplier.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/AttackSpeedMultiplier.java deleted file mode 100644 index 9011f67..0000000 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/AttackSpeedMultiplier.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.willfp.ecoarmor.effects.effects; - -import com.willfp.ecoarmor.effects.Effect; -import org.bukkit.attribute.Attribute; -import org.bukkit.attribute.AttributeInstance; -import org.bukkit.attribute.AttributeModifier; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; - -public class AttackSpeedMultiplier extends Effect { - public AttackSpeedMultiplier() { - super("attack-speed-multiplier", Double.class); - } - - @Override - protected void onEnable(@NotNull final Player player) { - AttributeInstance attackSpeed = player.getAttribute(Attribute.GENERIC_ATTACK_SPEED); - assert attackSpeed != null; - - Double multiplier = this.getStrengthForPlayer(player); - - if (multiplier == null) { - return; - } - - AttributeModifier modifier = new AttributeModifier(this.getUuid(), "attack-speed-multiplier", 1 - multiplier, AttributeModifier.Operation.MULTIPLY_SCALAR_1); - if (attackSpeed.getModifiers().stream().noneMatch(attributeModifier -> attributeModifier.getUniqueId().equals(modifier.getUniqueId()))) { - attackSpeed.addModifier(modifier); - } - } - - @Override - protected void onDisable(@NotNull final Player player) { - AttributeInstance attackSpeed = player.getAttribute(Attribute.GENERIC_ATTACK_SPEED); - assert attackSpeed != null; - - attackSpeed.removeModifier(new AttributeModifier(this.getUuid(), "attack-speed-multiplier", 0, AttributeModifier.Operation.MULTIPLY_SCALAR_1)); - } -} diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/BonusHearts.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/BonusHearts.java deleted file mode 100644 index 1179350..0000000 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/BonusHearts.java +++ /dev/null @@ -1,47 +0,0 @@ -package com.willfp.ecoarmor.effects.effects; - -import com.willfp.ecoarmor.effects.Effect; -import org.bukkit.attribute.Attribute; -import org.bukkit.attribute.AttributeInstance; -import org.bukkit.attribute.AttributeModifier; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; - -public class BonusHearts extends Effect { - public BonusHearts() { - super("bonus-hearts", Integer.class); - } - - @Override - protected void onEnable(@NotNull final Player player) { - AttributeInstance maxHealth = player.getAttribute(Attribute.GENERIC_MAX_HEALTH); - assert maxHealth != null; - - Integer bonus = this.getStrengthForPlayer(player); - - if (bonus == null) { - return; - } - - bonus *= 2; - - if (player.getHealth() >= maxHealth.getValue()) { - this.getPlugin().getScheduler().runLater(() -> { - player.setHealth(player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()); - }, 1); - } - - AttributeModifier modifier = new AttributeModifier(this.getUuid(), "bonus-hearts", bonus, AttributeModifier.Operation.ADD_NUMBER); - if (maxHealth.getModifiers().stream().noneMatch(attributeModifier -> attributeModifier.getUniqueId().equals(modifier.getUniqueId()))) { - maxHealth.addModifier(modifier); - } - } - - @Override - protected void onDisable(@NotNull final Player player) { - AttributeInstance maxHealth = player.getAttribute(Attribute.GENERIC_MAX_HEALTH); - assert maxHealth != null; - - maxHealth.removeModifier(new AttributeModifier(this.getUuid(), "bonus-hearts", 0, AttributeModifier.Operation.ADD_NUMBER)); - } -} diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/BossDamageMultiplier.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/BossDamageMultiplier.java deleted file mode 100644 index 73ad19a..0000000 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/BossDamageMultiplier.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.willfp.ecoarmor.effects.effects; - -import com.willfp.ecoarmor.effects.Effect; -import org.bukkit.NamespacedKey; -import org.bukkit.entity.Boss; -import org.bukkit.entity.ElderGuardian; -import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; -import org.bukkit.entity.Projectile; -import org.bukkit.event.EventHandler; -import org.bukkit.event.entity.EntityDamageByEntityEvent; -import org.bukkit.persistence.PersistentDataType; -import org.bukkit.projectiles.ProjectileSource; -import org.jetbrains.annotations.NotNull; - -@SuppressWarnings("deprecation") -public class BossDamageMultiplier extends Effect { - public BossDamageMultiplier() { - super("boss-damage-multiplier", Double.class); - } - - @EventHandler - public void listener(@NotNull final EntityDamageByEntityEvent event) { - if (event.isCancelled()) { - return; - } - - Entity victim = event.getEntity(); - - if (!(victim instanceof Boss || victim instanceof ElderGuardian) && !victim.getPersistentDataContainer().has(new NamespacedKey("ecobosses", "boss"), PersistentDataType.STRING)) { - return; - } - - Player attacker = null; - if (event.getDamager() instanceof Projectile) { - ProjectileSource shooter = ((Projectile) event.getDamager()).getShooter(); - if (shooter == null) { - return; - } - - if (shooter instanceof Player) { - attacker = (Player) shooter; - } - } else if (event.getDamager() instanceof Player) { - attacker = (Player) event.getDamager(); - } - - if (attacker == null) { - return; - } - - this.applyIfEnabled(attacker, multiplier -> event.setDamage(event.getDamage() * multiplier)); - } -} diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/BowDamageMultiplier.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/BowDamageMultiplier.java deleted file mode 100644 index e2ebd0f..0000000 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/BowDamageMultiplier.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.willfp.ecoarmor.effects.effects; - -import com.willfp.ecoarmor.effects.Effect; -import org.bukkit.entity.Arrow; -import org.bukkit.entity.Player; -import org.bukkit.entity.Projectile; -import org.bukkit.event.EventHandler; -import org.bukkit.event.entity.EntityDamageByEntityEvent; -import org.bukkit.projectiles.ProjectileSource; -import org.jetbrains.annotations.NotNull; - -public class BowDamageMultiplier extends Effect { - public BowDamageMultiplier() { - super("bow-damage-multiplier", Double.class); - } - - @EventHandler - public void listener(@NotNull final EntityDamageByEntityEvent event) { - if (event.isCancelled()) { - return; - } - - if (!(event.getDamager() instanceof Arrow)) { - return; - } - - ProjectileSource shooter = ((Projectile) event.getDamager()).getShooter(); - - if (!(shooter instanceof Player)) { - return; - } - - Player player = (Player) shooter; - - this.applyIfEnabled(player, multiplier -> event.setDamage(event.getDamage() * multiplier)); - } -} diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/DamageMultiplier.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/DamageMultiplier.java deleted file mode 100644 index 7b669a5..0000000 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/DamageMultiplier.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.willfp.ecoarmor.effects.effects; - -import com.willfp.ecoarmor.effects.Effect; -import org.bukkit.entity.Player; -import org.bukkit.entity.Projectile; -import org.bukkit.event.EventHandler; -import org.bukkit.event.entity.EntityDamageByEntityEvent; -import org.bukkit.projectiles.ProjectileSource; -import org.jetbrains.annotations.NotNull; - -public class DamageMultiplier extends Effect { - public DamageMultiplier() { - super("damage-multiplier", Double.class); - } - - @EventHandler - public void listener(@NotNull final EntityDamageByEntityEvent event) { - if (event.isCancelled()) { - return; - } - - Player attacker = null; - if (event.getDamager() instanceof Projectile) { - ProjectileSource shooter = ((Projectile) event.getDamager()).getShooter(); - if (shooter == null) { - return; - } - - if (shooter instanceof Player) { - attacker = (Player) shooter; - } - } else if (event.getDamager() instanceof Player) { - attacker = (Player) event.getDamager(); - } - - if (attacker == null) { - return; - } - - this.applyIfEnabled(attacker, multiplier -> event.setDamage(event.getDamage() * multiplier)); - } -} diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/DamageTakenMultiplier.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/DamageTakenMultiplier.java deleted file mode 100644 index 103a372..0000000 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/DamageTakenMultiplier.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.willfp.ecoarmor.effects.effects; - -import com.willfp.ecoarmor.effects.Effect; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.entity.EntityDamageEvent; -import org.jetbrains.annotations.NotNull; - -public class DamageTakenMultiplier extends Effect { - public DamageTakenMultiplier() { - super("damage-taken-multiplier", Double.class); - } - - @EventHandler - public void listener(@NotNull final EntityDamageEvent event) { - if (event.isCancelled()) { - return; - } - - if (!(event.getEntity() instanceof Player)) { - return; - } - - Player player = (Player) event.getEntity(); - - this.applyIfEnabled(player, multiplier -> event.setDamage(event.getDamage() * multiplier)); - } -} diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/DurabilityMultiplier.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/DurabilityMultiplier.java deleted file mode 100644 index 59808d0..0000000 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/DurabilityMultiplier.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.willfp.ecoarmor.effects.effects; - -import com.willfp.eco.util.NumberUtils; -import com.willfp.ecoarmor.effects.Effect; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.player.PlayerItemDamageEvent; -import org.jetbrains.annotations.NotNull; - -public class DurabilityMultiplier extends Effect { - public DurabilityMultiplier() { - super("durability-multiplier", Double.class); - } - - @EventHandler - public void listener(@NotNull final PlayerItemDamageEvent event) { - if (event.isCancelled()) { - return; - } - - Player player = event.getPlayer(); - - this.applyIfEnabled(player, multiplier -> { - if (NumberUtils.randFloat(0, 100) < 1 - (1 / multiplier)) { - event.setCancelled(true); - } - }); - } -} diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/EvadeChance.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/EvadeChance.java deleted file mode 100644 index 1606335..0000000 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/EvadeChance.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.willfp.ecoarmor.effects.effects; - -import com.willfp.eco.util.NumberUtils; -import com.willfp.ecoarmor.effects.Effect; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.entity.EntityDamageEvent; -import org.jetbrains.annotations.NotNull; - -public class EvadeChance extends Effect { - public EvadeChance() { - super("evade-chance", Double.class); - } - - @EventHandler - public void listener(@NotNull final EntityDamageEvent event) { - if (event.isCancelled()) { - return; - } - - if (!(event.getEntity() instanceof Player)) { - return; - } - - Player player = (Player) event.getEntity(); - - this.applyIfEnabled(player, chance -> { - if (NumberUtils.randFloat(0, 100) < chance) { - event.setCancelled(true); - } - }); - } -} diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/ExperienceMultiplier.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/ExperienceMultiplier.java deleted file mode 100644 index 96e86e0..0000000 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/ExperienceMultiplier.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.willfp.ecoarmor.effects.effects; - -import com.willfp.eco.core.events.NaturalExpGainEvent; -import com.willfp.ecoarmor.effects.Effect; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.jetbrains.annotations.NotNull; - -public class ExperienceMultiplier extends Effect { - public ExperienceMultiplier() { - super("experience-multiplier", Double.class); - } - - @EventHandler - public void listener(@NotNull final NaturalExpGainEvent event) { - Player player = event.getExpChangeEvent().getPlayer(); - - if (event.getExpChangeEvent().getAmount() < 0) { - return; - } - - this.applyIfEnabled(player, multiplier -> event.getExpChangeEvent().setAmount((int) Math.ceil(event.getExpChangeEvent().getAmount() * multiplier))); - } -} diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/FallDamageMultiplier.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/FallDamageMultiplier.java deleted file mode 100644 index c063931..0000000 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/FallDamageMultiplier.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.willfp.ecoarmor.effects.effects; - -import com.willfp.ecoarmor.effects.Effect; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.entity.EntityDamageEvent; -import org.jetbrains.annotations.NotNull; - -public class FallDamageMultiplier extends Effect { - public FallDamageMultiplier() { - super("fall-damage-multiplier", Double.class); - } - - @EventHandler - public void listener(@NotNull final EntityDamageEvent event) { - if (event.isCancelled()) { - return; - } - - if (!(event.getEntity() instanceof Player)) { - return; - } - - if (event.getCause() != EntityDamageEvent.DamageCause.FALL) { - return; - } - - Player player = (Player) event.getEntity(); - - this.applyIfEnabled(player, multiplier -> event.setDamage(event.getDamage() * multiplier)); - } -} diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/Flight.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/Flight.java deleted file mode 100644 index cdd03e4..0000000 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/Flight.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.willfp.ecoarmor.effects.effects; - -import com.willfp.ecoarmor.effects.Effect; -import org.bukkit.GameMode; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; - -public class Flight extends Effect { - public Flight() { - super("flight", Boolean.class); - } - - @Override - protected void onEnable(@NotNull final Player player) { - player.setAllowFlight(true); - } - - @Override - protected void onDisable(@NotNull final Player player) { - if (player.hasPermission("ecoarmor.noflydisable")) { - return; - } - - if (player.getGameMode() == GameMode.SURVIVAL || player.getGameMode() == GameMode.ADVENTURE) { - player.setAllowFlight(false); - } - } -} diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/HungerLossMultiplier.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/HungerLossMultiplier.java deleted file mode 100644 index bd71fb1..0000000 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/HungerLossMultiplier.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.willfp.ecoarmor.effects.effects; - -import com.willfp.eco.util.NumberUtils; -import com.willfp.ecoarmor.effects.Effect; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.entity.FoodLevelChangeEvent; -import org.jetbrains.annotations.NotNull; - -public class HungerLossMultiplier extends Effect { - public HungerLossMultiplier() { - super("hunger-loss-multiplier", Double.class); - } - - @EventHandler - public void listener(@NotNull final FoodLevelChangeEvent event) { - if (!(event.getEntity() instanceof Player)) { - return; - } - - Player player = (Player) event.getEntity(); - - Double multiplier = this.getStrengthForPlayer(player); - - if (multiplier == null) { - return; - } - - if (event.getFoodLevel() > player.getFoodLevel()) { - return; - } - - if (multiplier < 1) { - if (NumberUtils.randFloat(0, 1) > multiplier) { - event.setCancelled(true); - } - } else { - int difference = player.getFoodLevel() - event.getFoodLevel(); - difference = (int) Math.ceil(difference * multiplier); - event.setFoodLevel(player.getFoodLevel() - difference); - } - } -} diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/KnockbackMultiplier.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/KnockbackMultiplier.java deleted file mode 100644 index 3c5f1ec..0000000 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/KnockbackMultiplier.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.willfp.ecoarmor.effects.effects; - -import com.willfp.ecoarmor.effects.Effect; -import org.bukkit.attribute.Attribute; -import org.bukkit.attribute.AttributeInstance; -import org.bukkit.attribute.AttributeModifier; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; - -public class KnockbackMultiplier extends Effect { - public KnockbackMultiplier() { - super("knockback-multiplier", Double.class); - } - - @Override - protected void onEnable(@NotNull final Player player) { - AttributeInstance movementSpeed = player.getAttribute(Attribute.GENERIC_ATTACK_KNOCKBACK); - assert movementSpeed != null; - - Double strength = this.getStrengthForPlayer(player); - - if (strength == null) { - return; - } - - AttributeModifier modifier = new AttributeModifier(this.getUuid(), "kb-multiplier", strength - 1, AttributeModifier.Operation.MULTIPLY_SCALAR_1); - if (movementSpeed.getModifiers().stream().noneMatch(attributeModifier -> attributeModifier.getUniqueId().equals(modifier.getUniqueId()))) { - movementSpeed.addModifier(modifier); - } - } - - @Override - protected void onDisable(@NotNull final Player player) { - AttributeInstance movementSpeed = player.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED); - assert movementSpeed != null; - - movementSpeed.removeModifier(new AttributeModifier(this.getUuid(), "kb-multiplier", 0, AttributeModifier.Operation.MULTIPLY_SCALAR_1)); - } -} diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/MeleeDamageMultiplier.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/MeleeDamageMultiplier.java deleted file mode 100644 index 5212758..0000000 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/MeleeDamageMultiplier.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.willfp.ecoarmor.effects.effects; - -import com.willfp.ecoarmor.effects.Effect; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.entity.EntityDamageByEntityEvent; -import org.jetbrains.annotations.NotNull; - -public class MeleeDamageMultiplier extends Effect { - public MeleeDamageMultiplier() { - super("melee-damage-multiplier", Double.class); - } - - @EventHandler - public void listener(@NotNull final EntityDamageByEntityEvent event) { - if (event.isCancelled()) { - return; - } - - if (!(event.getDamager() instanceof Player)) { - return; - } - - Player attacker = (Player) event.getDamager(); - - this.applyIfEnabled(attacker, multiplier -> event.setDamage(event.getDamage() * multiplier)); - } -} diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/RegenerationMultiplier.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/RegenerationMultiplier.java deleted file mode 100644 index 82318f1..0000000 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/RegenerationMultiplier.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.willfp.ecoarmor.effects.effects; - -import com.willfp.ecoarmor.effects.Effect; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.entity.EntityRegainHealthEvent; -import org.jetbrains.annotations.NotNull; - -public class RegenerationMultiplier extends Effect { - public RegenerationMultiplier() { - super("regeneration-multiplier", Double.class); - } - - @EventHandler - public void listener(@NotNull final EntityRegainHealthEvent event) { - if (event.isCancelled()) { - return; - } - - if (!(event.getEntity() instanceof Player)) { - return; - } - - Player player = (Player) event.getEntity(); - - this.applyIfEnabled(player, multiplier -> event.setAmount(event.getAmount() * multiplier)); - } -} diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/SpeedMultiplier.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/SpeedMultiplier.java deleted file mode 100644 index d8b3b90..0000000 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/SpeedMultiplier.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.willfp.ecoarmor.effects.effects; - -import com.willfp.ecoarmor.effects.Effect; -import org.bukkit.attribute.Attribute; -import org.bukkit.attribute.AttributeInstance; -import org.bukkit.attribute.AttributeModifier; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; - -public class SpeedMultiplier extends Effect { - public SpeedMultiplier() { - super("speed-multiplier", Double.class); - } - - @Override - protected void onEnable(@NotNull final Player player) { - AttributeInstance movementSpeed = player.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED); - assert movementSpeed != null; - - Double strength = this.getStrengthForPlayer(player); - - if (strength == null) { - return; - } - - AttributeModifier modifier = new AttributeModifier(this.getUuid(), "speed-multiplier", strength - 1, AttributeModifier.Operation.MULTIPLY_SCALAR_1); - if (movementSpeed.getModifiers().stream().noneMatch(attributeModifier -> attributeModifier.getUniqueId().equals(modifier.getUniqueId()))) { - movementSpeed.addModifier(modifier); - } - } - - @Override - protected void onDisable(@NotNull final Player player) { - AttributeInstance movementSpeed = player.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED); - assert movementSpeed != null; - - movementSpeed.removeModifier(new AttributeModifier(this.getUuid(), "speed-multiplier", 0, AttributeModifier.Operation.MULTIPLY_SCALAR_1)); - } -} diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/Telekinesis.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/Telekinesis.java deleted file mode 100644 index dd20e89..0000000 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/Telekinesis.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.willfp.ecoarmor.effects.effects; - -import com.willfp.eco.util.NumberUtils; -import com.willfp.eco.util.TelekinesisUtils; -import com.willfp.ecoarmor.effects.Effect; -import com.willfp.ecoarmor.sets.ArmorSet; -import com.willfp.ecoarmor.sets.util.ArmorUtils; -import org.bukkit.Location; -import org.bukkit.block.Block; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.entity.EntityDamageByEntityEvent; -import org.bukkit.util.Vector; -import org.jetbrains.annotations.NotNull; - -public class Telekinesis extends Effect { - public Telekinesis() { - super("telekinesis", Boolean.class); - TelekinesisUtils.registerTest(player -> this.getStrengthForPlayer(player) != null); - } -} diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/TridentDamageMultiplier.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/TridentDamageMultiplier.java deleted file mode 100644 index 55eb50f..0000000 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/TridentDamageMultiplier.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.willfp.ecoarmor.effects.effects; - -import com.willfp.ecoarmor.effects.Effect; -import org.bukkit.entity.Player; -import org.bukkit.entity.Projectile; -import org.bukkit.entity.Trident; -import org.bukkit.event.EventHandler; -import org.bukkit.event.entity.EntityDamageByEntityEvent; -import org.bukkit.projectiles.ProjectileSource; -import org.jetbrains.annotations.NotNull; - -public class TridentDamageMultiplier extends Effect { - public TridentDamageMultiplier() { - super("trident-damage-multiplier", Double.class); - } - - @EventHandler - public void listener(@NotNull final EntityDamageByEntityEvent event) { - if (event.isCancelled()) { - return; - } - - if (!(event.getDamager() instanceof Trident)) { - return; - } - - ProjectileSource shooter = ((Projectile) event.getDamager()).getShooter(); - - if (!(shooter instanceof Player)) { - return; - } - - Player player = (Player) shooter; - - this.applyIfEnabled(player, multiplier -> event.setDamage(event.getDamage() * multiplier)); - } -} diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/WarpChance.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/WarpChance.java deleted file mode 100644 index bf06ecb..0000000 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/effects/WarpChance.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.willfp.ecoarmor.effects.effects; - -import com.willfp.eco.util.NumberUtils; -import com.willfp.ecoarmor.effects.Effect; -import org.bukkit.Location; -import org.bukkit.block.Block; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.entity.EntityDamageByEntityEvent; -import org.bukkit.util.Vector; -import org.jetbrains.annotations.NotNull; - -public class WarpChance extends Effect { - public WarpChance() { - super("warp-chance", Double.class); - } - - @EventHandler - public void listener(@NotNull final EntityDamageByEntityEvent event) { - if (event.isCancelled()) { - return; - } - - if (!(event.getDamager() instanceof Player)) { - return; - } - - if (!(event.getEntity() instanceof LivingEntity)) { - return; - } - - Player player = (Player) event.getDamager(); - LivingEntity victim = (LivingEntity) event.getEntity(); - - Double chance = this.getStrengthForPlayer(player); - - if (chance == null) { - return; - } - - if (NumberUtils.randFloat(0, 100) > chance) { - return; - } - - Vector between = victim.getLocation().subtract(player.getLocation()).toVector(); - Location behind = victim.getLocation().add(between); - - behind.setYaw(player.getLocation().getYaw() + 180); - - Block head = behind.add(0, 1.4, 0).getBlock(); - - if (!head.getType().isAir()) { - return; - } - - player.getLocation().setYaw(player.getLocation().getYaw() + 180); - player.teleport(behind); - } -} diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/util/EffectWatcher.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/util/EffectWatcher.java deleted file mode 100644 index 97a8447..0000000 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/effects/util/EffectWatcher.java +++ /dev/null @@ -1,89 +0,0 @@ -package com.willfp.ecoarmor.effects.util; - -import com.willfp.eco.core.EcoPlugin; -import com.willfp.eco.core.PluginDependent; -import com.willfp.eco.core.events.ArmorChangeEvent; -import com.willfp.eco.core.events.ArmorEquipEvent; -import com.willfp.ecoarmor.effects.Effect; -import com.willfp.ecoarmor.effects.Effects; -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.Listener; -import org.bukkit.potion.PotionEffect; -import org.jetbrains.annotations.NotNull; - -public class EffectWatcher extends PluginDependent implements Listener { - /** - * Pass an {@link EcoPlugin} in order to interface with it. - * - * @param plugin The plugin to manage. - */ - public EffectWatcher(@NotNull final EcoPlugin plugin) { - super(plugin); - } - - /** - * Listener for armor equipping. - * - * @param event The event to listen for. - */ - @EventHandler - public void armorEquipListener(@NotNull final ArmorChangeEvent event) { - Player player = event.getPlayer(); - ArmorSet set = ArmorUtils.getSetOnPlayer(player); - - boolean conditionsMet = ArmorUtils.areConditionsMet(player); - - for (Effect effect : Effects.values()) { - boolean enabled = true; - - if (set == null) { - effect.disable(player); - continue; - } - - Object strength = set.getEffectStrength(effect); - - if (ArmorUtils.isWearingAdvanced(player)) { - Object advancedStrength = set.getAdvancedEffectStrength(effect); - if (advancedStrength != null) { - strength = advancedStrength; - } - } - - if (strength == null) { - enabled = false; - } - - if (!conditionsMet) { - enabled = false; - } - - if (enabled) { - effect.enable(player, strength); - } else { - effect.disable(player); - } - } - - if (set == null || !conditionsMet) { - for (PotionEffect effect : player.getActivePotionEffects()) { - if (effect.getDuration() >= 0x5ffffff && effect.getDuration() <= 0x6ffffff) { - player.removePotionEffect(effect.getType()); - } - } - } else { - set.getPotionEffects().forEach((potionEffectType, integer) -> { - player.addPotionEffect(new PotionEffect(potionEffectType, 0x6ffffff, integer - 1, false, false, true)); - }); - - if (ArmorUtils.isWearingAdvanced(player)) { - set.getAdvancedPotionEffects().forEach((potionEffectType, integer) -> { - player.addPotionEffect(new PotionEffect(potionEffectType, 0x6ffffff, integer - 1, false, false, true)); - }); - } - } - } -} diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/sets/ArmorSet.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/sets/ArmorSet.java index 1187c31..3c1176e 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/sets/ArmorSet.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/sets/ArmorSet.java @@ -4,7 +4,6 @@ import com.willfp.eco.core.EcoPlugin; import com.willfp.eco.core.config.interfaces.Config; import com.willfp.eco.core.config.interfaces.JSONConfig; import com.willfp.eco.core.display.Display; -import com.willfp.eco.core.fast.FastItemStack; import com.willfp.eco.core.items.CustomItem; import com.willfp.eco.core.items.Items; import com.willfp.eco.core.items.builder.ItemBuilder; @@ -12,15 +11,17 @@ import com.willfp.eco.core.items.builder.ItemStackBuilder; import com.willfp.eco.core.items.builder.LeatherArmorBuilder; import com.willfp.eco.core.items.builder.SkullBuilder; import com.willfp.eco.core.recipe.Recipes; -import com.willfp.eco.util.StringUtils; -import com.willfp.ecoarmor.conditions.Condition; -import com.willfp.ecoarmor.conditions.Conditions; -import com.willfp.ecoarmor.effects.Effect; -import com.willfp.ecoarmor.effects.Effects; import com.willfp.ecoarmor.sets.meta.ArmorSlot; import com.willfp.ecoarmor.sets.util.ArmorUtils; import com.willfp.ecoarmor.upgrades.Tier; import com.willfp.ecoarmor.upgrades.Tiers; +import com.willfp.libreforge.api.conditions.Condition; +import com.willfp.libreforge.api.conditions.Conditions; +import com.willfp.libreforge.api.conditions.ConfiguredCondition; +import com.willfp.libreforge.api.effects.ConfiguredEffect; +import com.willfp.libreforge.api.effects.Effect; +import com.willfp.libreforge.api.effects.Effects; +import com.willfp.libreforge.api.provider.Holder; import lombok.AccessLevel; import lombok.Getter; import org.bukkit.Bukkit; @@ -37,14 +38,17 @@ import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.HashMap; +import java.util.HashSet; import java.util.List; -import java.util.Locale; import java.util.Map; import java.util.Objects; +import java.util.Set; import java.util.stream.Collectors; -@SuppressWarnings("unchecked") -public class ArmorSet { +/* +TODO: Split off ArmorSet between two separate armorset objects (one advanced, one not) + */ +public class ArmorSet implements Holder { /** * Instance of EcoArmor. */ @@ -67,19 +71,19 @@ public class ArmorSet { * Conditions and their values. */ @Getter - private final Map, Object> conditions = new HashMap<>(); + private final Set conditions = new HashSet<>(); /** * Effects and their strengths. */ @Getter - private final Map, Object> effects = new HashMap<>(); + private final Set effects = new HashSet<>(); /** * Effects and their strengths on advanced armor. */ @Getter - private final Map, Object> advancedEffects = new HashMap<>(); + private final Set advancedEffects = new HashSet<>(); /** * Potion effects to be applied on equip. @@ -131,21 +135,18 @@ public class ArmorSet { this.name = config.getString("name"); for (JSONConfig cfg : this.getConfig().getSubsections("conditions")) { - Condition effect = Conditions.getByName(cfg.getString("id")); - Object value = cfg.get("args"); - conditions.put(effect, value); + Condition effect = Conditions.INSTANCE.getByID(cfg.getString("id")); + conditions.add(new ConfiguredCondition(effect, cfg.getSubsection("args"))); } for (JSONConfig cfg : this.getConfig().getSubsections("effects")) { - Effect effect = Effects.getByName(cfg.getString("id")); - Object value = cfg.get("args"); - effects.put(effect, value); + Effect effect = Effects.INSTANCE.getByID(cfg.getString("id")); + effects.add(new ConfiguredEffect(effect, cfg.getSubsection("args"))); } for (JSONConfig cfg : this.getConfig().getSubsections("advancedEffects")) { - Effect effect = Effects.getByName(cfg.getString("id")); - Object value = cfg.get("args"); - advancedEffects.put(effect, value); + Effect effect = Effects.INSTANCE.getByID(cfg.getString("id")); + advancedEffects.add(new ConfiguredEffect(effect, cfg.getSubsection("args"))); } for (JSONConfig cfg : this.getConfig().getSubsections("potionEffects")) { @@ -367,49 +368,6 @@ public class ArmorSet { return advancedItems.get(slot); } - /** - * Get condition value of effect. - * - * @param condition The condition to query. - * @param The type of the condition value. - * @return The value. - */ - @Nullable - public T getConditionValue(@NotNull final Condition condition) { - return (T) conditions.get(condition); - } - - /** - * Get effect strength of effect. - * - * @param effect The effect to query. - * @param The type of the effect value. - * @return The strength. - */ - @Nullable - public T getEffectStrength(@NotNull final Effect effect) { - return (T) effects.get(effect); - } - - /** - * Get effect strength of effect on advanced armor. - * - * @param effect The effect to query. - * @param The type of the effect value. - * @return The strength. - */ - @Nullable - public T getAdvancedEffectStrength(@NotNull final Effect effect) { - Object strength = advancedEffects.get(effect); - if (strength instanceof Integer) { - if (effect.getTypeClass().equals(Double.class)) { - strength = (double) (int) strength; - } - } - - return (T) strength; - } - @Override public boolean equals(final Object o) { if (this == o) { diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/sets/util/ArmorUtils.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/sets/util/ArmorUtils.java index 4285cf3..68f6816 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/sets/util/ArmorUtils.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoarmor/sets/util/ArmorUtils.java @@ -1,14 +1,12 @@ package com.willfp.ecoarmor.sets.util; import com.willfp.ecoarmor.EcoArmorPlugin; -import com.willfp.ecoarmor.conditions.Condition; import com.willfp.ecoarmor.sets.ArmorSet; import com.willfp.ecoarmor.sets.ArmorSets; import com.willfp.ecoarmor.sets.meta.ArmorSlot; import com.willfp.ecoarmor.upgrades.Tier; import com.willfp.ecoarmor.upgrades.Tiers; import lombok.experimental.UtilityClass; -import org.bukkit.Bukkit; import org.bukkit.attribute.Attribute; import org.bukkit.attribute.AttributeModifier; import org.bukkit.entity.Player; @@ -21,7 +19,6 @@ import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; -import java.util.Map; import java.util.UUID; @UtilityClass @@ -109,27 +106,6 @@ public class ArmorUtils { return null; } - /** - * Get if all conditions are met for a player. - * - * @param player The player. - * @return If conditions are men. - */ - public boolean areConditionsMet(@NotNull final Player player) { - ArmorSet set = getSetOnPlayer(player); - if (set == null) { - return true; - } - - for (Map.Entry, Object> entry : set.getConditions().entrySet()) { - if (!entry.getKey().isMet(player, entry.getValue())) { - return false; - } - } - - return true; - } - /** * Get tier on upgrade crystal. *