Changed blacklist hooks.

This commit is contained in:
sk89q 2010-12-25 22:16:45 -08:00
parent b28202f1cb
commit 696ae7c967
9 changed files with 196 additions and 79 deletions

View File

@ -141,20 +141,20 @@ public boolean onDestroyWith(int item, Player player) {
}
/**
* Called on right click. Returns true to let the action pass through.
* Called on place. Returns true to let the action pass through.
*
* @param item
* @param player
* @return
*/
public boolean onCreate(int item, Player player) {
public boolean onPlace(int item, Player player) {
List<BlacklistEntry> entries = getEntries(item);
if (entries == null) {
return true;
}
boolean ret = true;
for (BlacklistEntry entry : entries) {
if (!entry.onCreate(item, player)) {
if (!entry.onPlace(item, player)) {
ret = false;
}
}
@ -164,18 +164,39 @@ public boolean onCreate(int item, Player player) {
/**
* Called on right click upon. Returns true to let the action pass through.
*
* @param item
* @param block
* @param player
* @return
*/
public boolean onUse(Block block, Player player) {
public boolean onRightClick(Block block, Player player) {
List<BlacklistEntry> entries = getEntries(block.getType());
if (entries == null) {
return true;
}
boolean ret = true;
for (BlacklistEntry entry : entries) {
if (!entry.onUse(block, player)) {
if (!entry.onRightClick(block, player)) {
ret = false;
}
}
return ret;
}
/**
* Called on item use. Returns true to let the action pass through.
*
* @param item
* @param player
* @return
*/
public boolean onUse(int item, Player player) {
List<BlacklistEntry> entries = getEntries(item);
if (entries == null) {
return true;
}
boolean ret = true;
for (BlacklistEntry entry : entries) {
if (!entry.onUse(item, player)) {
ret = false;
}
}
@ -345,12 +366,12 @@ public void load(File file) throws IOException {
} else if (parts[0].equalsIgnoreCase("on-left")
|| parts[0].equalsIgnoreCase("on-destroy-with")) {
entry.setDestroyWithActions(parts[1].split(","));
} else if (parts[0].equalsIgnoreCase("on-right")
|| parts[0].equalsIgnoreCase("on-create")) {
entry.setCreateActions(parts[1].split(","));
} else if (parts[0].equalsIgnoreCase("on-right-on")
|| parts[0].equalsIgnoreCase("on-use")) {
} else if (parts[0].equalsIgnoreCase("on-place")) {
entry.setPlaceActions(parts[1].split(","));
} else if (parts[0].equalsIgnoreCase("on-use")) {
entry.setUseActions(parts[1].split(","));
} else if (parts[0].equalsIgnoreCase("on-right-click")) {
entry.setRightClickActions(parts[1].split(","));
} else if (parts[0].equalsIgnoreCase("on-drop")) {
entry.setDropActions(parts[1].split(","));
} else if (parts[0].equalsIgnoreCase("on-acquire")) {

View File

@ -55,13 +55,17 @@ public class BlacklistEntry {
*/
private String[] destroyWithActions;
/**
* List of actions to perform on right click.
* List of actions to perform on block placement.
*/
private String[] createActions;
private String[] placeActions;
/**
* List of actions to perform on item use.
*/
private String[] useActions;
/**
* List of actions to perform on right click upon.
*/
private String[] useActions;
private String[] rightClickActions;
/**
* List of actions to perform on drop.
*/
@ -160,17 +164,17 @@ public void setDestroyWithActions(String[] actions) {
}
/**
* @return the rightClickActions
* @return
*/
public String[] getCreateActions() {
return createActions;
public String[] getPlaceActions() {
return placeActions;
}
/**
* @param actions
*/
public void setCreateActions(String[] actions) {
this.createActions = actions;
public void setPlaceActions(String[] actions) {
this.placeActions = actions;
}
/**
@ -187,6 +191,20 @@ public void setUseActions(String[] actions) {
this.useActions = actions;
}
/**
* @return
*/
public String[] getRightClickActions() {
return rightClickActions;
}
/**
* @param actions
*/
public void setRightClickActions(String[] actions) {
this.rightClickActions = actions;
}
/**
* @return
*/
@ -401,14 +419,14 @@ public void tell(String itemName) {
}
/**
* Called on right click. Returns true to let the action pass through.
* Called on block placement. Returns true to let the action pass through.
*
* @param item
* @param player
* @return
*/
public boolean onCreate(final int item, final Player player) {
if (createActions == null) {
public boolean onPlace(final int item, final Player player) {
if (placeActions == null) {
return true;
}
@ -416,7 +434,7 @@ public boolean onCreate(final int item, final Player player) {
ActionHandler handler = new ActionHandler() {
public void log(String itemName) {
blacklist.getLogger().logCreateAttempt(player, item, comment);
blacklist.getLogger().logPlaceAttempt(player, item, comment);
}
public void kick(String itemName) {
player.kick("You can't place " + itemName);
@ -433,7 +451,43 @@ public void tell(String itemName) {
}
};
return process(item, player, createActions, handler, true, false);
return process(item, player, placeActions, handler, true, false);
}
/**
* Called on use. Returns true to let the action pass through.
*
* @param item
* @param player
* @return
*/
public boolean onUse(final int item, final Player player) {
if (useActions == null) {
return true;
}
final BlacklistEntry entry = this;
ActionHandler handler = new ActionHandler() {
public void log(String itemName) {
blacklist.getLogger().logUseAttempt(player, item, comment);
}
public void kick(String itemName) {
player.kick("You can't use " + itemName);
}
public void ban(String itemName) {
entry.banPlayer(player, "Banned: You can't use " + itemName);
}
public void notifyAdmins(String itemName) {
entry.notifyAdmins(player.getName() + " (use) " + itemName
+ (comment != null ? " (" + comment + ")" : "") + ".");
}
public void tell(String itemName) {
player.sendMessage(Colors.Yellow + "You're not allowed to use " + itemName + ".");
}
};
return process(item, player, useActions, handler, false, false);
}
/**
@ -443,7 +497,7 @@ public void tell(String itemName) {
* @param player
* @return
*/
public boolean onUse(final Block block, final Player player) {
public boolean onRightClick(final Block block, final Player player) {
if (useActions == null) {
return true;
}
@ -452,7 +506,7 @@ public boolean onUse(final Block block, final Player player) {
ActionHandler handler = new ActionHandler() {
public void log(String itemName) {
blacklist.getLogger().logUseAttempt(player, block, comment);
blacklist.getLogger().logRightClickAttempt(player, block, comment);
}
public void kick(String itemName) {
player.kick("You can't use " + itemName);

View File

@ -88,9 +88,21 @@ public void logBreakAttempt(Player player, Block block, String comment) {
* @param player
* @param block
*/
public void logUseAttempt(Player player, Block block, String comment) {
public void logUseAttempt(Player player, int item, String comment) {
for (BlacklistLoggerHandler handler : handlers) {
handler.logUseAttempt(player, block, comment);
handler.logUseAttempt(player, item, comment);
}
}
/**
* Log a right click on attempt.
*
* @param player
* @param block
*/
public void logRightClickAttempt(Player player, Block block, String comment) {
for (BlacklistLoggerHandler handler : handlers) {
handler.logRightClickAttempt(player, block, comment);
}
}
@ -107,14 +119,14 @@ public void logDestroyWithAttempt(Player player, int item, String comment) {
}
/**
* Log a right click attempt.
* Log a place attempt.
*
* @param player
* @param item
*/
public void logCreateAttempt(Player player, int item, String comment) {
public void logPlaceAttempt(Player player, int item, String comment) {
for (BlacklistLoggerHandler handler : handlers) {
handler.logCreateAttempt(player, item, comment);
handler.logPlaceAttempt(player, item, comment);
}
}

View File

@ -38,12 +38,12 @@ public interface BlacklistLoggerHandler {
*/
public void logBreakAttempt(Player player, Block block, String comment);
/**
* Log a right click on attempt.
* Log a use attempt.
*
* @param player
* @param block
*/
public void logUseAttempt(Player player, Block block, String comment);
public void logUseAttempt(Player player, int item, String comment);
/**
* Right a left click attempt.
*
@ -52,12 +52,19 @@ public interface BlacklistLoggerHandler {
*/
public void logDestroyWithAttempt(Player player, int item, String comment);
/**
* Log a right click attempt.
* Log a place attempt.
*
* @param player
* @param item
*/
public void logCreateAttempt(Player player, int item, String comment);
public void logPlaceAttempt(Player player, int item, String comment);
/**
* Log a right click on attempt.
*
* @param player
* @param item
*/
public void logRightClickAttempt(Player player, Block block, String comment);
/**
* Log a drop attempt.
*

View File

@ -60,9 +60,9 @@ public void logBreakAttempt(Player player, Block block, String comment) {
* @param player
* @param block
*/
public void logUseAttempt(Player player, Block block, String comment) {
public void logRightClickAttempt(Player player, Block block, String comment) {
logger.log(Level.INFO, "WorldGuard: " + player.getName()
+ " tried to use " + getFriendlyItemName(block.getType())
+ " tried to right click " + getFriendlyItemName(block.getType())
+ (comment != null ? " (" + comment + ")" : ""));
}
@ -84,9 +84,21 @@ public void logDestroyWithAttempt(Player player, int item, String comment) {
* @param player
* @param item
*/
public void logCreateAttempt(Player player, int item, String comment) {
public void logPlaceAttempt(Player player, int item, String comment) {
logger.log(Level.INFO, "WorldGuard: " + player.getName()
+ " tried to create " + getFriendlyItemName(item)
+ " tried to place " + getFriendlyItemName(item)
+ (comment != null ? " (" + comment + ")" : ""));
}
/**
* Log a use attempt.
*
* @param player
* @param item
*/
public void logUseAttempt(Player player, int item, String comment) {
logger.log(Level.INFO, "WorldGuard: " + player.getName()
+ " tried to use " + getFriendlyItemName(item)
+ (comment != null ? " (" + comment + ")" : ""));
}

View File

@ -146,8 +146,8 @@ public void logBreakAttempt(Player player, Block block, String comment) {
* @param player
* @param block
*/
public void logUseAttempt(Player player, Block block, String comment) {
logEvent("USE", player.getName(),
public void logRightClickAttempt(Player player, Block block, String comment) {
logEvent("RIGHT_CLICK", player.getName(),
block.getX(), block.getY(), block.getZ(), block.getType(),
comment);
}
@ -165,13 +165,25 @@ public void logDestroyWithAttempt(Player player, int item, String comment) {
}
/**
* Log a right click attempt.
* Log a place attempt.
*
* @param player
* @param item
*/
public void logCreateAttempt(Player player, int item, String comment) {
logEvent("CREATE", player.getName(),
public void logPlaceAttempt(Player player, int item, String comment) {
logEvent("PLACE", player.getName(),
(int)Math.floor(player.getX()), (int)Math.floor(player.getY()),
(int)Math.floor(player.getZ()), item, comment);
}
/**
* Log a use attempt.
*
* @param player
* @param item
*/
public void logUseAttempt(Player player, int item, String comment) {
logEvent("USE", player.getName(),
(int)Math.floor(player.getX()), (int)Math.floor(player.getY()),
(int)Math.floor(player.getZ()), item, comment);
}

View File

@ -246,8 +246,8 @@ public void logBreakAttempt(Player player, Block block, String comment) {
* @param player
* @param block
*/
public void logUseAttempt(Player player, Block block, String comment) {
log(player, "Tried to use " + getFriendlyItemName(block.getType())
public void logRightClickAttempt(Player player, Block block, String comment) {
log(player, "Tried to right click " + getFriendlyItemName(block.getType())
+ " " + getCoordinates(block),
comment);
}
@ -268,8 +268,18 @@ public void logDestroyWithAttempt(Player player, int item, String comment) {
* @param player
* @param item
*/
public void logCreateAttempt(Player player, int item, String comment) {
log(player, "Tried to create " + getFriendlyItemName(item), comment);
public void logPlaceAttempt(Player player, int item, String comment) {
log(player, "Tried to place " + getFriendlyItemName(item), comment);
}
/**
* Log a block use attempt.
*
* @param player
* @param item
*/
public void logUseAttempt(Player player, int item, String comment) {
log(player, "Tried to use " + getFriendlyItemName(item), comment);
}
/**

View File

@ -634,10 +634,8 @@ public boolean onItemUse(Player player, Block blockPlaced,
if (blacklist != null) {
int itemId = item.getItemId();
if (itemId >= 325 && itemId <= 327) {
if (!blacklist.onCreate(itemId, player)) {
return true;
}
if (!blacklist.onUse(itemId, player)) {
return true;
}
}
@ -660,13 +658,11 @@ public boolean onBlockPlace(Player player, Block blockPlaced,
int itemId = itemInHand.getItemId();
if (blacklist != null) {
if (itemId < 325 || itemId > 327) {
if (!blacklist.onCreate(itemId, player)) {
return true;
}
if (!blacklist.onPlace(itemId, player)) {
return true;
}
if (!blacklist.onUse(blockClicked, player)) {
if (!blacklist.onRightClick(blockClicked, player)) {
return true;
}
}
@ -702,8 +698,6 @@ public boolean onBlockPlace(Player player, Block blockPlaced,
*/
@Override
public boolean onBlockDestroy(Player player, Block block) {
int type = block.getType();
if (blacklist != null) {
if (!blacklist.onDestroyWith(player.getItemInHand(), player)) {
return true;
@ -747,7 +741,7 @@ public boolean onOpenInventory(Player player, Inventory inventory) {
/*Block block = new Block(54, complexBlock.getX(),
complexBlock.getY(), complexBlock.getZ());
if (!blacklist.onSilentUse(block, player)) {
if (!blacklist.onRightClick(block, player)) {
return true;
}*/
@ -858,10 +852,6 @@ public boolean onExplode(Block block) {
*/
@Override
public boolean onFlow(Block blockFrom, Block blockTo) {
int x = blockFrom.getX();
int y = blockFrom.getY();
int z = blockFrom.getZ();
boolean isWater = blockFrom.getType() == 8 || blockFrom.getType() == 9;
boolean isLava = blockFrom.getType() == 10 || blockFrom.getType() == 11;

View File

@ -11,7 +11,7 @@
# Example to block ore and catch some events:
# [coalore,goldore,ironore]
# on-destroy-with=deny,log,kick
# on-create=deny,tell
# on-place=deny,tell
#
# Options:
# - ignore-groups (comma-delimited list of groups to not affect)
@ -22,8 +22,9 @@
# - 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-create (the item/block in the user's inventory is being created)
# - on-use (the block is right clicked)
# - on-place (a block is being placed)
# - on-use (an item like a lighter is being used)
# - on-right-click (the block is right clicked -- curently INEFFECTIVE)
# - on-drop (the item is being dropped from the player's inventory)
# - on-acquire (the item enters a player's inventory via some method)
#
@ -68,24 +69,22 @@
# Some examples follow. Remember to remove # in front if you want them
# to work for you!
# Deny lava buckets
#[lavabucket]
#ignore-groups=admins,mods
#on-destroy-with=deny,log,kick
#on-create=deny,tell
#on-use=deny,tell
# Deny lighter usage
#[259]
#on-use=deny,tell
# Deny some ore
#[coalore,goldore,ironore]
#ignore-groups=admins,mods,vip
#ignore-groups=admins,mods
#on-destroy=notify,deny,log
#[cobblestone]
#on-create=deny,tell,log
#on-place=deny,tell,log
#[lever]
#on-break=deny
# This is an example of the 'durability cheat' workaround that destroys your
# tool when you drop it
#[256,257,258,259,267,268,269,270,271,272,273,274,275,276,277,278,279,283,284,285,286,290,291,292,293,294,346]
#on-drop=deny,tell
#comment=Durability Hacks
#message=Your tool was destroyed
#on-break=deny,tell