From 6ee87c160010e93468718d59950d9a839f0aa2ed Mon Sep 17 00:00:00 2001 From: Rothes <449181985@qq.com> Date: Sun, 12 Jun 2022 21:23:19 +0800 Subject: [PATCH] Fix entity death drops rollback --- .../prism/actions/ItemStackAction.java | 45 ++++++++++++------- .../prism/listeners/PrismEntityEvents.java | 1 - 2 files changed, 28 insertions(+), 18 deletions(-) diff --git a/Prism/src/main/java/network/darkhelmet/prism/actions/ItemStackAction.java b/Prism/src/main/java/network/darkhelmet/prism/actions/ItemStackAction.java index a7c8b8d3..39725299 100644 --- a/Prism/src/main/java/network/darkhelmet/prism/actions/ItemStackAction.java +++ b/Prism/src/main/java/network/darkhelmet/prism/actions/ItemStackAction.java @@ -14,6 +14,7 @@ import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; +import org.bukkit.OfflinePlayer; import org.bukkit.block.Block; import org.bukkit.block.BlockFace; import org.bukkit.block.Jukebox; @@ -197,6 +198,12 @@ protected ChangeResult placeItems(Player player, PrismParameters parameters, boo final Block block = getWorld().getBlockAt(getLoc()); Inventory inventory = null; + // Entity death drops. Just remove the drops. + if (getUuid() == null || getActionType().getName().equals("item-drop")) { + removeItemEntity(); + return new ChangeResultImpl(ChangeResultType.APPLIED, null); + } + // Item drop/pickup from player inventories if (getActionType().getName().equals("item-drop") || getActionType().getName().equals("item-pickup")) { @@ -385,23 +392,7 @@ protected ChangeResult placeItems(Player player, PrismParameters parameters, boo // Item was added to the inv, we need to remove the entity if (added && (n.equals("item-drop") || n.equals("item-pickup"))) { - if (!removeFromCache(getId())) { - // Not cached, search nearby for it. - for (final Entity entity : getLoc().getWorld().getNearbyEntities(getLoc(), 10, 10, 10)) { - if (entity instanceof Item) { - final ItemStack stack = ((Item) entity).getItemStack(); - if (stack.isSimilar(getItem())) { - // Remove the event's number of items from - // the stack - stack.setAmount(stack.getAmount() - getItem().getAmount()); - if (stack.getAmount() == 0) { - entity.remove(); - } - break; - } - } - } - } + removeItemEntity(); } } @@ -471,4 +462,24 @@ protected ChangeResult placeItems(Player player, PrismParameters parameters, boo } return new ChangeResultImpl(result, null); } + + private void removeItemEntity() { + if (!removeFromCache(getId())) { + // Not cached, search nearby for it. + for (final Entity entity : getLoc().getWorld().getNearbyEntities(getLoc(), 10, 10, 10)) { + if (entity instanceof Item) { + final ItemStack stack = ((Item) entity).getItemStack(); + if (stack.isSimilar(getItem())) { + // Remove the event's number of items from + // the stack + stack.setAmount(stack.getAmount() - getItem().getAmount()); + if (stack.getAmount() == 0) { + entity.remove(); + } + break; + } + } + } + } + } } diff --git a/Prism/src/main/java/network/darkhelmet/prism/listeners/PrismEntityEvents.java b/Prism/src/main/java/network/darkhelmet/prism/listeners/PrismEntityEvents.java index 1382bec0..5dc5cde1 100644 --- a/Prism/src/main/java/network/darkhelmet/prism/listeners/PrismEntityEvents.java +++ b/Prism/src/main/java/network/darkhelmet/prism/listeners/PrismEntityEvents.java @@ -323,7 +323,6 @@ public void onEntityDeathDropItemSpawn(final ItemSpawnEvent event) { return; } ItemStack itemStack = entity.getItemStack(); - System.out.println(drops.itemStacks); if (drops.itemStacks.contains(itemStack)) { if (drops.sourceName != null) { RecordingQueue.addToQueue(ActionFactory.createItemStack("item-drop", itemStack, itemStack.getAmount(), -1, null,