Compare commits

...
10 Commits
16 changed files with 790 additions and 210 deletions

No files matched your search

+9
View File
@@ -1,3 +1,12 @@
1.8:
- Updated for Minecraft beta.
- Blacklist hooks have CHANGED. The new hooks are work better. on-create has
been replaced with on-place (for block placement) and on-use
(for item usage, light buckets and lighters). The old on-use is now
on-right-click although it currently does nothing.
- Added coordinates to blacklist file logger.
- Added suffocation damage prevention.
1.7.1:
- Updated for v0.2.8.
+86
View File
@@ -0,0 +1,86 @@
<project name="WorldGuard" default="dist" basedir=".">
<description>WorldGuard fixes bugs with Minecraft SMP and provides for
protection.</description>
<property name="src.dir" location="src"/>
<property name="build.dir" location="build"/>
<property name="dist.dir" location="dist"/>
<property name="release.dir" location="release"/>
<property name="lib.dir" location="lib"/>
<target name="init">
<mkdir dir="${build.dir}"/>
</target>
<!-- Compile the source files -->
<target name="compile" depends="init">
<javac srcdir="${src.dir}" deprecation="true" includeantruntime="true" destdir="${build.dir}" debug="true">
<classpath>
<fileset dir="${lib.dir}">
<include name="*.jar"/>
</fileset>
</classpath>
</javac>
</target>
<!-- Build the .jar -->
<target name="jar" depends="compile">
<mkdir dir="${dist.dir}"/>
<manifest file="manifest.mf" mode="replace">
<attribute name="Implementation-Title" value="WorldGuard"/>
<attribute name="Implementation-Version" value="${version}"/>
<attribute name="WorldGuard-Version" value="${version}"/>
<attribute name="Class-Path" value="WorldGuard.jar"/>
</manifest>
<jar jarfile="${dist.dir}/WorldGuard.jar" basedir="${build.dir}" manifest="manifest.mf"/>
</target>
<!-- Create the .jar -->
<target name="dist">
<property name="version" value="nightly"/>
<antcall target="jar"/>
</target>
<!-- Build a release -->
<target name="release">
<input message="Enter version:" addproperty="version"/>
<antcall target="jar"/>
<delete dir="${release.dir}"/>
<mkdir dir="${release.dir}"/>
<copy todir="${release.dir}">
<fileset dir="."/>
<globmapper from="*.txt" to="*.txt"/>
</copy>
<copy file="worldguard.properties" todir="${release.dir}"/>
<copy tofile="${release.dir}/WorldGuard.jar" file="${dist.dir}/WorldGuard.jar"/>
<zip destfile="${release.dir}/worldguard-${version}.zip" basedir="${release.dir}" excludes="*.zip"/>
<mkdir dir="${release.dir}/src"/>
<copy todir="${release.dir}/src">
<fileset dir="${src.dir}"/>
</copy>
<zip destfile="${release.dir}/worldguard-${version}-source.zip" basedir="${release.dir}" excludes="*.zip"/>
</target>
<!-- Clean the output -->
<target name="clean">
<delete dir="${build.dir}"/>
<delete dir="${dist.dir}"/>
<delete dir="${release.dir}"/>
</target>
<!--<target name="-get-version-git" if="git-revision">
<sequential>
<exec executable="git" failifexecutionfails="false" outputproperty="git-revision">
<arg value="rev-parse"/>
<arg value="HEAD"/>
</exec>
<exec executable="git" outputproperty="git-revision-dirty">
<arg value="diff"/>
<arg value="- -shortstat"/>
</exec>
<condition else="dev-${git-revision}-modified" property="version" value="dev-${git-revision}">
<equals arg1="" arg2="${git-revision-dirty}"/>
</condition>
</sequential>
</target>-->
</project>
-2
View File
@@ -1,2 +0,0 @@
Manifest-Version: 1.0
WorldGuard-Version: 1.7.1
+32 -11
View File
@@ -141,20 +141,20 @@ public class Blacklist {
}
/**
* Called on right click. Returns true to let the action pass through.
* Called on place. Returns true to let the action pass through.
*
* @param item
* @param player
* @return
*/
public boolean onCreate(int item, Player player) {
public boolean onPlace(int item, Player player) {
List<BlacklistEntry> entries = getEntries(item);
if (entries == null) {
return true;
}
boolean ret = true;
for (BlacklistEntry entry : entries) {
if (!entry.onCreate(item, player)) {
if (!entry.onPlace(item, player)) {
ret = false;
}
}
@@ -164,18 +164,39 @@ public class Blacklist {
/**
* Called on right click upon. Returns true to let the action pass through.
*
* @param item
* @param block
* @param player
* @return
*/
public boolean onUse(Block block, Player player) {
public boolean onRightClick(Block block, Player player) {
List<BlacklistEntry> entries = getEntries(block.getType());
if (entries == null) {
return true;
}
boolean ret = true;
for (BlacklistEntry entry : entries) {
if (!entry.onUse(block, player)) {
if (!entry.onRightClick(block, player)) {
ret = false;
}
}
return ret;
}
/**
* Called on item use. Returns true to let the action pass through.
*
* @param item
* @param player
* @return
*/
public boolean onUse(int item, Player player) {
List<BlacklistEntry> entries = getEntries(item);
if (entries == null) {
return true;
}
boolean ret = true;
for (BlacklistEntry entry : entries) {
if (!entry.onUse(item, player)) {
ret = false;
}
}
@@ -345,12 +366,12 @@ public class Blacklist {
} else if (parts[0].equalsIgnoreCase("on-left")
|| parts[0].equalsIgnoreCase("on-destroy-with")) {
entry.setDestroyWithActions(parts[1].split(","));
} else if (parts[0].equalsIgnoreCase("on-right")
|| parts[0].equalsIgnoreCase("on-create")) {
entry.setCreateActions(parts[1].split(","));
} else if (parts[0].equalsIgnoreCase("on-right-on")
|| parts[0].equalsIgnoreCase("on-use")) {
} else if (parts[0].equalsIgnoreCase("on-place")) {
entry.setPlaceActions(parts[1].split(","));
} else if (parts[0].equalsIgnoreCase("on-use")) {
entry.setUseActions(parts[1].split(","));
} else if (parts[0].equalsIgnoreCase("on-right-click")) {
entry.setRightClickActions(parts[1].split(","));
} else if (parts[0].equalsIgnoreCase("on-drop")) {
entry.setDropActions(parts[1].split(","));
} else if (parts[0].equalsIgnoreCase("on-acquire")) {
+69 -15
View File
@@ -55,13 +55,17 @@ public class BlacklistEntry {
*/
private String[] destroyWithActions;
/**
* List of actions to perform on right click.
* List of actions to perform on block placement.
*/
private String[] createActions;
private String[] placeActions;
/**
* List of actions to perform on item use.
*/
private String[] useActions;
/**
* List of actions to perform on right click upon.
*/
private String[] useActions;
private String[] rightClickActions;
/**
* List of actions to perform on drop.
*/
@@ -160,17 +164,17 @@ public class BlacklistEntry {
}
/**
* @return the rightClickActions
* @return
*/
public String[] getCreateActions() {
return createActions;
public String[] getPlaceActions() {
return placeActions;
}
/**
* @param actions
*/
public void setCreateActions(String[] actions) {
this.createActions = actions;
public void setPlaceActions(String[] actions) {
this.placeActions = actions;
}
/**
@@ -187,6 +191,20 @@ public class BlacklistEntry {
this.useActions = actions;
}
/**
* @return
*/
public String[] getRightClickActions() {
return rightClickActions;
}
/**
* @param actions
*/
public void setRightClickActions(String[] actions) {
this.rightClickActions = actions;
}
/**
* @return
*/
@@ -401,14 +419,14 @@ public class BlacklistEntry {
}
/**
* Called on right click. Returns true to let the action pass through.
* Called on block placement. Returns true to let the action pass through.
*
* @param item
* @param player
* @return
*/
public boolean onCreate(final int item, final Player player) {
if (createActions == null) {
public boolean onPlace(final int item, final Player player) {
if (placeActions == null) {
return true;
}
@@ -416,7 +434,7 @@ public class BlacklistEntry {
ActionHandler handler = new ActionHandler() {
public void log(String itemName) {
blacklist.getLogger().logCreateAttempt(player, item, comment);
blacklist.getLogger().logPlaceAttempt(player, item, comment);
}
public void kick(String itemName) {
player.kick("You can't place " + itemName);
@@ -433,7 +451,43 @@ public class BlacklistEntry {
}
};
return process(item, player, createActions, handler, true, false);
return process(item, player, placeActions, handler, true, false);
}
/**
* Called on use. Returns true to let the action pass through.
*
* @param item
* @param player
* @return
*/
public boolean onUse(final int item, final Player player) {
if (useActions == null) {
return true;
}
final BlacklistEntry entry = this;
ActionHandler handler = new ActionHandler() {
public void log(String itemName) {
blacklist.getLogger().logUseAttempt(player, item, comment);
}
public void kick(String itemName) {
player.kick("You can't use " + itemName);
}
public void ban(String itemName) {
entry.banPlayer(player, "Banned: You can't use " + itemName);
}
public void notifyAdmins(String itemName) {
entry.notifyAdmins(player.getName() + " (use) " + itemName
+ (comment != null ? " (" + comment + ")" : "") + ".");
}
public void tell(String itemName) {
player.sendMessage(Colors.Yellow + "You're not allowed to use " + itemName + ".");
}
};
return process(item, player, useActions, handler, false, false);
}
/**
@@ -443,7 +497,7 @@ public class BlacklistEntry {
* @param player
* @return
*/
public boolean onUse(final Block block, final Player player) {
public boolean onRightClick(final Block block, final Player player) {
if (useActions == null) {
return true;
}
@@ -452,7 +506,7 @@ public class BlacklistEntry {
ActionHandler handler = new ActionHandler() {
public void log(String itemName) {
blacklist.getLogger().logUseAttempt(player, block, comment);
blacklist.getLogger().logRightClickAttempt(player, block, comment);
}
public void kick(String itemName) {
player.kick("You can't use " + itemName);
+17 -5
View File
@@ -88,9 +88,21 @@ public class BlacklistLogger implements BlacklistLoggerHandler {
* @param player
* @param block
*/
public void logUseAttempt(Player player, Block block, String comment) {
public void logUseAttempt(Player player, int item, String comment) {
for (BlacklistLoggerHandler handler : handlers) {
handler.logUseAttempt(player, block, comment);
handler.logUseAttempt(player, item, comment);
}
}
/**
* Log a right click on attempt.
*
* @param player
* @param block
*/
public void logRightClickAttempt(Player player, Block block, String comment) {
for (BlacklistLoggerHandler handler : handlers) {
handler.logRightClickAttempt(player, block, comment);
}
}
@@ -107,14 +119,14 @@ public class BlacklistLogger implements BlacklistLoggerHandler {
}
/**
* Log a right click attempt.
* Log a place attempt.
*
* @param player
* @param item
*/
public void logCreateAttempt(Player player, int item, String comment) {
public void logPlaceAttempt(Player player, int item, String comment) {
for (BlacklistLoggerHandler handler : handlers) {
handler.logCreateAttempt(player, item, comment);
handler.logPlaceAttempt(player, item, comment);
}
}
+11 -4
View File
@@ -38,12 +38,12 @@ public interface BlacklistLoggerHandler {
*/
public void logBreakAttempt(Player player, Block block, String comment);
/**
* Log a right click on attempt.
* Log a use attempt.
*
* @param player
* @param block
*/
public void logUseAttempt(Player player, Block block, String comment);
public void logUseAttempt(Player player, int item, String comment);
/**
* Right a left click attempt.
*
@@ -52,12 +52,19 @@ public interface BlacklistLoggerHandler {
*/
public void logDestroyWithAttempt(Player player, int item, String comment);
/**
* Log a right click attempt.
* Log a place attempt.
*
* @param player
* @param item
*/
public void logCreateAttempt(Player player, int item, String comment);
public void logPlaceAttempt(Player player, int item, String comment);
/**
* Log a right click on attempt.
*
* @param player
* @param item
*/
public void logRightClickAttempt(Player player, Block block, String comment);
/**
* Log a drop attempt.
*
+16 -4
View File
@@ -60,9 +60,9 @@ public class ConsoleLoggerHandler implements BlacklistLoggerHandler {
* @param player
* @param block
*/
public void logUseAttempt(Player player, Block block, String comment) {
public void logRightClickAttempt(Player player, Block block, String comment) {
logger.log(Level.INFO, "WorldGuard: " + player.getName()
+ " tried to use " + getFriendlyItemName(block.getType())
+ " tried to right click " + getFriendlyItemName(block.getType())
+ (comment != null ? " (" + comment + ")" : ""));
}
@@ -84,9 +84,21 @@ public class ConsoleLoggerHandler implements BlacklistLoggerHandler {
* @param player
* @param item
*/
public void logCreateAttempt(Player player, int item, String comment) {
public void logPlaceAttempt(Player player, int item, String comment) {
logger.log(Level.INFO, "WorldGuard: " + player.getName()
+ " tried to create " + getFriendlyItemName(item)
+ " tried to place " + getFriendlyItemName(item)
+ (comment != null ? " (" + comment + ")" : ""));
}
/**
* Log a use attempt.
*
* @param player
* @param item
*/
public void logUseAttempt(Player player, int item, String comment) {
logger.log(Level.INFO, "WorldGuard: " + player.getName()
+ " tried to use " + getFriendlyItemName(item)
+ (comment != null ? " (" + comment + ")" : ""));
}
+17 -5
View File
@@ -146,8 +146,8 @@ public class DatabaseLoggerHandler implements BlacklistLoggerHandler {
* @param player
* @param block
*/
public void logUseAttempt(Player player, Block block, String comment) {
logEvent("USE", player.getName(),
public void logRightClickAttempt(Player player, Block block, String comment) {
logEvent("RIGHT_CLICK", player.getName(),
block.getX(), block.getY(), block.getZ(), block.getType(),
comment);
}
@@ -165,13 +165,25 @@ public class DatabaseLoggerHandler implements BlacklistLoggerHandler {
}
/**
* Log a right click attempt.
* Log a place attempt.
*
* @param player
* @param item
*/
public void logCreateAttempt(Player player, int item, String comment) {
logEvent("CREATE", player.getName(),
public void logPlaceAttempt(Player player, int item, String comment) {
logEvent("PLACE", player.getName(),
(int)Math.floor(player.getX()), (int)Math.floor(player.getY()),
(int)Math.floor(player.getZ()), item, comment);
}
/**
* Log a use attempt.
*
* @param player
* @param item
*/
public void logUseAttempt(Player player, int item, String comment) {
logEvent("USE", player.getName(),
(int)Math.floor(player.getX()), (int)Math.floor(player.getY()),
(int)Math.floor(player.getZ()), item, comment);
}
+29 -6
View File
@@ -206,6 +206,16 @@ public class FileLoggerHandler implements BlacklistLoggerHandler {
}
}
/**
* Gets the coordinates of a block in text form for the log.
*
* @param block
* @return
*/
private String getCoordinates(Block block) {
return "@" + block.getX() + "," + block.getY() + "," + block.getZ();
}
/**
* Log a block destroy attempt.
*
@@ -213,7 +223,8 @@ public class FileLoggerHandler implements BlacklistLoggerHandler {
* @param block
*/
public void logDestroyAttempt(Player player, Block block, String comment) {
log(player, "Tried to destroy " + getFriendlyItemName(block.getType()),
log(player, "Tried to destroy " + getFriendlyItemName(block.getType())
+ " " + getCoordinates(block),
comment);
}
@@ -224,7 +235,8 @@ public class FileLoggerHandler implements BlacklistLoggerHandler {
* @param block
*/
public void logBreakAttempt(Player player, Block block, String comment) {
log(player, "Tried to break " + getFriendlyItemName(block.getType()),
log(player, "Tried to break " + getFriendlyItemName(block.getType())
+ " " + getCoordinates(block),
comment);
}
@@ -234,8 +246,9 @@ public class FileLoggerHandler implements BlacklistLoggerHandler {
* @param player
* @param block
*/
public void logUseAttempt(Player player, Block block, String comment) {
log(player, "Tried to use " + getFriendlyItemName(block.getType()),
public void logRightClickAttempt(Player player, Block block, String comment) {
log(player, "Tried to right click " + getFriendlyItemName(block.getType())
+ " " + getCoordinates(block),
comment);
}
@@ -255,8 +268,18 @@ public class FileLoggerHandler implements BlacklistLoggerHandler {
* @param player
* @param item
*/
public void logCreateAttempt(Player player, int item, String comment) {
log(player, "Tried to create " + getFriendlyItemName(item), comment);
public void logPlaceAttempt(Player player, int item, String comment) {
log(player, "Tried to place " + getFriendlyItemName(item), comment);
}
/**
* Log a block use attempt.
*
* @param player
* @param item
*/
public void logUseAttempt(Player player, int item, String comment) {
log(player, "Tried to use " + getFriendlyItemName(item), comment);
}
/**
+43
View File
@@ -0,0 +1,43 @@
// $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/>.
*/
/**
* Inventory related functions.
*
* @author sk89q
*/
public class ItemArrayUtil {
/**
* Set the contents of an ItemArray.
*
* @param itemArray
* @param contents
*/
public static void setContents(ItemArray<?> itemArray, Item[] contents) {
int size = itemArray.getContentsSize();
for (int i = 0; i < size; i++) {
if (contents[i] == null) {
itemArray.removeItem(i);
} else {
itemArray.setSlot(contents[i], i);
}
}
}
}
+12 -42
View File
@@ -60,16 +60,9 @@ public class WorldGuard extends Plugin {
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("EXPLODE", PluginListener.Priority.HIGH);
registerHook("IGNITE", PluginListener.Priority.HIGH);
registerHook("FLOW", PluginListener.Priority.HIGH);
registerHook("LOGINCHECK", PluginListener.Priority.HIGH);
registerHook("LOGIN", PluginListener.Priority.MEDIUM);
registerHook("BLOCK_CREATED", PluginListener.Priority.HIGH);
@@ -78,38 +71,15 @@ public class WorldGuard extends Plugin {
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("ITEM_USE", PluginListener.Priority.HIGH);
registerHook("ITEM_PICK_UP", PluginListener.Priority.HIGH);
registerHook("SIGN_CHANGE", PluginListener.Priority.HIGH);
registerHook("OPEN_INVENTORY", 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");
}
registerHook("BLOCK_PHYSICS", PluginListener.Priority.MEDIUM);
registerHook("HEALTH_CHANGE", PluginListener.Priority.MEDIUM);
registerHook("DAMAGE", PluginListener.Priority.MEDIUM);
registerHook("LIQUID_DESTROY", PluginListener.Priority.MEDIUM);
if (missingFeatures.size() > 0) {
logger.log(Level.WARNING, "WorldGuard: Your version of hMod does not support "
@@ -133,7 +103,7 @@ public class WorldGuard extends Plugin {
etc.getLoader().addListener(hook, listener, this, priority);
return true;
} catch (IllegalArgumentException e) {
//logger.log(Level.WARNING, "WorldGuard: Missing hook " + name + "!");
logger.log(Level.WARNING, "WorldGuard: Missing hook " + name + "!");
return false;
}
}
+153 -101
View File
@@ -27,6 +27,7 @@ import java.util.Map;
import java.util.HashMap;
import java.util.Random;
import java.io.*;
import com.sk89q.worldedit.blocks.BlockType;
/**
* Event listener for Hey0's server mod.
@@ -81,7 +82,6 @@ public class WorldGuardListener extends PluginListener {
private boolean disableAllFire;
private boolean simulateSponge;
private int spongeRadius;
private boolean itemDurability;
private Set<Integer> fireNoSpreadBlocks;
private Set<Integer> allowedLavaSpreadOver;
private Set<Integer> itemDropBlacklist;
@@ -94,8 +94,12 @@ public class WorldGuardListener extends PluginListener {
private boolean disableLavaDamage;
private boolean disableFireDamage;
private boolean disableWaterDamage;
private boolean disableSuffocationDamage;
private boolean teleportOnSuffocation;
private int loginProtection;
private int spawnProtection;
private boolean teleportToHome;
private boolean exactRespawn;
private boolean kickOnDeath;
private Blacklist blacklist;
@@ -188,7 +192,6 @@ public class WorldGuardListener extends PluginListener {
classicWater = properties.getBoolean("classic-water", false);
simulateSponge = properties.getBoolean("simulate-sponge", true);
spongeRadius = Math.max(1, properties.getInt("sponge-radius", 3)) - 1;
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);
@@ -196,9 +199,13 @@ public class WorldGuardListener extends PluginListener {
disableLavaDamage = properties.getBoolean("disable-lava-damage", false);
disableFireDamage = properties.getBoolean("disable-fire-damage", false);
disableWaterDamage = properties.getBoolean("disable-water-damage", false);
disableSuffocationDamage = properties.getBoolean("disable-suffocation-damage", false);
teleportOnSuffocation = properties.getBoolean("teleport-on-suffocation", false);
loginProtection = properties.getInt("login-protection", 3);
spawnProtection = properties.getInt("spawn-protection", 0);
kickOnDeath = properties.getBoolean("kick-on-death", false);
teleportToHome = properties.getBoolean("teleport-to-home-on-death", false);
exactRespawn = properties.getBoolean("exact-respawn", false);
// Console log configuration
boolean logConsole = properties.getBoolean("log-console", true);
@@ -311,7 +318,8 @@ public class WorldGuardListener extends PluginListener {
player.sendMessage(Colors.Yellow + "Fire spread is currently globally disabled.");
}
if (loginProtection > 0 || spawnProtection > 0 || kickOnDeath) {
if (loginProtection > 0 || spawnProtection > 0
|| kickOnDeath || teleportToHome || exactRespawn) {
recentLogins.put(player.getName(), System.currentTimeMillis());
}
@@ -391,48 +399,50 @@ public class WorldGuardListener extends PluginListener {
} else if ((split[0].equalsIgnoreCase("/stack")
|| split[0].equalsIgnoreCase("/;"))
&& player.canUseCommand("/stack")) {
hn[] items = player.getInventory().getArray();
Item[] items = player.getInventory().getContents();
int len = items.length;
int affected = 0;
for (int i = 0; i < len; i++) {
hn item = items[i];
Item item = items[i];
// Avoid infinite stacks and stacks with durability
if (item == null || item.a <= 0 || item.d > 0) {
if (item == null || item.getAmount() <= 0
|| shouldNotStack(item.getItemId())) {
continue;
}
// Ignore buckets
if (item.c >= 325 && item.c <= 327) {
if (item.getItemId() >= 325 && item.getItemId() <= 327) {
continue;
}
if (item.a < 64) {
int needed = 64 - item.a; // Number of needed items until 64
if (item.getAmount() < 64) {
int needed = 64 - item.getAmount(); // 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];
Item item2 = items[j];
// Avoid infinite stacks and stacks with durability
if (item2 == null || item2.a <= 0 || item2.d > 0) {
if (item2 == null || item2.getAmount() <= 0
|| shouldNotStack(item.getItemId())) {
continue;
}
// Same type?
if (item2.c == item.c) {
if (item2.getItemId() == item.getItemId()) {
// This stack won't fit in the parent stack
if (item2.a > needed) {
item.a = 64;
item2.a -= needed;
if (item2.getAmount() > needed) {
item.setAmount(64);
item2.setAmount(item2.getAmount() - needed);
break;
// This stack will
} else {
items[j] = null;
item.a += item2.a;
needed = 64 - item.a;
item.setAmount(item.getAmount() + item2.getAmount());
needed = 64 - item.getAmount();
}
affected++;
@@ -442,7 +452,7 @@ public class WorldGuardListener extends PluginListener {
}
if (affected > 0) {
player.getInventory().updateInventory();
ItemArrayUtil.setContents((ItemArray<?>)player.getInventory(), items);
}
player.sendMessage(Colors.Yellow + "Items compacted into stacks!");
@@ -474,6 +484,24 @@ public class WorldGuardListener extends PluginListener {
return false;
}
/**
* Returns true if an item should not be stacked.
*
* @param id
* @return
*/
private static boolean shouldNotStack(int id) {
return (id >= 256 && id <= 259)
|| id == 261
|| (id >= 267 && id <= 279)
|| (id >= 281 && id <= 286)
|| (id >= 290 && id <= 294)
|| (id >= 298 && id <= 317)
|| (id >= 325 && id <= 327)
|| id == 335
|| id == 346;
}
/**
* Called before the console command is parsed. Return true if you don't
@@ -572,12 +600,12 @@ public class WorldGuardListener extends PluginListener {
@Override
public boolean onInventoryChange(Player player) {
if (blacklist != null && blacklist.hasOnAcquire()) {
hn[] items = player.getInventory().getArray();
Item[] items = player.getInventory().getContents();
boolean needUpdate = false;
for (int i = 0; i < items.length; i++) {
if (items[i] != null) {
if (!blacklist.onAcquire(items[i].c, player)) {
if (!blacklist.onAcquire(items[i].getItemId(), player)) {
items[i] = null;
needUpdate = true;
}
@@ -585,7 +613,7 @@ public class WorldGuardListener extends PluginListener {
}
if (needUpdate) {
player.getInventory().updateInventory();
ItemArrayUtil.setContents((ItemArray<?>)player.getInventory(), items);
}
}
@@ -606,10 +634,8 @@ public class WorldGuardListener extends PluginListener {
if (blacklist != null) {
int itemId = item.getItemId();
if (itemId >= 325 && itemId <= 327) {
if (!blacklist.onCreate(itemId, player)) {
return true;
}
if (!blacklist.onUse(itemId, player)) {
return true;
}
}
@@ -632,13 +658,11 @@ public class WorldGuardListener extends PluginListener {
int itemId = itemInHand.getItemId();
if (blacklist != null) {
if (itemId < 325 || itemId > 327) {
if (!blacklist.onCreate(itemId, player)) {
return true;
}
if (!blacklist.onPlace(itemId, player)) {
return true;
}
if (!blacklist.onUse(blockClicked, player)) {
if (!blacklist.onRightClick(blockClicked, player)) {
return true;
}
}
@@ -674,8 +698,6 @@ public class WorldGuardListener extends PluginListener {
*/
@Override
public boolean onBlockDestroy(Player player, Block block) {
int type = block.getType();
if (blacklist != null) {
if (!blacklist.onDestroyWith(player.getItemInHand(), player)) {
return true;
@@ -708,77 +730,39 @@ public class WorldGuardListener extends PluginListener {
}
/**
* Called when either a sign, chest or furnace is changed.
* Called when a player attempts to open an inventory; whether it's a
* workbench, a chest or their own player inventory
*
* @param player
* player who changed it
* @param complexBlock
* complex block that changed
* @return true if you want any changes to be reverted
* @param player user who attempted to open the inventory
* @param inventory the inventory that they are attempting to open
* @return
*/
@Override
public boolean onComplexBlockChange(Player player, ComplexBlock complexBlock) {
if (blacklist != null) {
if (complexBlock instanceof Chest) {
Block block = new Block(54, complexBlock.getX(),
complexBlock.getY(), complexBlock.getZ());
if (!blacklist.onSilentUse(block, player)) {
return true;
}
} else if (complexBlock instanceof Furnace) {
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;
}
} 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;
}
}
}
public boolean onOpenInventory(Player player, Inventory inventory) {
/*Block block = new Block(54, complexBlock.getX(),
complexBlock.getY(), complexBlock.getZ());
if (!blacklist.onRightClick(block, player)) {
return true;
}*/
return false;
}
/**
* Called when either a sign, chest or furnace is sent to a player
*
* @param player
* player who the block is being sent to
* @param complexBlock
* complex block that's being sent
* @return true if you want the chest, furnace or sign to be empty
* Called when a sign is changed by a player (Usually, when they first place it)
*
* @param player Player who changed the sign
* @param sign Sign which had changed
* @return true if you wish to cancel this change
*/
@Override
public boolean onSendComplexBlock(Player player, ComplexBlock complexBlock) {
if (blacklist != null) {
if (complexBlock instanceof Chest) {
Block block = new Block(54, complexBlock.getX(),
complexBlock.getY(), complexBlock.getZ());
public boolean onSignChange(Player player, Sign sign) {
int id = etc.getServer().getBlockIdAt(sign.getX(),
sign.getY(), sign.getZ());
Block block = new Block(id, sign.getX(),
sign.getY(), sign.getZ());
if (!blacklist.onSilentUse(block, player)) {
return true;
}
} else if (complexBlock instanceof Furnace) {
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;
}
}
if (!blacklist.onSilentUse(block, player)) {
return true;
}
return false;
@@ -868,10 +852,6 @@ public class WorldGuardListener extends PluginListener {
*/
@Override
public boolean onFlow(Block blockFrom, Block blockTo) {
int x = blockFrom.getX();
int y = blockFrom.getY();
int z = blockFrom.getZ();
boolean isWater = blockFrom.getType() == 8 || blockFrom.getType() == 9;
boolean isLava = blockFrom.getType() == 10 || blockFrom.getType() == 11;
@@ -955,11 +935,28 @@ public class WorldGuardListener extends PluginListener {
public boolean onHealthChange(Player player, int oldValue, int newValue) {
String playerName = player.getName();
if (disableSuffocationDamage && oldValue - newValue == 1) {
Location loc = player.getLocation();
int x = (int)Math.floor(loc.x);
int y = (int)Math.floor(loc.y);
int z = (int)Math.floor(loc.z);
int type = etc.getServer().getBlockIdAt(x, y + 1, z); // Head
// Assuming that this is suffocation damage
if ((type < 8 || type > 11) && !BlockType.canPassThrough(type)) {
if (teleportOnSuffocation) {
findFreePosition(player, x, y, z);
}
return true;
}
}
if (invinciblePlayers.contains(playerName)) {
return oldValue > newValue;
}
if (loginProtection > 0 || spawnProtection > 0 || kickOnDeath) {
if (loginProtection > 0 || spawnProtection > 0
|| kickOnDeath || teleportToHome || exactRespawn) {
long now = System.currentTimeMillis();
boolean recentLogin = false;
@@ -979,13 +976,29 @@ public class WorldGuardListener extends PluginListener {
}
}
if (kickOnDeath && oldValue == -1 && newValue == 20 && !recentLogin) {
boolean alreadyMoved = false;
if (teleportToHome && oldValue <= 0 && newValue == 20 && !recentLogin) {
Warp warp = etc.getDataSource().getHome(player.getName());
if (warp != null) {
player.teleportTo(warp.Location);
alreadyMoved = true;
} else if (player.canUseCommand("/sethome")) {
player.sendMessage(Colors.Yellow + "Use /sethome to set your spawn location.");
}
}
if (exactRespawn && !alreadyMoved && oldValue <= 0 && newValue == 20 && !recentLogin) {
player.teleportTo(etc.getServer().getSpawnLocation());
}
if (kickOnDeath && oldValue <= 0 && newValue == 20 && !recentLogin) {
player.kick("You died! Rejoin please.");
return false;
}
if (spawnProtection > 0) {
if (oldValue == -1 && newValue == 20 && !recentLogin) { // Player was just respawned
if (oldValue <= 0 && newValue == 20 && !recentLogin) { // Player was just respawned
lastSpawn.put(player.getName(), now);
} else if (lastSpawn.containsKey(playerName)) {
long time = lastSpawn.get(playerName);
@@ -1099,4 +1112,43 @@ public class WorldGuardListener extends PluginListener {
blacklist.getLogger().close();
}
}
/**
* Find a position for the player to stand that is not inside a block.
* Blocks above the player will be iteratively tested until there is
* a series of two free blocks. The player will be teleported to
* that free position.
*
* @param player
* @param sx
* @param sy
* @param sz
*/
public void findFreePosition(Player player, int sx, int sy, int sz) {
int x = sx;
int y = Math.max(0, sy);
int origY = y;
int z = sz;
byte free = 0;
while (y <= 129) {
if (BlockType.canPassThrough(etc.getServer().getBlockIdAt(x, y, z))) {
free++;
} else {
free = 0;
}
if (free == 2) {
if (y - 1 != origY) {
player.teleportTo(x + 0.5, y, z + 0.5,
player.getRotation(), player.getPitch());
}
return;
}
y++;
}
}
}
@@ -0,0 +1,271 @@
// $Id$
/*
* WorldEdit
* 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.worldedit.blocks;
import java.util.Map;
import java.util.HashMap;
import java.util.EnumSet;
/**
* Block types.
*
* @author sk89q
*/
public enum BlockType {
AIR(0, "Air", "air"),
STONE(1, "Stone", new String[]{"stone", "rock"}),
GRASS(2, "Grass", "grass"),
DIRT(3, "Dirt", "dirt"),
COBBLESTONE(4, "Cobblestone", "cobblestone"),
WOOD(5, "Wood", "wood"),
SAPLING(6, "Sapling", "sapling"),
BEDROCK(7, "Bedrock", "bedrock"),
WATER(8, "Water", "watermoving"),
STATIONARY_WATER(9, "Water (stationary)", "water"),
LAVA(10, "Lava", "lavamoving"),
STATIONARY_LAVA(11, "Lava (stationary)", "lava"),
SAND(12, "Sand", "sand"),
GRAVEL(13, "Gravel", "gravel"),
GOLD_ORE(14, "Gold ore", "goldore"),
IRON_ORE(15, "Iron ore", "ironore"),
COAL_ORE(16, "Coal ore", "coalore"),
LOG(17, "Log", "log"),
LEAVES(18, "Leaves", "leaves"),
SPONGE(19, "Sponge", "sponge"),
GLASS(20, "Glass", "glass"),
CLOTH(35, "Cloth", "cloth"),
YELLOW_FLOWER(37, "Yellow flower", "yellowflower"),
RED_FLOWER(38, "Red rose", new String[]{"redflower", "redrose"}),
BROWN_MUSHROOM(39, "Brown mushroom", "brownmushroom"),
RED_MUSHROOM(40, "Red mushroom", "redmushroom"),
GOLD_BLOCK(41, "Gold block", new String[]{"gold", "goldblock"}),
IRON_BLOCK(42, "Iron block", new String[]{"iron", "ironblock"}),
DOUBLE_STEP(43, "Double step", "doublestep"),
STEP(44, "Step", "step"),
BRICK(45, "Brick", "brick"),
TNT(46, "TNT", "tnt"),
BOOKCASE(47, "Bookcase", new String[]{"bookshelf", "bookshelf"}),
MOSSY_COBBLESTONE(48, "Cobblestone (mossy)", "mossycobblestone"),
OBSIDIAN(49, "Obsidian", "obsidian"),
TORCH(50, "Torch", "torch"),
FIRE(51, "Fire", "fire"),
MOB_SPAWNER(52, "Mob spawner", "mobspawner"),
WOODEN_STAIRS(53, "Wooden stairs", "woodstairs"),
CHEST(54, "Chest", "chest"),
REDSTONE_WIRE(55, "Redstone wire", "redstone"),
DIAMOND_ORE(56, "Diamond ore", "diamondore"),
DIAMOND_BLOCK(57, "Diamond block", new String[]{"diamond", "diamondblock"}),
WORKBENCH(58, "Workbench", "workbench"),
CROPS(59, "Crops", "crops"),
SOIL(60, "Soil", "soil"),
FURNACE(61, "Furnace", "furnace"),
BURNING_FURNACE(62, "Furnace (burning)", "burningfurnace"),
SIGN_POST(63, "Sign post", new String[]{"sign", "signpost"}),
WOODEN_DOOR(64, "Wooden door", "wooddoor"),
LADDER(65, "Ladder", "ladder"),
MINECART_TRACKS(66, "Minecart tracks", new String[]{"track", "tracks"}),
COBBLESTONE_STAIRS(67, "Cobblestone stairs", "cobblestonestairs"),
WALL_SIGN(68, "Wall sign", "wallsign"),
LEVER(69, "Lever", "level"),
STONE_PRESSURE_PLATE(70, "Stone pressure plate", "stonepressureplate"),
IRON_DOOR(71, "Iron Door", "irondoor"),
WOODEN_PRESSURE_PLATE(72, "Wooden pressure plate", "woodpressureplate"),
REDSTONE_ORE(73, "Redstone ore", "redstoneore"),
GLOWING_REDSTONE_ORE(74, "Glowing redstone ore", "glowingredstoneore"),
REDSTONE_TORCH_OFF(75, "Redstone torch (off)",
new String[]{"redstonetorch"," redstonetorchon"}),
REDSTONE_TORCH_ON(76, "Redstone torch (on)", "redstonetorchon"),
STONE_BUTTON(77, "Stone Button", "stonebutton"),
SNOW(78, "Snow", "snow"),
ICE(79, "Ice", "ice"),
SNOW_BLOCK(80, "Snow block", "snowblock"),
CACTUS(81, "Cactus", "cactus"),
CLAY(82, "Clay", "clay"),
REED(83, "Reed", "reed"),
JUKEBOX(84, "Jukebox", "jukebox"),
FENCE(85, "Fence", "fence"),
PUMPKIN(86, "Pumpkin", "pumpkin"),
RED_BLOCK(87, "Cobblestone (red mossy)", new String[]{"redmossycobblestone", "redcobblestone"}),
HELL_DIRT(88, "Mud", "mud"),
HELL_GOLD(89, "Brittle gold", "brittlegold"),
PORTAL(90, "Portal", "portal"),
LIGHTED_PUMPKIN(91, "Pumpkin (on)", new String[]{"pumpkinlighted", "pumpkinon", "litpumpkin"});
/**
* Stores a map of the IDs for fast access.
*/
private static final Map<Integer,BlockType> ids = new HashMap<Integer,BlockType>();
/**
* Stores a map of the names for fast access.
*/
private static final Map<String,BlockType> lookup = new HashMap<String,BlockType>();
private final int id;
private final String name;
private final String[] lookupKeys;
static {
for(BlockType type : EnumSet.allOf(BlockType.class)) {
ids.put(type.id, type);
for (String key : type.lookupKeys) {
lookup.put(key, type);
}
}
}
/**
* Construct the type.
*
* @param id
* @param name
*/
BlockType(int id, String name, String lookupKey) {
this.id = id;
this.name = name;
this.lookupKeys = new String[]{lookupKey};
}
/**
* Construct the type.
*
* @param id
* @param name
*/
BlockType(int id, String name, String[] lookupKeys) {
this.id = id;
this.name = name;
this.lookupKeys = lookupKeys;
}
/**
* Return type from ID. May return null.
*
* @param id
* @return
*/
public static BlockType fromID(int id) {
return ids.get(id);
}
/**
* Return type from name. May return null.
*
* @param name
* @return
*/
public static BlockType lookup(String name) {
return lookup.get(name.toLowerCase());
}
/**
* Get block numeric ID.
*
* @return
*/
public int getID() {
return id;
}
/**
* Get user-friendly block name.
*
* @return
*/
public String getName() {
return name;
}
/**
* Checks to see whether a block should be placed last.
*
* @param id
* @return
*/
public boolean shouldPlaceLast() {
return shouldPlaceLast(id);
}
/**
* Checks to see whether a block should be placed last.
*
* @param id
* @return
*/
public static boolean shouldPlaceLast(int id) {
return id == 6 // Saplings
|| id == 37 // Yellow flower
|| id == 38 // Red flower
|| id == 39 // Brown mushroom
|| id == 40 // Red mush room
|| id == 50 // Torch
|| id == 51 // Fire
|| id == 55 // Redstone wire
|| id == 59 // Crops
|| id == 63 // Sign post
|| id == 64 // Wooden door
|| id == 65 // Ladder
|| id == 66 // Minecart tracks
|| id == 68 // Wall sign
|| id == 69 // Lever
|| id == 70 // Stone pressure plate
|| id == 71 // Iron door
|| id == 72 // Wooden pressure plate
|| id == 75 // Redstone torch (off)
|| id == 76 // Redstone torch (on)
|| id == 77 // Stone button
|| id == 78 // Snow
|| id == 81 // Cactus
|| id == 83 // Reed
|| id == 90; // Portal
}
/**
* Checks whether a block can be passed through.
*
* @param id
* @return
*/
public static boolean canPassThrough(int id) {
return id == 0 // Air
|| id == 6 // Saplings
|| id == 37 // Yellow flower
|| id == 38 // Red flower
|| id == 39 // Brown mushroom
|| id == 40 // Red mush room
|| id == 50 // Torch
|| id == 51 // Fire
|| id == 55 // Redstone wire
|| id == 59 // Crops
|| id == 63 // Sign post
|| id == 65 // Ladder
|| id == 66 // Minecart tracks
|| id == 68 // Wall sign
|| id == 69 // Lever
|| id == 70 // Stone pressure plate
|| id == 72 // Wooden pressure plate
|| id == 75 // Redstone torch (off)
|| id == 76 // Redstone torch (on)
|| id == 77 // Stone button
|| id == 78 // Snow
|| id == 83 // Reed
|| id == 90; // Portal
}
}
+14 -15
View File
@@ -11,7 +11,7 @@
# Example to block ore and catch some events:
# [coalore,goldore,ironore]
# on-destroy-with=deny,log,kick
# on-create=deny,tell
# on-place=deny,tell
#
# Options:
# - ignore-groups (comma-delimited list of groups to not affect)
@@ -22,8 +22,9 @@
# - on-destroy (when a block of this type is being destroyed)
# - on-break (when a block of this type is about to be broken)
# - on-destroy-with (the item/block held by the user while destroying)
# - on-create (the item/block in the user's inventory is being created)
# - on-use (the block is right clicked)
# - on-place (a block is being placed)
# - on-use (an item like a lighter is being used)
# - on-right-click (the block is right clicked -- curently INEFFECTIVE)
# - on-drop (the item is being dropped from the player's inventory)
# - on-acquire (the item enters a player's inventory via some method)
#
@@ -68,24 +69,22 @@
# Some examples follow. Remember to remove # in front if you want them
# to work for you!
# Deny lava buckets
#[lavabucket]
#ignore-groups=admins,mods
#on-destroy-with=deny,log,kick
#on-create=deny,tell
#on-use=deny,tell
# Deny lighter usage
#[259]
#on-use=deny,tell
# Deny some ore
#[coalore,goldore,ironore]
#ignore-groups=admins,mods,vip
#ignore-groups=admins,mods
#on-destroy=notify,deny,log
#[cobblestone]
#on-create=deny,tell,log
#on-place=deny,tell,log
#[lever]
#on-break=deny
# This is an example of the 'durability cheat' workaround that destroys your
# tool when you drop it
#[256,257,258,259,267,268,269,270,271,272,273,274,275,276,277,278,279,283,284,285,286,290,291,292,293,294,346]
#on-drop=deny,tell
#comment=Durability Hacks
#message=Your tool was destroyed
#on-break=deny,tell
+11
View File
@@ -65,6 +65,11 @@ disable-fall-damage=false
disable-lava-damage=false
disable-fire-damage=false
disable-water-damage=false
disable-suffocation-damage=false
# Teleports player when s/he is suffocating. This can be abused to get
# through ceilings.
teleport-on-suffocation=false
# Disable fire spreading between blocks. Note that this does not prevent
# fire damage -- it only prevents fire spread.
@@ -95,3 +100,9 @@ log-database=false
log-file-open-files=10
log-file-path=worldguard/logs/%Y-%m-%d.log
log-file=false
# On death options.
teleport-to-home-on-death=false
exact-respawn=false
#EOF