Compare commits

..
19 Commits
Author SHA1 Message Date
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
8 changed files with 320 additions and 323 deletions

No files matched your search

+21
View File
@@ -1,3 +1,24 @@
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.
+34 -13
View File
@@ -22,11 +22,11 @@ use or not:
- 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.
- OR just fix the durability bug.
- Prevent gravel and sand from falling.
- OR just fix the durability bug. *Requires special version of hMod
- Prevent gravel and sand from falling. *Requires special version of hMod
- Allow portal blocks to be placed anywhere.
*Requires special version of hMod
hMod is required as WorldGuard is a plugin for hMod.
@@ -37,7 +37,16 @@ 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.
- item-durability (def. true)
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)
@@ -48,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.
@@ -58,12 +67,15 @@ WorldGuard on your server. You can either restart your server or use
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)
@@ -85,7 +97,7 @@ WorldGuard on your server. You can either restart your server or use
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)
@@ -107,14 +119,17 @@ 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.
- log-console (def. true)
For blacklist log actions, print to console.
@@ -178,6 +193,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
---------------
+1 -1
View File
@@ -1,2 +1,2 @@
Manifest-Version: 1.0
WorldGuard-Version: 1.4.1
WorldGuard-Version: 1.6
+107 -34
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,40 +56,76 @@ 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.ITEM_PICK_UP, 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);
loader.addListener(PluginLoader.Hook.INVENTORY_CHANGE, listener, this,
PluginListener.Priority.HIGH);
loader.addListener(PluginLoader.Hook.BLOCK_PHYSICS, listener, this,
PluginListener.Priority.MEDIUM);
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("DISCONNECT", PluginListener.Priority.HIGH);
registerHook("ITEM_DROP", PluginListener.Priority.HIGH);
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 (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;
}
}
/**
@@ -134,4 +173,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();
}
}
+151 -160
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.
@@ -58,12 +55,20 @@ public class WorldGuardListener extends PluginListener {
* Properties file for WorldGuard.
*/
private PropertiesFile properties = new PropertiesFile("worldguard.properties");
/**
* Stop fire spread mode.
* List of players with god mode on.
*/
private Set<String> invinciblePlayers = 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;
@@ -72,7 +77,6 @@ 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;
@@ -81,6 +85,9 @@ public class WorldGuardListener extends PluginListener {
private boolean noPhysicsGravel;
private boolean noPhysicsSand;
private boolean allowPortalAnywhere;
private int loginProtection;
private int spawnProtection;
private boolean kickOnDeath;
private Blacklist blacklist;
/**
@@ -129,24 +136,28 @@ public class WorldGuardListener extends PluginListener {
public void loadConfiguration() {
properties.load();
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);
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", true);
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);
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);
@@ -171,18 +182,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));
@@ -235,6 +246,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()) {
@@ -252,10 +264,15 @@ 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());
}
}
/**
@@ -266,6 +283,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")) {
@@ -287,6 +305,40 @@ 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;
}
return false;
@@ -299,6 +351,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) {
@@ -335,6 +388,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();
@@ -350,9 +404,9 @@ public class WorldGuardListener extends PluginListener {
}
}
if (!itemDurability) {
/*if (!itemDurability) {
item.setDamage(0);
}
}*/
return false;
}
@@ -366,6 +420,7 @@ public class WorldGuardListener extends PluginListener {
* 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)) {
@@ -383,9 +438,10 @@ public class WorldGuardListener extends PluginListener {
* 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()) {
hj[] items = player.getInventory().getArray();
hl[] items = player.getInventory().getArray();
boolean needUpdate = false;
for (int i = 0; i < items.length; i++) {
@@ -416,6 +472,7 @@ public class WorldGuardListener extends PluginListener {
* @param itemInHand
* @return false if you want the action to go through
*/
@Override
public boolean onBlockCreate(Player player, Block blockPlaced, Block blockClicked,
int itemInHand) {
if (blacklist != null) {
@@ -474,6 +531,7 @@ public class WorldGuardListener extends PluginListener {
* @param block
* @return
*/
@Override
public boolean onBlockDestroy(Player player, Block block) {
int type = block.getType();
@@ -486,88 +544,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, 1);
}
// 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;
}
@@ -579,6 +555,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)) {
@@ -598,6 +575,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) {
@@ -640,6 +618,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) {
@@ -675,6 +654,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;
@@ -719,6 +699,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;
@@ -744,6 +725,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();
@@ -817,70 +799,79 @@ public class WorldGuardListener extends PluginListener {
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 true;
}
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 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());
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();
}
}
@@ -1,47 +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.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Formatter;
import java.util.logging.LogRecord;
import java.util.logging.Level;
/**
* Used for formatting.
*
* @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();
text.append("[");
text.append(dateFormat.format(new Date(record.getMillis())));
text.append("] ");
text.append(record.getMessage());
text.append("\r\n");
return text.toString();
}
}
+6 -4
View File
@@ -16,9 +16,6 @@ sponge-radius=3
# Simulate classic water
classic-water=false
# Fix block lag
block-lag-fix=false
# Adjust physics
allow-portal-anywhere=false
no-physics-gravel=false
@@ -33,12 +30,17 @@ block-creepers=false
block-lighter=false
block-tnt=false
# Health related
login-protection=3
spawn-protection=0
kick-on-death=false
# Control fire
disable-all-fire-spread=false
disallowed-fire-spread-blocks=
# Disable lava fire and spread
disable-lava-fire=false
disable-lava-fire=true
allowed-lava-spread-blocks=
# Log/blacklist