diff --git a/CHANGELOG.md b/CHANGELOG.md index 5a3457846..d360629fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,7 @@ * Fixed Programmable Androids rotating in the wrong direction * Fixed #2176 * Fixed #2103 +* Fixed #2184 ## Release Candidate 15 (01 Aug 2020) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/EnchantmentRune.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/EnchantmentRune.java index a272fb502..f4522a725 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/EnchantmentRune.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/EnchantmentRune.java @@ -17,7 +17,6 @@ import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Entity; import org.bukkit.entity.Item; import org.bukkit.entity.Player; -import org.bukkit.event.player.PlayerDropItemEvent; import org.bukkit.inventory.ItemStack; import io.github.thebusybiscuit.slimefun4.core.handlers.ItemDropHandler; @@ -70,7 +69,7 @@ public class EnchantmentRune extends SimpleSlimefunItem { if (Slimefun.hasUnlocked(p, this, true)) { Slimefun.runSync(() -> { try { - addRandomEnchantment(p, e, item); + addRandomEnchantment(p, item); } catch (Exception x) { error("An Exception occured while trying to apply an Enchantment Rune", x); @@ -85,21 +84,21 @@ public class EnchantmentRune extends SimpleSlimefunItem { }; } - private void addRandomEnchantment(Player p, PlayerDropItemEvent e, Item item) { + private void addRandomEnchantment(Player p, Item rune) { // Being sure the entity is still valid and not picked up or whatsoever. - if (!item.isValid()) { + if (!rune.isValid()) { return; } - Location l = item.getLocation(); + Location l = rune.getLocation(); Collection entites = l.getWorld().getNearbyEntities(l, RANGE, RANGE, RANGE, this::findCompatibleItem); Optional optional = entites.stream().findFirst(); if (optional.isPresent()) { - Item entity = (Item) optional.get(); - ItemStack target = entity.getItemStack(); + Item item = (Item) optional.get(); + ItemStack itemStack = item.getItemStack(); - List potentialEnchantments = applicableEnchantments.get(target.getType()); + List potentialEnchantments = applicableEnchantments.get(itemStack.getType()); if (potentialEnchantments == null) { SlimefunPlugin.getLocalization().sendMessage(p, "messages.enchantment-rune.fail", true); @@ -111,7 +110,7 @@ public class EnchantmentRune extends SimpleSlimefunItem { // Removing the enchantments that the item already has from enchantmentSet // This also removes any conflicting enchantments - removeIllegalEnchantments(target, potentialEnchantments); + removeIllegalEnchantments(itemStack, potentialEnchantments); if (potentialEnchantments.isEmpty()) { SlimefunPlugin.getLocalization().sendMessage(p, "messages.enchantment-rune.no-enchantment", true); @@ -119,30 +118,24 @@ public class EnchantmentRune extends SimpleSlimefunItem { } Enchantment enchantment = potentialEnchantments.get(ThreadLocalRandom.current().nextInt(potentialEnchantments.size())); - int level = 1; - - if (enchantment.getMaxLevel() != 1) { - level = ThreadLocalRandom.current().nextInt(enchantment.getMaxLevel()) + 1; - } - - target.addEnchantment(enchantment, level); - - if (target.getAmount() == 1) { - e.setCancelled(true); + int level = getRandomlevel(enchantment); + if (itemStack.getAmount() == 1) { // This lightning is just an effect, it deals no damage. l.getWorld().strikeLightningEffect(l); Slimefun.runSync(() -> { // Being sure entities are still valid and not picked up or whatsoever. - if (item.isValid() && entity.isValid() && target.getAmount() == 1) { + if (rune.isValid() && item.isValid() && itemStack.getAmount() == 1) { l.getWorld().spawnParticle(Particle.CRIT_MAGIC, l, 1); l.getWorld().playSound(l, Sound.ENTITY_ZOMBIE_VILLAGER_CURE, 1F, 1F); - entity.remove(); item.remove(); - l.getWorld().dropItemNaturally(l, target); + rune.remove(); + + itemStack.addEnchantment(enchantment, level); + l.getWorld().dropItemNaturally(l, itemStack); SlimefunPlugin.getLocalization().sendMessage(p, "messages.enchantment-rune.success", true); } @@ -154,6 +147,16 @@ public class EnchantmentRune extends SimpleSlimefunItem { } } + private int getRandomlevel(Enchantment enchantment) { + int level = 1; + + if (enchantment.getMaxLevel() != 1) { + level = ThreadLocalRandom.current().nextInt(enchantment.getMaxLevel()) + 1; + } + + return level; + } + private void removeIllegalEnchantments(ItemStack target, List potentialEnchantments) { for (Enchantment enchantment : target.getEnchantments().keySet()) { Iterator iterator = potentialEnchantments.iterator(); diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/SoulboundRune.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/SoulboundRune.java index d35c00ee7..9a9c4d54e 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/SoulboundRune.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/items/magical/SoulboundRune.java @@ -8,7 +8,6 @@ import org.bukkit.Sound; import org.bukkit.entity.Entity; import org.bukkit.entity.Item; import org.bukkit.entity.Player; -import org.bukkit.event.player.PlayerDropItemEvent; import org.bukkit.inventory.ItemStack; import io.github.thebusybiscuit.slimefun4.core.attributes.Soulbound; @@ -51,7 +50,7 @@ public class SoulboundRune extends SimpleSlimefunItem { return true; } - Slimefun.runSync(() -> activate(p, e, item), 20L); + Slimefun.runSync(() -> activate(p, item), 20L); return true; } @@ -59,7 +58,7 @@ public class SoulboundRune extends SimpleSlimefunItem { }; } - private void activate(Player p, PlayerDropItemEvent e, Item rune) { + private void activate(Player p, Item rune) { // Being sure the entity is still valid and not picked up or whatsoever. if (!rune.isValid()) { return; @@ -74,9 +73,6 @@ public class SoulboundRune extends SimpleSlimefunItem { ItemStack itemStack = item.getItemStack(); if (itemStack.getAmount() == 1) { - // Prevent other plugins from processing this Item as we will remove it soon - e.setCancelled(true); - // This lightning is just an effect, it deals no damage. l.getWorld().strikeLightningEffect(l);