From e12fcdb1b8819df776babc52282a530519860cd5 Mon Sep 17 00:00:00 2001 From: sk89q Date: Wed, 17 Nov 2010 20:33:29 -0800 Subject: [PATCH] Moved the block lag fix to a low priority listener. --- src/WorldGuard.java | 7 ++ src/WorldGuardListener.java | 161 +++++++++++++++++++++--------------- 2 files changed, 101 insertions(+), 67 deletions(-) diff --git a/src/WorldGuard.java b/src/WorldGuard.java index 89adb145..60da626b 100644 --- a/src/WorldGuard.java +++ b/src/WorldGuard.java @@ -39,6 +39,11 @@ public class WorldGuard extends Plugin { */ private static final WorldGuardListener listener = new WorldGuardListener(); + /** + * Low priority version. + */ + private static final WorldGuardListener.LowPriorityListener lowPriorityListener = + listener.getLowPriorityListener(); /** * Initializes the plugin. @@ -59,6 +64,8 @@ public void initialize() { PluginListener.Priority.HIGH); loader.addListener(PluginLoader.Hook.BLOCK_DESTROYED, listener, this, PluginListener.Priority.HIGH); + loader.addListener(PluginLoader.Hook.BLOCK_DESTROYED, lowPriorityListener, this, + PluginListener.Priority.LOW); loader.addListener(PluginLoader.Hook.DISCONNECT, listener, this, PluginListener.Priority.HIGH); } diff --git a/src/WorldGuardListener.java b/src/WorldGuardListener.java index 5fe91c63..f45a4ab7 100644 --- a/src/WorldGuardListener.java +++ b/src/WorldGuardListener.java @@ -231,73 +231,6 @@ public boolean onBlockDestroy(Player player, Block block) { } } } - - if (blockLagFix - && type != 64 // Wooden door - && type != 71 // Iron door - && type != 77 // Stone button - && type != 69 // Lever - && type != 7 // Bedrock - && type != 51 // Fire - && type != 46 // TNT - && type != 59 // Crops - && type != 62 // Burning furnace - && type != 50 // Torch - && type != 75 // Redstone torch - && type != 76 // Redstone torch - ) { - - if (block.getStatus() == 3) { - int dropped = type; - int count = 1; - - if (type == 1) { dropped = 4; } // Stone - else if (type == 2) { dropped = 3; } // Grass - else if (type == 16) { dropped = 263; } // Coal ore - else if (type == 18) { // Leaves - if (rand.nextDouble() > 0.95) { - dropped = 6; - } else { - dropped = 0; - } - } - else if (type == 47) { dropped = 0; } // Bookshelves - else if (type == 52) { dropped = 0; } // Mob spawner - else if (type == 53) { dropped = 5; } // Wooden stairs - else if (type == 55) { dropped = 331; } // Redstone wire - else if (type == 56) { dropped = 264; } // Diamond ore - else if (type == 60) { dropped = 3; } // Soil - else if (type == 63) { dropped = 323; } // Sign post - else if (type == 67) { dropped = 4; } // Cobblestone stairs - else if (type == 68) { dropped = 323; } // Wall sign - else if (type == 73) { dropped = 331; count = 4; } // Redstone ore - else if (type == 74) { dropped = 331; count = 4; } // Glowing redstone ore - else if (type == 75) { dropped = 76; count = 4; } // Redstone torch - else if (type == 79) { dropped = 0; count = 4; } // Ice - else if (type == 82) { dropped = 337; count = 4; } // Clay - else if (type == 83) { dropped = 338; count = 4; } // Reed - else if (type == 89) { dropped = 348; } // Lightstone - - etc.getServer().setBlockAt(0, block.getX(), block.getY(), block.getZ()); - - if (dropped > 0) { - for (int i = 0; i < count; i++) { - etc.getServer().dropItem(block.getX(), block.getY(), block.getZ(), - dropped, i); - } - - // Drop flint with gravel - if (type == 13) { - if (rand.nextDouble() > 0.95) { - etc.getServer().dropItem(block.getX(), block.getY(), block.getZ(), - 318, 1); - } - } - } - } - - return true; - } return false; } @@ -518,4 +451,98 @@ public Map loadBlacklist(File file) } } } + + /** + * Get the low priority listener. + * + * @return + */ + public LowPriorityListener getLowPriorityListener() { + return new LowPriorityListener(); + } + + /** + * Low priority listener. + */ + public class LowPriorityListener extends PluginListener { + /** + * Called when a person left clicks a block. + * + * @param player + * @param block + * @return + */ + public boolean onBlockDestroy(Player player, Block block) { + int type = block.getType(); + + if (blockLagFix + && type != 64 // Wooden door + && type != 71 // Iron door + && type != 77 // Stone button + && type != 69 // Lever + && type != 7 // Bedrock + && type != 51 // Fire + && type != 46 // TNT + && type != 59 // Crops + && type != 62 // Burning furnace + && type != 50 // Torch + && type != 75 // Redstone torch + && type != 76 // Redstone torch + ) { + + if (block.getStatus() == 3) { + int dropped = type; + int count = 1; + + if (type == 1) { dropped = 4; } // Stone + else if (type == 2) { dropped = 3; } // Grass + else if (type == 16) { dropped = 263; } // Coal ore + else if (type == 18) { // Leaves + if (rand.nextDouble() > 0.95) { + dropped = 6; + } else { + dropped = 0; + } + } + else if (type == 47) { dropped = 0; } // Bookshelves + else if (type == 52) { dropped = 0; } // Mob spawner + else if (type == 53) { dropped = 5; } // Wooden stairs + else if (type == 55) { dropped = 331; } // Redstone wire + else if (type == 56) { dropped = 264; } // Diamond ore + else if (type == 60) { dropped = 3; } // Soil + else if (type == 63) { dropped = 323; } // Sign post + else if (type == 67) { dropped = 4; } // Cobblestone stairs + else if (type == 68) { dropped = 323; } // Wall sign + else if (type == 73) { dropped = 331; count = 4; } // Redstone ore + else if (type == 74) { dropped = 331; count = 4; } // Glowing redstone ore + else if (type == 75) { dropped = 76; count = 4; } // Redstone torch + else if (type == 79) { dropped = 0; count = 4; } // Ice + else if (type == 82) { dropped = 337; count = 4; } // Clay + else if (type == 83) { dropped = 338; count = 4; } // Reed + else if (type == 89) { dropped = 348; } // Lightstone + + etc.getServer().setBlockAt(0, block.getX(), block.getY(), block.getZ()); + + if (dropped > 0) { + for (int i = 0; i < count; i++) { + etc.getServer().dropItem(block.getX(), block.getY(), block.getZ(), + dropped, i); + } + + // Drop flint with gravel + if (type == 13) { + if (rand.nextDouble() > 0.95) { + etc.getServer().dropItem(block.getX(), block.getY(), block.getZ(), + 318, 1); + } + } + } + } + + return true; + } + + return false; + } + } } \ No newline at end of file