mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2025-01-23 16:41:20 +01:00
Added on-break event to the blacklist.
This commit is contained in:
parent
9bc3a25191
commit
93c0295744
@ -92,6 +92,28 @@ public boolean onDestroy(final Block block, final Player player) {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called on block break. Returns true to let the action pass
|
||||||
|
* through.
|
||||||
|
*
|
||||||
|
* @param block
|
||||||
|
* @param player
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public boolean onBreak(final Block block, final Player player) {
|
||||||
|
List<BlacklistEntry> entries = getEntries(block.getType());
|
||||||
|
if (entries == null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
boolean ret = true;
|
||||||
|
for (BlacklistEntry entry : entries) {
|
||||||
|
if (!entry.onBreak(block, player)) {
|
||||||
|
ret = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called on left click. Returns true to let the action pass through.
|
* Called on left click. Returns true to let the action pass through.
|
||||||
*
|
*
|
||||||
@ -269,6 +291,8 @@ public void load(File file) throws IOException {
|
|||||||
entry.setIgnoreGroups(parts[1].split(","));
|
entry.setIgnoreGroups(parts[1].split(","));
|
||||||
} else if (parts[0].equalsIgnoreCase("on-destroy")) {
|
} else if (parts[0].equalsIgnoreCase("on-destroy")) {
|
||||||
entry.setDestroyActions(parts[1].split(","));
|
entry.setDestroyActions(parts[1].split(","));
|
||||||
|
} else if (parts[0].equalsIgnoreCase("on-break")) {
|
||||||
|
entry.setBreakActions(parts[1].split(","));
|
||||||
} else if (parts[0].equalsIgnoreCase("on-left")
|
} else if (parts[0].equalsIgnoreCase("on-left")
|
||||||
|| parts[0].equalsIgnoreCase("on-destroy-with")) {
|
|| parts[0].equalsIgnoreCase("on-destroy-with")) {
|
||||||
entry.setDestroyWithActions(parts[1].split(","));
|
entry.setDestroyWithActions(parts[1].split(","));
|
||||||
|
@ -46,6 +46,10 @@ public class BlacklistEntry {
|
|||||||
* List of actions to perform on destruction.
|
* List of actions to perform on destruction.
|
||||||
*/
|
*/
|
||||||
private String[] destroyActions;
|
private String[] destroyActions;
|
||||||
|
/**
|
||||||
|
* List of actions to perform on break.
|
||||||
|
*/
|
||||||
|
private String[] breakActions;
|
||||||
/**
|
/**
|
||||||
* List of actions to perform on left click.
|
* List of actions to perform on left click.
|
||||||
*/
|
*/
|
||||||
@ -104,6 +108,20 @@ public void setDestroyActions(String[] actions) {
|
|||||||
this.destroyActions = actions;
|
this.destroyActions = actions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String[] getBreakActions() {
|
||||||
|
return breakActions;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param actions
|
||||||
|
*/
|
||||||
|
public void setBreakActions(String[] actions) {
|
||||||
|
this.breakActions = actions;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@ -243,6 +261,42 @@ public void tell(String itemName) {
|
|||||||
return process(block.getType(), player, destroyActions, handler);
|
return process(block.getType(), player, destroyActions, handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called on block break. Returns true to let the action pass
|
||||||
|
* through.
|
||||||
|
*
|
||||||
|
* @param block
|
||||||
|
* @param player
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public boolean onBreak(final Block block, final Player player) {
|
||||||
|
if (breakActions == null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
final BlacklistEntry entry = this;
|
||||||
|
|
||||||
|
ActionHandler handler = new ActionHandler() {
|
||||||
|
public void log(String itemName) {
|
||||||
|
blacklist.getLogger().logBreakAttempt(player, block);
|
||||||
|
}
|
||||||
|
public void kick(String itemName) {
|
||||||
|
player.kick("You are not allowed to break " + itemName);
|
||||||
|
}
|
||||||
|
public void ban(String itemName) {
|
||||||
|
entry.banPlayer(player, "Banned: You are not allowed to break " + itemName);
|
||||||
|
}
|
||||||
|
public void notifyAdmins(String itemName) {
|
||||||
|
entry.notifyAdmins(player.getName() + " tried to break " + itemName + ".");
|
||||||
|
}
|
||||||
|
public void tell(String itemName) {
|
||||||
|
player.sendMessage(Colors.Yellow + "You are not allowed to break " + itemName + ".");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return process(block.getType(), player, breakActions, handler);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called on left click. Returns true to let the action pass through.
|
* Called on left click. Returns true to let the action pass through.
|
||||||
*
|
*
|
||||||
|
@ -70,6 +70,18 @@ public void logDestroyAttempt(Player player, Block block) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Log a block break attempt.
|
||||||
|
*
|
||||||
|
* @param player
|
||||||
|
* @param block
|
||||||
|
*/
|
||||||
|
public void logBreakAttempt(Player player, Block block) {
|
||||||
|
for (BlacklistLoggerHandler handler : handlers) {
|
||||||
|
handler.logBreakAttempt(player, block);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Log a right click on attempt.
|
* Log a right click on attempt.
|
||||||
*
|
*
|
||||||
|
@ -30,6 +30,13 @@ public interface BlacklistLoggerHandler {
|
|||||||
* @param block
|
* @param block
|
||||||
*/
|
*/
|
||||||
public void logDestroyAttempt(Player player, Block block);
|
public void logDestroyAttempt(Player player, Block block);
|
||||||
|
/**
|
||||||
|
* Log a block break attempt.
|
||||||
|
*
|
||||||
|
* @param player
|
||||||
|
* @param block
|
||||||
|
*/
|
||||||
|
public void logBreakAttempt(Player player, Block block);
|
||||||
/**
|
/**
|
||||||
* Log a right click on attempt.
|
* Log a right click on attempt.
|
||||||
*
|
*
|
||||||
|
@ -29,7 +29,7 @@ public class ConsoleLoggerHandler implements BlacklistLoggerHandler {
|
|||||||
* Logger.
|
* Logger.
|
||||||
*/
|
*/
|
||||||
private static final Logger logger = Logger.getLogger("Minecraft.WorldGuard");
|
private static final Logger logger = Logger.getLogger("Minecraft.WorldGuard");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Log a block destroy attempt.
|
* Log a block destroy attempt.
|
||||||
*
|
*
|
||||||
@ -41,6 +41,17 @@ public void logDestroyAttempt(Player player, Block block) {
|
|||||||
+ " tried to destroy " + getFriendlyItemName(block.getType()));
|
+ " tried to destroy " + getFriendlyItemName(block.getType()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Log a block break attempt.
|
||||||
|
*
|
||||||
|
* @param player
|
||||||
|
* @param block
|
||||||
|
*/
|
||||||
|
public void logBreakAttempt(Player player, Block block) {
|
||||||
|
logger.log(Level.INFO, "WorldGuard: " + player.getName()
|
||||||
|
+ " tried to break " + getFriendlyItemName(block.getType()));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Log a right click on attempt.
|
* Log a right click on attempt.
|
||||||
*
|
*
|
||||||
|
@ -112,7 +112,7 @@ private void logEvent(String event, String name, int x, int y, int z, int item)
|
|||||||
+ e.getMessage());
|
+ e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Log a block destroy attempt.
|
* Log a block destroy attempt.
|
||||||
*
|
*
|
||||||
@ -124,6 +124,17 @@ public void logDestroyAttempt(Player player, Block block) {
|
|||||||
block.getX(), block.getY(), block.getZ(), block.getType());
|
block.getX(), block.getY(), block.getZ(), block.getType());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Log a block break attempt.
|
||||||
|
*
|
||||||
|
* @param player
|
||||||
|
* @param block
|
||||||
|
*/
|
||||||
|
public void logBreakAttempt(Player player, Block block) {
|
||||||
|
logEvent("BREAK", player.getName(),
|
||||||
|
block.getX(), block.getY(), block.getZ(), block.getType());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Log a right click on attempt.
|
* Log a right click on attempt.
|
||||||
*
|
*
|
||||||
|
@ -215,6 +215,16 @@ public void logDestroyAttempt(Player player, Block block) {
|
|||||||
log(player, "Tried to destroy " + getFriendlyItemName(block.getType()));
|
log(player, "Tried to destroy " + getFriendlyItemName(block.getType()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Log a block break attempt.
|
||||||
|
*
|
||||||
|
* @param player
|
||||||
|
* @param block
|
||||||
|
*/
|
||||||
|
public void logBreakAttempt(Player player, Block block) {
|
||||||
|
log(player, "Tried to break " + getFriendlyItemName(block.getType()));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Log a right click on attempt.
|
* Log a right click on attempt.
|
||||||
*
|
*
|
||||||
|
@ -71,6 +71,8 @@ public void initialize() {
|
|||||||
PluginListener.Priority.HIGH);
|
PluginListener.Priority.HIGH);
|
||||||
loader.addListener(PluginLoader.Hook.BLOCK_DESTROYED, listener, this,
|
loader.addListener(PluginLoader.Hook.BLOCK_DESTROYED, listener, this,
|
||||||
PluginListener.Priority.CRITICAL);
|
PluginListener.Priority.CRITICAL);
|
||||||
|
loader.addListener(PluginLoader.Hook.BLOCK_BROKEN, listener, this,
|
||||||
|
PluginListener.Priority.HIGH);
|
||||||
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,
|
||||||
|
@ -516,6 +516,23 @@ else if (type == 18) { // Leaves
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when a person actually breaks the block.
|
||||||
|
*
|
||||||
|
* @param player
|
||||||
|
* @param block
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public boolean onBlockBreak(Player player, Block block) {
|
||||||
|
if (blacklist != null) {
|
||||||
|
if (!blacklist.onBreak(block, player)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when either a sign, chest or furnace is changed.
|
* Called when either a sign, chest or furnace is changed.
|
||||||
*
|
*
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
#
|
#
|
||||||
# Events:
|
# Events:
|
||||||
# - on-destroy (when a block of this type is being destroyed)
|
# - on-destroy (when a block of this type is being destroyed)
|
||||||
|
# - on-break (when a block of this type is about to be broken)
|
||||||
# - on-destroy-with (the item/block held by the user while destroying)
|
# - on-destroy-with (the item/block held by the user while destroying)
|
||||||
# - on-create (the item/block in the user's inventory is being created)
|
# - on-create (the item/block in the user's inventory is being created)
|
||||||
# - on-use (the block is right clicked)
|
# - on-use (the block is right clicked)
|
||||||
@ -67,4 +68,7 @@
|
|||||||
#on-destroy=notify,deny,log
|
#on-destroy=notify,deny,log
|
||||||
|
|
||||||
#[cobblestone]
|
#[cobblestone]
|
||||||
#on-create=deny,tell,log
|
#on-create=deny,tell,log
|
||||||
|
|
||||||
|
#[lever]
|
||||||
|
#on-break=deny
|
Loading…
Reference in New Issue
Block a user