Cleaned up javadoc, deprecated duplicate methods, other cleanup

This commit is contained in:
zml2008 2012-02-20 15:14:55 -08:00
parent 6b4f872742
commit 6f4a62c7a3
52 changed files with 601 additions and 916 deletions

View File

@ -25,58 +25,58 @@ public abstract class LocalPlayer {
/**
* Get a player's name.
*
* @return
* @return The player's name
*/
public abstract String getName();
/**
* Returns true if the player is inside a group.
*
* @param group
* @return
* @param group The group to check
* @return Whether this player is in {@code group}
*/
public abstract boolean hasGroup(String group);
/**
* Get the player's position.
*
* @return
* @return The player's position
*/
public abstract Vector getPosition();
/**
* Kick the player.
*
* @param msg
* @param msg The message to kick the player with
*/
public abstract void kick(String msg);
/**
* Ban the player.
*
* @param msg
* @param msg The message to ban the player with
*/
public abstract void ban(String msg);
/**
* Send the player a message;
*
* @param msg
* @param msg The message to send to the player
*/
public abstract void printRaw(String msg);
/**
* Get the player's list of groups.
*
* @return
* @return The groups this player is in
*/
public abstract String[] getGroups();
/**
* Returns whether a player has permission.
*
* @param perm
* @return
* @param perm The permission to check
* @return Whether this player has {@code perm}
*/
public abstract boolean hasPermission(String perm);

View File

@ -73,7 +73,7 @@ public Blacklist(Boolean useAsWhitelist, Logger logger) {
/**
* Returns whether the list is empty.
*
* @return
* @return whether the blacklist is empty
*/
public boolean isEmpty() {
return blacklist.isEmpty();
@ -82,8 +82,8 @@ public boolean isEmpty() {
/**
* Get the entries for an item or list.
*
* @param id
* @return
* @param id The item id to get blacklist information for
* @return The blacklist entries for {@code id}
*/
public List<BlacklistEntry> getEntries(int id) {
return blacklist.get(id);
@ -92,7 +92,7 @@ public List<BlacklistEntry> getEntries(int id) {
/**
* Get the number of individual items that have blacklist entries.
*
* @return
* @return The number of items in the blacklist
*/
public int getItemCount() {
return blacklist.size();
@ -101,7 +101,7 @@ public int getItemCount() {
/**
* Returns whether the blacklist is used as a whitelist.
*
* @return
* @return whether the blacklist is be used as a whitelist
*/
public boolean isWhitelist() {
return useAsWhitelist;
@ -110,7 +110,7 @@ public boolean isWhitelist() {
/**
* Get the logger.
*
* @return
* @return The logger used in this blacklist
*/
public BlacklistLogger getLogger() {
return blacklistLogger;
@ -119,10 +119,10 @@ public BlacklistLogger getLogger() {
/**
* Method to handle the event.
*
* @param event
* @param forceRepeat
* @param silent
* @return
* @param event The event to check
* @param forceRepeat Whether to force quickly repeating notifications
* @param silent Whether to force-deny notifications
* @return Whether the event is allowed
*/
public boolean check(BlacklistEvent event, boolean forceRepeat, boolean silent) {
List<BlacklistEntry> entries = getEntries(event.getType());
@ -141,8 +141,8 @@ public boolean check(BlacklistEvent event, boolean forceRepeat, boolean silent)
/**
* Load the blacklist.
*
* @param file
* @throws IOException
* @param file The file to load from
* @throws IOException if an error occurred reading from the file
*/
public void load(File file) throws IOException {
FileReader input = null;
@ -170,7 +170,7 @@ public void load(File file) throws IOException {
currentEntries = new ArrayList<BlacklistEntry>();
for (String item : items) {
int id = 0;
int id;
try {
id = Integer.parseInt(item.trim());
@ -248,7 +248,7 @@ public void load(File file) throws IOException {
if (input != null) {
input.close();
}
} catch (IOException e2) {
} catch (IOException ignore) {
}
}
}
@ -256,7 +256,7 @@ public void load(File file) throws IOException {
/**
* Get the last event.
*
* @return
* @return The last event
*/
public BlacklistEvent getLastEvent() {
return lastEvent;
@ -265,8 +265,8 @@ public BlacklistEvent getLastEvent() {
/**
* Notify administrators.
*
* @param event
* @param comment
* @param event The event to notify about
* @param comment The comment to notify with
*/
public void notify(BlacklistEvent event, String comment) {
lastEvent = event;
@ -282,14 +282,14 @@ public void notify(BlacklistEvent event, String comment) {
/**
* Sends a notification to all subscribing users.
*
* @param msg
* @param msg The message to broadcast
*/
public abstract void broadcastNotification(String msg);
/**
* Forget a player.
*
* @param player
* @param player The player to forget
*/
public void forgetPlayer(LocalPlayer player) {
lastAffected.remove(player.getName());
@ -305,7 +305,8 @@ public void forgetAllPlayers() {
/**
* Get an item's ID from its name.
*
* @param name
* @param name the name of the item to look up
* @return the id for name if contained in ItemId, else -1
*/
private static int getItemID(String name) {
ItemType type = ItemType.lookup(name);
@ -319,7 +320,8 @@ private static int getItemID(String name) {
/**
* Get an item's friendly name with its ID.
*
* @param id
* @param id The id to look up
* @return The item's friendly name
*/
private static String getFriendlyItemName(int id) {
ItemType type = ItemType.fromID(id);

View File

@ -69,7 +69,7 @@ public class BlacklistEntry {
/**
* Construct the object.
*
* @param blacklist
* @param blacklist The blacklist that contains this entry
*/
public BlacklistEntry(Blacklist blacklist) {
this.blacklist = blacklist;
@ -112,98 +112,98 @@ public void setIgnorePermissions(String[] ignorePermissions) {
}
/**
* @return
* @return The actions that occur when breaking
*/
public String[] getBreakActions() {
return breakActions;
}
/**
* @param actions
* @param actions The actions to occur when breaking
*/
public void setBreakActions(String[] actions) {
this.breakActions = actions;
}
/**
* @return
* @return The actions that occur when destroying with a specific item
*/
public String[] getDestroyWithActions() {
return destroyWithActions;
}
/**
* @param actions
* @param actions The actions to occur when destroying with an item
*/
public void setDestroyWithActions(String[] actions) {
this.destroyWithActions = actions;
}
/**
* @return
* @return The actions that will occur when placing
*/
public String[] getPlaceActions() {
return placeActions;
}
/**
* @param actions
* @param actions The actions to occur when placing
*/
public void setPlaceActions(String[] actions) {
this.placeActions = actions;
}
/**
* @return
* @return The actions that will occur when interacting
*/
public String[] getInteractActions() {
return interactActions;
}
/**
* @param actions
* @param actions The actions to occur when interacting
*/
public void setInteractActions(String[] actions) {
this.interactActions = actions;
}
/**
* @return
* @return The actions that will occur when using
*/
public String[] getUseActions() {
return useActions;
}
/**
* @param actions
* @param actions The actions to occur when using
*/
public void setUseActions(String[] actions) {
this.useActions = actions;
}
/**
* @return
* @return The actions that will occur when dropping
*/
public String[] getDropActions() {
return dropActions;
}
/**
* @param actions
* @param actions The actions to occur when dropping
*/
public void setDropActions(String[] actions) {
this.dropActions = actions;
}
/**
* @return
* @return The actions that will occur when acquiring
*/
public String[] getAcquireActions() {
return acquireActions;
}
/**
* @param actions
* @param actions The actions to occur when acquiring
*/
public void setAcquireActions(String[] actions) {
this.acquireActions = actions;
@ -240,8 +240,8 @@ public void setComment(String comment) {
/**
* Returns true if this player should be ignored.
*
* @param player
* @return
* @param player The player to check
* @return whether this player should be ignored for blacklist blocking
*/
public boolean shouldIgnore(LocalPlayer player) {
if (ignoreGroups != null) {
@ -266,8 +266,8 @@ public boolean shouldIgnore(LocalPlayer player) {
/**
* Get the associated actions with an event.
*
* @param event
* @return
* @param event The event to check
* @return The actions for the given event
*/
private String[] getActions(BlacklistEvent event) {
if (event instanceof BlockBreakBlacklistEvent) {
@ -299,11 +299,11 @@ private String[] getActions(BlacklistEvent event) {
/**
* Method to handle the event.
*
* @param useAsWhitelist
* @param event
* @param forceRepeat
* @param silent
* @return
* @param useAsWhitelist Whether this entry is buing used in a whitelist
* @param event The event to check
* @param forceRepeat Whether to force repeating notifications even within the delay limit
* @param silent Whether to prevent notifications from happening
* @return Whether the action was allowed
*/
public boolean check(boolean useAsWhitelist, BlacklistEvent event, boolean forceRepeat, boolean silent) {
LocalPlayer player = event.getPlayer();
@ -329,11 +329,11 @@ public boolean check(boolean useAsWhitelist, BlacklistEvent event, boolean force
String actions[] = getActions(event);
boolean ret = useAsWhitelist ? false : true;
boolean ret = !useAsWhitelist;
// Nothing to do
if (actions == null) {
return useAsWhitelist ? false : true;
return ret;
}
for (String action : actions) {
@ -412,7 +412,7 @@ public boolean check(boolean useAsWhitelist, BlacklistEvent event, boolean force
/**
* Get an item's friendly name with its ID.
*
* @param id
* @param id The id to get a name for
*/
private static String getFriendlyItemName(int id) {
ItemType type = ItemType.fromID(id);

View File

@ -39,16 +39,16 @@ public class BlacklistLogger implements BlacklistLoggerHandler {
/**
* Add a handler.
*
* @param handler
* @param handler The handler to add
*/
public void addHandler(BlacklistLoggerHandler handler) {
handlers.add(handler);
}
/**
* Add a handler.
* Remove a handler.
*
* @param handler
* @param handler The handler to remove
*/
public void removeHandler(BlacklistLoggerHandler handler) {
handlers.remove(handler);
@ -64,7 +64,7 @@ public void clearHandlers() {
/**
* Log an event.
*
* @param event
* @param event The event to log
*/
public void logEvent(BlacklistEvent event, String comment) {
for (BlacklistLoggerHandler handler : handlers) {

View File

@ -32,8 +32,8 @@ public class BlacklistTrackedEvent {
/**
* Construct the object.
*
* @param event
* @param time
* @param event The event tracked
* @param time The time at which the event occurred
*/
public BlacklistTrackedEvent(BlacklistEvent event, long time) {
this.event = event;

View File

@ -39,9 +39,9 @@ public abstract class BlacklistEvent {
/**
* Construct the object.
*
* @param player
* @param pos
* @param type
* @param player The player associated with this event
* @param pos The position the event occurred at
* @param type The type of item used
*/
public BlacklistEvent(LocalPlayer player, Vector pos, int type) {
this.player = player;
@ -51,8 +51,8 @@ public BlacklistEvent(LocalPlayer player, Vector pos, int type) {
/**
* Get the player.
*
* @return
*
* @return The player associated with this event
*/
public LocalPlayer getPlayer() {
return player;
@ -61,16 +61,16 @@ public LocalPlayer getPlayer() {
/**
* Get the position.
*
* @return
* @return The position of this event
*/
public Vector getPosition() {
return pos;
}
/**
* Get the type.
* Get the item type.
*
* @return
* @return The type associated with this event
*/
public int getType() {
return type;
@ -79,7 +79,7 @@ public int getType() {
/**
* Get a short description such as "break" or "destroy with."
*
* @return
* @return The event description
*/
public abstract String getDescription();
}

View File

@ -26,12 +26,7 @@ public class BlockBreakBlacklistEvent extends BlockBlacklistEvent {
public BlockBreakBlacklistEvent(LocalPlayer player, Vector pos, int type) {
super(player, pos, type);
}
/**
* Get a short description such as "break" or "destroy with."
*
* @return
*/
@Override
public String getDescription() {
return "break";

View File

@ -26,12 +26,7 @@ public class BlockInteractBlacklistEvent extends BlockBlacklistEvent {
public BlockInteractBlacklistEvent(LocalPlayer player, Vector pos, int type) {
super(player, pos, type);
}
/**
* Get a short description such as "break" or "destroy with."
*
* @return
*/
@Override
public String getDescription() {
return "interact with";

View File

@ -26,12 +26,7 @@ public class BlockPlaceBlacklistEvent extends BlockBlacklistEvent {
public BlockPlaceBlacklistEvent(LocalPlayer player, Vector pos, int type) {
super(player, pos, type);
}
/**
* Get a short description such as "break" or "destroy with."
*
* @return
*/
@Override
public String getDescription() {
return "place";

View File

@ -26,12 +26,7 @@ public class DestroyWithBlacklistEvent extends BlacklistEvent {
public DestroyWithBlacklistEvent(LocalPlayer player, Vector pos, int type) {
super(player, pos, type);
}
/**
* Get a short description such as "break" or "destroy with."
*
* @return
*/
@Override
public String getDescription() {
return "destroy with";

View File

@ -26,12 +26,7 @@ public class ItemAcquireBlacklistEvent extends ItemBlacklistEvent {
public ItemAcquireBlacklistEvent(LocalPlayer player, Vector pos, int type) {
super(player, pos, type);
}
/**
* Get a short description such as "break" or "destroy with."
*
* @return
*/
@Override
public String getDescription() {
return "acquire";

View File

@ -26,12 +26,7 @@ public class ItemDropBlacklistEvent extends ItemBlacklistEvent {
public ItemDropBlacklistEvent(LocalPlayer player, Vector pos, int type) {
super(player, pos, type);
}
/**
* Get a short description such as "break" or "destroy with."
*
* @return
*/
@Override
public String getDescription() {
return "drop";

View File

@ -26,12 +26,7 @@ public class ItemUseBlacklistEvent extends ItemBlacklistEvent {
public ItemUseBlacklistEvent(LocalPlayer player, Vector pos, int type) {
super(player, pos, type);
}
/**
* Get a short description such as "break" or "destroy with."
*
* @return
*/
@Override
public String getDescription() {
return "use";

View File

@ -48,11 +48,6 @@ public ConsoleLoggerHandler(String worldName, Logger logger) {
this.logger = logger;
}
/**
* Log an event.
*
* @param event
*/
public void logEvent(BlacklistEvent event, String comment) {
// Block break
if (event instanceof BlockBreakBlacklistEvent) {
@ -113,14 +108,15 @@ public void logEvent(BlacklistEvent event, String comment) {
/**
* Get an item's friendly name with its ID.
*
* @param id
* @param id The item id
* @return The friendly name of the item
*/
private static String getFriendlyItemName(int id) {
ItemType type = ItemType.fromID(id);
if (type != null) {
return type.getName() + " (#" + id + ")";
} else {
return "#" + id + "";
return "#" + id;
}
}

View File

@ -73,11 +73,12 @@ public class DatabaseLoggerHandler implements BlacklistLoggerHandler {
/**
* Construct the object.
*
* @param dsn
* @param user
* @param pass
* @param table
* @param worldName
* @param dsn The DSN for the connection
* @param user The username to connect with
* @param pass The password to connect with
* @param table The table to log to
* @param worldName The name of the world to log
* @param logger The logger to log errors to
*/
public DatabaseLoggerHandler(String dsn, String user, String pass, String table, String worldName, Logger logger) {
this.dsn = dsn;
@ -91,8 +92,8 @@ public DatabaseLoggerHandler(String dsn, String user, String pass, String table,
/**
* Gets the database connection.
*
* @return
* @throws SQLException
* @return The database connection
* @throws SQLException when the connection cannot be created
*/
private Connection getConnection() throws SQLException {
if (conn == null || conn.isClosed()) {
@ -104,11 +105,11 @@ private Connection getConnection() throws SQLException {
/**
* Log an event to the database.
*
* @param event
* @param player
* @param pos
* @param item
* @param comment
* @param event The event to log
* @param player The player associated with the event
* @param pos The location of the event
* @param item The item used
* @param comment The comment associated with the event
*/
private void logEvent(String event, LocalPlayer player, Vector pos, int item,
String comment) {
@ -137,7 +138,7 @@ private void logEvent(String event, LocalPlayer player, Vector pos, int item,
/**
* Log an event.
*
* @param event
* @param event The event to log
*/
public void logEvent(BlacklistEvent event, String comment) {
// Block break
@ -197,7 +198,7 @@ public void close() {
if (conn != null && !conn.isClosed()) {
conn.close();
}
} catch (SQLException e) {
} catch (SQLException ignore) {
}
}

View File

@ -85,8 +85,9 @@ public class FileLoggerHandler implements BlacklistLoggerHandler {
/**
* Construct the object.
*
* @param pathPattern
* @param worldName
* @param pathPattern The pattern for the logflie path
* @param worldName The name of the world
* @param logger The logger used to log errors
*/
public FileLoggerHandler(String pathPattern, String worldName, Logger logger) {
this.pathPattern = pathPattern;
@ -97,9 +98,10 @@ public FileLoggerHandler(String pathPattern, String worldName, Logger logger) {
/**
* Construct the object.
*
* @param pathPattern
* @param cacheSize
* @param worldName
* @param pathPattern The pattern for logfile paths
* @param cacheSize The size of the file cache
* @param worldName The name of the associated world
* @param logger The logger to log errors with
*/
public FileLoggerHandler(String pathPattern, int cacheSize, String worldName, Logger logger) {
if (cacheSize < 1) {
@ -114,7 +116,8 @@ public FileLoggerHandler(String pathPattern, int cacheSize, String worldName, Lo
/**
* Build the path.
*
* @return
* @param playerName The name of the playername
* @return The path for the logfile
*/
private String buildPath(String playerName) {
GregorianCalendar calendar = new GregorianCalendar();
@ -171,8 +174,9 @@ private String buildPath(String playerName) {
/**
* Log a message.
*
* @param player
* @param message
* @param player The player to log
* @param message The message to log
* @param comment The comment associated with the logged event
*/
private void log(LocalPlayer player, String message, String comment) {
String path = buildPath(player.getName());
@ -220,7 +224,7 @@ private void log(LocalPlayer player, String message, String comment) {
Map.Entry<String,FileLoggerWriter> entry = it.next();
try {
entry.getValue().getWriter().close();
} catch (IOException e) {
} catch (IOException ignore) {
}
it.remove();
@ -240,8 +244,8 @@ private void log(LocalPlayer player, String message, String comment) {
/**
* Gets the coordinates in text form for the log.
*
* @param pos
* @return
* @param pos The position to get coordinates for
* @return The position's coordinates in human-readable form
*/
private String getCoordinates(Vector pos) {
return "@" + pos.getBlockX() + "," + pos.getBlockY() + "," + pos.getBlockZ();
@ -255,55 +259,17 @@ private void logEvent(BlacklistEvent event, String text, int id, Vector pos, Str
/**
* Log an event.
*
* @param event
* @param event The event to log
*/
public void logEvent(BlacklistEvent event, String comment) {
// Block break
if (event instanceof BlockBreakBlacklistEvent) {
BlockBreakBlacklistEvent evt = (BlockBreakBlacklistEvent)event;
logEvent(event, "break", evt.getType(), evt.getPosition(), comment);
// Block place
} else if (event instanceof BlockPlaceBlacklistEvent) {
BlockPlaceBlacklistEvent evt = (BlockPlaceBlacklistEvent)event;
logEvent(event, "place", evt.getType(), evt.getPosition(), comment);
// Block interact
} else if (event instanceof BlockInteractBlacklistEvent) {
BlockInteractBlacklistEvent evt = (BlockInteractBlacklistEvent)event;
logEvent(event, "interact with", evt.getType(), evt.getPosition(), comment);
// Destroy with
} else if (event instanceof DestroyWithBlacklistEvent) {
DestroyWithBlacklistEvent evt = (DestroyWithBlacklistEvent)event;
logEvent(event, "destroy with", evt.getType(), evt.getPosition(), comment);
// Acquire
} else if (event instanceof ItemAcquireBlacklistEvent) {
ItemAcquireBlacklistEvent evt = (ItemAcquireBlacklistEvent)event;
logEvent(event, "acquire", evt.getType(), evt.getPosition(), comment);
// Drop
} else if (event instanceof ItemDropBlacklistEvent) {
ItemDropBlacklistEvent evt = (ItemDropBlacklistEvent)event;
logEvent(event, "drop", evt.getType(), evt.getPosition(), comment);
// Use
} else if (event instanceof ItemUseBlacklistEvent) {
ItemUseBlacklistEvent evt = (ItemUseBlacklistEvent)event;
logEvent(event, "use", evt.getType(), evt.getPosition(), comment);
// Unknown
} else {
log(event.getPlayer(), "Unknown event: "
+ event.getClass().getCanonicalName(), comment);
}
logEvent(event, event.getDescription(), event.getType(), event.getPosition(), comment);
}
/**
* Get an item's friendly name with its ID.
*
* @param id
* @param id The id to get a friendly name for
* @return The friendly name
*/
private static String getFriendlyItemName(int id) {
ItemType type = ItemType.fromID(id);
@ -321,7 +287,7 @@ public void close() {
for (Map.Entry<String,FileLoggerWriter> entry : writers.entrySet()) {
try {
entry.getValue().getWriter().close();
} catch (IOException e) {
} catch (IOException ignore) {
}
}

View File

@ -42,8 +42,8 @@ public class FileLoggerWriter implements Comparable<FileLoggerWriter> {
/**
* Construct the object.
*
* @param path
* @param writer
* @param path The path to write to
* @param writer The writer for the file
*/
public FileLoggerWriter(String path, BufferedWriter writer) {
this.path = path;
@ -54,14 +54,14 @@ public FileLoggerWriter(String path, BufferedWriter writer) {
/**
* File path.
*
* @return
* @return The path the logger is logging to
*/
public String getPath() {
return path;
}
/**
* @return the writer
* @return the writer being logged to
*/
public BufferedWriter getWriter() {
return writer;
@ -81,12 +81,6 @@ public void updateLastUse() {
lastUse = System.currentTimeMillis();
}
/**
* Comparison function.
*
* @param other
* @return
*/
public int compareTo(FileLoggerWriter other) {
if (lastUse > other.lastUse) {
return 1;

View File

@ -57,6 +57,7 @@ public void kick(String msg) {
@Override
public void ban(String msg) {
player.setBanned(true);
player.kickPlayer(msg);
}

View File

@ -50,8 +50,8 @@ private BukkitUtil() {
/**
* Converts the location of a Bukkit block to a WorldEdit vector.
*
* @param block
* @return
* @param block The block to convert
* @return The block's location as a BlockVector
*/
public static BlockVector toVector(Block block) {
return new BlockVector(block.getX(), block.getY(), block.getZ());
@ -60,8 +60,8 @@ public static BlockVector toVector(Block block) {
/**
* Converts a Bukkit location to a WorldEdit vector.
*
* @param loc
* @return
* @param loc A Bukkit Location
* @return A Vector with the location's x, y, and z values
*/
public static Vector toVector(Location loc) {
return new Vector(loc.getX(), loc.getY(), loc.getZ());
@ -70,8 +70,8 @@ public static Vector toVector(Location loc) {
/**
* Converts a Bukkit vector to a WorldEdit vector.
*
* @param vector
* @return
* @param vector The Bukkit vector
* @return A WorldEdit vector with the same values as the Bukkit vector.
*/
public static Vector toVector(org.bukkit.util.Vector vector) {
return new Vector(vector.getX(), vector.getY(), vector.getZ());
@ -80,9 +80,9 @@ public static Vector toVector(org.bukkit.util.Vector vector) {
/**
* Converts a WorldEdit vector to a Bukkit location.
*
* @param world
* @param vec
* @return
* @param world The World to create the new Location with
* @param vec The vector to use for coordinates
* @return The Vector as a location with a World of world
*/
public static Location toLocation(World world, Vector vec) {
return new Location(world, vec.getX(), vec.getY(), vec.getZ());
@ -91,10 +91,12 @@ public static Location toLocation(World world, Vector vec) {
/**
* Matches one player based on name.
*
* @param server
* @param name
* @return
* @param server The server to check
* @param name The name to attempt to match
* @deprecated see {@link WorldGuardPlugin#matchSinglePlayer(org.bukkit.command.CommandSender, String)}
* @return The matched player if any, otherwise null
*/
@Deprecated
public static Player matchSinglePlayer(Server server, String name) {
List<Player> players = server.matchPlayer(name);
if (players.size() == 0) {
@ -106,8 +108,10 @@ public static Player matchSinglePlayer(Server server, String name) {
/**
* Drops a sign item and removes a sign.
*
* @param block
* @param block The block
* @deprecated see {@link org.bukkit.block.Block#breakNaturally()}
*/
@Deprecated
public static void dropSign(Block block) {
block.setTypeId(0);
block.getWorld().dropItemNaturally(block.getLocation(),

View File

@ -109,7 +109,7 @@ public class ConfigurationManager {
/**
* Construct the object.
*
* @param plugin
* @param plugin The plugin instance
*/
public ConfigurationManager(WorldGuardPlugin plugin) {
this.plugin = plugin;
@ -152,10 +152,7 @@ public void load() {
get(world);
}
try {
config.setHeader(CONFIG_HEADER);
} catch (Throwable t) {
}
config.setHeader(CONFIG_HEADER);
if (!config.save()) {
plugin.getLogger().severe("Error saving configuration!");
@ -172,8 +169,8 @@ public void unload() {
/**
* Get the configuration for a world.
*
* @param world
* @return
* @param world The world to get the configuration for
* @return {@code world}'s configuration
*/
public WorldConfiguration get(World world) {
String worldName = world.getName();
@ -190,7 +187,7 @@ public WorldConfiguration get(World world) {
/**
* Forget a player.
*
* @param player
* @param player The player to forget about
*/
public void forgetPlayer(LocalPlayer player) {
for (Map.Entry<String, WorldConfiguration> entry
@ -210,7 +207,7 @@ public void forgetPlayer(LocalPlayer player) {
/**
* Enable god mode for a player.
*
* @param player
* @param player The player to enable god mode for.
*/
@Deprecated
public void enableGodMode(Player player) {
@ -220,7 +217,7 @@ public void enableGodMode(Player player) {
/**
* Disable god mode for a player.
*
* @param player
* @param player The player to disable godmode for
*/
@Deprecated
public void disableGodMode(Player player) {
@ -230,8 +227,8 @@ public void disableGodMode(Player player) {
/**
* Check to see if god mode is enabled for a player.
*
* @param player
* @return
* @param player The player to check
* @return Whether the player has godmode through WorldGuard or CommandBook
*/
public boolean hasGodMode(Player player) {
if (hasCommandBookGodMode) {
@ -246,7 +243,7 @@ public boolean hasGodMode(Player player) {
/**
* Enable amphibious mode for a player.
*
* @param player
* @param player The player to enable amphibious mode for
*/
public void enableAmphibiousMode(Player player) {
hasAmphibious.add(player.getName());
@ -255,17 +252,17 @@ public void enableAmphibiousMode(Player player) {
/**
* Disable amphibious mode for a player.
*
* @param player
* @param player The player to disable amphibious mode for
*/
public void disableAmphibiousMode(Player player) {
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
* @return
* @param player The player to check
* @return Whether {@code player} has amphibious mode
*/
public boolean hasAmphibiousMode(Player player) {
return hasAmphibious.contains(player.getName());

View File

@ -49,7 +49,7 @@ public class FlagStateManager implements Runnable {
/**
* Construct the object.
*
* @param plugin
* @param plugin The plugin instance
*/
public FlagStateManager(WorldGuardPlugin plugin) {
this.plugin = plugin;
@ -99,10 +99,10 @@ public void run() {
/**
* Process healing for a player.
*
* @param applicable
* @param player
* @param state
*
* @param applicable The set of applicable regions
* @param player The player to process healing flags on
* @param state The player's state
*/
private void processHeal(ApplicableRegionSet applicable, Player player,
PlayerFlagState state) {
@ -141,9 +141,9 @@ private void processHeal(ApplicableRegionSet applicable, Player player,
/**
* Process restoring hunger for a player.
*
* @param applicable
* @param player
* @param state
* @param applicable The set of applicable regions
* @param player The player to process hunger flags on
* @param state The player's state
*/
private void processFeed(ApplicableRegionSet applicable, Player player,
PlayerFlagState state) {
@ -178,7 +178,7 @@ private void processFeed(ApplicableRegionSet applicable, Player player,
/**
* Forget a player.
*
* @param player
* @param player The player to forget
*/
public synchronized void forget(Player player) {
states.remove(player.getName());
@ -192,10 +192,11 @@ public synchronized void forgetAll() {
}
/**
* Get a player's flag state.
* Get a player's flag state. A new state will be created if there is no existing
* state for the player.
*
* @param player
* @return
* @param player The player to get a state for
* @return The {@code player}'s state
*/
public synchronized PlayerFlagState getState(Player player) {
PlayerFlagState state = states.get(player.getName());

View File

@ -42,7 +42,7 @@ public class LegacyWorldGuardMigration {
/**
* Port over the blacklist.
*
* @param plugin
* @param plugin The plugin instance
*/
public static void migrateBlacklist(WorldGuardPlugin plugin) {
World mainWorld = plugin.getServer().getWorlds().get(0);
@ -75,7 +75,7 @@ public static void migrateBlacklist(WorldGuardPlugin plugin) {
/**
* Migrate region settings.
*
* @param plugin
* @param plugin The plugin instance
*/
public static void migrateRegions(WorldGuardPlugin plugin) {
try {
@ -109,8 +109,8 @@ public static void migrateRegions(WorldGuardPlugin plugin) {
/**
* Copies a file.
*
* @param from
* @param to
* @param from The source file
* @param to The destination file
* @return true if successful
*/
private static boolean copyFile(File from, File to) {
@ -131,20 +131,20 @@ private static boolean copyFile(File from, File to) {
out.close();
return true;
} catch (FileNotFoundException ex) {
} catch (IOException e) {
} catch (FileNotFoundException ignore) {
} catch (IOException ignore) {
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
} catch (IOException ignore) {
}
}
if (out != null) {
try {
out.close();
} catch (IOException e) {
} catch (IOException ignore) {
}
}
}

View File

@ -127,7 +127,7 @@ private void appendGlobalConfiguration(ConfigurationManager config) {
configLog.put(field.getName(), val);
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
} catch (IllegalAccessException ignore) {
}
}
@ -274,7 +274,7 @@ private void appendWorldConfigurations(WorldGuardPlugin plugin, List<World> worl
configLog.put(field.getName(), String.valueOf(val));
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
} catch (IllegalAccessException ignore) {
}
}
@ -324,7 +324,7 @@ public void write(File file) throws IOException {
if (writer != null) {
try {
writer.close();
} catch (IOException e) {
} catch (IOException ignore) {
}
}
}

View File

@ -28,12 +28,12 @@ public class SpongeUtil {
/**
* Remove water around a sponge.
*
* @param plugin
* @param world
* @param ox
* @param oy
* @param oz
*
* @param plugin The plugin instace
* @param world The world the sponge isin
* @param ox The x coordinate of the 'sponge' block
* @param oy The y coordinate of the 'sponge' block
* @param oz The z coordinate of the 'sponge' block
*/
public static void clearSpongeWater(WorldGuardPlugin plugin, World world, int ox, int oy, int oz) {
ConfigurationManager cfg = plugin.getGlobalStateManager();
@ -53,11 +53,11 @@ public static void clearSpongeWater(WorldGuardPlugin plugin, World world, int ox
/**
* Add water around a sponge.
*
* @param plugin
* @param world
* @param ox
* @param oy
* @param oz
* @param plugin The plugin instance
* @param world The world the sponge is located in
* @param ox The x coordinate of the 'sponge' block
* @param oy The y coordinate of the 'sponge' block
* @param oz The z coordinate of the 'sponge' block
*/
public static void addSpongeWater(WorldGuardPlugin plugin, World world, int ox, int oy, int oz) {
ConfigurationManager cfg = plugin.getGlobalStateManager();

View File

@ -67,7 +67,6 @@ public class WorldConfiguration {
private String worldName;
private YAMLProcessor parentConfig;
private YAMLProcessor config;
private File configFile;
private File blacklistFile;
private Blacklist blacklist;
@ -159,7 +158,7 @@ public class WorldConfiguration {
*/
public WorldConfiguration(WorldGuardPlugin plugin, String worldName, YAMLProcessor parentConfig) {
File baseFolder = new File(plugin.getDataFolder(), "worlds/" + worldName);
configFile = new File(baseFolder, "config.yml");
File configFile = new File(baseFolder, "config.yml");
blacklistFile = new File(baseFolder, "blacklist.txt");
this.plugin = plugin;
@ -169,7 +168,7 @@ public WorldConfiguration(WorldGuardPlugin plugin, String worldName, YAMLProcess
plugin.createDefaultConfiguration(configFile, "config_world.yml");
plugin.createDefaultConfiguration(blacklistFile, "blacklist.txt");
config = new YAMLProcessor(this.configFile, true, YAMLFormat.EXTENDED);
config = new YAMLProcessor(configFile, true, YAMLFormat.EXTENDED);
loadConfiguration();
plugin.getLogger().info("Loaded configuration for world '" + worldName + '"');
@ -470,10 +469,7 @@ private void loadConfiguration() {
}
}
try {
config.setHeader(CONFIG_HEADER);
} catch (Throwable t) {
}
config.setHeader(CONFIG_HEADER);
config.save();
}

View File

@ -18,7 +18,6 @@
*/
package com.sk89q.worldguard.bukkit;
import static com.sk89q.worldguard.bukkit.BukkitUtil.dropSign;
import static com.sk89q.worldguard.bukkit.BukkitUtil.toVector;
import org.bukkit.ChatColor;
@ -69,7 +68,7 @@ public class WorldGuardBlockListener implements Listener {
/**
* Construct the object.
*
* @param plugin
* @param plugin The plugin instance
*/
public WorldGuardBlockListener(WorldGuardPlugin plugin) {
this.plugin = plugin;
@ -85,8 +84,8 @@ public void registerEvents() {
/**
* Get the world configuration given a world.
*
* @param world
* @return
* @param world The world to get the configuration for.
* @return The configuration for {@code world}
*/
protected WorldConfiguration getWorldConfig(World world) {
return plugin.getGlobalStateManager().get(world);
@ -95,14 +94,14 @@ protected WorldConfiguration getWorldConfig(World world) {
/**
* Get the world configuration given a player.
*
* @param player
* @return
* @param player The player to get the wold from
* @return The {@link WorldConfiguration} for the player's world
*/
protected WorldConfiguration getWorldConfig(Player player) {
return plugin.getGlobalStateManager().get(player.getWorld());
return getWorldConfig(player.getWorld());
}
/**
/*
* Called when a block is damaged.
*/
@EventHandler(priority = EventPriority.HIGH)
@ -125,7 +124,7 @@ public void onBlockDamage(BlockDamageEvent event) {
}
}
/**
/*
* Called when a block is broken.
*/
@EventHandler(priority = EventPriority.HIGH)
@ -178,7 +177,7 @@ public void onBlockBreak(BlockBreakEvent event) {
}
}
/**
/*
* Called when fluids flow.
*/
@EventHandler
@ -275,7 +274,7 @@ public void onBlockFromTo(BlockFromToEvent event) {
}
}
/**
/*
* Called when a block gets ignited.
*/
@EventHandler(priority = EventPriority.HIGH)
@ -377,7 +376,7 @@ public void onBlockIgnite(BlockIgniteEvent event) {
}
/**
/*
* Called when a block is destroyed from burning.
*/
@EventHandler(priority = EventPriority.HIGH)
@ -433,7 +432,7 @@ public void onBlockBurn(BlockBurnEvent event) {
}
}
/**
/*
* Called when block physics occurs.
*/
@EventHandler
@ -469,7 +468,7 @@ public void onBlockPhysics(BlockPhysicsEvent event) {
}
}
/**
/*
* Called when a player places a block.
*/
@EventHandler(priority = EventPriority.HIGH)
@ -524,7 +523,7 @@ public void onBlockPlace(BlockPlaceEvent event) {
}
}
/**
/*
* Called when redstone changes.
*/
@EventHandler(priority = EventPriority.HIGH)
@ -560,7 +559,7 @@ public void onBlockRedstoneChange(BlockRedstoneEvent event) {
}
}
/**
/*
* Called when a sign is changed.
*/
@EventHandler(priority = EventPriority.HIGH)
@ -573,7 +572,7 @@ public void onSignChange(SignChangeEvent event) {
if (event.getLine(0).equalsIgnoreCase("[Lock]")) {
if (wcfg.isChestProtectedPlacement(event.getBlock(), player)) {
player.sendMessage(ChatColor.DARK_RED + "You do not own the adjacent chest.");
dropSign(event.getBlock());
event.getBlock().breakNaturally();
event.setCancelled(true);
return;
}
@ -582,7 +581,7 @@ public void onSignChange(SignChangeEvent event) {
player.sendMessage(ChatColor.RED
+ "The [Lock] sign must be a sign post, not a wall sign.");
dropSign(event.getBlock());
event.getBlock().breakNaturally();
event.setCancelled(true);
return;
}
@ -591,7 +590,7 @@ public void onSignChange(SignChangeEvent event) {
player.sendMessage(ChatColor.RED
+ "The first owner line must be your name.");
dropSign(event.getBlock());
event.getBlock().breakNaturally();
event.setCancelled(true);
return;
}
@ -603,7 +602,7 @@ public void onSignChange(SignChangeEvent event) {
player.sendMessage(ChatColor.RED
+ "That is not a safe block that you're putting this sign on.");
dropSign(event.getBlock());
event.getBlock().breakNaturally();
event.setCancelled(true);
return;
}
@ -616,8 +615,8 @@ public void onSignChange(SignChangeEvent event) {
if (event.getLine(0).equalsIgnoreCase("[Lock]")) {
player.sendMessage(ChatColor.RED
+ "WorldGuard's sign chest protection is disabled.");
dropSign(event.getBlock());
event.getBlock().breakNaturally();
event.setCancelled(true);
return;
}
@ -657,7 +656,7 @@ public void onLeavesDecay(LeavesDecayEvent event) {
}
}
/**
/*
* Called when a block is formed based on world conditions.
*/
@EventHandler(priority = EventPriority.HIGH)
@ -701,7 +700,7 @@ public void onBlockForm(BlockFormEvent event) {
}
}
/**
/*
* Called when a block spreads based on world conditions.
*/
@EventHandler(priority = EventPriority.HIGH)
@ -745,7 +744,7 @@ public void onBlockSpread(BlockSpreadEvent event) {
}
}
/**
/*
* Called when a block fades.
*/
@EventHandler(priority = EventPriority.HIGH)
@ -784,7 +783,7 @@ public void onBlockFade(BlockFadeEvent event) {
}
}
/**
/*
* Called when a piston extends
*/
@EventHandler(priority = EventPriority.HIGH)
@ -810,7 +809,7 @@ public void onBlockPistonExtend(BlockPistonExtendEvent event) {
}
}
/**
/*
* Called when a piston retracts
*/
@EventHandler(priority = EventPriority.HIGH)
@ -826,6 +825,7 @@ public void onBlockPistonRetract(BlockPistonRetractEvent event) {
if (!(plugin.getGlobalRegionManager().allows(DefaultFlag.PISTONS, event.getRetractLocation()))
|| !(plugin.getGlobalRegionManager().allows(DefaultFlag.PISTONS, event.getBlock().getLocation()))) {
event.setCancelled(true);
return;
}
}
}

View File

@ -85,7 +85,7 @@ public class WorldGuardEntityListener implements Listener {
/**
* Construct the object;
*
* @param plugin
* @param plugin The plugin instance
*/
public WorldGuardEntityListener(WorldGuardPlugin plugin) {
this.plugin = plugin;
@ -98,9 +98,6 @@ public void registerEvents() {
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}
/**
* Called when an entity interacts with another object.
*/
@EventHandler(priority = EventPriority.HIGH)
public void onEntityInteract(EntityInteractEvent event) {
Entity entity = event.getEntity();
@ -116,9 +113,6 @@ public void onEntityInteract(EntityInteractEvent event) {
}
}
/**
* Called when an entity dies.
*/
@EventHandler(priority = EventPriority.HIGH)
public void onEntityDeath(EntityDeathEvent event) {
WorldConfiguration wcfg = plugin.getGlobalStateManager().get(event.getEntity().getWorld());
@ -128,20 +122,11 @@ public void onEntityDeath(EntityDeathEvent event) {
event.setDroppedExp(0);
}
try {
if (event instanceof PlayerDeathEvent && wcfg.disableDeathMessages) {
((PlayerDeathEvent) event).setDeathMessage("");
}
} catch (Throwable t) {
// old CraftBukkit, eat it
if (event instanceof PlayerDeathEvent && wcfg.disableDeathMessages) {
((PlayerDeathEvent) event).setDeathMessage("");
}
}
/**
* Called on entity damage by a block.
*
* @param event
*/
private void onEntityDamageByBlock(EntityDamageByBlockEvent event) {
Entity defender = event.getEntity();
DamageCause type = event.getCause();
@ -191,11 +176,6 @@ private void onEntityDamageByBlock(EntityDamageByBlockEvent event) {
}
}
/**
* Called on entity damage by an entity.
*
* @param event
*/
private void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
if (event.getCause() == DamageCause.PROJECTILE) {
onEntityDamageByProjectile(event);
@ -346,11 +326,6 @@ private void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
}
}
/**
* Called on entity damage by a projectile.
*
* @param event
*/
private void onEntityDamageByProjectile(EntityDamageByEntityEvent event) {
Entity defender = event.getEntity();
Entity attacker = ((Projectile) event.getDamager()).getShooter();
@ -400,9 +375,6 @@ private void onEntityDamageByProjectile(EntityDamageByEntityEvent event) {
}
/**
* Called on entity damage.
*/
@EventHandler(priority = EventPriority.HIGH)
public void onEntityDamage(EntityDamageEvent event) {
if (event.isCancelled()) {
@ -481,9 +453,6 @@ public void onEntityDamage(EntityDamageEvent event) {
}
}
/**
* Called on entity combust.
*/
@EventHandler(priority = EventPriority.HIGH)
public void onEntityCombust(EntityCombustEvent event) {
if (event.isCancelled()) {
@ -505,7 +474,7 @@ public void onEntityCombust(EntityCombustEvent event) {
}
}
/**
/*
* Called on entity explode.
*/
@EventHandler(priority = EventPriority.HIGH)
@ -622,7 +591,7 @@ public void onEntityExplode(EntityExplodeEvent event) {
}
/**
/*
* Called on explosion prime
*/
@EventHandler(priority = EventPriority.HIGH)
@ -642,9 +611,6 @@ public void onExplosionPrime(ExplosionPrimeEvent event) {
}
/**
* Called on creature spawn.
*/
@EventHandler(priority = EventPriority.HIGH)
public void onCreatureSpawn(CreatureSpawnEvent event) {
if (event.isCancelled()) {
@ -688,9 +654,6 @@ public void onCreatureSpawn(CreatureSpawnEvent event) {
}
}
/**
* Called on pig zap.
*/
@EventHandler(priority = EventPriority.HIGH)
public void onPigZap(PigZapEvent event) {
if (event.isCancelled()) {
@ -705,9 +668,6 @@ public void onPigZap(PigZapEvent event) {
}
}
/**
* Called on creeper power.
*/
@EventHandler(priority = EventPriority.HIGH)
public void onCreeperPower(CreeperPowerEvent event) {
if (event.isCancelled()) {
@ -722,9 +682,6 @@ public void onCreeperPower(CreeperPowerEvent event) {
}
}
/**
* Called when a painting is removed.
*/
@EventHandler(priority = EventPriority.HIGH)
public void onPaintingBreak(PaintingBreakEvent breakEvent) {
if (breakEvent.isCancelled()) {
@ -765,9 +722,6 @@ public void onPaintingBreak(PaintingBreakEvent breakEvent) {
}
}
/**
* Called on painting place.
*/
@EventHandler(priority = EventPriority.HIGH)
public void onPaintingPlace(PaintingPlaceEvent event) {
if (event.isCancelled()) {
@ -799,9 +753,6 @@ public void onPaintingPlace(PaintingPlaceEvent event) {
}
}
/**
* Called on entity health regain.
*/
@EventHandler(priority = EventPriority.HIGH)
public void onEntityRegainHealth(EntityRegainHealthEvent event) {
if (event.isCancelled()) {
@ -822,6 +773,8 @@ public void onEntityRegainHealth(EntityRegainHealthEvent event) {
/**
* Called when an enderman picks up or puts down a block and some other cases.
*
* @param event Relevant event details
*/
@EventHandler(priority = EventPriority.HIGH)
public void onEndermanPickup(EntityChangeBlockEvent event) {
@ -885,8 +838,8 @@ public void onFoodLevelChange(FoodLevelChangeEvent event) {
* the region denies invincibility, the player must have an extra permission
* to override it. (worldguard.god.override-regions)
*
* @param player
* @return
* @param player The player to check
* @return Whether {@code player} is invincible
*/
private boolean isInvincible(Player player) {
ConfigurationManager cfg = plugin.getGlobalStateManager();
@ -895,7 +848,7 @@ private boolean isInvincible(Player player) {
boolean god = cfg.hasGodMode(player);
if (wcfg.useRegions) {
Boolean flag = RegionQueryUtil.isAllowedInvinciblity(plugin, player);
boolean allowed = flag == null || flag == true;
boolean allowed = flag == null || flag;
boolean invincible = RegionQueryUtil.isInvincible(plugin, player);
if (allowed) {

View File

@ -96,11 +96,6 @@ public void registerEvents() {
}
class PlayerMoveHandler implements Listener {
/**
* Called when a player attempts to move.
*
* @param event
*/
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerMove(PlayerMoveEvent event) {
Player player = event.getPlayer();
@ -218,10 +213,6 @@ public void onPlayerMove(PlayerMoveEvent event) {
}
}
/**
* Called when a player joins a server.
*/
@SuppressWarnings("deprecation")
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
@ -273,9 +264,6 @@ public void onPlayerJoin(PlayerJoinEvent event) {
}
}
/**
* Called when a player leaves a server.
*/
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event) {
Player player = event.getPlayer();
@ -318,9 +306,6 @@ public void onPlayerQuit(PlayerQuitEvent event) {
plugin.forgetPlayer(player);
}
/**
* Called when a player interacts with an item.
*/
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerInteract(PlayerInteractEvent event) {
Player player = event.getPlayer();
@ -355,7 +340,7 @@ public void onPlayerInteract(PlayerInteractEvent event) {
/**
* Called when a player left clicks air.
*
* @param event
* @param event Thrown event
*/
private void handleAirLeftClick(PlayerInteractEvent event) {
// I don't think we have to do anything here yet.
@ -365,7 +350,7 @@ private void handleAirLeftClick(PlayerInteractEvent event) {
/**
* Called when a player left clicks a block.
*
* @param event
* @param event Thrown event
*/
private void handleBlockLeftClick(PlayerInteractEvent event) {
if (event.isCancelled()) return;
@ -428,7 +413,7 @@ private void handleBlockLeftClick(PlayerInteractEvent event) {
/**
* Called when a player right clicks air.
*
* @param event
* @param event Thrown event
*/
private void handleAirRightClick(PlayerInteractEvent event) {
if (event.isCancelled()) {
@ -457,7 +442,7 @@ private void handleAirRightClick(PlayerInteractEvent event) {
/**
* Called when a player right clicks a block.
*
* @param event
* @param event Thrown event
*/
private void handleBlockRightClick(PlayerInteractEvent event) {
if (event.isCancelled()) {
@ -730,7 +715,7 @@ private void handleBlockRightClick(PlayerInteractEvent event) {
/**
* Called when a player steps on a pressure plate or tramples crops.
*
* @param event
* @param event Thrown event
*/
private void handlePhysicalInteract(PlayerInteractEvent event) {
if (event.isCancelled()) return;
@ -832,9 +817,6 @@ public void onPlayerItem(PlayerItemEvent event) {
}
}*/
/**
* Called when a player attempts to drop an item.
*/
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerDropItem(PlayerDropItemEvent event) {
if (event.isCancelled()) {
@ -856,9 +838,6 @@ public void onPlayerDropItem(PlayerDropItemEvent event) {
}
}
/**
* Called when a player attempts to pickup an item.
*/
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerPickupItem(PlayerPickupItemEvent event) {
if (event.isCancelled()) {
@ -880,9 +859,7 @@ public void onPlayerPickupItem(PlayerPickupItemEvent event) {
}
}
/**
* Called when a bucket is filled.
*/
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerBucketFill(PlayerBucketFillEvent event) {
Player player = event.getPlayer();
@ -916,9 +893,6 @@ public void onPlayerBucketFill(PlayerBucketFillEvent event) {
}
}
/**
* Called when a bucket is empty.
*/
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerBucketEmpty(PlayerBucketEmptyEvent event) {
Player player = event.getPlayer();
@ -943,10 +917,7 @@ public void onPlayerBucketEmpty(PlayerBucketEmptyEvent event) {
}
}
}
/**
* Called when a player is respawned.
*/
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerRespawn(PlayerRespawnEvent event) {
Player player = event.getPlayer();
@ -969,9 +940,6 @@ public void onPlayerRespawn(PlayerRespawnEvent event) {
}
}
/**
* Called when a player changes their held item.
*/
@EventHandler(priority = EventPriority.HIGH)
public void onItemHeldChange(PlayerItemHeldEvent event) {
Player player = event.getPlayer();
@ -990,9 +958,6 @@ public void onItemHeldChange(PlayerItemHeldEvent event) {
}
}
/**
* Called when a player enters a bed.
*/
@EventHandler(priority = EventPriority.HIGH)
public void onPlayerBedEnter(PlayerBedEnterEvent event) {
if (event.isCancelled()) {
@ -1019,9 +984,6 @@ public void onPlayerBedEnter(PlayerBedEnterEvent event) {
}
}
/**
* Called on command run.
*/
@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
Player player = event.getPlayer();

View File

@ -29,8 +29,6 @@
import java.util.Iterator;
import java.util.List;
import java.util.jar.JarFile;
import java.util.logging.Filter;
import java.util.logging.Logger;
import java.util.zip.ZipEntry;
import com.sk89q.bukkit.util.CommandsManagerRegistration;
@ -43,6 +41,7 @@
import org.bukkit.block.Block;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
@ -217,16 +216,16 @@ public boolean onCommand(CommandSender sender, Command cmd, String label,
/**
* Get the GlobalRegionManager.
*
* @return
* @return The plugin's global region manager
*/
public GlobalRegionManager getGlobalRegionManager() {
return globalRegionManager;
}
/**
* Get the WorldGuardConfiguraton.
* Get the WorldGuard Configuration.
*
* @return
* @return ConfigurationManager
* @deprecated Use {@link #getGlobalStateManager()} instead
*/
@Deprecated
@ -237,27 +236,28 @@ public ConfigurationManager getGlobalConfiguration() {
/**
* Gets the flag state manager.
*
* @return
* @return The flag state manager
*/
public FlagStateManager getFlagStateManager() {
return flagStateManager;
}
/**
* Get the WorldGuardConfiguraton.
*
* @return
* Get the global ConfigurationManager.
* USe this to access global configuration values and per-world configuration values.
* @return The global ConfigurationManager
*/
public ConfigurationManager getGlobalStateManager() {
return configuration;
}
/**
* Check whether a player is in a group.
* Check whether a player is in a group.
* This calls the corresponding method in PermissionsResolverManager
*
* @param player
* @param group
* @return
* @param player The player to check
* @param group The group
* @return whether {@code player} is in {@code group}
*/
public boolean inGroup(Player player, String group) {
try {
@ -270,9 +270,9 @@ public boolean inGroup(Player player, String group) {
/**
* Get the groups of a player.
*
* @param player
* @return
* This calls the corresponding method in PermissionsResolverManager.
* @param player The player to check
* @return The names of each group the playe is in.
*/
public String[] getGroups(Player player) {
try {
@ -287,37 +287,39 @@ public String[] getGroups(Player player) {
* Gets the name of a command sender. This is a unique name and this
* method should never return a "display name".
*
* @param sender
* @return
* @param sender The sender to get the name of
* @return The unique name of the sender.
*/
public String toUniqueName(CommandSender sender) {
if (sender instanceof Player) {
return ((Player) sender).getName();
} else {
if (sender instanceof ConsoleCommandSender) {
return "*Console*";
} else {
return sender.getName();
}
}
/**
* Gets the name of a command sender. This play be a display name.
*
* @param sender
* @return
* @param sender The CommandSender to get the name of.
* @return The name of the given sender
*/
public String toName(CommandSender sender) {
if (sender instanceof Player) {
return ((Player) sender).getName();
} else {
if (sender instanceof ConsoleCommandSender) {
return "*Console*";
} else if (sender instanceof Player) {
return ((Player) sender).getDisplayName();
} else {
return sender.getName();
}
}
/**
* Checks permissions.
*
* @param sender
* @param perm
* @return
* @param sender The sender to check the permission on.
* @param perm The permission to check the permission on.
* @return whether {@code sender} has {@code perm}
*/
public boolean hasPermission(CommandSender sender, String perm) {
if (sender.isOp()) {
@ -343,9 +345,9 @@ public boolean hasPermission(CommandSender sender, String perm) {
/**
* Checks permissions and throws an exception if permission is not met.
*
* @param sender
* @param perm
* @throws CommandPermissionsException
* @param sender The sender to check the permission on.
* @param perm The permission to check the permission on.
* @throws CommandPermissionsException if {@code sender} doesn't have {@code perm}
*/
public void checkPermission(CommandSender sender, String perm)
throws CommandPermissionsException {
@ -357,9 +359,9 @@ public void checkPermission(CommandSender sender, String perm)
/**
* Checks to see if the sender is a player, otherwise throw an exception.
*
* @param sender
* @return
* @throws CommandException
* @param sender The {@link CommandSender} to check
* @return {@code sender} casted to a player
* @throws CommandException if {@code sender} isn't a {@link Player}
*/
public Player checkPlayer(CommandSender sender)
throws CommandException {
@ -373,8 +375,13 @@ public Player checkPlayer(CommandSender sender)
/**
* Match player names.
*
* @param filter
* @return
* The filter string uses the following format:
* @[name] looks up all players with the exact {@code name}
* *[name] matches any player whose name contains {@code name}
* [name] matches any player whose name starts with {@code name}
*
* @param filter The filter string to check.
* @return A {@link List} of players who match {@code filter}
*/
public List<Player> matchPlayerNames(String filter) {
Player[] players = getServer().getOnlinePlayers();
@ -426,9 +433,9 @@ public List<Player> matchPlayerNames(String filter) {
* Checks if the given list of players is greater than size 0, otherwise
* throw an exception.
*
* @param players
* @return
* @throws CommandException
* @param players The {@link List} to check
* @return {@code players} as an {@link Iterable}
* @throws CommandException If {@code players} is empty
*/
protected Iterable<Player> checkPlayerMatch(List<Player> players)
throws CommandException {
@ -441,12 +448,19 @@ protected Iterable<Player> checkPlayerMatch(List<Player> players)
}
/**
* Checks permissions and throws an exception if permission is not met.
*
* @param source
* @param filter
* Matches players based on the specified filter string
*
* The filter string format is as follows:
* * returns all the players currently online
* If {@code sender} is a {@link Player}:
* #world returns all players in the world that {@code sender} is in
* #near reaturns all players within 30 blocks of {@code sender}'s location
* Otherwise, the format is as specified in {@link #matchPlayerNames(String)}
*
* @param source The CommandSender who is trying to find a player
* @param filter The filter string for players
* @return iterator for players
* @throws CommandException no matches found
* @throws CommandException if no matches are found
*/
public Iterable<Player> matchPlayers(CommandSender source, String filter)
throws CommandException {
@ -507,10 +521,11 @@ public Iterable<Player> matchPlayers(CommandSender source, String filter)
/**
* Match only a single player.
*
* @param sender
* @param filter
* @return
* @throws CommandException
* @param sender The {@link CommandSender} who is requesting a player match
* @param filter The filter string.
* @see #matchPlayers(org.bukkit.entity.Player) for filter string syntax
* @return The single player
* @throws CommandException If more than one player match was found
*/
public Player matchSinglePlayer(CommandSender sender, String filter)
throws CommandException {
@ -532,11 +547,14 @@ public Player matchSinglePlayer(CommandSender sender, String filter)
/**
* Match only a single player or console.
*
* @param sender
* @param filter
* @return
* @throws CommandException
*
* The filter string syntax is as follows:
* #console, *console, or ! return the server console
* All syntax from {@link #matchSinglePlayer(org.bukkit.command.CommandSender, String)}
* @param sender The sender trying to match a CommandSender
* @param filter The filter string
* @return The resulting CommandSender
* @throws CommandException if either zero or more than one player matched.
*/
public CommandSender matchPlayerOrConsole(CommandSender sender, String filter)
throws CommandException {
@ -554,20 +572,27 @@ public CommandSender matchPlayerOrConsole(CommandSender sender, String filter)
/**
* Get a single player as an iterator for players.
*
* @param player
* @return iterator for players
* @param player The player to return in an Iterable
* @return iterator for player
*/
public Iterable<Player> matchPlayers(Player player) {
return Arrays.asList(new Player[] {player});
return Arrays.asList(player);
}
/**
* Match a world.
* @param sender
*
* @param filter
* @return
* @throws CommandException
*
* The filter string syntax is as follows:
* #main returns the main world
* #normal returns the first world with a normal environment
* #nether return the first world with a nether environment
* #player:[name] returns the world that a player named {@code name} is located in, if the player is online.
* [name] A world with the name {@code name}
*
* @param sender The sender requesting a match
* @param filter The filter string
* @return The resulting world
* @throws CommandException if no world matches
*/
public World matchWorld(CommandSender sender, String filter) throws CommandException {
List<World> worlds = getServer().getWorlds();
@ -625,8 +650,8 @@ public World matchWorld(CommandSender sender, String filter) throws CommandExcep
/**
* Gets a copy of the WorldEdit plugin.
*
* @return
* @throws CommandException
* @return The WorldEditPlugin instance
* @throws CommandException If there is no WorldEditPlugin available
*/
public WorldEditPlugin getWorldEdit() throws CommandException {
Plugin worldEdit = getServer().getPluginManager().getPlugin("WorldEdit");
@ -644,8 +669,8 @@ public WorldEditPlugin getWorldEdit() throws CommandException {
/**
* Wrap a player as a LocalPlayer.
*
* @param player
* @return
* @param player The player to wrap
* @return The wrapped player
*/
public LocalPlayer wrapPlayer(Player player) {
return new BukkitPlayer(this, player);
@ -654,8 +679,8 @@ public LocalPlayer wrapPlayer(Player player) {
/**
* Create a default configuration file from the .jar.
*
* @param actual
* @param defaultName
* @param actual The destination file
* @param defaultName The name of the file inside the jar's defaults folder
*/
public void createDefaultConfiguration(File actual,
String defaultName) {
@ -701,14 +726,14 @@ public void createDefaultConfiguration(File actual,
if (input != null) {
input.close();
}
} catch (IOException e) {
} catch (IOException ignore) {
}
try {
if (output != null) {
output.close();
}
} catch (IOException e) {
} catch (IOException ignore) {
}
}
}
@ -716,12 +741,16 @@ public void createDefaultConfiguration(File actual,
/**
* Notifies all with the notify permission.
*
* @param msg
* This will check both superperms and WEPIF,
* but makes sure WEPIF checks don't result in duplicate notifications
*
* @param msg The notification to broadcast
*/
public void broadcastNotification(String msg) {
getServer().broadcast(msg, "worldguard.notify");
for (Player player : getServer().getOnlinePlayers()) {
if (hasPermission(player, "worldguard.notify")) {
if (hasPermission(player, "worldguard.notify") &&
!player.hasPermission("worldguard.notify")) { // Make sure the player wasn't already broadcasted to.
player.sendMessage(msg);
}
}
@ -731,7 +760,7 @@ public void broadcastNotification(String msg) {
/**
* Forgets a player.
*
* @param player
* @param player The player to remove state information for
*/
public void forgetPlayer(Player player) {
flagStateManager.forget(player);
@ -741,9 +770,10 @@ public void forgetPlayer(Player player) {
* Checks to see if a player can build at a location. This will return
* true if region protection is disabled.
*
* @param player
* @param loc
* @return
* @param player The player to check.
* @param loc The location to check at.
* @see GlobalRegionManager#canBuild(org.bukkit.entity.Player, org.bukkit.Location)
* @return whether {@code player} can build at {@code loc}
*/
public boolean canBuild(Player player, Location loc) {
return getGlobalRegionManager().canBuild(player, loc);
@ -753,9 +783,10 @@ public boolean canBuild(Player player, Location loc) {
* Checks to see if a player can build at a location. This will return
* true if region protection is disabled.
*
* @param player
* @param block
* @return
* @param player The player to check
* @param block The block to check at.
* @see GlobalRegionManager#canBuild(org.bukkit.entity.Player, org.bukkit.block.Block)
* @return whether {@code player} can build at {@code block}'s location
*/
public boolean canBuild(Player player, Block block) {
return getGlobalRegionManager().canBuild(player, block);
@ -778,9 +809,17 @@ public RegionManager getRegionManager(World world) {
/**
* Replace macros in the text.
*
* @param sender
* @param message
* @return
* The macros replaced are as follows:
* %name%: The name of {@code sender}. See {@link #toName(org.bukkit.command.CommandSender)}
* %id%: The unique name of the sender. See {@link #toUniqueName(org.bukkit.command.CommandSender)}
* %online%: The number of players currently online on the server
* If {@code sender} is a Player:
* %world%: The name of the world {@code sender} is located in
* %health%: The health of {@code sender}. See {@link org.bukkit.entity.Player#getHealth()}
*
* @param sender The sender to check
* @param message The message to replace macros in
* @return The message with macros replaced
*/
public String replaceMacros(CommandSender sender, String message) {
Player[] online = getServer().getOnlinePlayers();

View File

@ -24,11 +24,15 @@ public void registerEvents() {
@EventHandler
public void onPluginEnable(PluginEnableEvent event) {
plugin.getGlobalStateManager().updateCommandBookGodMode();
if (event.getPlugin().getDescription().getName().equalsIgnoreCase("CommandBook")) {
plugin.getGlobalStateManager().updateCommandBookGodMode();
}
}
@EventHandler
public void onPluginDisable(PluginDisableEvent event) {
plugin.getGlobalStateManager().updateCommandBookGodMode();
if (event.getPlugin().getDescription().getName().equalsIgnoreCase("CommandBook")) {
plugin.getGlobalStateManager().updateCommandBookGodMode();
}
}
}

View File

@ -44,9 +44,6 @@ public void registerEvents() {
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}
/**
* Called when a vehicle is destroyed.
*/
@EventHandler
public void onVehicleDestroy(VehicleDestroyEvent event) {
Vehicle vehicle = event.getVehicle();
@ -74,9 +71,6 @@ public void onVehicleDestroy(VehicleDestroyEvent event) {
}
}
/**
* Called when a vehicle moves.
*/
@EventHandler
public void onVehicleMove(VehicleMoveEvent event) {
Vehicle vehicle = event.getVehicle();

View File

@ -42,7 +42,7 @@ public class WorldGuardWeatherListener implements Listener {
/**
* Construct the object;
*
* @param plugin
* @param plugin The plugin instance
*/
public WorldGuardWeatherListener(WorldGuardPlugin plugin) {
this.plugin = plugin;

View File

@ -19,7 +19,7 @@ public class WorldGuardWorldListener implements Listener {
/**
* Construct the object;
*
* @param plugin
* @param plugin The plugin instance
*/
public WorldGuardWorldListener(WorldGuardPlugin plugin) {
this.plugin = plugin;
@ -32,9 +32,6 @@ public void registerEvents() {
plugin.getServer().getPluginManager().registerEvents(this, plugin);
}
/**
* Called when a chunk is loaded.
*/
@EventHandler
public void onChunkLoad(ChunkLoadEvent event) {
ConfigurationManager cfg = plugin.getGlobalStateManager();
@ -56,14 +53,19 @@ public void onChunkLoad(ChunkLoadEvent event) {
}
}
/**
* Called when a world is loaded.
*/
@EventHandler
public void onWorldLoad(WorldLoadEvent event) {
initWorld(event.getWorld());
}
/**
* Initialize the settings for the specified world
* @see WorldConfiguration#alwaysRaining
* @see WorldConfiguration#disableWeather
* @see WorldConfiguration#alwaysThundering
* @see WorldConfiguration#disableThunder
* @param world The specified world
*/
public void initWorld(World world) {
ConfigurationManager cfg = plugin.getGlobalStateManager();
WorldConfiguration wcfg = cfg.get(world);

View File

@ -58,7 +58,7 @@
import com.sk89q.worldguard.protection.databases.migrators.AbstractDatabaseMigrator;
import com.sk89q.worldguard.protection.databases.migrators.MigrationException;
import com.sk89q.worldguard.protection.databases.migrators.MigratorKey;
import com.sk89q.worldguard.util.RegionUtil;
import com.sk89q.worldguard.protection.databases.RegionDBUtil;
public class RegionCommands {
private final WorldGuardPlugin plugin;
@ -118,7 +118,7 @@ public void define(CommandContext args, CommandSender sender) throws CommandExce
// Get the list of region owners
if (args.argsLength() > 1) {
region.setOwners(RegionUtil.parseDomainString(args.getSlice(1), 1));
region.setOwners(RegionDBUtil.parseDomainString(args.getSlice(1), 1));
}
mgr.addRegion(region);
@ -191,7 +191,7 @@ public void redefine(CommandContext args, CommandSender sender) throws CommandEx
region.setPriority(existing.getPriority());
try {
region.setParent(existing.getParent());
} catch (CircularInheritanceException e) {
} catch (CircularInheritanceException ignore) {
}
mgr.addRegion(region);
@ -256,7 +256,7 @@ public void claim(CommandContext args, CommandSender sender) throws CommandExcep
// Get the list of region owners
if (args.argsLength() > 1) {
region.setOwners(RegionUtil.parseDomainString(args.getSlice(1), 1));
region.setOwners(RegionDBUtil.parseDomainString(args.getSlice(1), 1));
}
WorldConfiguration wcfg = plugin.getGlobalStateManager().get(player.getWorld());
@ -494,8 +494,8 @@ public void list(CommandContext args, CommandSender sender) throws CommandExcept
if (!own)
plugin.checkPermission(sender, "worldguard.region.list");
if (args.argsLength() > 0 + argl) {
page = Math.max(0, args.getInteger(0 + argl) - 1);
if (args.argsLength() > argl) {
page = Math.max(0, args.getInteger(argl) - 1);
}
if (args.argsLength() > 1 + argl) {
@ -513,8 +513,8 @@ public void list(CommandContext args, CommandSender sender) throws CommandExcept
String[] regionIDList = new String[size];
int index = 0;
boolean show = false;
String prefix = "";
boolean show;
String prefix;
for (String id : regions.keySet()) {
show = false;
prefix = "";
@ -780,7 +780,7 @@ public void setParent(CommandContext args, CommandSender sender) throws CommandE
if (args.argsLength() == 1) {
try {
region.setParent(null);
} catch (CircularInheritanceException e) {
} catch (CircularInheritanceException ignore) {
}
sender.sendMessage(ChatColor.YELLOW
@ -982,17 +982,17 @@ public void migratedb(CommandContext args, CommandSender sender) throws CommandE
AbstractDatabaseMigrator migrator = cls.getConstructor(WorldGuardPlugin.class).newInstance(plugin);
migrator.migrate();
} catch (IllegalArgumentException e) {
} catch (SecurityException e) {
} catch (InstantiationException e) {
} catch (IllegalAccessException e) {
} catch (InvocationTargetException e) {
} catch (NoSuchMethodException e) {
} catch (IllegalArgumentException ignore) {
} catch (SecurityException ignore) {
} catch (InstantiationException ignore) {
} catch (IllegalAccessException ignore) {
} catch (InvocationTargetException ignore) {
} catch (NoSuchMethodException ignore) {
} catch (MigrationException e) {
throw new CommandException("Error migrating database: " + e.getMessage());
}
sender.sendMessage(ChatColor.YELLOW + "Regions have been migrated successfuly.\n" +
sender.sendMessage(ChatColor.YELLOW + "Regions have been migrated successfully.\n" +
"If you wish to use the destination format as your new backend, please update your config and reload WorldGuard.");
}
}

View File

@ -34,7 +34,7 @@
import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import com.sk89q.worldguard.protection.databases.ProtectionDatabaseException;
import com.sk89q.worldguard.util.RegionUtil;
import com.sk89q.worldguard.protection.databases.RegionDBUtil;
// @TODO: A lot of code duplication here! Need to fix.
@ -70,7 +70,7 @@ public void addMember(CommandContext args, CommandSender sender) throws CommandE
plugin.checkPermission(sender, "worldguard.region.addmember." + id.toLowerCase());
}
RegionUtil.addToDomain(region.getMembers(), args.getPaddedSlice(2, 0), 0);
RegionDBUtil.addToDomain(region.getMembers(), args.getPaddedSlice(2, 0), 0);
sender.sendMessage(ChatColor.YELLOW
+ "Region '" + id + "' updated.");
@ -102,7 +102,7 @@ public void addOwner(CommandContext args, CommandSender sender) throws CommandEx
Boolean flag = region.getFlag(DefaultFlag.BUYABLE);
DefaultDomain owners = region.getOwners();
if (flag != null && flag == true && owners != null && owners.size() == 0) {
if (flag != null && flag && owners != null && owners.size() == 0) {
if (!plugin.hasPermission(player, "worldguard.region.unlimited")) {
int maxRegionCount = plugin.getGlobalStateManager().get(world).getMaxRegionCount(player);
if (maxRegionCount >= 0 && mgr.getRegionCountOfPlayer(localPlayer)
@ -121,7 +121,7 @@ public void addOwner(CommandContext args, CommandSender sender) throws CommandEx
}
}
RegionUtil.addToDomain(region.getOwners(), args.getPaddedSlice(2, 0), 0);
RegionDBUtil.addToDomain(region.getOwners(), args.getPaddedSlice(2, 0), 0);
sender.sendMessage(ChatColor.YELLOW
+ "Region '" + id + "' updated.");
@ -159,7 +159,7 @@ public void removeMember(CommandContext args, CommandSender sender) throws Comma
plugin.checkPermission(sender, "worldguard.region.removemember." + id.toLowerCase());
}
RegionUtil.removeFromDomain(region.getMembers(), args.getPaddedSlice(2, 0), 0);
RegionDBUtil.removeFromDomain(region.getMembers(), args.getPaddedSlice(2, 0), 0);
sender.sendMessage(ChatColor.YELLOW
+ "Region '" + id + "' updated.");
@ -198,7 +198,7 @@ public void removeOwner(CommandContext args,
plugin.checkPermission(sender, "worldguard.region.removeowner." + id.toLowerCase());
}
RegionUtil.removeFromDomain(region.getOwners(), args.getPaddedSlice(2, 0), 0);
RegionDBUtil.removeFromDomain(region.getOwners(), args.getPaddedSlice(2, 0), 0);
sender.sendMessage(ChatColor.YELLOW
+ "Region '" + id + "' updated.");

View File

@ -31,9 +31,9 @@ public interface ChestProtection {
/**
* Returns whether a block is protected.
*
* @param block
* @param player
* @return
* @param block The block to check
* @param player The player to check
* @return Whether the block is protected for player
*/
public boolean isProtected(Block block, Player player);
@ -41,26 +41,27 @@ public interface ChestProtection {
* Returns whether a location where a chest block is trying to be created
* is protected.
*
* @param block
* @param player
* @return
* @param block The block to check
* @param player The player to check
* @return Whether {@code player} can place a block at the specified block
*/
public boolean isProtectedPlacement(Block block, Player player);
/**
* Returns whether an adjacent chest is protected.
*
* @param searchBlock
* @param player
* @return
* @param searchBlock The block to check
* @param player The player to check
* @return Whether {@code searchBlock} is protected from access by {@code player}
*/
public boolean isAdjacentChestProtected(Block searchBlock, Player player);
/**
* Returns whether a material is a chest.
*
* @param material
* @return
*
* @param material The material to check
* @deprecated see {@link #isChest(int)}
* @return {@link #isChest(int)}
*/
@Deprecated
public boolean isChest(Material material);
@ -68,8 +69,8 @@ public interface ChestProtection {
/**
* Returns whether a material is a chest.
*
* @param type
* @return
* @param type The type to check
* @return Whether type is a 'chest' (block that can be protected)
*/
public boolean isChest(int type);

View File

@ -127,23 +127,23 @@ public boolean isAdjacentChestProtected(Block searchBlock, Player player) {
side = searchBlock;
res = isProtected(side, player);
if (res != null && res == true) return res;
if (res != null && res) return res;
side = searchBlock.getRelative(-1, 0, 0);
res = isProtected(side, player);
if (res != null && res == true) return res;
if (res != null && res) return res;
side = searchBlock.getRelative(1, 0, 0);
res = isProtected(side, player);
if (res != null && res == true) return res;
if (res != null && res) return res;
side = searchBlock.getRelative(0, 0, -1);
res = isProtected(side, player);
if (res != null && res == true) return res;
if (res != null && res) return res;
side = searchBlock.getRelative(0, 0, 1);
res = isProtected(side, player);
if (res != null && res == true) return res;
if (res != null && res) return res;
return false;
}

View File

@ -6,8 +6,8 @@ public interface Domain {
/**
* Returns true if a domain contains a player.
*
* @param player
* @return
* @param player The player to check
* @return whether this domain contains {@code player}
*/
public boolean contains(LocalPlayer player);
}

View File

@ -53,8 +53,8 @@ public class ApplicableRegionSet implements Iterable<ProtectedRegion> {
/**
* Construct the object.
*
* @param applicable
* @param globalRegion
* @param applicable The regions contained in this set
* @param globalRegion The global region, set aside for special handling.
*/
public ApplicableRegionSet(Collection<ProtectedRegion> applicable,
ProtectedRegion globalRegion) {
@ -65,7 +65,7 @@ public ApplicableRegionSet(Collection<ProtectedRegion> applicable,
/**
* Checks if a player can build in an area.
*
* @param player
* @param player The player to chec
* @return build ability
*/
public boolean canBuild(LocalPlayer player) {
@ -75,7 +75,7 @@ public boolean canBuild(LocalPlayer player) {
/**
* Checks if a player can use buttons and such in an area.
*
* @param player
* @param player The player to check
* @return able to use items
*/
public boolean canUse(LocalPlayer player) {
@ -151,7 +151,7 @@ public boolean isMemberOfAll(LocalPlayer player) {
* @param flag flag to check
* @param player null to not check owners and members
* @param groupPlayer player to use for the group flag check
* @return
* @return the allow/deny state for the flag
*/
private boolean internalGetState(StateFlag flag, LocalPlayer player,
LocalPlayer groupPlayer) {
@ -275,16 +275,16 @@ private boolean internalGetState(StateFlag flag, LocalPlayer player,
found = true;
}
return found == false ? def :
return !found ? def :
(allowed || (player != null && needsClear.size() == 0));
}
/**
* Clear a region's parents for isFlagAllowed().
*
* @param needsClear
* @param hasCleared
* @param region
* @param needsClear The regions that should be cleared
* @param hasCleared The regions already cleared
* @param region The region to start from
*/
private void clearParents(Set<ProtectedRegion> needsClear,
Set<ProtectedRegion> hasCleared, ProtectedRegion region) {
@ -299,6 +299,11 @@ private void clearParents(Set<ProtectedRegion> needsClear,
}
}
/**
* @see #getFlag(com.sk89q.worldguard.protection.flags.Flag, com.sk89q.worldguard.LocalPlayer)
* @param flag flag to check
* @return value of the flag
*/
public <T extends Flag<V>, V> V getFlag(T flag) {
return getFlag(flag, null);
}
@ -308,6 +313,7 @@ public <T extends Flag<V>, V> V getFlag(T flag) {
* (use {@link #allows(StateFlag, LocalPlayer)} for that).
*
* @param flag flag to check
* @param groupPlayer player to check {@link RegionGroup}s against
* @return value of the flag
* @throws IllegalArgumentException if a StateFlag is given
*/
@ -372,9 +378,9 @@ public <T extends Flag<V>, V> V getFlag(T flag, LocalPlayer groupPlayer) {
/**
* Clear a region's parents for getFlag().
*
* @param needsClear
* @param hasCleared
* @param region
* @param needsClear The regions that should be cleared
* @param hasCleared The regions already cleared
* @param region The region to start from
*/
private void clearParents(Map<ProtectedRegion, ?> needsClear,
Set<ProtectedRegion> hasCleared, ProtectedRegion region) {
@ -392,7 +398,7 @@ private void clearParents(Map<ProtectedRegion, ?> needsClear,
/**
* Get the number of regions that are included.
*
* @return
* @return the size of this ApplicbleRegionSet
*/
public int size() {
return applicable.size();
@ -400,8 +406,6 @@ public int size() {
/**
* Get an iterator of affected regions.
*
* @return
*/
public Iterator<ProtectedRegion> iterator() {
return applicable.iterator();

View File

@ -73,7 +73,7 @@ public class GlobalRegionManager {
/**
* Construct the object.
*
* @param plugin
* @param plugin The plugin instance
*/
public GlobalRegionManager(WorldGuardPlugin plugin) {
this.plugin = plugin;
@ -93,8 +93,8 @@ public void unload() {
/**
* Get the path for a world's regions file.
*
* @param name
* @return
* @param name The name of the world
* @return The region file path for a world's region file
*/
protected File getPath(String name) {
return new File(plugin.getDataFolder(),
@ -104,13 +104,12 @@ protected File getPath(String name) {
/**
* Unload region information for a world.
*
* @param name
* @param name The name of the world to unload
*/
public void unload(String name) {
RegionManager manager = managers.get(name);
RegionManager manager = managers.remove(name);
if (manager != null) {
managers.remove(name);
lastModified.remove(name);
}
}
@ -126,12 +125,12 @@ public void unloadAll() {
/**
* Load region information for a world.
*
* @param world
* @return
* @param world The world to load a RegionManager for
* @return the loaded RegionManager
*/
public RegionManager load(World world) {
String name = world.getName();
ProtectionDatabase database = null;
ProtectionDatabase database;
File file = null;
try {
@ -209,7 +208,7 @@ public void reloadChanged() {
load(world);
}
}
} catch (Exception e) {
} catch (Exception ignore) {
}
}
}
@ -217,8 +216,8 @@ public void reloadChanged() {
/**
* Get the region manager for a particular world.
*
* @param world
* @return
* @param world The world to get a RegionManager for
* @return The region manager.
*/
public RegionManager get(World world) {
RegionManager manager = managers.get(world.getName());
@ -233,9 +232,9 @@ public RegionManager get(World world) {
/**
* Returns whether the player can bypass.
*
* @param player
* @param world
* @return
* @param player The player to check
* @param world The world to check for
* @return Whether {@code player} has bypass permission for {@code world}
*/
public boolean hasBypass(LocalPlayer player, World world) {
return player.hasPermission("worldguard.region.bypass."
@ -245,21 +244,21 @@ public boolean hasBypass(LocalPlayer player, World world) {
/**
* Returns whether the player can bypass.
*
* @param player
* @param world
* @return
* @param player The player to check
* @param world The world to check
* @return Whether {@code player} has bypass permission for {@code world}
*/
public boolean hasBypass(Player player, World world) {
return plugin.hasPermission(player, "worldguard.region.bypass."
+ world.getName());
+ world.getName());
}
/**
* Check if a player has permission to build at a block.
*
* @param player
* @param block
* @return
* @param player The player to check
* @param block The block to check at
* @return Whether {@code player} can build at {@code block}'s location
*/
public boolean canBuild(Player player, Block block) {
return canBuild(player, block.getLocation());
@ -268,9 +267,9 @@ public boolean canBuild(Player player, Block block) {
/**
* Check if a player has permission to build at a location.
*
* @param player
* @param loc
* @return
* @param player The player to check
* @param loc The location to check
* @return Whether {@code player} can build at {@code loc}
*/
public boolean canBuild(Player player, Location loc) {
World world = loc.getWorld();
@ -294,6 +293,14 @@ public boolean canBuild(Player player, Location loc) {
return true;
}
/**
* Checks to see whether a flag is allowed.
*
* @see #allows(com.sk89q.worldguard.protection.flags.StateFlag, org.bukkit.Location, com.sk89q.worldguard.LocalPlayer)
* @param flag The flag to check
* @param loc The location to check the flag at
* @return Whether the flag is allowed
*/
public boolean allows(StateFlag flag, Location loc) {
return allows(flag, loc, null);
}
@ -301,9 +308,10 @@ public boolean allows(StateFlag flag, Location loc) {
/**
* Checks to see whether a flag is allowed.
*
* @param flag
* @param loc
* @return
* @param flag The flag to check
* @param loc The location to check the flag at
* @param player The player to check for the flag's {@link com.sk89q.worldguard.protection.flags.RegionGroup}
* @return Whether the flag is allowed
*/
public boolean allows(StateFlag flag, Location loc, LocalPlayer player) {
World world = loc.getWorld();

View File

@ -78,7 +78,8 @@ public class CSVDatabase extends AbstractProtectionDatabase {
* Construct the database with a path to a file. No file is read or
* written at this time.
*
* @param file
* @param file The file in CSV format containing the region database
* @param logger The logger to log errors to
*/
public CSVDatabase(File file, Logger logger) {
this.file = file;
@ -92,9 +93,6 @@ public void save() throws ProtectionDatabaseException {
throw new UnsupportedOperationException("CSV format is no longer implemented");
}
/**
* Load the database from file.
*/
public void load() throws ProtectionDatabaseException {
Map<String,ProtectedRegion> regions =
new HashMap<String,ProtectedRegion>();
@ -208,8 +206,8 @@ public void load() throws ProtectionDatabaseException {
/**
* Used to parse the specified domain in the CSV file.
*
* @param data
* @return
* @param data The domain data as a string
* @return The domain data as a DefaultDomain
*/
private DefaultDomain parseDomains(String data) {
if (data == null) {
@ -251,7 +249,7 @@ private DefaultDomain parseDomains(String data) {
/**
* Used to parse the list of flags.
*
* @param data
* @param data The flag data in string format
*/
private void parseFlags(ProtectedRegion region, String data) {
if (data == null) {
@ -336,8 +334,8 @@ private String writeFlag(State state, String flag) {
/**
* Returns a null if a string is null or empty.
*
* @param str
* @return
* @param str The string to format
* @return null if the string is empty or null, otherwise the provided string
*/
protected String nullEmptyString(String str) {
if (str == null) {
@ -349,18 +347,10 @@ protected String nullEmptyString(String str) {
}
}
/**
* Get a list of protected regions.
*
* @return
*/
public Map<String,ProtectedRegion> getRegions() {
return regions;
}
/**
* Get a list of protected regions.
*/
public void setRegions(Map<String,ProtectedRegion> regions) {
this.regions = regions;
}

View File

@ -34,39 +34,39 @@ public interface ProtectionDatabase {
* Load the list of regions. The method should not modify the list returned
* by getRegions() unless the load finishes successfully.
*
* @throws ProtectionDatabaseException
* @throws ProtectionDatabaseException when an error occurs
*/
public void load() throws ProtectionDatabaseException;
/**
* Save the list of regions.
*
* @throws ProtectionDatabaseException
* @throws ProtectionDatabaseException when an error occurs
*/
public void save() throws ProtectionDatabaseException;
/**
* Load the list of regions into a region manager.
*
* @param manager
* @throws ProtectionDatabaseException
* @param manager The manager to load regions into
* @throws ProtectionDatabaseException when an error occurs
*/
public void load(RegionManager manager) throws ProtectionDatabaseException;
/**
* Save the list of regions from a region manager.
*
* @param manager
* @throws ProtectionDatabaseException
* @param manager The manager to load regions into
* @throws ProtectionDatabaseException when an error occurs
*/
public void save(RegionManager manager) throws ProtectionDatabaseException;
/**
* Get a list of regions.
*
* @return
* @return the regions loaded by this ProtectionDatabase
*/
public Map<String,ProtectedRegion> getRegions();
/**
* Set the list of regions.
*
* @param regions
* @param regions The regions to be applied to this ProtectionDatabase
*/
public void setRegions(Map<String,ProtectedRegion> regions);
}

View File

@ -32,18 +32,18 @@
* @author sk89q
*/
public class RegionDBUtil {
private static Pattern groupPattern = Pattern.compile("^[gG]:(.+)$");
private static Pattern groupPattern = Pattern.compile("(?i)^[G]:(.+)$");
private RegionDBUtil() {
}
/**
* Parse a group/player DefaultDomain specification for areas.
* Add the given names to {@code domain}
*
* @param domain
* @param split
* @param startIndex
* @param domain The domain to add to
* @param split The {@link String[]} containing names to add to {@code domain}
* @param startIndex The beginning index in the array
*/
public static void addToDomain(DefaultDomain domain, String[] split,
int startIndex) {
@ -59,11 +59,11 @@ public static void addToDomain(DefaultDomain domain, String[] split,
}
/**
* Parse a group/player DefaultDomain specification for areas.
*
* @param domain
* @param split
* @param startIndex
* Remove the given names from {@code domain}
*
* @param domain The domain to remove from
* @param split The {@link String[]} containing names to remove from {@code domain}
* @param startIndex The beginning index in the array
*/
public static void removeFromDomain(DefaultDomain domain, String[] split,
int startIndex) {
@ -81,9 +81,9 @@ public static void removeFromDomain(DefaultDomain domain, String[] split,
/**
* Parse a group/player DefaultDomain specification for areas.
*
* @param split
* @param startIndex
* @return
* @param split The array of names to add
* @param startIndex The beginning index in the array
* @return The resulting DefaultDomain
*/
public static DefaultDomain parseDomainString(String[] split, int startIndex) {
DefaultDomain domain = new DefaultDomain();
@ -104,8 +104,8 @@ public static DefaultDomain parseDomainString(String[] split, int startIndex) {
/**
* Creates a comma separated list of PreparedStatement place holders
*
* @param length
* @return
* @param length The number of wildcards to create
* @return A string with {@code length} wildcards for usage in a PreparedStatement
*/
public static String preparePlaceHolders(int length) {
StringBuilder builder = new StringBuilder();
@ -121,9 +121,9 @@ public static String preparePlaceHolders(int length) {
/**
* Adds all of the parsed values to the PreparedStatement
*
* @param preparedStatement
* @param values
* @throws SQLException
* @param preparedStatement The preparedStanement to add to
* @param values The values to set
* @throws SQLException see {@link PreparedStatement#setString(int, String)}
*/
public static void setValues(PreparedStatement preparedStatement, String... values) throws SQLException {
for (int i = 0; i < values.length; i++) {

View File

@ -49,46 +49,28 @@ public class FlatRegionManager extends RegionManager {
/**
* Construct the manager.
*
* @param regionloader
* @param regionLoader The loader for regions
*/
public FlatRegionManager(ProtectionDatabase regionloader) {
super(regionloader);
public FlatRegionManager(ProtectionDatabase regionLoader) {
super(regionLoader);
regions = new TreeMap<String, ProtectedRegion>();
}
/**
* Get a list of protected regions.
*
* @return
*/
@Override
public Map<String, ProtectedRegion> getRegions() {
return regions;
}
/**
* Set a list of protected regions.
*/
@Override
public void setRegions(Map<String, ProtectedRegion> regions) {
this.regions = new TreeMap<String, ProtectedRegion>(regions);
}
/**
* Adds a region.
*
* @param region
*/
@Override
public void addRegion(ProtectedRegion region) {
regions.put(region.getId().toLowerCase(), region);
}
/**
* Removes a region and its children.
*
* @param id
*/
@Override
public void removeRegion(String id) {
ProtectedRegion region = regions.get(id.toLowerCase());
@ -110,33 +92,16 @@ public void removeRegion(String id) {
}
}
/**
* Return whether a region exists by an ID.
*
* @param id
* @return
*/
@Override
public boolean hasRegion(String id) {
return regions.containsKey(id.toLowerCase());
}
/**
* Get a region by its ID.
*
* @param id
*/
@Override
public ProtectedRegion getRegion(String id) {
return regions.get(id.toLowerCase());
}
/**
* Get an object for a point for rules to be applied with.
*
* @param pt
* @return
*/
@Override
public ApplicableRegionSet getApplicableRegions(Vector pt) {
TreeSet<ProtectedRegion> appRegions =
@ -182,12 +147,6 @@ public ApplicableRegionSet getApplicableRegions(ProtectedRegion checkRegion) {
return new ApplicableRegionSet(intersectRegions, regions.get("__global__"));
}*/
/**
* Get a list of region IDs that contain a point.
*
* @param pt
* @return
*/
@Override
public List<String> getApplicableRegionsIDs(Vector pt) {
List<String> applicable = new ArrayList<String>();
@ -201,11 +160,6 @@ public List<String> getApplicableRegionsIDs(Vector pt) {
return applicable;
}
/**
* Get an object for a region for rules to be applied with.
*
* @return
*/
@Override
public ApplicableRegionSet getApplicableRegions(ProtectedRegion checkRegion) {
@ -223,13 +177,6 @@ public ApplicableRegionSet getApplicableRegions(ProtectedRegion checkRegion) {
return new ApplicableRegionSet(intersectRegions, regions.get("__global__"));
}
/**
* Returns true if the provided region overlaps with any other region that
* is not owned by the player.
*
* @param player
* @return
*/
@Override
public boolean overlapsUnownedRegion(ProtectedRegion checkRegion, LocalPlayer player) {
List<ProtectedRegion> appRegions = new ArrayList<ProtectedRegion>();
@ -252,11 +199,6 @@ public boolean overlapsUnownedRegion(ProtectedRegion checkRegion, LocalPlayer pl
return intersectRegions.size() > 0;
}
/**
* Get the number of regions.
*
* @return
*/
@Override
public int size() {
return regions.size();

View File

@ -18,10 +18,8 @@
*/
package com.sk89q.worldguard.protection.managers;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
@ -56,29 +54,21 @@ public class PRTreeRegionManager extends RegionManager {
/**
* Construct the manager.
*
* @param regionloader
* @throws IOException
* @param regionLoader The region loader to use
* @throws ProtectionDatabaseException when an error occurs while loading
*/
public PRTreeRegionManager(ProtectionDatabase regionloader) throws ProtectionDatabaseException {
super(regionloader);
public PRTreeRegionManager(ProtectionDatabase regionLoader) throws ProtectionDatabaseException {
super(regionLoader);
regions = new TreeMap<String, ProtectedRegion>();
tree = new PRTree<ProtectedRegion>(converter, BRANCH_FACTOR);
this.load();
}
/**
* Get a list of protected regions.
*
* @return
*/
@Override
public Map<String, ProtectedRegion> getRegions() {
return regions;
}
/**
* Set a list of protected regions.
*/
@Override
public void setRegions(Map<String, ProtectedRegion> regions) {
this.regions = new TreeMap<String, ProtectedRegion>(regions);
@ -86,11 +76,6 @@ public void setRegions(Map<String, ProtectedRegion> regions) {
tree.load(regions.values());
}
/**
* Adds a region.
*
* @param region
*/
@Override
public void addRegion(ProtectedRegion region) {
regions.put(region.getId().toLowerCase(), region);
@ -98,32 +83,16 @@ public void addRegion(ProtectedRegion region) {
tree.load(regions.values());
}
/**
* Return whether a region exists by an ID.
*
* @param id
* @return
*/
@Override
public boolean hasRegion(String id) {
return regions.containsKey(id.toLowerCase());
}
/**
* Get a region by its ID.
*
* @param id
*/
@Override
public ProtectedRegion getRegion(String id) {
return regions.get(id.toLowerCase());
}
/**
* Removes a region and its children.
*
* @param id
*/
@Override
public void removeRegion(String id) {
ProtectedRegion region = regions.get(id.toLowerCase());
@ -132,9 +101,7 @@ public void removeRegion(String id) {
if (region != null) {
List<String> removeRegions = new ArrayList<String>();
Iterator<ProtectedRegion> iter = regions.values().iterator();
while (iter.hasNext()) {
ProtectedRegion curRegion = iter.next();
for (ProtectedRegion curRegion : regions.values()) {
if (curRegion.getParent() == region) {
removeRegions.add(curRegion.getId().toLowerCase());
}
@ -149,12 +116,6 @@ public void removeRegion(String id) {
tree.load(regions.values());
}
/**
* Get an object for a point for rules to be applied with.
*
* @param pt
* @return
*/
@Override
public ApplicableRegionSet getApplicableRegions(Vector pt) {
List<ProtectedRegion> appRegions =
@ -189,12 +150,6 @@ public ApplicableRegionSet getApplicableRegions(ProtectedRegion checkRegion) {
return new ApplicableRegionSet(intersectRegions, regions.get("__global__"));
}
/**
* Get a list of region IDs that contain a point.
*
* @param pt
* @return
*/
@Override
public List<String> getApplicableRegionsIDs(Vector pt) {
List<String> applicable = new ArrayList<String>();
@ -211,13 +166,6 @@ public List<String> getApplicableRegionsIDs(Vector pt) {
return applicable;
}
/**
* Returns true if the provided region overlaps with any other region that
* is not owned by the player.
*
* @param player
* @return
*/
@Override
public boolean overlapsUnownedRegion(ProtectedRegion checkRegion, LocalPlayer player) {
List<ProtectedRegion> appRegions = new ArrayList<ProtectedRegion>();
@ -240,11 +188,6 @@ public boolean overlapsUnownedRegion(ProtectedRegion checkRegion, LocalPlayer pl
return intersectRegions.size() > 0;
}
/**
* Get the number of regions.
*
* @return
*/
@Override
public int size() {
return regions.size();

View File

@ -45,7 +45,7 @@ public abstract class RegionManager {
/**
* Construct the object.
*
* @param loader
* @param loader The loader for this region
*/
public RegionManager(ProtectionDatabase loader) {
this.loader = loader;
@ -55,7 +55,7 @@ public RegionManager(ProtectionDatabase loader) {
* Load the list of regions. If the regions do not load properly, then
* the existing list should be used (as stored previously).
*
* @throws IOException thrown on load error
* @throws ProtectionDatabaseException when an error occurs
*/
public void load() throws ProtectionDatabaseException {
loader.load(this);
@ -64,7 +64,7 @@ public void load() throws ProtectionDatabaseException {
/**
* Save the list of regions.
*
* @throws IOException thrown on save eIf checking multiple flags for a single locationror
* @throws ProtectionDatabaseException when an error occurs while saving
*/
public void save() throws ProtectionDatabaseException {
loader.save(this);

View File

@ -36,9 +36,9 @@ public class ProtectedCuboidRegion extends ProtectedRegion {
/**
* Construct a new instance of this cuboid region.
*
* @param id
* @param pt1
* @param pt2
* @param id The region id
* @param pt1 The first point of this region
* @param pt2 The second point of this region
*/
public ProtectedCuboidRegion(String id, BlockVector pt1, BlockVector pt2) {
super(id);
@ -48,8 +48,8 @@ public ProtectedCuboidRegion(String id, BlockVector pt1, BlockVector pt2) {
/**
* Given any two points, sets the minimum and maximum points
*
* @param pt1
* @param pt2
* @param pt1 The first point of this region
* @param pt2 The second point of this region
*/
private void setMinMaxPoints(BlockVector pt1, BlockVector pt2) {
List<Vector> points = new ArrayList<Vector>();
@ -61,7 +61,7 @@ private void setMinMaxPoints(BlockVector pt1, BlockVector pt2) {
/**
* Set the lower point of the cuboid.
*
* @param pt
* @param pt The point to set as the minimum point
*/
public void setMinimumPoint(BlockVector pt) {
setMinMaxPoints(pt, max);
@ -70,7 +70,7 @@ public void setMinimumPoint(BlockVector pt) {
/**
* Set the upper point of the cuboid.
*
* @param pt
* @param pt The point to set as the maximum point
*/
public void setMaximumPoint(BlockVector pt) {
setMinMaxPoints(min, pt);
@ -91,9 +91,6 @@ public List<BlockVector2D> getPoints() {
return pts;
}
/**
* Checks to see if a point is inside this region.
*/
@Override
public boolean contains(Vector pt) {
final double x = pt.getX();
@ -157,29 +154,17 @@ public List<ProtectedRegion> getIntersectingRegions(List<ProtectedRegion> region
return intersectingRegions;
}
/**
* Return the type of region as a user-friendly name.
*
* @return type of region
*/
@Override
public String getTypeName() {
return "cuboid";
}
/**
* Get the number of Blocks in this region
*
* @return
*/
@Override
public int volume() {
int xLength = max.getBlockX() - min.getBlockX() + 1;
int yLength = max.getBlockY() - min.getBlockY() + 1;
int zLength = max.getBlockZ() - min.getBlockZ() + 1;
int volume = xLength * yLength * zLength;
return volume;
return xLength * yLength * zLength;
}
}

View File

@ -42,9 +42,9 @@ public ProtectedPolygonalRegion(String id, List<BlockVector2D> points, int minY,
/**
* Sets the min and max points from all the 2d points and the min/max Y values
*
* @param points2D
* @param minY
* @param maxY
* @param points2D A {@link List} of points that this region should contain
* @param minY The minimum y coordinate
* @param maxY The maximum y coordinate
*/
private void setMinMaxPoints(List<BlockVector2D> points2D, int minY, int maxY) {
List<Vector> points = new ArrayList<Vector>();
@ -156,11 +156,6 @@ public String getTypeName() {
return "polygon";
}
/**
* Get the number of Blocks in this region
*
* @return
*/
@Override
public int volume() {
int volume = 0;

View File

@ -78,7 +78,7 @@ public abstract class ProtectedRegion implements Comparable<ProtectedRegion> {
/**
* Construct a new instance of this region.
*
* @param id
* @param id The id (name) of this region.
*/
public ProtectedRegion(String id) {
this.id = id;
@ -87,7 +87,7 @@ public ProtectedRegion(String id) {
/**
* Sets the minimum and maximum points of the bounding box for a region
*
* @param points
* @param points The points to set. Must have at least one element.
*/
protected void setMinMaxPoints(List<Vector> points) {
int minX = points.get(0).getBlockX();
@ -116,6 +116,8 @@ protected void setMinMaxPoints(List<Vector> points) {
}
/**
* Gets the id of this region
*
* @return the id
*/
public String getId() {
@ -166,7 +168,7 @@ public ProtectedRegion getParent() {
* in circular inheritance.
*
* @param parent the curParent to setFlag
* @throws CircularInheritanceException
* @throws CircularInheritanceException when circular inheritance is detected
*/
public void setParent(ProtectedRegion parent) throws CircularInheritanceException {
if (parent == null) {
@ -303,9 +305,9 @@ public boolean isMemberOnly(LocalPlayer player) {
/**
* Get a flag's value.
*
* @param <T>
* @param <V>
* @param flag
* @param <T> The flag type
* @param <V> The type of the flag's value
* @param flag The flag to check
* @return value or null if isn't defined
*/
@SuppressWarnings("unchecked")
@ -323,10 +325,10 @@ public <T extends Flag<V>, V> V getFlag(T flag) {
/**
* Set a flag's value.
*
* @param <T>
* @param <V>
* @param flag
* @param val
* @param <T> The flag type
* @param <V> The type of the flag's value
* @param flag The flag to check
* @param val The value to set
*/
public <T extends Flag<V>, V> void setFlag(T flag, V val) {
if (val == null) {
@ -339,7 +341,7 @@ public <T extends Flag<V>, V> void setFlag(T flag, V val) {
/**
* Get the map of flags.
*
* @return
* @return The map of flags currently used for this region
*/
public Map<Flag<?>, Object> getFlags() {
return flags;
@ -348,7 +350,7 @@ public Map<Flag<?>, Object> getFlags() {
/**
* Get the map of flags.
*
* @param flags
* @param flags The flags to set
*/
public void setFlags(Map<Flag<?>, Object> flags) {
this.flags = flags;
@ -357,30 +359,30 @@ public void setFlags(Map<Flag<?>, Object> flags) {
/**
* Gets the 2D points for this region
*
* @return
* @return The points for this region as (x, z) coordinates
*/
public abstract List<BlockVector2D> getPoints();
/**
* Get the number of blocks in this region
*
* @return
* @return the volume of this region in blocks
*/
public abstract int volume();
/**
* Check to see if a point is inside this region.
*
* @param pt
* @return
* @param pt The point to check
* @return Whether {@code pt} is in this region
*/
public abstract boolean contains(Vector pt);
/**
* Check to see if a point is inside this region.
*
* @param pt
* @return
* @param pt The point to check
* @return Whether {@code pt} is in this region
*/
public boolean contains(BlockVector2D pt) {
return contains(new Vector(pt.getBlockX(), min.getBlockY(), pt.getBlockZ()));
@ -389,10 +391,10 @@ public boolean contains(BlockVector2D pt) {
/**
* Check to see if a point is inside this region.
*
* @param x
* @param y
* @param z
* @return
* @param x The x coordinate to check
* @param y The y coordinate to check
* @param z The z coordinate to check
* @return Whether this region contains the points at the given coordinate
*/
public boolean contains(int x, int y, int z) {
return contains(new Vector(x, y, z));
@ -419,8 +421,7 @@ public boolean containsAny(List<BlockVector2D> pts) {
* Orders primarily by the priority, descending<br>
* Orders secondarily by the id, ascending
*
* @param other
* @return
* @param other The region to compare to
*/
public int compareTo(ProtectedRegion other) {
if (priority > other.priority) {
@ -442,9 +443,9 @@ public int compareTo(ProtectedRegion other) {
/**
* Get a list of intersecting regions.
*
* @param regions
* @return
* @throws UnsupportedIntersectionException
* @param regions The list of regions to source from
* @return The elements of {@code regions} that intersect with this region
* @throws UnsupportedIntersectionException if an invalid intersection is detected
*/
public abstract List<ProtectedRegion> getIntersectingRegions(
List<ProtectedRegion> regions)
@ -454,7 +455,8 @@ public abstract List<ProtectedRegion> getIntersectingRegions(
* Checks if the bounding box of a region intersects with with the bounding
* box of this region
*
* @param region
* @param region The region to check
* @return whether the given region intersects
*/
protected boolean intersectsBoundingBox(ProtectedRegion region) {
BlockVector rMaxPoint = region.getMaximumPoint();
@ -477,8 +479,8 @@ protected boolean intersectsBoundingBox(ProtectedRegion region) {
/**
* Compares all edges of two regions to see if any of them intersect
*
* @param region
* @return
* @param region The region to check
* @return whether any edges of a region intersect
*/
protected boolean intersectsEdges(ProtectedRegion region) {
List<BlockVector2D> pts1 = getPoints();
@ -511,16 +513,14 @@ protected boolean intersectsEdges(ProtectedRegion region) {
/**
* Checks to see if the given ID is accurate.
*
* @param id
* @return
* @param id The id to check
* @see #idPattern
* @return Whether the region id given is valid
*/
public static boolean isValidId(String id) {
return idPattern.matcher(id).matches();
}
/**
* Returns the hash code.
*/
@Override
public int hashCode(){
return id.hashCode();
@ -542,7 +542,6 @@ public boolean equals(Object obj) {
/**
* Thrown when setting a curParent would create a circular inheritance
* situation.
*
*/
public static class CircularInheritanceException extends Exception {
private static final long serialVersionUID = 7479613488496776022L;

View File

@ -25,17 +25,24 @@ public class ArrayReader<T> {
public ArrayReader(T[] arr) {
this.arr = arr;
}
/**
* Gets an element from the array
* @param index The index to get an element at
* @return The element at {@code index} if the index is within bounds, otherwise null
*/
public T get(int index) {
if (arr.length > index) {
return arr[index];
} else {
return null;
}
return get(index, null);
}
/**
* Gets an element from the array
* @param index The index to get an element at
* @param def the default value, used when the given index is out of bounds
* @return The element at {@code index} if the index is within bounds, otherwise the default value
*/
public T get(int index, T def) {
if (arr.length > index) {
if (index >= 0 && arr.length > index) {
return arr[index];
} else {
return def;

View File

@ -1,41 +0,0 @@
/*
* WorldGuard
* Copyright (C) 2011 sk89q <http://www.sk89q.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sk89q.worldguard.util;
import java.lang.reflect.Field;
/**
* @author zml2008
*/
public class ReflectionUtil {
@SuppressWarnings("unchecked")
public static <T> T getField(Object from, String name) {
Class<?> checkClass = from.getClass();
do {
try {
Field field = checkClass.getDeclaredField(name);
field.setAccessible(true);
return (T) field.get(from);
} catch (NoSuchFieldException e) {
} catch (IllegalAccessException e) {
}
} while (checkClass.getSuperclass() != Object.class && ((checkClass = checkClass.getSuperclass()) != null));
return null;
}
}

View File

@ -19,83 +19,58 @@
package com.sk89q.worldguard.util;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.sk89q.worldguard.domains.DefaultDomain;
import com.sk89q.worldguard.protection.databases.RegionDBUtil;
/**
* Various utility functions for regions.
*
* @author sk89q
*/
@Deprecated
public class RegionUtil {
private static Pattern groupPattern = Pattern.compile("^[gG]:(.+)$");
private RegionUtil() {
}
/**
* Parse a group/player DefaultDomain specification for areas.
*
* @param domain
* @param split
* @param startIndex
* @param domain The domain
* @param split The arguments
* @param startIndex The index to start at
* @deprecated see {@link RegionDBUtil#addToDomain(com.sk89q.worldguard.domains.DefaultDomain, String[], int)}
*/
@Deprecated
public static void addToDomain(DefaultDomain domain, String[] split,
int startIndex) {
for (int i = startIndex; i < split.length; i++) {
String s = split[i];
Matcher m = groupPattern.matcher(s);
if (m.matches()) {
domain.addGroup(m.group(1));
} else {
domain.addPlayer(s);
}
}
RegionDBUtil.addToDomain(domain, split, startIndex);
}
/**
* Parse a group/player DefaultDomain specification for areas.
*
* @param domain
* @param split
* @param startIndex
* @param domain The domain to add to
* @param split The arguments
* @param startIndex The index to start at
* @deprecated see {@link RegionDBUtil#removeFromDomain(com.sk89q.worldguard.domains.DefaultDomain, String[], int)}
*/
@Deprecated
public static void removeFromDomain(DefaultDomain domain, String[] split,
int startIndex) {
for (int i = startIndex; i < split.length; i++) {
String s = split[i];
Matcher m = groupPattern.matcher(s);
if (m.matches()) {
domain.removeGroup(m.group(1));
} else {
domain.removePlayer(s);
}
}
RegionDBUtil.removeFromDomain(domain, split, startIndex);
}
/**
* Parse a group/player DefaultDomain specification for areas.
*
* @param split
* @param startIndex
* @return
*
* @param split The arguments
* @param startIndex The index to start at
* @deprecated see {@link RegionDBUtil#parseDomainString(String[], int)}
* @return the parsed domain
*/
@Deprecated
public static DefaultDomain parseDomainString(String[] split, int startIndex) {
DefaultDomain domain = new DefaultDomain();
for (int i = startIndex; i < split.length; i++) {
String s = split[i];
Matcher m = groupPattern.matcher(s);
if (m.matches()) {
domain.addGroup(m.group(1));
} else {
domain.addPlayer(s);
}
}
return domain;
return RegionDBUtil.parseDomainString(split, startIndex);
}
}