From 20ab821862f35979ea40371d50a283818619f73c Mon Sep 17 00:00:00 2001 From: Auxilor Date: Mon, 14 Dec 2020 15:20:18 +0000 Subject: [PATCH] "Optimised" telekinesis --- .../ecoenchants/util/internal/DropQueue.java | 29 ++++++++++++------- .../ecoenchants/util/internal/Loader.java | 1 + 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/util/internal/DropQueue.java b/Plugin/src/main/java/com/willfp/ecoenchants/util/internal/DropQueue.java index 4d126fbb..0346bf72 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/util/internal/DropQueue.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/util/internal/DropQueue.java @@ -28,6 +28,8 @@ public class DropQueue { private boolean hasTelekinesis = false; private ItemStack item; + private static boolean useOrb; + /** * Create {@link DropQueue} linked to player * @@ -116,25 +118,22 @@ public class DropQueue { * Push the queue */ public void push() { - if (!hasTelekinesis) hasTelekinesis = EnchantChecks.item(item, EcoEnchants.TELEKINESIS); - if (hasTelekinesis && !EcoEnchants.TELEKINESIS.isEnabled()) hasTelekinesis = false; - + if(!hasTelekinesis) hasTelekinesis = EnchantChecks.item(item, EcoEnchants.TELEKINESIS); + if(hasTelekinesis && !EcoEnchants.TELEKINESIS.isEnabled()) hasTelekinesis = false; World world = loc.getWorld(); assert world != null; - if (hasTelekinesis) { - for (ItemStack drop : items) { - HashMap nope = player.getInventory().addItem(drop); - nope.forEach(((integer, itemStack) -> { - world.dropItemNaturally(loc.add(0.5, 0, 0.5), itemStack).setVelocity(new Vector()); - })); + if(hasTelekinesis) { + HashMap leftover = player.getInventory().addItem(items.toArray(new ItemStack[]{})); + for(ItemStack drop : leftover.values()) { + world.dropItemNaturally(loc.add(0.5, 0, 0.5), drop).setVelocity(new Vector()); } if (xp > 0) { PlayerExpChangeEvent event = new PlayerExpChangeEvent(player, xp); Bukkit.getPluginManager().callEvent(event); - if (EcoEnchants.TELEKINESIS.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "use-orb")) { - ExperienceOrb orb = (ExperienceOrb) player.getWorld().spawnEntity(player.getLocation().add(0, 0.2, 0), EntityType.EXPERIENCE_ORB); + if (useOrb) { + ExperienceOrb orb = (ExperienceOrb) world.spawnEntity(player.getLocation().add(0, 0.2, 0), EntityType.EXPERIENCE_ORB); orb.setVelocity(new Vector(0, 0, 0)); orb.setExperience(event.getAmount()); } else { @@ -152,4 +151,12 @@ public class DropQueue { } } } + + public static void update() { + useOrb = EcoEnchants.TELEKINESIS.getConfig().getBool(EcoEnchants.CONFIG_LOCATION + "use-orb"); + } + + static { + update(); + } } diff --git a/Plugin/src/main/java/com/willfp/ecoenchants/util/internal/Loader.java b/Plugin/src/main/java/com/willfp/ecoenchants/util/internal/Loader.java index a404eaee..408f2957 100644 --- a/Plugin/src/main/java/com/willfp/ecoenchants/util/internal/Loader.java +++ b/Plugin/src/main/java/com/willfp/ecoenchants/util/internal/Loader.java @@ -365,6 +365,7 @@ public class Loader { EnchantmentRarity.update(); EnchantmentTarget.update(); EcoEnchants.update(); + DropQueue.update(); EnchantDisplay.update(); TabCompleterEnchantinfo.reload(); EcoEnchant.EnchantmentType.update();