Added protection and plugin support.

This commit is contained in:
sk89q 2010-11-17 22:51:09 -08:00
parent a7aed1a278
commit 92edff6ffe
2 changed files with 41 additions and 3 deletions

View File

@ -37,8 +37,14 @@ public class WorldGuard extends Plugin {
/**
* Listener for the plugin system.
*/
private static final WorldGuardListener listener =
new WorldGuardListener();
private WorldGuardListener listener;
/**
* Initialize the plugin.
*/
public WorldGuard() {
listener = new WorldGuardListener(this);
}
/**
* Initializes the plugin.

View File

@ -48,6 +48,10 @@ public class WorldGuardListener extends PluginListener {
*/
private static Random rand = new Random();
/**
* Plugin host.
*/
private WorldGuard plugin;
/**
* Properties file for CraftBook.
*/
@ -70,6 +74,15 @@ public class WorldGuardListener extends PluginListener {
private boolean classicWater;
private Map<Integer,BlacklistEntry> blacklist;
/**
* Construct the listener.
*
* @param plugin
*/
public WorldGuardListener(WorldGuard plugin) {
this.plugin = plugin;
}
/**
* Convert a comma-delimited list to a set of integers.
*
@ -245,7 +258,7 @@ public class WorldGuardListener extends PluginListener {
&& type != 50 // Torch
&& type != 75 // Redstone torch
&& type != 76 // Redstone torch
) {
&& canDestroyBlock(player, block)) {
if (block.getStatus() == 3) {
int dropped = type;
@ -423,6 +436,25 @@ public class WorldGuardListener extends PluginListener {
BlacklistEntry.forgetPlayer(player);
}
/**
* Checks if a block can be destroyed.
*
* @param player
* @param block
* @return
*/
public boolean canDestroyBlock(Player player, Block block) {
plugin.toggleEnabled(); // Prevent infinite loop
try {
return !(Boolean)etc.getLoader().callHook(PluginLoader.Hook.BLOCK_DESTROYED,
new Object[]{ player.getUser(), block });
} catch (Throwable t) {
return true;
} finally {
plugin.toggleEnabled();
}
}
/**
* Load the blacklist.
*