mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2024-11-27 21:15:57 +01:00
Improved plugin compatibility with the block lag fix.
This commit is contained in:
parent
1edc48b16f
commit
e95d7a8b6e
@ -70,7 +70,7 @@ public void initialize() {
|
|||||||
loader.addListener(PluginLoader.Hook.BLOCK_CREATED, listener, this,
|
loader.addListener(PluginLoader.Hook.BLOCK_CREATED, listener, this,
|
||||||
PluginListener.Priority.HIGH);
|
PluginListener.Priority.HIGH);
|
||||||
loader.addListener(PluginLoader.Hook.BLOCK_DESTROYED, listener, this,
|
loader.addListener(PluginLoader.Hook.BLOCK_DESTROYED, listener, this,
|
||||||
PluginListener.Priority.HIGH);
|
PluginListener.Priority.CRITICAL);
|
||||||
loader.addListener(PluginLoader.Hook.DISCONNECT, listener, this,
|
loader.addListener(PluginLoader.Hook.DISCONNECT, listener, this,
|
||||||
PluginListener.Priority.HIGH);
|
PluginListener.Priority.HIGH);
|
||||||
loader.addListener(PluginLoader.Hook.ITEM_DROP , listener, this,
|
loader.addListener(PluginLoader.Hook.ITEM_DROP , listener, this,
|
||||||
|
@ -450,7 +450,7 @@ public boolean onBlockDestroy(Player player, Block block) {
|
|||||||
// destroyed. Since this causes the hook to eventually call
|
// destroyed. Since this causes the hook to eventually call
|
||||||
// twice, we try to nullify it below
|
// twice, we try to nullify it below
|
||||||
if (canDestroyBlock(player, block)) {
|
if (canDestroyBlock(player, block)) {
|
||||||
if (block.getStatus() == 3) {
|
if (block.getStatus() == 3 && canBreakBlock(player, block)) {
|
||||||
int dropItem = type;
|
int dropItem = type;
|
||||||
int count = 1;
|
int count = 1;
|
||||||
|
|
||||||
@ -501,8 +501,7 @@ else if (type == 18) { // Leaves
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Now loop this hook back through!
|
// Now loop this hook back through!
|
||||||
block.setStatus(3); // Block is destroyed
|
simulateBlockDestroy(player, block);
|
||||||
canDestroyBlock(player, block);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -735,6 +734,44 @@ public void onDisconnect(Player player) {
|
|||||||
BlacklistEntry.forgetPlayer(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.
|
* Checks if a block can be destroyed.
|
||||||
*
|
*
|
||||||
@ -742,7 +779,7 @@ public void onDisconnect(Player player) {
|
|||||||
* @param block
|
* @param block
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public boolean canDestroyBlock(Player player, Block block) {
|
private boolean canDestroyBlock(Player player, Block block) {
|
||||||
plugin.toggleEnabled(); // Prevent infinite loop
|
plugin.toggleEnabled(); // Prevent infinite loop
|
||||||
try {
|
try {
|
||||||
return !(Boolean)etc.getLoader().callHook(PluginLoader.Hook.BLOCK_DESTROYED,
|
return !(Boolean)etc.getLoader().callHook(PluginLoader.Hook.BLOCK_DESTROYED,
|
||||||
|
Loading…
Reference in New Issue
Block a user