From 931d35495a3450fbf6c9d6b509ee6396b82ecf73 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Mon, 28 Dec 2020 16:31:03 +0000 Subject: [PATCH] Improved codestyle (10/?) --- .../eco/core/proxy/v1_15_R1/TridentStack.java | 2 +- .../eco/core/proxy/v1_16_R1/TridentStack.java | 2 +- .../eco/core/proxy/v1_16_R2/TridentStack.java | 2 +- .../eco/core/proxy/v1_16_R3/TridentStack.java | 2 +- .../ecoenchants/config/configs/Target.java | 7 +- .../options/sorting/SorterManager.java | 25 +- .../ecoenchants/artifact/SmokeArtifact.java | 2 +- .../ecoenchants/artifact/SoulArtifact.java | 2 +- .../artifact/SoulFireArtifact.java | 2 +- .../ecoenchants/artifact/SparkleArtifact.java | 2 +- .../ecoenchants/artifact/TotemArtifact.java | 2 +- .../ecoenchants/artifact/WarpedArtifact.java | 2 +- .../ecoenchants/artifact/WaterArtifact.java | 2 +- .../ecoenchants/artifact/WitchArtifact.java | 2 +- .../ecoenchants/artifact/ZapArtifact.java | 2 +- .../ecoenchants/normal/ShotAssist.java | 38 +- .../ecoenchants/normal/Sickening.java | 9 +- .../ecoenchants/normal/Slaughter.java | 10 +- .../ecoenchants/normal/Slicing.java | 18 +- .../ecoenchants/normal/Spearfishing.java | 30 +- .../ecoenchants/normal/Spiked.java | 27 +- .../ecoenchants/normal/Splash.java | 44 +- .../enchantments/ecoenchants/normal/Stab.java | 5 +- .../ecoenchants/normal/Stalwart.java | 7 +- .../ecoenchants/normal/Stamina.java | 29 +- .../ecoenchants/normal/StoneSwitcher.java | 21 +- .../ecoenchants/normal/StrayAspect.java | 13 +- .../ecoenchants/normal/Succession.java | 9 +- .../ecoenchants/normal/Supercritical.java | 12 +- .../ecoenchants/normal/Sycophant.java | 5 +- .../ecoenchants/normal/Tectonic.java | 18 +- .../ecoenchants/normal/Telekinesis.java | 94 +++- .../enchantments/ecoenchants/normal/Thor.java | 12 +- .../ecoenchants/normal/Thrive.java | 14 +- .../ecoenchants/normal/Tornado.java | 9 +- .../ecoenchants/normal/Toxic.java | 12 +- .../ecoenchants/normal/Transfuse.java | 24 +- .../ecoenchants/normal/Tripleshot.java | 11 +- .../ecoenchants/normal/VampireAspect.java | 12 +- .../enchantments/ecoenchants/normal/Vein.java | 19 +- .../ecoenchants/normal/Venom.java | 9 +- .../ecoenchants/normal/VoidAffinity.java | 9 +- .../ecoenchants/normal/Voltage.java | 31 +- .../ecoenchants/normal/WaterAffinity.java | 8 +- .../ecoenchants/normal/WaterAspect.java | 8 +- .../ecoenchants/normal/Weakening.java | 17 +- .../ecoenchants/normal/Wisdom.java | 16 +- .../ecoenchants/normal/Wound.java | 13 +- .../enchantments/ecoenchants/normal/Zeus.java | 9 +- .../ecoenchants/special/Soulbound.java | 45 +- .../ecoenchants/special/Spring.java | 8 +- .../ecoenchants/special/Streamlining.java | 6 +- .../ecoenchants/special/Volatile.java | 22 +- .../ecoenchants/spell/Vitalize.java | 4 +- .../enchantments/itemtypes/Spell.java | 4 +- .../support/obtaining/VillagerListeners.java | 83 ++- .../enchantments/util/SpellRunnable.java | 7 +- .../enchantments/util/WatcherTriggers.java | 477 +++++++++++++----- .../worldguard/WorldguardManager.java | 41 +- .../plugins/WorldguardIntegrationImpl.java | 18 +- .../core/proxy/proxies/TridentStackProxy.java | 3 +- .../biomes/enchants/defensive/Tropical.java | 2 +- .../SprintArtifactsListener.java | 33 +- .../summoning/SummoningEnchantment.java | 99 ++-- .../java/com/willfp/eco/util/StringUtils.java | 12 +- 65 files changed, 1091 insertions(+), 453 deletions(-) diff --git a/eco-core/core-nms/v1_15_R1/src/main/java/com/willfp/eco/core/proxy/v1_15_R1/TridentStack.java b/eco-core/core-nms/v1_15_R1/src/main/java/com/willfp/eco/core/proxy/v1_15_R1/TridentStack.java index 72365bdb..04337810 100644 --- a/eco-core/core-nms/v1_15_R1/src/main/java/com/willfp/eco/core/proxy/v1_15_R1/TridentStack.java +++ b/eco-core/core-nms/v1_15_R1/src/main/java/com/willfp/eco/core/proxy/v1_15_R1/TridentStack.java @@ -14,4 +14,4 @@ public final class TridentStack implements TridentStackProxy { EntityThrownTrident t = ((CraftTrident) trident).getHandle(); return CraftItemStack.asBukkitCopy(t.trident); } -} \ No newline at end of file +} diff --git a/eco-core/core-nms/v1_16_R1/src/main/java/com/willfp/eco/core/proxy/v1_16_R1/TridentStack.java b/eco-core/core-nms/v1_16_R1/src/main/java/com/willfp/eco/core/proxy/v1_16_R1/TridentStack.java index 419cf2fd..8080d45a 100644 --- a/eco-core/core-nms/v1_16_R1/src/main/java/com/willfp/eco/core/proxy/v1_16_R1/TridentStack.java +++ b/eco-core/core-nms/v1_16_R1/src/main/java/com/willfp/eco/core/proxy/v1_16_R1/TridentStack.java @@ -14,4 +14,4 @@ public final class TridentStack implements TridentStackProxy { EntityThrownTrident t = ((CraftTrident) trident).getHandle(); return CraftItemStack.asBukkitCopy(t.trident); } -} \ No newline at end of file +} diff --git a/eco-core/core-nms/v1_16_R2/src/main/java/com/willfp/eco/core/proxy/v1_16_R2/TridentStack.java b/eco-core/core-nms/v1_16_R2/src/main/java/com/willfp/eco/core/proxy/v1_16_R2/TridentStack.java index c0fcd974..e1e55bf3 100644 --- a/eco-core/core-nms/v1_16_R2/src/main/java/com/willfp/eco/core/proxy/v1_16_R2/TridentStack.java +++ b/eco-core/core-nms/v1_16_R2/src/main/java/com/willfp/eco/core/proxy/v1_16_R2/TridentStack.java @@ -14,4 +14,4 @@ public final class TridentStack implements TridentStackProxy { EntityThrownTrident t = ((CraftTrident) trident).getHandle(); return CraftItemStack.asBukkitCopy(t.trident); } -} \ No newline at end of file +} diff --git a/eco-core/core-nms/v1_16_R3/src/main/java/com/willfp/eco/core/proxy/v1_16_R3/TridentStack.java b/eco-core/core-nms/v1_16_R3/src/main/java/com/willfp/eco/core/proxy/v1_16_R3/TridentStack.java index 7bf5f4b6..5af20aa2 100644 --- a/eco-core/core-nms/v1_16_R3/src/main/java/com/willfp/eco/core/proxy/v1_16_R3/TridentStack.java +++ b/eco-core/core-nms/v1_16_R3/src/main/java/com/willfp/eco/core/proxy/v1_16_R3/TridentStack.java @@ -14,4 +14,4 @@ public final class TridentStack implements TridentStackProxy { EntityThrownTrident t = ((CraftTrident) trident).getHandle(); return CraftItemStack.asBukkitCopy(t.trident); } -} \ No newline at end of file +} diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/config/configs/Target.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/config/configs/Target.java index 9c241a5a..2677d3cc 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/config/configs/Target.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/config/configs/Target.java @@ -2,6 +2,7 @@ package com.willfp.ecoenchants.config.configs; import com.willfp.eco.util.config.BaseConfig; import org.bukkit.Material; +import org.jetbrains.annotations.NotNull; import java.util.HashSet; import java.util.Set; @@ -15,12 +16,12 @@ public class Target extends BaseConfig { } public Set getTargets() { - return config.getConfigurationSection("targets").getKeys(false); + return this.getConfig().getConfigurationSection("targets").getKeys(false); } - public Set getTargetMaterials(String target) { + public Set getTargetMaterials(@NotNull final String target) { Set materials = new HashSet<>(); - config.getStringList("targets." + target).forEach((materialName) -> { + this.getConfig().getStringList("targets." + target).forEach((materialName) -> { materials.add(Material.getMaterial(materialName.toUpperCase())); }); diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/sorting/SorterManager.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/sorting/SorterManager.java index 07b3ad22..7f67f88e 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/sorting/SorterManager.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/display/options/sorting/SorterManager.java @@ -8,29 +8,32 @@ import com.willfp.ecoenchants.display.options.sorting.implementations.RarityType import com.willfp.ecoenchants.display.options.sorting.implementations.RarityTypeLengthSorter; import com.willfp.ecoenchants.display.options.sorting.implementations.TypeAlphabeticSorter; import com.willfp.ecoenchants.display.options.sorting.implementations.TypeLengthSorter; +import lombok.experimental.UtilityClass; +import org.jetbrains.annotations.NotNull; import java.util.Arrays; import java.util.HashSet; import java.util.Set; +@UtilityClass public class SorterManager { - private static final Set values = new HashSet<>(); + private static final Set REGISTERED = new HashSet<>(); - public static EnchantmentSorter getSorter(SortParameters... parameters) { - return values.stream() + public static EnchantmentSorter getSorter(@NotNull final SortParameters... parameters) { + return REGISTERED.stream() .filter(enchantmentSorter -> Arrays.asList(enchantmentSorter.getParameters()).containsAll(Arrays.asList(parameters)) && enchantmentSorter.getParameters().length == parameters.length) .findFirst() .orElse(new AlphabeticSorter()); } static { - values.add(new AlphabeticSorter()); - values.add(new LengthSorter()); - values.add(new TypeAlphabeticSorter()); - values.add(new TypeLengthSorter()); - values.add(new RarityAlphabeticSorter()); - values.add(new RarityLengthSorter()); - values.add(new RarityTypeAlphabeticSorter()); - values.add(new RarityTypeLengthSorter()); + REGISTERED.add(new AlphabeticSorter()); + REGISTERED.add(new LengthSorter()); + REGISTERED.add(new TypeAlphabeticSorter()); + REGISTERED.add(new TypeLengthSorter()); + REGISTERED.add(new RarityAlphabeticSorter()); + REGISTERED.add(new RarityLengthSorter()); + REGISTERED.add(new RarityTypeAlphabeticSorter()); + REGISTERED.add(new RarityTypeLengthSorter()); } } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/SmokeArtifact.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/SmokeArtifact.java index 16881cd8..5daffb07 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/SmokeArtifact.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/SmokeArtifact.java @@ -13,4 +13,4 @@ public class SmokeArtifact extends Artifact { public Particle getParticle() { return Particle.CAMPFIRE_COSY_SMOKE; } -} \ No newline at end of file +} diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/SoulArtifact.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/SoulArtifact.java index 7232011b..0db4975b 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/SoulArtifact.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/SoulArtifact.java @@ -16,4 +16,4 @@ public class SoulArtifact extends Artifact { public Particle getParticle() { return Particle.SOUL; } -} \ No newline at end of file +} diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/SoulFireArtifact.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/SoulFireArtifact.java index 80b99ae0..dc6a5af2 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/SoulFireArtifact.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/SoulFireArtifact.java @@ -16,4 +16,4 @@ public class SoulFireArtifact extends Artifact { public Particle getParticle() { return Particle.SOUL_FIRE_FLAME; } -} \ No newline at end of file +} diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/SparkleArtifact.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/SparkleArtifact.java index 53deb656..faf8d825 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/SparkleArtifact.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/SparkleArtifact.java @@ -13,4 +13,4 @@ public class SparkleArtifact extends Artifact { public Particle getParticle() { return Particle.FIREWORKS_SPARK; } -} \ No newline at end of file +} diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/TotemArtifact.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/TotemArtifact.java index b21dad79..7d70809d 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/TotemArtifact.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/TotemArtifact.java @@ -13,4 +13,4 @@ public class TotemArtifact extends Artifact { public Particle getParticle() { return Particle.TOTEM; } -} \ No newline at end of file +} diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/WarpedArtifact.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/WarpedArtifact.java index 6f160b64..ab6367c5 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/WarpedArtifact.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/WarpedArtifact.java @@ -16,4 +16,4 @@ public class WarpedArtifact extends Artifact { public Particle getParticle() { return Particle.WARPED_SPORE; } -} \ No newline at end of file +} diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/WaterArtifact.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/WaterArtifact.java index 68b59612..a82dce6b 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/WaterArtifact.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/WaterArtifact.java @@ -13,4 +13,4 @@ public class WaterArtifact extends Artifact { public Particle getParticle() { return Particle.DRIP_WATER; } -} \ No newline at end of file +} diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/WitchArtifact.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/WitchArtifact.java index 9e343aa6..11058963 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/WitchArtifact.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/WitchArtifact.java @@ -13,4 +13,4 @@ public class WitchArtifact extends Artifact { public Particle getParticle() { return Particle.SPELL_WITCH; } -} \ No newline at end of file +} diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/ZapArtifact.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/ZapArtifact.java index 9b1aa4ad..ee4a7112 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/ZapArtifact.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/artifact/ZapArtifact.java @@ -19,4 +19,4 @@ public class ZapArtifact extends Artifact { public Particle.DustOptions getDustOptions() { return new Particle.DustOptions(Color.YELLOW, 1.0f); } -} \ No newline at end of file +} diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/ShotAssist.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/ShotAssist.java index 6215944e..40fbb1ee 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/ShotAssist.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/ShotAssist.java @@ -9,30 +9,46 @@ import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.entity.EntityDamageByEntityEvent; +import org.jetbrains.annotations.NotNull; + public class ShotAssist extends EcoEnchant { public ShotAssist() { super( "shot_assist", EnchantmentType.NORMAL ); } - @EventHandler - public void onHit(EntityDamageByEntityEvent event) { - if (!(event.getDamager() instanceof Arrow)) - return; - if(!(((Arrow) event.getDamager()).getShooter() instanceof Player)) - return; - if (!(event.getEntity() instanceof LivingEntity)) - return; - if(event.isCancelled()) return; + @EventHandler + public void onHit(@NotNull final EntityDamageByEntityEvent event) { + if (!(event.getDamager() instanceof Arrow)) { + return; + } + + if (!(((Arrow) event.getDamager()).getShooter() instanceof Player)) { + return; + } + + if (!(event.getEntity() instanceof LivingEntity)) { + return; + } + + if (event.isCancelled()) { + return; + } Player player = (Player) ((Arrow) event.getDamager()).getShooter(); + assert player != null; + int points = EnchantChecks.getArmorPoints(player, this, 0); - if(this.getDisabledWorlds().contains(player.getWorld())) return; + if (this.getDisabledWorlds().contains(player.getWorld())) { + return; + } - if(points == 0) return; + if (points == 0) { + return; + } double damage = event.getDamage(); double multiplier = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "multiplier"); diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Sickening.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Sickening.java index b0963020..85d3b246 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Sickening.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Sickening.java @@ -20,9 +20,14 @@ public class Sickening extends EcoEnchant { } @Override - public void onArrowDamage(@NotNull LivingEntity attacker, @NotNull LivingEntity victim, @NotNull Arrow arrow, int level, @NotNull EntityDamageByEntityEvent event) { - if(!EnchantmentUtils.passedChance(this, level)) + public void onArrowDamage(@NotNull final LivingEntity attacker, + @NotNull final LivingEntity victim, + @NotNull final Arrow arrow, + final int level, + @NotNull final EntityDamageByEntityEvent event) { + if (!EnchantmentUtils.passedChance(this, level)) { return; + } int duration = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "duration-per-level"); diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Slaughter.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Slaughter.java index 2f62eaa3..04d8d90d 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Slaughter.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Slaughter.java @@ -17,8 +17,14 @@ public class Slaughter extends EcoEnchant { } @Override - public void onArrowDamage(@NotNull LivingEntity attacker, @NotNull LivingEntity victim, @NotNull Arrow arrow, int level, @NotNull EntityDamageByEntityEvent event) { - if(victim instanceof Monster) return; + public void onArrowDamage(@NotNull final LivingEntity attacker, + @NotNull final LivingEntity victim, + @NotNull final Arrow arrow, + final int level, + @NotNull final EntityDamageByEntityEvent event) { + if (victim instanceof Monster) { + return; + } double damage = event.getDamage(); double multiplier = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "multiplier"); diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Slicing.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Slicing.java index 0b7dcd9b..b824bbfc 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Slicing.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Slicing.java @@ -11,6 +11,7 @@ import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.player.PlayerMoveEvent; +import org.jetbrains.annotations.NotNull; import java.util.ArrayList; public class Slicing extends EcoEnchant { @@ -22,14 +23,20 @@ public class Slicing extends EcoEnchant { private final ArrayList entities = new ArrayList<>(); @EventHandler - public void onPlayerCollide(PlayerMoveEvent event) { + public void onPlayerCollide(@NotNull final PlayerMoveEvent event) { Player player = event.getPlayer(); - if (!player.isGliding()) + if (!player.isGliding()) { return; + } - if (!EnchantChecks.chestplate(player, this)) return; - if(this.getDisabledWorlds().contains(player.getWorld())) return; + if (!EnchantChecks.chestplate(player, this)) { + return; + } + + if (this.getDisabledWorlds().contains(player.getWorld())) { + return; + } for (Entity entity : player.getNearbyEntities(1, 1, 1)) { LivingEntity victim; @@ -39,8 +46,9 @@ public class Slicing extends EcoEnchant { continue; } - if (entities.contains(victim)) + if (entities.contains(victim)) { continue; + } double damage = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "damage-per-level"); int level = EnchantChecks.getMainhandLevel(player, this); diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Spearfishing.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Spearfishing.java index f4da8253..717955c0 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Spearfishing.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Spearfishing.java @@ -16,6 +16,7 @@ import org.bukkit.entity.Trident; import org.bukkit.event.EventHandler; import org.bukkit.event.entity.ProjectileHitEvent; import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.Collections; @@ -27,31 +28,44 @@ public class Spearfishing extends EcoEnchant { "spearfishing", EnchantmentType.NORMAL ); } + @EventHandler - public void onSpearfishingLand(ProjectileHitEvent event) { - if (event.getEntityType() != EntityType.TRIDENT) + public void onSpearfishingLand(@NotNull final ProjectileHitEvent event) { + if (event.getEntityType() != EntityType.TRIDENT) { return; + } - if (!(event.getEntity().getShooter() instanceof Player)) + if (!(event.getEntity().getShooter() instanceof Player)) { return; + } - if (!(event.getEntity() instanceof Trident)) return; + if (!(event.getEntity() instanceof Trident)) { + return; + } Trident trident = (Trident) event.getEntity(); - if(!trident.getWorld().getBlockAt(trident.getLocation().add(0, 0.2, 0)).getType().equals(Material.WATER)) + if (!trident.getWorld().getBlockAt(trident.getLocation().add(0, 0.2, 0)).getType().equals(Material.WATER)) { return; + } Player player = (Player) event.getEntity().getShooter(); - if(this.getDisabledWorlds().contains(player.getWorld())) return; + + if (this.getDisabledWorlds().contains(player.getWorld())) { + return; + } ItemStack item = ProxyUtils.getProxy(TridentStackProxy.class).getTridentStack(trident); - if (!EnchantChecks.item(item, this)) return; + if (!EnchantChecks.item(item, this)) { + return; + } int level = EnchantChecks.getItemLevel(item, this); - if(!EnchantmentUtils.passedChance(this, level)) + + if (!EnchantmentUtils.passedChance(this, level)) { return; + } List potentialDrops = new ArrayList<>(); this.getConfig().getStrings(EcoEnchants.CONFIG_LOCATION + "drops").forEach(material -> { diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Spiked.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Spiked.java index 419ce38d..3b6cee74 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Spiked.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Spiked.java @@ -9,6 +9,8 @@ import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.player.PlayerFishEvent; +import org.jetbrains.annotations.NotNull; + public class Spiked extends EcoEnchant { public Spiked() { super( @@ -16,23 +18,34 @@ public class Spiked extends EcoEnchant { ); } @EventHandler - public void onFish(PlayerFishEvent event) { - if(!event.getState().equals(PlayerFishEvent.State.CAUGHT_ENTITY)) + public void onFish(@NotNull final PlayerFishEvent event) { + if (!event.getState().equals(PlayerFishEvent.State.CAUGHT_ENTITY)) { return; + } - if(!(event.getCaught() instanceof LivingEntity)) + if (!(event.getCaught() instanceof LivingEntity)) { return; + } Player player = event.getPlayer(); LivingEntity victim = (LivingEntity) event.getCaught(); - if(victim.hasMetadata("NPC")) return; + if (victim.hasMetadata("NPC")) { + return; + } - if(!AntigriefManager.canInjure(player, victim)) return; + if (!AntigriefManager.canInjure(player, victim)) { + return; + } - if (!EnchantChecks.mainhand(player, this)) return; - if(this.getDisabledWorlds().contains(player.getWorld())) return; + if (!EnchantChecks.mainhand(player, this)) { + return; + } + + if (this.getDisabledWorlds().contains(player.getWorld())) { + return; + } int level = EnchantChecks.getMainhandLevel(player, this); diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Splash.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Splash.java index 76c9162b..f61011d3 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Splash.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Splash.java @@ -18,6 +18,8 @@ import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageEvent; import org.bukkit.event.entity.ProjectileHitEvent; import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.NotNull; + public class Splash extends EcoEnchant { public Splash() { super( @@ -25,14 +27,18 @@ public class Splash extends EcoEnchant { ); } @EventHandler - public void onSplashLand(ProjectileHitEvent event) { - if (event.getEntityType() != EntityType.TRIDENT) + public void onSplashLand(@NotNull final ProjectileHitEvent event) { + if (event.getEntityType() != EntityType.TRIDENT) { return; + } - if (!(event.getEntity().getShooter() instanceof Player)) + if (!(event.getEntity().getShooter() instanceof Player)) { return; + } - if (!(event.getEntity() instanceof Trident)) return; + if (!(event.getEntity() instanceof Trident)) { + return; + } @@ -41,8 +47,13 @@ public class Splash extends EcoEnchant { ItemStack item = ProxyUtils.getProxy(TridentStackProxy.class).getTridentStack(trident); - if (!EnchantChecks.item(item, this)) return; - if(this.getDisabledWorlds().contains(player.getWorld())) return; + if (!EnchantChecks.item(item, this)) { + return; + } + + if (this.getDisabledWorlds().contains(player.getWorld())) { + return; + } int level = EnchantChecks.getItemLevel(item, this); @@ -50,16 +61,27 @@ public class Splash extends EcoEnchant { double damage = level * this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "damage-per-level"); for (Entity e : trident.getNearbyEntities(radius, radius, radius)) { - if(e.hasMetadata("NPC")) continue; + if (e.hasMetadata("NPC")) { + continue; + } + + if (!(e instanceof LivingEntity)) { + continue; + } - if (!(e instanceof LivingEntity)) continue; LivingEntity entity = (LivingEntity) e; - if(e.equals(player)) continue; + + if (e.equals(player)) { + continue; + } Bukkit.getPluginManager().callEvent(new EntityDamageByEntityEvent(trident, entity, EntityDamageEvent.DamageCause.ENTITY_ATTACK, damage)); - if(!AntigriefManager.canInjure(player, entity)) continue; + if (!AntigriefManager.canInjure(player, entity)) { + continue; + } + entity.damage(damage, trident); } } -} \ No newline at end of file +} diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Stab.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Stab.java index b5907c5b..d1a15d96 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Stab.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Stab.java @@ -15,7 +15,10 @@ public class Stab extends EcoEnchant { } @Override - public void onMeleeAttack(@NotNull LivingEntity attacker, @NotNull LivingEntity victim, int level, @NotNull EntityDamageByEntityEvent event) { + public void onMeleeAttack(@NotNull final LivingEntity attacker, + @NotNull final LivingEntity victim, + final int level, + @NotNull final EntityDamageByEntityEvent event) { double baseDamage = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "damage-base"); double perLevelDamage = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "damage-per-level"); double damage = baseDamage + (level * perLevelDamage); diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Stalwart.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Stalwart.java index 205062e4..d99a0e96 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Stalwart.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Stalwart.java @@ -18,9 +18,12 @@ public class Stalwart extends EcoEnchant { } @Override - public void onDamageWearingArmor(@NotNull LivingEntity victim, int level, @NotNull EntityDamageEvent event) { - if(!EnchantmentUtils.passedChance(this, level)) + public void onDamageWearingArmor(@NotNull final LivingEntity victim, + final int level, + @NotNull final EntityDamageEvent event) { + if (!EnchantmentUtils.passedChance(this, level)) { return; + } int duration = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "duration-per-level"); duration *= level; diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Stamina.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Stamina.java index c03dde20..38bf285b 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Stamina.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Stamina.java @@ -7,6 +7,8 @@ import com.willfp.ecoenchants.enchantments.util.EnchantmentUtils; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.entity.FoodLevelChangeEvent; +import org.jetbrains.annotations.NotNull; + public class Stamina extends EcoEnchant { public Stamina() { super( @@ -14,21 +16,34 @@ public class Stamina extends EcoEnchant { ); } @EventHandler - public void onStaminaHunger(FoodLevelChangeEvent event) { - if (!(event.getEntity() instanceof Player)) + public void onStaminaHunger(@NotNull final FoodLevelChangeEvent event) { + if (!(event.getEntity() instanceof Player)) { return; + } Player player = (Player) event.getEntity(); - if(!player.isSprinting()) return; + if (!player.isSprinting()) { + return; + } - if(!EnchantChecks.boots(player, this)) return; - if(this.getDisabledWorlds().contains(player.getWorld())) return; - if(event.getFoodLevel() > player.getFoodLevel()) return; + if (!EnchantChecks.boots(player, this)) { + return; + } + + if (this.getDisabledWorlds().contains(player.getWorld())) { + return; + } + + if (event.getFoodLevel() > player.getFoodLevel()) { + return; + } int level = EnchantChecks.getBootsLevel(player, this); - if(!EnchantmentUtils.passedChance(this, level)) + + if (!EnchantmentUtils.passedChance(this, level)) { return; + } event.setCancelled(true); } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/StoneSwitcher.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/StoneSwitcher.java index 4cad25fd..84900daa 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/StoneSwitcher.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/StoneSwitcher.java @@ -22,13 +22,21 @@ public class StoneSwitcher extends EcoEnchant { } @Override - public void onBlockBreak(@NotNull Player player, @NotNull Block block, int level, @NotNull BlockBreakEvent event) { - if (player.getGameMode() == GameMode.CREATIVE || player.getGameMode() == GameMode.SPECTATOR) + public void onBlockBreak(@NotNull final Player player, + @NotNull final Block block, + final int level, + @NotNull final BlockBreakEvent event) { + if (player.getGameMode() == GameMode.CREATIVE || player.getGameMode() == GameMode.SPECTATOR) { return; + } - if(!block.getType().equals(Material.STONE)) return; - if(!EnchantmentUtils.passedChance(this, level)) + if (!block.getType().equals(Material.STONE)) { return; + } + + if (!EnchantmentUtils.passedChance(this, level)) { + return; + } event.setDropItems(false); @@ -39,7 +47,10 @@ public class StoneSwitcher extends EcoEnchant { selectedIndex = NumberUtils.equalIfOver(selectedIndex, this.getConfig().getStrings(EcoEnchants.CONFIG_LOCATION + "blocks").size() - 1); String materialName = this.getConfig().getStrings(EcoEnchants.CONFIG_LOCATION + "blocks").get(selectedIndex); material = Material.getMaterial(materialName.toUpperCase()); - if(material == null) material = Material.COBBLESTONE; + + if (material == null) { + material = Material.COBBLESTONE; + } ItemStack item = new ItemStack(material, 1); diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/StrayAspect.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/StrayAspect.java index 928d75c8..83209b2c 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/StrayAspect.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/StrayAspect.java @@ -21,12 +21,19 @@ public class StrayAspect extends EcoEnchant { } @Override - public void onMeleeAttack(@NotNull LivingEntity attacker, @NotNull LivingEntity victim, int level, @NotNull EntityDamageByEntityEvent event) { - if(attacker instanceof Player && ProxyUtils.getProxy(CooldownProxy.class).getAttackCooldown((Player) attacker) != 1.0f && !this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "allow-not-fully-charged")) { + public void onMeleeAttack(@NotNull final LivingEntity attacker, + @NotNull final LivingEntity victim, + final int level, + @NotNull final EntityDamageByEntityEvent event) { + if (attacker instanceof Player + && ProxyUtils.getProxy(CooldownProxy.class).getAttackCooldown((Player) attacker) != 1.0f + && !this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "allow-not-fully-charged")) { return; } - if(!EnchantmentUtils.passedChance(this, level)) + + if (!EnchantmentUtils.passedChance(this, level)) { return; + } int ticksPerLevel = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "ticks-per-level"); diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Succession.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Succession.java index 29a33e4e..f3610f98 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Succession.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Succession.java @@ -21,7 +21,10 @@ public class Succession extends EcoEnchant { } @Override - public void onBowShoot(@NotNull LivingEntity shooter, @NotNull Arrow arrow, int level, @NotNull EntityShootBowEvent event) { + public void onBowShoot(@NotNull final LivingEntity shooter, + @NotNull final Arrow arrow, + final int level, + @NotNull final EntityShootBowEvent event) { int number = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "extra-arrows"); boolean fire = EnchantChecks.mainhand(shooter, Enchantment.ARROW_FIRE); @@ -30,7 +33,9 @@ public class Succession extends EcoEnchant { this.getPlugin().getScheduler().runLater(() -> { Arrow arrow1 = shooter.launchProjectile(Arrow.class, event.getProjectile().getVelocity()); arrow1.setPickupStatus(AbstractArrow.PickupStatus.DISALLOWED); - if(fire) arrow1.setFireTicks(Integer.MAX_VALUE); + if (fire) { + arrow1.setFireTicks(Integer.MAX_VALUE); + } if (this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "per-arrow-damage") && shooter instanceof Player) { DurabilityUtils.damageItem((Player) shooter, ((Player) shooter).getInventory().getItemInMainHand(), 1, ((Player) shooter).getInventory().getHeldItemSlot()); diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Supercritical.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Supercritical.java index b39ca1dd..e51520fc 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Supercritical.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Supercritical.java @@ -19,13 +19,19 @@ public class Supercritical extends EcoEnchant { } @Override - public void onMeleeAttack(@NotNull LivingEntity attacker, @NotNull LivingEntity victim, int level, @NotNull EntityDamageByEntityEvent event) { - if(attacker instanceof Player && ProxyUtils.getProxy(CooldownProxy.class).getAttackCooldown((Player) attacker) != 1.0f && !this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "allow-not-fully-charged")) { + public void onMeleeAttack(@NotNull final LivingEntity attacker, + @NotNull final LivingEntity victim, + final int level, + @NotNull final EntityDamageByEntityEvent event) { + if (attacker instanceof Player + && ProxyUtils.getProxy(CooldownProxy.class).getAttackCooldown((Player) attacker) != 1.0f + && !this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "allow-not-fully-charged")) { return; } - if(!EnchantmentUtils.passedChance(this, level)) + if (!EnchantmentUtils.passedChance(this, level)) { return; + } event.setDamage(event.getDamage() * this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "damage-multiplier")); } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Sycophant.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Sycophant.java index 2dc2eee7..af5fb9e3 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Sycophant.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Sycophant.java @@ -17,7 +17,10 @@ public class Sycophant extends EcoEnchant { } @Override - public void onDeflect(@NotNull Player blocker, @NotNull LivingEntity attacker, int level, @NotNull EntityDamageByEntityEvent event) { + public void onDeflect(@NotNull final Player blocker, + @NotNull final LivingEntity attacker, + final int level, + @NotNull final EntityDamageByEntityEvent event) { double multiplier = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "health-per-level"); double amountToHeal = level * multiplier; double newHealth = attacker.getHealth() + amountToHeal; diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Tectonic.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Tectonic.java index 5ee8f3ad..be4d121b 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Tectonic.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Tectonic.java @@ -19,10 +19,14 @@ public class Tectonic extends EcoEnchant { } @Override - public void onFallDamage(@NotNull LivingEntity faller, int level, @NotNull EntityDamageEvent event) { + public void onFallDamage(@NotNull final LivingEntity faller, + final int level, + @NotNull final EntityDamageEvent event) { - if (!event.getCause().equals(EntityDamageEvent.DamageCause.FALL)) + if (!event.getCause().equals(EntityDamageEvent.DamageCause.FALL)) { return; + } + int radius = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "initial-radius") + (this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "per-level-radius") * level - 1); int damage = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "initial-damage") + (this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "per-level-damage") * level - 1); @@ -30,12 +34,16 @@ public class Tectonic extends EcoEnchant { Collection entities = faller.getWorld().getNearbyEntities(faller.getLocation(), radius, 2, radius); for (Entity entity : entities) { - if (entity.equals(faller)) + if (entity.equals(faller)) { continue; - if(!(entity instanceof LivingEntity)) continue; + } + if (!(entity instanceof LivingEntity)) { + continue; + } entity.teleport(entity.getLocation().add(0, 0.3, 0)); - if(faller instanceof Player && !AntigriefManager.canInjure((Player) faller, (LivingEntity) entity)) + if (faller instanceof Player && !AntigriefManager.canInjure((Player) faller, (LivingEntity) entity)) { return; + } ((LivingEntity) entity).damage(damage); } } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Telekinesis.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Telekinesis.java index 930088a0..b45bcf96 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Telekinesis.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Telekinesis.java @@ -24,6 +24,7 @@ import org.bukkit.event.EventPriority; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockDropItemEvent; import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.Collection; @@ -44,91 +45,130 @@ public class Telekinesis extends EcoEnchant { // For block drops @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true) - public void telekinesisDropItem(BlockDropItemEvent event) { + public void telekinesisDropItem(@NotNull final BlockDropItemEvent event) { Player player = event.getPlayer(); - if(!always && !EnchantChecks.mainhand(player, this)) return; - if(this.getDisabledWorldNames().contains(player.getWorld().getName())) return; + if (!always && !EnchantChecks.mainhand(player, this)) { + return; + } - if (event.isCancelled()) return; + if (this.getDisabledWorldNames().contains(player.getWorld().getName())) { + return; + } + + if (event.isCancelled()) { + return; + } Block block = event.getBlock(); - if (!AntigriefManager.canBreakBlock(player, block)) return; + if (!AntigriefManager.canBreakBlock(player, block)) { + return; + } List drops = new ArrayList<>(); - for(Item item : event.getItems()) drops.add(item.getItemStack()); + + for (Item item : event.getItems()) { + drops.add(item.getItemStack()); + } event.getItems().clear(); DropQueue queue = new DropQueue(player) .setLocation(block.getLocation()) .addItems(drops); - if(!always) queue.forceTelekinesis(); + + if (!always) { + queue.forceTelekinesis(); + } + queue.push(); } // For exp drops, blockdropitemevent doesn't cover xp @EventHandler(priority = EventPriority.HIGH) - public void telekinesisBreak(BlockBreakEvent event) { + public void telekinesisBreak(@NotNull final BlockBreakEvent event) { Player player = event.getPlayer(); Block block = event.getBlock(); - if(!always && !EnchantChecks.mainhand(player, this)) return; - if(this.getDisabledWorlds().contains(player.getWorld())) return; - - if (player.getGameMode() == GameMode.CREATIVE || player.getGameMode() == GameMode.SPECTATOR) + if (!always && !EnchantChecks.mainhand(player, this)) { return; + } - if (event.isCancelled()) + if (this.getDisabledWorlds().contains(player.getWorld())) { return; + } - if (!AntigriefManager.canBreakBlock(player, block)) return; + if (player.getGameMode() == GameMode.CREATIVE || player.getGameMode() == GameMode.SPECTATOR) { + return; + } - if(block.getType().equals(Material.SPAWNER)) event.setExpToDrop(0); + if (event.isCancelled()) { + return; + } + + if (!AntigriefManager.canBreakBlock(player, block)) { + return; + } + + if (block.getType().equals(Material.SPAWNER)) { + event.setExpToDrop(0); + } DropQueue queue = new DropQueue(player) .setLocation(block.getLocation()) .addXP(event.getExpToDrop()); - if(!always) queue.forceTelekinesis(); + + if (!always) { + queue.forceTelekinesis(); + } + queue.push(); event.setExpToDrop(0); } @EventHandler(priority = EventPriority.HIGH) - public void telekinesisKill(EntityDeathByEntityEvent event) { + public void telekinesisKill(@NotNull final EntityDeathByEntityEvent event) { Player player = null; LivingEntity entity = event.getVictim(); ItemStack item = null; - if(entity instanceof Player && this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "not-on-players")) + if (entity instanceof Player && this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "not-on-players")) { return; + } - if(event.getKiller() instanceof Player) { + if (event.getKiller() instanceof Player) { player = (Player) event.getKiller(); item = player.getInventory().getItemInMainHand(); - } else if(event.getKiller() instanceof Arrow) { - if(((Arrow) event.getKiller()).getShooter() instanceof Player) { + } else if (event.getKiller() instanceof Arrow) { + if (((Arrow) event.getKiller()).getShooter() instanceof Player) { player = (Player) ((Arrow) event.getKiller()).getShooter(); item = player.getInventory().getItemInMainHand(); } - } else if(event.getKiller() instanceof Trident) { - if(((Trident) event.getKiller()).getShooter() instanceof Player) { + } else if (event.getKiller() instanceof Trident) { + if (((Trident) event.getKiller()).getShooter() instanceof Player) { player = (Player) ((Trident) event.getKiller()).getShooter(); item = ProxyUtils.getProxy(TridentStackProxy.class).getTridentStack((Trident) event.getKiller()); } } - if(player == null || item == null) return; + if (player == null || item == null) { + return; + } - if (!EnchantChecks.item(item, this)) return; - if(this.getDisabledWorlds().contains(player.getWorld())) return; + if (!EnchantChecks.item(item, this)) { + return; + } + + if (this.getDisabledWorlds().contains(player.getWorld())) { + return; + } int xp = event.getXp(); Collection drops = event.getDrops(); - if(entity instanceof Player && Soulbound.getSoulboundItems((Player) entity) != null) { + if (entity instanceof Player && Soulbound.getSoulboundItems((Player) entity) != null) { drops.removeAll(Soulbound.getSoulboundItems((Player) entity)); } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Thor.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Thor.java index 4159d2ab..d2e4de9b 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Thor.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Thor.java @@ -20,13 +20,19 @@ public class Thor extends EcoEnchant { } @Override - public void onMeleeAttack(@NotNull LivingEntity attacker, @NotNull LivingEntity victim, int level, @NotNull EntityDamageByEntityEvent event) { - if (attacker instanceof Player && ProxyUtils.getProxy(CooldownProxy.class).getAttackCooldown((Player) attacker) != 1.0f && !this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "allow-not-fully-charged")) { + public void onMeleeAttack(@NotNull final LivingEntity attacker, + @NotNull final LivingEntity victim, + final int level, + @NotNull final EntityDamageByEntityEvent event) { + if (attacker instanceof Player + && ProxyUtils.getProxy(CooldownProxy.class).getAttackCooldown((Player) attacker) != 1.0f + && !this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "allow-not-fully-charged")) { return; } - if (!EnchantmentUtils.passedChance(this, level)) + if (!EnchantmentUtils.passedChance(this, level)) { return; + } double damage = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "lightning-damage"); diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Thrive.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Thrive.java index 5a58f2f6..18388062 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Thrive.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Thrive.java @@ -10,6 +10,8 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; +import org.jetbrains.annotations.NotNull; + public class Thrive extends EcoEnchant { public Thrive() { super( @@ -17,25 +19,31 @@ public class Thrive extends EcoEnchant { ); } @EventHandler - public void onArmorEquip(ArmorEquipEvent event) { + public void onArmorEquip(@NotNull final ArmorEquipEvent event) { final Player player = event.getPlayer(); this.getPlugin().getScheduler().runLater(() -> { int totalProsperityPoints = EnchantChecks.getArmorPoints(player, EcoEnchants.PROSPERITY, 0); int totalThrivePoints = EnchantChecks.getArmorPoints(player, EcoEnchants.THRIVE, 0); + if (totalThrivePoints == 0 && totalProsperityPoints == 0) { player.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getDefaultValue()); return; } - if(EcoEnchants.THRIVE.getDisabledWorlds().contains(player.getWorld())) return; + + if (EcoEnchants.THRIVE.getDisabledWorlds().contains(player.getWorld())) { + return; + } double thriveBonus = totalThrivePoints * EcoEnchants.THRIVE.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "health-per-point"); double prosperityBonus = totalProsperityPoints * EcoEnchants.PROSPERITY.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "health-per-point"); double bonus = thriveBonus + prosperityBonus; boolean onMaxHealth = false; - if (player.getHealth() == player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()) + + if (player.getHealth() == player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()) { onMaxHealth = true; + } player.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getDefaultValue() + bonus); boolean finalOnMaxHealth = onMaxHealth; diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Tornado.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Tornado.java index 4bb553e3..a038668b 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Tornado.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Tornado.java @@ -16,14 +16,15 @@ public class Tornado extends EcoEnchant { } @Override - public void onMeleeAttack(@NotNull LivingEntity attacker, @NotNull LivingEntity victim, int level, @NotNull EntityDamageByEntityEvent event) { + public void onMeleeAttack(@NotNull final LivingEntity attacker, + @NotNull final LivingEntity victim, + final int level, + @NotNull final EntityDamageByEntityEvent event) { double baseVelocity = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "velocity-per-level"); double yVelocity = baseVelocity * level; Vector toAdd = new Vector(0, yVelocity, 0); - this.getPlugin().getScheduler().runLater(() -> { - victim.setVelocity(victim.getVelocity().clone().add(toAdd)); - }, 1); + this.getPlugin().getScheduler().runLater(() -> victim.setVelocity(victim.getVelocity().clone().add(toAdd)), 1); } } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Toxic.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Toxic.java index 36c09430..eec0a907 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Toxic.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Toxic.java @@ -21,13 +21,19 @@ public class Toxic extends EcoEnchant { } @Override - public void onMeleeAttack(@NotNull LivingEntity attacker, @NotNull LivingEntity victim, int level, @NotNull EntityDamageByEntityEvent event) { - if (attacker instanceof Player && ProxyUtils.getProxy(CooldownProxy.class).getAttackCooldown((Player) attacker) != 1.0f && !this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "allow-not-fully-charged")) { + public void onMeleeAttack(@NotNull final LivingEntity attacker, + @NotNull final LivingEntity victim, + final int level, + @NotNull final EntityDamageByEntityEvent event) { + if (attacker instanceof Player + && ProxyUtils.getProxy(CooldownProxy.class).getAttackCooldown((Player) attacker) != 1.0f + && !this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "allow-not-fully-charged")) { return; } - if (!EnchantmentUtils.passedChance(this, level)) + if (!EnchantmentUtils.passedChance(this, level)) { return; + } victim.addPotionEffect(new PotionEffect(PotionEffectType.POISON, level * 10 + 20, level)); } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Transfuse.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Transfuse.java index 5dde651e..72f82dda 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Transfuse.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Transfuse.java @@ -24,26 +24,36 @@ public class Transfuse extends EcoEnchant { } @Override - public void onBlockBreak(@NotNull Player player, @NotNull Block block, int level, @NotNull BlockBreakEvent event) { - if (player.getGameMode() == GameMode.CREATIVE || player.getGameMode() == GameMode.SPECTATOR) + public void onBlockBreak(@NotNull final Player player, + @NotNull final Block block, + final int level, + @NotNull final BlockBreakEvent event) { + if (player.getGameMode() == GameMode.CREATIVE || player.getGameMode() == GameMode.SPECTATOR) { return; + } - if(!EnchantmentUtils.passedChance(this, level)) + if (!EnchantmentUtils.passedChance(this, level)) { return; + } event.setDropItems(false); - if(!this.getConfig().getStrings(EcoEnchants.CONFIG_LOCATION + "works-on").stream().map(string -> Material.getMaterial(string.toUpperCase())).collect(Collectors.toList()).contains(block.getType())) + if (!this.getConfig().getStrings(EcoEnchants.CONFIG_LOCATION + "works-on").stream() + .map(string -> Material.getMaterial(string.toUpperCase())) + .collect(Collectors.toList()).contains(block.getType())) { return; + } Material material; double random = NumberUtils.randFloat(0, 1); - double band = 1/(double) this.getConfig().getStrings(EcoEnchants.CONFIG_LOCATION + "blocks").size(); - int selectedIndex = (int) Math.floor(random/band); + double band = 1 / (double) this.getConfig().getStrings(EcoEnchants.CONFIG_LOCATION + "blocks").size(); + int selectedIndex = (int) Math.floor(random / band); selectedIndex = NumberUtils.equalIfOver(selectedIndex, this.getConfig().getStrings(EcoEnchants.CONFIG_LOCATION + "blocks").size() - 1); String materialName = this.getConfig().getStrings(EcoEnchants.CONFIG_LOCATION + "blocks").get(selectedIndex); material = Material.getMaterial(materialName.toUpperCase()); - if(material == null) material = Material.COBBLESTONE; + if (material == null) { + material = Material.COBBLESTONE; + } ItemStack item = new ItemStack(material, 1); diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Tripleshot.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Tripleshot.java index be9d7f4b..2e86cf94 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Tripleshot.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Tripleshot.java @@ -20,17 +20,20 @@ public class Tripleshot extends EcoEnchant { } @Override - public void onBowShoot(@NotNull LivingEntity shooter, @NotNull Arrow arrow, int level, @NotNull EntityShootBowEvent event) { - + public void onBowShoot(@NotNull final LivingEntity shooter, + @NotNull final Arrow arrow, + final int level, + @NotNull final EntityShootBowEvent event) { for (int i = -1; i < 2; i += 2) { - Vector velocity = event.getProjectile().getVelocity(); float radians = (float) ((float) i * Math.toRadians(this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "angle"))); velocity.rotateAroundY(radians); Arrow arrow1 = shooter.launchProjectile(Arrow.class, velocity); - if(EnchantChecks.mainhand(shooter, Enchantment.ARROW_FIRE)) arrow1.setFireTicks(Integer.MAX_VALUE); + if (EnchantChecks.mainhand(shooter, Enchantment.ARROW_FIRE)) { + arrow1.setFireTicks(Integer.MAX_VALUE); + } arrow1.setPickupStatus(AbstractArrow.PickupStatus.DISALLOWED); } } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/VampireAspect.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/VampireAspect.java index a4b6f3fe..211b5ea6 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/VampireAspect.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/VampireAspect.java @@ -21,13 +21,19 @@ public class VampireAspect extends EcoEnchant { } @Override - public void onMeleeAttack(@NotNull LivingEntity attacker, @NotNull LivingEntity victim, int level, @NotNull EntityDamageByEntityEvent event) { - if(attacker instanceof Player && ProxyUtils.getProxy(CooldownProxy.class).getAttackCooldown((Player) attacker) != 1.0f && !this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "allow-not-fully-charged")) { + public void onMeleeAttack(@NotNull final LivingEntity attacker, + @NotNull final LivingEntity victim, + final int level, + @NotNull final EntityDamageByEntityEvent event) { + if (attacker instanceof Player + && ProxyUtils.getProxy(CooldownProxy.class).getAttackCooldown((Player) attacker) != 1.0f + && !this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "allow-not-fully-charged")) { return; } - if(!EnchantmentUtils.passedChance(this, level)) + if (!EnchantmentUtils.passedChance(this, level)) { return; + } victim.addPotionEffect(new PotionEffect(PotionEffectType.WITHER, level * 10 + 20, level)); } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Vein.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Vein.java index d4ce70a2..94713f9a 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Vein.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Vein.java @@ -27,17 +27,24 @@ public class Vein extends EcoEnchant { } @Override - public void onBlockBreak(@NotNull Player player, @NotNull Block block, int level, @NotNull BlockBreakEvent event) { - if (block.hasMetadata("block-ignore")) + public void onBlockBreak(@NotNull final Player player, + @NotNull final Block block, + final int level, + @NotNull final BlockBreakEvent event) { + if (block.hasMetadata("block-ignore")) { return; + } - if (player.isSneaking() && this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "disable-on-sneak")) return; + if (player.isSneaking() && this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "disable-on-sneak")) { + return; + } List materials = new ArrayList<>(); this.getConfig().getStrings(EcoEnchants.CONFIG_LOCATION + "whitelisted-blocks").forEach(name -> materials.add(Material.getMaterial(name.toUpperCase()))); - if (!materials.contains(block.getType())) + if (!materials.contains(block.getType())) { return; + } int blocksPerLevel = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "blocks-per-level"); int limit = level * blocksPerLevel; @@ -48,7 +55,9 @@ public class Vein extends EcoEnchant { for (Block veinBlock : blockSet) { veinBlock.setMetadata("block-ignore", new FixedMetadataValue(this.getPlugin(), true)); - if (!AntigriefManager.canBreakBlock(player, veinBlock)) continue; + if (!AntigriefManager.canBreakBlock(player, veinBlock)) { + continue; + } ProxyUtils.getProxy(BlockBreakProxy.class).breakBlock(player, veinBlock); diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Venom.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Venom.java index b118c0e0..db5c73d4 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Venom.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Venom.java @@ -18,9 +18,14 @@ public class Venom extends EcoEnchant { } @Override - public void onArrowDamage(@NotNull LivingEntity attacker, @NotNull LivingEntity victim, @NotNull Arrow arrow, int level, @NotNull EntityDamageByEntityEvent event) { - if (!EnchantmentUtils.passedChance(this, level)) + public void onArrowDamage(@NotNull final LivingEntity attacker, + @NotNull final LivingEntity victim, + @NotNull final Arrow arrow, + final int level, + @NotNull final EntityDamageByEntityEvent event) { + if (!EnchantmentUtils.passedChance(this, level)) { return; + } victim.addPotionEffect(new PotionEffect(PotionEffectType.WITHER, level * 10 + 20, level)); } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/VoidAffinity.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/VoidAffinity.java index a0f6f123..3c275127 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/VoidAffinity.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/VoidAffinity.java @@ -17,9 +17,14 @@ public class VoidAffinity extends EcoEnchant { } @Override - public void onTridentDamage(@NotNull LivingEntity attacker, @NotNull LivingEntity victim, @NotNull Trident trident, int level, @NotNull EntityDamageByEntityEvent event) { - if(!attacker.getWorld().getEnvironment().equals(World.Environment.THE_END)) + public void onTridentDamage(@NotNull final LivingEntity attacker, + @NotNull final LivingEntity victim, + @NotNull final Trident trident, + final int level, + @NotNull final EntityDamageByEntityEvent event) { + if (!attacker.getWorld().getEnvironment().equals(World.Environment.THE_END)) { return; + } double multiplier = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "multiplier"); diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Voltage.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Voltage.java index 671e25ac..801836cb 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Voltage.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Voltage.java @@ -18,7 +18,7 @@ public class Voltage extends EcoEnchant { "voltage", EnchantmentType.NORMAL ); } - private static final Material[] items = { + private static final Material[] ITEMS = { Material.IRON_HELMET, Material.IRON_CHESTPLATE, Material.IRON_LEGGINGS, @@ -36,17 +36,30 @@ public class Voltage extends EcoEnchant { }; @Override - public void onMeleeAttack(@NotNull LivingEntity attacker, @NotNull LivingEntity victim, int level, @NotNull EntityDamageByEntityEvent event) { + public void onMeleeAttack(@NotNull final LivingEntity attacker, + @NotNull final LivingEntity victim, + final int level, + @NotNull final EntityDamageByEntityEvent event) { EntityEquipment equipment = victim.getEquipment(); - if(equipment == null) return; - - int pieces = 0; - for (ItemStack armorPiece : equipment.getArmorContents()) { - if(armorPiece == null) continue; - if(Arrays.asList(items).contains(armorPiece.getType())) pieces++; + if (equipment == null) { + return; } - if(pieces == 0) return; + int pieces = 0; + + for (ItemStack armorPiece : equipment.getArmorContents()) { + if (armorPiece == null) { + continue; + } + + if (Arrays.asList(ITEMS).contains(armorPiece.getType())) { + pieces++; + } + } + + if (pieces == 0) { + return; + } double multiplier = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "multiplier"); diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/WaterAffinity.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/WaterAffinity.java index b0ad7a64..6fd7fbb6 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/WaterAffinity.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/WaterAffinity.java @@ -16,9 +16,13 @@ public class WaterAffinity extends EcoEnchant { } @Override - public void onMeleeAttack(@NotNull LivingEntity attacker, @NotNull LivingEntity victim, int level, @NotNull EntityDamageByEntityEvent event) { - if(!attacker.getLocation().getBlock().getType().equals(Material.WATER)) + public void onMeleeAttack(@NotNull final LivingEntity attacker, + @NotNull final LivingEntity victim, + final int level, + @NotNull final EntityDamageByEntityEvent event) { + if (!attacker.getLocation().getBlock().getType().equals(Material.WATER)) { return; + } double damage = event.getDamage(); double multiplier = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "multiplier"); diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/WaterAspect.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/WaterAspect.java index 96c427ea..6a30492a 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/WaterAspect.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/WaterAspect.java @@ -18,9 +18,13 @@ public class WaterAspect extends EcoEnchant { } @Override - public void onMeleeAttack(@NotNull LivingEntity attacker, @NotNull LivingEntity victim, int level, @NotNull EntityDamageByEntityEvent event) { - if(!(victim instanceof Blaze || victim instanceof MagmaCube || victim instanceof Enderman)) + public void onMeleeAttack(@NotNull final LivingEntity attacker, + @NotNull final LivingEntity victim, + final int level, + @NotNull final EntityDamageByEntityEvent event) { + if (!(victim instanceof Blaze || victim instanceof MagmaCube || victim instanceof Enderman)) { return; + } double multiplier = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "multiplier"); diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Weakening.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Weakening.java index a8cbb44f..00a6a51e 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Weakening.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Weakening.java @@ -18,26 +18,29 @@ public class Weakening extends EcoEnchant { } @Override - public void onMeleeAttack(@NotNull LivingEntity attacker, @NotNull LivingEntity victim, int level, @NotNull EntityDamageByEntityEvent event) { + public void onMeleeAttack(@NotNull final LivingEntity attacker, + @NotNull final LivingEntity victim, + final int level, + @NotNull final EntityDamageByEntityEvent event) { int ticksPerLevel = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "ticks-per-level"); int ticks = ticksPerLevel * level; victim.setMetadata("weak", new FixedMetadataValue(this.getPlugin(), true)); - this.getPlugin().getScheduler().runLater(() -> { - victim.removeMetadata("weak", this.getPlugin()); - }, ticks); + this.getPlugin().getScheduler().runLater(() -> victim.removeMetadata("weak", this.getPlugin()), ticks); } @EventHandler - public void onDamage(EntityDamageEvent event) { - if(!(event.getEntity() instanceof LivingEntity)) + public void onDamage(@NotNull final EntityDamageEvent event) { + if (!(event.getEntity() instanceof LivingEntity)) { return; + } LivingEntity victim = (LivingEntity) event.getEntity(); - if(!victim.hasMetadata("weak")) + if (!victim.hasMetadata("weak")) { return; + } event.setDamage(event.getDamage() * this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "multiplier-while-weak")); } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Wisdom.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Wisdom.java index 150a7055..717dcf04 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Wisdom.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Wisdom.java @@ -7,6 +7,8 @@ import com.willfp.ecoenchants.enchantments.meta.EnchantmentType; import com.willfp.ecoenchants.enchantments.util.EnchantChecks; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.jetbrains.annotations.NotNull; + public class Wisdom extends EcoEnchant { public Wisdom() { super( @@ -14,14 +16,20 @@ public class Wisdom extends EcoEnchant { ); } @EventHandler - public void onExpChange(NaturalExpGainEvent event) { + public void onExpChange(@NotNull final NaturalExpGainEvent event) { Player player = event.getExpChangeEvent().getPlayer(); - if(event.getExpChangeEvent().getAmount() < 0) return; + if (event.getExpChangeEvent().getAmount() < 0) { + return; + } - if (!EnchantChecks.mainhand(player, this)) return; + if (!EnchantChecks.mainhand(player, this)) { + return; + } - if(this.getDisabledWorlds().contains(player.getWorld())) return; + if (this.getDisabledWorlds().contains(player.getWorld())) { + return; + } int level = EnchantChecks.getMainhandLevel(player, this); diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Wound.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Wound.java index 2c1d2d7b..3bc20a94 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Wound.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Wound.java @@ -19,9 +19,14 @@ public class Wound extends EcoEnchant { } @Override - public void onArrowDamage(@NotNull LivingEntity attacker, @NotNull LivingEntity victim, @NotNull Arrow arrow, int level, @NotNull EntityDamageByEntityEvent event) { - if (!EnchantmentUtils.passedChance(this, level)) + public void onArrowDamage(@NotNull final LivingEntity attacker, + @NotNull final LivingEntity victim, + @NotNull final Arrow arrow, + final int level, + @NotNull final EntityDamageByEntityEvent event) { + if (!EnchantmentUtils.passedChance(this, level)) { return; + } double bleedDamage = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "bleed-damage"); @@ -36,7 +41,9 @@ public class Wound extends EcoEnchant { victim.damage(bleedDamage); - if (currentBleedCount.get() >= finalBleedCount) bukkitRunnable.cancel(); + if (currentBleedCount.get() >= finalBleedCount) { + bukkitRunnable.cancel(); + } }).runTaskTimer(0, 10); } } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Zeus.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Zeus.java index 4392e858..fdc9cd5b 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Zeus.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Zeus.java @@ -18,9 +18,14 @@ public class Zeus extends EcoEnchant { } @Override - public void onArrowDamage(@NotNull LivingEntity attacker, @NotNull LivingEntity victim, @NotNull Arrow arrow, int level, @NotNull EntityDamageByEntityEvent event) { - if (!EnchantmentUtils.passedChance(this, level)) + public void onArrowDamage(@NotNull final LivingEntity attacker, + @NotNull final LivingEntity victim, + @NotNull final Arrow arrow, + final int level, + @NotNull final EntityDamageByEntityEvent event) { + if (!EnchantmentUtils.passedChance(this, level)) { return; + } double damage = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "lightning-damage"); diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Soulbound.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Soulbound.java index f706b12f..ea13b93f 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Soulbound.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Soulbound.java @@ -9,6 +9,7 @@ import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.player.PlayerRespawnEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.EnchantmentStorageMeta; +import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.Arrays; @@ -21,47 +22,57 @@ public class Soulbound extends EcoEnchant { "soulbound", EnchantmentType.SPECIAL ); } - private static final HashMap> soulboundItemsMap = new HashMap<>(); + private static final HashMap> SOULBOUND_ITEMS = new HashMap<>(); - public static List getSoulboundItems(Player player) { - return soulboundItemsMap.get(player); + public static List getSoulboundItems(@NotNull final Player player) { + return SOULBOUND_ITEMS.get(player); } @EventHandler(priority = EventPriority.HIGHEST) - public void onSoulboundDeath(PlayerDeathEvent event) { - if(event.getKeepInventory()) return; + public void onSoulboundDeath(@NotNull final PlayerDeathEvent event) { + if (event.getKeepInventory()) { + return; + } Player player = event.getEntity(); List soulboundItems = new ArrayList<>(); // Stored as list to preserve duplicates - if(this.getDisabledWorlds().contains(player.getWorld())) return; + if (this.getDisabledWorlds().contains(player.getWorld())) { + return; + } Arrays.stream(player.getInventory().getContents()).filter(Objects::nonNull).forEach((itemStack -> { - if(itemStack.containsEnchantment(this)) soulboundItems.add(itemStack); + if (itemStack.containsEnchantment(this)) { + soulboundItems.add(itemStack); + } - if(itemStack.getItemMeta() instanceof EnchantmentStorageMeta && (((EnchantmentStorageMeta) itemStack.getItemMeta()).getStoredEnchants().containsKey(this))) soulboundItems.add(itemStack); + if (itemStack.getItemMeta() instanceof EnchantmentStorageMeta && (((EnchantmentStorageMeta) itemStack.getItemMeta()).getStoredEnchants().containsKey(this))) { + soulboundItems.add(itemStack); + } })); event.getDrops().removeAll(soulboundItems); - soulboundItemsMap.remove(player); - soulboundItemsMap.put(player, soulboundItems); + SOULBOUND_ITEMS.remove(player); + SOULBOUND_ITEMS.put(player, soulboundItems); } @EventHandler(priority = EventPriority.HIGHEST) - public void onSoulboundRespawn(PlayerRespawnEvent event) { - if(!soulboundItemsMap.containsKey(event.getPlayer())) return; + public void onSoulboundRespawn(@NotNull final PlayerRespawnEvent event) { + if (!SOULBOUND_ITEMS.containsKey(event.getPlayer())) { + return; + } - List soulboundItems = soulboundItemsMap.get(event.getPlayer()); + List soulboundItems = SOULBOUND_ITEMS.get(event.getPlayer()); soulboundItems.forEach((itemStack -> { - if(Arrays.asList(event.getPlayer().getInventory().getContents()).contains(itemStack)) return; + if (Arrays.asList(event.getPlayer().getInventory().getContents()).contains(itemStack)) { + return; + } event.getPlayer().getInventory().addItem(itemStack); })); - this.getPlugin().getScheduler().runLater(() -> { - soulboundItemsMap.remove(event.getPlayer()); - }, 1); + this.getPlugin().getScheduler().runLater(() -> SOULBOUND_ITEMS.remove(event.getPlayer()), 1); } } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Spring.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Spring.java index c5743ace..d9a4f657 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Spring.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Spring.java @@ -16,14 +16,18 @@ public class Spring extends EcoEnchant { } @Override - public void onDamageWearingArmor(@NotNull LivingEntity victim, int level, @NotNull EntityDamageEvent event) { + public void onDamageWearingArmor(@NotNull final LivingEntity victim, + final int level, + @NotNull final EntityDamageEvent event) { if (event.getCause() == EntityDamageEvent.DamageCause.FALL) { event.setCancelled(true); } } @Override - public void onJump(@NotNull Player player, int level, @NotNull PlayerMoveEvent event) { + public void onJump(@NotNull final Player player, + final int level, + @NotNull final PlayerMoveEvent event) { double multiplier = 0.5 + ((double) (level * level) / 4 - 0.2) / 3; player.setVelocity(player.getLocation().getDirection().multiply(multiplier).setY(multiplier)); } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Streamlining.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Streamlining.java index 1dd51e53..552748d2 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Streamlining.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Streamlining.java @@ -15,8 +15,10 @@ public class Streamlining extends EcoEnchant { } @Override - public void onArmorEquip(@NotNull Player player, int level, @NotNull ArmorEquipEvent event) { - if(level == 0) { + public void onArmorEquip(@NotNull final Player player, + final int level, + @NotNull final ArmorEquipEvent event) { + if (level == 0) { player.setWalkSpeed(0.2f); return; } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Volatile.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Volatile.java index 7bafc7a5..e6fb0c50 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Volatile.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Volatile.java @@ -21,22 +21,34 @@ public class Volatile extends EcoEnchant { } @Override - public void onMeleeAttack(@NotNull LivingEntity uncastAttacker, @NotNull LivingEntity victim, int level, @NotNull EntityDamageByEntityEvent event) { - if(!(uncastAttacker instanceof Player)) return; + public void onMeleeAttack(@NotNull final LivingEntity uncastAttacker, + @NotNull final LivingEntity victim, + final int level, + @NotNull final EntityDamageByEntityEvent event) { + if (!(uncastAttacker instanceof Player)) { + return; + } Player attacker = (Player) uncastAttacker; - if (ProxyUtils.getProxy(CooldownProxy.class).getAttackCooldown(attacker) != 1.0f && !this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "allow-not-fully-charged")) + if (ProxyUtils.getProxy(CooldownProxy.class).getAttackCooldown(attacker) != 1.0f + && !this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "allow-not-fully-charged")) { return; - if(!EnchantmentUtils.passedChance(this, level)) + } + + if (!EnchantmentUtils.passedChance(this, level)) { return; + } boolean fire = this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "fire"); boolean breakblocks = this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "break-blocks"); float power = (float) (0.5 + (level * 0.5)); - if (!AntigriefManager.canCreateExplosion(attacker, event.getEntity().getLocation())) return; + if (!AntigriefManager.canCreateExplosion(attacker, event.getEntity().getLocation())) { + return; + } + if (breakblocks && !AntigriefManager.canBreakBlock(attacker, event.getEntity().getLocation().getWorld().getBlockAt(event.getEntity().getLocation()))) { return; } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/spell/Vitalize.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/spell/Vitalize.java index 5febaaa1..59174b7d 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/spell/Vitalize.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/spell/Vitalize.java @@ -12,7 +12,9 @@ public class Vitalize extends Spell { } @Override - public void onUse(@NotNull Player player, int level, @NotNull PlayerInteractEvent event) { + public void onUse(@NotNull final Player player, + final int level, + @NotNull final PlayerInteractEvent event) { player.setHealth(player.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()); } } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/itemtypes/Spell.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/itemtypes/Spell.java index 9e61441a..3fc0c55d 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/itemtypes/Spell.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/itemtypes/Spell.java @@ -31,7 +31,7 @@ import java.util.UUID; public abstract class Spell extends EcoEnchant { private final HashMap tracker = new HashMap<>(); private final Set runningSpell = new HashSet<>(); - private static final List leftClickItems = Arrays.asList( + private static final List LEFT_CLICK_ITEMS = Arrays.asList( Material.FISHING_ROD, Material.BOW ); @@ -59,7 +59,7 @@ public abstract class Spell extends EcoEnchant { runningSpell.add(player.getUniqueId()); this.getPlugin().getScheduler().runLater(() -> runningSpell.remove(player.getUniqueId()), 5); - if (leftClickItems.contains(player.getInventory().getItemInMainHand().getType())) { + if (LEFT_CLICK_ITEMS.contains(player.getInventory().getItemInMainHand().getType())) { if (!(event.getAction().equals(Action.LEFT_CLICK_AIR) || event.getAction().equals(Action.LEFT_CLICK_BLOCK))) { return; } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/obtaining/VillagerListeners.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/obtaining/VillagerListeners.java index 8137f0cf..72c79a1f 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/obtaining/VillagerListeners.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/support/obtaining/VillagerListeners.java @@ -15,6 +15,7 @@ import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.MerchantRecipe; import org.bukkit.inventory.meta.EnchantmentStorageMeta; import org.bukkit.inventory.meta.ItemMeta; +import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.Collections; @@ -27,12 +28,14 @@ public class VillagerListeners implements Listener { // For books @EventHandler - public void onVillagerGainBookTrade(VillagerAcquireTradeEvent event) { - if (!event.getRecipe().getResult().getType().equals(Material.ENCHANTED_BOOK)) + public void onVillagerGainBookTrade(@NotNull final VillagerAcquireTradeEvent event) { + if (!event.getRecipe().getResult().getType().equals(Material.ENCHANTED_BOOK)) { return; + } - if (!Configs.CONFIG.getBool("villager.enabled")) + if (!Configs.CONFIG.getBool("villager.enabled")) { return; + } ItemStack result = event.getRecipe().getResult().clone(); int uses = event.getRecipe().getUses(); @@ -42,7 +45,9 @@ public class VillagerListeners implements Listener { float priceMultiplier = event.getRecipe().getPriceMultiplier(); List ingredients = event.getRecipe().getIngredients(); - if (!(result.getItemMeta() instanceof EnchantmentStorageMeta)) return; + if (!(result.getItemMeta() instanceof EnchantmentStorageMeta)) { + return; + } EnchantmentStorageMeta meta = (EnchantmentStorageMeta) result.getItemMeta(); @@ -52,12 +57,17 @@ public class VillagerListeners implements Listener { double multiplier = 0.01 / Configs.CONFIG.getDouble("villager.book-times-less-likely"); for (EcoEnchant enchantment : enchantments) { - if (NumberUtils.randFloat(0, 1) > enchantment.getRarity().getVillagerProbability() * multiplier) + if (NumberUtils.randFloat(0, 1) > enchantment.getRarity().getVillagerProbability() * multiplier) { continue; - if (!enchantment.canGetFromVillager()) + } + + if (!enchantment.canGetFromVillager()) { continue; - if (!enchantment.isEnabled()) + } + + if (!enchantment.isEnabled()) { continue; + } int level; @@ -74,9 +84,7 @@ public class VillagerListeners implements Listener { level = (int) Math.ceil(enchantlevel2 / enchantlevel3); } - meta.getStoredEnchants().forEach(((enchantment1, integer) -> { - meta.removeStoredEnchant(enchantment1); - })); + meta.getStoredEnchants().forEach(((enchantment1, integer) -> meta.removeStoredEnchant(enchantment1))); meta.addStoredEnchant(enchantment, level, false); break; @@ -91,15 +99,19 @@ public class VillagerListeners implements Listener { // For tools @EventHandler - public void onVillagerGainItemTrade(VillagerAcquireTradeEvent event) { + public void onVillagerGainItemTrade(@NotNull final VillagerAcquireTradeEvent event) { - if (!EnchantmentTarget.ALL.getMaterials().contains(event.getRecipe().getResult().getType())) + if (!EnchantmentTarget.ALL.getMaterials().contains(event.getRecipe().getResult().getType())) { return; + } - if (event.getRecipe().getResult().getType().equals(Material.BOOK)) return; - - if (!Configs.CONFIG.getBool("villager.enabled")) + if (event.getRecipe().getResult().getType().equals(Material.BOOK)) { return; + } + + if (!Configs.CONFIG.getBool("villager.enabled")) { + return; + } ItemStack result = event.getRecipe().getResult().clone(); int uses = event.getRecipe().getUses(); @@ -109,7 +121,9 @@ public class VillagerListeners implements Listener { float priceMultiplier = event.getRecipe().getPriceMultiplier(); List ingredients = event.getRecipe().getIngredients(); - if (result.getItemMeta() instanceof EnchantmentStorageMeta) return; + if (result.getItemMeta() instanceof EnchantmentStorageMeta) { + return; + } ItemMeta meta = result.getItemMeta(); @@ -121,25 +135,42 @@ public class VillagerListeners implements Listener { double multiplier = 0.01; for (EcoEnchant enchantment : enchantments) { - if (NumberUtils.randFloat(0, 1) > enchantment.getRarity().getVillagerProbability() * multiplier) + if (NumberUtils.randFloat(0, 1) > enchantment.getRarity().getVillagerProbability() * multiplier) { continue; - if (!enchantment.canGetFromVillager()) + } + + if (!enchantment.canGetFromVillager()) { continue; - if (!enchantment.canEnchantItem(result)) + } + + if (!enchantment.canEnchantItem(result)) { continue; - if (!enchantment.isEnabled()) + } + + if (!enchantment.isEnabled()) { continue; + } AtomicBoolean anyConflicts = new AtomicBoolean(false); toAdd.forEach((enchant, integer) -> { - if (enchantment.conflictsWithAny(toAdd.keySet())) anyConflicts.set(true); - if (enchant.conflictsWith(enchantment)) anyConflicts.set(true); + if (enchantment.conflictsWithAny(toAdd.keySet())) { + anyConflicts.set(true); + } + + if (enchant.conflictsWith(enchantment)) { + anyConflicts.set(true); + } EcoEnchant ecoEnchant = EcoEnchants.getFromEnchantment(enchant); - if (enchantment.getType().equals(ecoEnchant.getType()) && ecoEnchant.getType().isSingular()) + + if (enchantment.getType().equals(ecoEnchant.getType()) && ecoEnchant.getType().isSingular()) { anyConflicts.set(true); + } }); - if (anyConflicts.get()) continue; + + if (anyConflicts.get()) { + continue; + } int level; @@ -163,9 +194,7 @@ public class VillagerListeners implements Listener { } } - toAdd.forEach(((enchantment, integer) -> { - meta.addEnchant(enchantment, integer, false); - })); + toAdd.forEach(((enchantment, integer) -> meta.addEnchant(enchantment, integer, false))); result.setItemMeta(meta); diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/SpellRunnable.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/SpellRunnable.java index 7c2b34dc..a12792a5 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/SpellRunnable.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/SpellRunnable.java @@ -4,15 +4,18 @@ package com.willfp.ecoenchants.enchantments.util; import com.willfp.eco.util.lambda.Callable; import com.willfp.ecoenchants.enchantments.itemtypes.Spell; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; public class SpellRunnable { private final Spell spell; private final Player player; private long endTime = 0; private Callable callable = () -> { + // Empty as must be set using this#setTask }; - public SpellRunnable(Spell spell, Player player) { + public SpellRunnable(@NotNull final Spell spell, + @NotNull final Player player) { this.spell = spell; this.player = player; } @@ -34,7 +37,7 @@ public class SpellRunnable { endTime = System.currentTimeMillis() + (long) ((spell.getCooldownTime() * 1000L) * Spell.getCooldownMultiplier(player)); } - public void setTask(Callable callable) { + public void setTask(@NotNull final Callable callable) { this.callable = callable; } } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/WatcherTriggers.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/WatcherTriggers.java index 79f54943..e373337c 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/WatcherTriggers.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/util/WatcherTriggers.java @@ -28,6 +28,7 @@ import org.bukkit.event.entity.ProjectileLaunchEvent; import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.potion.PotionEffectType; +import org.jetbrains.annotations.NotNull; import java.text.DecimalFormat; import java.util.Set; @@ -35,59 +36,94 @@ import java.util.UUID; @SuppressWarnings("deprecation") public class WatcherTriggers extends PluginDependent implements Listener { - public WatcherTriggers(AbstractEcoPlugin plugin) { + private static final Set PREVIOUS_PLAYERS_ON_GROUND = Sets.newHashSet(); + private static final DecimalFormat FORMAT = new DecimalFormat("0.00"); + + + public WatcherTriggers(@NotNull final AbstractEcoPlugin plugin) { super(plugin); } @EventHandler(ignoreCancelled = true) - public void onArrowDamage(EntityDamageByEntityEvent event) { - if (McmmoManager.isFake(event)) + public void onArrowDamage(@NotNull final EntityDamageByEntityEvent event) { + if (McmmoManager.isFake(event)) { return; - if (!(event.getDamager() instanceof Arrow)) + } + + if (!(event.getDamager() instanceof Arrow)) { return; - if (!(event.getEntity() instanceof LivingEntity)) + } + + if (!(event.getEntity() instanceof LivingEntity)) { return; - if (((Arrow) event.getDamager()).getShooter() == null) + } + + if (((Arrow) event.getDamager()).getShooter() == null) { return; - if (!(((Arrow) event.getDamager()).getShooter() instanceof LivingEntity)) + } + + if (!(((Arrow) event.getDamager()).getShooter() instanceof LivingEntity)) { return; + } LivingEntity attacker = (LivingEntity) ((Arrow) event.getDamager()).getShooter(); Arrow arrow = (Arrow) event.getDamager(); LivingEntity victim = (LivingEntity) event.getEntity(); - if (victim.hasMetadata("NPC")) return; + if (victim.hasMetadata("NPC")) { + return; + } - if (attacker instanceof Player && !AntigriefManager.canInjure((Player) attacker, victim)) return; + if (attacker instanceof Player && !AntigriefManager.canInjure((Player) attacker, victim)) { + return; + } - if (event.isCancelled()) return; + if (event.isCancelled()) { + return; + } EnchantChecks.getEnchantsOnArrow(arrow).forEach(((enchant, level) -> { - if (event.isCancelled()) return; - if (!enchant.isEnabled()) return; - if (enchant.getDisabledWorlds().contains(attacker.getWorld())) return; + if (event.isCancelled()) { + return; + } + + if (!enchant.isEnabled()) { + return; + } + + if (enchant.getDisabledWorlds().contains(attacker.getWorld())) { + return; + } + enchant.onArrowDamage(attacker, victim, arrow, level, event); })); } @EventHandler(ignoreCancelled = true) - public void onTridentDamage(EntityDamageByEntityEvent event) { - if (McmmoManager.isFake(event)) - return; - if (!(event.getDamager() instanceof Trident)) + public void onTridentDamage(@NotNull final EntityDamageByEntityEvent event) { + if (McmmoManager.isFake(event)) { return; + } - if (!(((Trident) event.getDamager()).getShooter() instanceof LivingEntity)) + if (!(event.getDamager() instanceof Trident)) { return; + } - if (((Trident) event.getDamager()).getShooter() == null) + if (!(((Trident) event.getDamager()).getShooter() instanceof LivingEntity)) { return; + } - if (!(event.getEntity() instanceof LivingEntity)) + if (((Trident) event.getDamager()).getShooter() == null) { return; + } - if (event.isCancelled()) + if (!(event.getEntity() instanceof LivingEntity)) { return; + } + + if (event.isCancelled()) { + return; + } LivingEntity attacker = (LivingEntity) ((Trident) event.getDamager()).getShooter(); Trident trident = (Trident) event.getDamager(); @@ -95,282 +131,455 @@ public class WatcherTriggers extends PluginDependent implements Listener { LivingEntity victim = (LivingEntity) event.getEntity(); - if (victim.hasMetadata("NPC")) return; + if (victim.hasMetadata("NPC")) { + return; + } - if (attacker instanceof Player && !AntigriefManager.canInjure((Player) attacker, victim)) return; + if (attacker instanceof Player && !AntigriefManager.canInjure((Player) attacker, victim)) { + return; + } EnchantChecks.getEnchantsOnItem(item).forEach(((enchant, level) -> { - if (event.isCancelled()) return; - if (!enchant.isEnabled()) return; - if (enchant.getDisabledWorlds().contains(attacker.getWorld())) return; + if (event.isCancelled()) { + return; + } + + if (!enchant.isEnabled()) { + return; + } + + if (enchant.getDisabledWorlds().contains(attacker.getWorld())) { + return; + } + enchant.onTridentDamage(attacker, victim, trident, level, event); })); } - - private static final Set prevPlayersOnGround = Sets.newHashSet(); - private static final DecimalFormat df = new DecimalFormat("0.00"); - @EventHandler(ignoreCancelled = true) - public void onJump(PlayerMoveEvent event) { - if (McmmoManager.isFake(event)) + public void onJump(@NotNull final PlayerMoveEvent event) { + if (McmmoManager.isFake(event)) { return; + } + Player player = event.getPlayer(); if (player.getVelocity().getY() > 0) { float jumpVelocity = 0.42f; if (player.hasPotionEffect(PotionEffectType.JUMP)) { jumpVelocity += ((float) player.getPotionEffect(PotionEffectType.JUMP).getAmplifier() + 1) * 0.1F; } - jumpVelocity = Float.parseFloat(df.format(jumpVelocity).replace(',', '.')); - if (event.getPlayer().getLocation().getBlock().getType() != Material.LADDER && prevPlayersOnGround.contains(player.getUniqueId())&& !player.isOnGround() && Float.compare((float) player.getVelocity().getY(), jumpVelocity) == 0) { + jumpVelocity = Float.parseFloat(FORMAT.format(jumpVelocity).replace(',', '.')); + if (event.getPlayer().getLocation().getBlock().getType() != Material.LADDER + && PREVIOUS_PLAYERS_ON_GROUND.contains(player.getUniqueId()) + && !player.isOnGround() + && Float.compare((float) player.getVelocity().getY(), jumpVelocity) == 0) { EnchantChecks.getEnchantsOnArmor(player).forEach((enchant, level) -> { - if (event.isCancelled()) return; - if (!enchant.isEnabled()) return; - if (enchant.getDisabledWorlds().contains(player.getWorld())) return; + if (event.isCancelled()) { + return; + } + + if (!enchant.isEnabled()) { + return; + } + + if (enchant.getDisabledWorlds().contains(player.getWorld())) { + return; + } + enchant.onJump(player, level, event); }); } } if (player.isOnGround()) { - prevPlayersOnGround.add(player.getUniqueId()); + PREVIOUS_PLAYERS_ON_GROUND.add(player.getUniqueId()); } else { - prevPlayersOnGround.remove(player.getUniqueId()); + PREVIOUS_PLAYERS_ON_GROUND.remove(player.getUniqueId()); } } @EventHandler(ignoreCancelled = true) - public void onMeleeAttack(EntityDamageByEntityEvent event) { - if (McmmoManager.isFake(event)) - return; - if (!(event.getDamager() instanceof LivingEntity)) + public void onMeleeAttack(@NotNull final EntityDamageByEntityEvent event) { + if (McmmoManager.isFake(event)) { return; + } - if (!(event.getEntity() instanceof LivingEntity)) + if (!(event.getDamager() instanceof LivingEntity)) { return; + } - if (event.isCancelled()) + if (!(event.getEntity() instanceof LivingEntity)) { return; + } + + if (event.isCancelled()) { + return; + } LivingEntity attacker = (LivingEntity) event.getDamager(); LivingEntity victim = (LivingEntity) event.getEntity(); - if (victim.hasMetadata("NPC")) return; + if (victim.hasMetadata("NPC")) { + return; + } - if (attacker instanceof Player && !AntigriefManager.canInjure((Player) attacker, victim)) return; + if (attacker instanceof Player && !AntigriefManager.canInjure((Player) attacker, victim)) { + return; + } EnchantChecks.getEnchantsOnMainhand(attacker).forEach((enchant, level) -> { - if (event.isCancelled()) return; - if (!enchant.isEnabled()) return; - if (enchant.getDisabledWorlds().contains(attacker.getWorld())) return; + if (event.isCancelled()) { + return; + } + + if (!enchant.isEnabled()) { + return; + } + + if (enchant.getDisabledWorlds().contains(attacker.getWorld())) { + return; + } + enchant.onMeleeAttack(attacker, victim, level, event); }); } @EventHandler(ignoreCancelled = true) - public void onBowShoot(EntityShootBowEvent event) { - if (McmmoManager.isFake(event)) + public void onBowShoot(@NotNull final EntityShootBowEvent event) { + if (McmmoManager.isFake(event)) { return; - if (event.getProjectile().getType() != EntityType.ARROW) + } + + if (event.getProjectile().getType() != EntityType.ARROW) { return; + } LivingEntity shooter = event.getEntity(); Arrow arrow = (Arrow) event.getProjectile(); EnchantChecks.getEnchantsOnMainhand(shooter).forEach((enchant, level) -> { - if (event.isCancelled()) return; - if (!enchant.isEnabled()) return; - if (enchant.getDisabledWorlds().contains(shooter.getWorld())) return; + if (event.isCancelled()) { + return; + } + + if (!enchant.isEnabled()) { + return; + } + + if (enchant.getDisabledWorlds().contains(shooter.getWorld())) { + return; + } + enchant.onBowShoot(shooter, arrow, level, event); }); } @EventHandler(ignoreCancelled = true) - public void onFallDamage(EntityDamageEvent event) { - if (McmmoManager.isFake(event)) - return; - if (!event.getCause().equals(EntityDamageEvent.DamageCause.FALL)) + public void onFallDamage(@NotNull final EntityDamageEvent event) { + if (McmmoManager.isFake(event)) { return; + } - if (!(event.getEntity() instanceof LivingEntity)) + if (!event.getCause().equals(EntityDamageEvent.DamageCause.FALL)) { return; + } + + if (!(event.getEntity() instanceof LivingEntity)) { + return; + } LivingEntity victim = (LivingEntity) event.getEntity(); EnchantChecks.getEnchantsOnArmor(victim).forEach((enchant, level) -> { - if (event.isCancelled()) return; - if (!enchant.isEnabled()) return; - if (enchant.getDisabledWorlds().contains(victim.getWorld())) return; + if (event.isCancelled()) { + return; + } + + if (!enchant.isEnabled()) { + return; + } + + if (enchant.getDisabledWorlds().contains(victim.getWorld())) { + return; + } + enchant.onFallDamage(victim, level, event); }); } @EventHandler(ignoreCancelled = true) - public void onArrowHit(ProjectileHitEvent event) { - if (McmmoManager.isFake(event)) - return; - if (!(event.getEntity().getShooter() instanceof LivingEntity)) + public void onArrowHit(@NotNull final ProjectileHitEvent event) { + if (McmmoManager.isFake(event)) { return; + } - if (!(event.getEntity() instanceof Arrow)) return; - - if (event.getEntity().getShooter() == null) + if (!(event.getEntity().getShooter() instanceof LivingEntity)) { return; + } + + if (!(event.getEntity() instanceof Arrow)) { + return; + } + + if (event.getEntity().getShooter() == null) { + return; + } Arrow arrow = (Arrow) event.getEntity(); LivingEntity shooter = (LivingEntity) event.getEntity().getShooter(); EnchantChecks.getEnchantsOnArrow(arrow).forEach(((enchant, level) -> { - if (!enchant.isEnabled()) return; - if (enchant.getDisabledWorlds().contains(shooter.getWorld())) return; + if (!enchant.isEnabled()) { + return; + } + + if (enchant.getDisabledWorlds().contains(shooter.getWorld())) { + return; + } + enchant.onArrowHit(shooter, level, event); })); } @EventHandler(ignoreCancelled = true) - public void onTridentHit(ProjectileHitEvent event) { - if (McmmoManager.isFake(event)) - return; - if (!(event.getEntity().getShooter() instanceof LivingEntity)) - return; - if (event.getEntity().getShooter() == null) + public void onTridentHit(@NotNull final ProjectileHitEvent event) { + if (McmmoManager.isFake(event)) { return; + } - if (!(event.getEntity() instanceof Trident)) return; + if (!(event.getEntity().getShooter() instanceof LivingEntity)) { + return; + } + + if (event.getEntity().getShooter() == null) { + return; + } + + if (!(event.getEntity() instanceof Trident)) { + return; + } Trident trident = (Trident) event.getEntity(); ItemStack item = ProxyUtils.getProxy(TridentStackProxy.class).getTridentStack(trident); LivingEntity shooter = (LivingEntity) event.getEntity().getShooter(); EnchantChecks.getEnchantsOnItem(item).forEach(((enchant, level) -> { - if (!enchant.isEnabled()) return; - if (enchant.getDisabledWorlds().contains(shooter.getWorld())) return; + if (!enchant.isEnabled()) { + return; + } + + if (enchant.getDisabledWorlds().contains(shooter.getWorld())) { + return; + } + enchant.onTridentHit(shooter, level, event); })); } @EventHandler(ignoreCancelled = true) - public void onBlockBreak(BlockBreakEvent event) { - if (McmmoManager.isFake(event)) + public void onBlockBreak(@NotNull final BlockBreakEvent event) { + if (McmmoManager.isFake(event)) { return; + } + Player player = event.getPlayer(); Block block = event.getBlock(); - if (!AntigriefManager.canBreakBlock(player, block)) return; - - if (event.isCancelled()) + if (!AntigriefManager.canBreakBlock(player, block)) { return; + } + + if (event.isCancelled()) { + return; + } EnchantChecks.getEnchantsOnMainhand(player).forEach((enchant, level) -> { - if (event.isCancelled()) return; - if (!enchant.isEnabled()) return; - if (enchant.getDisabledWorlds().contains(player.getWorld())) return; + if (event.isCancelled()) { + return; + } + + if (!enchant.isEnabled()) { + return; + } + + if (enchant.getDisabledWorlds().contains(player.getWorld())) { + return; + } + enchant.onBlockBreak(player, block, level, event); }); } @EventHandler(ignoreCancelled = true) - public void onDamageWearingArmor(EntityDamageEvent event) { - if (McmmoManager.isFake(event)) + public void onDamageWearingArmor(@NotNull final EntityDamageEvent event) { + if (McmmoManager.isFake(event)) { return; - if (!(event.getEntity() instanceof LivingEntity)) + } + + if (!(event.getEntity() instanceof LivingEntity)) { return; + } LivingEntity victim = (LivingEntity) event.getEntity(); EnchantChecks.getEnchantsOnArmor(victim).forEach((enchant, level) -> { - if (event.isCancelled()) return; - if (!enchant.isEnabled()) return; - if (enchant.getDisabledWorlds().contains(victim.getWorld())) return; + if (event.isCancelled()) { + return; + } + + if (!enchant.isEnabled()) { + return; + } + + if (enchant.getDisabledWorlds().contains(victim.getWorld())) { + return; + } + enchant.onDamageWearingArmor(victim, level, event); }); } @EventHandler(ignoreCancelled = true) - public void onArmorEquip(ArmorEquipEvent event) { - if (McmmoManager.isFake(event)) + public void onArmorEquip(@NotNull final ArmorEquipEvent event) { + if (McmmoManager.isFake(event)) { return; + } + Player player = event.getPlayer(); - this.getPlugin().getScheduler().runLater(() -> { - EcoEnchants.values().forEach((enchant -> { - if (event.isCancelled()) return; - if (!enchant.isEnabled()) return; - if (enchant.getDisabledWorlds().contains(player.getWorld())) return; - int level = EnchantChecks.getArmorPoints(player, enchant); - enchant.onArmorEquip(player, level, event); - })); - }, 1); + this.getPlugin().getScheduler().runLater(() -> EcoEnchants.values().forEach(enchant -> { + if (event.isCancelled()) { + return; + } + + if (!enchant.isEnabled()) { + return; + } + + if (enchant.getDisabledWorlds().contains(player.getWorld())) { + return; + } + + int level = EnchantChecks.getArmorPoints(player, enchant); + enchant.onArmorEquip(player, level, event); + }), 1); } @EventHandler(ignoreCancelled = true) - public void onDamageBlock(BlockDamageEvent event) { - if (McmmoManager.isFake(event)) + public void onDamageBlock(@NotNull final BlockDamageEvent event) { + if (McmmoManager.isFake(event)) { return; + } + Player player = event.getPlayer(); Block block = event.getBlock(); - if (event.getBlock().getDrops(player.getInventory().getItemInMainHand()).isEmpty()) + if (event.getBlock().getDrops(player.getInventory().getItemInMainHand()).isEmpty()) { return; + } EnchantChecks.getEnchantsOnMainhand(player).forEach((enchant, level) -> { - if (event.isCancelled()) return; - if (!enchant.isEnabled()) return; - if (enchant.getDisabledWorlds().contains(player.getWorld())) return; + if (event.isCancelled()) { + return; + } + + if (!enchant.isEnabled()) { + return; + } + + if (enchant.getDisabledWorlds().contains(player.getWorld())) { + return; + } + enchant.onDamageBlock(player, block, level, event); }); } @EventHandler(ignoreCancelled = true) - public void onTridentLaunch(ProjectileLaunchEvent event) { - if (McmmoManager.isFake(event)) + public void onTridentLaunch(@NotNull final ProjectileLaunchEvent event) { + if (McmmoManager.isFake(event)) { return; + } - if (!(event.getEntity() instanceof Trident)) + if (!(event.getEntity() instanceof Trident)) { return; + } - if (!(event.getEntity().getShooter() instanceof LivingEntity)) + if (!(event.getEntity().getShooter() instanceof LivingEntity)) { return; + } Trident trident = (Trident) event.getEntity(); LivingEntity shooter = (LivingEntity) trident.getShooter(); ItemStack item = ProxyUtils.getProxy(TridentStackProxy.class).getTridentStack(trident); EnchantChecks.getEnchantsOnItem(item).forEach((enchant, level) -> { - if (event.isCancelled()) return; - if (!enchant.isEnabled()) return; - if (enchant.getDisabledWorlds().contains(shooter.getWorld())) return; + if (event.isCancelled()) { + return; + } + + if (!enchant.isEnabled()) { + return; + } + + if (enchant.getDisabledWorlds().contains(shooter.getWorld())) { + return; + } + enchant.onTridentLaunch(shooter, trident, level, event); }); } @EventHandler(ignoreCancelled = true) - public void onDeflect(EntityDamageByEntityEvent event) { - if (McmmoManager.isFake(event)) + public void onDeflect(@NotNull final EntityDamageByEntityEvent event) { + if (McmmoManager.isFake(event)) { return; + } - if (!(event.getEntity() instanceof Player)) + if (!(event.getEntity() instanceof Player)) { return; + } - if (!(event.getDamager() instanceof LivingEntity)) + if (!(event.getDamager() instanceof LivingEntity)) { return; + } Player blocker = (Player) event.getEntity(); LivingEntity attacker = (LivingEntity) event.getDamager(); - if (!blocker.isBlocking()) return; + if (!blocker.isBlocking()) { + return; + } - if (!AntigriefManager.canInjure(blocker, attacker)) return; + if (!AntigriefManager.canInjure(blocker, attacker)) { + return; + } + + EcoEnchants.values().forEach(enchant -> { + if (event.isCancelled()) { + return; + } + + if (!enchant.isEnabled()) { + return; + } + + if (enchant.getDisabledWorlds().contains(blocker.getWorld())) { + return; + } - EcoEnchants.values().forEach((enchant -> { - if (event.isCancelled()) return; - if (!enchant.isEnabled()) return; - if (enchant.getDisabledWorlds().contains(blocker.getWorld())) return; int level; - if (!EnchantChecks.offhand(blocker, enchant) && !EnchantChecks.mainhand(blocker, enchant)) return; - if (EnchantChecks.offhand(blocker, enchant)) level = EnchantChecks.getOffhandLevel(blocker, enchant); - else level = EnchantChecks.getMainhandLevel(blocker, enchant); + + if (!EnchantChecks.offhand(blocker, enchant) && !EnchantChecks.mainhand(blocker, enchant)) { + return; + } + + if (EnchantChecks.offhand(blocker, enchant)) { + level = EnchantChecks.getOffhandLevel(blocker, enchant); + } else { + level = EnchantChecks.getMainhandLevel(blocker, enchant); + } enchant.onDeflect(blocker, attacker, level, event); - })); + }); } } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/integrations/worldguard/WorldguardManager.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/integrations/worldguard/WorldguardManager.java index f86ae04d..ef1a0e4d 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/integrations/worldguard/WorldguardManager.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/integrations/worldguard/WorldguardManager.java @@ -1,23 +1,26 @@ package com.willfp.ecoenchants.integrations.worldguard; import com.willfp.ecoenchants.enchantments.EcoEnchant; +import lombok.experimental.UtilityClass; import org.bukkit.Location; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; import java.util.HashSet; import java.util.Set; +@UtilityClass public class WorldguardManager { - private static final Set worldguardWrappers = new HashSet<>(); + private static final Set REGISTERED = new HashSet<>(); /** * Register a new WorldGuard integration * * @param worldguard The integration to register */ - public static void register(WorldguardWrapper worldguard) { - worldguardWrappers.add(worldguard); + public static void register(@NotNull final WorldguardWrapper worldguard) { + REGISTERED.add(worldguard); } /** @@ -26,8 +29,9 @@ public class WorldguardManager { * @param flagName The name of the flag * @param defaultValue The default value for the flag to have */ - public static void registerFlag(String flagName, boolean defaultValue) { - worldguardWrappers.forEach(worldguardWrapper -> worldguardWrapper.registerFlag(flagName, defaultValue)); + public static void registerFlag(@NotNull final String flagName, + final boolean defaultValue) { + REGISTERED.forEach(worldguardWrapper -> worldguardWrapper.registerFlag(flagName, defaultValue)); } /** @@ -37,10 +41,15 @@ public class WorldguardManager { * @param player The player to query * @return If the enchantment is enabled at a player's location */ - public static boolean enabledForPlayer(EcoEnchant enchant, LivingEntity player) { - if (!(player instanceof Player)) return true; - if(worldguardWrappers.isEmpty()) return true; - return worldguardWrappers.stream().anyMatch(worldguardWrapper -> worldguardWrapper.enabledForPlayer(enchant, (Player) player, player.getLocation())); + public static boolean enabledForPlayer(@NotNull final EcoEnchant enchant, + @NotNull final LivingEntity player) { + if (!(player instanceof Player)) { + return true; + } + if (REGISTERED.isEmpty()) { + return true; + } + return REGISTERED.stream().anyMatch(worldguardWrapper -> worldguardWrapper.enabledForPlayer(enchant, (Player) player, player.getLocation())); } /** @@ -51,9 +60,15 @@ public class WorldguardManager { * @param location The location to query * @return If the enchantment is enabled at a player's location */ - public static boolean enabledForPlayer(EcoEnchant enchant, LivingEntity player, Location location) { - if (!(player instanceof Player)) return true; - if(worldguardWrappers.isEmpty()) return true; - return worldguardWrappers.stream().anyMatch(worldguardWrapper -> worldguardWrapper.enabledForPlayer(enchant, (Player) player, location)); + public static boolean enabledForPlayer(@NotNull final EcoEnchant enchant, + @NotNull final LivingEntity player, + @NotNull final Location location) { + if (!(player instanceof Player)) { + return true; + } + if (REGISTERED.isEmpty()) { + return true; + } + return REGISTERED.stream().anyMatch(worldguardWrapper -> worldguardWrapper.enabledForPlayer(enchant, (Player) player, location)); } } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/integrations/worldguard/plugins/WorldguardIntegrationImpl.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/integrations/worldguard/plugins/WorldguardIntegrationImpl.java index 79e40b71..17866ace 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/integrations/worldguard/plugins/WorldguardIntegrationImpl.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/integrations/worldguard/plugins/WorldguardIntegrationImpl.java @@ -9,22 +9,30 @@ import com.willfp.ecoenchants.enchantments.EcoEnchant; import com.willfp.ecoenchants.integrations.worldguard.WorldguardWrapper; import org.bukkit.Location; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; public class WorldguardIntegrationImpl implements WorldguardWrapper { private static final FlagRegistry REGISTRY = WorldGuard.getInstance().getFlagRegistry(); @Override - public void registerFlag(String name, boolean def) { + public void registerFlag(@NotNull final String name, + final boolean def) { StateFlag flag = new StateFlag(name, def); - if(REGISTRY.get(name) == null) { + if (REGISTRY.get(name) == null) { REGISTRY.register(flag); } } @Override - public boolean enabledForPlayer(EcoEnchant enchant, Player player, Location location) { - if(WorldGuard.getInstance().getPlatform().getSessionManager().hasBypass(WorldGuardPlugin.inst().wrapPlayer(player), BukkitAdapter.adapt(location.getWorld()))) return true; - return WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery().queryState(BukkitAdapter.adapt(location), WorldGuardPlugin.inst().wrapPlayer(player), (StateFlag) REGISTRY.get(enchant.getKey().getKey() + "-enabled")) == StateFlag.State.ALLOW; + public boolean enabledForPlayer(@NotNull final EcoEnchant enchant, + @NotNull final Player player, + @NotNull final Location location) { + if (WorldGuard.getInstance().getPlatform().getSessionManager().hasBypass(WorldGuardPlugin.inst().wrapPlayer(player), BukkitAdapter.adapt(location.getWorld()))) { + return true; + } + + return WorldGuard.getInstance().getPlatform().getRegionContainer().createQuery() + .queryState(BukkitAdapter.adapt(location), WorldGuardPlugin.inst().wrapPlayer(player), (StateFlag) REGISTRY.get(enchant.getKey().getKey() + "-enabled")) == StateFlag.State.ALLOW; } @Override diff --git a/eco-core/core-proxy/src/main/java/com/willfp/eco/core/proxy/proxies/TridentStackProxy.java b/eco-core/core-proxy/src/main/java/com/willfp/eco/core/proxy/proxies/TridentStackProxy.java index 0a6ff570..282f7063 100644 --- a/eco-core/core-proxy/src/main/java/com/willfp/eco/core/proxy/proxies/TridentStackProxy.java +++ b/eco-core/core-proxy/src/main/java/com/willfp/eco/core/proxy/proxies/TridentStackProxy.java @@ -7,6 +7,7 @@ import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; public interface TridentStackProxy extends AbstractProxy { + /** * Get a trident's ItemStack. * @@ -14,4 +15,4 @@ public interface TridentStackProxy extends AbstractProxy { * @return The trident's ItemStack. */ ItemStack getTridentStack(@NotNull Trident trident); -} \ No newline at end of file +} diff --git a/eco-extensions/biomes/src/main/java/com/willfp/ecoenchants/biomes/enchants/defensive/Tropical.java b/eco-extensions/biomes/src/main/java/com/willfp/ecoenchants/biomes/enchants/defensive/Tropical.java index f6cf76de..09772f6c 100644 --- a/eco-extensions/biomes/src/main/java/com/willfp/ecoenchants/biomes/enchants/defensive/Tropical.java +++ b/eco-extensions/biomes/src/main/java/com/willfp/ecoenchants/biomes/enchants/defensive/Tropical.java @@ -14,7 +14,7 @@ public class Tropical extends BiomesEnchantment { } @Override - public boolean isValid(@NotNull Biome biome) { + public boolean isValid(@NotNull final Biome biome) { return Arrays.stream(new String[]{"jungle"}).anyMatch(biome.name().toLowerCase()::contains); } } diff --git a/eco-extensions/sprint-artifacts/src/main/java/com/willfp/ecoenchants/sprintartifacts/SprintArtifactsListener.java b/eco-extensions/sprint-artifacts/src/main/java/com/willfp/ecoenchants/sprintartifacts/SprintArtifactsListener.java index e8e1ec38..f36e2ab7 100644 --- a/eco-extensions/sprint-artifacts/src/main/java/com/willfp/ecoenchants/sprintartifacts/SprintArtifactsListener.java +++ b/eco-extensions/sprint-artifacts/src/main/java/com/willfp/ecoenchants/sprintartifacts/SprintArtifactsListener.java @@ -11,6 +11,7 @@ import org.bukkit.event.Listener; import org.bukkit.event.player.PlayerMoveEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; +import org.jetbrains.annotations.NotNull; import java.util.Objects; import java.util.Optional; @@ -18,27 +19,43 @@ import java.util.Optional; @SuppressWarnings("deprecation") public class SprintArtifactsListener implements Listener { @EventHandler - public void onPlayerMove(PlayerMoveEvent event) { + public void onPlayerMove(@NotNull final PlayerMoveEvent event) { Player player = event.getPlayer(); - if(!player.isSprinting()) return; - if(!player.isOnGround()) return; + if (!player.isSprinting()) { + return; + } + + if (!player.isOnGround()) { + return; + } ItemStack boots = player.getInventory().getBoots(); - if(boots == null) return; + if (boots == null) { + return; + } ItemMeta bootsMeta = boots.getItemMeta(); - if(bootsMeta == null) return; + if (bootsMeta == null) { + return; + } Optional matching = bootsMeta.getEnchants().keySet().stream() .map(EcoEnchants::getFromEnchantment) .filter(Objects::nonNull) .filter(enchantment -> enchantment.getType().equals(EnchantmentType.ARTIFACT)) .findFirst(); - if(!matching.isPresent()) return; + if (!matching.isPresent()) { + return; + } Artifact artifact = (Artifact) matching.get(); - if (!EnchantChecks.boots(player, artifact)) return; - if(artifact.getDisabledWorlds().contains(player.getWorld())) return; + if (!EnchantChecks.boots(player, artifact)) { + return; + } + + if (artifact.getDisabledWorlds().contains(player.getWorld())) { + return; + } player.getWorld().spawnParticle(artifact.getParticle(), player.getLocation().add(0, 0.1, 0), 1, 0, 0, 0, 0, artifact.getDustOptions(), true); } diff --git a/eco-extensions/summoning/src/main/java/com/willfp/ecoenchants/summoning/SummoningEnchantment.java b/eco-extensions/summoning/src/main/java/com/willfp/ecoenchants/summoning/SummoningEnchantment.java index ae7fad7e..221f45a1 100644 --- a/eco-extensions/summoning/src/main/java/com/willfp/ecoenchants/summoning/SummoningEnchantment.java +++ b/eco-extensions/summoning/src/main/java/com/willfp/ecoenchants/summoning/SummoningEnchantment.java @@ -28,7 +28,10 @@ import org.jetbrains.annotations.NotNull; public abstract class SummoningEnchantment extends EcoEnchant { private final SummoningType summoningType; - protected SummoningEnchantment(String key, EnchantmentType type, SummoningType summoningType, Prerequisite... prerequisites) { + protected SummoningEnchantment(@NotNull final String key, + @NotNull final EnchantmentType type, + @NotNull final SummoningType summoningType, + @NotNull final Prerequisite... prerequisites) { super(key, type, prerequisites); this.summoningType = summoningType; @@ -37,36 +40,60 @@ public abstract class SummoningEnchantment extends EcoEnchant { public abstract EntityType getEntity(); @Override - public void onMeleeAttack(@NotNull LivingEntity attacker, @NotNull LivingEntity victim, int level, @NotNull EntityDamageByEntityEvent event) { - if(!summoningType.equals(SummoningType.MELEE)) return; - - doSpawn(attacker, victim, level); - } - - @Override - public void onArrowDamage(@NotNull LivingEntity attacker, @NotNull LivingEntity victim, @NotNull Arrow arrow, int level, @NotNull EntityDamageByEntityEvent event) { - if(!summoningType.equals(SummoningType.RANGED)) return; - - doSpawn(attacker, victim, level); - } - - @Override - public void onTridentDamage(@NotNull LivingEntity attacker, @NotNull LivingEntity victim, @NotNull Trident trident, int level, @NotNull EntityDamageByEntityEvent event) { - if(!summoningType.equals(SummoningType.TRIDENT)) return; - - doSpawn(attacker, victim, level); - } - - private void doSpawn(LivingEntity attacker, LivingEntity victim, int level) { - - if(summoningType.equals(SummoningType.MELEE) && attacker instanceof Player && ProxyUtils.getProxy(CooldownProxy.class).getAttackCooldown((Player) attacker) != 1.0f && !this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "allow-not-fully-charged")) { + public void onMeleeAttack(@NotNull final LivingEntity attacker, + @NotNull final LivingEntity victim, + final int level, + @NotNull final EntityDamageByEntityEvent event) { + if (!summoningType.equals(SummoningType.MELEE)) { return; } - if(!EnchantmentUtils.passedChance(this, level)) - return; + doSpawn(attacker, victim, level); + } - if(!victim.getMetadata("eco-target").isEmpty()) return; + @Override + public void onArrowDamage(@NotNull final LivingEntity attacker, + @NotNull final LivingEntity victim, + @NotNull final Arrow arrow, + final int level, + @NotNull final EntityDamageByEntityEvent event) { + if (!summoningType.equals(SummoningType.RANGED)) { + return; + } + + doSpawn(attacker, victim, level); + } + + @Override + public void onTridentDamage(@NotNull final LivingEntity attacker, + @NotNull final LivingEntity victim, + @NotNull final Trident trident, + final int level, + @NotNull final EntityDamageByEntityEvent event) { + if (!summoningType.equals(SummoningType.TRIDENT)) { + return; + } + + doSpawn(attacker, victim, level); + } + + private void doSpawn(@NotNull final LivingEntity attacker, + @NotNull final LivingEntity victim, + final int level) { + + if (summoningType.equals(SummoningType.MELEE) + && attacker instanceof Player && ProxyUtils.getProxy(CooldownProxy.class).getAttackCooldown((Player) attacker) != 1.0f + && !this.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "allow-not-fully-charged")) { + return; + } + + if (!EnchantmentUtils.passedChance(this, level)) { + return; + } + + if (!victim.getMetadata("eco-target").isEmpty()) { + return; + } Location location = victim.getLocation().clone(); World world = victim.getWorld(); @@ -75,12 +102,14 @@ public abstract class SummoningEnchantment extends EcoEnchant { int ticksToLive = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "ticks-to-live-per-level") * level; double health = this.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "health-per-level") * level; - for(int i = 0; i < toSpawn; i++) { + for (int i = 0; i < toSpawn; i++) { Location locToSpawn = location.clone().add(NumberUtils.randFloat(-3, 3), NumberUtils.randFloat(0, 3), NumberUtils.randFloat(-3, 3)); Mob entity = (Mob) world.spawnEntity(locToSpawn, this.getEntity()); entity.setTarget(victim); - if(health > entity.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()) health = entity.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue(); + if (health > entity.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue()) { + health = entity.getAttribute(Attribute.GENERIC_MAX_HEALTH).getValue(); + } entity.setHealth(health); entity.setMetadata("eco-target", new FixedMetadataValue(this.getPlugin(), victim)); @@ -89,16 +118,20 @@ public abstract class SummoningEnchantment extends EcoEnchant { } @EventHandler - public void onSwitchTarget(EntityTargetEvent event) { - if(event.getEntity().getMetadata("eco-target").isEmpty()) return; + public void onSwitchTarget(@NotNull final EntityTargetEvent event) { + if (event.getEntity().getMetadata("eco-target").isEmpty()) { + return; + } LivingEntity target = (LivingEntity) event.getEntity().getMetadata("eco-target").get(0).value(); event.setTarget(target); } @EventHandler(priority = EventPriority.LOW) - public void onDropItem(EntityDeathEvent event) { - if(event.getEntity().getMetadata("eco-target").isEmpty()) return; + public void onDropItem(@NotNull final EntityDeathEvent event) { + if (event.getEntity().getMetadata("eco-target").isEmpty()) { + return; + } event.getDrops().clear(); event.setDroppedExp(0); diff --git a/eco-util/src/main/java/com/willfp/eco/util/StringUtils.java b/eco-util/src/main/java/com/willfp/eco/util/StringUtils.java index e12813e7..94515f08 100644 --- a/eco-util/src/main/java/com/willfp/eco/util/StringUtils.java +++ b/eco-util/src/main/java/com/willfp/eco/util/StringUtils.java @@ -47,7 +47,7 @@ public class StringUtils { return ChatColor.translateAlternateColorCodes('&', translateHexColorCodes(processedMessage)); } - private static String translateHexColorCodes(String message) { + private static String translateHexColorCodes(@NotNull final String message) { Pattern hexPattern = Pattern.compile("&#" + "([A-Fa-f0-9]{6})" + ""); Matcher matcher = hexPattern.matcher(message); StringBuffer buffer = new StringBuffer(message.length() + 4 * 8); @@ -91,15 +91,15 @@ public class StringUtils { /** * Remove a string of characters from the start of a string. * - * @param s The string to remove the prefix from. + * @param string The string to remove the prefix from. * @param prefix The substring to remove. * @return The string with the prefix removed. */ - public String removePrefix(@NotNull final String s, + public String removePrefix(@NotNull final String string, @NotNull final String prefix) { - if (s.startsWith(prefix)) { - return s.substring(prefix.length()); + if (string.startsWith(prefix)) { + return string.substring(prefix.length()); } - return s; + return string; } }