mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2024-12-24 18:19:03 +01:00
Added protection and plugin support.
This commit is contained in:
parent
a7aed1a278
commit
92edff6ffe
@ -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.
|
||||
|
@ -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 boolean onBlockDestroy(Player player, Block block) {
|
||||
&& 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 void onDisconnect(Player player) {
|
||||
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.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user