Compare commits

...
7 Commits
14 changed files with 402 additions and 93 deletions

No files matched your search

+21
View File
@@ -1,3 +1,24 @@
1.3
- UPGRADE WARNING: If you are using database logging, you must add a
NULL 'comment' VARCHAR field to the table. The line of SQL that you
can run for MySQL can be found in blacklist_table.sql.
- Improved plugin compatibility with the block lag fix. For maximum
compatibility, you must now list WorldGuard as the first plugin in
server.properties and you cannot reload or enable the plugin
while the server is up. This is for bad plugins that unnecessarily
use the "critical" priority for its hooks like the LWC. Most plugins
don't do that though, so this won't apply for most people.
- Fixed signs being blank if they were denied via the blacklist.
- Added on-break event to the blacklist.
- Added comments and messages. Comments are only for your own use and they
are printed with the log and notify actions of the blacklist. The
message replaces the message that is shown the user and it is optional.
- The blacklist notification messages are now more compact and are
light grey instead of light purple.
- The notify, log, and tell actions will now trigger every time for the
on-break, on-create, on-drop events rather than wait 3 seconds between
events for the same item or block for a player.
1.2
- /stopfire and /allowfire disable and enable fire spreading globally.
- Block lag fix slightly improved in accuracy for item drops.
+6 -1
View File
@@ -92,7 +92,12 @@ WorldGuard on your server. You can either restart your server or use
friendly message than if you used the 'tell' action of the blacklist).
- block-lag-fix (def. false)
Attempts to fix block lag.
Attempts to fix block lag. For maximum compatibility with other plugins,
you must list WorldGuard as the first plugin in server.properties and
you cannot reload or enable WorldGuard while the server is up.
This is for bad plugins that unnecessarily use the "critical" priority
for its hooks like the LWC. Most plugins, the popular protection ones
included, don't do that though so this won't apply for most people.
- log-console (def. true)
For blacklist log actions, print to console.
+5
View File
@@ -12,5 +12,10 @@ CREATE TABLE `blacklist_events` (
`z` int(11) NOT NULL,
`item` int(11) NOT NULL,
`time` int(11) NOT NULL,
`comment` varchar(255) NULL,
PRIMARY KEY (`id`)
);
-- Required update if you have an older version of the table:
ALTER TABLE `blacklist_events` ADD `comment` VARCHAR( 255 ) NULL
+1 -1
View File
@@ -1,2 +1,2 @@
Manifest-Version: 1.0
WorldGuard-Version: 1.2
WorldGuard-Version: 1.3
+28
View File
@@ -92,6 +92,28 @@ public class Blacklist {
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.
*
@@ -269,6 +291,8 @@ public class Blacklist {
entry.setIgnoreGroups(parts[1].split(","));
} else if (parts[0].equalsIgnoreCase("on-destroy")) {
entry.setDestroyActions(parts[1].split(","));
} else if (parts[0].equalsIgnoreCase("on-break")) {
entry.setBreakActions(parts[1].split(","));
} else if (parts[0].equalsIgnoreCase("on-left")
|| parts[0].equalsIgnoreCase("on-destroy-with")) {
entry.setDestroyWithActions(parts[1].split(","));
@@ -280,6 +304,10 @@ public class Blacklist {
entry.setUseActions(parts[1].split(","));
} else if (parts[0].equalsIgnoreCase("on-drop")) {
entry.setDropActions(parts[1].split(","));
} else if (parts[0].equalsIgnoreCase("message")) {
entry.setMessage(parts[1].trim());
} else if (parts[0].equalsIgnoreCase("comment")) {
entry.setComment(parts[1].trim());
} else {
unknownOption = true;
}
+150 -25
View File
@@ -46,6 +46,10 @@ public class BlacklistEntry {
* List of actions to perform on destruction.
*/
private String[] destroyActions;
/**
* List of actions to perform on break.
*/
private String[] breakActions;
/**
* List of actions to perform on left click.
*/
@@ -62,6 +66,11 @@ public class BlacklistEntry {
* List of actions to perform on drop.
*/
private String[] dropActions;
/**
* Comment for the log.
*/
private String message;
private String comment;
/**
* Construct the object.
@@ -104,6 +113,20 @@ public class BlacklistEntry {
this.destroyActions = actions;
}
/**
* @return
*/
public String[] getBreakActions() {
return breakActions;
}
/**
* @param actions
*/
public void setBreakActions(String[] actions) {
this.breakActions = actions;
}
/**
* @return
*/
@@ -160,6 +183,34 @@ public class BlacklistEntry {
this.dropActions = actions;
}
/**
* @return the message
*/
public String getMessage() {
return message;
}
/**
* @param message the message to set
*/
public void setMessage(String message) {
this.message = message;
}
/**
* @return the comment
*/
public String getComment() {
return comment;
}
/**
* @param comment the comment to set
*/
public void setComment(String comment) {
this.comment = comment;
}
/**
* Returns true if this player should be ignored.
*
@@ -188,7 +239,7 @@ public class BlacklistEntry {
for (Player player : etc.getServer().getPlayerList()) {
if (player.canUseCommand("/wprotectalerts")
|| player.canUseCommand("/worldguardnotify")) {
player.sendMessage(Colors.LightPurple + "WorldGuard: " + str);
player.sendMessage(Colors.LightGray + "WG: " + str);
}
}
}
@@ -224,7 +275,7 @@ public class BlacklistEntry {
ActionHandler handler = new ActionHandler() {
public void log(String itemName) {
blacklist.getLogger().logDestroyAttempt(player, block);
blacklist.getLogger().logDestroyAttempt(player, block, comment);
}
public void kick(String itemName) {
player.kick("You are not allowed to destroy " + itemName);
@@ -233,14 +284,52 @@ public class BlacklistEntry {
entry.banPlayer(player, "Banned: You are not allowed to destroy " + itemName);
}
public void notifyAdmins(String itemName) {
entry.notifyAdmins(player.getName() + " tried to destroy " + itemName + ".");
entry.notifyAdmins(player.getName() + " (destroy) " + itemName
+ (comment != null ? " (" + comment + ")" : "") + ".");
}
public void tell(String itemName) {
player.sendMessage(Colors.Yellow + "You are not allowed to destroy " + itemName + ".");
}
};
return process(block.getType(), player, destroyActions, handler);
return process(block.getType(), player, destroyActions, handler, false);
}
/**
* 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, comment);
}
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() + " (break) " + itemName
+ (comment != null ? " (" + comment + ")" : "") + ".");
}
public void tell(String itemName) {
player.sendMessage(Colors.Yellow + "You are not allowed to break " + itemName + ".");
}
};
return process(block.getType(), player, breakActions, handler, true);
}
/**
@@ -259,7 +348,7 @@ public class BlacklistEntry {
ActionHandler handler = new ActionHandler() {
public void log(String itemName) {
blacklist.getLogger().logDestroyWithAttempt(player, item);
blacklist.getLogger().logDestroyWithAttempt(player, item, comment);
}
public void kick(String itemName) {
player.kick("You can't destroy with " + itemName);
@@ -268,14 +357,15 @@ public class BlacklistEntry {
entry.banPlayer(player, "Banned: You can't destroy with " + itemName);
}
public void notifyAdmins(String itemName) {
entry.notifyAdmins(player.getName() + " tried to destroyed with " + itemName + ".");
entry.notifyAdmins(player.getName() + " (destroy w/) " + itemName
+ (comment != null ? " (" + comment + ")" : "") + ".");
}
public void tell(String itemName) {
player.sendMessage(Colors.Yellow + "You can't destroy with " + itemName + ".");
}
};
return process(item, player, destroyWithActions, handler);
return process(item, player, destroyWithActions, handler, false);
}
/**
@@ -294,23 +384,24 @@ public class BlacklistEntry {
ActionHandler handler = new ActionHandler() {
public void log(String itemName) {
blacklist.getLogger().logCreateAttempt(player, item);
blacklist.getLogger().logCreateAttempt(player, item, comment);
}
public void kick(String itemName) {
player.kick("You can't create " + itemName);
player.kick("You can't place " + itemName);
}
public void ban(String itemName) {
entry.banPlayer(player, "Banned: You can't create " + itemName);
entry.banPlayer(player, "Banned: You can't place " + itemName);
}
public void notifyAdmins(String itemName) {
entry.notifyAdmins(player.getName() + " tried to create " + itemName + ".");
entry.notifyAdmins(player.getName() + " (place) " + itemName
+ (comment != null ? " (" + comment + ")" : "") + ".");
}
public void tell(String itemName) {
player.sendMessage(Colors.Yellow + "You can't create " + itemName + ".");
player.sendMessage(Colors.Yellow + "You can't place " + itemName + ".");
}
};
return process(item, player, createActions, handler);
return process(item, player, createActions, handler, true);
}
/**
@@ -329,7 +420,7 @@ public class BlacklistEntry {
ActionHandler handler = new ActionHandler() {
public void log(String itemName) {
blacklist.getLogger().logUseAttempt(player, block);
blacklist.getLogger().logUseAttempt(player, block, comment);
}
public void kick(String itemName) {
player.kick("You can't use " + itemName);
@@ -338,14 +429,15 @@ public class BlacklistEntry {
entry.banPlayer(player, "Banned: You can't use " + itemName);
}
public void notifyAdmins(String itemName) {
entry.notifyAdmins(player.getName() + " tried to use " + 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(block.getType(), player, useActions, handler);
return process(block.getType(), player, useActions, handler, false);
}
/**
@@ -373,7 +465,7 @@ public class BlacklistEntry {
}
};
return process(block.getType(), player, useActions, handler);
return process(block.getType(), player, useActions, handler, false);
}
/**
@@ -392,7 +484,7 @@ public class BlacklistEntry {
ActionHandler handler = new ActionHandler() {
public void log(String itemName) {
blacklist.getLogger().logDropAttempt(player, item);
blacklist.getLogger().logDropAttempt(player, item, comment);
}
public void kick(String itemName) {
player.kick("You can't drop " + itemName);
@@ -401,14 +493,15 @@ public class BlacklistEntry {
entry.banPlayer(player, "Banned: You can't drop " + itemName);
}
public void notifyAdmins(String itemName) {
entry.notifyAdmins(player.getName() + " tried to drop " + itemName + ".");
entry.notifyAdmins(player.getName() + " (drop) " + itemName
+ (comment != null ? " (" + comment + ")" : "") + ".");
}
public void tell(String itemName) {
player.sendMessage(Colors.Yellow + "You're not allowed to drop " + itemName + ".");
}
};
return process(item, player, dropActions, handler);
return process(item, player, dropActions, handler, true);
}
/**
@@ -417,9 +510,13 @@ public class BlacklistEntry {
* @param id
* @param player
* @param actions
* @param handler
* @param allowRepeat
* @return
*/
private boolean process(int id, Player player, String[] actions, ActionHandler handler) {
private boolean process(int id, Player player, String[] actions,
ActionHandler handler, boolean allowRepeat) {
if (shouldIgnore(player)) {
return true;
}
@@ -444,19 +541,47 @@ public class BlacklistEntry {
boolean ret = true;
for (String action : actions) {
// Deny
if (action.equalsIgnoreCase("deny")) {
ret = false;
// Kick
} else if (action.equalsIgnoreCase("kick")) {
handler.kick(etc.getDataSource().getItem(id));
if (this.message != null) {
player.kick(String.format(this.message,
etc.getDataSource().getItem(id)));
} else {
handler.kick(etc.getDataSource().getItem(id));
}
// Ban
} else if (action.equalsIgnoreCase("ban")) {
handler.ban(etc.getDataSource().getItem(id));
} else if (!repeating) {
if (this.message != null) {
banPlayer(player, "Banned: " + String.format(this.message,
etc.getDataSource().getItem(id)));
} else {
handler.ban(etc.getDataSource().getItem(id));
}
} else if (!repeating || allowRepeat) {
// Notify
if (action.equalsIgnoreCase("notify")) {
handler.notifyAdmins(etc.getDataSource().getItem(id));
// Log
} else if (action.equalsIgnoreCase("log")) {
handler.log(etc.getDataSource().getItem(id));
} else if (!repeating && action.equalsIgnoreCase("tell")) {
handler.tell(etc.getDataSource().getItem(id));
// Tell
} else if (action.equalsIgnoreCase("tell")) {
if (this.message != null) {
player.sendMessage(Colors.Yellow +
String.format(message, etc.getDataSource().getItem(id))
+ ".");
} else {
handler.tell(etc.getDataSource().getItem(id));
}
}
}
}
+22 -10
View File
@@ -64,9 +64,21 @@ public class BlacklistLogger implements BlacklistLoggerHandler {
* @param player
* @param block
*/
public void logDestroyAttempt(Player player, Block block) {
public void logDestroyAttempt(Player player, Block block, String comment) {
for (BlacklistLoggerHandler handler : handlers) {
handler.logDestroyAttempt(player, block);
handler.logDestroyAttempt(player, block, comment);
}
}
/**
* Log a block break attempt.
*
* @param player
* @param block
*/
public void logBreakAttempt(Player player, Block block, String comment) {
for (BlacklistLoggerHandler handler : handlers) {
handler.logBreakAttempt(player, block, comment);
}
}
@@ -76,9 +88,9 @@ public class BlacklistLogger implements BlacklistLoggerHandler {
* @param player
* @param block
*/
public void logUseAttempt(Player player, Block block) {
public void logUseAttempt(Player player, Block block, String comment) {
for (BlacklistLoggerHandler handler : handlers) {
handler.logUseAttempt(player, block);
handler.logUseAttempt(player, block, comment);
}
}
@@ -88,9 +100,9 @@ public class BlacklistLogger implements BlacklistLoggerHandler {
* @param player
* @param item
*/
public void logDestroyWithAttempt(Player player, int item) {
public void logDestroyWithAttempt(Player player, int item, String comment) {
for (BlacklistLoggerHandler handler : handlers) {
handler.logDestroyWithAttempt(player, item);
handler.logDestroyWithAttempt(player, item, comment);
}
}
@@ -100,9 +112,9 @@ public class BlacklistLogger implements BlacklistLoggerHandler {
* @param player
* @param item
*/
public void logCreateAttempt(Player player, int item) {
public void logCreateAttempt(Player player, int item, String comment) {
for (BlacklistLoggerHandler handler : handlers) {
handler.logCreateAttempt(player, item);
handler.logCreateAttempt(player, item, comment);
}
}
@@ -112,9 +124,9 @@ public class BlacklistLogger implements BlacklistLoggerHandler {
* @param player
* @param item
*/
public void logDropAttempt(Player player, int item) {
public void logDropAttempt(Player player, int item, String comment) {
for (BlacklistLoggerHandler handler : handlers) {
handler.logDropAttempt(player, item);
handler.logDropAttempt(player, item, comment);
}
}
+12 -5
View File
@@ -29,35 +29,42 @@ public interface BlacklistLoggerHandler {
* @param player
* @param block
*/
public void logDestroyAttempt(Player player, Block block);
public void logDestroyAttempt(Player player, Block block, String comment);
/**
* Log a block break attempt.
*
* @param player
* @param block
*/
public void logBreakAttempt(Player player, Block block, String comment);
/**
* Log a right click on attempt.
*
* @param player
* @param block
*/
public void logUseAttempt(Player player, Block block);
public void logUseAttempt(Player player, Block block, String comment);
/**
* Right a left click attempt.
*
* @param player
* @param item
*/
public void logDestroyWithAttempt(Player player, int item);
public void logDestroyWithAttempt(Player player, int item, String comment);
/**
* Log a right click attempt.
*
* @param player
* @param item
*/
public void logCreateAttempt(Player player, int item);
public void logCreateAttempt(Player player, int item, String comment);
/**
* Log a drop attempt.
*
* @param player
* @param item
*/
public void logDropAttempt(Player player, int item);
public void logDropAttempt(Player player, int item, String comment);
/**
* Close the logger.
*/
+28 -11
View File
@@ -29,16 +29,29 @@ public class ConsoleLoggerHandler implements BlacklistLoggerHandler {
* Logger.
*/
private static final Logger logger = Logger.getLogger("Minecraft.WorldGuard");
/**
* Log a block destroy attempt.
*
* @param player
* @param block
*/
public void logDestroyAttempt(Player player, Block block) {
public void logDestroyAttempt(Player player, Block block, String comment) {
logger.log(Level.INFO, "WorldGuard: " + player.getName()
+ " tried to destroy " + getFriendlyItemName(block.getType()));
+ " tried to destroy " + getFriendlyItemName(block.getType())
+ (comment != null ? " (" + comment + ")" : ""));
}
/**
* Log a block break attempt.
*
* @param player
* @param block
*/
public void logBreakAttempt(Player player, Block block, String comment) {
logger.log(Level.INFO, "WorldGuard: " + player.getName()
+ " tried to break " + getFriendlyItemName(block.getType())
+ (comment != null ? " (" + comment + ")" : ""));
}
/**
@@ -47,9 +60,10 @@ public class ConsoleLoggerHandler implements BlacklistLoggerHandler {
* @param player
* @param block
*/
public void logUseAttempt(Player player, Block block) {
public void logUseAttempt(Player player, Block block, String comment) {
logger.log(Level.INFO, "WorldGuard: " + player.getName()
+ " tried to use " + getFriendlyItemName(block.getType()));
+ " tried to use " + getFriendlyItemName(block.getType())
+ (comment != null ? " (" + comment + ")" : ""));
}
/**
@@ -58,9 +72,10 @@ public class ConsoleLoggerHandler implements BlacklistLoggerHandler {
* @param player
* @param item
*/
public void logDestroyWithAttempt(Player player, int item) {
public void logDestroyWithAttempt(Player player, int item, String comment) {
logger.log(Level.INFO, "WorldGuard: " + player.getName()
+ " tried to destroy with " + getFriendlyItemName(item));
+ " tried to destroy with " + getFriendlyItemName(item)
+ (comment != null ? " (" + comment + ")" : ""));
}
/**
@@ -69,9 +84,10 @@ public class ConsoleLoggerHandler implements BlacklistLoggerHandler {
* @param player
* @param item
*/
public void logCreateAttempt(Player player, int item) {
public void logCreateAttempt(Player player, int item, String comment) {
logger.log(Level.INFO, "WorldGuard: " + player.getName()
+ " tried to create " + getFriendlyItemName(item));
+ " tried to create " + getFriendlyItemName(item)
+ (comment != null ? " (" + comment + ")" : ""));
}
/**
@@ -80,9 +96,10 @@ public class ConsoleLoggerHandler implements BlacklistLoggerHandler {
* @param player
* @param item
*/
public void logDropAttempt(Player player, int item) {
public void logDropAttempt(Player player, int item, String comment) {
logger.log(Level.INFO, "WorldGuard: " + player.getName()
+ " tried to drop " + getFriendlyItemName(item));
+ " tried to drop " + getFriendlyItemName(item)
+ (comment != null ? " (" + comment + ")" : ""));
}
/**
+31 -14
View File
@@ -91,14 +91,16 @@ public class DatabaseLoggerHandler implements BlacklistLoggerHandler {
* @param y
* @param z
* @param item
* @param comment
*/
private void logEvent(String event, String name, int x, int y, int z, int item) {
private void logEvent(String event, String name, int x, int y, int z, int item,
String comment) {
try {
Connection conn = getConnection();
PreparedStatement stmt = conn.prepareStatement(
"INSERT INTO " + table
+ "(event, player, x, y, z, item, time) VALUES "
+ "(?, ?, ?, ?, ?, ?, ?)");
+ "(event, player, x, y, z, item, time, comment) VALUES "
+ "(?, ?, ?, ?, ?, ?, ?, ?)");
stmt.setString(1, event);
stmt.setString(2, name);
stmt.setInt(3, x);
@@ -106,22 +108,36 @@ public class DatabaseLoggerHandler implements BlacklistLoggerHandler {
stmt.setInt(5, z);
stmt.setInt(6, item);
stmt.setInt(7, (int)(System.currentTimeMillis() / 1000));
stmt.setString(8, comment);
stmt.executeUpdate();
} catch (SQLException e) {
logger.log(Level.SEVERE, "Failed to log blacklist event to database: "
+ e.getMessage());
}
}
/**
* Log a block destroy attempt.
*
* @param player
* @param block
*/
public void logDestroyAttempt(Player player, Block block) {
public void logDestroyAttempt(Player player, Block block, String comment) {
logEvent("DESTROY", player.getName(),
block.getX(), block.getY(), block.getZ(), block.getType());
block.getX(), block.getY(), block.getZ(), block.getType(),
comment);
}
/**
* Log a block break attempt.
*
* @param player
* @param block
*/
public void logBreakAttempt(Player player, Block block, String comment) {
logEvent("BREAK", player.getName(),
block.getX(), block.getY(), block.getZ(), block.getType(),
comment);
}
/**
@@ -130,9 +146,10 @@ public class DatabaseLoggerHandler implements BlacklistLoggerHandler {
* @param player
* @param block
*/
public void logUseAttempt(Player player, Block block) {
public void logUseAttempt(Player player, Block block, String comment) {
logEvent("USE", player.getName(),
block.getX(), block.getY(), block.getZ(), block.getType());
block.getX(), block.getY(), block.getZ(), block.getType(),
comment);
}
/**
@@ -141,10 +158,10 @@ public class DatabaseLoggerHandler implements BlacklistLoggerHandler {
* @param player
* @param item
*/
public void logDestroyWithAttempt(Player player, int item) {
public void logDestroyWithAttempt(Player player, int item, String comment) {
logEvent("DESTROY_WITH", player.getName(),
(int)Math.floor(player.getX()), (int)Math.floor(player.getY()),
(int)Math.floor(player.getZ()), item);
(int)Math.floor(player.getZ()), item, comment);
}
/**
@@ -153,10 +170,10 @@ public class DatabaseLoggerHandler implements BlacklistLoggerHandler {
* @param player
* @param item
*/
public void logCreateAttempt(Player player, int item) {
public void logCreateAttempt(Player player, int item, String comment) {
logEvent("CREATE", player.getName(),
(int)Math.floor(player.getX()), (int)Math.floor(player.getY()),
(int)Math.floor(player.getZ()), item);
(int)Math.floor(player.getZ()), item, comment);
}
/**
@@ -165,10 +182,10 @@ public class DatabaseLoggerHandler implements BlacklistLoggerHandler {
* @param player
* @param item
*/
public void logDropAttempt(Player player, int item) {
public void logDropAttempt(Player player, int item, String comment) {
logEvent("DROP", player.getName(),
(int)Math.floor(player.getX()), (int)Math.floor(player.getY()),
(int)Math.floor(player.getZ()), item);
(int)Math.floor(player.getZ()), item, comment);
}
/**
+26 -12
View File
@@ -143,11 +143,12 @@ public class FileLoggerHandler implements BlacklistLoggerHandler {
* @param player
* @param message
*/
private void log(Player player, String message) {
private void log(Player player, String message, String comment) {
String path = buildPath(player.getName());
try {
String date = dateFormat.format(new Date());
String line = "[" + date + "] " + player.getName() + ": " + message + "\r\n";
String line = "[" + date + "] " + player.getName() + ": " + message
+ (comment != null ? " (" + comment + ")" : "") + "\r\n";
FileLoggerWriter writer = writers.get(path);
@@ -211,8 +212,20 @@ public class FileLoggerHandler implements BlacklistLoggerHandler {
* @param player
* @param block
*/
public void logDestroyAttempt(Player player, Block block) {
log(player, "Tried to destroy " + getFriendlyItemName(block.getType()));
public void logDestroyAttempt(Player player, Block block, String comment) {
log(player, "Tried to destroy " + getFriendlyItemName(block.getType()),
comment);
}
/**
* Log a block break attempt.
*
* @param player
* @param block
*/
public void logBreakAttempt(Player player, Block block, String comment) {
log(player, "Tried to break " + getFriendlyItemName(block.getType()),
comment);
}
/**
@@ -221,8 +234,9 @@ public class FileLoggerHandler implements BlacklistLoggerHandler {
* @param player
* @param block
*/
public void logUseAttempt(Player player, Block block) {
log(player, "Tried to use " + getFriendlyItemName(block.getType()));
public void logUseAttempt(Player player, Block block, String comment) {
log(player, "Tried to use " + getFriendlyItemName(block.getType()),
comment);
}
/**
@@ -231,8 +245,8 @@ public class FileLoggerHandler implements BlacklistLoggerHandler {
* @param player
* @param item
*/
public void logDestroyWithAttempt(Player player, int item) {
log(player, "Tried to destroy with " + getFriendlyItemName(item));
public void logDestroyWithAttempt(Player player, int item, String comment) {
log(player, "Tried to destroy with " + getFriendlyItemName(item), comment);
}
/**
@@ -241,8 +255,8 @@ public class FileLoggerHandler implements BlacklistLoggerHandler {
* @param player
* @param item
*/
public void logCreateAttempt(Player player, int item) {
log(player, "Tried to create " + getFriendlyItemName(item));
public void logCreateAttempt(Player player, int item, String comment) {
log(player, "Tried to create " + getFriendlyItemName(item), comment);
}
/**
@@ -251,8 +265,8 @@ public class FileLoggerHandler implements BlacklistLoggerHandler {
* @param player
* @param item
*/
public void logDropAttempt(Player player, int item) {
log(player, "Tried to drop " + getFriendlyItemName(item));
public void logDropAttempt(Player player, int item, String comment) {
log(player, "Tried to drop " + getFriendlyItemName(item), comment);
}
/**
+2
View File
@@ -70,6 +70,8 @@ public class WorldGuard extends Plugin {
loader.addListener(PluginLoader.Hook.BLOCK_CREATED, listener, this,
PluginListener.Priority.HIGH);
loader.addListener(PluginLoader.Hook.BLOCK_DESTROYED, listener, this,
PluginListener.Priority.CRITICAL);
loader.addListener(PluginLoader.Hook.BLOCK_BROKEN, listener, this,
PluginListener.Priority.HIGH);
loader.addListener(PluginLoader.Hook.DISCONNECT, listener, this,
PluginListener.Priority.HIGH);
+58 -13
View File
@@ -450,7 +450,7 @@ public class WorldGuardListener extends PluginListener {
// destroyed. Since this causes the hook to eventually call
// twice, we try to nullify it below
if (canDestroyBlock(player, block)) {
if (block.getStatus() == 3) {
if (block.getStatus() == 3 && canBreakBlock(player, block)) {
int dropItem = type;
int count = 1;
@@ -501,8 +501,7 @@ public class WorldGuardListener extends PluginListener {
}
// Now loop this hook back through!
block.setStatus(3); // Block is destroyed
canDestroyBlock(player, block);
simulateBlockDestroy(player, block);
}
return true;
@@ -517,6 +516,23 @@ public class WorldGuardListener extends PluginListener {
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.
*
@@ -583,15 +599,6 @@ public class WorldGuardListener extends PluginListener {
Block block = new Block(id, complexBlock.getX(),
complexBlock.getY(), complexBlock.getZ());
if (!blacklist.onSilentUse(block, player)) {
return true;
}
} else if (complexBlock instanceof Sign) {
int id = etc.getServer().getBlockIdAt(complexBlock.getX(),
complexBlock.getY(), complexBlock.getZ());
Block block = new Block(id, complexBlock.getX(),
complexBlock.getY(), complexBlock.getZ());
if (!blacklist.onSilentUse(block, player)) {
return true;
}
@@ -735,6 +742,44 @@ public class WorldGuardListener extends PluginListener {
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.
*
@@ -742,7 +787,7 @@ public class WorldGuardListener extends PluginListener {
* @param block
* @return
*/
public boolean canDestroyBlock(Player player, Block block) {
private boolean canDestroyBlock(Player player, Block block) {
plugin.toggleEnabled(); // Prevent infinite loop
try {
return !(Boolean)etc.getLoader().callHook(PluginLoader.Hook.BLOCK_DESTROYED,
+12 -1
View File
@@ -15,9 +15,12 @@
#
# Options:
# - ignore-groups (comma-delimited list of groups to not affect)
# - comment (message for yourself that is printed with 'log' and 'notify')
# - message (optional message to show the user instead; %s is the item name)
#
# Events:
# - 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)
@@ -67,4 +70,12 @@
#on-destroy=notify,deny,log
#[cobblestone]
#on-create=deny,tell,log
#on-create=deny,tell,log
#[lever]
#on-break=deny
#[diamondpickaxe,woodpickaxe]
#on-drop=deny
#comment=durability cheat
#message=Your item was destroyed