Improved plugin compatibility with the block lag fix.

This commit is contained in:
sk89q 2010-11-20 10:56:47 -08:00
parent 1edc48b16f
commit e95d7a8b6e
2 changed files with 42 additions and 5 deletions

View File

@ -70,7 +70,7 @@ public void initialize() {
loader.addListener(PluginLoader.Hook.BLOCK_CREATED, listener, this,
PluginListener.Priority.HIGH);
loader.addListener(PluginLoader.Hook.BLOCK_DESTROYED, listener, this,
PluginListener.Priority.HIGH);
PluginListener.Priority.CRITICAL);
loader.addListener(PluginLoader.Hook.DISCONNECT, listener, this,
PluginListener.Priority.HIGH);
loader.addListener(PluginLoader.Hook.ITEM_DROP , listener, this,

View File

@ -450,7 +450,7 @@ public boolean onBlockDestroy(Player player, Block block) {
// destroyed. Since this causes the hook to eventually call
// twice, we try to nullify it below
if (canDestroyBlock(player, block)) {
if (block.getStatus() == 3) {
if (block.getStatus() == 3 && canBreakBlock(player, block)) {
int dropItem = type;
int count = 1;
@ -501,8 +501,7 @@ else if (type == 18) { // Leaves
}
// Now loop this hook back through!
block.setStatus(3); // Block is destroyed
canDestroyBlock(player, block);
simulateBlockDestroy(player, block);
}
return true;
@ -735,6 +734,44 @@ public void onDisconnect(Player player) {
BlacklistEntry.forgetPlayer(player);
}
/**
* Simulate the block destroy hook.
*
* @param player
* @param block
* @return
*/
private boolean simulateBlockDestroy(Player player, Block block) {
plugin.toggleEnabled(); // Prevent infinite loop
try {
block.setStatus(3);;
return !(Boolean)etc.getLoader().callHook(PluginLoader.Hook.BLOCK_DESTROYED,
new Object[]{ player.getUser(), block });
} catch (Throwable t) {
return true;
} finally {
plugin.toggleEnabled();
}
}
/**
* Checks if a block can be broken.
*
* @param player
* @param block
* @return
*/
private boolean canBreakBlock(Player player, Block orig) {
try {
Block block = etc.getServer().getBlockAt(
orig.getX(), orig.getY(), orig.getZ());
return !(Boolean)etc.getLoader().callHook(PluginLoader.Hook.BLOCK_BROKEN,
new Object[]{ player.getUser(), block });
} catch (Throwable t) {
return true;
}
}
/**
* Checks if a block can be destroyed.
*
@ -742,7 +779,7 @@ public void onDisconnect(Player player) {
* @param block
* @return
*/
public boolean canDestroyBlock(Player player, Block block) {
private boolean canDestroyBlock(Player player, Block block) {
plugin.toggleEnabled(); // Prevent infinite loop
try {
return !(Boolean)etc.getLoader().callHook(PluginLoader.Hook.BLOCK_DESTROYED,