Trailing whitespace removal

This commit is contained in:
Wizjany 2011-09-27 06:13:19 -04:00
parent fb535e620c
commit 94c794de6f
32 changed files with 467 additions and 467 deletions

View File

@ -45,7 +45,7 @@ public abstract class Blacklist {
* Logger. * Logger.
*/ */
private static final Logger logger = Logger.getLogger("Minecraft.WorldGuard"); private static final Logger logger = Logger.getLogger("Minecraft.WorldGuard");
/** /**
* List of entries by block ID. * List of entries by block ID.
*/ */
@ -73,7 +73,7 @@ public Blacklist(Boolean useAsWhitelist) {
/** /**
* Returns whether the list is empty. * Returns whether the list is empty.
* *
* @return * @return
*/ */
public boolean isEmpty() { public boolean isEmpty() {
@ -82,35 +82,35 @@ public boolean isEmpty() {
/** /**
* Get the entries for an item or list. * Get the entries for an item or list.
* *
* @param id * @param id
* @return * @return
*/ */
public List<BlacklistEntry> getEntries(int id) { public List<BlacklistEntry> getEntries(int id) {
return blacklist.get(id); return blacklist.get(id);
} }
/** /**
* Get the number of individual items that have blacklist entries. * Get the number of individual items that have blacklist entries.
* *
* @return * @return
*/ */
public int getItemCount() { public int getItemCount() {
return blacklist.size(); return blacklist.size();
} }
/** /**
* Returns whether the blacklist is used as a whitelist. * Returns whether the blacklist is used as a whitelist.
* *
* @return * @return
*/ */
public boolean isWhitelist() { public boolean isWhitelist() {
return useAsWhitelist; return useAsWhitelist;
} }
/** /**
* Get the logger. * Get the logger.
* *
* @return * @return
*/ */
public BlacklistLogger getLogger() { public BlacklistLogger getLogger() {
@ -119,7 +119,7 @@ public BlacklistLogger getLogger() {
/** /**
* Method to handle the event. * Method to handle the event.
* *
* @param event * @param event
* @param forceRepeat * @param forceRepeat
* @param silent * @param silent
@ -253,36 +253,36 @@ public void load(File file) throws IOException {
} }
} }
} }
/** /**
* Get the last event. * Get the last event.
* *
* @return * @return
*/ */
public BlacklistEvent getLastEvent() { public BlacklistEvent getLastEvent() {
return lastEvent; return lastEvent;
} }
/** /**
* Notify administrators. * Notify administrators.
* *
* @param event * @param event
* @param comment * @param comment
*/ */
public void notify(BlacklistEvent event, String comment) { public void notify(BlacklistEvent event, String comment) {
lastEvent = event; lastEvent = event;
broadcastNotification(ChatColor.GRAY + "WG: " broadcastNotification(ChatColor.GRAY + "WG: "
+ ChatColor.LIGHT_PURPLE + event.getPlayer().getName() + ChatColor.LIGHT_PURPLE + event.getPlayer().getName()
+ ChatColor.GOLD + " (" + event.getDescription() + ") " + ChatColor.GOLD + " (" + event.getDescription() + ") "
+ ChatColor.WHITE + ChatColor.WHITE
+ getFriendlyItemName(event.getType()) + getFriendlyItemName(event.getType())
+ (comment != null ? " (" + comment + ")" : "") + "."); + (comment != null ? " (" + comment + ")" : "") + ".");
} }
/** /**
* Sends a notification to all subscribing users. * Sends a notification to all subscribing users.
* *
* @param msg * @param msg
*/ */
public abstract void broadcastNotification(String msg); public abstract void broadcastNotification(String msg);
@ -305,7 +305,7 @@ public void forgetAllPlayers() {
/** /**
* Get an item's ID from its name. * Get an item's ID from its name.
* *
* @param name * @param name
*/ */
private static int getItemID(String name) { private static int getItemID(String name) {
@ -319,7 +319,7 @@ private static int getItemID(String name) {
/** /**
* Get an item's friendly name with its ID. * Get an item's friendly name with its ID.
* *
* @param id * @param id
*/ */
private static String getFriendlyItemName(int id) { private static String getFriendlyItemName(int id) {

View File

@ -54,7 +54,7 @@ public class BlacklistEntry {
* List of permissions to not affect. * List of permissions to not affect.
*/ */
private Set<String> ignorePermissions; private Set<String> ignorePermissions;
private String[] breakActions; private String[] breakActions;
private String[] destroyWithActions; private String[] destroyWithActions;
private String[] placeActions; private String[] placeActions;
@ -62,13 +62,13 @@ public class BlacklistEntry {
private String[] useActions; private String[] useActions;
private String[] dropActions; private String[] dropActions;
private String[] acquireActions; private String[] acquireActions;
private String message; private String message;
private String comment; private String comment;
/** /**
* Construct the object. * Construct the object.
* *
* @param blacklist * @param blacklist
*/ */
public BlacklistEntry(Blacklist blacklist) { public BlacklistEntry(Blacklist blacklist) {
@ -262,35 +262,35 @@ public boolean shouldIgnore(LocalPlayer player) {
return false; return false;
} }
/** /**
* Get the associated actions with an event. * Get the associated actions with an event.
* *
* @param event * @param event
* @return * @return
*/ */
private String[] getActions(BlacklistEvent event) { private String[] getActions(BlacklistEvent event) {
if (event instanceof BlockBreakBlacklistEvent) { if (event instanceof BlockBreakBlacklistEvent) {
return breakActions; return breakActions;
} else if (event instanceof BlockPlaceBlacklistEvent) { } else if (event instanceof BlockPlaceBlacklistEvent) {
return placeActions; return placeActions;
} else if (event instanceof BlockInteractBlacklistEvent) { } else if (event instanceof BlockInteractBlacklistEvent) {
return interactActions; return interactActions;
} else if (event instanceof DestroyWithBlacklistEvent) { } else if (event instanceof DestroyWithBlacklistEvent) {
return destroyWithActions; return destroyWithActions;
} else if (event instanceof ItemAcquireBlacklistEvent) { } else if (event instanceof ItemAcquireBlacklistEvent) {
return acquireActions; return acquireActions;
} else if (event instanceof ItemDropBlacklistEvent) { } else if (event instanceof ItemDropBlacklistEvent) {
return dropActions; return dropActions;
} else if (event instanceof ItemUseBlacklistEvent) { } else if (event instanceof ItemUseBlacklistEvent) {
return useActions; return useActions;
} else { } else {
return null; return null;
} }
@ -298,8 +298,8 @@ private String[] getActions(BlacklistEvent event) {
/** /**
* Method to handle the event. * Method to handle the event.
* *
* @param useAsWhitelist * @param useAsWhitelist
* @param event * @param event
* @param forceRepeat * @param forceRepeat
* @param silent * @param silent
@ -307,7 +307,7 @@ private String[] getActions(BlacklistEvent event) {
*/ */
public boolean check(boolean useAsWhitelist, BlacklistEvent event, boolean forceRepeat, boolean silent) { public boolean check(boolean useAsWhitelist, BlacklistEvent event, boolean forceRepeat, boolean silent) {
LocalPlayer player = event.getPlayer(); LocalPlayer player = event.getPlayer();
if (shouldIgnore(player)) { if (shouldIgnore(player)) {
return true; return true;
} }
@ -328,21 +328,21 @@ public boolean check(boolean useAsWhitelist, BlacklistEvent event, boolean force
String actions[] = getActions(event); String actions[] = getActions(event);
boolean ret = useAsWhitelist ? false : true; boolean ret = useAsWhitelist ? false : true;
// Nothing to do // Nothing to do
if (actions == null) { if (actions == null) {
return useAsWhitelist ? false : true; return useAsWhitelist ? false : true;
} }
for (String action : actions) { for (String action : actions) {
// Deny // Deny
if (action.equalsIgnoreCase("deny")) { if (action.equalsIgnoreCase("deny")) {
if (silent) { if (silent) {
return false; return false;
} }
ret = false; ret = false;
// Allow // Allow
@ -358,7 +358,7 @@ public boolean check(boolean useAsWhitelist, BlacklistEvent event, boolean force
if (silent) { if (silent) {
continue; continue;
} }
if (this.message != null) { if (this.message != null) {
player.kick(String.format(this.message, player.kick(String.format(this.message,
getFriendlyItemName(event.getType()))); getFriendlyItemName(event.getType())));
@ -372,7 +372,7 @@ public boolean check(boolean useAsWhitelist, BlacklistEvent event, boolean force
if (silent) { if (silent) {
continue; continue;
} }
if (this.message != null) { if (this.message != null) {
player.ban("Banned: " + String.format(this.message, player.ban("Banned: " + String.format(this.message,
getFriendlyItemName(event.getType()))); getFriendlyItemName(event.getType())));
@ -381,12 +381,12 @@ public boolean check(boolean useAsWhitelist, BlacklistEvent event, boolean force
+ event.getDescription() + " " + event.getDescription() + " "
+ getFriendlyItemName(event.getType())); + getFriendlyItemName(event.getType()));
} }
} else if (!silent && (!repeating || forceRepeat)) { } else if (!silent && (!repeating || forceRepeat)) {
// Notify // Notify
if (action.equalsIgnoreCase("notify")) { if (action.equalsIgnoreCase("notify")) {
blacklist.notify(event, comment); blacklist.notify(event, comment);
// Log // Log
} else if (action.equalsIgnoreCase("log")) { } else if (action.equalsIgnoreCase("log")) {
blacklist.getLogger().logEvent(event, comment); blacklist.getLogger().logEvent(event, comment);
@ -411,7 +411,7 @@ public boolean check(boolean useAsWhitelist, BlacklistEvent event, boolean force
/** /**
* Get an item's friendly name with its ID. * Get an item's friendly name with its ID.
* *
* @param id * @param id
*/ */
private static String getFriendlyItemName(int id) { private static String getFriendlyItemName(int id) {

View File

@ -60,7 +60,7 @@ public void removeHandler(BlacklistLoggerHandler handler) {
public void clearHandlers() { public void clearHandlers() {
handlers.clear(); handlers.clear();
} }
/** /**
* Log an event. * Log an event.
* *

View File

@ -31,8 +31,8 @@ public class BlacklistTrackedEvent {
/** /**
* Construct the object. * Construct the object.
* *
* @param event * @param event
* @param time * @param time
*/ */
public BlacklistTrackedEvent(BlacklistEvent event, long time) { public BlacklistTrackedEvent(BlacklistEvent event, long time) {

View File

@ -34,7 +34,7 @@ public interface BlacklistLoggerHandler {
* @param comment * @param comment
*/ */
public void logEvent(BlacklistEvent event, String comment); public void logEvent(BlacklistEvent event, String comment);
/** /**
* Close the logger. * Close the logger.
*/ */

View File

@ -41,13 +41,13 @@ public class ConsoleLoggerHandler implements BlacklistLoggerHandler {
* Logger. * Logger.
*/ */
private static final Logger logger = Logger.getLogger("Minecraft.WorldGuard"); private static final Logger logger = Logger.getLogger("Minecraft.WorldGuard");
private String worldName; private String worldName;
public ConsoleLoggerHandler(String worldName) public ConsoleLoggerHandler(String worldName)
{ {
this.worldName = worldName; this.worldName = worldName;
} }
/** /**
@ -62,49 +62,49 @@ public void logEvent(BlacklistEvent event, String comment) {
logger.log(Level.INFO, "WorldGuard: [" + worldName + "] " + event.getPlayer().getName() logger.log(Level.INFO, "WorldGuard: [" + worldName + "] " + event.getPlayer().getName()
+ " tried to break " + getFriendlyItemName(evt.getType()) + " tried to break " + getFriendlyItemName(evt.getType())
+ (comment != null ? " (" + comment + ")" : "")); + (comment != null ? " (" + comment + ")" : ""));
// Block place // Block place
} else if (event instanceof BlockPlaceBlacklistEvent) { } else if (event instanceof BlockPlaceBlacklistEvent) {
BlockPlaceBlacklistEvent evt = (BlockPlaceBlacklistEvent)event; BlockPlaceBlacklistEvent evt = (BlockPlaceBlacklistEvent)event;
logger.log(Level.INFO, "WorldGuard: [" + worldName + "] " + event.getPlayer().getName() logger.log(Level.INFO, "WorldGuard: [" + worldName + "] " + event.getPlayer().getName()
+ " tried to place " + getFriendlyItemName(evt.getType()) + " tried to place " + getFriendlyItemName(evt.getType())
+ (comment != null ? " (" + comment + ")" : "")); + (comment != null ? " (" + comment + ")" : ""));
// Block interact // Block interact
} else if (event instanceof BlockInteractBlacklistEvent) { } else if (event instanceof BlockInteractBlacklistEvent) {
BlockInteractBlacklistEvent evt = (BlockInteractBlacklistEvent)event; BlockInteractBlacklistEvent evt = (BlockInteractBlacklistEvent)event;
logger.log(Level.INFO, "WorldGuard: [" + worldName + "] " + event.getPlayer().getName() logger.log(Level.INFO, "WorldGuard: [" + worldName + "] " + event.getPlayer().getName()
+ " tried to interact with " + getFriendlyItemName(evt.getType()) + " tried to interact with " + getFriendlyItemName(evt.getType())
+ (comment != null ? " (" + comment + ")" : "")); + (comment != null ? " (" + comment + ")" : ""));
// Destroy with // Destroy with
} else if (event instanceof DestroyWithBlacklistEvent) { } else if (event instanceof DestroyWithBlacklistEvent) {
DestroyWithBlacklistEvent evt = (DestroyWithBlacklistEvent)event; DestroyWithBlacklistEvent evt = (DestroyWithBlacklistEvent)event;
logger.log(Level.INFO, "WorldGuard: [" + worldName + "] " + event.getPlayer().getName() logger.log(Level.INFO, "WorldGuard: [" + worldName + "] " + event.getPlayer().getName()
+ " tried to destroy with " + getFriendlyItemName(evt.getType()) + " tried to destroy with " + getFriendlyItemName(evt.getType())
+ (comment != null ? " (" + comment + ")" : "")); + (comment != null ? " (" + comment + ")" : ""));
// Acquire // Acquire
} else if (event instanceof ItemAcquireBlacklistEvent) { } else if (event instanceof ItemAcquireBlacklistEvent) {
ItemAcquireBlacklistEvent evt = (ItemAcquireBlacklistEvent)event; ItemAcquireBlacklistEvent evt = (ItemAcquireBlacklistEvent)event;
logger.log(Level.INFO, "WorldGuard: [" + worldName + "] " + event.getPlayer().getName() logger.log(Level.INFO, "WorldGuard: [" + worldName + "] " + event.getPlayer().getName()
+ " tried to acquire " + getFriendlyItemName(evt.getType()) + " tried to acquire " + getFriendlyItemName(evt.getType())
+ (comment != null ? " (" + comment + ")" : "")); + (comment != null ? " (" + comment + ")" : ""));
// Drop // Drop
} else if (event instanceof ItemDropBlacklistEvent) { } else if (event instanceof ItemDropBlacklistEvent) {
ItemDropBlacklistEvent evt = (ItemDropBlacklistEvent)event; ItemDropBlacklistEvent evt = (ItemDropBlacklistEvent)event;
logger.log(Level.INFO, "WorldGuard: [" + worldName + "] " + event.getPlayer().getName() logger.log(Level.INFO, "WorldGuard: [" + worldName + "] " + event.getPlayer().getName()
+ " tried to drop " + getFriendlyItemName(evt.getType()) + " tried to drop " + getFriendlyItemName(evt.getType())
+ (comment != null ? " (" + comment + ")" : "")); + (comment != null ? " (" + comment + ")" : ""));
// Use // Use
} else if (event instanceof ItemUseBlacklistEvent) { } else if (event instanceof ItemUseBlacklistEvent) {
ItemUseBlacklistEvent evt = (ItemUseBlacklistEvent)event; ItemUseBlacklistEvent evt = (ItemUseBlacklistEvent)event;
logger.log(Level.INFO, "WorldGuard: [" + worldName + "] " + event.getPlayer().getName() logger.log(Level.INFO, "WorldGuard: [" + worldName + "] " + event.getPlayer().getName()
+ " tried to use " + getFriendlyItemName(evt.getType()) + " tried to use " + getFriendlyItemName(evt.getType())
+ (comment != null ? " (" + comment + ")" : "")); + (comment != null ? " (" + comment + ")" : ""));
// Unknown // Unknown
} else { } else {
logger.log(Level.INFO, "WorldGuard: [" + worldName + "] " + event.getPlayer().getName() logger.log(Level.INFO, "WorldGuard: [" + worldName + "] " + event.getPlayer().getName()
@ -114,7 +114,7 @@ public void logEvent(BlacklistEvent event, String comment) {
/** /**
* Get an item's friendly name with its ID. * Get an item's friendly name with its ID.
* *
* @param id * @param id
*/ */
private static String getFriendlyItemName(int id) { private static String getFriendlyItemName(int id) {

View File

@ -74,12 +74,12 @@ public class DatabaseLoggerHandler implements BlacklistLoggerHandler {
/** /**
* Construct the object. * Construct the object.
* *
* @param dsn * @param dsn
* @param user * @param user
* @param pass * @param pass
* @param table * @param table
* @param worldName * @param worldName
*/ */
public DatabaseLoggerHandler(String dsn, String user, String pass, String table, String worldName) { public DatabaseLoggerHandler(String dsn, String user, String pass, String table, String worldName) {
this.dsn = dsn; this.dsn = dsn;
@ -91,7 +91,7 @@ public DatabaseLoggerHandler(String dsn, String user, String pass, String table,
/** /**
* Gets the database connection. * Gets the database connection.
* *
* @return * @return
* @throws SQLException * @throws SQLException
*/ */
@ -104,7 +104,7 @@ private Connection getConnection() throws SQLException {
/** /**
* Log an event to the database. * Log an event to the database.
* *
* @param event * @param event
* @param name * @param name
* @param x * @param x
@ -136,7 +136,7 @@ private void logEvent(String event, LocalPlayer player, Vector pos, int item,
+ e.getMessage()); + e.getMessage());
} }
} }
/** /**
* Log an event. * Log an event.
* *
@ -148,43 +148,43 @@ public void logEvent(BlacklistEvent event, String comment) {
BlockBreakBlacklistEvent evt = (BlockBreakBlacklistEvent)event; BlockBreakBlacklistEvent evt = (BlockBreakBlacklistEvent)event;
logEvent("BREAK", evt.getPlayer(), evt.getPosition(), logEvent("BREAK", evt.getPlayer(), evt.getPosition(),
evt.getType(), comment); evt.getType(), comment);
// Block place // Block place
} else if (event instanceof BlockPlaceBlacklistEvent) { } else if (event instanceof BlockPlaceBlacklistEvent) {
BlockPlaceBlacklistEvent evt = (BlockPlaceBlacklistEvent)event; BlockPlaceBlacklistEvent evt = (BlockPlaceBlacklistEvent)event;
logEvent("PLACE", evt.getPlayer(), evt.getPosition(), logEvent("PLACE", evt.getPlayer(), evt.getPosition(),
evt.getType(), comment); evt.getType(), comment);
// Block interact // Block interact
} else if (event instanceof BlockInteractBlacklistEvent) { } else if (event instanceof BlockInteractBlacklistEvent) {
BlockInteractBlacklistEvent evt = (BlockInteractBlacklistEvent)event; BlockInteractBlacklistEvent evt = (BlockInteractBlacklistEvent)event;
logEvent("INTERACT", evt.getPlayer(), evt.getPosition(), logEvent("INTERACT", evt.getPlayer(), evt.getPosition(),
evt.getType(), comment); evt.getType(), comment);
// Destroy with // Destroy with
} else if (event instanceof DestroyWithBlacklistEvent) { } else if (event instanceof DestroyWithBlacklistEvent) {
DestroyWithBlacklistEvent evt = (DestroyWithBlacklistEvent)event; DestroyWithBlacklistEvent evt = (DestroyWithBlacklistEvent)event;
logEvent("DESTROY_WITH", evt.getPlayer(), evt.getPosition(), logEvent("DESTROY_WITH", evt.getPlayer(), evt.getPosition(),
evt.getType(), comment); evt.getType(), comment);
// Acquire // Acquire
} else if (event instanceof ItemAcquireBlacklistEvent) { } else if (event instanceof ItemAcquireBlacklistEvent) {
ItemAcquireBlacklistEvent evt = (ItemAcquireBlacklistEvent)event; ItemAcquireBlacklistEvent evt = (ItemAcquireBlacklistEvent)event;
logEvent("ACQUIRE", evt.getPlayer(), evt.getPlayer().getPosition(), logEvent("ACQUIRE", evt.getPlayer(), evt.getPlayer().getPosition(),
evt.getType(), comment); evt.getType(), comment);
// Drop // Drop
} else if (event instanceof ItemDropBlacklistEvent) { } else if (event instanceof ItemDropBlacklistEvent) {
ItemDropBlacklistEvent evt = (ItemDropBlacklistEvent)event; ItemDropBlacklistEvent evt = (ItemDropBlacklistEvent)event;
logEvent("DROP", evt.getPlayer(), evt.getPlayer().getPosition(), logEvent("DROP", evt.getPlayer(), evt.getPlayer().getPosition(),
evt.getType(), comment); evt.getType(), comment);
// Use // Use
} else if (event instanceof ItemUseBlacklistEvent) { } else if (event instanceof ItemUseBlacklistEvent) {
ItemUseBlacklistEvent evt = (ItemUseBlacklistEvent)event; ItemUseBlacklistEvent evt = (ItemUseBlacklistEvent)event;
logEvent("USE", evt.getPlayer(), evt.getPlayer().getPosition(), logEvent("USE", evt.getPlayer(), evt.getPlayer().getPosition(),
evt.getType(), comment); evt.getType(), comment);
// Unknown // Unknown
} else { } else {
logEvent("UNKNOWN", event.getPlayer(), event.getPlayer().getPosition(), logEvent("UNKNOWN", event.getPlayer(), event.getPlayer().getPosition(),
@ -201,7 +201,7 @@ public void close() {
conn.close(); conn.close();
} }
} catch (SQLException e) { } catch (SQLException e) {
} }
} }
} }

View File

@ -88,7 +88,7 @@ public class FileLoggerHandler implements BlacklistLoggerHandler {
* Construct the object. * Construct the object.
* *
* @param pathPattern * @param pathPattern
* @param worldName * @param worldName
*/ */
public FileLoggerHandler(String pathPattern, String worldName) { public FileLoggerHandler(String pathPattern, String worldName) {
this.pathPattern = pathPattern; this.pathPattern = pathPattern;
@ -100,7 +100,7 @@ public FileLoggerHandler(String pathPattern, String worldName) {
* *
* @param pathPattern * @param pathPattern
* @param cacheSize * @param cacheSize
* @param worldName * @param worldName
*/ */
public FileLoggerHandler(String pathPattern, int cacheSize, String worldName) { public FileLoggerHandler(String pathPattern, int cacheSize, String worldName) {
if (cacheSize < 1) { if (cacheSize < 1) {
@ -113,7 +113,7 @@ public FileLoggerHandler(String pathPattern, int cacheSize, String worldName) {
/** /**
* Build the path. * Build the path.
* *
* @return * @return
*/ */
private String buildPath(String playerName) { private String buildPath(String playerName) {
@ -159,18 +159,18 @@ private String buildPath(String playerName) {
} else if (group.matches("%s")) { } else if (group.matches("%s")) {
rep = String.format("%02d", calendar.get(Calendar.SECOND)); rep = String.format("%02d", calendar.get(Calendar.SECOND));
} }
m.appendReplacement(buffer, rep); m.appendReplacement(buffer, rep);
} }
m.appendTail(buffer); m.appendTail(buffer);
return buffer.toString(); return buffer.toString();
} }
/** /**
* Log a message. * Log a message.
* *
* @param player * @param player
* @param message * @param message
*/ */
@ -180,7 +180,7 @@ private void log(LocalPlayer player, String message, String comment) {
String date = dateFormat.format(new Date()); String date = dateFormat.format(new Date());
String line = "[" + date + "] " + player.getName() + ": " + message String line = "[" + date + "] " + player.getName() + ": " + message
+ (comment != null ? " (" + comment + ")" : "") + "\r\n"; + (comment != null ? " (" + comment + ")" : "") + "\r\n";
FileLoggerWriter writer = writers.get(path); FileLoggerWriter writer = writers.get(path);
// Writer already exists! // Writer already exists!
@ -202,7 +202,7 @@ private void log(LocalPlayer player, String message, String comment) {
if (parent != null && !parent.exists()) { if (parent != null && !parent.exists()) {
parent.mkdirs(); parent.mkdirs();
} }
FileWriter stream = new FileWriter(path, true); FileWriter stream = new FileWriter(path, true);
BufferedWriter out = new BufferedWriter(stream); BufferedWriter out = new BufferedWriter(stream);
out.write(line); out.write(line);
@ -239,19 +239,19 @@ private void log(LocalPlayer player, String message, String comment) {
/** /**
* Gets the coordinates in text form for the log. * Gets the coordinates in text form for the log.
* *
* @param pos * @param pos
* @return * @return
*/ */
private String getCoordinates(Vector pos) { private String getCoordinates(Vector pos) {
return "@" + pos.getBlockX() + "," + pos.getBlockY() + "," + pos.getBlockZ(); return "@" + pos.getBlockX() + "," + pos.getBlockY() + "," + pos.getBlockZ();
} }
private void logEvent(BlacklistEvent event, String text, int id, Vector pos, String comment) { private void logEvent(BlacklistEvent event, String text, int id, Vector pos, String comment) {
log(event.getPlayer(), "Tried to " + text + " " + getFriendlyItemName(id) log(event.getPlayer(), "Tried to " + text + " " + getFriendlyItemName(id)
+ " " + getCoordinates(pos), comment); + " " + getCoordinates(pos), comment);
} }
/** /**
* Log an event. * Log an event.
* *
@ -262,37 +262,37 @@ public void logEvent(BlacklistEvent event, String comment) {
if (event instanceof BlockBreakBlacklistEvent) { if (event instanceof BlockBreakBlacklistEvent) {
BlockBreakBlacklistEvent evt = (BlockBreakBlacklistEvent)event; BlockBreakBlacklistEvent evt = (BlockBreakBlacklistEvent)event;
logEvent(event, "break", evt.getType(), evt.getPosition(), comment); logEvent(event, "break", evt.getType(), evt.getPosition(), comment);
// Block place // Block place
} else if (event instanceof BlockPlaceBlacklistEvent) { } else if (event instanceof BlockPlaceBlacklistEvent) {
BlockPlaceBlacklistEvent evt = (BlockPlaceBlacklistEvent)event; BlockPlaceBlacklistEvent evt = (BlockPlaceBlacklistEvent)event;
logEvent(event, "place", evt.getType(), evt.getPosition(), comment); logEvent(event, "place", evt.getType(), evt.getPosition(), comment);
// Block interact // Block interact
} else if (event instanceof BlockInteractBlacklistEvent) { } else if (event instanceof BlockInteractBlacklistEvent) {
BlockInteractBlacklistEvent evt = (BlockInteractBlacklistEvent)event; BlockInteractBlacklistEvent evt = (BlockInteractBlacklistEvent)event;
logEvent(event, "interact with", evt.getType(), evt.getPosition(), comment); logEvent(event, "interact with", evt.getType(), evt.getPosition(), comment);
// Destroy with // Destroy with
} else if (event instanceof DestroyWithBlacklistEvent) { } else if (event instanceof DestroyWithBlacklistEvent) {
DestroyWithBlacklistEvent evt = (DestroyWithBlacklistEvent)event; DestroyWithBlacklistEvent evt = (DestroyWithBlacklistEvent)event;
logEvent(event, "destroy with", evt.getType(), evt.getPosition(), comment); logEvent(event, "destroy with", evt.getType(), evt.getPosition(), comment);
// Acquire // Acquire
} else if (event instanceof ItemAcquireBlacklistEvent) { } else if (event instanceof ItemAcquireBlacklistEvent) {
ItemAcquireBlacklistEvent evt = (ItemAcquireBlacklistEvent)event; ItemAcquireBlacklistEvent evt = (ItemAcquireBlacklistEvent)event;
logEvent(event, "acquire", evt.getType(), evt.getPosition(), comment); logEvent(event, "acquire", evt.getType(), evt.getPosition(), comment);
// Drop // Drop
} else if (event instanceof ItemDropBlacklistEvent) { } else if (event instanceof ItemDropBlacklistEvent) {
ItemDropBlacklistEvent evt = (ItemDropBlacklistEvent)event; ItemDropBlacklistEvent evt = (ItemDropBlacklistEvent)event;
logEvent(event, "drop", evt.getType(), evt.getPosition(), comment); logEvent(event, "drop", evt.getType(), evt.getPosition(), comment);
// Use // Use
} else if (event instanceof ItemUseBlacklistEvent) { } else if (event instanceof ItemUseBlacklistEvent) {
ItemUseBlacklistEvent evt = (ItemUseBlacklistEvent)event; ItemUseBlacklistEvent evt = (ItemUseBlacklistEvent)event;
logEvent(event, "use", evt.getType(), evt.getPosition(), comment); logEvent(event, "use", evt.getType(), evt.getPosition(), comment);
// Unknown // Unknown
} else { } else {
log(event.getPlayer(), "Unknown event: " log(event.getPlayer(), "Unknown event: "

View File

@ -41,8 +41,8 @@ public class FileLoggerWriter implements Comparable<FileLoggerWriter> {
/** /**
* Construct the object. * Construct the object.
* *
* @param path * @param path
* @param writer * @param writer
*/ */
public FileLoggerWriter(String path, BufferedWriter writer) { public FileLoggerWriter(String path, BufferedWriter writer) {
@ -53,7 +53,7 @@ public FileLoggerWriter(String path, BufferedWriter writer) {
/** /**
* File path. * File path.
* *
* @return * @return
*/ */
public String getPath() { public String getPath() {
@ -73,7 +73,7 @@ public BufferedWriter getWriter() {
public long getLastUse() { public long getLastUse() {
return lastUse; return lastUse;
} }
/** /**
* Update last use time. * Update last use time.
*/ */
@ -83,7 +83,7 @@ public void updateLastUse() {
/** /**
* Comparison function. * Comparison function.
* *
* @param other * @param other
* @return * @return
*/ */

View File

@ -34,12 +34,12 @@
/** /**
* Represents the global configuration and also delegates configuration * Represents the global configuration and also delegates configuration
* for individual worlds. * for individual worlds.
* *
* @author sk89q * @author sk89q
* @author Michael * @author Michael
*/ */
public class ConfigurationManager { public class ConfigurationManager {
private static final String CONFIG_HEADER = "#\r\n" + private static final String CONFIG_HEADER = "#\r\n" +
"# WorldGuard's main configuration file\r\n" + "# WorldGuard's main configuration file\r\n" +
"#\r\n" + "#\r\n" +
@ -65,22 +65,22 @@ public class ConfigurationManager {
* Reference to the plugin. * Reference to the plugin.
*/ */
private WorldGuardPlugin plugin; private WorldGuardPlugin plugin;
/** /**
* Holds configurations for different worlds. * Holds configurations for different worlds.
*/ */
private Map<String, WorldConfiguration> worlds; private Map<String, WorldConfiguration> worlds;
/** /**
* List of people with god mode. * List of people with god mode.
*/ */
private Set<String> hasGodMode = new HashSet<String>(); private Set<String> hasGodMode = new HashSet<String>();
/** /**
* List of people who can breathe underwater. * List of people who can breathe underwater.
*/ */
private Set<String> hasAmphibious = new HashSet<String>(); private Set<String> hasAmphibious = new HashSet<String>();
public boolean suppressTickSyncWarnings; public boolean suppressTickSyncWarnings;
public boolean useRegionsScheduler; public boolean useRegionsScheduler;
public boolean activityHaltToggle = false; public boolean activityHaltToggle = false;
@ -89,7 +89,7 @@ public class ConfigurationManager {
/** /**
* Construct the object. * Construct the object.
* *
* @param plugin * @param plugin
*/ */
public ConfigurationManager(WorldGuardPlugin plugin) { public ConfigurationManager(WorldGuardPlugin plugin) {
@ -104,7 +104,7 @@ public void load() {
// Create the default configuration file // Create the default configuration file
WorldGuardPlugin.createDefaultConfiguration( WorldGuardPlugin.createDefaultConfiguration(
new File(plugin.getDataFolder(), "config.yml"), "config.yml"); new File(plugin.getDataFolder(), "config.yml"), "config.yml");
Configuration config = plugin.getConfiguration(); Configuration config = plugin.getConfiguration();
config.load(); config.load();
@ -139,14 +139,14 @@ public void unload() {
/** /**
* Get the configuration for a world. * Get the configuration for a world.
* *
* @param world * @param world
* @return * @return
*/ */
public WorldConfiguration get(World world) { public WorldConfiguration get(World world) {
String worldName = world.getName(); String worldName = world.getName();
WorldConfiguration config = worlds.get(worldName); WorldConfiguration config = worlds.get(worldName);
if (config == null) { if (config == null) {
config = new WorldConfiguration(plugin, worldName); config = new WorldConfiguration(plugin, worldName);
worlds.put(worldName, config); worlds.put(worldName, config);
@ -157,75 +157,75 @@ public WorldConfiguration get(World world) {
/** /**
* Forget a player. * Forget a player.
* *
* @param player * @param player
*/ */
public void forgetPlayer(LocalPlayer player) { public void forgetPlayer(LocalPlayer player) {
for (Map.Entry<String, WorldConfiguration> entry for (Map.Entry<String, WorldConfiguration> entry
: worlds.entrySet()) { : worlds.entrySet()) {
// The blacklist needs to forget players // The blacklist needs to forget players
Blacklist bl = entry.getValue().getBlacklist(); Blacklist bl = entry.getValue().getBlacklist();
if (bl != null) { if (bl != null) {
bl.forgetPlayer(player); bl.forgetPlayer(player);
} }
} }
hasGodMode.remove(player.getName()); hasGodMode.remove(player.getName());
hasAmphibious.remove(player.getName()); hasAmphibious.remove(player.getName());
} }
/** /**
* Enable god mode for a player. * Enable god mode for a player.
* *
* @param player * @param player
*/ */
public void enableGodMode(Player player) { public void enableGodMode(Player player) {
hasGodMode.add(player.getName()); hasGodMode.add(player.getName());
} }
/** /**
* Disable god mode for a player. * Disable god mode for a player.
* *
* @param player * @param player
*/ */
public void disableGodMode(Player player) { public void disableGodMode(Player player) {
hasGodMode.remove(player.getName()); hasGodMode.remove(player.getName());
} }
/** /**
* Check to see if god mode is enabled for a player. * Check to see if god mode is enabled for a player.
* *
* @param player * @param player
* @return * @return
*/ */
public boolean hasGodMode(Player player) { public boolean hasGodMode(Player player) {
return hasGodMode.contains(player.getName()); return hasGodMode.contains(player.getName());
} }
/** /**
* Enable amphibious mode for a player. * Enable amphibious mode for a player.
* *
* @param player * @param player
*/ */
public void enableAmphibiousMode(Player player) { public void enableAmphibiousMode(Player player) {
hasAmphibious.add(player.getName()); hasAmphibious.add(player.getName());
} }
/** /**
* Disable amphibious mode for a player. * Disable amphibious mode for a player.
* *
* @param player * @param player
*/ */
public void disableAmphibiousMode(Player player) { public void disableAmphibiousMode(Player player) {
hasAmphibious.remove(player.getName()); hasAmphibious.remove(player.getName());
} }
/** /**
* Check to see if amphibious mode is enabled for a player. * Check to see if amphibious mode is enabled for a player.
* *
* @param player * @param player
* @return * @return
*/ */
public boolean hasAmphibiousMode(Player player) { public boolean hasAmphibiousMode(Player player) {
return hasAmphibious.contains(player.getName()); return hasAmphibious.contains(player.getName());

View File

@ -16,11 +16,11 @@
*/ */
class LegacyConsoleSender implements CommandSender { class LegacyConsoleSender implements CommandSender {
private Server server; private Server server;
public LegacyConsoleSender(Server server) { public LegacyConsoleSender(Server server) {
this.server = server; this.server = server;
} }
public void sendMessage(String message) { public void sendMessage(String message) {
WorldGuardPlugin.logger.info(message); WorldGuardPlugin.logger.info(message);
} }
@ -28,7 +28,7 @@ public void sendMessage(String message) {
public Server getServer() { public Server getServer() {
return server; return server;
} }
public String getName() { public String getName() {
return "CONSOLE"; return "CONSOLE";
} }

View File

@ -38,7 +38,7 @@ public class LoggerToChatHandler extends Handler {
/** /**
* Construct the object. * Construct the object.
* *
* @param player * @param player
*/ */
public LoggerToChatHandler(CommandSender player) { public LoggerToChatHandler(CommandSender player) {

View File

@ -457,7 +457,7 @@ public Blacklist getBlacklist() {
public String getWorldName() { public String getWorldName() {
return this.worldName; return this.worldName;
} }
public boolean isChestProtected(Block block, Player player) { public boolean isChestProtected(Block block, Player player) {
if (!signChestProtection) { if (!signChestProtection) {
return false; return false;
@ -468,14 +468,14 @@ public boolean isChestProtected(Block block, Player player) {
} }
return chestProtection.isProtected(block, player); return chestProtection.isProtected(block, player);
} }
public boolean isChestProtected(Block block) { public boolean isChestProtected(Block block) {
if (!signChestProtection) { if (!signChestProtection) {
return false; return false;
} }
return chestProtection.isProtected(block, null); return chestProtection.isProtected(block, null);
} }
public boolean isChestProtectedPlacement(Block block, Player player) { public boolean isChestProtectedPlacement(Block block, Player player) {
if (!signChestProtection) { if (!signChestProtection) {
return false; return false;

View File

@ -44,29 +44,29 @@
/** /**
* This class keeps track of region information for every world. It loads * This class keeps track of region information for every world. It loads
* world region information as needed. * world region information as needed.
* *
* @author sk89q * @author sk89q
* @author Redecouverte * @author Redecouverte
*/ */
public class GlobalRegionManager { public class GlobalRegionManager {
private static final Logger logger = Logger.getLogger("Minecraft.WorldGuard"); private static final Logger logger = Logger.getLogger("Minecraft.WorldGuard");
/** /**
* Reference to the plugin. * Reference to the plugin.
*/ */
private WorldGuardPlugin plugin; private WorldGuardPlugin plugin;
/** /**
* Reference to the global configuration. * Reference to the global configuration.
*/ */
private ConfigurationManager config; private ConfigurationManager config;
/** /**
* Map of managers per-world. * Map of managers per-world.
*/ */
private HashMap<String, RegionManager> managers; private HashMap<String, RegionManager> managers;
/** /**
* Stores the list of modification dates for the world files. This allows * Stores the list of modification dates for the world files. This allows
* WorldGuard to reload files as needed. * WorldGuard to reload files as needed.
@ -75,8 +75,8 @@ public class GlobalRegionManager {
/** /**
* Construct the object. * Construct the object.
* *
* @param plugin * @param plugin
*/ */
public GlobalRegionManager(WorldGuardPlugin plugin) { public GlobalRegionManager(WorldGuardPlugin plugin) {
this.plugin = plugin; this.plugin = plugin;
@ -92,10 +92,10 @@ public void unload() {
managers.clear(); managers.clear();
lastModified.clear(); lastModified.clear();
} }
/** /**
* Get the path for a world's regions file. * Get the path for a world's regions file.
* *
* @param name * @param name
* @return * @return
*/ */
@ -106,7 +106,7 @@ protected File getPath(String name) {
/** /**
* Unload region information for a world. * Unload region information for a world.
* *
* @param name * @param name
*/ */
public void unload(String name) { public void unload(String name) {
@ -128,14 +128,14 @@ public void unloadAll() {
/** /**
* Load region information for a world. * Load region information for a world.
* *
* @param world * @param world
* @return * @return
*/ */
public RegionManager load(World world) { public RegionManager load(World world) {
String name = world.getName(); String name = world.getName();
File file = getPath(name); File file = getPath(name);
try { try {
// Create a manager // Create a manager
RegionManager manager = new FlatRegionManager(new YAMLDatabase(file)); RegionManager manager = new FlatRegionManager(new YAMLDatabase(file));
@ -147,7 +147,7 @@ public RegionManager load(World world) {
// Store the last modification date so we can track changes // Store the last modification date so we can track changes
lastModified.put(name, file.lastModified()); lastModified.put(name, file.lastModified());
return manager; return manager;
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
logger.warning("WorldGuard: Region file for world \"" logger.warning("WorldGuard: Region file for world \""
@ -159,11 +159,11 @@ public RegionManager load(World world) {
logger.warning("WorldGuard: Error loading regions for world \"" logger.warning("WorldGuard: Error loading regions for world \""
+ name + "\":" + e.getMessage()); + name + "\":" + e.getMessage());
} }
// @TODO: THIS CREATES PROBLEMS!! // @TODO: THIS CREATES PROBLEMS!!
return null; return null;
} }
/** /**
* Preloads region managers for all worlds. * Preloads region managers for all worlds.
*/ */
@ -183,7 +183,7 @@ public void reloadChanged() {
File file = getPath(name); File file = getPath(name);
Long oldDate = lastModified.get(name); Long oldDate = lastModified.get(name);
if (oldDate == null) { if (oldDate == null) {
oldDate = 0L; oldDate = 0L;
} }
@ -191,7 +191,7 @@ public void reloadChanged() {
try { try {
if (file.lastModified() > oldDate) { if (file.lastModified() > oldDate) {
World world = plugin.getServer().getWorld(name); World world = plugin.getServer().getWorld(name);
if (world != null) { if (world != null) {
load(world); load(world);
} }
@ -203,7 +203,7 @@ public void reloadChanged() {
/** /**
* Get the region manager for a particular world. * Get the region manager for a particular world.
* *
* @param world * @param world
* @return * @return
*/ */
@ -228,10 +228,10 @@ public boolean hasBypass(LocalPlayer player, World world) {
return player.hasPermission("worldguard.region.bypass." return player.hasPermission("worldguard.region.bypass."
+ world.getName()); + world.getName());
} }
/** /**
* Returns whether the player can bypass. * Returns whether the player can bypass.
* *
* @param player * @param player
* @param world * @param world
* @return * @return
@ -240,33 +240,33 @@ public boolean hasBypass(Player player, World world) {
return plugin.hasPermission(player, "worldguard.region.bypass." return plugin.hasPermission(player, "worldguard.region.bypass."
+ world.getName()); + world.getName());
} }
/** /**
* Check if a player has permission to build at a block. * Check if a player has permission to build at a block.
* *
* @param player * @param player
* @param block * @param block
* @return * @return
*/ */
public boolean canBuild(Player player, Block block) { public boolean canBuild(Player player, Block block) {
return canBuild(player, block.getLocation()); return canBuild(player, block.getLocation());
} }
/** /**
* Check if a player has permission to build at a location. * Check if a player has permission to build at a location.
* *
* @param player * @param player
* @param loc * @param loc
* @return * @return
*/ */
public boolean canBuild(Player player, Location loc) { public boolean canBuild(Player player, Location loc) {
World world = loc.getWorld(); World world = loc.getWorld();
WorldConfiguration worldConfig = config.get(world); WorldConfiguration worldConfig = config.get(world);
if (!worldConfig.useRegions) { if (!worldConfig.useRegions) {
return true; return true;
} }
LocalPlayer localPlayer = plugin.wrapPlayer(player); LocalPlayer localPlayer = plugin.wrapPlayer(player);
if (!hasBypass(player, world)) { if (!hasBypass(player, world)) {
@ -280,10 +280,10 @@ public boolean canBuild(Player player, Location loc) {
return true; return true;
} }
/** /**
* Checks to see whether a flag is allowed. * Checks to see whether a flag is allowed.
* *
* @param flag * @param flag
* @param loc * @param loc
* @return * @return
@ -291,11 +291,11 @@ public boolean canBuild(Player player, Location loc) {
public boolean allows(StateFlag flag, Location loc) { public boolean allows(StateFlag flag, Location loc) {
World world = loc.getWorld(); World world = loc.getWorld();
WorldConfiguration worldConfig = config.get(world); WorldConfiguration worldConfig = config.get(world);
if (!worldConfig.useRegions) { if (!worldConfig.useRegions) {
return true; return true;
} }
RegionManager mgr = plugin.getGlobalRegionManager().get(world); RegionManager mgr = plugin.getGlobalRegionManager().get(world);
return mgr.getApplicableRegions(toVector(loc)).allows(flag); return mgr.getApplicableRegions(toVector(loc)).allows(flag);
} }

View File

@ -44,12 +44,12 @@
/** /**
* Represents a protected area database that uses CSV files. * Represents a protected area database that uses CSV files.
* *
* @author sk89q * @author sk89q
*/ */
public class CSVDatabase extends AbstractProtectionDatabase { public class CSVDatabase extends AbstractProtectionDatabase {
private static Logger logger = Logger.getLogger("Minecraft.WorldGuard"); private static Logger logger = Logger.getLogger("Minecraft.WorldGuard");
/** /**
* References the CSV file. * References the CSV file.
*/ */
@ -58,11 +58,11 @@ public class CSVDatabase extends AbstractProtectionDatabase {
* Holds the list of regions. * Holds the list of regions.
*/ */
private Map<String,ProtectedRegion> regions; private Map<String,ProtectedRegion> regions;
/** /**
* Construct the database with a path to a file. No file is read or * Construct the database with a path to a file. No file is read or
* written at this time. * written at this time.
* *
* @param file * @param file
*/ */
public CSVDatabase(File file) { public CSVDatabase(File file) {
@ -84,28 +84,28 @@ public void load() throws IOException {
new HashMap<String,ProtectedRegion>(); new HashMap<String,ProtectedRegion>();
Map<ProtectedRegion,String> parentSets = Map<ProtectedRegion,String> parentSets =
new LinkedHashMap<ProtectedRegion, String>(); new LinkedHashMap<ProtectedRegion, String>();
CSVReader reader = new CSVReader(new FileReader(file)); CSVReader reader = new CSVReader(new FileReader(file));
try { try {
String[] line; String[] line;
while ((line = reader.readNext()) != null) { while ((line = reader.readNext()) != null) {
if (line.length < 2) { if (line.length < 2) {
logger.warning("Invalid region definition: " + line); logger.warning("Invalid region definition: " + line);
continue; continue;
} }
String id = line[0].toLowerCase().replace(".", ""); String id = line[0].toLowerCase().replace(".", "");
String type = line[1]; String type = line[1];
ArrayReader<String> entries = new ArrayReader<String>(line); ArrayReader<String> entries = new ArrayReader<String>(line);
if (type.equalsIgnoreCase("cuboid")) { if (type.equalsIgnoreCase("cuboid")) {
if (line.length < 8) { if (line.length < 8) {
logger.warning("Invalid region definition: " + line); logger.warning("Invalid region definition: " + line);
continue; continue;
} }
Vector pt1 = new Vector( Vector pt1 = new Vector(
Integer.parseInt(line[2]), Integer.parseInt(line[2]),
Integer.parseInt(line[3]), Integer.parseInt(line[3]),
@ -117,12 +117,12 @@ public void load() throws IOException {
BlockVector min = Vector.getMinimum(pt1, pt2).toBlockVector(); BlockVector min = Vector.getMinimum(pt1, pt2).toBlockVector();
BlockVector max = Vector.getMaximum(pt1, pt2).toBlockVector(); BlockVector max = Vector.getMaximum(pt1, pt2).toBlockVector();
int priority = entries.get(8) == null ? 0 : Integer.parseInt(entries.get(8)); int priority = entries.get(8) == null ? 0 : Integer.parseInt(entries.get(8));
String ownersData = entries.get(9); String ownersData = entries.get(9);
String flagsData = entries.get(10); String flagsData = entries.get(10);
//String enterMessage = nullEmptyString(entries.get(11)); //String enterMessage = nullEmptyString(entries.get(11));
ProtectedRegion region = new ProtectedCuboidRegion(id, min, max); ProtectedRegion region = new ProtectedCuboidRegion(id, min, max);
region.setPriority(priority); region.setPriority(priority);
parseFlags(region, flagsData); parseFlags(region, flagsData);
@ -140,7 +140,7 @@ public void load() throws IOException {
BlockVector min = Vector.getMinimum(pt1, pt2).toBlockVector(); BlockVector min = Vector.getMinimum(pt1, pt2).toBlockVector();
BlockVector max = Vector.getMaximum(pt1, pt2).toBlockVector(); BlockVector max = Vector.getMaximum(pt1, pt2).toBlockVector();
int priority = entries.get(8) == null ? 0 : Integer.parseInt(entries.get(8)); int priority = entries.get(8) == null ? 0 : Integer.parseInt(entries.get(8));
String parentId = entries.get(9); String parentId = entries.get(9);
String ownersData = entries.get(10); String ownersData = entries.get(10);
@ -148,14 +148,14 @@ public void load() throws IOException {
String flagsData = entries.get(12); String flagsData = entries.get(12);
//String enterMessage = nullEmptyString(entries.get(13)); //String enterMessage = nullEmptyString(entries.get(13));
//String leaveMessage = nullEmptyString(entries.get(14)); //String leaveMessage = nullEmptyString(entries.get(14));
ProtectedRegion region = new ProtectedCuboidRegion(id, min, max); ProtectedRegion region = new ProtectedCuboidRegion(id, min, max);
region.setPriority(priority); region.setPriority(priority);
parseFlags(region, flagsData); parseFlags(region, flagsData);
region.setOwners(this.parseDomains(ownersData)); region.setOwners(this.parseDomains(ownersData));
region.setMembers(this.parseDomains(membersData)); region.setMembers(this.parseDomains(membersData));
regions.put(id, region); regions.put(id, region);
// Link children to parents later // Link children to parents later
if (parentId.length() > 0) { if (parentId.length() > 0) {
parentSets.put(region, parentId); parentSets.put(region, parentId);
@ -168,7 +168,7 @@ public void load() throws IOException {
} catch (IOException e) { } catch (IOException e) {
} }
} }
for (Map.Entry<ProtectedRegion, String> entry : parentSets.entrySet()) { for (Map.Entry<ProtectedRegion, String> entry : parentSets.entrySet()) {
ProtectedRegion parent = regions.get(entry.getValue()); ProtectedRegion parent = regions.get(entry.getValue());
if (parent != null) { if (parent != null) {
@ -182,13 +182,13 @@ public void load() throws IOException {
logger.warning("Unknown region parent: " + entry.getValue()); logger.warning("Unknown region parent: " + entry.getValue());
} }
} }
this.regions = regions; this.regions = regions;
} }
/** /**
* Used to parse the specified domain in the CSV file. * Used to parse the specified domain in the CSV file.
* *
* @param data * @param data
* @return * @return
*/ */
@ -196,19 +196,19 @@ private DefaultDomain parseDomains(String data) {
if (data == null) { if (data == null) {
return new DefaultDomain(); return new DefaultDomain();
} }
DefaultDomain domain = new DefaultDomain(); DefaultDomain domain = new DefaultDomain();
Pattern pattern = Pattern.compile("^([A-Za-z]):(.*)$"); Pattern pattern = Pattern.compile("^([A-Za-z]):(.*)$");
String[] parts = data.split(","); String[] parts = data.split(",");
for (String part : parts) { for (String part : parts) {
if (part.trim().length() == 0) { if (part.trim().length() == 0) {
continue; continue;
} }
Matcher matcher = pattern.matcher(part); Matcher matcher = pattern.matcher(part);
if (!matcher.matches()) { if (!matcher.matches()) {
logger.warning("Invalid owner specification: " + part); logger.warning("Invalid owner specification: " + part);
continue; continue;
@ -225,22 +225,22 @@ private DefaultDomain parseDomains(String data) {
logger.warning("Unknown owner specification: " + type); logger.warning("Unknown owner specification: " + type);
} }
} }
return domain; return domain;
} }
/** /**
* Used to parse the list of flags. * Used to parse the list of flags.
* *
* @param data * @param data
*/ */
private void parseFlags(ProtectedRegion region, String data) { private void parseFlags(ProtectedRegion region, String data) {
if (data == null) { if (data == null) {
return; return;
} }
State curState = State.ALLOW; State curState = State.ALLOW;
for (int i = 0; i < data.length(); i++) { for (int i = 0; i < data.length(); i++) {
char k = data.charAt(i); char k = data.charAt(i);
if (k == '+') { if (k == '+') {
@ -262,7 +262,7 @@ private void parseFlags(ProtectedRegion region, String data) {
} else { } else {
flagStr = String.valueOf(k); flagStr = String.valueOf(k);
} }
StateFlag flag = DefaultFlag.getLegacyFlag(flagStr); StateFlag flag = DefaultFlag.getLegacyFlag(flagStr);
if (flag != null) { if (flag != null) {
region.setFlag(flag, curState); region.setFlag(flag, curState);
@ -275,29 +275,29 @@ private void parseFlags(ProtectedRegion region, String data) {
/** /**
* Used to write the list of domains. * Used to write the list of domains.
* *
* @param domain * @param domain
* @return * @return
*/ */
/* private String writeDomains(DefaultDomain domain) { /* private String writeDomains(DefaultDomain domain) {
StringBuilder str = new StringBuilder(); StringBuilder str = new StringBuilder();
for (String player : domain.getPlayers()) { for (String player : domain.getPlayers()) {
str.append("u:" + player + ","); str.append("u:" + player + ",");
} }
for (String group : domain.getGroups()) { for (String group : domain.getGroups()) {
str.append("g:" + group + ","); str.append("g:" + group + ",");
} }
return str.length() > 0 ? return str.length() > 0 ?
str.toString().substring(0, str.length() - 1) : ""; str.toString().substring(0, str.length() - 1) : "";
}*/ }*/
/** /**
* Helper method to prepend '+' or '-' in front of a flag according * Helper method to prepend '+' or '-' in front of a flag according
* to the flag's state. * to the flag's state.
* *
* @param state * @param state
* @param flag * @param flag
* @return * @return
@ -309,14 +309,14 @@ private String writeFlag(State state, String flag) {
} else if (state == State.DENY) { } else if (state == State.DENY) {
return "-" + flag; return "-" + flag;
} }
return ""; return "";
} }
*/ */
/** /**
* Returns a null if a string is null or empty. * Returns a null if a string is null or empty.
* *
* @param str * @param str
* @return * @return
*/ */

View File

@ -27,46 +27,46 @@
/** /**
* Represents a database to read and write lists of regions from and to. * Represents a database to read and write lists of regions from and to.
* *
* @author sk89q * @author sk89q
*/ */
public interface ProtectionDatabase { public interface ProtectionDatabase {
/** /**
* Load the list of regions. The method should not modify the list returned * Load the list of regions. The method should not modify the list returned
* by getRegions() unless the load finishes successfully. * by getRegions() unless the load finishes successfully.
* *
* @throws IOException * @throws IOException
*/ */
public void load() throws IOException; public void load() throws IOException;
/** /**
* Save the list of regions. * Save the list of regions.
* *
* @throws IOException * @throws IOException
*/ */
public void save() throws IOException; public void save() throws IOException;
/** /**
* Load the list of regions into a region manager. * Load the list of regions into a region manager.
* *
* @param manager * @param manager
* @throws IOException * @throws IOException
*/ */
public void load(RegionManager manager) throws IOException; public void load(RegionManager manager) throws IOException;
/** /**
* Save the list of regions from a region manager. * Save the list of regions from a region manager.
* *
* @param manager * @param manager
* @throws IOException * @throws IOException
*/ */
public void save(RegionManager manager) throws IOException; public void save(RegionManager manager) throws IOException;
/** /**
* Get a list of regions. * Get a list of regions.
* *
* @return * @return
*/ */
public Map<String,ProtectedRegion> getRegions(); public Map<String,ProtectedRegion> getRegions();
/** /**
* Set the list of regions. * Set the list of regions.
* *
* @param regions * @param regions
*/ */
public void setRegions(Map<String,ProtectedRegion> regions); public void setRegions(Map<String,ProtectedRegion> regions);

View File

@ -26,7 +26,7 @@
* @author sk89q * @author sk89q
*/ */
public final class DefaultFlag { public final class DefaultFlag {
public static final StateFlag PASSTHROUGH = new StateFlag("passthrough", 'z', false); public static final StateFlag PASSTHROUGH = new StateFlag("passthrough", 'z', false);
public static final StateFlag BUILD = new StateFlag("build", 'b', true); public static final StateFlag BUILD = new StateFlag("build", 'b', true);
public static final StateFlag PVP = new StateFlag("pvp", 'p', true); public static final StateFlag PVP = new StateFlag("pvp", 'p', true);
@ -101,17 +101,17 @@ public final class DefaultFlag {
ENTRY.setGroupFlag(ENTRY_PERM); ENTRY.setGroupFlag(ENTRY_PERM);
EXIT.setGroupFlag(EXIT_PERM); EXIT.setGroupFlag(EXIT_PERM);
} }
private DefaultFlag() { private DefaultFlag() {
} }
public static Flag<?>[] getFlags() { public static Flag<?>[] getFlags() {
return flagsList; return flagsList;
} }
/** /**
* Get the legacy flag. * Get the legacy flag.
* *
* @param flagString * @param flagString
* @return null if not found * @return null if not found
*/ */
@ -121,7 +121,7 @@ public static StateFlag getLegacyFlag(String flagString) {
return (StateFlag) flag; return (StateFlag) flag;
} }
} }
return null; return null;
} }
} }

View File

@ -27,7 +27,7 @@
* @author sk89q * @author sk89q
*/ */
public class DoubleFlag extends Flag<Double> { public class DoubleFlag extends Flag<Double> {
public DoubleFlag(String name, char legacyCode) { public DoubleFlag(String name, char legacyCode) {
super(name, legacyCode); super(name, legacyCode);
} }
@ -40,7 +40,7 @@ public DoubleFlag(String name) {
public Double parseInput(WorldGuardPlugin plugin, CommandSender sender, public Double parseInput(WorldGuardPlugin plugin, CommandSender sender,
String input) throws InvalidFlagFormat { String input) throws InvalidFlagFormat {
input = input.trim(); input = input.trim();
try { try {
return Double.parseDouble(input); return Double.parseDouble(input);
} catch (NumberFormatException e) { } catch (NumberFormatException e) {

View File

@ -25,35 +25,35 @@
/** /**
* *
* @author sk89q * @author sk89q
* @param <T> * @param <T>
*/ */
public abstract class Flag<T> { public abstract class Flag<T> {
private String name; private String name;
private Character legacyCode; private Character legacyCode;
public Flag(String name, char legacyCode) { public Flag(String name, char legacyCode) {
this.name = name; this.name = name;
this.legacyCode = legacyCode; this.legacyCode = legacyCode;
} }
public Flag(String name) { public Flag(String name) {
this.name = name; this.name = name;
this.legacyCode = null; this.legacyCode = null;
} }
public String getName() { public String getName() {
return name; return name;
} }
public Character getLegacyCode() { public Character getLegacyCode() {
return legacyCode; return legacyCode;
} }
public abstract T parseInput(WorldGuardPlugin plugin, CommandSender sender, public abstract T parseInput(WorldGuardPlugin plugin, CommandSender sender,
String input) throws InvalidFlagFormat; String input) throws InvalidFlagFormat;
public abstract T unmarshal(Object o); public abstract T unmarshal(Object o);
public abstract Object marshal(T o); public abstract Object marshal(T o);
} }

View File

@ -27,7 +27,7 @@
* @author sk89q * @author sk89q
*/ */
public class IntegerFlag extends Flag<Integer> { public class IntegerFlag extends Flag<Integer> {
public IntegerFlag(String name, char legacyCode) { public IntegerFlag(String name, char legacyCode) {
super(name, legacyCode); super(name, legacyCode);
} }
@ -40,7 +40,7 @@ public IntegerFlag(String name) {
public Integer parseInput(WorldGuardPlugin plugin, CommandSender sender, public Integer parseInput(WorldGuardPlugin plugin, CommandSender sender,
String input) throws InvalidFlagFormat { String input) throws InvalidFlagFormat {
input = input.trim(); input = input.trim();
try { try {
return Integer.parseInt(input); return Integer.parseInt(input);
} catch (NumberFormatException e) { } catch (NumberFormatException e) {

View File

@ -39,7 +39,7 @@ public static enum RegionGroup {
} }
private RegionGroup def; private RegionGroup def;
public RegionGroupFlag(String name, char legacyCode, RegionGroup def) { public RegionGroupFlag(String name, char legacyCode, RegionGroup def) {
super(name, legacyCode); super(name, legacyCode);
this.def = def; this.def = def;
@ -58,7 +58,7 @@ public RegionGroup getDefault() {
public RegionGroup parseInput(WorldGuardPlugin plugin, CommandSender sender, public RegionGroup parseInput(WorldGuardPlugin plugin, CommandSender sender,
String input) throws InvalidFlagFormat { String input) throws InvalidFlagFormat {
input = input.trim(); input = input.trim();
if (input.equalsIgnoreCase("members") || input.equalsIgnoreCase("member")) { if (input.equalsIgnoreCase("members") || input.equalsIgnoreCase("member")) {
return RegionGroup.MEMBERS; return RegionGroup.MEMBERS;
} else if (input.equalsIgnoreCase("owners") || input.equalsIgnoreCase("owner")) { } else if (input.equalsIgnoreCase("owners") || input.equalsIgnoreCase("owner")) {
@ -149,5 +149,5 @@ public static boolean isMember(ApplicableRegionSet set,
return false; return false;
} }
} }

View File

@ -27,15 +27,15 @@
* @author sk89q * @author sk89q
*/ */
public class StateFlag extends Flag<StateFlag.State> { public class StateFlag extends Flag<StateFlag.State> {
public enum State { public enum State {
ALLOW, ALLOW,
DENY DENY
} }
private boolean def; private boolean def;
private RegionGroupFlag groupFlag; private RegionGroupFlag groupFlag;
public StateFlag(String name, char legacyCode, boolean def) { public StateFlag(String name, char legacyCode, boolean def) {
super(name, legacyCode); super(name, legacyCode);
this.def = def; this.def = def;
@ -62,7 +62,7 @@ public void setGroupFlag(RegionGroupFlag groupFlag) {
public State parseInput(WorldGuardPlugin plugin, CommandSender sender, public State parseInput(WorldGuardPlugin plugin, CommandSender sender,
String input) throws InvalidFlagFormat { String input) throws InvalidFlagFormat {
input = input.trim(); input = input.trim();
if (input.equalsIgnoreCase("allow")) { if (input.equalsIgnoreCase("allow")) {
return State.ALLOW; return State.ALLOW;
} else if (input.equalsIgnoreCase("deny")) { } else if (input.equalsIgnoreCase("deny")) {
@ -96,5 +96,5 @@ public Object marshal(State o) {
return null; return null;
} }
} }
} }

View File

@ -27,7 +27,7 @@
* @author sk89q * @author sk89q
*/ */
public class StringFlag extends Flag<String> { public class StringFlag extends Flag<String> {
public StringFlag(String name, char legacyCode) { public StringFlag(String name, char legacyCode) {
super(name, legacyCode); super(name, legacyCode);
} }
@ -55,5 +55,5 @@ public String unmarshal(Object o) {
public Object marshal(String o) { public Object marshal(String o) {
return o; return o;
} }
} }

View File

@ -33,7 +33,7 @@
* @author sk89q * @author sk89q
*/ */
public class VectorFlag extends Flag<Vector> { public class VectorFlag extends Flag<Vector> {
public VectorFlag(String name, char legacyCode) { public VectorFlag(String name, char legacyCode) {
super(name, legacyCode); super(name, legacyCode);
} }
@ -46,7 +46,7 @@ public VectorFlag(String name) {
public Vector parseInput(WorldGuardPlugin plugin, CommandSender sender, public Vector parseInput(WorldGuardPlugin plugin, CommandSender sender,
String input) throws InvalidFlagFormat { String input) throws InvalidFlagFormat {
input = input.trim(); input = input.trim();
try { try {
return BukkitUtil.toVector(plugin.checkPlayer(sender).getLocation()); return BukkitUtil.toVector(plugin.checkPlayer(sender).getLocation());
} catch (CommandException e) { } catch (CommandException e) {
@ -62,14 +62,14 @@ public Vector unmarshal(Object o) {
Object rawX = map.get("x"); Object rawX = map.get("x");
Object rawY = map.get("y"); Object rawY = map.get("y");
Object rawZ = map.get("z"); Object rawZ = map.get("z");
if (rawX == null || rawY == null || rawZ == null) { if (rawX == null || rawY == null || rawZ == null) {
return null; return null;
} }
return new Vector(toNumber(rawX), toNumber(rawY), toNumber(rawZ)); return new Vector(toNumber(rawX), toNumber(rawY), toNumber(rawZ));
} }
return null; return null;
} }
@ -81,7 +81,7 @@ public Object marshal(Vector o) {
vec.put("z", o.getZ()); vec.put("z", o.getZ());
return vec; return vec;
} }
private double toNumber(Object o) { private double toNumber(Object o) {
if (o instanceof Integer) { if (o instanceof Integer) {
return (Integer) o; return (Integer) o;

View File

@ -36,7 +36,7 @@
* A very simple implementation of the region manager that uses a flat list * A very simple implementation of the region manager that uses a flat list
* and iterates through the list to identify applicable regions. This method * and iterates through the list to identify applicable regions. This method
* is not very efficient. * is not very efficient.
* *
* @author sk89q * @author sk89q
*/ */
public class FlatRegionManager extends RegionManager { public class FlatRegionManager extends RegionManager {
@ -48,8 +48,8 @@ public class FlatRegionManager extends RegionManager {
/** /**
* Construct the manager. * Construct the manager.
* *
* @param regionloader * @param regionloader
*/ */
public FlatRegionManager(ProtectionDatabase regionloader) { public FlatRegionManager(ProtectionDatabase regionloader) {
super(regionloader); super(regionloader);
@ -76,7 +76,7 @@ public void setRegions(Map<String, ProtectedRegion> regions) {
/** /**
* Adds a region. * Adds a region.
* *
* @param region * @param region
*/ */
@Override @Override
@ -86,7 +86,7 @@ public void addRegion(ProtectedRegion region) {
/** /**
* Removes a region and its children. * Removes a region and its children.
* *
* @param id * @param id
*/ */
@Override @Override
@ -112,7 +112,7 @@ public void removeRegion(String id) {
/** /**
* Return whether a region exists by an ID. * Return whether a region exists by an ID.
* *
* @param id * @param id
* @return * @return
*/ */
@ -123,7 +123,7 @@ public boolean hasRegion(String id) {
/** /**
* Get a region by its ID. * Get a region by its ID.
* *
* @param id * @param id
*/ */
@Override @Override
@ -133,7 +133,7 @@ public ProtectedRegion getRegion(String id) {
/** /**
* Get an object for a point for rules to be applied with. * Get an object for a point for rules to be applied with.
* *
* @param pt * @param pt
* @return * @return
*/ */
@ -145,16 +145,16 @@ public ApplicableRegionSet getApplicableRegions(Vector pt) {
for (ProtectedRegion region : regions.values()) { for (ProtectedRegion region : regions.values()) {
if (region.contains(pt)) { if (region.contains(pt)) {
appRegions.add(region); appRegions.add(region);
ProtectedRegion parent = region.getParent(); ProtectedRegion parent = region.getParent();
while (parent != null) { while (parent != null) {
if (!appRegions.contains(parent)) { if (!appRegions.contains(parent)) {
appRegions.add(region); appRegions.add(region);
} }
parent = parent.getParent(); parent = parent.getParent();
} }
} }
} }
@ -184,7 +184,7 @@ public ApplicableRegionSet getApplicableRegions(ProtectedRegion checkRegion) {
/** /**
* Get a list of region IDs that contain a point. * Get a list of region IDs that contain a point.
* *
* @param pt * @param pt
* @return * @return
*/ */
@ -203,7 +203,7 @@ public List<String> getApplicableRegionsIDs(Vector pt) {
/** /**
* Get an object for a region for rules to be applied with. * Get an object for a region for rules to be applied with.
* *
* @return * @return
*/ */
@Override @Override
@ -213,7 +213,7 @@ public ApplicableRegionSet getApplicableRegions(ProtectedRegion checkRegion) {
appRegions.addAll(regions.values()); appRegions.addAll(regions.values());
List<ProtectedRegion> intersectRegions; List<ProtectedRegion> intersectRegions;
try { try {
intersectRegions = checkRegion.getIntersectingRegions(appRegions); intersectRegions = checkRegion.getIntersectingRegions(appRegions);
} catch (Exception e) { } catch (Exception e) {
@ -226,7 +226,7 @@ public ApplicableRegionSet getApplicableRegions(ProtectedRegion checkRegion) {
/** /**
* Returns true if the provided region overlaps with any other region that * Returns true if the provided region overlaps with any other region that
* is not owned by the player. * is not owned by the player.
* *
* @param player * @param player
* @return * @return
*/ */
@ -254,7 +254,7 @@ public boolean overlapsUnownedRegion(ProtectedRegion checkRegion, LocalPlayer pl
/** /**
* Get the number of regions. * Get the number of regions.
* *
* @return * @return
*/ */
@Override @Override

View File

@ -54,9 +54,9 @@ public class PRTreeRegionManager extends RegionManager {
/** /**
* Construct the manager. * Construct the manager.
* *
* @param regionloader * @param regionloader
* @throws IOException * @throws IOException
*/ */
public PRTreeRegionManager(ProtectionDatabase regionloader) throws IOException { public PRTreeRegionManager(ProtectionDatabase regionloader) throws IOException {
super(regionloader); super(regionloader);
@ -87,7 +87,7 @@ public void setRegions(Map<String, ProtectedRegion> regions) {
/** /**
* Adds a region. * Adds a region.
* *
* @param region * @param region
*/ */
@Override @Override
@ -99,7 +99,7 @@ public void addRegion(ProtectedRegion region) {
/** /**
* Return whether a region exists by an ID. * Return whether a region exists by an ID.
* *
* @param id * @param id
* @return * @return
*/ */
@ -110,7 +110,7 @@ public boolean hasRegion(String id) {
/** /**
* Get a region by its ID. * Get a region by its ID.
* *
* @param id * @param id
*/ */
@Override @Override
@ -120,7 +120,7 @@ public ProtectedRegion getRegion(String id) {
/** /**
* Removes a region and its children. * Removes a region and its children.
* *
* @param id * @param id
*/ */
@Override @Override
@ -150,7 +150,7 @@ public void removeRegion(String id) {
/** /**
* Get an object for a point for rules to be applied with. * Get an object for a point for rules to be applied with.
* *
* @param pt * @param pt
* @return * @return
*/ */
@ -167,7 +167,7 @@ public ApplicableRegionSet getApplicableRegions(Vector pt) {
appRegions.add(region); appRegions.add(region);
} }
} }
Collections.sort(appRegions); Collections.sort(appRegions);
return new ApplicableRegionSet(appRegions, regions.get("__global__")); return new ApplicableRegionSet(appRegions, regions.get("__global__"));
@ -190,7 +190,7 @@ public ApplicableRegionSet getApplicableRegions(ProtectedRegion checkRegion) {
/** /**
* Get a list of region IDs that contain a point. * Get a list of region IDs that contain a point.
* *
* @param pt * @param pt
* @return * @return
*/ */
@ -213,7 +213,7 @@ public List<String> getApplicableRegionsIDs(Vector pt) {
/** /**
* Returns true if the provided region overlaps with any other region that * Returns true if the provided region overlaps with any other region that
* is not owned by the player. * is not owned by the player.
* *
* @param player * @param player
* @return * @return
*/ */
@ -241,7 +241,7 @@ public boolean overlapsUnownedRegion(ProtectedRegion checkRegion, LocalPlayer pl
/** /**
* Get the number of regions. * Get the number of regions.
* *
* @return * @return
*/ */
@Override @Override

View File

@ -34,16 +34,16 @@
* simple implementation uses a flat list and iterates through the entire list * simple implementation uses a flat list and iterates through the entire list
* to look for applicable regions, but a more complicated (and more efficient) * to look for applicable regions, but a more complicated (and more efficient)
* implementation may use space partitioning techniques. * implementation may use space partitioning techniques.
* *
* @author sk89q * @author sk89q
*/ */
public abstract class RegionManager { public abstract class RegionManager {
protected ProtectionDatabase loader; protected ProtectionDatabase loader;
/** /**
* Construct the object. * Construct the object.
* *
* @param loader * @param loader
*/ */
public RegionManager(ProtectionDatabase loader) { public RegionManager(ProtectionDatabase loader) {
@ -72,7 +72,7 @@ public void save() throws IOException {
/** /**
* Get a map of protected regions. Use one of the region manager methods * Get a map of protected regions. Use one of the region manager methods
* if possible if working with regions. * if possible if working with regions.
* *
* @return map of regions, with keys being region IDs (lowercase) * @return map of regions, with keys being region IDs (lowercase)
*/ */
public abstract Map<String, ProtectedRegion> getRegions(); public abstract Map<String, ProtectedRegion> getRegions();
@ -80,7 +80,7 @@ public void save() throws IOException {
/** /**
* Set a list of protected regions. Keys should be lowercase in the given * Set a list of protected regions. Keys should be lowercase in the given
* map fo regions. * map fo regions.
* *
* @param regions map of regions * @param regions map of regions
*/ */
public abstract void setRegions(Map<String, ProtectedRegion> regions); public abstract void setRegions(Map<String, ProtectedRegion> regions);
@ -88,14 +88,14 @@ public void save() throws IOException {
/** /**
* Adds a region. If a region by the given name already exists, then * Adds a region. If a region by the given name already exists, then
* the existing region will be replaced. * the existing region will be replaced.
* *
* @param region region to add * @param region region to add
*/ */
public abstract void addRegion(ProtectedRegion region); public abstract void addRegion(ProtectedRegion region);
/** /**
* Return whether a region exists by an ID. * Return whether a region exists by an ID.
* *
* @param id id of the region, can be mixed-case * @param id id of the region, can be mixed-case
* @return whether the region exists * @return whether the region exists
*/ */
@ -103,7 +103,7 @@ public void save() throws IOException {
/** /**
* Get a region by its ID. * Get a region by its ID.
* *
* @param id id of the region, can be mixed-case * @param id id of the region, can be mixed-case
* @return region or null if it doesn't exist * @return region or null if it doesn't exist
*/ */
@ -111,7 +111,7 @@ public void save() throws IOException {
/** /**
* Removes a region, including inheriting children. * Removes a region, including inheriting children.
* *
* @param id id of the region, can be mixed-case * @param id id of the region, can be mixed-case
*/ */
public abstract void removeRegion(String id); public abstract void removeRegion(String id);
@ -119,7 +119,7 @@ public void save() throws IOException {
/** /**
* Get an object for a point for rules to be applied with. Use this in order * Get an object for a point for rules to be applied with. Use this in order
* to query for flag data or membership data for a given point. * to query for flag data or membership data for a given point.
* *
* @param loc Bukkit location * @param loc Bukkit location
* @return applicable region set * @return applicable region set
*/ */
@ -130,7 +130,7 @@ public ApplicableRegionSet getApplicableRegions(org.bukkit.Location loc) {
/** /**
* Get an object for a point for rules to be applied with. Use this in order * Get an object for a point for rules to be applied with. Use this in order
* to query for flag data or membership data for a given point. * to query for flag data or membership data for a given point.
* *
* @param pt point * @param pt point
* @return applicable region set * @return applicable region set
*/ */
@ -150,7 +150,7 @@ public abstract ApplicableRegionSet getApplicableRegions(
/** /**
* Get a list of region IDs that contain a point. * Get a list of region IDs that contain a point.
* *
* @param pt point * @param pt point
* @return list of region Ids * @return list of region Ids
*/ */
@ -159,7 +159,7 @@ public abstract ApplicableRegionSet getApplicableRegions(
/** /**
* Returns true if the provided region overlaps with any other region that * Returns true if the provided region overlaps with any other region that
* is not owned by the player. * is not owned by the player.
* *
* @param region region to check * @param region region to check
* @param player player to check against * @param player player to check against
* @return whether there is an overlap * @return whether there is an overlap

View File

@ -46,8 +46,8 @@ public class ProtectedCuboidRegion extends ProtectedRegion {
* Construct a new instance of this cuboid region. * Construct a new instance of this cuboid region.
* *
* @param id * @param id
* @param min * @param min
* @param max * @param max
*/ */
public ProtectedCuboidRegion(String id, BlockVector min, BlockVector max) { public ProtectedCuboidRegion(String id, BlockVector min, BlockVector max) {
super(id); super(id);
@ -109,7 +109,7 @@ public boolean contains(Vector pt) {
/* /*
public boolean intersectsWith(ProtectedRegion region) throws UnsupportedIntersectionException { public boolean intersectsWith(ProtectedRegion region) throws UnsupportedIntersectionException {
if (region instanceof ProtectedCuboidRegion) { if (region instanceof ProtectedCuboidRegion) {
ProtectedCuboidRegion r1 = (ProtectedCuboidRegion) this; ProtectedCuboidRegion r1 = (ProtectedCuboidRegion) this;
ProtectedCuboidRegion r2 = (ProtectedCuboidRegion) region; ProtectedCuboidRegion r2 = (ProtectedCuboidRegion) region;
@ -144,7 +144,7 @@ public List<ProtectedRegion> getIntersectingRegions(List<ProtectedRegion> region
BlockVector rMaxPoint = region.getMaximumPoint(); BlockVector rMaxPoint = region.getMaximumPoint();
// Check whether the region is outside the min and max vector // Check whether the region is outside the min and max vector
if ((rMinPoint.getBlockX() < min.getBlockX() && rMaxPoint.getBlockX() < min.getBlockX()) if ((rMinPoint.getBlockX() < min.getBlockX() && rMaxPoint.getBlockX() < min.getBlockX())
|| (rMinPoint.getBlockX() > max.getBlockX() && rMaxPoint.getBlockX() > max.getBlockX()) || (rMinPoint.getBlockX() > max.getBlockX() && rMaxPoint.getBlockX() > max.getBlockX())
&& ((rMinPoint.getBlockY() < min.getBlockY() && rMaxPoint.getBlockY() < min.getBlockY()) && ((rMinPoint.getBlockY() < min.getBlockY() && rMaxPoint.getBlockY() < min.getBlockY())
|| (rMinPoint.getBlockY() > max.getBlockY() && rMaxPoint.getBlockY() > max.getBlockY())) || (rMinPoint.getBlockY() > max.getBlockY() && rMaxPoint.getBlockY() > max.getBlockY()))
@ -182,7 +182,7 @@ public List<ProtectedRegion> getIntersectingRegions(List<ProtectedRegion> region
} }
} }
} else if (region instanceof ProtectedCuboidRegion) { } else if (region instanceof ProtectedCuboidRegion) {
BlockVector ptcMin = region.getMinimumPoint(); BlockVector ptcMin = region.getMinimumPoint();
BlockVector ptcMax = region.getMaximumPoint(); BlockVector ptcMax = region.getMaximumPoint();
if (this.contains(new Vector(ptcMin.getBlockX(), ptcMin.getBlockY(), ptcMin.getBlockZ())) if (this.contains(new Vector(ptcMin.getBlockX(), ptcMin.getBlockY(), ptcMin.getBlockZ()))
@ -197,7 +197,7 @@ public List<ProtectedRegion> getIntersectingRegions(List<ProtectedRegion> region
continue; continue;
} }
} else { } else {
throw new UnsupportedOperationException("Not supported yet."); throw new UnsupportedOperationException("Not supported yet.");
} }
// Check whether the current regions edges collide with the regions edges // Check whether the current regions edges collide with the regions edges
@ -258,7 +258,7 @@ public List<ProtectedRegion> getIntersectingRegions(List<ProtectedRegion> region
/** /**
* Return the type of region as a user-friendly name. * Return the type of region as a user-friendly name.
* *
* @return type of region * @return type of region
*/ */
@Override @Override
@ -268,7 +268,7 @@ public String getTypeName() {
/** /**
* Get the number of Blocks in this region * Get the number of Blocks in this region
* *
* @return * @return
*/ */
@Override @Override

View File

@ -155,7 +155,7 @@ public List<ProtectedRegion> getIntersectingRegions(List<ProtectedRegion> region
BlockVector rMaxPoint = region.getMaximumPoint(); BlockVector rMaxPoint = region.getMaximumPoint();
// Check whether the region is outside the min and max vector // Check whether the region is outside the min and max vector
if ((rMinPoint.getBlockX() < min.getBlockX() && rMaxPoint.getBlockX() < min.getBlockX()) if ((rMinPoint.getBlockX() < min.getBlockX() && rMaxPoint.getBlockX() < min.getBlockX())
|| (rMinPoint.getBlockX() > max.getBlockX() && rMaxPoint.getBlockX() > max.getBlockX()) || (rMinPoint.getBlockX() > max.getBlockX() && rMaxPoint.getBlockX() > max.getBlockX())
&& ((rMinPoint.getBlockY() < min.getBlockY() && rMaxPoint.getBlockY() < min.getBlockY()) && ((rMinPoint.getBlockY() < min.getBlockY() && rMaxPoint.getBlockY() < min.getBlockY())
|| (rMinPoint.getBlockY() > max.getBlockY() && rMaxPoint.getBlockY() > max.getBlockY())) || (rMinPoint.getBlockY() > max.getBlockY() && rMaxPoint.getBlockY() > max.getBlockY()))
@ -190,7 +190,7 @@ public List<ProtectedRegion> getIntersectingRegions(List<ProtectedRegion> region
} }
} }
} else if (region instanceof ProtectedCuboidRegion) { } else if (region instanceof ProtectedCuboidRegion) {
BlockVector ptcMin = region.getMinimumPoint(); BlockVector ptcMin = region.getMinimumPoint();
BlockVector ptcMax = region.getMaximumPoint(); BlockVector ptcMax = region.getMaximumPoint();
if (this.contains(new Vector(ptcMin.getBlockX(), ptcMin.getBlockY(), ptcMin.getBlockZ())) if (this.contains(new Vector(ptcMin.getBlockX(), ptcMin.getBlockY(), ptcMin.getBlockZ()))
@ -205,7 +205,7 @@ public List<ProtectedRegion> getIntersectingRegions(List<ProtectedRegion> region
continue; continue;
} }
} else { } else {
throw new UnsupportedOperationException("Not supported yet."); throw new UnsupportedOperationException("Not supported yet.");
} }
// Check whether the current regions edges collide with the regions edges // Check whether the current regions edges collide with the regions edges
@ -261,7 +261,7 @@ public List<ProtectedRegion> getIntersectingRegions(List<ProtectedRegion> region
/** /**
* Return the type of region as a user-friendly name. * Return the type of region as a user-friendly name.
* *
* @return type of region * @return type of region
*/ */
@Override @Override
@ -271,7 +271,7 @@ public String getTypeName() {
/** /**
* Get the number of Blocks in this region * Get the number of Blocks in this region
* *
* @return * @return
*/ */
@Override @Override

View File

@ -33,38 +33,38 @@
/** /**
* Represents a region of any shape and size that can be protected. * Represents a region of any shape and size that can be protected.
* *
* @author sk89q * @author sk89q
*/ */
public abstract class ProtectedRegion implements Comparable<ProtectedRegion> { public abstract class ProtectedRegion implements Comparable<ProtectedRegion> {
private static final Pattern idPattern = Pattern.compile("^[A-Za-z0-9_,'\\-\\+/]{1,}$"); private static final Pattern idPattern = Pattern.compile("^[A-Za-z0-9_,'\\-\\+/]{1,}$");
/** /**
* Holds the region's ID. * Holds the region's ID.
*/ */
private String id; private String id;
/** /**
* Priority. * Priority.
*/ */
private int priority = 0; private int priority = 0;
/** /**
* Holds the curParent. * Holds the curParent.
*/ */
private ProtectedRegion parent; private ProtectedRegion parent;
/** /**
* List of owners. * List of owners.
*/ */
private DefaultDomain owners = new DefaultDomain(); private DefaultDomain owners = new DefaultDomain();
/** /**
* List of members. * List of members.
*/ */
private DefaultDomain members = new DefaultDomain(); private DefaultDomain members = new DefaultDomain();
/** /**
* List of flags. * List of flags.
*/ */
@ -113,7 +113,7 @@ public int getPriority() {
public void setPriority(int priority) { public void setPriority(int priority) {
this.priority = priority; this.priority = priority;
} }
/** /**
* @return the curParent * @return the curParent
*/ */
@ -124,20 +124,20 @@ public ProtectedRegion getParent() {
/** /**
* Set the curParent. This checks to make sure that it will not result * Set the curParent. This checks to make sure that it will not result
* in circular inheritance. * in circular inheritance.
* *
* @param parent the curParent to setFlag * @param parent the curParent to setFlag
* @throws CircularInheritanceException * @throws CircularInheritanceException
*/ */
public void setParent(ProtectedRegion parent) throws CircularInheritanceException { public void setParent(ProtectedRegion parent) throws CircularInheritanceException {
if (parent == null) { if (parent == null) {
this.parent = null; this.parent = null;
return; return;
} }
if (parent == this) { if (parent == this) {
throw new CircularInheritanceException(); throw new CircularInheritanceException();
} }
ProtectedRegion p = parent.getParent(); ProtectedRegion p = parent.getParent();
while (p != null) { while (p != null) {
if (p == this) { if (p == this) {
@ -145,7 +145,7 @@ public void setParent(ProtectedRegion parent) throws CircularInheritanceExceptio
} }
p = p.getParent(); p = p.getParent();
} }
this.parent = parent; this.parent = parent;
} }
@ -181,16 +181,16 @@ public void setMembers(DefaultDomain members) {
/** /**
* Checks whether a region has members or owners. * Checks whether a region has members or owners.
* *
* @return whether there are members or owners * @return whether there are members or owners
*/ */
public boolean hasMembersOrOwners() { public boolean hasMembersOrOwners() {
return owners.size() > 0 || members.size() > 0; return owners.size() > 0 || members.size() > 0;
} }
/** /**
* Checks whether a player is an owner of region or any of its parents. * Checks whether a player is an owner of region or any of its parents.
* *
* @param player player to check * @param player player to check
* @return whether an owner * @return whether an owner
*/ */
@ -198,23 +198,23 @@ public boolean isOwner(LocalPlayer player) {
if (owners.contains(player)) { if (owners.contains(player)) {
return true; return true;
} }
ProtectedRegion curParent = getParent(); ProtectedRegion curParent = getParent();
while (curParent != null) { while (curParent != null) {
if (curParent.getOwners().contains(player)) { if (curParent.getOwners().contains(player)) {
return true; return true;
} }
curParent = curParent.getParent(); curParent = curParent.getParent();
} }
return false; return false;
} }
/** /**
* Checks whether a player is a member OR OWNER of the region * Checks whether a player is a member OR OWNER of the region
* or any of its parents. * or any of its parents.
* *
* @param player player to check * @param player player to check
* @return whether an owner or member * @return whether an owner or member
*/ */
@ -222,17 +222,17 @@ public boolean isMember(LocalPlayer player) {
if (owners.contains(player) || members.contains(player)) { if (owners.contains(player) || members.contains(player)) {
return true; return true;
} }
ProtectedRegion curParent = getParent(); ProtectedRegion curParent = getParent();
while (curParent != null) { while (curParent != null) {
if (curParent.getOwners().contains(player) if (curParent.getOwners().contains(player)
|| curParent.getMembers().contains(player)) { || curParent.getMembers().contains(player)) {
return true; return true;
} }
curParent = curParent.getParent(); curParent = curParent.getParent();
} }
return false; return false;
} }
@ -259,10 +259,10 @@ public boolean isMemberOnly(LocalPlayer player) {
return false; return false;
} }
/** /**
* Get a flag's value. * Get a flag's value.
* *
* @param <T> * @param <T>
* @param <V> * @param <V>
* @param flag * @param flag
@ -279,10 +279,10 @@ public <T extends Flag<V>, V> V getFlag(T flag) {
} }
return val; return val;
} }
/** /**
* Set a flag's value. * Set a flag's value.
* *
* @param <T> * @param <T>
* @param <V> * @param <V>
* @param flag * @param flag
@ -295,20 +295,20 @@ public <T extends Flag<V>, V> void setFlag(T flag, V val) {
flags.put(flag, val); flags.put(flag, val);
} }
} }
/** /**
* Get the map of flags. * Get the map of flags.
* *
* @return * @return
*/ */
public Map<Flag<?>, Object> getFlags() { public Map<Flag<?>, Object> getFlags() {
return flags; return flags;
} }
/** /**
* Get the map of flags. * Get the map of flags.
* *
* @param flags * @param flags
*/ */
public void setFlags(Map<Flag<?>, Object> flags) { public void setFlags(Map<Flag<?>, Object> flags) {
this.flags = flags; this.flags = flags;
@ -316,22 +316,22 @@ public void setFlags(Map<Flag<?>, Object> flags) {
/** /**
* Get the number of blocks in this region * Get the number of blocks in this region
* *
* @return * @return
*/ */
public abstract int volume(); public abstract int volume();
/** /**
* Check to see if a point is inside this region. * Check to see if a point is inside this region.
* *
* @param pt * @param pt
* @return * @return
*/ */
public abstract boolean contains(Vector pt); public abstract boolean contains(Vector pt);
/** /**
* Compares to another region. * Compares to another region.
* *
* @param other * @param other
* @return * @return
*/ */
@ -349,14 +349,14 @@ public int compareTo(ProtectedRegion other) {
/** /**
* Return the type of region as a user-friendly, lowercase name. * Return the type of region as a user-friendly, lowercase name.
* *
* @return type of region * @return type of region
*/ */
public abstract String getTypeName(); public abstract String getTypeName();
/** /**
* Get a list of intersecting regions. * Get a list of intersecting regions.
* *
* @param regions * @param regions
* @return * @return
* @throws UnsupportedIntersectionException * @throws UnsupportedIntersectionException
@ -364,17 +364,17 @@ public int compareTo(ProtectedRegion other) {
public abstract List<ProtectedRegion> getIntersectingRegions( public abstract List<ProtectedRegion> getIntersectingRegions(
List<ProtectedRegion> regions) List<ProtectedRegion> regions)
throws UnsupportedIntersectionException; throws UnsupportedIntersectionException;
/** /**
* Checks to see if the given ID is accurate. * Checks to see if the given ID is accurate.
* *
* @param id * @param id
* @return * @return
*/ */
public static boolean isValidId(String id) { public static boolean isValidId(String id) {
return idPattern.matcher(id).matches(); return idPattern.matcher(id).matches();
} }
/** /**
* Returns the hash code. * Returns the hash code.
*/ */
@ -382,7 +382,7 @@ public static boolean isValidId(String id) {
public int hashCode(){ public int hashCode(){
return id.hashCode(); return id.hashCode();
} }
/** /**
* Returns whether this region has the same ID as another region. * Returns whether this region has the same ID as another region.
*/ */
@ -391,15 +391,15 @@ public boolean equals(Object obj) {
if (!(obj instanceof ProtectedRegion)) { if (!(obj instanceof ProtectedRegion)) {
return false; return false;
} }
ProtectedRegion other = (ProtectedRegion) obj; ProtectedRegion other = (ProtectedRegion) obj;
return other.getId().equals(getId()); return other.getId().equals(getId());
} }
/** /**
* Thrown when setting a curParent would create a circular inheritance * Thrown when setting a curParent would create a circular inheritance
* situation. * situation.
* *
*/ */
public static class CircularInheritanceException extends Exception { public static class CircularInheritanceException extends Exception {
private static final long serialVersionUID = 7479613488496776022L; private static final long serialVersionUID = 7479613488496776022L;

View File

@ -38,10 +38,10 @@
* a file and call its load() method. For specifying node paths in the * a file and call its load() method. For specifying node paths in the
* various get*() methods, they support SK's path notation, allowing you to * various get*() methods, they support SK's path notation, allowing you to
* select child nodes by delimiting node names with periods. * select child nodes by delimiting node names with periods.
* *
* <p> * <p>
* For example, given the following configuration file:</p> * For example, given the following configuration file:</p>
* *
* <pre>members: * <pre>members:
* - Hollie * - Hollie
* - Jason * - Jason
@ -56,41 +56,41 @@
* cool: false * cool: false
* eats: * eats:
* babies: true</pre> * babies: true</pre>
* *
* <p>Calling code could access sturmeh's baby eating state by using * <p>Calling code could access sturmeh's baby eating state by using
* <code>getBoolean("sturmeh.eats.babies", false)</code>. For lists, there are * <code>getBoolean("sturmeh.eats.babies", false)</code>. For lists, there are
* methods such as <code>getStringList</code> that will return a type safe list. * methods such as <code>getStringList</code> that will return a type safe list.
* *
* <p>This class is currently incomplete. It is not yet possible to get a node. * <p>This class is currently incomplete. It is not yet possible to get a node.
* </p> * </p>
* *
* @author sk89q * @author sk89q
*/ */
public class Configuration extends ConfigurationNode { public class Configuration extends ConfigurationNode {
private Yaml yaml; private Yaml yaml;
private File file; private File file;
private String header = null; private String header = null;
public Configuration(File file) { public Configuration(File file) {
super(new HashMap<String, Object>()); super(new HashMap<String, Object>());
DumperOptions options = new DumperOptions(); DumperOptions options = new DumperOptions();
options.setIndent(2); options.setIndent(2);
options.setDefaultFlowStyle(DumperOptions.FlowStyle.AUTO); options.setDefaultFlowStyle(DumperOptions.FlowStyle.AUTO);
yaml = new Yaml(new SafeConstructor(), new Representer(), options); yaml = new Yaml(new SafeConstructor(), new Representer(), options);
this.file = file; this.file = file;
} }
/** /**
* Loads the configuration file. * Loads the configuration file.
* *
* @throws IOException * @throws IOException
*/ */
public void load() throws IOException { public void load() throws IOException {
FileInputStream stream = null; FileInputStream stream = null;
try { try {
stream = new FileInputStream(file); stream = new FileInputStream(file);
read(yaml.load(new UnicodeReader(stream))); read(yaml.load(new UnicodeReader(stream)));
@ -179,7 +179,7 @@ public boolean save() {
return false; return false;
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private void read(Object input) throws ConfigurationException { private void read(Object input) throws ConfigurationException {
try { try {
@ -192,9 +192,9 @@ private void read(Object input) throws ConfigurationException {
throw new ConfigurationException("Root document must be an key-value structure"); throw new ConfigurationException("Root document must be an key-value structure");
} }
} }
/** /**
* This method returns an empty ConfigurationNode for using as a * This method returns an empty ConfigurationNode for using as a
* default in methods that select a node from a node list. * default in methods that select a node from a node list.
* @return * @return
*/ */

View File

@ -30,30 +30,30 @@
/** /**
* Represents a configuration node. * Represents a configuration node.
* *
* @author sk89q * @author sk89q
*/ */
public class ConfigurationNode { public class ConfigurationNode {
protected Map<String, Object> root; protected Map<String, Object> root;
protected ConfigurationNode(Map<String, Object> root) { protected ConfigurationNode(Map<String, Object> root) {
this.root = root; this.root = root;
} }
/** /**
* Clear all nodes. * Clear all nodes.
*/ */
public void clear() { public void clear() {
root.clear(); root.clear();
} }
/** /**
* Gets a property at a location. This will either return an Object * Gets a property at a location. This will either return an Object
* or null, with null meaning that no configuration value exists at * or null, with null meaning that no configuration value exists at
* that location. This could potentially return a default value (not yet * that location. This could potentially return a default value (not yet
* implemented) as defined by a plugin, if this is a plugin-tied * implemented) as defined by a plugin, if this is a plugin-tied
* configuration. * configuration.
* *
* @param path path to node (dot notation) * @param path path to node (dot notation)
* @return object or null * @return object or null
*/ */
@ -66,35 +66,35 @@ public Object getProperty(String path) {
} }
return val; return val;
} }
String[] parts = path.split("\\."); String[] parts = path.split("\\.");
Map<String, Object> node = root; Map<String, Object> node = root;
for (int i = 0; i < parts.length; i++) { for (int i = 0; i < parts.length; i++) {
Object o = node.get(parts[i]); Object o = node.get(parts[i]);
if (o == null) { if (o == null) {
return null; return null;
} }
if (i == parts.length - 1) { if (i == parts.length - 1) {
return o; return o;
} }
try { try {
node = (Map<String, Object>)o; node = (Map<String, Object>)o;
} catch (ClassCastException e) { } catch (ClassCastException e) {
return null; return null;
} }
} }
return null; return null;
} }
/** /**
* Prepare a value for serialization, in case it's not a native type * Prepare a value for serialization, in case it's not a native type
* (and we don't want to serialize objects as YAML objects). * (and we don't want to serialize objects as YAML objects).
* *
* @param value * @param value
* @return * @return
*/ */
@ -107,53 +107,53 @@ private Object prepareSerialization(Object value) {
out.put("z", vec.getZ()); out.put("z", vec.getZ());
return out; return out;
} }
return value; return value;
} }
/** /**
* Set the property at a location. This will override existing * Set the property at a location. This will override existing
* configuration data to have it conform to key/value mappings. * configuration data to have it conform to key/value mappings.
* *
* @param path * @param path
* @param value * @param value
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void setProperty(String path, Object value) { public void setProperty(String path, Object value) {
value = prepareSerialization(value); value = prepareSerialization(value);
if (!path.contains(".")) { if (!path.contains(".")) {
root.put(path, value); root.put(path, value);
return; return;
} }
String[] parts = path.split("\\."); String[] parts = path.split("\\.");
Map<String, Object> node = root; Map<String, Object> node = root;
for (int i = 0; i < parts.length; i++) { for (int i = 0; i < parts.length; i++) {
Object o = node.get(parts[i]); Object o = node.get(parts[i]);
// Found our target! // Found our target!
if (i == parts.length - 1) { if (i == parts.length - 1) {
node.put(parts[i], value); node.put(parts[i], value);
return; return;
} }
if (o == null || !(o instanceof Map)) { if (o == null || !(o instanceof Map)) {
// This will override existing configuration data! // This will override existing configuration data!
o = new HashMap<String, Object>(); o = new HashMap<String, Object>();
node.put(parts[i], o); node.put(parts[i], o);
} }
node = (Map<String, Object>)o; node = (Map<String, Object>)o;
} }
} }
/** /**
* Adds a new node to the given path. The returned object is a reference * Adds a new node to the given path. The returned object is a reference
* to the new node. This method will replace an existing node at * to the new node. This method will replace an existing node at
* the same path. See <code>setProperty</code>. * the same path. See <code>setProperty</code>.
* *
* @param path * @param path
* @return * @return
*/ */
@ -169,7 +169,7 @@ public ConfigurationNode addNode(String path) {
* or null, with null meaning that no configuration value exists at * or null, with null meaning that no configuration value exists at
* that location. If the object at the particular location is not actually * that location. If the object at the particular location is not actually
* a string, it will be converted to its string representation. * a string, it will be converted to its string representation.
* *
* @param path path to node (dot notation) * @param path path to node (dot notation)
* @return string or null * @return string or null
*/ */
@ -185,7 +185,7 @@ public String getString(String path) {
* Gets a vector at a location. This will either return an Vector * Gets a vector at a location. This will either return an Vector
* or a null. If the object at the particular location is not * or a null. If the object at the particular location is not
* actually a string, it will be converted to its string representation. * actually a string, it will be converted to its string representation.
* *
* @param path path to node (dot notation) * @param path path to node (dot notation)
* @return string or default * @return string or default
*/ */
@ -194,15 +194,15 @@ public Vector getVector(String path) {
if (o == null) { if (o == null) {
return null; return null;
} }
Double x = o.getDouble("x"); Double x = o.getDouble("x");
Double y = o.getDouble("y"); Double y = o.getDouble("y");
Double z = o.getDouble("z"); Double z = o.getDouble("z");
if (x == null || y == null || z == null) { if (x == null || y == null || z == null) {
return null; return null;
} }
return new Vector(x, y, z); return new Vector(x, y, z);
} }
@ -210,7 +210,7 @@ public Vector getVector(String path) {
* Gets a 2D vector at a location. This will either return an Vector * Gets a 2D vector at a location. This will either return an Vector
* or a null. If the object at the particular location is not * or a null. If the object at the particular location is not
* actually a string, it will be converted to its string representation. * actually a string, it will be converted to its string representation.
* *
* @param path path to node (dot notation) * @param path path to node (dot notation)
* @return string or default * @return string or default
*/ */
@ -219,14 +219,14 @@ public Vector2D getVector2d(String path) {
if (o == null) { if (o == null) {
return null; return null;
} }
Double x = o.getDouble("x"); Double x = o.getDouble("x");
Double z = o.getDouble("z"); Double z = o.getDouble("z");
if (x == null || z == null) { if (x == null || z == null) {
return null; return null;
} }
return new Vector2D(x, z); return new Vector2D(x, z);
} }
@ -234,7 +234,7 @@ public Vector2D getVector2d(String path) {
* Gets a string at a location. This will either return an Vector * Gets a string at a location. This will either return an Vector
* or the default value. If the object at the particular location is not * or the default value. If the object at the particular location is not
* actually a string, it will be converted to its string representation. * actually a string, it will be converted to its string representation.
* *
* @param path path to node (dot notation) * @param path path to node (dot notation)
* @param def default value * @param def default value
* @return string or default * @return string or default
@ -252,7 +252,7 @@ public Vector getVector(String path, Vector def) {
* Gets a string at a location. This will either return an String * Gets a string at a location. This will either return an String
* or the default value. If the object at the particular location is not * or the default value. If the object at the particular location is not
* actually a string, it will be converted to its string representation. * actually a string, it will be converted to its string representation.
* *
* @param path path to node (dot notation) * @param path path to node (dot notation)
* @param def default value * @param def default value
* @return string or default * @return string or default
@ -271,7 +271,7 @@ public String getString(String path, String def) {
* or null. If the object at the particular location is not * or null. If the object at the particular location is not
* actually a integer, the default value will be returned. However, other * actually a integer, the default value will be returned. However, other
* number types will be casted to an integer. * number types will be casted to an integer.
* *
* @param path path to node (dot notation) * @param path path to node (dot notation)
* @return integer or null * @return integer or null
*/ */
@ -289,7 +289,7 @@ public Integer getInt(String path) {
* or the default value. If the object at the particular location is not * or the default value. If the object at the particular location is not
* actually a integer, the default value will be returned. However, other * actually a integer, the default value will be returned. However, other
* number types will be casted to an integer. * number types will be casted to an integer.
* *
* @param path path to node (dot notation) * @param path path to node (dot notation)
* @param def default value * @param def default value
* @return int or default * @return int or default
@ -309,7 +309,7 @@ public int getInt(String path, int def) {
* or null. If the object at the particular location is not * or null. If the object at the particular location is not
* actually a double, the default value will be returned. However, other * actually a double, the default value will be returned. However, other
* number types will be casted to an double. * number types will be casted to an double.
* *
* @param path path to node (dot notation) * @param path path to node (dot notation)
* @return double or null * @return double or null
*/ */
@ -327,7 +327,7 @@ public Double getDouble(String path) {
* or the default value. If the object at the particular location is not * or the default value. If the object at the particular location is not
* actually a double, the default value will be returned. However, other * actually a double, the default value will be returned. However, other
* number types will be casted to an double. * number types will be casted to an double.
* *
* @param path path to node (dot notation) * @param path path to node (dot notation)
* @param def default value * @param def default value
* @return double or default * @return double or default
@ -346,7 +346,7 @@ public double getDouble(String path, double def) {
* Gets a boolean at a location. This will either return an boolean * Gets a boolean at a location. This will either return an boolean
* or null. If the object at the particular location is not * or null. If the object at the particular location is not
* actually a boolean, the default value will be returned. * actually a boolean, the default value will be returned.
* *
* @param path path to node (dot notation) * @param path path to node (dot notation)
* @return boolean or null * @return boolean or null
*/ */
@ -363,7 +363,7 @@ public Boolean getBoolean(String path) {
* Gets a boolean at a location. This will either return an boolean * Gets a boolean at a location. This will either return an boolean
* or the default value. If the object at the particular location is not * or the default value. If the object at the particular location is not
* actually a boolean, the default value will be returned. * actually a boolean, the default value will be returned.
* *
* @param path path to node (dot notation) * @param path path to node (dot notation)
* @param def default value * @param def default value
* @return boolean or default * @return boolean or default
@ -377,11 +377,11 @@ public boolean getBoolean(String path, boolean def) {
return o; return o;
} }
} }
/** /**
* Get a list of keys at a location. If the map at the particular location * Get a list of keys at a location. If the map at the particular location
* does not exist or it is not a map, null will be returned. * does not exist or it is not a map, null will be returned.
* *
* @param path path to node (dot notation) * @param path path to node (dot notation)
* @return list of keys * @return list of keys
*/ */
@ -401,7 +401,7 @@ public List<String> getKeys(String path) {
/** /**
* Gets a list of objects at a location. If the list is not defined, * Gets a list of objects at a location. If the list is not defined,
* null will be returned. The node must be an actual list. * null will be returned. The node must be an actual list.
* *
* @param path path to node (dot notation) * @param path path to node (dot notation)
* @return boolean or default * @return boolean or default
*/ */
@ -416,7 +416,7 @@ public List<Object> getList(String path) {
return null; return null;
} }
} }
/** /**
* Gets a list of strings. Non-valid entries will not be in the list. * Gets a list of strings. Non-valid entries will not be in the list.
* There will be no null slots. If the list is not defined, the * There will be no null slots. If the list is not defined, the
@ -424,7 +424,7 @@ public List<Object> getList(String path) {
* and an empty list will be returned instead. If an item in the list * and an empty list will be returned instead. If an item in the list
* is not a string, it will be converted to a string. The node must be * is not a string, it will be converted to a string. The node must be
* an actual list and not just a string. * an actual list and not just a string.
* *
* @param path path to node (dot notation) * @param path path to node (dot notation)
* @param def default value or null for an empty list as default * @param def default value or null for an empty list as default
* @return list of strings * @return list of strings
@ -440,20 +440,20 @@ public List<String> getStringList(String path, List<String> def) {
if (o == null) { if (o == null) {
continue; continue;
} }
list.add(o.toString()); list.add(o.toString());
} }
return list; return list;
} }
/** /**
* Gets a list of integers. Non-valid entries will not be in the list. * Gets a list of integers. Non-valid entries will not be in the list.
* There will be no null slots. If the list is not defined, the * There will be no null slots. If the list is not defined, the
* default will be returned. 'null' can be passed for the default * default will be returned. 'null' can be passed for the default
* and an empty list will be returned instead. The node must be * and an empty list will be returned instead. The node must be
* an actual list and not just an integer. * an actual list and not just an integer.
* *
* @param path path to node (dot notation) * @param path path to node (dot notation)
* @param def default value or null for an empty list as default * @param def default value or null for an empty list as default
* @return list of integers * @return list of integers
@ -471,17 +471,17 @@ public List<Integer> getIntList(String path, List<Integer> def) {
list.add(i); list.add(i);
} }
} }
return list; return list;
} }
/** /**
* Gets a list of doubles. Non-valid entries will not be in the list. * Gets a list of doubles. Non-valid entries will not be in the list.
* There will be no null slots. If the list is not defined, the * There will be no null slots. If the list is not defined, the
* default will be returned. 'null' can be passed for the default * default will be returned. 'null' can be passed for the default
* and an empty list will be returned instead. The node must be * and an empty list will be returned instead. The node must be
* an actual list and cannot be just a double. * an actual list and cannot be just a double.
* *
* @param path path to node (dot notation) * @param path path to node (dot notation)
* @param def default value or null for an empty list as default * @param def default value or null for an empty list as default
* @return list of integers * @return list of integers
@ -499,17 +499,17 @@ public List<Double> getDoubleList(String path, List<Double> def) {
list.add(i); list.add(i);
} }
} }
return list; return list;
} }
/** /**
* Gets a list of booleans. Non-valid entries will not be in the list. * Gets a list of booleans. Non-valid entries will not be in the list.
* There will be no null slots. If the list is not defined, the * There will be no null slots. If the list is not defined, the
* default will be returned. 'null' can be passed for the default * default will be returned. 'null' can be passed for the default
* and an empty list will be returned instead. The node must be * and an empty list will be returned instead. The node must be
* an actual list and cannot be just a boolean, * an actual list and cannot be just a boolean,
* *
* @param path path to node (dot notation) * @param path path to node (dot notation)
* @param def default value or null for an empty list as default * @param def default value or null for an empty list as default
* @return list of integers * @return list of integers
@ -527,111 +527,111 @@ public List<Boolean> getBooleanList(String path, List<Boolean> def) {
list.add(tetsu); list.add(tetsu);
} }
} }
return list; return list;
} }
/** /**
* Gets a list of vectors. Non-valid entries will not be in the list. * Gets a list of vectors. Non-valid entries will not be in the list.
* There will be no null slots. If the list is not defined, the * There will be no null slots. If the list is not defined, the
* default will be returned. 'null' can be passed for the default * default will be returned. 'null' can be passed for the default
* and an empty list will be returned instead. The node must be * and an empty list will be returned instead. The node must be
* an actual node and cannot be just a vector, * an actual node and cannot be just a vector,
* *
* @param path path to node (dot notation) * @param path path to node (dot notation)
* @param def default value or null for an empty list as default * @param def default value or null for an empty list as default
* @return list of integers * @return list of integers
*/ */
public List<Vector> getVectorList( public List<Vector> getVectorList(
String path, List<Vector> def) { String path, List<Vector> def) {
List<ConfigurationNode> raw = getNodeList(path, null); List<ConfigurationNode> raw = getNodeList(path, null);
List<Vector> list = new ArrayList<Vector>(); List<Vector> list = new ArrayList<Vector>();
for (ConfigurationNode o : raw) { for (ConfigurationNode o : raw) {
Double x = o.getDouble("x"); Double x = o.getDouble("x");
Double y = o.getDouble("y"); Double y = o.getDouble("y");
Double z = o.getDouble("z"); Double z = o.getDouble("z");
if (x == null || y == null || z == null) { if (x == null || y == null || z == null) {
continue; continue;
} }
list.add(new Vector(x, y, z)); list.add(new Vector(x, y, z));
} }
return list; return list;
} }
/** /**
* Gets a list of 2D vectors. Non-valid entries will not be in the list. * Gets a list of 2D vectors. Non-valid entries will not be in the list.
* There will be no null slots. If the list is not defined, the * There will be no null slots. If the list is not defined, the
* default will be returned. 'null' can be passed for the default * default will be returned. 'null' can be passed for the default
* and an empty list will be returned instead. The node must be * and an empty list will be returned instead. The node must be
* an actual node and cannot be just a vector, * an actual node and cannot be just a vector,
* *
* @param path path to node (dot notation) * @param path path to node (dot notation)
* @param def default value or null for an empty list as default * @param def default value or null for an empty list as default
* @return list of integers * @return list of integers
*/ */
public List<Vector2D> getVector2dList( public List<Vector2D> getVector2dList(
String path, List<Vector2D> def) { String path, List<Vector2D> def) {
List<ConfigurationNode> raw = getNodeList(path, null); List<ConfigurationNode> raw = getNodeList(path, null);
List<Vector2D> list = new ArrayList<Vector2D>(); List<Vector2D> list = new ArrayList<Vector2D>();
for (ConfigurationNode o : raw) { for (ConfigurationNode o : raw) {
Double x = o.getDouble("x"); Double x = o.getDouble("x");
Double z = o.getDouble("z"); Double z = o.getDouble("z");
if (x == null || z == null) { if (x == null || z == null) {
continue; continue;
} }
list.add(new Vector2D(x, z)); list.add(new Vector2D(x, z));
} }
return list; return list;
} }
/** /**
* Gets a list of 2D vectors. Non-valid entries will not be in the list. * Gets a list of 2D vectors. Non-valid entries will not be in the list.
* There will be no null slots. If the list is not defined, the * There will be no null slots. If the list is not defined, the
* default will be returned. 'null' can be passed for the default * default will be returned. 'null' can be passed for the default
* and an empty list will be returned instead. The node must be * and an empty list will be returned instead. The node must be
* an actual node and cannot be just a vector, * an actual node and cannot be just a vector,
* *
* @param path path to node (dot notation) * @param path path to node (dot notation)
* @param def default value or null for an empty list as default * @param def default value or null for an empty list as default
* @return list of integers * @return list of integers
*/ */
public List<BlockVector2D> getBlockVector2dList( public List<BlockVector2D> getBlockVector2dList(
String path, List<BlockVector2D> def) { String path, List<BlockVector2D> def) {
List<ConfigurationNode> raw = getNodeList(path, null); List<ConfigurationNode> raw = getNodeList(path, null);
List<BlockVector2D> list = new ArrayList<BlockVector2D>(); List<BlockVector2D> list = new ArrayList<BlockVector2D>();
for (ConfigurationNode o : raw) { for (ConfigurationNode o : raw) {
Double x = o.getDouble("x"); Double x = o.getDouble("x");
Double z = o.getDouble("z"); Double z = o.getDouble("z");
if (x == null || z == null) { if (x == null || z == null) {
continue; continue;
} }
list.add(new BlockVector2D(x, z)); list.add(new BlockVector2D(x, z));
} }
return list; return list;
} }
/** /**
* Gets a list of nodes. Non-valid entries will not be in the list. * Gets a list of nodes. Non-valid entries will not be in the list.
* There will be no null slots. If the list is not defined, the * There will be no null slots. If the list is not defined, the
* default will be returned. 'null' can be passed for the default * default will be returned. 'null' can be passed for the default
* and an empty list will be returned instead. The node must be * and an empty list will be returned instead. The node must be
* an actual node and cannot be just a boolean, * an actual node and cannot be just a boolean,
* *
* @param path path to node (dot notation) * @param path path to node (dot notation)
* @param def default value or null for an empty list as default * @param def default value or null for an empty list as default
* @return list of integers * @return list of integers
@ -649,15 +649,15 @@ public List<ConfigurationNode> getNodeList(String path, List<ConfigurationNode>
list.add(new ConfigurationNode((Map<String, Object>)o)); list.add(new ConfigurationNode((Map<String, Object>)o));
} }
} }
return list; return list;
} }
/** /**
* Get a configuration node at a path. If the node doesn't exist or the * Get a configuration node at a path. If the node doesn't exist or the
* path does not lead to a node, null will be returned. A node has * path does not lead to a node, null will be returned. A node has
* key/value mappings. * key/value mappings.
* *
* @param path * @param path
* @return node or null * @return node or null
*/ */
@ -667,14 +667,14 @@ public ConfigurationNode getNode(String path) {
if (raw instanceof Map) { if (raw instanceof Map) {
return new ConfigurationNode((Map<String, Object>)raw); return new ConfigurationNode((Map<String, Object>)raw);
} }
return null; return null;
} }
/** /**
* Get a list of nodes at a location. If the map at the particular location * Get a list of nodes at a location. If the map at the particular location
* does not exist or it is not a map, null will be returned. * does not exist or it is not a map, null will be returned.
* *
* @param path path to node (dot notation) * @param path path to node (dot notation)
* @return map of nodes * @return map of nodes
*/ */
@ -686,23 +686,23 @@ public Map<String, ConfigurationNode> getNodes(String path) {
} else if (o instanceof Map) { } else if (o instanceof Map) {
Map<String, ConfigurationNode> nodes = Map<String, ConfigurationNode> nodes =
new HashMap<String, ConfigurationNode>(); new HashMap<String, ConfigurationNode>();
for (Map.Entry<String, Object> entry : ((Map<String, Object>)o).entrySet()) { for (Map.Entry<String, Object> entry : ((Map<String, Object>)o).entrySet()) {
if (entry.getValue() instanceof Map) { if (entry.getValue() instanceof Map) {
nodes.put(entry.getKey(), nodes.put(entry.getKey(),
new ConfigurationNode((Map<String, Object>) entry.getValue())); new ConfigurationNode((Map<String, Object>) entry.getValue()));
} }
} }
return nodes; return nodes;
} else { } else {
return null; return null;
} }
} }
/** /**
* Casts a value to an integer. May return null. * Casts a value to an integer. May return null.
* *
* @param o * @param o
* @return * @return
*/ */
@ -723,10 +723,10 @@ private static Integer castInt(Object o) {
return null; return null;
} }
} }
/** /**
* Casts a value to a double. May return null. * Casts a value to a double. May return null.
* *
* @param o * @param o
* @return * @return
*/ */
@ -747,10 +747,10 @@ private static Double castDouble(Object o) {
return null; return null;
} }
} }
/** /**
* Casts a value to a boolean. May return null. * Casts a value to a boolean. May return null.
* *
* @param o * @param o
* @return * @return
*/ */
@ -763,11 +763,11 @@ private static Boolean castBoolean(Object o) {
return null; return null;
} }
} }
/** /**
* Remove the property at a location. This will override existing * Remove the property at a location. This will override existing
* configuration data to have it conform to key/value mappings. * configuration data to have it conform to key/value mappings.
* *
* @param path * @param path
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@ -776,19 +776,19 @@ public void removeProperty(String path) {
root.remove(path); root.remove(path);
return; return;
} }
String[] parts = path.split("\\."); String[] parts = path.split("\\.");
Map<String, Object> node = root; Map<String, Object> node = root;
for (int i = 0; i < parts.length; i++) { for (int i = 0; i < parts.length; i++) {
Object o = node.get(parts[i]); Object o = node.get(parts[i]);
// Found our target! // Found our target!
if (i == parts.length - 1) { if (i == parts.length - 1) {
node.remove(parts[i]); node.remove(parts[i]);
return; return;
} }
node = (Map<String, Object>)o; node = (Map<String, Object>)o;
} }
} }