From bf4d6813321ca5574d8635e7bdf54b262b229563 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Wed, 30 Dec 2020 13:13:23 +0000 Subject: [PATCH] Fixed CallingCurse, DecayCurse, Forcefield, Magnetic, Repairing --- .../willfp/ecoenchants/EcoEnchantsPlugin.java | 13 ++++--------- .../ecoenchants/curse/CallingCurse.java | 12 +++++++----- .../ecoenchants/curse/DecayCurse.java | 4 ++-- .../ecoenchants/normal/Forcefield.java | 17 ++++++++++------- .../ecoenchants/normal/Magnetic.java | 12 ++++++------ .../ecoenchants/special/Repairing.java | 4 ++-- 6 files changed, 31 insertions(+), 31 deletions(-) diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/EcoEnchantsPlugin.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/EcoEnchantsPlugin.java index ea3e8559..c06f2a55 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/EcoEnchantsPlugin.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/EcoEnchantsPlugin.java @@ -71,15 +71,6 @@ public class EcoEnchantsPlugin extends AbstractEcoPlugin { this.getLog().info(""); - EcoEnchants.values().forEach(enchant -> { - if (enchant.isEnabled()) { - this.getEventManager().registerListener(enchant); - if (enchant instanceof EcoRunnable) { - this.getScheduler().syncRepeating((EcoRunnable) enchant, 5, ((EcoRunnable) enchant).getTime()); - } - } - }); - this.getLog().info(EcoEnchants.values().size() + " Enchantments Loaded:"); this.getLog().info(EcoEnchants.values().stream().map(ecoEnchant -> ecoEnchant.getType().getColor() + ecoEnchant.getName()).collect(Collectors.joining(", "))); @@ -123,6 +114,10 @@ public class EcoEnchantsPlugin extends AbstractEcoPlugin { this.getScheduler().runLater(() -> { if (ecoEnchant.isEnabled()) { this.getEventManager().registerListener(ecoEnchant); + + if (ecoEnchant instanceof EcoRunnable) { + this.getScheduler().syncRepeating((EcoRunnable) ecoEnchant, 5, ((EcoRunnable) ecoEnchant).getTime()); + } } }, 1); })); diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/curse/CallingCurse.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/curse/CallingCurse.java index a9483d7b..11da944f 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/curse/CallingCurse.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/curse/CallingCurse.java @@ -20,14 +20,15 @@ import org.jetbrains.annotations.NotNull; import java.util.HashMap; public class CallingCurse extends EcoEnchant implements EcoRunnable { + private final HashMap players = new HashMap<>(); + private double distance = EcoEnchants.CALLING_CURSE.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "distance"); + public CallingCurse() { super( "calling_curse", EnchantmentType.CURSE ); } - private final HashMap players = new HashMap<>(); - @EventHandler public void onArmorEquip(@NotNull final ArmorEquipEvent event) { refresh(); @@ -45,18 +46,19 @@ public class CallingCurse extends EcoEnchant implements EcoRunnable { private void refresh() { players.clear(); - this.getPlugin().getServer().getOnlinePlayers().forEach(player -> { + this.getPlugin().getScheduler().runLater(() -> this.getPlugin().getServer().getOnlinePlayers().forEach(player -> { int level = EnchantChecks.getArmorPoints(player, this, 0); if (level > 0) { players.put(player, level); } - }); + }), 1); + + distance = EcoEnchants.CALLING_CURSE.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "distance"); } @Override public void run() { players.forEach((player, level) -> { - double distance = EcoEnchants.CALLING_CURSE.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "distance"); if (this.getDisabledWorlds().contains(player.getWorld())) { return; } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/curse/DecayCurse.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/curse/DecayCurse.java index cedcedb6..2f49e7c2 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/curse/DecayCurse.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/curse/DecayCurse.java @@ -67,11 +67,11 @@ public class DecayCurse extends EcoEnchant implements EcoRunnable { private void refresh() { players.clear(); - this.getPlugin().getServer().getOnlinePlayers().forEach(player -> { + this.getPlugin().getScheduler().runLater(() -> this.getPlugin().getServer().getOnlinePlayers().forEach(player -> { if (Arrays.stream(player.getInventory().getContents()).parallel().anyMatch(item -> EnchantChecks.item(item, this))) { players.add(player); } - }); + }), 1); amount = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "multiplier"); } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Forcefield.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Forcefield.java index e06dfa2f..0e14c2d2 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Forcefield.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Forcefield.java @@ -18,14 +18,17 @@ import org.jetbrains.annotations.NotNull; import java.util.HashMap; public class Forcefield extends EcoEnchant implements EcoRunnable { + private final HashMap players = new HashMap<>(); + double initialDistance = EcoEnchants.FORCEFIELD.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "initial-distance"); + double bonus = EcoEnchants.FORCEFIELD.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "bonus-per-level"); + double damagePerPoint = EcoEnchants.FORCEFIELD.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "damage-per-level"); + public Forcefield() { super( "forcefield", EnchantmentType.NORMAL ); } - private final HashMap players = new HashMap<>(); - @EventHandler public void onArmorEquip(@NotNull final ArmorEquipEvent event) { refresh(); @@ -43,12 +46,15 @@ public class Forcefield extends EcoEnchant implements EcoRunnable { private void refresh() { players.clear(); - this.getPlugin().getServer().getOnlinePlayers().forEach(player -> { + this.getPlugin().getScheduler().runLater(() -> this.getPlugin().getServer().getOnlinePlayers().forEach(player -> { int level = EnchantChecks.getArmorPoints(player, this, 0); if (level > 0) { players.put(player, level); } - }); + }), 1); + initialDistance = EcoEnchants.FORCEFIELD.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "initial-distance"); + bonus = EcoEnchants.FORCEFIELD.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "bonus-per-level"); + damagePerPoint = EcoEnchants.FORCEFIELD.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "damage-per-level"); } @Override @@ -57,10 +63,7 @@ public class Forcefield extends EcoEnchant implements EcoRunnable { if (this.getDisabledWorlds().contains(player.getWorld())) { return; } - double initialDistance = EcoEnchants.FORCEFIELD.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "initial-distance"); - double bonus = EcoEnchants.FORCEFIELD.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "bonus-per-level"); double distance = initialDistance + (level * bonus); - double damagePerPoint = EcoEnchants.FORCEFIELD.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "damage-per-level"); final double damage = damagePerPoint * level; for (Entity e : player.getWorld().getNearbyEntities(player.getLocation(), distance, 2.0d, distance)) { diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Magnetic.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Magnetic.java index 1163e518..7245c573 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Magnetic.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/normal/Magnetic.java @@ -20,16 +20,16 @@ import org.jetbrains.annotations.NotNull; import java.util.HashMap; public class Magnetic extends EcoEnchant implements EcoRunnable { + private double initialDistance = 1; + private double bonus = 1; + private final HashMap players = new HashMap<>(); + public Magnetic() { super( "magnetic", EnchantmentType.NORMAL ); } - private final HashMap players = new HashMap<>(); - private double initialDistance = 1; - private double bonus = 1; - @EventHandler public void onArmorEquip(@NotNull final ArmorEquipEvent event) { refresh(); @@ -47,12 +47,12 @@ public class Magnetic extends EcoEnchant implements EcoRunnable { private void refresh() { players.clear(); - this.getPlugin().getServer().getOnlinePlayers().forEach(player -> { + this.getPlugin().getScheduler().runLater(() -> this.getPlugin().getServer().getOnlinePlayers().forEach(player -> { int level = EnchantChecks.getArmorPoints(player, this, 0); if (level > 0) { players.put(player, level); } - }); + }), 1); initialDistance = EcoEnchants.MAGNETIC.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "initial-distance"); bonus = EcoEnchants.MAGNETIC.getConfig().getDouble(EcoEnchants.CONFIG_LOCATION + "bonus-per-level"); } diff --git a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Repairing.java b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Repairing.java index 92e1c418..13d314e4 100644 --- a/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Repairing.java +++ b/eco-core/core-plugin/src/main/java/com/willfp/ecoenchants/enchantments/ecoenchants/special/Repairing.java @@ -68,11 +68,11 @@ public class Repairing extends EcoEnchant implements EcoRunnable { private void refresh() { players.clear(); - this.getPlugin().getServer().getOnlinePlayers().forEach(player -> { + this.getPlugin().getScheduler().runLater(() -> this.getPlugin().getServer().getOnlinePlayers().forEach(player -> { if (Arrays.stream(player.getInventory().getContents()).parallel().anyMatch(item -> EnchantChecks.item(item, this))) { players.add(player); } - }); + }), 1); amount = this.getConfig().getInt(EcoEnchants.CONFIG_LOCATION + "multiplier"); }