Compare commits

...
50 Commits
Author SHA1 Message Date
sk89q 257c12e727 Updated for 0.2.8. 2010-12-04 00:15:50 -08:00
sk89q 8b3eaa70fb Updated for newer builds of hMod. 2010-12-02 22:56:47 -08:00
sk89q c96bb890b4 Caught NullPointerException caused by getting the players list too early. 2010-12-01 22:43:36 -08:00
sk89q 8192a1962a Updated for 1.7. 2010-11-30 21:59:39 -08:00
sk89q 80df9c6aa4 Improved blacklist support for the new hooks. 2010-11-30 21:54:36 -08:00
sk89q 8073089da4 Updated for Minecraft update. Untested. 2010-11-30 17:24:07 -08:00
sk89q 23e7d4a8bb Updated for 1.7. 2010-11-30 02:48:39 -08:00
sk89q 0e1e92df13 Added option to prevent block damage created by flowing water (Minecart tracks, Redstone wire, etc.) 2010-11-30 02:44:01 -08:00
sk89q d13f0b9191 Made /stack ignore buckets. 2010-11-30 02:33:51 -08:00
sk89q aa2bffbd00 Fixed /god for the new hMod versions. 2010-11-30 02:27:13 -08:00
sk89q a456d67528 Updated readmes. 2010-11-30 02:19:18 -08:00
sk89q 95f074342c Fixed damage type prevention. 2010-11-30 02:04:12 -08:00
sk89q 74016bf93e Made amphibious feature in WorldGuard more efficient and fixed missing group console spam. 2010-11-30 01:41:07 -08:00
sk89q 3f8bac582c Added /reload WorldGuard command; adjusted wg-invincible so that it won't console spam every time someone joins. 2010-11-29 12:59:44 -08:00
sk89q 6b57e58d63 Fixed damage type protection affecting all entities. Added wg-invincible and wg-amphibious groups that let you give certain players invincibility or underwater breathing. 2010-11-29 12:39:12 -08:00
sk89q 19aa20537d Added the ability to disable fall, water, lava, and fire damage individually. 2010-11-29 12:30:42 -08:00
sk89q cf31df35ec Switched water/lava bucket block to use new onItemUse hook. 2010-11-28 15:54:29 -08:00
sk89q 6d39ce7240 Added /stack command, alias /; to compact items into stacks (up to 64 items). Works for even non-stackable items like signs and it won't stack items with durability or infinite supply. 2010-11-26 01:06:32 -08:00
sk89q 0f3c1b94d7 Caught error message for when the configuration file does not exist. 2010-11-25 23:27:33 -08:00
sk89q 13cc6736e2 /god mode now at least lets you gain health while it is on. 2010-11-25 13:47:20 -08:00
sk89q 64629bd878 Updated README and CHANGELOG. 2010-11-25 02:40:46 -08:00
sk89q e42be555b1 Fixed spelling error in /god and allowed use of /god on others. 2010-11-25 02:37:50 -08:00
sk89q c62c5f5cae Updated for 1.6. 2010-11-25 00:02:59 -08:00
sk89q 313bdbd8bf Added spawn protection, updated login protection. 2010-11-24 23:55:27 -08:00
sk89q 765b606e18 Added login protection. 2010-11-24 23:13:42 -08:00
sk89q c0be685846 Added /god mode. 2010-11-24 22:44:09 -08:00
sk89q 133e4c2c78 Updated for 1.5.1. 2010-11-24 13:10:29 -08:00
sk89q b7e91ac6d0 'Fixed' java.lang.NoSuchMethodError: Item.setDamage(I)V. 2010-11-24 13:09:53 -08:00
sk89q 79518e6503 Updated CHANGELOG. 2010-11-24 12:44:37 -08:00
sk89q 2999f9d168 Removed warning emitted when a hook does not exist. 2010-11-24 12:43:18 -08:00
sk89q b4d8b2095d Changed some configuration defaults: summary-on-start=true, disable-lava-fire=true, simulate-sponge=true, item-durability=false. 2010-11-24 12:41:32 -08:00
sk89q f7099f2093 Improved README. 2010-11-24 12:31:56 -08:00
sk89q 8c51795b1a Removed mention of the block lag fix. 2010-11-24 12:26:58 -08:00
sk89q ba523ce3f3 Updated for 1.5. 2010-11-24 12:18:45 -08:00
sk89q e4af400acb Added a startup message indicating when all features all supported. 2010-11-24 12:17:26 -08:00
sk89q ffa38f9fd1 Removed the block lag fix and cleaned up code. 2010-11-24 12:02:04 -08:00
sk89q 84ccabdf34 Improved missing feature detection. 2010-11-24 11:58:54 -08:00
sk89q c0b4d95082 Added documentation for required hooks. Improved missing hook messages. 2010-11-23 22:42:30 -08:00
sk89q f305b3a119 Hooks are now conditionally loaded. summary-on-start is now disabled by default and mentioned in the README. 2010-11-23 22:31:28 -08:00
sk89q 48ace4947b Updated for 1.4.1. 2010-11-21 11:40:26 -08:00
sk89q 57acbebaf1 Fixed issue with the block lag fix dropping item stacks of 0 quantity. 2010-11-21 11:34:46 -08:00
sk89q e15311178b Updated the README.txt. 2010-11-21 01:36:13 -08:00
sk89q 7385be7eff Fixed typo in worldguard.properties. 2010-11-21 01:30:50 -08:00
sk89q 9a29474132 Updated for 1.4. 2010-11-21 01:29:52 -08:00
sk89q 881f050f0d Inventory checks now won't be used if there are no on-acquire events. 2010-11-21 01:25:59 -08:00
sk89q 339bf1a06d Improved documentation. 2010-11-21 01:21:20 -08:00
sk89q bc70678387 Updated for new version of durability fix. 2010-11-21 01:13:33 -08:00
sk89q c3eef60672 Added no-physics-gravel, no-physics-sand, and allow-portal-anywhere. 2010-11-21 01:12:00 -08:00
sk89q eb78b390ca Added item-durability and blacklist on-acquire event. Thanks to Dinnerbone for heading my requests :) 2010-11-21 00:45:16 -08:00
sk89q a0fc3472e4 Updated blacklist and added Sturmeh's item durability 'fix' as sample rules. 2010-11-20 20:10:29 -08:00
16 changed files with 1087 additions and 333 deletions

No files matched your search

