diff --git a/build.xml b/build.xml
index 647f83de..bcf37351 100644
--- a/build.xml
+++ b/build.xml
@@ -32,6 +32,7 @@
+
@@ -53,14 +54,16 @@
+
+
-
+
-
+
diff --git a/config.yml b/config.yml
new file mode 100644
index 00000000..d315bcff
--- /dev/null
+++ b/config.yml
@@ -0,0 +1,41 @@
+summary-on-start: false
+protection:
+ enforce-single-session: true
+ item-drop-blacklist: []
+ item-durability: false
+simulation:
+ classic-water: false
+ sponge:
+ enable: true
+ radius: 3
+physics:
+ no-physics-gravel: false
+ no-physics-sand: false
+ allow-portal-anywhere: false
+ disable-water-damage-blocks: []
+ignition:
+ block-tnt: false
+ block-lighter: false
+fire:
+ disable-fire-spread: false
+ disable-fire-spread-blocks: []
+ disable-lava-fire-spread: true
+ lava-spread-blocks: []
+mobs:
+ block-creeper-explosions: false
+spawn:
+ login-protection: 3
+ spawn-protection: 0
+ kick-on-death: false
+ exact-respawn: false
+ teleport-to-home-on-death: false
+player-damage:
+ disable-fall-damage: false
+ disable-lava-damage: false
+ disable-fire-damage: false
+ disable-water-damage: false
+ disable-suffocation-damage: false
+ teleport-on-suffocation: false
+regions:
+ enable: true
+ wand: 287
\ No newline at end of file
diff --git a/plugin.yml b/plugin.yml
new file mode 100644
index 00000000..8e360014
--- /dev/null
+++ b/plugin.yml
@@ -0,0 +1,3 @@
+name: WorldGuard
+main: com.sk89q.worldguard.bukkit.WorldGuardPlugin
+version: WGVERSIONMACRO
\ No newline at end of file
diff --git a/src/Blacklist.java b/src/Blacklist.java
deleted file mode 100644
index 3b55e7db..00000000
--- a/src/Blacklist.java
+++ /dev/null
@@ -1,418 +0,0 @@
-// $Id$
-/*
- * WorldGuard
- * Copyright (C) 2010 sk89q
- *
- * 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 .
-*/
-
-import java.util.Map;
-import java.util.HashMap;
-import java.util.List;
-import java.util.ArrayList;
-import java.util.logging.Logger;
-import java.util.logging.Level;
-import java.io.*;
-
-/**
- *
- * @author sk89q
- */
-public class Blacklist {
- /**
- * Logger.
- */
- private static final Logger logger = Logger.getLogger("Minecraft.WorldGuard");
-
- /**
- * List of entries by block ID.
- */
- private Map> blacklist
- = new HashMap>();
- /**
- * Logger.
- */
- private BlacklistLogger blacklistLogger = new BlacklistLogger();
-
- /**
- * Blacklist contains on-acquire events.
- */
- private boolean hasOnAcquire;
-
- /**
- * Returns whether the list is empty.
- *
- * @return
- */
- public boolean isEmpty() {
- return blacklist.isEmpty();
- }
-
- /**
- * Get the entries for an item or list.
- */
- public List getEntries(int id) {
- return blacklist.get(id);
- }
-
- /**
- * Get the logger.
- *
- * @return
- */
- public BlacklistLogger getLogger() {
- return blacklistLogger;
- }
-
- /**
- * Called on block destruction. Returns true to let the action pass
- * through.
- *
- * @param block
- * @param player
- * @return
- */
- public boolean onDestroy(final Block block, final Player player) {
- List entries = getEntries(block.getType());
- if (entries == null) {
- return true;
- }
- boolean ret = true;
- for (BlacklistEntry entry : entries) {
- if (!entry.onDestroy(block, player)) {
- ret = false;
- }
- }
- return ret;
- }
-
- /**
- * Called on block break. Returns true to let the action pass
- * through.
- *
- * @param block
- * @param player
- * @return
- */
- public boolean onBreak(final Block block, final Player player) {
- List entries = getEntries(block.getType());
- if (entries == null) {
- return true;
- }
- boolean ret = true;
- for (BlacklistEntry entry : entries) {
- if (!entry.onBreak(block, player)) {
- ret = false;
- }
- }
- return ret;
- }
-
- /**
- * Called on left click. Returns true to let the action pass through.
- *
- * @param item
- * @param player
- * @return
- */
- public boolean onDestroyWith(int item, Player player) {
- List entries = getEntries(item);
- if (entries == null) {
- return true;
- }
- boolean ret = true;
- for (BlacklistEntry entry : entries) {
- if (!entry.onDestroyWith(item, player)) {
- ret = false;
- }
- }
- return ret;
- }
-
- /**
- * Called on place. Returns true to let the action pass through.
- *
- * @param item
- * @param player
- * @return
- */
- public boolean onPlace(int item, Player player) {
- List entries = getEntries(item);
- if (entries == null) {
- return true;
- }
- boolean ret = true;
- for (BlacklistEntry entry : entries) {
- if (!entry.onPlace(item, player)) {
- ret = false;
- }
- }
- return ret;
- }
-
- /**
- * Called on right click upon. Returns true to let the action pass through.
- *
- * @param block
- * @param player
- * @return
- */
- public boolean onRightClick(Block block, Player player) {
- List entries = getEntries(block.getType());
- if (entries == null) {
- return true;
- }
- boolean ret = true;
- for (BlacklistEntry entry : entries) {
- 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 entries = getEntries(item);
- if (entries == null) {
- return true;
- }
- boolean ret = true;
- for (BlacklistEntry entry : entries) {
- if (!entry.onUse(item, player)) {
- ret = false;
- }
- }
- return ret;
- }
-
- /**
- * Called on right click upon. Returns true to let the action pass through.
- *
- * @param item
- * @param player
- * @return
- */
- public boolean onSilentUse(Block block, Player player) {
- List entries = getEntries(block.getType());
- if (entries == null) {
- return true;
- }
- boolean ret = true;
- for (BlacklistEntry entry : entries) {
- if (!entry.onSilentUse(block, player)) {
- ret = false;
- }
- }
- return ret;
- }
-
- /**
- * Called on drop. Returns true to let the action pass through.
- *
- * @param item
- * @param player
- * @return
- */
- public boolean onDrop(int item, Player player) {
- List entries = getEntries(item);
- if (entries == null) {
- return true;
- }
- boolean ret = true;
- for (BlacklistEntry entry : entries) {
- if (!entry.onDrop(item, player)) {
- ret = false;
- }
- }
- 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 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 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.
- *
- * @param file
- * @return
- * @throws IOException
- */
- public void load(File file) throws IOException {
- FileReader input = null;
- Map> blacklist =
- new HashMap>();
-
- try {
- input = new FileReader(file);
- BufferedReader buff = new BufferedReader(input);
-
- hasOnAcquire = false;
-
- String line;
- List currentEntries = null;
- while ((line = buff.readLine()) != null) {
- line = line.trim();
-
- // Blank line
- if (line.length() == 0) {
- continue;
- } else if (line.charAt(0) == ';' || line.charAt(0) == '#') {
- continue;
- }
-
- if (line.matches("^\\[.*\\]$")) {
- String[] items = line.substring(1, line.length() - 1).split(",");
- currentEntries = new ArrayList();
-
- for (String item : items) {
- int id = 0;
-
- try {
- id = Integer.parseInt(item.trim());
- } catch (NumberFormatException e) {
- id = etc.getDataSource().getItem(item.trim());
- if (id == 0) {
- logger.log(Level.WARNING, "WorldGuard: Unknown block name: "
- + item);
- break;
- }
- }
-
- BlacklistEntry entry = new BlacklistEntry(this);
- if (blacklist.containsKey(id)) {
- blacklist.get(id).add(entry);
- } else {
- List entries = new ArrayList();
- entries.add(entry);
- blacklist.put(id, entries);
- }
- currentEntries.add(entry);
- }
- } else if (currentEntries != null) {
- String[] parts = line.split("=");
-
- if (parts.length == 1) {
- logger.log(Level.WARNING, "Found option with no value "
- + file.getName() + " for '" + line + "'");
- continue;
- }
-
- boolean unknownOption = false;
-
- for (BlacklistEntry entry : currentEntries) {
- if (parts[0].equalsIgnoreCase("ignore-groups")) {
- entry.setIgnoreGroups(parts[1].split(","));
- } else if (parts[0].equalsIgnoreCase("on-destroy")) {
- entry.setDestroyActions(parts[1].split(","));
- } else if (parts[0].equalsIgnoreCase("on-break")) {
- entry.setBreakActions(parts[1].split(","));
- } else if (parts[0].equalsIgnoreCase("on-left")
- || parts[0].equalsIgnoreCase("on-destroy-with")) {
- entry.setDestroyWithActions(parts[1].split(","));
- } 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")) {
- hasOnAcquire = true;
- entry.setAcquireActions(parts[1].split(","));
- } else if (parts[0].equalsIgnoreCase("message")) {
- entry.setMessage(parts[1].trim());
- } else if (parts[0].equalsIgnoreCase("comment")) {
- entry.setComment(parts[1].trim());
- } else {
- unknownOption = true;
- }
- }
-
- if (unknownOption) {
- logger.log(Level.WARNING, "Unknown option '" + parts[0]
- + "' in " + file.getName() + " for '" + line + "'");
- }
- } else {
- logger.log(Level.WARNING, "Found option with no heading "
- + file.getName() + " for '" + line + "'");
- }
- }
-
- this.blacklist = blacklist;
- } finally {
- try {
- if (input != null) {
- input.close();
- }
- } catch (IOException e2) {
- }
- }
- }
-
- /**
- * Blacklist contains on-acquire events.
- *
- * @return
- */
- public boolean hasOnAcquire() {
- return hasOnAcquire;
- }
-}
diff --git a/src/BlacklistEntry.java b/src/BlacklistEntry.java
deleted file mode 100644
index 7215af72..00000000
--- a/src/BlacklistEntry.java
+++ /dev/null
@@ -1,746 +0,0 @@
-// $Id$
-/*
- * WorldGuard
- * Copyright (C) 2010 sk89q
- *
- * 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 .
-*/
-
-import java.util.Set;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.HashMap;
-
-/**
- *
- * @author sk89q
- */
-public class BlacklistEntry {
- /**
- * Used to prevent spamming.
- */
- private static Map lastAffected =
- new HashMap();
- /**
- * Parent blacklist entry.
- */
- private Blacklist blacklist;
- /**
- * List of groups to not affect.
- */
- private Set ignoreGroups;
- /**
- * List of actions to perform on destruction.
- */
- private String[] destroyActions;
- /**
- * List of actions to perform on break.
- */
- private String[] breakActions;
- /**
- * List of actions to perform on left click.
- */
- private String[] destroyWithActions;
- /**
- * List of actions to perform on block placement.
- */
- 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[] rightClickActions;
- /**
- * List of actions to perform on drop.
- */
- private String[] dropActions;
- /**
- * 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.
- *
- * @param blacklist
- */
- public BlacklistEntry(Blacklist blacklist) {
- this.blacklist = blacklist;
- }
-
- /**
- * @return the ignoreGroups
- */
- public String[] getIgnoreGroups() {
- return ignoreGroups.toArray(new String[ignoreGroups.size()]);
- }
-
- /**
- * @param ignoreGroups the ignoreGroups to set
- */
- public void setIgnoreGroups(String[] ignoreGroups) {
- Set ignoreGroupsSet = new HashSet();
- for (String group : ignoreGroups) {
- ignoreGroupsSet.add(group.toLowerCase());
- }
- this.ignoreGroups = ignoreGroupsSet;
- }
-
- /**
- * @return
- */
- public String[] getDestroyActions() {
- return destroyActions;
- }
-
- /**
- * @param actions
- */
- public void setDestroyActions(String[] actions) {
- this.destroyActions = actions;
- }
-
- /**
- * @return
- */
- public String[] getBreakActions() {
- return breakActions;
- }
-
- /**
- * @param actions
- */
- public void setBreakActions(String[] actions) {
- this.breakActions = actions;
- }
-
- /**
- * @return
- */
- public String[] getDestroyWithActions() {
- return destroyWithActions;
- }
-
- /**
- * @param action
- */
- public void setDestroyWithActions(String[] actions) {
- this.destroyWithActions = actions;
- }
-
- /**
- * @return
- */
- public String[] getPlaceActions() {
- return placeActions;
- }
-
- /**
- * @param actions
- */
- public void setPlaceActions(String[] actions) {
- this.placeActions = actions;
- }
-
- /**
- * @return
- */
- public String[] getUseActions() {
- return useActions;
- }
-
- /**
- * @param actions
- */
- public void setUseActions(String[] actions) {
- this.useActions = actions;
- }
-
- /**
- * @return
- */
- public String[] getRightClickActions() {
- return rightClickActions;
- }
-
- /**
- * @param actions
- */
- public void setRightClickActions(String[] actions) {
- this.rightClickActions = actions;
- }
-
- /**
- * @return
- */
- public String[] getDropActions() {
- return dropActions;
- }
-
- /**
- * @param actions
- */
- public void setDropActions(String[] actions) {
- this.dropActions = actions;
- }
-
- /**
- * @return
- */
- public String[] getAcquireActions() {
- return acquireActions;
- }
-
- /**
- * @param actions
- */
- public void setAcquireActions(String[] actions) {
- this.acquireActions = actions;
- }
-
- /**
- * @return the message
- */
- public String getMessage() {
- return message;
- }
-
- /**
- * @param message the message to set
- */
- public void setMessage(String message) {
- this.message = message;
- }
-
- /**
- * @return the comment
- */
- public String getComment() {
- return comment;
- }
-
- /**
- * @param comment the comment to set
- */
- public void setComment(String comment) {
- this.comment = comment;
- }
-
- /**
- * Returns true if this player should be ignored.
- *
- * @param player
- * @return
- */
- public boolean shouldIgnore(Player player) {
- if (ignoreGroups == null) {
- return false;
- }
- for (String group : player.getGroups()) {
- if (ignoreGroups.contains(group.toLowerCase())) {
- return true;
- }
- }
-
- return false;
- }
-
- /**
- * Announces a message to all administrators.
- *
- * @param str
- */
- public void notifyAdmins(String str) {
- for (Player player : etc.getServer().getPlayerList()) {
- if (player.canUseCommand("/wprotectalerts")
- || player.canUseCommand("/worldguardnotify")) {
- player.sendMessage(Colors.LightGray + "WG: " + str);
- }
- }
- }
-
- /**
- * Ban a player.
- *
- * @param player
- * @param msg
- */
- public void banPlayer(Player player, String msg) {
- etc.getServer().ban(player.getName());
- etc.getLoader().callHook(PluginLoader.Hook.BAN, new Object[]{
- player.getUser(), player.getUser(), msg
- });
- player.kick(msg);
- }
-
- /**
- * Called on block destruction. Returns true to let the action pass
- * through.
- *
- * @param block
- * @param player
- * @return
- */
- public boolean onDestroy(final Block block, final Player player) {
- if (destroyActions == null) {
- return true;
- }
-
- final BlacklistEntry entry = this;
-
- ActionHandler handler = new ActionHandler() {
- public void log(String itemName) {
- blacklist.getLogger().logDestroyAttempt(player, block, comment);
- }
- public void kick(String itemName) {
- player.kick("You are not allowed to destroy " + itemName);
- }
- public void ban(String itemName) {
- entry.banPlayer(player, "Banned: You are not allowed to destroy " + itemName);
- }
- public void notifyAdmins(String itemName) {
- entry.notifyAdmins(player.getName() + " (destroy) " + itemName
- + (comment != null ? " (" + comment + ")" : "") + ".");
- }
- public void tell(String itemName) {
- player.sendMessage(Colors.Yellow + "You are not allowed to destroy " + itemName + ".");
- }
- };
-
- return process(block.getType(), player, destroyActions, handler, false, false);
- }
-
- /**
- * Called on block break. Returns true to let the action pass
- * through.
- *
- * @param block
- * @param player
- * @return
- */
- public boolean onBreak(final Block block, final Player player) {
- if (breakActions == null) {
- return true;
- }
-
- final BlacklistEntry entry = this;
-
- ActionHandler handler = new ActionHandler() {
- public void log(String itemName) {
- blacklist.getLogger().logBreakAttempt(player, block, comment);
- }
- public void kick(String itemName) {
- player.kick("You are not allowed to break " + itemName);
- }
- public void ban(String itemName) {
- entry.banPlayer(player, "Banned: You are not allowed to break " + itemName);
- }
- public void notifyAdmins(String itemName) {
- entry.notifyAdmins(player.getName() + " (break) " + itemName
- + (comment != null ? " (" + comment + ")" : "") + ".");
- }
- public void tell(String itemName) {
- player.sendMessage(Colors.Yellow + "You are not allowed to break " + itemName + ".");
- }
- };
-
- return process(block.getType(), player, breakActions, handler, true, false);
- }
-
- /**
- * Called on left click. Returns true to let the action pass through.
- *
- * @param item
- * @param player
- * @return
- */
- public boolean onDestroyWith(final int item, final Player player) {
- if (destroyWithActions == null) {
- return true;
- }
-
- final BlacklistEntry entry = this;
-
- ActionHandler handler = new ActionHandler() {
- public void log(String itemName) {
- blacklist.getLogger().logDestroyWithAttempt(player, item, comment);
- }
- public void kick(String itemName) {
- player.kick("You can't destroy with " + itemName);
- }
- public void ban(String itemName) {
- entry.banPlayer(player, "Banned: You can't destroy with " + itemName);
- }
- public void notifyAdmins(String itemName) {
- entry.notifyAdmins(player.getName() + " (destroy w/) " + itemName
- + (comment != null ? " (" + comment + ")" : "") + ".");
- }
- public void tell(String itemName) {
- player.sendMessage(Colors.Yellow + "You can't destroy with " + itemName + ".");
- }
- };
-
- return process(item, player, destroyWithActions, handler, false, false);
- }
-
- /**
- * Called on block placement. Returns true to let the action pass through.
- *
- * @param item
- * @param player
- * @return
- */
- public boolean onPlace(final int item, final Player player) {
- if (placeActions == null) {
- return true;
- }
-
- final BlacklistEntry entry = this;
-
- ActionHandler handler = new ActionHandler() {
- public void log(String itemName) {
- blacklist.getLogger().logPlaceAttempt(player, item, comment);
- }
- public void kick(String itemName) {
- player.kick("You can't place " + itemName);
- }
- public void ban(String itemName) {
- entry.banPlayer(player, "Banned: You can't place " + itemName);
- }
- public void notifyAdmins(String itemName) {
- entry.notifyAdmins(player.getName() + " (place) " + itemName
- + (comment != null ? " (" + comment + ")" : "") + ".");
- }
- public void tell(String itemName) {
- player.sendMessage(Colors.Yellow + "You can't place " + itemName + ".");
- }
- };
-
- 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);
- }
-
- /**
- * Called on right click upon. Returns true to let the action pass through.
- *
- * @param item
- * @param player
- * @return
- */
- public boolean onRightClick(final Block block, final Player player) {
- if (useActions == null) {
- return true;
- }
-
- final BlacklistEntry entry = this;
-
- ActionHandler handler = new ActionHandler() {
- public void log(String itemName) {
- blacklist.getLogger().logRightClickAttempt(player, block, 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(block.getType(), player, useActions, handler, false, false);
- }
-
- /**
- * Called on right click upon. Returns true to let the action pass through.
- *
- * @param item
- * @param player
- * @return
- */
- public boolean onSilentUse(final Block block, final Player player) {
- if (useActions == null) {
- return true;
- }
-
- return process(block.getType(), player, useActions, silentHandler, false, true);
- }
-
- /**
- * Called on item drop. Returns true to let the action pass through.
- *
- * @param item
- * @param player
- * @return
- */
- public boolean onDrop(final int item, final Player player) {
- if (dropActions == null) {
- return true;
- }
-
- final BlacklistEntry entry = this;
-
- ActionHandler handler = new ActionHandler() {
- public void log(String itemName) {
- blacklist.getLogger().logDropAttempt(player, item, comment);
- }
- public void kick(String itemName) {
- player.kick("You can't drop " + itemName);
- }
- public void ban(String itemName) {
- entry.banPlayer(player, "Banned: You can't drop " + itemName);
- }
- public void notifyAdmins(String itemName) {
- entry.notifyAdmins(player.getName() + " (drop) " + itemName
- + (comment != null ? " (" + comment + ")" : "") + ".");
- }
- public void tell(String itemName) {
- player.sendMessage(Colors.Yellow + "You're not allowed to drop " + itemName + ".");
- }
- };
-
- return process(item, player, dropActions, handler, 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);
- }
-
- /**
- * Internal method to handle the actions.
- *
- * @param id
- * @param player
- * @param actions
- * @param handler
- * @param allowRepeat
- * @param silent
- * @return
- */
- private boolean process(int id, Player player, String[] actions,
- ActionHandler handler, boolean allowRepeat, boolean silent) {
-
- if (shouldIgnore(player)) {
- return true;
- }
-
- String name = player.getName();
- long now = System.currentTimeMillis();
- boolean repeating = false;
-
- // Check to see whether this event is being repeated
- BlacklistTrackedEvent tracked = lastAffected.get(name);
- if (tracked != null) {
- if (tracked.getId() == id && tracked.getTime() > now - 3000) {
- repeating = true;
- } else {
- tracked.setTime(now);
- tracked.setId(id);
- }
- } else {
- lastAffected.put(name, new BlacklistTrackedEvent(id, now));
- }
-
- boolean ret = true;
-
- for (String action : actions) {
- // Deny
- if (action.equalsIgnoreCase("deny")) {
- if (silent) {
- return false;
- }
- ret = false;
-
- // Kick
- } else if (action.equalsIgnoreCase("kick")) {
- if (this.message != null) {
- player.kick(String.format(this.message,
- etc.getDataSource().getItem(id)));
- } else {
- handler.kick(etc.getDataSource().getItem(id));
- }
-
- // Ban
- } else if (action.equalsIgnoreCase("ban")) {
- handler.ban(etc.getDataSource().getItem(id));
- if (this.message != null) {
- banPlayer(player, "Banned: " + String.format(this.message,
- etc.getDataSource().getItem(id)));
- } else {
- handler.ban(etc.getDataSource().getItem(id));
- }
-
- } else if (!repeating || allowRepeat) {
- // Notify
- if (action.equalsIgnoreCase("notify")) {
- handler.notifyAdmins(etc.getDataSource().getItem(id));
-
- // Log
- } else if (action.equalsIgnoreCase("log")) {
- handler.log(etc.getDataSource().getItem(id));
-
- // Tell
- } else if (action.equalsIgnoreCase("tell")) {
- if (this.message != null) {
- player.sendMessage(Colors.Yellow +
- String.format(message, etc.getDataSource().getItem(id))
- + ".");
- } else {
- handler.tell(etc.getDataSource().getItem(id));
- }
- }
- }
- }
-
- return ret;
- }
-
- /**
- * Forget a player.
- *
- * @param player
- */
- public static void forgetPlayer(Player player) {
- lastAffected.remove(player.getName());
- }
-
- /**
- * Forget all players.
- *
- * @param player
- */
- public static void forgetAllPlayers() {
- lastAffected.clear();
- }
-
- /**
- * Gets called for actions.
- */
- private static interface 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);
- }
-}
diff --git a/src/BlacklistLogger.java b/src/BlacklistLogger.java
deleted file mode 100644
index 2329244b..00000000
--- a/src/BlacklistLogger.java
+++ /dev/null
@@ -1,165 +0,0 @@
-// $Id$
-/*
- * WorldGuard
- * Copyright (C) 2010 sk89q
- *
- * 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 .
-*/
-
-import java.util.Set;
-import java.util.HashSet;
-
-/**
- *
- * @author sk89q
- */
-public class BlacklistLogger implements BlacklistLoggerHandler {
- /**
- * List of logger handlers.
- */
- private Set handlers
- = new HashSet();
-
- /**
- * Add a handler.
- *
- * @param handler
- */
- public void addHandler(BlacklistLoggerHandler handler) {
- handlers.add(handler);
- }
-
- /**
- * Add a handler.
- *
- * @param handler
- */
- public void removeHandler(BlacklistLoggerHandler handler) {
- handlers.remove(handler);
- }
-
- /**
- * Add a handler.
- *
- * @param handler
- */
- public void clearHandlers() {
- handlers.clear();
- }
-
- /**
- * Log a block destroy attempt.
- *
- * @param player
- * @param block
- */
- public void logDestroyAttempt(Player player, Block block, String comment) {
- for (BlacklistLoggerHandler handler : handlers) {
- handler.logDestroyAttempt(player, block, comment);
- }
- }
-
- /**
- * Log a block break attempt.
- *
- * @param player
- * @param block
- */
- public void logBreakAttempt(Player player, Block block, String comment) {
- for (BlacklistLoggerHandler handler : handlers) {
- handler.logBreakAttempt(player, block, comment);
- }
- }
-
- /**
- * Log a right click on attempt.
- *
- * @param player
- * @param block
- */
- public void logUseAttempt(Player player, int item, String comment) {
- for (BlacklistLoggerHandler handler : handlers) {
- 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);
- }
- }
-
- /**
- * Right a left click attempt.
- *
- * @param player
- * @param item
- */
- public void logDestroyWithAttempt(Player player, int item, String comment) {
- for (BlacklistLoggerHandler handler : handlers) {
- handler.logDestroyWithAttempt(player, item, comment);
- }
- }
-
- /**
- * Log a place attempt.
- *
- * @param player
- * @param item
- */
- public void logPlaceAttempt(Player player, int item, String comment) {
- for (BlacklistLoggerHandler handler : handlers) {
- handler.logPlaceAttempt(player, item, comment);
- }
- }
-
- /**
- * Log a drop attempt.
- *
- * @param player
- * @param item
- */
- public void logDropAttempt(Player player, int item, String comment) {
- for (BlacklistLoggerHandler handler : handlers) {
- handler.logDropAttempt(player, item, comment);
- }
- }
-
- /**
- * 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.
- */
- public void close() {
- for (BlacklistLoggerHandler handler : handlers) {
- handler.close();
- }
- }
-}
diff --git a/src/BlacklistLoggerHandler.java b/src/BlacklistLoggerHandler.java
deleted file mode 100644
index 790a12e8..00000000
--- a/src/BlacklistLoggerHandler.java
+++ /dev/null
@@ -1,86 +0,0 @@
-// $Id$
-/*
- * WorldGuard
- * Copyright (C) 2010 sk89q
- *
- * 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 .
-*/
-
-/**
- * Interface for loggers for the blacklist.
- *
- * @author sk89q
- */
-public interface BlacklistLoggerHandler {
- /**
- * Log a block destroy attempt.
- *
- * @param player
- * @param block
- */
- public void logDestroyAttempt(Player player, Block block, String comment);
- /**
- * Log a block break attempt.
- *
- * @param player
- * @param block
- */
- public void logBreakAttempt(Player player, Block block, String comment);
- /**
- * Log a use attempt.
- *
- * @param player
- * @param block
- */
- public void logUseAttempt(Player player, int item, String comment);
- /**
- * Right a left click attempt.
- *
- * @param player
- * @param item
- */
- public void logDestroyWithAttempt(Player player, int item, String comment);
- /**
- * Log a place attempt.
- *
- * @param player
- * @param item
- */
- 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.
- *
- * @param player
- * @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.
- */
- public void close();
-}
diff --git a/src/BlacklistTrackedEvent.java b/src/BlacklistTrackedEvent.java
deleted file mode 100644
index 0b55707e..00000000
--- a/src/BlacklistTrackedEvent.java
+++ /dev/null
@@ -1,66 +0,0 @@
-// $Id$
-/*
- * WorldGuard
- * Copyright (C) 2010 sk89q
- *
- * 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 .
-*/
-
-/**
- *
- * @author sk89q
- */
-public class BlacklistTrackedEvent {
- private int id;
- private long time;
-
- /**
- * Construct the object.
- *
- * @param id
- * @param time
- */
- public BlacklistTrackedEvent(int id, long time) {
- this.id = id;
- this.time = time;
- }
-
- /**
- * @return the id
- */
- public int getId() {
- return id;
- }
-
- /**
- * @param id the id to set
- */
- public void setId(int id) {
- this.id = id;
- }
-
- /**
- * @return the time
- */
- public long getTime() {
- return time;
- }
-
- /**
- * @param time the time to set
- */
- public void setTime(long time) {
- this.time = time;
- }
-}
diff --git a/src/ConsoleLoggerHandler.java b/src/ConsoleLoggerHandler.java
deleted file mode 100644
index b69faf19..00000000
--- a/src/ConsoleLoggerHandler.java
+++ /dev/null
@@ -1,143 +0,0 @@
-// $Id$
-/*
- * WorldGuard
- * Copyright (C) 2010 sk89q
- *
- * 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 .
-*/
-
-import java.util.logging.Logger;
-import java.util.logging.Level;
-
-/**
- *
- * @author sk89q
- */
-public class ConsoleLoggerHandler implements BlacklistLoggerHandler {
- /**
- * Logger.
- */
- private static final Logger logger = Logger.getLogger("Minecraft.WorldGuard");
-
- /**
- * Log a block destroy attempt.
- *
- * @param player
- * @param block
- */
- public void logDestroyAttempt(Player player, Block block, String comment) {
- logger.log(Level.INFO, "WorldGuard: " + player.getName()
- + " tried to destroy " + getFriendlyItemName(block.getType())
- + (comment != null ? " (" + comment + ")" : ""));
- }
-
- /**
- * Log a block break attempt.
- *
- * @param player
- * @param block
- */
- public void logBreakAttempt(Player player, Block block, String comment) {
- logger.log(Level.INFO, "WorldGuard: " + player.getName()
- + " tried to break " + getFriendlyItemName(block.getType())
- + (comment != null ? " (" + comment + ")" : ""));
- }
-
- /**
- * Log a right click on attempt.
- *
- * @param player
- * @param block
- */
- public void logRightClickAttempt(Player player, Block block, String comment) {
- logger.log(Level.INFO, "WorldGuard: " + player.getName()
- + " tried to right click " + getFriendlyItemName(block.getType())
- + (comment != null ? " (" + comment + ")" : ""));
- }
-
- /**
- * Log an attempt to destroy with an item.
- *
- * @param player
- * @param item
- */
- public void logDestroyWithAttempt(Player player, int item, String comment) {
- logger.log(Level.INFO, "WorldGuard: " + player.getName()
- + " tried to destroy with " + getFriendlyItemName(item)
- + (comment != null ? " (" + comment + ")" : ""));
- }
-
- /**
- * Log a block creation attempt.
- *
- * @param player
- * @param item
- */
- public void logPlaceAttempt(Player player, int item, String comment) {
- logger.log(Level.INFO, "WorldGuard: " + player.getName()
- + " 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 + ")" : ""));
- }
-
- /**
- * Log a drop attempt.
- *
- * @param player
- * @param item
- */
- public void logDropAttempt(Player player, int item, String comment) {
- logger.log(Level.INFO, "WorldGuard: " + player.getName()
- + " tried to drop " + getFriendlyItemName(item)
- + (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.
- *
- * @param id
- */
- private static String getFriendlyItemName(int id) {
- return etc.getDataSource().getItem(id) + " (#" + id + ")";
- }
-
- /**
- * Close the connection.
- */
- public void close() {
- }
-}
diff --git a/src/DatabaseLoggerHandler.java b/src/DatabaseLoggerHandler.java
deleted file mode 100644
index 2e3d2f05..00000000
--- a/src/DatabaseLoggerHandler.java
+++ /dev/null
@@ -1,227 +0,0 @@
-// $Id$
-/*
- * WorldGuard
- * Copyright (C) 2010 sk89q
- *
- * 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 .
-*/
-
-import java.util.logging.Logger;
-import java.util.logging.Level;
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.SQLException;
-import java.sql.PreparedStatement;
-
-/**
- *
- * @author sk89q
- */
-public class DatabaseLoggerHandler implements BlacklistLoggerHandler {
- /**
- * Logger.
- */
- private static final Logger logger = Logger.getLogger("Minecraft.WorldGuard");
-
- /**
- * DSN.
- */
- private String dsn;
- /**
- * Username.
- */
- private String user;
- /**
- * Password.
- */
- private String pass;
- /**
- * Table.
- */
- private String table;
- /**
- * Database connection.
- */
- private Connection conn;
-
- /**
- * Construct the object.
- *
- * @param dsn
- * @param user
- * @param pass
- */
- public DatabaseLoggerHandler(String dsn, String user, String pass, String table) {
- this.dsn = dsn;
- this.user = user;
- this.pass = pass;
- this.table = table;
- }
-
- /**
- * Gets the database connection.
- *
- * @return
- * @throws SQLException
- */
- private Connection getConnection() throws SQLException {
- if (conn == null || conn.isClosed()) {
- conn = DriverManager.getConnection(dsn, user, pass);
- }
- return conn;
- }
-
- /**
- * Log an event to the database.
- *
- * @param event
- * @param name
- * @param x
- * @param y
- * @param z
- * @param item
- * @param comment
- */
- private void logEvent(String event, String name, int x, int y, int z, int item,
- String comment) {
- try {
- Connection conn = getConnection();
- PreparedStatement stmt = conn.prepareStatement(
- "INSERT INTO " + table
- + "(event, player, x, y, z, item, time, comment) VALUES "
- + "(?, ?, ?, ?, ?, ?, ?, ?)");
- stmt.setString(1, event);
- stmt.setString(2, name);
- stmt.setInt(3, x);
- stmt.setInt(4, y);
- stmt.setInt(5, z);
- stmt.setInt(6, item);
- stmt.setInt(7, (int)(System.currentTimeMillis() / 1000));
- stmt.setString(8, comment);
- stmt.executeUpdate();
- } catch (SQLException e) {
- logger.log(Level.SEVERE, "Failed to log blacklist event to database: "
- + e.getMessage());
- }
- }
-
- /**
- * Log a block destroy attempt.
- *
- * @param player
- * @param block
- */
- public void logDestroyAttempt(Player player, Block block, String comment) {
- logEvent("DESTROY", player.getName(),
- block.getX(), block.getY(), block.getZ(), block.getType(),
- comment);
- }
-
- /**
- * Log a block break attempt.
- *
- * @param player
- * @param block
- */
- public void logBreakAttempt(Player player, Block block, String comment) {
- logEvent("BREAK", player.getName(),
- block.getX(), block.getY(), block.getZ(), block.getType(),
- comment);
- }
-
- /**
- * Log a right click on attempt.
- *
- * @param player
- * @param block
- */
- public void logRightClickAttempt(Player player, Block block, String comment) {
- logEvent("RIGHT_CLICK", player.getName(),
- block.getX(), block.getY(), block.getZ(), block.getType(),
- comment);
- }
-
- /**
- * Right a left click attempt.
- *
- * @param player
- * @param item
- */
- public void logDestroyWithAttempt(Player player, int item, String comment) {
- logEvent("DESTROY_WITH", player.getName(),
- (int)Math.floor(player.getX()), (int)Math.floor(player.getY()),
- (int)Math.floor(player.getZ()), item, comment);
- }
-
- /**
- * Log a place attempt.
- *
- * @param player
- * @param item
- */
- 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);
- }
-
- /**
- * Log a drop attempt.
- *
- * @param player
- * @param item
- */
- public void logDropAttempt(Player player, int item, String comment) {
- logEvent("DROP", player.getName(),
- (int)Math.floor(player.getX()), (int)Math.floor(player.getY()),
- (int)Math.floor(player.getZ()), item, 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.
- */
- public void close() {
- try {
- if (conn != null && !conn.isClosed()) {
- conn.close();
- }
- } catch (SQLException e) {
-
- }
- }
-}
diff --git a/src/FileLoggerHandler.java b/src/FileLoggerHandler.java
deleted file mode 100644
index 6f31d857..00000000
--- a/src/FileLoggerHandler.java
+++ /dev/null
@@ -1,326 +0,0 @@
-// $Id$
-/*
- * WorldGuard
- * Copyright (C) 2010 sk89q
- *
- * 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 .
-*/
-
-import java.util.logging.Logger;
-import java.util.logging.Level;
-import java.io.*;
-import java.util.regex.*;
-import java.util.Map;
-import java.util.Date;
-import java.util.Calendar;
-import java.util.GregorianCalendar;
-import java.util.TreeMap;
-import java.util.Iterator;
-import java.text.SimpleDateFormat;
-
-/**
- *
- * @author sk89q
- */
-public class FileLoggerHandler implements BlacklistLoggerHandler {
- /**
- * Logger.
- */
- private static final Logger logger = Logger.getLogger("Minecraft.WorldGuard");
- /**
- * Regex for patterns in the path.
- */
- private static Pattern pattern = Pattern.compile("%.");
- /**
- * Date format.
- */
- private static SimpleDateFormat dateFormat =
- new SimpleDateFormat("yyyyy-MM-dd HH:mm:ss");
-
- /**
- * Number of files to keep open at a time.
- */
- private int cacheSize = 10;
- /**
- * Path pattern.
- */
- private String pathPattern;
- /**
- * Cache of writers.
- */
- private TreeMap writers =
- new TreeMap();
-
- /**
- * Construct the object.
- *
- * @param pathPattern
- */
- public FileLoggerHandler(String pathPattern) {
- this.pathPattern = pathPattern;
- }
-
- /**
- * Construct the object.
- *
- * @param pathPattern
- * @param cacheSize
- */
- public FileLoggerHandler(String pathPattern, int cacheSize) {
- if (cacheSize < 1) {
- throw new IllegalArgumentException("Cache size cannot be less than 1");
- }
- this.pathPattern = pathPattern;
- this.cacheSize = cacheSize;
- }
-
- /**
- * Build the path.
- *
- * @return
- */
- private String buildPath(String playerName) {
- GregorianCalendar calendar = new GregorianCalendar();
-
- Matcher m = pattern.matcher(pathPattern);
- StringBuffer buffer = new StringBuffer();
-
- // Pattern replacements
- while (m.find()) {
- String group = m.group();
- String rep = "?";
-
- if (group.matches("%%")) {
- rep = "%";
- } else if (group.matches("%u")) {
- rep = playerName.toLowerCase().replaceAll("[^A-Za-z0-9_]", "_");
- if (rep.length() > 32) { // Actual max length is 16
- rep = rep.substring(0, 32);
- }
-
- // Date and time
- } else if (group.matches("%Y")) {
- rep = String.valueOf(calendar.get(Calendar.YEAR));
- } else if (group.matches("%m")) {
- rep = String.format("%02d", calendar.get(Calendar.MONTH));
- } else if (group.matches("%d")) {
- rep = String.format("%02d", calendar.get(Calendar.DAY_OF_MONTH));
- } else if (group.matches("%W")) {
- rep = String.format("%02d", calendar.get(Calendar.WEEK_OF_YEAR));
- } else if (group.matches("%H")) {
- rep = String.format("%02d", calendar.get(Calendar.HOUR_OF_DAY));
- } else if (group.matches("%h")) {
- rep = String.format("%02d", calendar.get(Calendar.HOUR));
- } else if (group.matches("%i")) {
- rep = String.format("%02d", calendar.get(Calendar.MINUTE));
- } else if (group.matches("%s")) {
- rep = String.format("%02d", calendar.get(Calendar.SECOND));
- }
-
- m.appendReplacement(buffer, rep);
- }
-
- m.appendTail(buffer);
-
- return buffer.toString();
- }
-
- /**
- * Log a message.
- *
- * @param player
- * @param message
- */
- private void log(Player player, String message, String comment) {
- String path = buildPath(player.getName());
- try {
- String date = dateFormat.format(new Date());
- String line = "[" + date + "] " + player.getName() + ": " + message
- + (comment != null ? " (" + comment + ")" : "") + "\r\n";
-
- FileLoggerWriter writer = writers.get(path);
-
- // Writer already exists!
- if (writer != null) {
- try {
- BufferedWriter out = writer.getWriter();
- out.write(line);
- out.flush();
- writer.updateLastUse();
- return;
- } catch (IOException e) {
- // Failed initial rewrite... let's re-open
- }
- }
-
- // Make parent directory
- File file = new File(path);
- File parent = file.getParentFile();
- if (parent != null && !parent.exists()) {
- parent.mkdirs();
- }
-
- FileWriter stream = new FileWriter(path, true);
- BufferedWriter out = new BufferedWriter(stream);
- out.write(line);
- out.flush();
- writer = new FileLoggerWriter(path, out);
- writers.put(path, writer);
-
- // Check to make sure our cache doesn't get too big!
- if (writers.size() > cacheSize) {
- Iterator> it =
- writers.entrySet().iterator();
-
- // Remove some entries
- for (; it.hasNext(); ) {
- Map.Entry entry = it.next();
- try {
- entry.getValue().getWriter().close();
- } catch (IOException e) {
- }
- it.remove();
-
- // Trimmed enough
- if (writers.size() <= cacheSize) {
- break;
- }
- }
- }
-
- } catch (IOException e) {
- logger.log(Level.WARNING, "Failed to log blacklist event to '"
- + path + "': " + e.getMessage());
- }
- }
-
- /**
- * 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.
- *
- * @param player
- * @param block
- */
- public void logDestroyAttempt(Player player, Block block, String comment) {
- log(player, "Tried to destroy " + getFriendlyItemName(block.getType())
- + " " + getCoordinates(block),
- comment);
- }
-
- /**
- * Log a block break attempt.
- *
- * @param player
- * @param block
- */
- public void logBreakAttempt(Player player, Block block, String comment) {
- log(player, "Tried to break " + getFriendlyItemName(block.getType())
- + " " + getCoordinates(block),
- comment);
- }
-
- /**
- * Log a right click on attempt.
- *
- * @param player
- * @param block
- */
- public void logRightClickAttempt(Player player, Block block, String comment) {
- log(player, "Tried to right click " + getFriendlyItemName(block.getType())
- + " " + getCoordinates(block),
- comment);
- }
-
- /**
- * Log an attempt to destroy with an item.
- *
- * @param player
- * @param item
- */
- public void logDestroyWithAttempt(Player player, int item, String comment) {
- log(player, "Tried to destroy with " + getFriendlyItemName(item), comment);
- }
-
- /**
- * Log a block creation attempt.
- *
- * @param player
- * @param item
- */
- 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);
- }
-
- /**
- * Log a drop attempt.
- *
- * @param player
- * @param item
- */
- public void logDropAttempt(Player player, int item, String comment) {
- 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.
- *
- * @param id
- */
- private static String getFriendlyItemName(int id) {
- return etc.getDataSource().getItem(id) + " (#" + id + ")";
- }
-
- /**
- * Close handles.
- */
- public void close() {
- for (Map.Entry entry : writers.entrySet()) {
- try {
- entry.getValue().getWriter().close();
- } catch (IOException e) {
- }
- }
-
- writers.clear();
- }
-}
diff --git a/src/FileLoggerWriter.java b/src/FileLoggerWriter.java
deleted file mode 100644
index ea87ef6f..00000000
--- a/src/FileLoggerWriter.java
+++ /dev/null
@@ -1,98 +0,0 @@
-// $Id$
-/*
- * WorldGuard
- * Copyright (C) 2010 sk89q
- *
- * 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 .
-*/
-
-import java.io.*;
-
-/**
- *
- * @author sk89q
- */
-public class FileLoggerWriter implements Comparable {
- /**
- * Path.
- */
- public String path;
- /**
- * Writer.
- */
- private BufferedWriter writer;
- /**
- * Last use.
- */
- private long lastUse;
-
- /**
- * Construct the object.
- *
- * @param writer
- */
- public FileLoggerWriter(String path, BufferedWriter writer) {
- this.path = path;
- this.writer = writer;
- lastUse = System.currentTimeMillis();
- }
-
- /**
- * File path.
- *
- * @return
- */
- public String getPath() {
- return path;
- }
-
- /**
- * @return the writer
- */
- public BufferedWriter getWriter() {
- return writer;
- }
-
- /**
- * @return the lastUse
- */
- public long getLastUse() {
- return lastUse;
- }
-
- /**
- * Update last use time.
- *
- * @return
- */
- public void updateLastUse() {
- lastUse = System.currentTimeMillis();
- }
-
- /**
- * Comparison function.
- *
- * @param other
- * @return
- */
- public int compareTo(FileLoggerWriter other) {
- if (lastUse > other.lastUse) {
- return 1;
- } else if (lastUse < other.lastUse) {
- return -1;
- } else {
- return 0;
- }
- }
-}
diff --git a/src/ItemArrayUtil.java b/src/ItemArrayUtil.java
deleted file mode 100644
index 2960b47a..00000000
--- a/src/ItemArrayUtil.java
+++ /dev/null
@@ -1,43 +0,0 @@
-// $Id$
-/*
- * WorldGuard
- * Copyright (C) 2010 sk89q
- *
- * 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 .
-*/
-
-/**
- * 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);
- }
- }
- }
-}
diff --git a/src/WorldGuard.java b/src/WorldGuard.java
deleted file mode 100644
index a6c443b1..00000000
--- a/src/WorldGuard.java
+++ /dev/null
@@ -1,202 +0,0 @@
-// $Id$
-/*
- * WorldGuard
- * Copyright (C) 2010 sk89q
- *
- * 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 .
-*/
-
-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.*;
-
-/**
- * Entry point for the plugin for hey0's mod.
- *
- * @author sk89q
- */
-public class WorldGuard extends Plugin {
- /**
- * Logger.
- */
- private static final Logger logger = Logger.getLogger("Minecraft.WorldGuard");
- /**
- * Listener for the plugin system.
- */
- private WorldGuardListener listener;
-
- /**
- * Initialize the plugin.
- */
- public WorldGuard() {
- try {
- listener = new WorldGuardListener(this);
- } catch (NoClassDefFoundError e) {
- logger.severe("*** WORLDGUARD FAILED TO LOAD. ALL PROTECTION IS DISABLED!");
- logger.severe("*** YOUR SERVER WILL BE SAVED AND STOPPED TO PREVENT DAMAGE TO YOUR WORLD. DISABLE WORLDGUARD OR CORRECT THE PROBLEM.");
- logger.severe("*** WorldEdit must be placed into the plugins/ directory");
- etc.getServer().useConsoleCommand("stop");
- }
- }
-
- /**
- * Initializes the plugin.
- */
- @Override
- public void initialize() {
- if (listener == null) {
- return;
- }
-
- List missingFeatures = new ArrayList();
-
- registerHook("COMMAND", PluginListener.Priority.MEDIUM);
- registerHook("SERVERCOMMAND", PluginListener.Priority.MEDIUM);
- 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);
- 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);
- 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("BLOCK_PHYSICS", PluginListener.Priority.MEDIUM);
- registerHook("HEALTH_CHANGE", PluginListener.Priority.MEDIUM);
- registerHook("DAMAGE", PluginListener.Priority.MEDIUM);
- registerHook("LIQUID_DESTROY", PluginListener.Priority.MEDIUM);
- registerHook("BLOCK_RIGHTCLICKED", PluginListener.Priority.MEDIUM);
-
- 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;
- }
- }
-
- /**
- * Enables the plugin.
- */
- @Override
- public void enable() {
- if (listener == null) {
- return;
- }
-
- logger.log(Level.INFO, "WorldGuard version " + getVersion() + " loaded");
- listener.loadConfiguration();
-
- etc.getInstance().addCommand("/stopfire", "Globally stop fire spread");
- etc.getInstance().addCommand("/allowfire", "Globally re-enable fire spread");
- }
-
- /**
- * Disables the plugin.
- */
- @Override
- public void disable() {
- try {
- listener.disable();
- BlacklistEntry.forgetAllPlayers();
- } catch (Throwable t) {
- }
-
- etc.getInstance().removeCommand("/stopfire");
- etc.getInstance().removeCommand("/allowfire");
- }
-
- /**
- * Get the WorldGuard version.
- *
- * @return
- */
- private String getVersion() {
- try {
- String classContainer = WorldGuard.class.getProtectionDomain()
- .getCodeSource().getLocation().toString();
- URL manifestUrl = new URL("jar:" + classContainer + "!/META-INF/MANIFEST.MF");
- Manifest manifest = new Manifest(manifestUrl.openStream());
- Attributes attrib = manifest.getMainAttributes();
- String ver = (String)attrib.getValue("WorldGuard-Version");
- return ver != null ? ver : "(unavailable)";
- } catch (IOException e) {
- return "(unknown)";
- }
- }
-
- /**
- * Joins a string from an array of strings.
- *
- * @param str
- * @param delimiter
- * @return
- */
- private static String concatMissingFeatures(List 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();
- }
-}
diff --git a/src/WorldGuardListener.java b/src/WorldGuardListener.java
deleted file mode 100644
index fd45dba5..00000000
--- a/src/WorldGuardListener.java
+++ /dev/null
@@ -1,1610 +0,0 @@
-// $Id$
-/*
- * WorldGuard
- * Copyright (C) 2010 sk89q
- *
- * 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 .
-*/
-
-import java.util.logging.Logger;
-import java.util.logging.Level;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-import java.util.Arrays;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.HashMap;
-import java.io.*;
-import com.sk89q.worldedit.BlockVector;
-import com.sk89q.worldedit.IncompleteRegionException;
-import com.sk89q.worldedit.Vector;
-import com.sk89q.worldedit.WorldEditNotInstalled;
-import com.sk89q.worldedit.blocks.BlockType;
-import com.sk89q.worldguard.LocalPlayer;
-import com.sk89q.worldguard.domains.DefaultDomain;
-import com.sk89q.worldguard.protection.*;
-
-/**
- * Event listener for Hey0's server mod.
- *
- * @author sk89q
- */
-public class WorldGuardListener extends PluginListener {
- /**
- * Logger.
- */
- private static final Logger logger = Logger.getLogger("Minecraft.WorldGuard");
-
- /**
- * Properties file for WorldGuard.
- */
- private PropertiesFile properties = new PropertiesFile("worldguard.properties");
-
- private static int CMD_LIST_SIZE = 9;
- private static Pattern groupPattern = Pattern.compile("^[gG]:(.+)$");
-
- private RegionManager regionManager = new FlatRegionManager();
- private ProtectionDatabase regionLoader =
- new CSVDatabase(new File("worldguard-regions.txt"));
-
- private Set invinciblePlayers = new HashSet();
- private Set amphibiousPlayers = new HashSet();
- private Map recentLogins = new HashMap();
- private Map lastSpawn = new HashMap();
-
- private boolean useRegions = false;
- private boolean stopFireSpread = false;
- private boolean enforceOneSession;
- private boolean blockCreepers;
- private boolean blockTNT;
- private boolean blockLighter;
- private boolean preventLavaFire;
- private boolean disableAllFire;
- private boolean simulateSponge;
- private int spongeRadius;
- private Set fireNoSpreadBlocks;
- private Set allowedLavaSpreadOver;
- private Set itemDropBlacklist;
- private Set 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 boolean disableSuffocationDamage;
- private boolean teleportOnSuffocation;
- private int loginProtection;
- private int spawnProtection;
- private boolean teleportToHome;
- private boolean exactRespawn;
- private boolean kickOnDeath;
- private int regionWand = 287;
- private Blacklist blacklist;
-
- /**
- * Construct the listener.
- *
- * @param plugin
- */
- public WorldGuardListener(WorldGuard plugin) {
- postReload();
- }
-
- /**
- * Convert a comma-delimited list to a set of integers.
- *
- * @param str
- * @return
- */
- private static Set toBlockIDSet(String str) {
- if (str.trim().length() == 0) {
- return null;
- }
-
- String[] items = str.split(",");
- Set result = new HashSet();
-
- for (String item : items) {
- try {
- result.add(Integer.parseInt(item.trim()));
- } catch (NumberFormatException e) {
- int id = etc.getDataSource().getItem(item.trim());
- if (id != 0) {
- result.add(id);
- } else {
- logger.log(Level.WARNING, "WorldGuard: Unknown block name: "
- + item);
- }
- }
- }
-
- 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() {
- try {
- properties.load();
- } catch (IOException e) {
- logger.log(Level.WARNING, "WorldGuard: Failed to load configuration: "
- + e.getMessage());
- }
-
- try {
- regionLoader.load();
- regionManager.setRegions(regionLoader.getRegions());
- } catch (IOException e) {
- logger.warning("WorldGuard: Failed to load regions: "
- + e.getMessage());
- }
-
- recentLogins.clear();
-
- // Load basic options
- useRegions = properties.getBoolean("use-regions", true);
- 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", 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", true);
- spongeRadius = Math.max(1, properties.getInt("sponge-radius", 3)) - 1;
- 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);
- 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);
- regionWand = properties.getInt("regions-wand", 287);
-
- // Console log configuration
- boolean logConsole = properties.getBoolean("log-console", true);
-
- // Database log configuration
- boolean logDatabase = properties.getBoolean("log-database", false);
- String dsn = properties.getString("log-database-dsn", "jdbc:mysql://localhost:3306/minecraft");
- String user = properties.getString("log-database-user", "root");
- String pass = properties.getString("log-database-pass", "");
- String table = properties.getString("log-database-table", "blacklist_events");
-
- // File log configuration
- boolean logFile = properties.getBoolean("log-file", false);
- String logFilePattern = properties.getString("log-file-path", "worldguard/logs/%Y-%m-%d.log");
- int logFileCacheSize = Math.max(1, properties.getInt("log-file-open-files", 10));
-
- // Load the blacklist
- try {
- // If there was an existing blacklist, close loggers
- if (blacklist != null) {
- blacklist.getLogger().close();
- }
-
- // First load the blacklist data from 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 (blist.isEmpty()) {
- this.blacklist = null;
- } else {
- this.blacklist = blist;
- logger.log(Level.INFO, "WorldGuard: Blacklist loaded.");
-
- BlacklistLogger blacklistLogger = blist.getLogger();
-
- if (logDatabase) {
- blacklistLogger.addHandler(new DatabaseLoggerHandler(dsn, user, pass, table));
- }
-
- if (logConsole) {
- blacklistLogger.addHandler(new ConsoleLoggerHandler());
- }
-
- if (logFile) {
- FileLoggerHandler handler =
- new FileLoggerHandler(logFilePattern, logFileCacheSize);
- blacklistLogger.addHandler(handler);
- }
- }
- } catch (FileNotFoundException e) {
- logger.log(Level.WARNING, "WorldGuard blacklist does not exist.");
- } catch (IOException e) {
- logger.log(Level.WARNING, "Could not load WorldGuard blacklist: "
- + e.getMessage());
- }
-
- // Print an overview of settings
- if (properties.getBoolean("summary-on-start", true)) {
- logger.log(Level.INFO, enforceOneSession ? "WorldGuard: Single session is enforced."
- : "WorldGuard: Single session is NOT ENFORCED.");
- logger.log(Level.INFO, blockTNT ? "WorldGuard: TNT ignition is blocked."
- : "WorldGuard: TNT ignition is PERMITTED.");
- logger.log(Level.INFO, blockLighter ? "WorldGuard: Lighters are blocked."
- : "WorldGuard: Lighters are PERMITTED.");
- logger.log(Level.INFO, preventLavaFire ? "WorldGuard: Lava fire is blocked."
- : "WorldGuard: Lava fire is PERMITTED.");
- if (disableAllFire) {
- logger.log(Level.INFO, "WorldGuard: All fire spread is disabled.");
- } else {
- if (fireNoSpreadBlocks != null) {
- logger.log(Level.INFO, "WorldGuard: Fire spread is limited to "
- + fireNoSpreadBlocks.size() + " block types.");
- } else {
- logger.log(Level.INFO, "WorldGuard: Fire spread is UNRESTRICTED.");
- }
- }
- }
- }
-
- /**
- * Called during the early login process to check whether or not to kick the
- * player
- *
- * @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()) {
- if (player.getName().equalsIgnoreCase(user)) {
- player.kick("Logged in from another location.");
- }
- }
- }
-
- return null;
- }
-
- /**
- * Called during the later login process
- *
- * @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 || teleportToHome || exactRespawn) {
- recentLogins.put(player.getName(), System.currentTimeMillis());
- }
-
- if (player.isInGroup("wg-invincible")) {
- invinciblePlayers.add(player.getName());
- }
-
- if (player.isInGroup("wg-amphibious")) {
- amphibiousPlayers.add(player.getName());
- }
- }
-
- /**
- * Called before the command is parsed. Return true if you don't want the
- * command to be parsed.
- *
- * @param player
- * @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")) {
- if (!stopFireSpread) {
- etc.getServer().messageAll(Colors.Yellow
- + "Fire spread has been globally disabled by " + player.getName() + ".");
- } else {
- player.sendMessage(Colors.Yellow + "Fire spread was already globally disabled.");
- }
- stopFireSpread = true;
- return true;
- } else if (split[0].equalsIgnoreCase("/allowfire")
- && player.canUseCommand("/stopfire")) {
- if (stopFireSpread) {
- etc.getServer().messageAll(Colors.Yellow
- + "Fire spread has been globally re-enabled by " + player.getName() + ".");
- } else {
- player.sendMessage(Colors.Yellow + "Fire spread was already globally enabled.");
- }
- 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")) {
- Item[] items = player.getInventory().getContents();
- int len = items.length;
-
- int affected = 0;
-
- for (int i = 0; i < len; i++) {
- Item item = items[i];
-
- // Avoid infinite stacks and stacks with durability
- if (item == null || item.getAmount() <= 0
- || shouldNotStack(item.getItemId())) {
- continue;
- }
-
- // Ignore buckets
- if (item.getItemId() >= 325 && item.getItemId() <= 327) {
- continue;
- }
-
- 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++) {
- Item item2 = items[j];
-
- // Avoid infinite stacks and stacks with durability
- if (item2 == null || item2.getAmount() <= 0
- || shouldNotStack(item.getItemId())) {
- continue;
- }
-
- // Same type?
- if (item2.getItemId() == item.getItemId()) {
- // This stack won't fit in the parent stack
- if (item2.getAmount() > needed) {
- item.setAmount(64);
- item2.setAmount(item2.getAmount() - needed);
- break;
- // This stack will
- } else {
- items[j] = null;
- item.setAmount(item.getAmount() + item2.getAmount());
- needed = 64 - item.getAmount();
- }
-
- affected++;
- }
- }
- }
- }
-
- if (affected > 0) {
- ItemArrayUtil.setContents((ItemArray>)player.getInventory(), items);
- }
-
- player.sendMessage(Colors.Yellow + "Items compacted into stacks!");
-
- return true;
- } else if (split[0].equalsIgnoreCase("/rg")
- || split[0].equalsIgnoreCase("/region")) {
- if (split.length < 2) {
- player.sendMessage(Colors.Rose + "/rg ...");
- return true;
- }
-
- String action = split[1];
- String[] args = new String[split.length - 1];
- System.arraycopy(split, 1, args, 0, split.length - 1);
-
- handleRegionCommand(player, action, args);
-
- 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;
- }
-
- /**
- * Handles a region command.
- *
- * @param player
- * @param action
- * @param args
- */
- private void handleRegionCommand(Player player, String action, String[] args) {
- if (action.equalsIgnoreCase("define")
- && canUseRegionCommand(player, "/regiondefine")) {
- if (args.length < 2) {
- player.sendMessage(Colors.Rose + "/rg define [owner1 [owner2 [owners...]]]");
- return;
- }
-
- try {
- String id = args[1].toLowerCase();
- BlockVector min = WorldEditBridge.getRegionMinimumPoint(player).toBlockVector();
- BlockVector max = WorldEditBridge.getRegionMaximumPoint(player).toBlockVector();
- ProtectedRegion region = new ProtectedCuboidRegion(min, max);
- if (args.length >= 3) {
- region.setOwners(parseDomainString(args, 2));
- }
- regionManager.addRegion(id, region);
- regionLoader.save(regionManager);
- player.sendMessage(Colors.Yellow + "Region saved as " + id + ".");
- } catch (WorldEditNotInstalled e) {
- player.sendMessage(Colors.Rose + "WorldEdit must be installed and enabled as a plugin.");
- } catch (IncompleteRegionException e) {
- player.sendMessage(Colors.Rose + "You must first define an area in WorldEdit.");
- } catch (IOException e) {
- player.sendMessage(Colors.Rose + "Region database failed to save: "
- + e.getMessage());
- }
- } else if (action.equalsIgnoreCase("flag")
- && canUseRegionCommand(player, "/regiondefine")) {
- if (args.length < 4) {
- player.sendMessage(Colors.Rose + "/rg flag ");
- return;
- }
-
- try {
- String id = args[1].toLowerCase();
- String flagStr = args[2];
- String stateStr = args[3];
- ProtectedRegion region = regionManager.getRegion(id);
-
- if (region == null) {
- player.sendMessage(Colors.Rose + "Could not find a region by that ID.");
- return;
- }
-
- AreaFlags.State state = null;
-
- if (stateStr.equalsIgnoreCase("allow")) {
- state = AreaFlags.State.ALLOW;
- } else if (stateStr.equalsIgnoreCase("deny")) {
- state = AreaFlags.State.DENY;
- } else if (stateStr.equalsIgnoreCase("none")) {
- state = AreaFlags.State.NONE;
- } else {
- player.sendMessage(Colors.Rose + "Acceptable states: allow, deny, none");
- return;
- }
-
- AreaFlags flags = region.getFlags();
-
- if (flagStr.equalsIgnoreCase("build")) {
- flags.allowBuild = state;
- } else if (flagStr.equalsIgnoreCase("pvp")) {
- flags.allowPvP = state;
- } else if (flagStr.equalsIgnoreCase("tnt")) {
- flags.allowTNT = state;
- } else if (flagStr.equalsIgnoreCase("lighter")) {
- flags.allowLighter = state;
- } else {
- player.sendMessage(Colors.Rose + "Acceptable flags: build, pvp, tnt, lighter");
- return;
- }
-
- regionLoader.save(regionManager);
- player.sendMessage(Colors.Yellow + "Region '" + id + "' updated.");
- } catch (IOException e) {
- player.sendMessage(Colors.Rose + "Region database failed to save: "
- + e.getMessage());
- }
- } else if (action.equalsIgnoreCase("info")
- && canUseRegionCommand(player, "/regioninfo")) {
- if (args.length < 2) {
- player.sendMessage(Colors.Rose + "/rg info ");
- return;
- }
-
- String id = args[1].toLowerCase();
- if (!regionManager.hasRegion(id)) {
- player.sendMessage(Colors.Rose + "A region with ID '"
- + id + "' doesn't exist.");
- return;
- }
-
- ProtectedRegion region = regionManager.getRegion(id);
- AreaFlags flags = region.getFlags();
- DefaultDomain domain = region.getOwners();
-
- player.sendMessage(Colors.Yellow + "Region ID: " + id);
- player.sendMessage(Colors.LightGray + "Type: " + region.getClass().getCanonicalName());
- player.sendMessage(Colors.LightBlue + "Build: " + flags.allowBuild.name());
- player.sendMessage(Colors.LightBlue + "PvP: " + flags.allowPvP.name());
- player.sendMessage(Colors.LightBlue + "TNT: " + flags.allowTNT.name());
- player.sendMessage(Colors.LightBlue + "Lighter: " + flags.allowLighter.name());
- player.sendMessage(Colors.LightPurple + "Players: " + domain.toPlayersString());
- player.sendMessage(Colors.LightPurple + "Groups: " + domain.toGroupsString());
- } else if (action.equalsIgnoreCase("add")
- && canUseRegionCommand(player, "/regiondefine")) {
- if (args.length < 2) {
- player.sendMessage(Colors.Rose + "/rg add ");
- return;
- }
-
- try {
- String id = args[1].toLowerCase();
- if (!regionManager.hasRegion(id)) {
- player.sendMessage(Colors.Rose + "A region with ID '"
- + id + "' doesn't exist.");
- return;
- }
-
- addToDomain(regionManager.getRegion(id).getOwners(), args, 1);
-
- regionLoader.save(regionManager);
- player.sendMessage(Colors.Yellow + "Region updated!");
- } catch (IOException e) {
- player.sendMessage(Colors.Rose + "Region database failed to save: "
- + e.getMessage());
- }
- } else if (action.equalsIgnoreCase("remove")
- && canUseRegionCommand(player, "/regiondefine")) {
- if (args.length < 2) {
- player.sendMessage(Colors.Rose + "/rg remove ");
- return;
- }
-
- try {
- String id = args[1].toLowerCase();
- if (!regionManager.hasRegion(id)) {
- player.sendMessage(Colors.Rose + "A region with ID '"
- + id + "' doesn't exist.");
- return;
- }
-
- removeFromDomain(regionManager.getRegion(id).getOwners(), args, 1);
-
- regionLoader.save(regionManager);
- player.sendMessage(Colors.Yellow + "Region updated!");
- } catch (IOException e) {
- player.sendMessage(Colors.Rose + "Region database failed to save: "
- + e.getMessage());
- }
- } else if (action.equalsIgnoreCase("list")
- && canUseRegionCommand(player, "/regionlist")) {
- int page = 0;
-
- if (args.length >= 2) {
- try {
- page = Math.max(0, Integer.parseInt(args[1]) - 1);
- } catch (NumberFormatException e) {
- page = 0;
- }
- }
-
- Map regions = regionManager.getRegions();
- int size = regions.size();
- int pages = (int)Math.ceil(size / (float)CMD_LIST_SIZE);
-
- String[] regionIDList = new String[size];
- int index = 0;
- for (String id : regions.keySet()) {
- regionIDList[index] = id;
- index++;
- }
- Arrays.sort(regionIDList);
-
-
- player.sendMessage(Colors.Rose + "Regions (page "
- + (page + 1) + " of " + pages + "):");
-
- if (page < pages) {
- for (int i = page * CMD_LIST_SIZE; i < page * CMD_LIST_SIZE + CMD_LIST_SIZE; i++) {
- if (i >= size) break;
- player.sendMessage(Colors.Yellow + (i + 1) + ". " + regionIDList[i]);
- }
- }
- } else if (action.equalsIgnoreCase("delete")
- && canUseRegionCommand(player, "/regiondelete")) {
- if (args.length < 2) {
- player.sendMessage(Colors.Rose + "/rg delete ");
- return;
- }
-
- try {
- String id = args[1].toLowerCase();
- if (!regionManager.hasRegion(id)) {
- player.sendMessage(Colors.Rose + "A region with ID '"
- + id + "' doesn't exist.");
- return;
- }
- regionManager.removeRegion(id);
- regionLoader.save(regionManager);
- player.sendMessage(Colors.Yellow + "Region removed!");
- } catch (IOException e) {
- player.sendMessage(Colors.Rose + "Region database failed to save: "
- + e.getMessage());
- }
- } else if (action.equalsIgnoreCase("save")
- && canUseRegionCommand(player, "/regionsave")) {
- try {
- regionLoader.save(regionManager);
- player.sendMessage(Colors.Yellow + "Region database saved to file!");
- } catch (IOException e) {
- player.sendMessage(Colors.Rose + "Region database failed to save: "
- + e.getMessage());
- }
- } else if (action.equalsIgnoreCase("load")
- && canUseRegionCommand(player, "/regionload")) {
- try {
- regionLoader.load(regionManager);
- player.sendMessage(Colors.Yellow + "Region database loaded from file!");
- } catch (IOException e) {
- player.sendMessage(Colors.Rose + "Region database failed to load: "
- + e.getMessage());
- }
- } else {
- player.sendMessage(Colors.Rose + "/rg ...");
- }
- }
-
- /**
- * Checks for the command or /region.
- *
- * @param player
- * @param cmd
- * @return
- */
- private static boolean canUseRegionCommand(Player player, String cmd) {
- return player.canUseCommand("/region")
- || player.canUseCommand(cmd);
- }
-
- /**
- * Parse a group/player DefaultDomain specification for areas.
- *
- * @param domain
- * @param split
- * @param startIndex
- */
- private static void addToDomain(DefaultDomain domain,
- String[] split, int startIndex) {
- for (int i = startIndex; i < split.length; i++) {
- String s = split[i];
- Matcher m = groupPattern.matcher(s);
- if (m.matches()) {
- domain.addGroup(m.group(1));
- } else {
- domain.addPlayer(s);
- }
- }
- }
-
- /**
- * Parse a group/player DefaultDomain specification for areas.
- *
- * @param domain
- * @param split
- * @param startIndex
- */
- private static void removeFromDomain(DefaultDomain domain,
- String[] split, int startIndex) {
- for (int i = startIndex; i < split.length; i++) {
- String s = split[i];
- Matcher m = groupPattern.matcher(s);
- if (m.matches()) {
- domain.removeGroup(m.group(1));
- } else {
- domain.removePlayer(s);
- }
- }
- }
-
- /**
- * Parse a group/player DefaultDomain specification for areas.
- *
- * @param split
- * @param startIndex
- * @return
- */
- private static DefaultDomain parseDomainString(String[] split, int startIndex) {
- DefaultDomain domain = new DefaultDomain();
-
- for (int i = startIndex; i < split.length; i++) {
- String s = split[i];
- Matcher m = groupPattern.matcher(s);
- if (m.matches()) {
- domain.addGroup(m.group(1));
- } else {
- domain.addPlayer(s);
- }
- }
-
- return domain;
- }
-
- /**
- * 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
- * want the server command to be parsed by the server.
- *
- * @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) {
- etc.getServer().messageAll(Colors.Yellow
- + "Fire spread has been globally disabled by server console.");
- logger.log(Level.INFO, "Fire spread is now globally disabled.");
- } else {
- logger.log(Level.INFO, "Fire spread was already globally disabled.");
- }
- stopFireSpread = true;
- return true;
- } else if (split[0].equalsIgnoreCase("fire-allow")) {
- if (stopFireSpread) {
- etc.getServer().messageAll(Colors.Yellow
- + "Fire spread has been globally re-enabled by server console.");
- logger.log(Level.INFO, "Fire spread is now globally enabled.");
- } else {
- logger.log(Level.INFO, "Fire spread was already globally enabled.");
- }
- stopFireSpread = false;
- return true;
- }
-
- return false;
- }
-
- /**
- * Called when a player drops an item.
- *
- * @param player
- * player who dropped the item
- * @param item
- * item that was dropped
- * @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();
- if (itemDropBlacklist.contains(n)) {
- player.sendMessage(Colors.Rose + "Item was destroyed!");
- return true;
- }
- }
-
- if (blacklist != null) {
- if (!blacklist.onDrop(item.getItemId(), player)) {
- return true;
- }
- }
-
- /*if (!itemDurability) {
- item.setDamage(0);
- }*/
-
- return false;
- }
-
- /**
- * 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()) {
- 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].getItemId(), player)) {
- items[i] = null;
- needUpdate = true;
- }
- }
- }
-
- if (needUpdate) {
- ItemArrayUtil.setContents((ItemArray>)player.getInventory(), items);
- }
- }
-
- 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 && item != null) {
- int itemId = item.getItemId();
-
- if (!blacklist.onUse(itemId, player)) {
- return true;
- }
- }
-
- if (useRegions && blockPlaced != null) {
- Vector pt = new Vector(blockPlaced.getX(),
- blockPlaced.getY(), blockPlaced.getZ());
- LocalPlayer localPlayer = new HMPlayer(player);
-
- if (!player.canUseCommand("/regionbypass")
- && !regionManager.getApplicableRegions(pt).canBuild(localPlayer)) {
- player.sendMessage(Colors.Red + "You don't have permission for this area.");
- 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 true if you want to undo the block placement
- */
- @Override
- public boolean onBlockPlace(Player player, Block blockPlaced,
- Block blockClicked, Item itemInHand) {
-
- int itemId = itemInHand.getItemId();
-
- if (useRegions) {
- Vector pt = new Vector(blockPlaced.getX(),
- blockPlaced.getY(), blockPlaced.getZ());
- LocalPlayer localPlayer = new HMPlayer(player);
-
- if (!player.canUseCommand("/regionbypass")
- && !regionManager.getApplicableRegions(pt).canBuild(localPlayer)) {
- player.sendMessage(Colors.Red + "You don't have permission for this area.");
- return true;
- }
- }
-
- if (blacklist != null) {
- if (!blacklist.onPlace(itemId, player)) {
- return true;
- }
-
- if (!blacklist.onRightClick(blockClicked, player)) {
- return true;
- }
- }
-
- if (simulateSponge && blockPlaced.getType() == 19) {
- int ox = blockPlaced.getX();
- int oy = blockPlaced.getY();
- int oz = blockPlaced.getZ();
-
- Server server = etc.getServer();
-
- for (int cx = -spongeRadius; cx <= spongeRadius; cx++) {
- for (int cy = -spongeRadius; cy <= spongeRadius; cy++) {
- for (int cz = -spongeRadius; cz <= spongeRadius; cz++) {
- int id = server.getBlockIdAt(ox + cx, oy + cy, oz + cz);
- if (id == 8 || id == 9) {
- server.setBlockAt(0, ox + cx, oy + cy, oz + cz);
- }
- }
- }
- }
- }
-
- return false;
- }
-
- /**
- * Called when a person left clicks a block.
- *
- * @param player
- * @param block
- * @return
- */
- @Override
- public boolean onBlockDestroy(Player player, Block block) {
- if (blacklist != null) {
- if (!blacklist.onDestroyWith(player.getItemInHand(), player)) {
- return true;
- }
-
- if (!blacklist.onDestroy(block, player)) {
- return true;
- }
- }
-
- return false;
- }
-
- /**
- * Called when a person actually breaks the block.
- *
- * @param player
- * @param block
- * @return
- */
- @Override
- public boolean onBlockBreak(Player player, Block block) {
- if (useRegions) {
- Vector pt = new Vector(block.getX(),
- block.getY(), block.getZ());
- LocalPlayer localPlayer = new HMPlayer(player);
-
- if (!player.canUseCommand("/regionbypass")
- && !regionManager.getApplicableRegions(pt).canBuild(localPlayer)) {
- player.sendMessage(Colors.Red + "You don't have permission for this area.");
- return true;
- }
- }
-
- if (blacklist != null) {
- if (!blacklist.onBreak(block, player)) {
- return true;
- }
- }
-
- return false;
- }
-
- /**
- * Called when a player attempts to open an inventory; whether it's a
- * workbench, a chest or their own player inventory
- *
- * @param player user who attempted to open the inventory
- * @param inventory the inventory that they are attempting to open
- * @return
- */
- 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;
- }*/
-
- if (useRegions && (inventory instanceof Chest
- || inventory instanceof DoubleChest
- || inventory instanceof Furnace)) {
- ComplexBlock chest = (ComplexBlock)inventory;
- Vector pt = new Vector(chest.getX(), chest.getY(), chest.getZ());
- LocalPlayer localPlayer = new HMPlayer(player);
-
- if (!player.canUseCommand("/regionbypass")
- && !regionManager.getApplicableRegions(pt).canBuild(localPlayer)) {
- player.sendMessage(Colors.Red + "You don't have permission for this area.");
- return true;
- }
- }
-
- return false;
- }
-
- /**
- * 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
- */
- public boolean onSignChange(Player player, Sign sign) {
- if (blacklist != null) {
- 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;
- }
- }
-
- return false;
- }
-
- /*
- * Called when either a lava block or a lighter tryes to light something on fire.
- * block status depends on the light source:
- * 1 = lava.
- * 2 = lighter (flint + steel).
- * 3 = spread (dynamic spreading of fire).
- * @param block
- * block that the fire wants to spawn in.
- *
- * @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;
- }
-
- if (blockLighter && block.getStatus() == 2) {
- return !player.canUseCommand("/uselighter")
- && !player.canUseCommand("/lighter");
- }
-
- if (stopFireSpread && block.getStatus() == 3) {
- return true;
- }
-
- if (disableAllFire && block.getStatus() == 3) {
- return true;
- }
-
- if (fireNoSpreadBlocks != null && block.getStatus() == 3) {
- int x = block.getX();
- int y = block.getY();
- int z = block.getZ();
- if (fireNoSpreadBlocks.contains(etc.getServer().getBlockIdAt(x, y - 1, z))
- || fireNoSpreadBlocks.contains(etc.getServer().getBlockIdAt(x + 1, y, z))
- || fireNoSpreadBlocks.contains(etc.getServer().getBlockIdAt(x - 1, y, z))
- || fireNoSpreadBlocks.contains(etc.getServer().getBlockIdAt(x, y, z - 1))
- || fireNoSpreadBlocks.contains(etc.getServer().getBlockIdAt(x, y, z + 1))) {
- return true;
- }
- }
-
- if (useRegions && player != null && !player.canUseCommand("/regionbypass")) {
- Vector pt = new Vector(block.getX(),
- block.getY(), block.getZ());
- LocalPlayer localPlayer = new HMPlayer(player);
-
- if (block.getStatus() == 2
- && !regionManager.getApplicableRegions(pt).canBuild(localPlayer)) {
- return true;
- }
-
- if (block.getStatus() == 2
- && !regionManager.getApplicableRegions(pt).allowsLighter()) {
- return true;
- }
- }
-
- return false;
- }
-
- /*
- * Called when a dynamite block or a creeper is triggerd.
- * block status depends on explosive compound:
- * 1 = dynamite.
- * 2 = creeper.
- * @param block
- * dynamite block/creeper location block.
- *
- * @return true if you dont the block to explode.
- */
- @Override
- public boolean onExplode(Block block) {
- if (blockCreepers && block.getStatus() == 2) {
- return true;
- }
-
- if (blockTNT && block.getStatus() == 1) {
- return true;
- }
-
- Vector pt = new Vector(block.getX(), block.getY(), block.getZ());
-
- if (useRegions) {
- if (block.getStatus() == 1) {
- if (!regionManager.getApplicableRegions(pt).allowsTNT()) {
- return true;
- }
-
- // TODO: TNT check to see if it would hit a region
- }
- }
-
- return false;
- }
-
- /*
- * Called when fluid wants to flow to a certain block.
- * (10 & 11 for lava and 8 & 9 for water)
- *
- * @param blockFrom
- * the block where the fluid came from.
- * (blocktype = fluid type)
- * @param blockTo
- * the block where fluid wants to flow to.
- *
- *
- * @return true if you dont want the substance to flow.
- */
- @Override
- public boolean onFlow(Block blockFrom, Block blockTo) {
- boolean isWater = blockFrom.getType() == 8 || blockFrom.getType() == 9;
- boolean isLava = blockFrom.getType() == 10 || blockFrom.getType() == 11;
-
- if (simulateSponge && isWater) {
- int ox = blockTo.getX();
- int oy = blockTo.getY();
- int oz = blockTo.getZ();
-
- Server server = etc.getServer();
-
- for (int cx = -spongeRadius; cx <= spongeRadius; cx++) {
- for (int cy = -spongeRadius; cy <= spongeRadius; cy++) {
- for (int cz = -spongeRadius; cz <= spongeRadius; cz++) {
- if (server.getBlockIdAt(ox + cx, oy + cy, oz + cz) == 19) {
- return true;
- }
- }
- }
- }
- }
-
- if (classicWater && isWater) {
- int blockBelow = etc.getServer().getBlockIdAt(blockFrom.getX(), blockFrom.getY() - 1, blockFrom.getZ());
- if (blockBelow != 0 && blockBelow != 8 && blockBelow != 9) {
- etc.getServer().setBlockAt(9, blockFrom.getX(), blockFrom.getY(), blockFrom.getZ());
- return false;
- }
- }
-
- if (allowedLavaSpreadOver != null && isLava) {
- int targetId = etc.getServer().getBlockIdAt(
- blockTo.getX(), blockTo.getY() - 1, blockTo.getZ());
- if (!allowedLavaSpreadOver.contains(targetId)) {
- return true;
- }
- }
-
- 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 (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 || teleportToHome || exactRespawn) {
- 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);
- }
- }
-
- 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 <= 0 && 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;
- }
-
- if (attacker != null && attacker.isPlayer()) {
- if (useRegions) {
- Vector pt = new Vector(defender.getX(),
- defender.getY(), defender.getZ());
-
- if (!regionManager.getApplicableRegions(pt).allowsPvP()) {
- player.sendMessage(Colors.Red + "You are in a no-PvP area.");
- return true;
- }
- }
- }
- }
-
- return false;
- }
-
- /**
- * Called when someone presses right click aimed at a block.
- * You can intercept this to add your own right click actions
- * to different item types (see itemInHand)
- *
- * @param player
- * @param blockClicked
- * @param itemInHand
- */
- public void onBlockRightClicked(Player player, Block blockClicked, Item item) {
- if (useRegions && item.getType().getId() == regionWand) {
- Vector pt = new Vector(blockClicked.getX(),
- blockClicked.getY(), blockClicked.getZ());
- ApplicableRegionSet app = regionManager.getApplicableRegions(pt);
- List regions = regionManager.getApplicableRegionsIDs(pt);
-
- if (regions.size() > 0) {
- player.sendMessage(Colors.Yellow + "Can you build? "
- + (app.canBuild(new HMPlayer(player)) ? "Yes" : "No"));
-
- StringBuilder str = new StringBuilder();
- for (Iterator it = regions.iterator(); it.hasNext(); ) {
- str.append(it.next());
- if (it.hasNext()) {
- str.append(", ");
- }
- }
-
- player.sendMessage(Colors.Yellow + "Applicable regions: " + str.toString());
- } else {
- player.sendMessage(Colors.Yellow + "WorldGuard: No defined regions here!");
- }
- }
- }
-
- /**
- * 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);
- invinciblePlayers.remove(player.getName());
- amphibiousPlayers.remove(player.getName());
- recentLogins.remove(player.getName());
- }
-
- /**
- * Call to disable the plugin.
- */
- public void disable() {
- if (blacklist != null) {
- 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++;
- }
- }
-}
\ No newline at end of file
diff --git a/src/com/sk89q/worldguard/LocalPlayer.java b/src/com/sk89q/worldguard/LocalPlayer.java
index 2d536a50..94f6aef2 100644
--- a/src/com/sk89q/worldguard/LocalPlayer.java
+++ b/src/com/sk89q/worldguard/LocalPlayer.java
@@ -19,6 +19,9 @@
package com.sk89q.worldguard;
+import java.util.List;
+import com.sk89q.worldedit.Vector;
+
public abstract class LocalPlayer {
/**
* Get a player's name.
@@ -35,6 +38,34 @@ public abstract class LocalPlayer {
*/
public abstract boolean hasGroup(String group);
+ /**
+ * Get the player's position.
+ *
+ * @return
+ */
+ public abstract Vector getPosition();
+
+ /**
+ * Kick the player.
+ *
+ * @param msg
+ */
+ public abstract void kick(String msg);
+
+ /**
+ * Ban the player.
+ *
+ * @param msg
+ */
+ public abstract void ban(String msg);
+
+ /**
+ * Get the player's list of groups.
+ *
+ * @return
+ */
+ public abstract List getGroups();
+
@Override
public boolean equals(Object obj) {
if (!(obj instanceof LocalPlayer)) {
diff --git a/src/HMPlayer.java b/src/com/sk89q/worldguard/bukkit/BukkitPlayer.java
similarity index 52%
rename from src/HMPlayer.java
rename to src/com/sk89q/worldguard/bukkit/BukkitPlayer.java
index fc247870..f574b76d 100644
--- a/src/HMPlayer.java
+++ b/src/com/sk89q/worldguard/bukkit/BukkitPlayer.java
@@ -17,12 +17,20 @@
* along with this program. If not, see .
*/
+package com.sk89q.worldguard.bukkit;
+
+import java.util.List;
+import org.bukkit.Location;
+import org.bukkit.entity.Player;
+import com.sk89q.worldedit.Vector;
import com.sk89q.worldguard.LocalPlayer;
-public class HMPlayer extends LocalPlayer {
+public class BukkitPlayer extends LocalPlayer {
private Player player;
+ private WorldGuardPlugin plugin;
- public HMPlayer(Player player) {
+ public BukkitPlayer(WorldGuardPlugin plugin, Player player) {
+ this.plugin = plugin;
this.player = player;
}
@@ -33,6 +41,28 @@ public String getName() {
@Override
public boolean hasGroup(String group) {
- return player.isInGroup(group);
+ return plugin.inGroup(player, group);
}
+
+ @Override
+ public Vector getPosition() {
+ Location loc = player.getLocation();
+ return new Vector(loc.getX(), loc.getY(), loc.getZ());
+ }
+
+ @Override
+ public void kick(String msg) {
+ player.kickPlayer(msg);
+ }
+
+ @Override
+ public void ban(String msg) {
+ player.kickPlayer(msg);
+ }
+
+ @Override
+ public List getGroups() {
+ return plugin.getGroups(player);
+ }
+
}
diff --git a/src/com/sk89q/worldguard/bukkit/BukkitUtil.java b/src/com/sk89q/worldguard/bukkit/BukkitUtil.java
new file mode 100644
index 00000000..61548e8f
--- /dev/null
+++ b/src/com/sk89q/worldguard/bukkit/BukkitUtil.java
@@ -0,0 +1,53 @@
+// $Id$
+/*
+ * WorldGuard
+ * Copyright (C) 2010 sk89q
+ *
+ * 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 .
+*/
+
+package com.sk89q.worldguard.bukkit;
+
+import java.util.List;
+import org.bukkit.block.Block;
+import org.bukkit.entity.Player;
+import org.bukkit.Location;
+import org.bukkit.Server;
+import com.sk89q.worldedit.BlockVector;
+import com.sk89q.worldedit.Vector;
+
+public class BukkitUtil {
+ private BukkitUtil() {
+ }
+
+ public static BlockVector toVector(Block block) {
+ return new BlockVector(block.getX(), block.getY(), block.getZ());
+ }
+
+ public static Vector toVector(Location loc) {
+ return new Vector(loc.getX(), loc.getY(), loc.getZ());
+ }
+
+ public static Vector toVector(org.bukkit.util.Vector vector) {
+ return new Vector(vector.getX(), vector.getY(), vector.getZ());
+ }
+
+ public static Player matchSinglePlayer(Server server, String name) {
+ List players = server.matchPlayer(name);
+ if (players.size() == 0) {
+ return null;
+ }
+ return players.get(0);
+ }
+}
diff --git a/src/LoggerToChatHandler.java b/src/com/sk89q/worldguard/bukkit/LoggerToChatHandler.java
similarity index 85%
rename from src/LoggerToChatHandler.java
rename to src/com/sk89q/worldguard/bukkit/LoggerToChatHandler.java
index 38116dcf..ba9d299e 100644
--- a/src/LoggerToChatHandler.java
+++ b/src/com/sk89q/worldguard/bukkit/LoggerToChatHandler.java
@@ -1,3 +1,4 @@
+package com.sk89q.worldguard.bukkit;
// $Id$
/*
* WorldGuard
@@ -19,6 +20,8 @@
import java.util.logging.Handler;
import java.util.logging.LogRecord;
+import org.bukkit.ChatColor;
+import org.bukkit.entity.Player;
/**
* Sends all logger messages to a player.
@@ -56,7 +59,7 @@ public void flush() {
* Publish a log record.
*/
public void publish(LogRecord record) {
- player.sendMessage(Colors.LightGray + record.getLevel().getName() + ": "
- + Colors.White + record.getMessage());
+ player.sendMessage(ChatColor.GRAY + record.getLevel().getName() + ": "
+ + ChatColor.WHITE + record.getMessage());
}
}
diff --git a/src/com/sk89q/worldguard/bukkit/WorldGuardBlockListener.java b/src/com/sk89q/worldguard/bukkit/WorldGuardBlockListener.java
new file mode 100644
index 00000000..e178004c
--- /dev/null
+++ b/src/com/sk89q/worldguard/bukkit/WorldGuardBlockListener.java
@@ -0,0 +1,284 @@
+// $Id$
+/*
+ * WorldGuard
+ * Copyright (C) 2010 sk89q
+ *
+ * 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 .
+*/
+
+package com.sk89q.worldguard.bukkit;
+
+import java.util.Iterator;
+import java.util.List;
+import org.bukkit.block.Block;
+import org.bukkit.ChatColor;
+import org.bukkit.entity.Player;
+import org.bukkit.World;
+import org.bukkit.event.block.*;
+import org.bukkit.event.block.BlockIgniteEvent.IgniteCause;
+import com.sk89q.worldedit.Vector;
+import com.sk89q.worldguard.LocalPlayer;
+import com.sk89q.worldguard.protection.ApplicableRegionSet;
+import static com.sk89q.worldguard.bukkit.BukkitUtil.*;
+
+public class WorldGuardBlockListener extends BlockListener {
+ /**
+ * Plugin.
+ */
+ private WorldGuardPlugin plugin;
+
+ /**
+ * Construct the object;
+ *
+ * @param plugin
+ */
+ public WorldGuardBlockListener(WorldGuardPlugin plugin) {
+ this.plugin = plugin;
+ }
+
+ /**
+ * Called when a block is damaged (or broken)
+ *
+ * @param event Relevant event details
+ */
+ public void onBlockDamage(BlockDamageEvent event) {
+ Player player = event.getPlayer();
+
+ if (plugin.useRegions) {
+ Vector pt = BukkitUtil.toVector(event.getBlock());
+ LocalPlayer localPlayer = plugin.wrapPlayer(player);
+
+ if (!plugin.hasPermission(player, "/regionbypass")
+ && !plugin.regionManager.getApplicableRegions(pt).canBuild(localPlayer)) {
+ player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");
+ event.setCancelled(true);
+ return;
+ }
+ }
+ }
+
+ /**
+ * Called when a block flows (water/lava)
+ *
+ * @param event Relevant event details
+ */
+ public void onBlockFlow(BlockFromToEvent event) {
+ World world = event.getBlock().getWorld();
+ Block blockFrom = event.getFromBlock();
+ Block blockTo = event.getBlock();
+
+ boolean isWater = blockFrom.getTypeId() == 8 || blockFrom.getTypeId() == 9;
+ boolean isLava = blockFrom.getTypeId() == 10 || blockFrom.getTypeId() == 11;
+
+ if (plugin.simulateSponge && isWater) {
+ int ox = blockTo.getX();
+ int oy = blockTo.getY();
+ int oz = blockTo.getZ();
+
+ for (int cx = -plugin.spongeRadius; cx <= plugin.spongeRadius; cx++) {
+ for (int cy = -plugin.spongeRadius; cy <= plugin.spongeRadius; cy++) {
+ for (int cz = -plugin.spongeRadius; cz <= plugin.spongeRadius; cz++) {
+ if (world.getBlockTypeIdAt(ox + cx, oy + cy, oz + cz) == 19) {
+ event.setCancelled(true);
+ return;
+ }
+ }
+ }
+ }
+ }
+
+ if (plugin.classicWater && isWater) {
+ int blockBelow = world.getBlockTypeIdAt(blockFrom.getX(), blockFrom.getY() - 1, blockFrom.getZ());
+ if (blockBelow != 0 && blockBelow != 8 && blockBelow != 9) {
+ world.getBlockAt(blockFrom.getX(), blockFrom.getY(), blockFrom.getZ()).setTypeId(9);
+ event.setCancelled(true);
+ return;
+ }
+ }
+
+ if (plugin.allowedLavaSpreadOver != null && isLava) {
+ int targetId = world.getBlockTypeIdAt(
+ blockTo.getX(), blockTo.getY() - 1, blockTo.getZ());
+ if (!plugin.allowedLavaSpreadOver.contains(targetId)) {
+ event.setCancelled(true);
+ return;
+ }
+ }
+ }
+
+ /**
+ * Called when a block gets ignited
+ *
+ * @param event Relevant event details
+ */
+ public void onBlockIgnite(BlockIgniteEvent event) {
+ IgniteCause cause = event.getCause();
+ Block block = event.getBlock();
+ Player player = event.getPlayer();
+ World world = block.getWorld();
+ boolean isFireSpread = cause == IgniteCause.SLOW_SPREAD
+ || cause == IgniteCause.SPREAD;
+
+ if (plugin.preventLavaFire && cause == IgniteCause.LAVA) {
+ event.setCancelled(true);
+ return;
+ }
+
+ if (plugin.disableAllFire) {
+ event.setCancelled(true);
+ return;
+ }
+
+ if (plugin.blockLighter && cause == IgniteCause.FLINT_AND_STEEL) {
+ event.setCancelled(!plugin.hasPermission(player, "/uselighter")
+ && !plugin.hasPermission(player, "/lighter"));
+ return;
+ }
+
+ if (plugin.stopFireSpread && isFireSpread) {
+ event.setCancelled(true);
+ return;
+ }
+
+ if (plugin.fireNoSpreadBlocks.size() > 0 && isFireSpread) {
+ int x = block.getX();
+ int y = block.getY();
+ int z = block.getZ();
+
+ if (plugin.fireNoSpreadBlocks.contains(world.getBlockAt(x, y - 1, z))
+ || plugin.fireNoSpreadBlocks.contains(world.getBlockAt(x + 1, y, z))
+ || plugin.fireNoSpreadBlocks.contains(world.getBlockAt(x - 1, y, z))
+ || plugin.fireNoSpreadBlocks.contains(world.getBlockAt(x, y, z - 1))
+ || plugin.fireNoSpreadBlocks.contains(world.getBlockAt(x, y, z + 1))) {
+ event.setCancelled(true);
+ return;
+ }
+ }
+
+ if (plugin.useRegions && player != null && !plugin.hasPermission(player, "/regionbypass")) {
+ Vector pt = toVector(block);
+ LocalPlayer localPlayer = plugin.wrapPlayer(player);
+
+ if (cause == IgniteCause.FLINT_AND_STEEL
+ && !plugin.regionManager.getApplicableRegions(pt).canBuild(localPlayer)) {
+ event.setCancelled(true);
+ return;
+ }
+
+ if (cause == IgniteCause.FLINT_AND_STEEL
+ && !plugin.regionManager.getApplicableRegions(pt).allowsLighter()) {
+ event.setCancelled(true);
+ return;
+ }
+ }
+ }
+
+ /**
+ * Called when block physics occurs
+ *
+ * @param event Relevant event details
+ */
+ public void onBlockPhysics(BlockPhysicsEvent event) {
+ int id = event.getChangedTypeId();
+
+ if (id == 13 && plugin.noPhysicsGravel) {
+ event.setCancelled(true);
+ return;
+ }
+
+ if (id == 12 && plugin.noPhysicsSand) {
+ event.setCancelled(true);
+ return;
+ }
+
+ if (id == 90 && plugin.allowPortalAnywhere) {
+ event.setCancelled(true);
+ return;
+ }
+ }
+
+ /**
+ * Called when a player places a block
+ *
+ * @param event Relevant event details
+ */
+ public void onBlockPlace(BlockPlaceEvent event) {
+ Block blockPlaced = event.getBlock();
+ Player player = event.getPlayer();
+ World world = blockPlaced.getWorld();
+
+ if (plugin.useRegions) {
+ Vector pt = new Vector(blockPlaced.getX(),
+ blockPlaced.getY(), blockPlaced.getZ());
+ LocalPlayer localPlayer = plugin.wrapPlayer(player);
+
+ if (!plugin.hasPermission(player, "/regionbypass")
+ && !plugin.regionManager.getApplicableRegions(pt).canBuild(localPlayer)) {
+ player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");
+ event.setCancelled(true);
+ return;
+ }
+ }
+
+ if (plugin.simulateSponge && blockPlaced.getTypeId() == 19) {
+ int ox = blockPlaced.getX();
+ int oy = blockPlaced.getY();
+ int oz = blockPlaced.getZ();
+
+ for (int cx = -plugin.spongeRadius; cx <= plugin.spongeRadius; cx++) {
+ for (int cy = -plugin.spongeRadius; cy <= plugin.spongeRadius; cy++) {
+ for (int cz = -plugin.spongeRadius; cz <= plugin.spongeRadius; cz++) {
+ int id = world.getBlockTypeIdAt(ox + cx, oy + cy, oz + cz);
+ if (id == 8 || id == 9) {
+ world.getBlockAt(ox + cx, oy + cy, oz + cz)
+ .setTypeId(0);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Called when a player right clicks a block
+ *
+ * @param event Relevant event details
+ */
+ public void onBlockRightClick(BlockRightClickEvent event) {
+ Player player = event.getPlayer();
+
+ if (plugin.useRegions && event.getItemInHand().getTypeId() == plugin.regionWand) {
+ Vector pt = toVector(event.getBlock());
+ ApplicableRegionSet app = plugin.regionManager.getApplicableRegions(pt);
+ List regions = plugin.regionManager.getApplicableRegionsIDs(pt);
+
+ if (regions.size() > 0) {
+ player.sendMessage(ChatColor.YELLOW + "Can you build? "
+ + (app.canBuild(plugin.wrapPlayer(player)) ? "Yes" : "No"));
+
+ StringBuilder str = new StringBuilder();
+ for (Iterator it = regions.iterator(); it.hasNext(); ) {
+ str.append(it.next());
+ if (it.hasNext()) {
+ str.append(", ");
+ }
+ }
+
+ player.sendMessage(ChatColor.YELLOW + "Applicable regions: " + str.toString());
+ } else {
+ player.sendMessage(ChatColor.YELLOW + "WorldGuard: No defined regions here!");
+ }
+ }
+ }
+}
diff --git a/src/com/sk89q/worldguard/bukkit/WorldGuardEntityListener.java b/src/com/sk89q/worldguard/bukkit/WorldGuardEntityListener.java
new file mode 100644
index 00000000..a9293eac
--- /dev/null
+++ b/src/com/sk89q/worldguard/bukkit/WorldGuardEntityListener.java
@@ -0,0 +1,111 @@
+// $Id$
+/*
+ * WorldGuard
+ * Copyright (C) 2010 sk89q
+ *
+ * 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 .
+*/
+
+package com.sk89q.worldguard.bukkit;
+
+import org.bukkit.ChatColor;
+import org.bukkit.entity.Entity;
+import org.bukkit.entity.Player;
+import org.bukkit.event.entity.*;
+import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
+import com.sk89q.worldedit.Vector;
+import static com.sk89q.worldguard.bukkit.BukkitUtil.*;
+
+public class WorldGuardEntityListener extends EntityListener {
+ /**
+ * Plugin.
+ */
+ private WorldGuardPlugin plugin;
+
+ /**
+ * Construct the object;
+ *
+ * @param plugin
+ */
+ public WorldGuardEntityListener(WorldGuardPlugin plugin) {
+ this.plugin = plugin;
+ }
+
+ public void onEntityDamageByBlock(EntityDamageByBlockEvent event) {
+ Entity defender = event.getEntity();
+ DamageCause type = event.getCause();
+
+ if (defender instanceof Player) {
+ Player player = (Player)defender;
+
+ if (plugin.invinciblePlayers.contains(player.getName())) {
+ event.setCancelled(true);
+ return;
+ }
+
+ if (plugin.disableFallDamage && type == DamageCause.FALL) {
+ event.setCancelled(true);
+ return;
+ }
+
+ if (plugin.disableLavaDamage && type == DamageCause.LAVA) {
+ event.setCancelled(true);
+ return;
+ }
+
+ if (plugin.disableFireDamage && (type == DamageCause.FIRE
+ || type == DamageCause.FIRE_TICK)) {
+ event.setCancelled(true);
+ return;
+ }
+
+ if (plugin.disableWaterDamage && type == DamageCause.DROWNING) {
+ event.setCancelled(true);
+ return;
+ }
+
+ if (type == DamageCause.DROWNING
+ && plugin.amphibiousPlayers.contains(player.getName())) {
+ event.setCancelled(true);
+ return;
+ }
+ }
+ }
+
+ public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
+ Entity attacker = event.getDamager();
+ Entity defender = event.getEntity();
+
+ if (defender instanceof Player) {
+ Player player = (Player)defender;
+
+ if (plugin.invinciblePlayers.contains(player.getName())) {
+ event.setCancelled(true);
+ return;
+ }
+
+ if (attacker != null && attacker instanceof Player) {
+ if (plugin.useRegions) {
+ Vector pt = toVector(defender.getLocation());
+
+ if (!plugin.regionManager.getApplicableRegions(pt).allowsPvP()) {
+ player.sendMessage(ChatColor.DARK_RED + "You are in a no-PvP area.");
+ event.setCancelled(true);
+ return;
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/src/com/sk89q/worldguard/bukkit/WorldGuardPlayerListener.java b/src/com/sk89q/worldguard/bukkit/WorldGuardPlayerListener.java
new file mode 100644
index 00000000..ad8bb0a7
--- /dev/null
+++ b/src/com/sk89q/worldguard/bukkit/WorldGuardPlayerListener.java
@@ -0,0 +1,625 @@
+// $Id$
+/*
+ * WorldGuard
+ * Copyright (C) 2010 sk89q
+ *
+ * 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 .
+*/
+
+package com.sk89q.worldguard.bukkit;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import org.bukkit.*;
+import org.bukkit.block.Block;
+import org.bukkit.entity.Player;
+import org.bukkit.event.player.*;
+import org.bukkit.inventory.ItemStack;
+import org.bukkit.plugin.Plugin;
+import org.bukkit.plugin.java.JavaPluginLoader;
+import com.sk89q.worldedit.BlockVector;
+import com.sk89q.worldedit.blocks.ItemType;
+import com.sk89q.worldedit.bukkit.WorldEditAPI;
+import com.sk89q.worldedit.bukkit.WorldEditPlugin;
+import com.sk89q.worldedit.regions.Region;
+import com.sk89q.worldedit.IncompleteRegionException;
+import com.sk89q.worldedit.LocalSession;
+import com.sk89q.worldedit.Vector;
+import com.sk89q.worldedit.WorldEditNotInstalled;
+import com.sk89q.worldguard.*;
+import com.sk89q.worldguard.domains.*;
+import com.sk89q.worldguard.protection.*;
+import static com.sk89q.worldguard.bukkit.BukkitUtil.*;
+
+/**
+ * Handles all events thrown in relation to a Player
+ */
+public class WorldGuardPlayerListener extends PlayerListener {
+ /**
+ * Plugin.
+ */
+ private WorldGuardPlugin plugin;
+ /**
+ * Group pattern used to specify groups for the region command.
+ */
+ private static Pattern groupPattern = Pattern.compile("^[gG]:(.+)$");
+
+ private static int CMD_LIST_SIZE = 9;
+
+ /**
+ * Construct the object;
+ *
+ * @param plugin
+ */
+ public WorldGuardPlayerListener(WorldGuardPlugin plugin) {
+ this.plugin = plugin;
+ }
+
+ /**
+ * Called when a player joins a server
+ *
+ * @param event Relevant event details
+ */
+ public void onPlayerJoin(PlayerEvent event) {
+ Player player = event.getPlayer();
+
+ if (plugin.stopFireSpread) {
+ player.sendMessage(ChatColor.YELLOW
+ + "Fire spread is currently globally disabled.");
+ }
+
+ if (plugin.loginProtection > 0 || plugin.spawnProtection > 0
+ || plugin.kickOnDeath || plugin.teleportToHome || plugin.exactRespawn) {
+ plugin.recentLogins.put(player.getName(), System.currentTimeMillis());
+ }
+
+ if (plugin.inGroup(player, "wg-invincible")) {
+ plugin.invinciblePlayers.add(player.getName());
+ }
+
+ if (plugin.inGroup(player, "wg-amphibious")) {
+ plugin.amphibiousPlayers.add(player.getName());
+ }
+ }
+
+ /**
+ * Called when a player leaves a server
+ *
+ * @param event Relevant event details
+ */
+ public void onPlayerQuit(PlayerEvent event) {
+ Player player = event.getPlayer();
+ plugin.invinciblePlayers.remove(player.getName());
+ plugin.amphibiousPlayers.remove(player.getName());
+ plugin.recentLogins.remove(player.getName());
+ }
+
+ /**
+ * Called when a player uses an item
+ *
+ * @param event Relevant event details
+ */
+ public void onPlayerItem(PlayerItemEvent event) {
+ if (plugin.useRegions && event.isBlock()) {
+ Player player = event.getPlayer();
+ Block block = event.getBlockClicked();
+ Vector pt = toVector(block);
+ LocalPlayer localPlayer = plugin.wrapPlayer(player);
+
+ if (!plugin.hasPermission(player, "/regionbypass")
+ && !plugin.regionManager.getApplicableRegions(pt).canBuild(localPlayer)) {
+ player.sendMessage(ChatColor.DARK_RED
+ + "You don't have permission for this area.");
+ event.setCancelled(true);
+ return;
+ }
+ }
+ }
+
+ /**
+ * Called when a player attempts to log in to the server
+ *
+ * @param event Relevant event details
+ */
+ public void onPlayerLogin(PlayerLoginEvent event) {
+ Player player = event.getPlayer();
+
+ if (plugin.enforceOneSession) {
+ String name = player.getName();
+
+ for (Player pl : plugin.getServer().getOnlinePlayers()) {
+ if (pl.getName().equalsIgnoreCase(name)) {
+ pl.kickPlayer("Logged in from another location.");
+ }
+ }
+ }
+ }
+
+ /**
+ * Called when a player attempts to use a command
+ *
+ * @param event Relevant event details
+ */
+ public void onPlayerCommand(PlayerChatEvent event) {
+ if (handleCommand(event)) {
+ event.setCancelled(true);
+ }
+ }
+
+ /**
+ * Called when a player attempts to use a command
+ *
+ * @param event Relevant event details
+ */
+ public boolean handleCommand(PlayerChatEvent event) {
+ Player player = event.getPlayer();
+ String[] split = event.getMessage().split(" ");
+
+ if (split[0].equalsIgnoreCase("/stopfire") &&
+ plugin.hasPermission(player, "/stopfire")) {
+ if (!plugin.stopFireSpread) {
+ plugin.getServer().broadcastMessage(ChatColor.YELLOW
+ + "Fire spread has been globally disabled by " + player.getName() + ".");
+ } else {
+ player.sendMessage(ChatColor.YELLOW + "Fire spread was already globally disabled.");
+ }
+ } else if (split[0].equalsIgnoreCase("/allowfire")
+ && plugin.hasPermission(player, "/stopfire")) {
+ if (plugin.stopFireSpread) {
+ plugin.getServer().broadcastMessage(ChatColor.YELLOW
+ + "Fire spread has been globally re-enabled by " + player.getName() + ".");
+ } else {
+ player.sendMessage(ChatColor.YELLOW + "Fire spread was already globally enabled.");
+ }
+
+ plugin.stopFireSpread = false;
+ } else if (split[0].equalsIgnoreCase("/god")
+ && plugin.hasPermission(player, "/god")) {
+ // Allow setting other people invincible
+ if (split.length > 1) {
+ if (!plugin.hasPermission(player, "/godother")) {
+ player.sendMessage(ChatColor.RED + "You don't have permission to make others invincible.");
+ return true;
+ }
+
+ Player other = matchSinglePlayer(plugin.getServer(), split[1]);
+ if (other == null) {
+ player.sendMessage(ChatColor.RED + "Player not found.");
+ } else {
+ if (!plugin.invinciblePlayers.contains(other.getName())) {
+ plugin.invinciblePlayers.add(other.getName());
+ player.sendMessage(ChatColor.YELLOW + other.getName() + " is now invincible!");
+ other.sendMessage(ChatColor.YELLOW + player.getName() + " has made you invincible!");
+ } else {
+ plugin.invinciblePlayers.remove(other.getName());
+ player.sendMessage(ChatColor.YELLOW + other.getName() + " is no longer invincible.");
+ other.sendMessage(ChatColor.YELLOW + player.getName() + " has taken away your invincibility.");
+ }
+ }
+ // Invincibility for one's self
+ } else {
+ if (!plugin.invinciblePlayers.contains(player.getName())) {
+ plugin.invinciblePlayers.add(player.getName());
+ player.sendMessage(ChatColor.YELLOW + "You are now invincible!");
+ } else {
+ plugin.invinciblePlayers.remove(player.getName());
+ player.sendMessage(ChatColor.YELLOW + "You are no longer invincible.");
+ }
+ }
+ } else if ((split[0].equalsIgnoreCase("/stack")
+ || split[0].equalsIgnoreCase("/;"))
+ && plugin.hasPermission(player, "/stack")) {
+ ItemStack[] items = player.getInventory().getContents();
+ int len = items.length;
+
+ int affected = 0;
+
+ for (int i = 0; i < len; i++) {
+ ItemStack item = items[i];
+
+ // Avoid infinite stacks and stacks with durability
+ if (item == null || item.getAmount() <= 0
+ || ItemType.shouldNotStack(item.getTypeId())) {
+ continue;
+ }
+
+ // Ignore buckets
+ if (item.getTypeId() >= 325 && item.getTypeId() <= 327) {
+ continue;
+ }
+
+ 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++) {
+ ItemStack item2 = items[j];
+
+ // Avoid infinite stacks and stacks with durability
+ if (item2 == null || item2.getAmount() <= 0
+ || ItemType.shouldNotStack(item.getTypeId())) {
+ continue;
+ }
+
+ // Same type?
+ if (item2.getTypeId() == item.getTypeId()) {
+ // This stack won't fit in the parent stack
+ if (item2.getAmount() > needed) {
+ item.setAmount(64);
+ item2.setAmount(item2.getAmount() - needed);
+ break;
+ // This stack will
+ } else {
+ items[j] = null;
+ item.setAmount(item.getAmount() + item2.getAmount());
+ needed = 64 - item.getAmount();
+ }
+
+ affected++;
+ }
+ }
+ }
+ }
+
+ if (affected > 0) {
+ player.getInventory().setContents(items);
+ }
+
+ player.sendMessage(ChatColor.YELLOW + "Items compacted into stacks!");
+ } else if (split[0].equalsIgnoreCase("/rg")
+ || split[0].equalsIgnoreCase("/region")) {
+ if (split.length < 2) {
+ player.sendMessage(ChatColor.RED + "/rg ...");
+ return true;
+ }
+
+ String action = split[1];
+ String[] args = new String[split.length - 1];
+ System.arraycopy(split, 1, args, 0, split.length - 1);
+
+ handleRegionCommand(player, action, args);
+ } else {
+ return false;
+ }
+
+ return true;
+ }
+
+ /**
+ * Handles a region command.
+ *
+ * @param player
+ * @param action
+ * @param args
+ */
+ private void handleRegionCommand(Player player, String action, String[] args) {
+ if (action.equalsIgnoreCase("define")
+ && canUseRegionCommand(player, "/regiondefine")) {
+ if (args.length < 2) {
+ player.sendMessage(ChatColor.RED + "/rg define [owner1 [owner2 [owners...]]]");
+ return;
+ }
+
+ try {
+ String id = args[1].toLowerCase();
+ Plugin wePlugin = plugin.getServer().getPluginManager().getPlugin("WorldEdit");
+ if (plugin == null) {
+ player.sendMessage(ChatColor.RED + "WorldEdit must be installed and enabled as a plugin.");
+ return;
+ }
+
+ WorldEditPlugin worldEdit = (WorldEditPlugin)wePlugin;
+ WorldEditAPI api = worldEdit.getAPI();
+
+ LocalSession session = api.getSession(player);
+ Region weRegion = session.getRegion();
+
+ BlockVector min = weRegion.getMinimumPoint().toBlockVector();
+ BlockVector max = weRegion.getMaximumPoint().toBlockVector();
+
+ ProtectedRegion region = new ProtectedCuboidRegion(min, max);
+ if (args.length >= 3) {
+ region.setOwners(parseDomainString(args, 2));
+ }
+ plugin.regionManager.addRegion(id, region);
+ plugin.regionLoader.save(plugin.regionManager);
+ player.sendMessage(ChatColor.YELLOW + "Region saved as " + id + ".");
+ } catch (IncompleteRegionException e) {
+ player.sendMessage(ChatColor.RED + "You must first define an area in WorldEdit.");
+ } catch (IOException e) {
+ player.sendMessage(ChatColor.RED + "Region database failed to save: "
+ + e.getMessage());
+ }
+ } else if (action.equalsIgnoreCase("flag")
+ && canUseRegionCommand(player, "/regiondefine")) {
+ if (args.length < 4) {
+ player.sendMessage(ChatColor.RED + "/rg flag ");
+ return;
+ }
+
+ try {
+ String id = args[1].toLowerCase();
+ String flagStr = args[2];
+ String stateStr = args[3];
+ ProtectedRegion region = plugin.regionManager.getRegion(id);
+
+ if (region == null) {
+ player.sendMessage(ChatColor.RED + "Could not find a region by that ID.");
+ return;
+ }
+
+ AreaFlags.State state = null;
+
+ if (stateStr.equalsIgnoreCase("allow")) {
+ state = AreaFlags.State.ALLOW;
+ } else if (stateStr.equalsIgnoreCase("deny")) {
+ state = AreaFlags.State.DENY;
+ } else if (stateStr.equalsIgnoreCase("none")) {
+ state = AreaFlags.State.NONE;
+ } else {
+ player.sendMessage(ChatColor.RED + "Acceptable states: allow, deny, none");
+ return;
+ }
+
+ AreaFlags flags = region.getFlags();
+
+ if (flagStr.equalsIgnoreCase("build")) {
+ flags.allowBuild = state;
+ } else if (flagStr.equalsIgnoreCase("pvp")) {
+ flags.allowPvP = state;
+ } else if (flagStr.equalsIgnoreCase("tnt")) {
+ flags.allowTNT = state;
+ } else if (flagStr.equalsIgnoreCase("lighter")) {
+ flags.allowLighter = state;
+ } else {
+ player.sendMessage(ChatColor.RED + "Acceptable flags: build, pvp, tnt, lighter");
+ return;
+ }
+
+ plugin.regionLoader.save(plugin.regionManager);
+ player.sendMessage(ChatColor.YELLOW + "Region '" + id + "' updated.");
+ } catch (IOException e) {
+ player.sendMessage(ChatColor.RED + "Region database failed to save: "
+ + e.getMessage());
+ }
+ } else if (action.equalsIgnoreCase("info")
+ && canUseRegionCommand(player, "/regioninfo")) {
+ if (args.length < 2) {
+ player.sendMessage(ChatColor.RED + "/rg info ");
+ return;
+ }
+
+ String id = args[1].toLowerCase();
+ if (!plugin.regionManager.hasRegion(id)) {
+ player.sendMessage(ChatColor.RED + "A region with ID '"
+ + id + "' doesn't exist.");
+ return;
+ }
+
+ ProtectedRegion region = plugin.regionManager.getRegion(id);
+ AreaFlags flags = region.getFlags();
+ DefaultDomain domain = region.getOwners();
+
+ player.sendMessage(ChatColor.YELLOW + "Region ID: " + id);
+ player.sendMessage(ChatColor.GRAY + "Type: " + region.getClass().getCanonicalName());
+ player.sendMessage(ChatColor.BLUE + "Build: " + flags.allowBuild.name());
+ player.sendMessage(ChatColor.BLUE + "PvP: " + flags.allowPvP.name());
+ player.sendMessage(ChatColor.BLUE + "TNT: " + flags.allowTNT.name());
+ player.sendMessage(ChatColor.BLUE + "Lighter: " + flags.allowLighter.name());
+ player.sendMessage(ChatColor.LIGHT_PURPLE + "Players: " + domain.toPlayersString());
+ player.sendMessage(ChatColor.LIGHT_PURPLE + "Groups: " + domain.toGroupsString());
+ } else if (action.equalsIgnoreCase("add")
+ && canUseRegionCommand(player, "/regiondefine")) {
+ if (args.length < 2) {
+ player.sendMessage(ChatColor.RED + "/rg add ");
+ return;
+ }
+
+ try {
+ String id = args[1].toLowerCase();
+ if (!plugin.regionManager.hasRegion(id)) {
+ player.sendMessage(ChatColor.RED + "A region with ID '"
+ + id + "' doesn't exist.");
+ return;
+ }
+
+ addToDomain(plugin.regionManager.getRegion(id).getOwners(), args, 1);
+
+ plugin.regionLoader.save(plugin.regionManager);
+ player.sendMessage(ChatColor.YELLOW + "Region updated!");
+ } catch (IOException e) {
+ player.sendMessage(ChatColor.RED + "Region database failed to save: "
+ + e.getMessage());
+ }
+ } else if (action.equalsIgnoreCase("remove")
+ && canUseRegionCommand(player, "/regiondefine")) {
+ if (args.length < 2) {
+ player.sendMessage(ChatColor.RED + "/rg remove ");
+ return;
+ }
+
+ try {
+ String id = args[1].toLowerCase();
+ if (!plugin.regionManager.hasRegion(id)) {
+ player.sendMessage(ChatColor.RED + "A region with ID '"
+ + id + "' doesn't exist.");
+ return;
+ }
+
+ removeFromDomain(plugin.regionManager.getRegion(id).getOwners(), args, 1);
+
+ plugin.regionLoader.save(plugin.regionManager);
+ player.sendMessage(ChatColor.YELLOW + "Region updated!");
+ } catch (IOException e) {
+ player.sendMessage(ChatColor.RED + "Region database failed to save: "
+ + e.getMessage());
+ }
+ } else if (action.equalsIgnoreCase("list")
+ && canUseRegionCommand(player, "/regionlist")) {
+ int page = 0;
+
+ if (args.length >= 2) {
+ try {
+ page = Math.max(0, Integer.parseInt(args[1]) - 1);
+ } catch (NumberFormatException e) {
+ page = 0;
+ }
+ }
+
+ Map regions = plugin.regionManager.getRegions();
+ int size = regions.size();
+ int pages = (int)Math.ceil(size / (float)CMD_LIST_SIZE);
+
+ String[] regionIDList = new String[size];
+ int index = 0;
+ for (String id : regions.keySet()) {
+ regionIDList[index] = id;
+ index++;
+ }
+ Arrays.sort(regionIDList);
+
+
+ player.sendMessage(ChatColor.RED + "Regions (page "
+ + (page + 1) + " of " + pages + "):");
+
+ if (page < pages) {
+ for (int i = page * CMD_LIST_SIZE; i < page * CMD_LIST_SIZE + CMD_LIST_SIZE; i++) {
+ if (i >= size) break;
+ player.sendMessage(ChatColor.YELLOW.toString() + (i + 1) + ". " + regionIDList[i]);
+ }
+ }
+ } else if (action.equalsIgnoreCase("delete")
+ && canUseRegionCommand(player, "/regiondelete")) {
+ if (args.length < 2) {
+ player.sendMessage(ChatColor.RED + "/rg delete ");
+ return;
+ }
+
+ try {
+ String id = args[1].toLowerCase();
+ if (!plugin.regionManager.hasRegion(id)) {
+ player.sendMessage(ChatColor.RED + "A region with ID '"
+ + id + "' doesn't exist.");
+ return;
+ }
+ plugin.regionManager.removeRegion(id);
+ plugin.regionLoader.save(plugin.regionManager);
+ player.sendMessage(ChatColor.YELLOW + "Region removed!");
+ } catch (IOException e) {
+ player.sendMessage(ChatColor.RED + "Region database failed to save: "
+ + e.getMessage());
+ }
+ } else if (action.equalsIgnoreCase("save")
+ && canUseRegionCommand(player, "/regionsave")) {
+ try {
+ plugin.regionLoader.save(plugin.regionManager);
+ player.sendMessage(ChatColor.YELLOW + "Region database saved to file!");
+ } catch (IOException e) {
+ player.sendMessage(ChatColor.RED + "Region database failed to save: "
+ + e.getMessage());
+ }
+ } else if (action.equalsIgnoreCase("load")
+ && canUseRegionCommand(player, "/regionload")) {
+ try {
+ plugin.regionLoader.load(plugin.regionManager);
+ player.sendMessage(ChatColor.YELLOW + "Region database loaded from file!");
+ } catch (IOException e) {
+ player.sendMessage(ChatColor.RED + "Region database failed to load: "
+ + e.getMessage());
+ }
+ } else {
+ player.sendMessage(ChatColor.RED + "/rg ...");
+ }
+ }
+
+ /**
+ * Checks for the command or /region.
+ *
+ * @param player
+ * @param cmd
+ * @return
+ */
+ private boolean canUseRegionCommand(Player player, String cmd) {
+ return plugin.hasPermission(player, "/region")
+ || plugin.hasPermission(player, cmd);
+ }
+
+ /**
+ * Parse a group/player DefaultDomain specification for areas.
+ *
+ * @param domain
+ * @param split
+ * @param startIndex
+ */
+ private static void addToDomain(DefaultDomain domain,
+ String[] split, int startIndex) {
+ for (int i = startIndex; i < split.length; i++) {
+ String s = split[i];
+ Matcher m = groupPattern.matcher(s);
+ if (m.matches()) {
+ domain.addGroup(m.group(1));
+ } else {
+ domain.addPlayer(s);
+ }
+ }
+ }
+
+ /**
+ * Parse a group/player DefaultDomain specification for areas.
+ *
+ * @param domain
+ * @param split
+ * @param startIndex
+ */
+ private static void removeFromDomain(DefaultDomain domain,
+ String[] split, int startIndex) {
+ for (int i = startIndex; i < split.length; i++) {
+ String s = split[i];
+ Matcher m = groupPattern.matcher(s);
+ if (m.matches()) {
+ domain.removeGroup(m.group(1));
+ } else {
+ domain.removePlayer(s);
+ }
+ }
+ }
+
+ /**
+ * Parse a group/player DefaultDomain specification for areas.
+ *
+ * @param split
+ * @param startIndex
+ * @return
+ */
+ private static DefaultDomain parseDomainString(String[] split, int startIndex) {
+ DefaultDomain domain = new DefaultDomain();
+
+ for (int i = startIndex; i < split.length; i++) {
+ String s = split[i];
+ Matcher m = groupPattern.matcher(s);
+ if (m.matches()) {
+ domain.addGroup(m.group(1));
+ } else {
+ domain.addPlayer(s);
+ }
+ }
+
+ return domain;
+ }
+}
diff --git a/src/com/sk89q/worldguard/bukkit/WorldGuardPlugin.java b/src/com/sk89q/worldguard/bukkit/WorldGuardPlugin.java
new file mode 100644
index 00000000..055b0771
--- /dev/null
+++ b/src/com/sk89q/worldguard/bukkit/WorldGuardPlugin.java
@@ -0,0 +1,280 @@
+// $Id$
+/*
+ * WorldGuard
+ * Copyright (C) 2010 sk89q
+ *
+ * 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 .
+*/
+
+package com.sk89q.worldguard.bukkit;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import java.util.regex.Pattern;
+import org.bukkit.entity.Player;
+import org.bukkit.Server;
+import org.bukkit.event.Event.Priority;
+import org.bukkit.event.Event;
+import org.bukkit.plugin.PluginDescriptionFile;
+import org.bukkit.plugin.PluginLoader;
+import org.bukkit.plugin.java.JavaPlugin;
+import org.bukkit.util.config.Configuration;
+import com.sk89q.worldguard.protection.CSVDatabase;
+import com.sk89q.worldguard.protection.FlatRegionManager;
+import com.sk89q.worldguard.protection.ProtectionDatabase;
+import com.sk89q.worldguard.protection.RegionManager;
+
+/**
+ * Plugin for Bukkit.
+ *
+ * @author sk89qs
+ */
+public class WorldGuardPlugin extends JavaPlugin {
+ private static final Logger logger = Logger.getLogger("Minecraft.WorldGuard");
+
+ private final WorldGuardPlayerListener playerListener =
+ new WorldGuardPlayerListener(this);
+ private final WorldGuardBlockListener blockListener =
+ new WorldGuardBlockListener(this);
+ private final WorldGuardEntityListener entityListener =
+ new WorldGuardEntityListener(this);
+
+ RegionManager regionManager = new FlatRegionManager();
+ ProtectionDatabase regionLoader =
+ new CSVDatabase(new File("worldguard-regions.txt"));
+
+ Set invinciblePlayers = new HashSet();
+ Set amphibiousPlayers = new HashSet();
+ Map recentLogins = new HashMap();
+ Map lastSpawn = new HashMap();
+
+ boolean stopFireSpread = false;
+
+ boolean useRegions = false;
+ boolean enforceOneSession;
+ boolean blockCreepers;
+ boolean blockTNT;
+ boolean blockLighter;
+ boolean preventLavaFire;
+ boolean disableAllFire;
+ boolean simulateSponge;
+ int spongeRadius;
+ Set fireNoSpreadBlocks;
+ Set allowedLavaSpreadOver;
+ Set itemDropBlacklist;
+ Set preventWaterDamage;
+ boolean classicWater;
+ boolean noPhysicsGravel;
+ boolean noPhysicsSand;
+ boolean allowPortalAnywhere;
+ boolean disableFallDamage;
+ boolean disableLavaDamage;
+ boolean disableFireDamage;
+ boolean disableWaterDamage;
+ boolean disableSuffocationDamage;
+ boolean teleportOnSuffocation;
+ int loginProtection;
+ int spawnProtection;
+ boolean teleportToHome;
+ boolean exactRespawn;
+ boolean kickOnDeath;
+ int regionWand = 287;
+
+ public WorldGuardPlugin(PluginLoader pluginLoader, Server instance,
+ PluginDescriptionFile desc, File folder, File plugin, ClassLoader cLoader) {
+ super(pluginLoader, instance, desc, folder, plugin, cLoader);
+
+ logger.info("WorldGuard " + desc.getVersion() + " loaded.");
+ loadConfiguration();
+ registerEvents();
+ }
+
+ public void onEnable() {
+ //loadConfiguration();
+ }
+
+ public void onDisable() {
+ }
+
+ private void registerEvents() {
+ getServer().getPluginManager().registerEvent(Event.Type.PLAYER_QUIT,
+ playerListener, Priority.Normal, this);
+ getServer().getPluginManager().registerEvent(Event.Type.PLAYER_COMMAND,
+ playerListener, Priority.Normal, this);
+ getServer().getPluginManager().registerEvent(Event.Type.BLOCK_DAMAGED,
+ blockListener, Priority.Normal, this);
+ getServer().getPluginManager().registerEvent(Event.Type.BLOCK_RIGHTCLICKED,
+ blockListener, Priority.Normal, this);
+ }
+
+ /**
+ * Load the configuration
+ */
+ public void loadConfiguration() {
+ Configuration config = getConfiguration();
+
+ try {
+ regionLoader.load();
+ regionManager.setRegions(regionLoader.getRegions());
+ } catch (IOException e) {
+ logger.warning("WorldGuard: Failed to load regions: "
+ + e.getMessage());
+ }
+
+ recentLogins.clear();
+
+ // Load basic options
+ enforceOneSession = config.getBoolean("protection.enforce-single-session", true);
+
+ blockCreepers = config.getBoolean("mobs.block-creeper-explosions", false);
+
+ blockTNT = config.getBoolean("ignition.block-tnt", false);
+ blockLighter = config.getBoolean("ignition.block-lighter", false);
+
+ preventLavaFire = config.getBoolean("fire.disable-lava-fire-spread", true);
+ disableAllFire = config.getBoolean("fire.disable-fire-spread", false);
+ preventWaterDamage = new HashSet(config.getIntList("physics.disable-water-damage-blocks", null));
+ itemDropBlacklist = new HashSet(config.getIntList("protection.item-drop-blacklist", null));
+ fireNoSpreadBlocks = new HashSet(config.getIntList("fire.disable-fire-spread", null));
+ allowedLavaSpreadOver = new HashSet(config.getIntList("fire.lava-spread-blocks", null));
+
+ classicWater = config.getBoolean("simulation.classic-water", false);
+ simulateSponge = config.getBoolean("simulation.sponge.enable", true);
+ spongeRadius = Math.max(1, config.getInt("simulation.sponge.radius", 3)) - 1;
+
+ noPhysicsGravel = config.getBoolean("physics.no-physics-gravel", false);
+ noPhysicsSand = config.getBoolean("physics.no-physics-sand", false);
+ allowPortalAnywhere = config.getBoolean("physics.allow-portal-anywhere", false);
+
+ disableFallDamage = config.getBoolean("player-damage.disable-fall-damage", false);
+ disableLavaDamage = config.getBoolean("player-damage.disable-lava-damage", false);
+ disableFireDamage = config.getBoolean("player-damage.disable-fire-damage", false);
+ disableWaterDamage = config.getBoolean("player-damage.disable-water-damage", false);
+ disableSuffocationDamage = config.getBoolean("player-damage.disable-suffocation-damage", false);
+ teleportOnSuffocation = config.getBoolean("player-damage.teleport-on-suffocation", false);
+
+ loginProtection = config.getInt("spawn.login-protection", 3);
+ spawnProtection = config.getInt("spawn.spawn-protection", 0);
+ kickOnDeath = config.getBoolean("spawn.kick-on-death", false);
+ teleportToHome = config.getBoolean("spawn.teleport-to-home-on-death", false);
+ exactRespawn = config.getBoolean("spawn.exact-respawn", false);
+
+ useRegions = config.getBoolean("regions.enable", true);
+ regionWand = config.getInt("regions.wand", 287);
+
+ /*
+ // Console log configuration
+ boolean logConsole = properties.getBoolean("log-console", true);
+
+ // Database log configuration
+ boolean logDatabase = properties.getBoolean("log-database", false);
+ String dsn = properties.getString("log-database-dsn", "jdbc:mysql://localhost:3306/minecraft");
+ String user = properties.getString("log-database-user", "root");
+ String pass = properties.getString("log-database-pass", "");
+ String table = properties.getString("log-database-table", "blacklist_events");
+
+ // File log configuration
+ boolean logFile = properties.getBoolean("log-file", false);
+ String logFilePattern = properties.getString("log-file-path", "worldguard/logs/%Y-%m-%d.log");
+ int logFileCacheSize = Math.max(1, properties.getInt("log-file-open-files", 10));
+
+ // Load the blacklist
+ try {
+ // If there was an existing blacklist, close loggers
+ if (blacklist != null) {
+ blacklist.getLogger().close();
+ }
+
+ // First load the blacklist data from 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 (blist.isEmpty()) {
+ this.blacklist = null;
+ } else {
+ this.blacklist = blist;
+ logger.log(Level.INFO, "WorldGuard: Blacklist loaded.");
+
+ BlacklistLogger blacklistLogger = blist.getLogger();
+
+ if (logDatabase) {
+ blacklistLogger.addHandler(new DatabaseLoggerHandler(dsn, user, pass, table));
+ }
+
+ if (logConsole) {
+ blacklistLogger.addHandler(new ConsoleLoggerHandler());
+ }
+
+ if (logFile) {
+ FileLoggerHandler handler =
+ new FileLoggerHandler(logFilePattern, logFileCacheSize);
+ blacklistLogger.addHandler(handler);
+ }
+ }
+ } catch (FileNotFoundException e) {
+ logger.log(Level.WARNING, "WorldGuard blacklist does not exist.");
+ } catch (IOException e) {
+ logger.log(Level.WARNING, "Could not load WorldGuard blacklist: "
+ + e.getMessage());
+ }*/
+
+ // Print an overview of settings
+ if (config.getBoolean("summary-on-start", true)) {
+ logger.log(Level.INFO, enforceOneSession ? "WorldGuard: Single session is enforced."
+ : "WorldGuard: Single session is NOT ENFORCED.");
+ logger.log(Level.INFO, blockTNT ? "WorldGuard: TNT ignition is blocked."
+ : "WorldGuard: TNT ignition is PERMITTED.");
+ logger.log(Level.INFO, blockLighter ? "WorldGuard: Lighters are blocked."
+ : "WorldGuard: Lighters are PERMITTED.");
+ logger.log(Level.INFO, preventLavaFire ? "WorldGuard: Lava fire is blocked."
+ : "WorldGuard: Lava fire is PERMITTED.");
+ if (disableAllFire) {
+ logger.log(Level.INFO, "WorldGuard: All fire spread is disabled.");
+ } else {
+ if (fireNoSpreadBlocks != null) {
+ logger.log(Level.INFO, "WorldGuard: Fire spread is limited to "
+ + fireNoSpreadBlocks.size() + " block types.");
+ } else {
+ logger.log(Level.INFO, "WorldGuard: Fire spread is UNRESTRICTED.");
+ }
+ }
+ }
+ }
+
+ boolean inGroup(Player player, String group) {
+ return true;
+ }
+
+ boolean hasPermission(Player player, String hasPermission) {
+ return true;
+ }
+
+ List getGroups(Player player) {
+ return new ArrayList();
+ }
+
+ BukkitPlayer wrapPlayer(Player player) {
+ return new BukkitPlayer(this, player);
+ }
+}