Fixed rollback for doublechests rolling back only one half under some

circumstances.
This commit is contained in:
Robin Kupper committed 2011-07-18 20:09:46 +02:00
1 parent 5bc267ae0a
commit 094a185764
3 files changed
+39 -14

No files matched your search

+17
View File
@@ -11,6 +11,8 @@ import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.block.BlockState;
import org.bukkit.block.ContainerBlock;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Entity;
@@ -168,6 +170,21 @@ public class BukkitUtils
return y;
}
public static int modifyContainer(BlockState b, ItemStack item) throws Exception {
if (!(b instanceof ContainerBlock))
throw new Exception("No container at " + b.getBlock().getLocation().toString());
final Inventory inv = ((ContainerBlock)b).getInventory();
if (item.getAmount() < 0) {
item.setAmount(-item.getAmount());
final ItemStack tmp = inv.removeItem(item).get(0);
return tmp != null ? tmp.getAmount() : 0;
} else if (item.getAmount() > 0) {
final ItemStack tmp = inv.addItem(item).get(0);
return tmp != null ? tmp.getAmount() : 0;
}
return 0;
}
public static class ItemStackComparator implements Comparator<ItemStack>
{
@Override