+55
View File
@@ -1,3 +1,58 @@
1.7.1:
- Updated for v0.2.8.
1.7
- Updated for v0.2.6_02 and hMod b129.
- Added option to prevent water from damaging particular blocks
(Redstone wire, Minecart tracks, etc.). See disable-water-damage-blocks.
- /reload WorldGuard should now reload WorldGuard's configuration.
- Added wg-invincible and wg-amphibious groups that let you give certain
players invincibility or underwater breathing.
- Added the ability to disable fall, water, lava, and/or fire damage.
- Water/lava bucket blocking should now be more reliable.
- Added /stack (alias /;) commands to stack items in your inventory into
piles up to 64 items in size. Even unstackable items like signs can be
stacked.
- /god mode should now let you gain health.
- /god mode should now work more reliably.
- Caught an error message for when the configuration file does not exist.
1.6
- Added spawn protection that prevents damage when a player spawns.
- Added login protection that prevents damage when a player joins.
- Added /god. /god can be used on others, provided that the /godother
permission is set for the command's user.
1.5.1
- Removed the 'java.lang.NoSuchMethodError: Item.setDamage(I)V' error
generated.
1.5
- Removed the block lag fix.
- WorldGuard now conditionally loads features so you can use any up-to-date
build of hMod and the unsupported features won't break the entire
plugin. When WG loads, check the server console for a report of
features that are not supported by your version of hMod.
- Changed some configuration defaults:
disable-lava-fire=true
simulate-sponge=true
item-durability=false
1.4.1
- Fixed issue with the block lag fix dropping item stacks of 0 quantity.
1.4
- New on-acquire hook. This does both a total inventory check on inventory
change and item pick up denial. The item pick up denial is largely
thanks to Dinnerbone for fulfilling my request to add a particular hook.
- Item durability can now be toggled with item-durability. Thanks to
Dinnerbone for figuring this out while filfilling my request. The
default setting is to fix item durability.
- New no-physics-gravel and no-physics-sand options allow you to
prevent gravel and sand from falling.
- New allow-portal-anywhere option allows you to create portal blocks
anywhere.
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
+81 -11
View File
@@ -13,17 +13,20 @@ use or not:
- Block TNT explosions.
- Block lighters from setting fires.
- Block all fires.
- Disable fall damage, lava damage, fire damage, and/or water damage.
- Allow fire but prevent it from burning certain blocks.
- Prevent lava from starting fires.
- Restrict lava spreading to only some block types.
- Simulate classic-esque water by letting water infinitely expand in
area (only if there is a block underneath).
- Prevent water from destroying blocks like Redstone wire and flowers.
- Simulate the function of the sponge from Minecraft Classic.
- Notify admins, block, log, kick or ban for the use of certain block types
or items.
- Temporarily stop fire globally with some commands.
- Fix the block lag.
- Destroy tools on drop to alleviate the durability cheat.
- Prevent gravel and sand from falling.
- Allow portal blocks to be placed anywhere.
hMod is required as WorldGuard is a plugin for hMod.
@@ -34,6 +37,18 @@ A "worldguard.properties" will be created the first the time that you load
WorldGuard on your server. You can either restart your server or use
/reloadplugin WorldGuard to reload the configuraton file after editing it.
NOTE: Some features may require a custom version of hMod. When the server
is loaded with the plugin, WorldGuard will tell you the features
unsupported by your version of hMod.
- summary-on-start (def. true)
Print a summary of WorldGuard's protection settings at-a-glance when
the plugin is loaded.
- item-durability (def. false)
**Requires special version of hMod
Enables item durability.
- classic-water (def. false)
Toggle use of classic water. Be foreward that your world may be
flooded if you are not careful. If you have WorldEdit, you can use
@@ -42,7 +57,7 @@ WorldGuard on your server. You can either restart your server or use
ground, but if there are air blocks underneath, the water will not
spread (preventing waterfalls from becoming tsunamis).
- simulate-sponge (def. false)
- simulate-sponge (def. true)
Toggle simulation of the sponge from Classic. It blocks water from
flowing near the sponge.
@@ -51,6 +66,18 @@ WorldGuard on your server. You can either restart your server or use
creating a 5x5x5 cuboid free of water. Increasing the number will
increase server load exponentially, although 3-5 has fairly low impact.
- no-physics-gravel (def. false)
**Requires special version of hMod
Prevents gravel from falling due to gravity.
- no-physics-sand (def. false)
**Requires special version of hMod
Prevents sand from falling due to gravity.
- allow-portal-anywhere (def. false)
**Requires special version of hMod
Allows you to place portal blocks anywhere.
- enforce-single-session (def. true)
Enforce single sessions. If the player is already found to be on
the server when s/he logs in, the other player will be kicked with
@@ -67,9 +94,10 @@ WorldGuard on your server. You can either restart your server or use
command; it is only used for permissions.
- block-creepers (def. false)
Block creeper explosions. They will not explode client-side.
Block creeper explosions from destroying terrain (and possibly from
causing damage).
- disable-lava-fire (def. false)
- disable-lava-fire (def. true)
Prevent lava from starting fires.
- allowed-lava-spread-blocks (no default)
@@ -84,6 +112,10 @@ WorldGuard on your server. You can either restart your server or use
to disable this feature. Enabling disable-all-fire-spread will
override this function.
- disable-water-damage-blocks (no default)
List of blocks that should not be destroyed by water (Redstone wire,
minecart tracks, flowers, etc.).
- item-drop-blacklist (no default)
List of block names/IDs to destroy on drop. This can alleviate the
durability cheat that allows you to drop your tools to fix their
@@ -91,14 +123,23 @@ WorldGuard on your server. You can either restart your server or use
this is an easier way to do it (this way also prints a more
friendly message than if you used the 'tell' action of the blacklist).
- block-lag-fix (def. false)
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.
- login-protection (def. 3)
Number of seconds to keep a player invincible when the player joins.
- spawn-protection (def. 0)
Number of seconds to keep a player invincible when the player spawns.
This does not apply to players joining the server.
- kick-on-death (def. false)
Kick players when they die (and respawn). This is to work around the
issues of invisible players when players die.
- disable-fall-damage (def. false)
- disable-lava-damage (def. false)
- disable-fire-damage (def. false)
- disable-water-damage (def. false)
Disable various types of damage.
- log-console (def. true)
For blacklist log actions, print to console.
@@ -162,6 +203,12 @@ Commands
WorldGuard. Note that disabling fire does not disable fire damage
but fire at least won't spread.
- /god
Toggles your invincibility. Players must have permission to use "/god"
to be able to use this command. You can also use this command to
toggle the invincibility of others although you must have the
"/godother" permission.
Server Commands
---------------
@@ -179,3 +226,26 @@ certain rules apply to only some groups.
Edit the included worldguard-blacklist.txt file and follow the
instructions inside. The file comes with the download for WorldGuard.
Other Features
--------------
To give someone invincibility every time s/he joins the server, create
a wg-invincible group and add the group to the user or have the user's
group inherit this group.
To give someone the ability to breathe under water, create
a wg-amphibious group and add the group to the user or have the user's
group inherit this group.
Thanks
------
While I would like to thank everyone for their support, I would like to
say thanks to the following individuals for their direct
contributions to WorldGuard:
- Sturmeh, for contributing the original durability workaround
- Meaglin, for changing the on flow hook at my request
- Dinnerbone, for implementing the on item pick up hook at my request,
and also for figuring out the durability bug in the process
+1 -1
View File
@@ -1,2 +1,2 @@
Manifest-Version: 1.0
WorldGuard-Version: 1.3
WorldGuard-Version: 1.7.1
+61
View File
@@ -45,6 +45,11 @@ public class Blacklist {
*/
private BlacklistLogger blacklistLogger = new BlacklistLogger();
/**
* Blacklist contains on-acquire events.
*/
private boolean hasOnAcquire;
/**
* Returns whether the list is empty.
*
@@ -219,6 +224,48 @@ public class Blacklist {
return ret;
}
/**
* Called on acquire. Returns true to let the action pass through.
*
* @param item
* @param player
* @return
*/
public boolean onAcquire(int item, Player player) {
List<BlacklistEntry> entries = getEntries(item);
if (entries == null) {
return true;
}
boolean ret = true;
for (BlacklistEntry entry : entries) {
if (!entry.onAcquire(item, player)) {
ret = false;
}
}
return ret;
}
/**
* Called on acquire. Returns true to let the action pass through.
*
* @param item
* @param player
* @return
*/
public boolean onSilentAcquire(int item, Player player) {
List<BlacklistEntry> entries = getEntries(item);
if (entries == null) {
return true;
}
boolean ret = true;
for (BlacklistEntry entry : entries) {
if (!entry.onSilentAcquire(item, player)) {
ret = false;
}
}
return ret;
}
/**
* Load the blacklist.
*
@@ -235,6 +282,8 @@ public class Blacklist {
input = new FileReader(file);
BufferedReader buff = new BufferedReader(input);
hasOnAcquire = false;
String line;
List<BlacklistEntry> currentEntries = null;
while ((line = buff.readLine()) != null) {
@@ -304,6 +353,9 @@ 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("on-acquire")) {
hasOnAcquire = true;
entry.setAcquireActions(parts[1].split(","));
} else if (parts[0].equalsIgnoreCase("message")) {
entry.setMessage(parts[1].trim());
} else if (parts[0].equalsIgnoreCase("comment")) {
@@ -333,4 +385,13 @@ public class Blacklist {
}
}
}
/**
* Blacklist contains on-acquire events.
*
* @return
*/
public boolean hasOnAcquire() {
return hasOnAcquire;
}
}
+96 -22
View File
@@ -67,11 +67,29 @@ public class BlacklistEntry {
*/
private String[] dropActions;
/**
* Comment for the log.
* List of actions to perform on drop.
*/
private String[] acquireActions;
/**
* Message for users.
*/
private String message;
/**
* Comment for administrators.
*/
private String comment;
/**
* Used to ignore messages.
*/
private static ActionHandler silentHandler = new ActionHandler() {
public void log(String itemName) {}
public void kick(String itemName) {}
public void ban(String itemName) {}
public void notifyAdmins(String itemName) {}
public void tell(String itemName) {}
};
/**
* Construct the object.
*
@@ -183,6 +201,20 @@ public class BlacklistEntry {
this.dropActions = actions;
}
/**
* @return
*/
public String[] getAcquireActions() {
return acquireActions;
}
/**
* @param actions
*/
public void setAcquireActions(String[] actions) {
this.acquireActions = actions;
}
/**
* @return the message
*/
@@ -292,7 +324,7 @@ public class BlacklistEntry {
}
};
return process(block.getType(), player, destroyActions, handler, false);
return process(block.getType(), player, destroyActions, handler, false, false);
}
/**
@@ -329,7 +361,7 @@ public class BlacklistEntry {
}
};
return process(block.getType(), player, breakActions, handler, true);
return process(block.getType(), player, breakActions, handler, true, false);
}
/**
@@ -365,7 +397,7 @@ public class BlacklistEntry {
}
};
return process(item, player, destroyWithActions, handler, false);
return process(item, player, destroyWithActions, handler, false, false);
}
/**
@@ -401,7 +433,7 @@ public class BlacklistEntry {
}
};
return process(item, player, createActions, handler, true);
return process(item, player, createActions, handler, true, false);
}
/**
@@ -437,7 +469,7 @@ public class BlacklistEntry {
}
};
return process(block.getType(), player, useActions, handler, false);
return process(block.getType(), player, useActions, handler, false, false);
}
/**
@@ -452,20 +484,7 @@ public class BlacklistEntry {
return true;
}
ActionHandler handler = new ActionHandler() {
public void log(String itemName) {
}
public void kick(String itemName) {
}
public void ban(String itemName) {
}
public void notifyAdmins(String itemName) {
}
public void tell(String itemName) {
}
};
return process(block.getType(), player, useActions, handler, false);
return process(block.getType(), player, useActions, silentHandler, false, true);
}
/**
@@ -501,7 +520,58 @@ public class BlacklistEntry {
}
};
return process(item, player, dropActions, handler, true);
return process(item, player, dropActions, handler, true, false);
}
/**
* Called on item acquire. Returns true to let the action pass through.
*
* @param item
* @param player
* @return
*/
public boolean onAcquire(final int item, final Player player) {
if (acquireActions == null) {
return true;
}
final BlacklistEntry entry = this;
ActionHandler handler = new ActionHandler() {
public void log(String itemName) {
blacklist.getLogger().logAcquireAttempt(player, item, comment);
}
public void kick(String itemName) {
player.kick("You can't acquire " + itemName);
}
public void ban(String itemName) {
entry.banPlayer(player, "Banned: You can't acquire " + itemName);
}
public void notifyAdmins(String itemName) {
entry.notifyAdmins(player.getName() + " (acquire) " + itemName
+ (comment != null ? " (" + comment + ")" : "") + ".");
}
public void tell(String itemName) {
player.sendMessage(Colors.Yellow + "You're not allowed to acquire " + itemName + ".");
}
};
return process(item, player, acquireActions, handler, true, false);
}
/**
* Called on item acquire. Returns true to let the action pass through.
*
* @param item
* @param player
* @return
*/
public boolean onSilentAcquire(final int item, final Player player) {
if (acquireActions == null) {
return true;
}
return process(item, player, acquireActions, silentHandler, false, true);
}
/**
@@ -512,10 +582,11 @@ public class BlacklistEntry {
* @param actions
* @param handler
* @param allowRepeat
* @param silent
* @return
*/
private boolean process(int id, Player player, String[] actions,
ActionHandler handler, boolean allowRepeat) {
ActionHandler handler, boolean allowRepeat, boolean silent) {
if (shouldIgnore(player)) {
return true;
@@ -543,6 +614,9 @@ public class BlacklistEntry {
for (String action : actions) {
// Deny
if (action.equalsIgnoreCase("deny")) {
if (silent) {
return false;
}
ret = false;
// Kick
+13 -1
View File
@@ -119,7 +119,7 @@ public class BlacklistLogger implements BlacklistLoggerHandler {
}
/**
* Log a right click attempt.
* Log a drop attempt.
*
* @param player
* @param item
@@ -130,6 +130,18 @@ public class BlacklistLogger implements BlacklistLoggerHandler {
}
}
/**
* Log an acquire attempt.
*
* @param player
* @param item
*/
public void logAcquireAttempt(Player player, int item, String comment) {
for (BlacklistLoggerHandler handler : handlers) {
handler.logAcquireAttempt(player, item, comment);
}
}
/**
* Close the connection.
*/
+7
View File
@@ -65,6 +65,13 @@ public interface BlacklistLoggerHandler {
* @param item
*/
public void logDropAttempt(Player player, int item, String comment);
/**
* Log an acquire attempt.
*
* @param player
* @param item
*/
public void logAcquireAttempt(Player player, int item, String comment);
/**
* Close the logger.
*/
+12
View File
@@ -102,6 +102,18 @@ public class ConsoleLoggerHandler implements BlacklistLoggerHandler {
+ (comment != null ? " (" + comment + ")" : ""));
}
/**
* Log an acquire attempt.
*
* @param player
* @param item
*/
public void logAcquireAttempt(Player player, int item, String comment) {
logger.log(Level.INFO, "WorldGuard: " + player.getName()
+ " tried to acquire " + getFriendlyItemName(item)
+ (comment != null ? " (" + comment + ")" : ""));
}
/**
* Get an item's friendly name with its ID.
*
+12
View File
@@ -188,6 +188,18 @@ public class DatabaseLoggerHandler implements BlacklistLoggerHandler {
(int)Math.floor(player.getZ()), item, comment);
}
/**
* Log an aquire attempt.
*
* @param player
* @param item
*/
public void logAcquireAttempt(Player player, int item, String comment) {
logEvent("AQUIRE", player.getName(),
(int)Math.floor(player.getX()), (int)Math.floor(player.getY()),
(int)Math.floor(player.getZ()), item, comment);
}
/**
* Close the connection.
*/
+10
View File
@@ -269,6 +269,16 @@ public class FileLoggerHandler implements BlacklistLoggerHandler {
log(player, "Tried to drop " + getFriendlyItemName(item), comment);
}
/**
* Log an acquire attempt.
*
* @param player
* @param item
*/
public void logAcquireAttempt(Player player, int item, String comment) {
log(player, "Tried to acquire " + getFriendlyItemName(item), comment);
}
/**
* Get an item's friendly name with its ID.
*
@@ -17,31 +17,48 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldguard;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Formatter;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
import java.util.logging.Level;
import java.util.logging.Handler;
import java.util.logging.LogRecord;
/**
* Used for formatting.
* Sends all logger messages to a player.
*
* @author sk89q
*/
public class SimpleLogFormat extends Formatter {
private static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
public String format(LogRecord record) {
StringBuilder text = new StringBuilder();
Level level = record.getLevel();
public class LoggerToChatHandler extends Handler {
/**
* Player.
*/
private Player player;
text.append("[");
text.append(dateFormat.format(new Date(record.getMillis())));
text.append("] ");
text.append(record.getMessage());
text.append("\r\n");
return text.toString();
/**
* Construct the object.
*
* @param player
*/
public LoggerToChatHandler(Player player) {
this.player = player;
}
/**
* Close the handler.
*/
public void close() {
}
/**
* Flush the output.
*/
public void flush() {
}
/**
* Publish a log record.
*/
public void publish(LogRecord record) {
player.sendMessage(Colors.LightGray + record.getLevel().getName() + ": "
+ Colors.White + record.getMessage());
}
}
+117 -28
View File
@@ -21,8 +21,11 @@ import java.util.logging.Logger;
import java.util.logging.Level;
import java.util.jar.Manifest;
import java.util.jar.Attributes;
import java.util.List;
import java.util.ArrayList;
import java.net.URL;
import java.io.*;
import java.lang.reflect.*;
/**
* Entry point for the plugin for hey0's mod.
@@ -53,34 +56,86 @@ public class WorldGuard extends Plugin {
public void initialize() {
PluginLoader loader = etc.getLoader();
loader.addListener(PluginLoader.Hook.COMMAND, listener, this,
PluginListener.Priority.MEDIUM);
loader.addListener(PluginLoader.Hook.SERVERCOMMAND, listener, this,
PluginListener.Priority.MEDIUM);
loader.addListener(PluginLoader.Hook.EXPLODE, listener, this,
PluginListener.Priority.HIGH);
loader.addListener(PluginLoader.Hook.IGNITE, listener, this,
PluginListener.Priority.HIGH);
loader.addListener(PluginLoader.Hook.FLOW, listener, this,
PluginListener.Priority.HIGH);
loader.addListener(PluginLoader.Hook.LOGINCHECK, listener, this,
PluginListener.Priority.HIGH);
loader.addListener(PluginLoader.Hook.LOGIN, listener, this,
PluginListener.Priority.MEDIUM);
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);
loader.addListener(PluginLoader.Hook.ITEM_DROP , listener, this,
PluginListener.Priority.HIGH);
loader.addListener(PluginLoader.Hook.COMPLEX_BLOCK_CHANGE, listener, this,
PluginListener.Priority.HIGH);
loader.addListener(PluginLoader.Hook.COMPLEX_BLOCK_SEND, listener, this,
PluginListener.Priority.HIGH);
List<String> missingFeatures = new ArrayList<String>();
registerHook("COMMAND", PluginListener.Priority.MEDIUM);
registerHook("SERVERCOMMAND", PluginListener.Priority.MEDIUM);
if (!registerHook("EXPLODE", PluginListener.Priority.HIGH)) {
missingFeatures.add("disabling TNT or creeper explosions");
}
if (!registerHook("IGNITE", PluginListener.Priority.HIGH)) {
missingFeatures.add("disabling fire or lava fire");
}
if (!registerHook("FLOW", PluginListener.Priority.HIGH)) {
missingFeatures.add("controlling lava flow");
missingFeatures.add("sponge simulation");
}
registerHook("LOGINCHECK", PluginListener.Priority.HIGH);
registerHook("LOGIN", PluginListener.Priority.MEDIUM);
registerHook("BLOCK_CREATED", PluginListener.Priority.HIGH);
registerHook("BLOCK_DESTROYED", PluginListener.Priority.CRITICAL);
registerHook("BLOCK_BROKEN", PluginListener.Priority.HIGH);
registerHook("BLOCK_PLACE", PluginListener.Priority.HIGH);
registerHook("DISCONNECT", PluginListener.Priority.HIGH);
registerHook("ITEM_DROP", PluginListener.Priority.HIGH);
if (!registerHook("ITEM_USE", PluginListener.Priority.HIGH)) {
missingFeatures.add("denying use of the lava or water buckets");
}
if (!registerHook("ITEM_PICK_UP", PluginListener.Priority.HIGH)) {
missingFeatures.add("denying item pickups");
missingFeatures.add("the item durability fix");
} else {
try {
Method method =
Item.class.getDeclaredMethod("setDamage", new Class[]{ Integer.class });
if (method == null) {
missingFeatures.add("the item durability fix");
}
} catch (NoSuchMethodException e) {
missingFeatures.add("the item durability fix");
}
}
registerHook("COMPLEX_BLOCK_CHANGE", PluginListener.Priority.HIGH);
registerHook("COMPLEX_BLOCK_SEND", PluginListener.Priority.HIGH);
registerHook("INVENTORY_CHANGE", PluginListener.Priority.HIGH);
if (!registerHook("BLOCK_PHYSICS", PluginListener.Priority.MEDIUM)) {
missingFeatures.add("controlling the physics of gravel, sand, or portal blocks");
}
if (!registerHook("HEALTH_CHANGE", PluginListener.Priority.MEDIUM)) {
missingFeatures.add("god mode");
}
if (!registerHook("DAMAGE", PluginListener.Priority.MEDIUM)) {
missingFeatures.add("disabling fall, water, lava, and fire damage");
}
if (!registerHook("LIQUID_DESTROY", PluginListener.Priority.MEDIUM)) {
missingFeatures.add("disabling water damage");
}
if (missingFeatures.size() > 0) {
logger.log(Level.WARNING, "WorldGuard: Your version of hMod does not support "
+ concatMissingFeatures(missingFeatures) + ".");
} else {
logger.log(Level.INFO, "WorldGuard: Your version of hMod appears to"
+ " support all features.");
}
}
/**
* Conditionally registers a hook.
*
* @param name
* @param priority
* @return where the hook was registered correctly
*/
public boolean registerHook(String name, PluginListener.Priority priority) {
try {
PluginLoader.Hook hook = PluginLoader.Hook.valueOf(name);
etc.getLoader().addListener(hook, listener, this, priority);
return true;
} catch (IllegalArgumentException e) {
//logger.log(Level.WARNING, "WorldGuard: Missing hook " + name + "!");
return false;
}
}
/**
@@ -128,4 +183,38 @@ public class WorldGuard extends Plugin {
return "(unknown)";
}
}
/**
* Joins a string from an array of strings.
*
* @param str
* @param delimiter
* @return
*/
private static String concatMissingFeatures(List<String> str) {
if (str.isEmpty()) {
return "";
}
int size = str.size();
StringBuilder buffer = new StringBuilder();
buffer.append("(1) ");
buffer.append(str.get(0));
for (int i = 1; i < size; i++) {
if (i == size - 1) {
buffer.append(" or ");
buffer.append("(");
buffer.append(i + 1);
buffer.append(") ");
buffer.append(str.get(i));
} else {
buffer.append(", ");
buffer.append("(");
buffer.append(i + 1);
buffer.append(") ");
buffer.append(str.get(i));
}
}
return buffer.toString();
}
}
+475 -183
View File
@@ -21,15 +21,12 @@ import java.util.Timer;
import java.util.TimerTask;
import java.util.logging.Logger;
import java.util.logging.Level;
import java.util.logging.Handler;
import java.util.logging.ConsoleHandler;
import java.util.Set;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Map;
import java.util.HashMap;
import java.util.Random;
import java.io.*;
import java.util.logging.FileHandler;
import com.sk89q.worldguard.*;
/**
* Event listener for Hey0's server mod.
@@ -59,15 +56,23 @@ public class WorldGuardListener extends PluginListener {
*/
private PropertiesFile properties = new PropertiesFile("worldguard.properties");
/**
* List of blocks to remove when possible.
* List of players with god mode on.
*/
private LinkedList<int[]> blockRemoveQueue = new LinkedList<int[]>();
private Set<String> invinciblePlayers = new HashSet<String>();
/**
* Stop fire spread mode.
* List of amphibious players.
*/
private Set<String> amphibiousPlayers = new HashSet<String>();
/**
* Used to keep recent join times.
*/
private Map<String,Long> recentLogins = new HashMap<String,Long>();
/**
* Used to keep recent spawn times.
*/
private Map<String,Long> lastSpawn = new HashMap<String,Long>();
private boolean stopFireSpread = false;
private boolean enforceOneSession;
private boolean blockCreepers;
private boolean blockTNT;
@@ -76,11 +81,22 @@ public class WorldGuardListener extends PluginListener {
private boolean disableAllFire;
private boolean simulateSponge;
private int spongeRadius;
private boolean blockLagFix;
private boolean itemDurability;
private Set<Integer> fireNoSpreadBlocks;
private Set<Integer> allowedLavaSpreadOver;
private Set<Integer> itemDropBlacklist;
private Set<Integer> preventWaterDamage;
private boolean classicWater;
private boolean noPhysicsGravel;
private boolean noPhysicsSand;
private boolean allowPortalAnywhere;
private boolean disableFallDamage;
private boolean disableLavaDamage;
private boolean disableFireDamage;
private boolean disableWaterDamage;
private int loginProtection;
private int spawnProtection;
private boolean kickOnDeath;
private Blacklist blacklist;
/**
@@ -90,6 +106,7 @@ public class WorldGuardListener extends PluginListener {
*/
public WorldGuardListener(WorldGuard plugin) {
this.plugin = plugin;
postReload();
}
/**
@@ -123,26 +140,65 @@ public class WorldGuardListener extends PluginListener {
return result;
}
/**
* Populates various lists.
*/
public void postReload() {
invinciblePlayers.clear();
amphibiousPlayers.clear();
try {
for (Player player : etc.getServer().getPlayerList()) {
if (player.isInGroup("wg-invincible")) {
invinciblePlayers.add(player.getName());
}
if (player.isInGroup("wg-amphibious")) {
amphibiousPlayers.add(player.getName());
}
}
} catch (NullPointerException e) { // Thrown if loaded too early
}
}
/**
* Load the configuration
*/
public void loadConfiguration() {
properties.load();
try {
properties.load();
} catch (IOException e) {
logger.log(Level.WARNING, "WorldGuard: Failed to load configuration: "
+ e.getMessage());
}
recentLogins.clear();
// Load basic options
enforceOneSession = properties.getBoolean("enforce-single-session", true);
blockCreepers = properties.getBoolean("block-creepers", false);
blockTNT = properties.getBoolean("block-tnt", false);
blockLighter = properties.getBoolean("block-lighter", false);
preventLavaFire = properties.getBoolean("disable-lava-fire", false);
preventLavaFire = properties.getBoolean("disable-lava-fire", true);
disableAllFire = properties.getBoolean("disable-all-fire-spread", false);
preventWaterDamage = toBlockIDSet(properties.getString("disable-water-damage-blocks", ""));
itemDropBlacklist = toBlockIDSet(properties.getString("item-drop-blacklist", ""));
fireNoSpreadBlocks = toBlockIDSet(properties.getString("disallowed-fire-spread-blocks", ""));
allowedLavaSpreadOver = toBlockIDSet(properties.getString("allowed-lava-spread-blocks", ""));
classicWater = properties.getBoolean("classic-water", false);
simulateSponge = properties.getBoolean("simulate-sponge", false);
simulateSponge = properties.getBoolean("simulate-sponge", true);
spongeRadius = Math.max(1, properties.getInt("sponge-radius", 3)) - 1;
blockLagFix = properties.getBoolean("block-lag-fix", false);
itemDurability = properties.getBoolean("item-durability", false);
noPhysicsGravel = properties.getBoolean("no-physics-gravel", false);
noPhysicsSand = properties.getBoolean("no-physics-sand", false);
allowPortalAnywhere = properties.getBoolean("allow-portal-anywhere", false);
disableFallDamage = properties.getBoolean("disable-fall-damage", false);
disableLavaDamage = properties.getBoolean("disable-lava-damage", false);
disableFireDamage = properties.getBoolean("disable-fire-damage", false);
disableWaterDamage = properties.getBoolean("disable-water-damage", false);
loginProtection = properties.getInt("login-protection", 3);
spawnProtection = properties.getInt("spawn-protection", 0);
kickOnDeath = properties.getBoolean("kick-on-death", false);
// Console log configuration
boolean logConsole = properties.getBoolean("log-console", true);
@@ -167,18 +223,18 @@ public class WorldGuardListener extends PluginListener {
}
// First load the blacklist data from worldguard-blacklist.txt
Blacklist blacklist = new Blacklist();
blacklist.load(new File("worldguard-blacklist.txt"));
Blacklist blist = new Blacklist();
blist.load(new File("worldguard-blacklist.txt"));
// If the blacklist is empty, then set the field to null
// and save some resources
if (blacklist.isEmpty()) {
if (blist.isEmpty()) {
this.blacklist = null;
} else {
this.blacklist = blacklist;
this.blacklist = blist;
logger.log(Level.INFO, "WorldGuard: Blacklist loaded.");
BlacklistLogger blacklistLogger = blacklist.getLogger();
BlacklistLogger blacklistLogger = blist.getLogger();
if (logDatabase) {
blacklistLogger.addHandler(new DatabaseLoggerHandler(dsn, user, pass, table));
@@ -231,6 +287,7 @@ public class WorldGuardListener extends PluginListener {
* @param user
* @return kick reason. null if you don't want to kick the player.
*/
@Override
public String onLoginChecks(String user) {
if (enforceOneSession) {
for (Player player : etc.getServer().getPlayerList()) {
@@ -248,10 +305,23 @@ public class WorldGuardListener extends PluginListener {
*
* @param player
*/
@Override
public void onLogin(Player player) {
if (stopFireSpread) {
player.sendMessage(Colors.Yellow + "Fire spread is currently globally disabled.");
}
if (loginProtection > 0 || spawnProtection > 0 || kickOnDeath) {
recentLogins.put(player.getName(), System.currentTimeMillis());
}
if (player.isInGroup("wg-invincible")) {
invinciblePlayers.add(player.getName());
}
if (player.isInGroup("wg-amphibious")) {
amphibiousPlayers.add(player.getName());
}
}
/**
@@ -262,6 +332,7 @@ public class WorldGuardListener extends PluginListener {
* @param split
* @return false if you want the command to be parsed.
*/
@Override
public boolean onCommand(Player player, String[] split) {
if (split[0].equalsIgnoreCase("/stopfire") &&
player.canUseCommand("/stopfire")) {
@@ -283,6 +354,122 @@ public class WorldGuardListener extends PluginListener {
}
stopFireSpread = false;
return true;
} else if (split[0].equalsIgnoreCase("/god")
&& player.canUseCommand("/god")) {
// Allow setting other people invincible
if (split.length > 1) {
if (!player.canUseCommand("/godother")) {
player.sendMessage(Colors.Rose + "You don't have permission to make others invincible.");
return true;
}
Player other = etc.getServer().matchPlayer(split[1]);
if (other == null) {
player.sendMessage(Colors.Rose + "Player not found.");
} else {
if (!invinciblePlayers.contains(other.getName())) {
invinciblePlayers.add(other.getName());
player.sendMessage(Colors.Yellow + other.getName() + " is now invincible!");
other.sendMessage(Colors.Yellow + player.getName() + " has made you invincible!");
} else {
invinciblePlayers.remove(other.getName());
player.sendMessage(Colors.Yellow + other.getName() + " is no longer invincible.");
other.sendMessage(Colors.Yellow + player.getName() + " has taken away your invincibility.");
}
}
// Invincibility for one's self
} else {
if (!invinciblePlayers.contains(player.getName())) {
invinciblePlayers.add(player.getName());
player.sendMessage(Colors.Yellow + "You are now invincible!");
} else {
invinciblePlayers.remove(player.getName());
player.sendMessage(Colors.Yellow + "You are no longer invincible.");
}
}
return true;
} else if ((split[0].equalsIgnoreCase("/stack")
|| split[0].equalsIgnoreCase("/;"))
&& player.canUseCommand("/stack")) {
hn[] items = player.getInventory().getArray();
int len = items.length;
int affected = 0;
for (int i = 0; i < len; i++) {
hn item = items[i];
// Avoid infinite stacks and stacks with durability
if (item == null || item.a <= 0 || item.d > 0) {
continue;
}
// Ignore buckets
if (item.c >= 325 && item.c <= 327) {
continue;
}
if (item.a < 64) {
int needed = 64 - item.a; // Number of needed items until 64
// Find another stack of the same type
for (int j = i + 1; j < len; j++) {
hn item2 = items[j];
// Avoid infinite stacks and stacks with durability
if (item2 == null || item2.a <= 0 || item2.d > 0) {
continue;
}
// Same type?
if (item2.c == item.c) {
// This stack won't fit in the parent stack
if (item2.a > needed) {
item.a = 64;
item2.a -= needed;
break;
// This stack will
} else {
items[j] = null;
item.a += item2.a;
needed = 64 - item.a;
}
affected++;
}
}
}
}
if (affected > 0) {
player.getInventory().updateInventory();
}
player.sendMessage(Colors.Yellow + "Items compacted into stacks!");
return true;
} else if (split[0].equalsIgnoreCase("/reload")
&& player.canUseCommand("/reload")
&& split.length > 1) {
if (split[1].equalsIgnoreCase("WorldGuard")) {
LoggerToChatHandler handler = new LoggerToChatHandler(player);
handler.setLevel(Level.ALL);
Logger minecraftLogger = Logger.getLogger("Minecraft");
minecraftLogger.addHandler(handler);
try {
loadConfiguration();
postReload();
player.sendMessage("WorldGuard configuration reloaded.");
} catch (Throwable t) {
player.sendMessage("Error while reloading: "
+ t.getMessage());
} finally {
minecraftLogger.removeHandler(handler);
}
return true;
}
}
return false;
@@ -295,6 +482,7 @@ public class WorldGuardListener extends PluginListener {
* @param split
* @return false if you want the command to be parsed.
*/
@Override
public boolean onConsoleCommand(String[] split) {
if (split[0].equalsIgnoreCase("fire-stop")) {
if (!stopFireSpread) {
@@ -331,6 +519,7 @@ public class WorldGuardListener extends PluginListener {
* @return true if you don't want the dropped item to be spawned in the
* world
*/
@Override
public boolean onItemDrop(Player player, Item item) {
if (itemDropBlacklist != null) {
int n = item.getItemId();
@@ -346,42 +535,107 @@ public class WorldGuardListener extends PluginListener {
}
}
/*if (!itemDurability) {
item.setDamage(0);
}*/
return false;
}
/**
* Called when someone presses right click. If they right clicked with a
* block you can return true to cancel that. You can intercept this to add
* your own right click actions to different item types (see itemInHand)
* Called when a player picks up an item.
*
* @param player
* player who picked up the item
* @param item
* item that was picked up
* @return true if you want to leave the item where it was
*/
@Override
public boolean onItemPickUp(Player player, Item item) {
if (blacklist != null && blacklist.hasOnAcquire()) {
if (!blacklist.onSilentAcquire(item.getItemId(), player)) {
return true;
}
}
return false;
}
/**
* Called when a player's inventory is modified.
*
* @param player
* player who's inventory was modified
* @return true if you want any changes to be reverted
*/
@Override
public boolean onInventoryChange(Player player) {
if (blacklist != null && blacklist.hasOnAcquire()) {
hn[] items = player.getInventory().getArray();
boolean needUpdate = false;
for (int i = 0; i < items.length; i++) {
if (items[i] != null) {
if (!blacklist.onAcquire(items[i].c, player)) {
items[i] = null;
needUpdate = true;
}
}
}
if (needUpdate) {
player.getInventory().updateInventory();
}
}
return false;
}
/**
* Called when a player uses an item (rightclick with item in hand)
* @param player the player
* @param blockPlaced where a block would end up when the item was a bucket
* @param blockClicked
* @param item the item being used (in hand)
* @return true to prevent using the item.
*/
@Override
public boolean onItemUse(Player player, Block blockPlaced,
Block blockClicked, Item item) {
if (blacklist != null) {
int itemId = item.getItemId();
if (itemId >= 325 && itemId <= 327) {
if (!blacklist.onCreate(itemId, player)) {
return true;
}
}
}
return false;
}
/**
* Called when someone places a block. Return true to prevent the placement.
*
* @param player
* @param blockPlaced
* @param blockClicked
* @param itemInHand
* @return false if you want the action to go through
* @return true if you want to undo the block placement
*/
public boolean onBlockCreate(Player player, Block blockPlaced, Block blockClicked,
int itemInHand) {
if (blacklist != null) {
if (!blacklist.onCreate(itemInHand, player)) {
// Water/lava bucket fix
if (itemInHand == 326 || itemInHand == 327) {
final int x = blockPlaced.getX();
final int y = blockPlaced.getY();
final int z = blockPlaced.getZ();
final int existingID = etc.getServer().getBlockIdAt(x, y, z);
@Override
public boolean onBlockPlace(Player player, Block blockPlaced,
Block blockClicked, Item itemInHand) {
int itemId = itemInHand.getItemId();
// This is REALLY BAD, but there's no other choice
// at the moment that is as reliable
timer.schedule(new TimerTask() {
public void run() {
try {
etc.getServer().setBlockAt(existingID, x, y, z);
} catch (Throwable t) {}
}
}, 200); // Just in case
if (blacklist != null) {
if (itemId < 325 || itemId > 327) {
if (!blacklist.onCreate(itemId, player)) {
return true;
}
return true;
}
if (!blacklist.onUse(blockClicked, player)) {
@@ -418,6 +672,7 @@ public class WorldGuardListener extends PluginListener {
* @param block
* @return
*/
@Override
public boolean onBlockDestroy(Player player, Block block) {
int type = block.getType();
@@ -430,88 +685,6 @@ public class WorldGuardListener extends PluginListener {
return true;
}
}
if (blockLagFix
&& type != 7 // Bedrock
&& type != 46 // TNT
&& type != 50 // Torch
&& type != 51 // Fire
&& type != 59 // Crops
&& type != 62 // Burning furnace
&& type != 64 // Wooden door
&& type != 69 // Lever
&& type != 71 // Iron door
&& type != 75 // Redstone torch
&& type != 76 // Redstone torch
&& type != 77 // Stone button
) {
// Check other plugins first to see if this block can be
// destroyed. Since this causes the hook to eventually call
// twice, we try to nullify it below
if (canDestroyBlock(player, block)) {
if (block.getStatus() == 3 && canBreakBlock(player, block)) {
int dropItem = type;
int count = 1;
if (type == 1) { dropItem = 4; } // Stone
else if (type == 2) { dropItem = 3; } // Grass
else if (type == 16) { dropItem = 263; } // Coal ore
else if (type == 18) { // Leaves
if (rand.nextDouble() > 0.95) {
dropItem = 6;
} else {
dropItem = 0;
}
}
else if (type == 20) { dropItem = 0; } // Glass
else if (type == 43) { dropItem = 44; } // Double step
else if (type == 47) { dropItem = 0; } // Bookshelves
else if (type == 52) { dropItem = 0; } // Mob spawner
else if (type == 53) { dropItem = 5; } // Wooden stairs
else if (type == 55) { dropItem = 331; } // Redstone wire
else if (type == 56) { dropItem = 264; } // Diamond ore
else if (type == 60) { dropItem = 3; } // Soil
else if (type == 63) { dropItem = 323; } // Sign post
else if (type == 67) { dropItem = 4; } // Cobblestone stairs
else if (type == 68) { dropItem = 323; } // Wall sign
else if (type == 73) { dropItem = 331; count = 4; } // Redstone ore
else if (type == 74) { dropItem = 331; count = 4; } // Glowing redstone ore
else if (type == 78) { dropItem = 0; } // Snow
else if (type == 79) { dropItem = 0; } // Ice
else if (type == 82) { dropItem = 337; count = 4; } // Clay
else if (type == 83) { dropItem = 338; } // Reed
else if (type == 89) { dropItem = 348; } // Lightstone
etc.getServer().setBlockAt(0, block.getX(), block.getY(), block.getZ());
if (dropItem > 0) {
for (int i = 0; i < count; i++) {
etc.getServer().dropItem(block.getX(), block.getY(), block.getZ(),
dropItem, i);
}
// Drop flint with gravel
if (type == 13) {
if (rand.nextDouble() >= 0.9) {
etc.getServer().dropItem(block.getX(), block.getY(), block.getZ(),
318, 1);
}
}
}
// Now loop this hook back through!
simulateBlockDestroy(player, block);
}
return true;
}
// So we don't have double hook calls caused by the
// plugin/protection check
block.setType(0);
block.setStatus(2);
}
return false;
}
@@ -523,6 +696,7 @@ public class WorldGuardListener extends PluginListener {
* @param block
* @return
*/
@Override
public boolean onBlockBreak(Player player, Block block) {
if (blacklist != null) {
if (!blacklist.onBreak(block, player)) {
@@ -542,6 +716,7 @@ public class WorldGuardListener extends PluginListener {
* complex block that changed
* @return true if you want any changes to be reverted
*/
@Override
public boolean onComplexBlockChange(Player player, ComplexBlock complexBlock) {
if (blacklist != null) {
if (complexBlock instanceof Chest) {
@@ -584,6 +759,7 @@ public class WorldGuardListener extends PluginListener {
* complex block that's being sent
* @return true if you want the chest, furnace or sign to be empty
*/
@Override
public boolean onSendComplexBlock(Player player, ComplexBlock complexBlock) {
if (blacklist != null) {
if (complexBlock instanceof Chest) {
@@ -619,6 +795,7 @@ public class WorldGuardListener extends PluginListener {
*
* @return true if you dont want the fire to ignite.
*/
@Override
public boolean onIgnite(Block block, Player player) {
if (preventLavaFire && block.getStatus() == 1) {
return true;
@@ -663,6 +840,7 @@ public class WorldGuardListener extends PluginListener {
*
* @return true if you dont the block to explode.
*/
@Override
public boolean onExplode(Block block) {
if (blockCreepers && block.getStatus() == 2) {
return true;
@@ -688,6 +866,7 @@ public class WorldGuardListener extends PluginListener {
*
* @return true if you dont want the substance to flow.
*/
@Override
public boolean onFlow(Block blockFrom, Block blockTo) {
int x = blockFrom.getX();
int y = blockFrom.getY();
@@ -733,70 +912,183 @@ public class WorldGuardListener extends PluginListener {
return false;
}
/**
* Called when the game is checking the physics for a certain block.
* This method is called frequently whenever a nearby block is changed,
* or if the block has just been placed.
* Currently the only supported blocks are sand, gravel and portals.
*
* @param block Block which requires special physics
* @param boolean true if this block has just been placed
* @return true if you do want to stop the default physics for this block
*/
public boolean onBlockPhysics(Block block, boolean placed) {
int id = block.getType();
if (id == 13 && noPhysicsGravel) {
return true;
}
if (id == 12 && noPhysicsSand) {
return true;
}
if (id == 90 && allowPortalAnywhere) {
return true;
}
return false;
}
/**
* Called when a players health changes.
* @param player
* the player which health is changed.
* @param oldValue
* old lives value
* @param newValue
* new lives value
* @return
* return true to stop the change.
*/
@Override
public boolean onHealthChange(Player player, int oldValue, int newValue) {
String playerName = player.getName();
if (invinciblePlayers.contains(playerName)) {
return oldValue > newValue;
}
if (loginProtection > 0 || spawnProtection > 0 || kickOnDeath) {
long now = System.currentTimeMillis();
boolean recentLogin = false;
if (recentLogins.containsKey(playerName)) {
long time = recentLogins.get(playerName);
long elapsed = now - time;
if (loginProtection > 0 && elapsed <= loginProtection * 1000
&& newValue < oldValue) {
return true;
}
recentLogin = elapsed <= 2000;
if (elapsed > 2000 && elapsed > loginProtection * 1000) {
recentLogins.remove(playerName);
}
}
if (kickOnDeath && oldValue == -1 && newValue == 20 && !recentLogin) {
player.kick("You died! Rejoin please.");
return false;
}
if (spawnProtection > 0) {
if (oldValue == -1 && newValue == 20 && !recentLogin) { // Player was just respawned
lastSpawn.put(player.getName(), now);
} else if (lastSpawn.containsKey(playerName)) {
long time = lastSpawn.get(playerName);
long elapsed = now - time;
if (elapsed < spawnProtection * 1000) {
return newValue < oldValue;
} else {
lastSpawn.remove(playerName);
}
}
}
}
return false;
}
/**
* Called when a living object is attacked.
* tip:
* Use isMob() and isPlayer() and getPlayer().
*
* @param type
* type of damage dealt.
* @param attacker
* object that is attacking.
* @param defender
* object that is defending.
* @param amount
* amount of damage dealt.
*
* @return
*/
@Override
public boolean onDamage(PluginLoader.DamageType type, BaseEntity attacker,
BaseEntity defender, int amount) {
if (defender.isPlayer()) {
Player player = defender.getPlayer();
if (invinciblePlayers.contains(player.getName())) {
return true;
}
if (disableFallDamage && type == PluginLoader.DamageType.FALL) {
return true;
}
if (disableLavaDamage && type == PluginLoader.DamageType.LAVA) {
return true;
}
if (disableFireDamage && (type == PluginLoader.DamageType.FIRE
|| type == PluginLoader.DamageType.FIRE_TICK)) {
return true;
}
if (disableWaterDamage && type == PluginLoader.DamageType.WATER) {
return true;
}
if (type == PluginLoader.DamageType.WATER
&& amphibiousPlayers.contains(player.getName())) {
return true;
}
}
return false;
}
/**
* Called when water or lava tries to populate a block, you can prevent
* crushing of torches, railways, flowers etc. You can alternatively allow
* to let normally solid blocks be crushed.
*
* @param currentState the current tristate, once it's set to a non DEFAULT_ACTION it is final.
* @param liquidBlock the type of the attacking block
* @param targetBlock the block to be destroyed
* @return final after a non DEFAULT_ACTION
*/
@Override
public PluginLoader.HookResult onLiquidDestroy(PluginLoader.HookResult currentState,
int liquidBlockId, Block targetBlock) {
if (preventWaterDamage != null && liquidBlockId <= 9) {
if (preventWaterDamage.contains(targetBlock.getType())) {
return PluginLoader.HookResult.PREVENT_ACTION;
}
}
return PluginLoader.HookResult.DEFAULT_ACTION;
}
/**
* Called on player disconnect
*
* @param player
*/
@Override
public void onDisconnect(Player player) {
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.
*
* @param player
* @param block
* @return
*/
private 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();
}
invinciblePlayers.remove(player.getName());
amphibiousPlayers.remove(player.getName());
recentLogins.remove(player.getName());
}
/**
@@ -1,64 +0,0 @@
// $Id$
/*
* WorldGuard
* Copyright (C) 2010 sk89q <http://www.sk89q.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldguard;
import java.util.logging.Formatter;
import java.util.logging.LogRecord;
import java.util.logging.Level;
import java.io.PrintWriter;
import java.io.StringWriter;
/**
* Used for formatting.
*
* @author sk89q
*/
public class ConsoleLogFormat extends Formatter {
public String format(LogRecord record) {
StringBuilder text = new StringBuilder();
Level level = record.getLevel();
if (level == Level.FINEST) {
text.append("[FINEST] ");
} else if (level == Level.FINER) {
text.append("[FINER] ");
} else if (level == Level.FINE) {
text.append("[FINE] ");
} else if (level == Level.INFO) {
text.append("[INFO] ");
} else if (level == Level.WARNING) {
text.append("[WARNING] ");
} else if (level == Level.SEVERE) {
text.append("[SEVERE] ");
}
text.append(record.getMessage());
text.append("\r\n");
Throwable t = record.getThrown();
if (t != null) {
StringWriter writer = new StringWriter();
t.printStackTrace(new PrintWriter(writer));
text.append(writer.toString());
}
return text.toString();
}
}
+14 -4
View File
@@ -25,6 +25,7 @@
# - on-create (the item/block in the user's inventory is being created)
# - on-use (the block is right clicked)
# - on-drop (the item is being dropped from the player's inventory)
# - on-acquire (the item enters a player's inventory via some method)
#
# Actions (for events):
# - deny (deny completely)
@@ -34,6 +35,13 @@
# - kick (kick player)
# - ban (ban player)
#
# With the on-acquire event, it will completely block item pick ups
# (the item will still be on the ground) if you use 'deny' but the other
# actions (notify, log, etc.) won't do anything. However, if the player
# receives the item via a different method (i.e. from a chest), all actions
# will work although the item is removed after a short delay rather than
# blocked from the beginning (as it is part client-side).
#
# Users with the /worldguardnotify permission will be receive notifications.
#
# -------------
@@ -75,7 +83,9 @@
#[lever]
#on-break=deny
#[diamondpickaxe,woodpickaxe]
#on-drop=deny
#comment=durability cheat
#message=Your item was destroyed
# 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
+97
View File
@@ -0,0 +1,97 @@
#
# WorldGuard configuration
#
# This is a starter copy of WorldGuard's configuration so you can configure
# WorldGuard right from the beginning. Copy it into your server folder
# (into where server.properties resides) and edit the file as your desire.
#
# Display a summary of WorldGuard's core protection features (lava fire
# disable and others) when Worldguard starts up.
summary-on-start=true
# Toggle the item durabiltiy fix
item-durability=true
# Simulate the sponge from Classic. It removes water and prevents water from
# flowing into an area containing sponges. Use this to protect circuits
# or to assist in underwater projects.
simulate-sponge=false
sponge-radius=3
# Simulate classic water. Water will spread infinitely. Be aware that this
# may likely flood your server.
classic-water=false
# Allow the placement of portal blocks anyway.
allow-portal-anywhere=false
# Prevent gravel from falling.
no-physics-gravel=false
# Prevent sand from falling.
no-physics-sand=false
# Kick the older player if a player attempts to join again without first
# logging out the first instance.
enforce-single-session=true
# List of items to destroy on drop. You can also accomplish this using
# the blacklist.
item-drop-blacklist=
# Simple prevention
block-creepers=false
block-lighter=false
block-tnt=false
# Login protection prevents players from getting any damage for a few
# seconds after joining the server.
login-protection=3
# Spawn protection prevents players from getting any damage after spawning
# (after dying).
spawn-protection=0
# This is an deprecated feature to fix a bug. This kicks a user once the
# player dies and attemtps to respawn. The player can then still rejoin
# and be alive.
kick-on-death=false
# Disable various ways of damage. If you want to give someone invincibility
# or the ability to breathe under water, create the groups wg-invincible
# and wg-amphibious respectively and apply them to users as needed.
disable-fall-damage=false
disable-lava-damage=false
disable-fire-damage=false
disable-water-damage=false
# Disable fire spreading between blocks. Note that this does not prevent
# fire damage -- it only prevents fire spread.
disable-all-fire-spread=false
# List blocks that fire should not spread to or between. Cloth and wood
# are some good examples.
disallowed-fire-spread-blocks=
# Prevent lava from starting fires.
disable-lava-fire=true
# List of blocks that lava is allowed to spread onto.
allowed-lava-spread-blocks=
# List of blocks that should not be destroyed by water (Redstone wire,
# minecart tracks, flowers, etc.).
disable-water-damage-blocks=
# Control where to log blacklist events to. You can use multiple log
# methods as you please.
log-console=true
log-database-dsn=jdbc\:mysql\://localhost\:3306/minecraft
log-database-pass=
log-database-table=blacklist_events
log-database-user=root
log-database=false
log-file-open-files=10
log-file-path=worldguard/logs/%Y-%m-%d.log
log-file=false