From c6033a7e1caf54617c9b45f5827f25e84c6ee65a Mon Sep 17 00:00:00 2001 From: sk89q Date: Tue, 16 Nov 2010 00:15:06 -0800 Subject: [PATCH] Chests are now empty when removed (so they longer drop their items). Profile debugging mode added that prints how long an operation took. --- src/EditSession.java | 5 +++++ src/ServerInterface.java | 26 ++++++++++++++++++++++++++ src/WorldEditListener.java | 13 +++++++++++++ 3 files changed, 44 insertions(+) diff --git a/src/EditSession.java b/src/EditSession.java index 7d39fd516..19b8afa8f 100644 --- a/src/EditSession.java +++ b/src/EditSession.java @@ -93,6 +93,11 @@ public class EditSession { if (y < 0 || y > 127) { return false; } + + // Clear the chest so that it doesn't drop items + if (ServerInterface.getBlockType(pt) == 54) { + ServerInterface.clearChest(pt); + } boolean result = ServerInterface.setBlockType(pt, block.getID()); if (block.getID() != 0) { diff --git a/src/ServerInterface.java b/src/ServerInterface.java index c42fb30d3..8dc987347 100644 --- a/src/ServerInterface.java +++ b/src/ServerInterface.java @@ -184,6 +184,32 @@ public class ServerInterface { return true; } + /** + * Clear a chest's contents. + * + * @param pt + */ + public static boolean clearChest(Vector pt) { + ComplexBlock cblock = etc.getServer().getComplexBlock( + pt.getBlockX(), pt.getBlockY(), pt.getBlockZ()); + + if (!(cblock instanceof Chest)) { + return false; + } + + Chest chest = (Chest)cblock; + hj[] itemArray = chest.getArray(); + + // Find an existing slot to put it into + for (int i = 0; itemArray.length > i; i++) { + itemArray[i] = null; + } + + chest.update(); + + return true; + } + /** * Generate a tree at a location. * diff --git a/src/WorldEditListener.java b/src/WorldEditListener.java index ce2224583..177e66a73 100644 --- a/src/WorldEditListener.java +++ b/src/WorldEditListener.java @@ -79,6 +79,10 @@ public class WorldEditListener extends PluginListener { */ private GroupRestrictionsManager restrictions = new GroupRestrictionsManager(); + /** + * True to time operations. + */ + private boolean profile; /** * List of allowed blocks. */ @@ -1702,11 +1706,18 @@ public class WorldEditListener extends PluginListener { new EditSession(session.getBlockChangeLimit()); editSession.enableQueue(); + long start = System.currentTimeMillis(); + try { return performCommand(player, session, editSession, split); } finally { session.remember(editSession); editSession.flushQueue(); + + if (profile) { + long time = System.currentTimeMillis() - start; + ply.sendMessage(Colors.Yellow + (time / 1000.0) + "s elapsed"); + } } } } @@ -1774,6 +1785,8 @@ public class WorldEditListener extends PluginListener { properties.load(); } + profile = properties.getBoolean("debug-profile", false); + // Get allowed blocks allowedBlocks = new HashSet(); for (String b : properties.getString("allowed-blocks",