Skip to content

Commit

Permalink
Fix entity death drops rollback
Browse files Browse the repository at this point in the history
  • Loading branch information
Rothes committed Jun 12, 2022
1 parent 0e4dddc commit 6ee87c1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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")) {

Expand Down Expand Up @@ -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();
}
}

Expand Down Expand Up @@ -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;
}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 6ee87c1

Please sign in to comment.