From 0c780166e0d7f71d3d0339a15c1e1eaa9d870d71 Mon Sep 17 00:00:00 2001
From: matt <4009945+MattBDev@users.noreply.github.com>
Date: Wed, 6 Feb 2019 00:03:52 -0500
Subject: [PATCH] Documentation and PlotId updates minor code tweaks in the
plot class too
Signed-off-by: matt <4009945+MattBDev@users.noreply.github.com>
---
.../plotsquared/bukkit/BukkitMain.java | 83 ++++-----
.../plotsquared/api/PlotAPI.java | 14 +-
.../plotsquared/plot/PlotSquared.java | 44 ++---
.../plotsquared/plot/commands/Cluster.java | 18 +-
.../plotsquared/plot/commands/Comment.java | 8 +-
.../plotsquared/plot/commands/Purge.java | 5 +-
.../plotsquared/plot/commands/Setup.java | 11 +-
.../plotsquared/plot/object/Plot.java | 163 +++++++++---------
.../plotsquared/plot/object/PlotId.java | 20 +--
9 files changed, 184 insertions(+), 182 deletions(-)
diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/BukkitMain.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/BukkitMain.java
index 78cd3a189..d58443025 100644
--- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/BukkitMain.java
+++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/BukkitMain.java
@@ -180,46 +180,49 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
continue;
}
- final PlotId id = PlotId.fromString(name);
- if (id != null) {
- final Plot plot = area.getOwnedPlot(id);
- if (plot != null) {
- if (PlotPlayer.wrap(plot.owner) == null) {
- if (world.getKeepSpawnInMemory()) {
- world.setKeepSpawnInMemory(false);
- return;
+ PlotId id;
+ try {
+ id = PlotId.fromString(name);
+ } catch (IllegalArgumentException ignored) {
+ continue;
+ }
+ final Plot plot = area.getOwnedPlot(id);
+ if (plot != null) {
+ if (PlotPlayer.wrap(plot.owner) == null) {
+ if (world.getKeepSpawnInMemory()) {
+ world.setKeepSpawnInMemory(false);
+ return;
+ }
+ final Chunk[] chunks = world.getLoadedChunks();
+ if (chunks.length == 0) {
+ if (!Bukkit.unloadWorld(world, true)) {
+ PlotSquared.debug("Failed to unload " + world.getName());
}
- final Chunk[] chunks = world.getLoadedChunks();
- if (chunks.length == 0) {
- if (!Bukkit.unloadWorld(world, true)) {
- PlotSquared.debug("Failed to unload " + world.getName());
- }
- return;
- } else {
- int index = 0;
- do {
- final Chunk chunkI = chunks[index++];
- boolean result;
- if (methodUnloadChunk0 != null) {
- try {
- result = (boolean) methodUnloadChunk0
- .invoke(world, chunkI.getX(), chunkI.getZ(), true);
- } catch (Throwable e) {
- methodUnloadChunk0 = null;
- e.printStackTrace();
- continue outer;
- }
- } else {
- result = world
- .unloadChunk(chunkI.getX(), chunkI.getZ(), true, false);
- }
- if (!result) {
+ return;
+ } else {
+ int index = 0;
+ do {
+ final Chunk chunkI = chunks[index++];
+ boolean result;
+ if (methodUnloadChunk0 != null) {
+ try {
+ result = (boolean) methodUnloadChunk0
+ .invoke(world, chunkI.getX(), chunkI.getZ(), true);
+ } catch (Throwable e) {
+ methodUnloadChunk0 = null;
+ e.printStackTrace();
continue outer;
}
- } while (index < chunks.length
- && System.currentTimeMillis() - start < 5);
- return;
- }
+ } else {
+ result = world
+ .unloadChunk(chunkI.getX(), chunkI.getZ(), true, false);
+ }
+ if (!result) {
+ continue outer;
+ }
+ } while (index < chunks.length
+ && System.currentTimeMillis() - start < 5);
+ return;
}
}
}
@@ -532,17 +535,17 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
}
@Override @Nullable
- public final ChunkGenerator getDefaultWorldGenerator(final String world, final String id) {
+ public final ChunkGenerator getDefaultWorldGenerator(final String worldName, final String id) {
final IndependentPlotGenerator result;
if (id != null && id.equalsIgnoreCase("single")) {
result = new SingleWorldGenerator();
} else {
result = PlotSquared.get().IMP.getDefaultGenerator();
- if (!PlotSquared.get().setupPlotWorld(world, id, result)) {
+ if (!PlotSquared.get().setupPlotWorld(worldName, id, result)) {
return null;
}
}
- return (ChunkGenerator) result.specify(world);
+ return (ChunkGenerator) result.specify(worldName);
}
@Override public void registerPlayerEvents() {
diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/api/PlotAPI.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/api/PlotAPI.java
index c966903be..a93f2fa26 100644
--- a/Core/src/main/java/com/github/intellectualsites/plotsquared/api/PlotAPI.java
+++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/api/PlotAPI.java
@@ -37,7 +37,7 @@ import java.util.UUID;
@SuppressWarnings({"unused", "WeakerAccess"}) @NoArgsConstructor public class PlotAPI {
/**
- * Get all plots.
+ * Gets all plots.
*
* @return all plots
* @see PlotSquared#getPlots()
@@ -77,7 +77,7 @@ import java.util.UUID;
}
/**
- * Get the PlotSquared storage file.
+ * Gets the PlotSquared storage file.
*
* @return storage configuration
* @see PlotSquared#storage
@@ -87,7 +87,7 @@ import java.util.UUID;
}
/**
- * Get the main class for this plugin. Only use this if you really need it.
+ * Gets the main class for this plugin. Only use this if you really need it.
*
* @return PlotSquared PlotSquared Main Class
* @see PlotSquared
@@ -114,7 +114,7 @@ import java.util.UUID;
}
/**
- * Get the block/biome set queue
+ * Gets the block/biome set queue
*
* @return GlobalBlockQueue.IMP
*/
@@ -145,7 +145,7 @@ import java.util.UUID;
}
/**
- * Get a list of PlotAreas in the world.
+ * Gets a list of PlotAreas in the world.
*
* @param world The world to check for plot areas
* @return A set of PlotAreas
@@ -198,7 +198,7 @@ import java.util.UUID;
}
/**
- * Get the PlotPlayer for a UUID.
+ * Gets the PlotPlayer for a UUID.
*
*
Please note that PlotSquared can be configured to provide
* different UUIDs than bukkit
@@ -212,7 +212,7 @@ import java.util.UUID;
}
/**
- * Get the PlotPlayer for a username.
+ * Gets the PlotPlayer for a username.
*
* @param player the player to wrap
* @return a {@code PlotPlayer}
diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/PlotSquared.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/PlotSquared.java
index b73fd9426..c686b21de 100644
--- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/PlotSquared.java
+++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/PlotSquared.java
@@ -288,7 +288,7 @@ import java.util.zip.ZipInputStream;
}
/**
- * Get an instance of PlotSquared.
+ * Gets an instance of PlotSquared.
*
* @return instance of PlotSquared
*/
@@ -383,7 +383,7 @@ import java.util.zip.ZipInputStream;
}
/**
- * Get the current PlotSquared version.
+ * Gets the current PlotSquared version.
*
* @return current version in config or null
*/
@@ -392,7 +392,7 @@ import java.util.zip.ZipInputStream;
}
/**
- * Get the server platform this plugin is running on this is running on.
+ * Gets the server platform this plugin is running on this is running on.
*
*
This will be either Bukkit or Sponge
*
@@ -507,7 +507,7 @@ import java.util.zip.ZipInputStream;
}
/**
- * Get all the base plots in a single set (for merged plots it just returns
+ * Gets all the base plots in a single set (for merged plots it just returns
* the bottom plot).
*
* @return Set of base Plots
@@ -806,7 +806,7 @@ import java.util.zip.ZipInputStream;
}
/**
- * Get all the plots in a single set.
+ * Gets all the plots in a single set.
*
* @return Set of Plots
*/
@@ -842,7 +842,7 @@ import java.util.zip.ZipInputStream;
}
/**
- * Get all the plots owned by a player name.
+ * Gets all the plots owned by a player name.
*
* @param world the world
* @param player the plot owner
@@ -854,7 +854,7 @@ import java.util.zip.ZipInputStream;
}
/**
- * Get all the plots owned by a player name.
+ * Gets all the plots owned by a player name.
*
* @param area the PlotArea
* @param player the plot owner
@@ -866,7 +866,7 @@ import java.util.zip.ZipInputStream;
}
/**
- * Get all plots by a PlotPlayer.
+ * Gets all plots by a PlotPlayer.
*
* @param world the world
* @param player the plot owner
@@ -877,7 +877,7 @@ import java.util.zip.ZipInputStream;
}
/**
- * Get all plots by a PlotPlayer.
+ * Gets all plots by a PlotPlayer.
*
* @param area the PlotArea
* @param player the plot owner
@@ -888,7 +888,7 @@ import java.util.zip.ZipInputStream;
}
/**
- * Get all plots by a UUID in a world.
+ * Gets all plots by a UUID in a world.
*
* @param world the world
* @param uuid the plot owner
@@ -905,7 +905,7 @@ import java.util.zip.ZipInputStream;
}
/**
- * Get all plots by a UUID in an area.
+ * Gets all plots by a UUID in an area.
*
* @param area the {@code PlotArea}
* @param uuid the plot owner
@@ -943,7 +943,7 @@ import java.util.zip.ZipInputStream;
}
/**
- * Get the plots for a PlotPlayer.
+ * Gets the plots for a PlotPlayer.
*
* @param player the player to retrieve the plots for
* @return Set of Plot
@@ -965,7 +965,7 @@ import java.util.zip.ZipInputStream;
}
/**
- * Get the plots for a UUID.
+ * Gets the plots for a UUID.
*
* @param uuid the plot owner
* @return Set of Plot's owned by the player
@@ -1000,7 +1000,7 @@ import java.util.zip.ZipInputStream;
}
/**
- * Get the plots for a UUID.
+ * Gets the plots for a UUID.
*
* @param uuid the UUID of the owner
* @return Set of Plot
@@ -1220,7 +1220,7 @@ import java.util.zip.ZipInputStream;
String name = split[0];
PlotId pos1 = PlotId.fromString(split[1]);
PlotId pos2 = PlotId.fromString(split[2]);
- if (pos1 == null || pos2 == null || name.isEmpty()) {
+ if (name.isEmpty()) {
throw new IllegalArgumentException("Invalid Area identifier: " + areaId
+ ". Expected form `--`");
}
@@ -1652,8 +1652,8 @@ import java.util.zip.ZipInputStream;
Settings.COMMIT = "https://github.com/IntellectualSites/PlotSquared/commit/" + Integer
.toHexString(version.hash);
System.out.println("Version is " + this.version);
- } catch (Throwable ignore) {
- ignore.printStackTrace();
+ } catch (Throwable throwable) {
+ throwable.printStackTrace();
}
Settings.save(configFile);
config = YamlConfiguration.loadConfiguration(configFile);
@@ -1815,7 +1815,7 @@ import java.util.zip.ZipInputStream;
}
/**
- * Get the Java version.
+ * Gets the Java version.
*
* @return the java version
*/
@@ -1889,7 +1889,7 @@ import java.util.zip.ZipInputStream;
}
/**
- * Get a list of PlotArea objects.
+ * Gets a list of PlotArea objects.
*
* @param world the world
* @return Collection of PlotArea objects
@@ -1901,7 +1901,7 @@ import java.util.zip.ZipInputStream;
}
/**
- * Get the relevant plot area for a specified location.
+ * Gets the relevant plot area for a specified location.
*
* - If there is only one plot area globally that will be returned.
*
- If there is only one plot area in the world, it will return that.
@@ -1922,7 +1922,7 @@ import java.util.zip.ZipInputStream;
}
/**
- * Get the {@code PlotArea} which contains a location.
+ * Gets the {@code PlotArea} which contains a location.
*
* - If the plot area does not contain a location, null
* will be returned.
@@ -1964,7 +1964,7 @@ import java.util.zip.ZipInputStream;
}
/**
- * Get Plots based on alias
+ * Gets Plots based on alias
*
* @param alias to search plots
* @param worldname to filter alias to a specific world [optional] null means all worlds
diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Cluster.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Cluster.java
index 9145d1b3d..4cb20487b 100644
--- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Cluster.java
+++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Cluster.java
@@ -84,10 +84,13 @@ import java.util.UUID;
if (currentClusters >= player.getAllowedPlots()) {
return sendMessage(player, C.CANT_CLAIM_MORE_CLUSTERS);
}
+ PlotId pos1;
+ PlotId pos2;
// check pos1 / pos2
- PlotId pos1 = PlotId.fromString(args[2]);
- PlotId pos2 = PlotId.fromString(args[3]);
- if (pos1 == null || pos2 == null) {
+ try{
+ pos1 = PlotId.fromString(args[2]);
+ pos2 = PlotId.fromString(args[3]);
+ } catch (IllegalArgumentException ignored) {
MainUtil.sendMessage(player, C.NOT_VALID_PLOT_ID);
return false;
}
@@ -209,10 +212,13 @@ import java.util.UUID;
"/plot cluster resize ");
return false;
}
+ PlotId pos1;
+ PlotId pos2;
// check pos1 / pos2
- PlotId pos1 = PlotId.fromString(args[1]);
- PlotId pos2 = PlotId.fromString(args[2]);
- if (pos1 == null || pos2 == null) {
+ try{
+ pos1 = PlotId.fromString(args[2]);
+ pos2 = PlotId.fromString(args[3]);
+ } catch (IllegalArgumentException ignored) {
MainUtil.sendMessage(player, C.NOT_VALID_PLOT_ID);
return false;
}
diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Comment.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Comment.java
index 775450517..9755d7150 100644
--- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Comment.java
+++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Comment.java
@@ -33,7 +33,13 @@ public class Comment extends SubCommand {
return false;
}
Location loc = player.getLocation();
- PlotId id = PlotId.fromString(args[1]);
+ PlotId id;
+ try {
+ id = PlotId.fromString(args[1]);
+ } catch (IllegalArgumentException ignored) {
+ MainUtil.sendMessage(player, C.NOT_VALID_PLOT_ID);
+ return false;
+ }
Plot plot = MainUtil.getPlotFromString(player, args[1], false);
int index;
if (plot == null) {
diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Purge.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Purge.java
index b8b38e298..9500dec73 100644
--- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Purge.java
+++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Purge.java
@@ -56,8 +56,9 @@ import java.util.UUID;
break;
case "plotid":
case "id":
- id = PlotId.fromString(split[1]);
- if (id == null) {
+ try {
+ id = PlotId.fromString(split[1]);
+ } catch (IllegalArgumentException ignored) {
C.NOT_VALID_PLOT_ID.send(player, split[1]);
return false;
}
diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Setup.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Setup.java
index facea4952..412927526 100644
--- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Setup.java
+++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Setup.java
@@ -182,8 +182,9 @@ import java.util.Map.Entry;
MainUtil.sendMessage(player, "&6What should be the minimum Plot Id?");
break;
case 3: // min
- object.min = PlotId.fromString(args[0]);
- if (object.min == null) {
+ try {
+ object.min = PlotId.fromString(args[0]);
+ } catch (IllegalArgumentException ignored) {
MainUtil.sendMessage(player, "&cYou must choose a valid minimum PlotId!");
return false;
}
@@ -192,8 +193,10 @@ import java.util.Map.Entry;
break;
case 4:
// max
- PlotId id = PlotId.fromString(args[0]);
- if (id == null) {
+ PlotId id;
+ try {
+ id = PlotId.fromString(args[0]);
+ } catch (IllegalArgumentException ignored) {
MainUtil.sendMessage(player, "&cYou must choose a valid maximum PlotId!");
return false;
}
diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java
index 85349cd55..69d0e63ab 100644
--- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java
+++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/Plot.java
@@ -41,14 +41,13 @@ import java.util.concurrent.ConcurrentHashMap;
*/
public class Plot {
+ private static final int MAX_HEIGHT = 256;
/**
* @deprecated raw access is deprecated
*/
@Deprecated private static HashSet connected_cache;
private static HashSet regions_cache;
- /**
- * The {@link PlotId}.
- */
+
private final PlotId id;
/**
* plot owner
@@ -91,9 +90,7 @@ public class Plot {
* - The methods are more likely to be left unchanged from version changes
*/
private PlotSettings settings;
- /**
- * The {@link PlotArea}.
- */
+
private PlotArea area;
/**
* Session only plot metadata (session is until the server stops)
@@ -188,7 +185,7 @@ public class Plot {
}
/**
- * Get a plot from a string e.g. [area];[id]
+ * Gets a plot from a string e.g. [area];[id]
*
* @param defaultArea If no area is specified
* @param string plot id/area + id
@@ -199,7 +196,7 @@ public class Plot {
if (split.length == 2) {
if (defaultArea != null) {
PlotId id = PlotId.fromString(split[0] + ';' + split[1]);
- return id != null ? defaultArea.getPlotAbs(id) : null;
+ return defaultArea.getPlotAbs(id);
}
} else if (split.length == 3) {
PlotArea pa = PlotSquared.get().getPlotArea(split[0], null);
@@ -253,7 +250,7 @@ public class Plot {
}
/**
- * Get the metadata for a key
+ * Gets the metadata for a key
*
* For persistent metadata use the flag system
*
@@ -281,7 +278,7 @@ public class Plot {
}
/**
- * Get the cluster this plot is associated with
+ * Gets the cluster this plot is associated with
*
* @return the PlotCluster object, or null
*/
@@ -299,9 +296,9 @@ public class Plot {
public List getPlayersInPlot() {
ArrayList players = new ArrayList<>();
for (Entry entry : UUIDHandler.getPlayers().entrySet()) {
- PlotPlayer pp = entry.getValue();
- if (this.equals(pp.getCurrentPlot())) {
- players.add(pp);
+ PlotPlayer plotPlayer = entry.getValue();
+ if (this.equals(plotPlayer.getCurrentPlot())) {
+ players.add(plotPlayer);
}
}
return players;
@@ -330,12 +327,7 @@ public class Plot {
return false;
}
Set connected = getConnectedPlots();
- for (Plot current : connected) {
- if (uuid.equals(current.owner)) {
- return true;
- }
- }
- return false;
+ return connected.stream().anyMatch(current -> uuid.equals(current.owner));
}
public boolean isOwnerAbs(UUID uuid) {
@@ -343,7 +335,7 @@ public class Plot {
}
/**
- * Get a immutable set of owner UUIDs for a plot (supports multi-owner mega-plots).
+ * Gets a immutable set of owner UUIDs for a plot (supports multi-owner mega-plots).
*
* @return the plot owners
*/
@@ -406,14 +398,16 @@ public class Plot {
}
/**
- * Get the {@link PlotId}.
+ * Gets the {@link PlotId} of this plot.
+ *
+ * @return the PlotId for this plot
*/
public PlotId getId() {
return this.id;
}
/**
- * Get the plot world object for this plot
+ * Gets the plot world object for this plot
* - The generic PlotArea object can be casted to its respective class for more control (e.g. HybridPlotWorld)
*
* @return PlotArea
@@ -441,7 +435,7 @@ public class Plot {
}
/**
- * Get the plot manager object for this plot
+ * Gets the plot manager object for this plot
* - The generic PlotManager object can be casted to its respective class for more control (e.g. HybridPlotManager)
*
* @return PlotManager
@@ -451,7 +445,7 @@ public class Plot {
}
/**
- * Get or create plot settings.
+ * Gets or create plot settings.
*
* @return PlotSettings
* @deprecated use equivalent plot method;
@@ -518,7 +512,7 @@ public class Plot {
}
/**
- * Get the timestamp of when the plot was created (unreliable)
+ * Gets the timestamp of when the plot was created (unreliable)
* - not accurate if the plot was created before this was implemented
* - Milliseconds since the epoch
*
@@ -532,7 +526,7 @@ public class Plot {
}
/**
- * Get if the plot is merged in a direction
+ * Gets if the plot is merged in a direction
* ------- Actual -------
* 0 = north
* 1 = east
@@ -586,7 +580,7 @@ public class Plot {
}
/**
- * Get the denied users.
+ * Gets the denied users.
*
* @return a set of denied users
*/
@@ -598,7 +592,7 @@ public class Plot {
}
/**
- * Set the denied users for this plot.
+ * Sets the denied users for this plot.
*
* @param uuids uuids to deny
*/
@@ -618,7 +612,7 @@ public class Plot {
}
/**
- * Get the trusted users.
+ * Gets the trusted users.
*
* @return a set of trusted users
*/
@@ -630,7 +624,7 @@ public class Plot {
}
/**
- * Set the trusted users for this plot.
+ * Sets the trusted users for this plot.
*
* @param uuids uuids to trust
*/
@@ -650,7 +644,7 @@ public class Plot {
}
/**
- * Get the members
+ * Gets the members
*
* @return a set of members
*/
@@ -662,7 +656,7 @@ public class Plot {
}
/**
- * Set the members for this plot
+ * Sets the members for this plot.
*
* @param uuids uuids to set member status for
*/
@@ -721,7 +715,7 @@ public class Plot {
}
/**
- * Set the plot owner (and update the database)
+ * Sets the plot owner (and update the database)
*
* @param owner uuid to set as owner
*/
@@ -747,7 +741,7 @@ public class Plot {
}
/**
- * Set the plot owner (and update the database)
+ * Sets the plot owner (and update the database)
*
* @param owner uuid to set as owner
* @param initiator player initiating set owner
@@ -845,7 +839,7 @@ public class Plot {
}
/**
- * Set the biome for a plot asynchronously
+ * Sets the biome for a plot asynchronously.
*
* @param biome The biome e.g. "forest"
* @param whenDone The task to run when finished, or null
@@ -947,7 +941,7 @@ public class Plot {
}
/**
- * Set the sign for a plot to a specific name
+ * Sets the sign for a plot to a specific name
*
* @param name name
*/
@@ -992,7 +986,7 @@ public class Plot {
}
/**
- * Set a flag for this plot
+ * Sets a flag for this plot
*
* @param flag Flag to set
* @param value Flag value
@@ -1015,7 +1009,7 @@ public class Plot {
}
/**
- * Get the flag for a given key
+ * Gets the flag for a given key
*
* @param key Flag to get value for
*/
@@ -1024,7 +1018,7 @@ public class Plot {
}
/**
- * Get the flag for a given key
+ * Gets the flag for a given key
*
* @param key the flag
* @param defaultValue if the key is null, the value to return
@@ -1118,7 +1112,7 @@ public class Plot {
}
/**
- * Get the number of tracked running tasks for this plot
+ * Gets the number of tracked running tasks for this plot
* - Used to track/limit the number of things a player can do on the plot at once
*
* @return number of tasks (int)
@@ -1217,7 +1211,7 @@ public class Plot {
}
/**
- * Set the home location
+ * Sets the home location
*
* @param location location to set as home
*/
@@ -1235,7 +1229,7 @@ public class Plot {
}
/**
- * Get the default home location for a plot
+ * Gets the default home location for a plot
* - Ignores any home location set for that specific plot
*
* @return Location
@@ -1276,27 +1270,24 @@ public class Plot {
for (RegionWrapper region : getRegions()) {
count +=
(region.maxX - (double) region.minX + 1) * (region.maxZ - (double) region.minZ + 1)
- * 256;
+ * MAX_HEIGHT;
}
return count;
}
/**
- * Get the average rating of the plot. This is the value displayed in /plot info
+ * Gets the average rating of the plot. This is the value displayed in /plot info
*
* @return average rating as double
*/
public double getAverageRating() {
- double sum = 0;
Collection ratings = this.getRatings().values();
- for (Rating rating : ratings) {
- sum += rating.getAverageRating();
- }
+ double sum = ratings.stream().mapToDouble(Rating::getAverageRating).sum();
return sum / ratings.size();
}
/**
- * Set a rating for a user
+ * Sets a rating for a user
* - If the user has already rated, the following will return false
*
* @param uuid uuid of rater
@@ -1328,7 +1319,7 @@ public class Plot {
}
/**
- * Get the ratings associated with a plot
+ * Gets the ratings associated with a plot
* - The rating object may contain multiple categories
*
* @return Map of user who rated to the rating
@@ -1383,7 +1374,7 @@ public class Plot {
}
/**
- * Set the plot sign if plot signs are enabled.
+ * Sets the plot sign if plot signs are enabled.
*/
public void setSign() {
if (this.owner == null) {
@@ -1502,7 +1493,7 @@ public class Plot {
}
/**
- * Set components such as border, wall, floor.
+ * Sets components such as border, wall, floor.
* (components are generator specific)
*/
public boolean setComponent(String component, String blocks) {
@@ -1531,10 +1522,10 @@ public class Plot {
return top;
}
+ //TODO Better documentation needed.
/**
* Return the bottom location for the plot.
*
- * @return
*/
public Location getBottomAbs() {
Location loc = this.area.getPlotManager().getPlotBottomLocAbs(this.area, this.id);
@@ -1543,7 +1534,7 @@ public class Plot {
}
/**
- * Swap the settings for two plots.
+ * Swaps the settings for two plots.
*
* @param plot the plot to swap data with
* @param whenDone the task to run at the end of this method.
@@ -1676,7 +1667,7 @@ public class Plot {
Location bot = other.getBottomAbs();
Location top = this.getTopAbs();
Location pos1 = new Location(this.getWorldName(), top.getX(), 0, bot.getZ());
- Location pos2 = new Location(this.getWorldName(), bot.getX(), 256, top.getZ());
+ Location pos2 = new Location(this.getWorldName(), bot.getX(), MAX_HEIGHT, top.getZ());
ChunkManager.manager.regenerateRegion(pos1, pos2, true, null);
} else {
this.area.getPlotManager().removeRoadEast(this.area, this);
@@ -1729,7 +1720,7 @@ public class Plot {
}
/**
- * Get plot display name.
+ * Gets plot display name.
*
* @return alias if set, else id
*/
@@ -1898,7 +1889,7 @@ public class Plot {
}
/**
- * Get the plot hashcode
+ * Gets the plot hashcode
* Note: The hashcode is unique if:
* - Plots are in the same world
* - The x,z coordinates are between Short.MIN_VALUE and Short.MAX_VALUE
@@ -1910,7 +1901,7 @@ public class Plot {
}
/**
- * Get the flags specific to this plot
+ * Gets the flags specific to this plot
* - Does not take default flags into account
*
* @return
@@ -1920,7 +1911,7 @@ public class Plot {
}
/**
- * Set a flag for this plot.
+ * Sets a flag for this plot.
*
* @param flags
*/
@@ -1929,7 +1920,7 @@ public class Plot {
}
/**
- * Get the plot alias.
+ * Gets the plot alias.
* - Returns an empty string if no alias is set
*
* @return The plot alias
@@ -1942,7 +1933,7 @@ public class Plot {
}
/**
- * Set the plot alias.
+ * Sets the plot alias.
*
* @param alias The alias
*/
@@ -1961,7 +1952,7 @@ public class Plot {
}
/**
- * Set the raw merge data
+ * Sets the raw merge data
* - Updates DB
* - Does not modify terrain
* ----------
@@ -1999,7 +1990,7 @@ public class Plot {
}
/**
- * Get the merged array.
+ * Gets the merged array.
*
* @return boolean [ north, east, south, west ]
*/
@@ -2008,10 +1999,10 @@ public class Plot {
}
/**
- * Set the raw merge data
+ * Sets the raw merge data
* - Updates DB
* - Does not modify terrain
- * Get if the plot is merged in a direction
+ * Gets if the plot is merged in a direction
* ----------
* 0 = north
* 1 = east
@@ -2038,7 +2029,7 @@ public class Plot {
}
/**
- * Get the set home location or 0,0,0 if no location is set
+ * Gets the set home location or 0,0,0 if no location is set
* - Does not take the default home location into account
*
* @return
@@ -2145,7 +2136,7 @@ public class Plot {
Location bot = other.getBottomAbs();
Location top = this.getTopAbs();
Location pos1 = new Location(this.getWorldName(), bot.getX(), 0, top.getZ());
- Location pos2 = new Location(this.getWorldName(), top.getX(), 256, bot.getZ());
+ Location pos2 = new Location(this.getWorldName(), top.getX(), MAX_HEIGHT, bot.getZ());
ChunkManager.manager.regenerateRegion(pos1, pos2, true, null);
} else {
this.getManager().removeRoadSouth(this.area, this);
@@ -2248,11 +2239,11 @@ public class Plot {
* Merge the plot settings
* - Used when a plot is merged
*
- * @param b
+ * @param plot
*/
- public void mergeData(Plot b) {
+ public void mergeData(Plot plot) {
HashMap, Object> flags1 = this.getFlags();
- HashMap, Object> flags2 = b.getFlags();
+ HashMap, Object> flags2 = plot.getFlags();
if ((!flags1.isEmpty() || !flags2.isEmpty()) && !flags1.equals(flags2)) {
boolean greater = flags1.size() > flags2.size();
if (greater) {
@@ -2262,30 +2253,30 @@ public class Plot {
}
HashMap, Object> net = (greater ? flags1 : flags2);
this.setFlags(net);
- b.setFlags(net);
+ plot.setFlags(net);
}
if (!this.getAlias().isEmpty()) {
- b.setAlias(this.getAlias());
- } else if (!b.getAlias().isEmpty()) {
- this.setAlias(b.getAlias());
+ plot.setAlias(this.getAlias());
+ } else if (!plot.getAlias().isEmpty()) {
+ this.setAlias(plot.getAlias());
}
for (UUID uuid : this.getTrusted()) {
- b.addTrusted(uuid);
+ plot.addTrusted(uuid);
}
- for (UUID uuid : b.getTrusted()) {
+ for (UUID uuid : plot.getTrusted()) {
this.addTrusted(uuid);
}
for (UUID uuid : this.getMembers()) {
- b.addMember(uuid);
+ plot.addMember(uuid);
}
- for (UUID uuid : b.getMembers()) {
+ for (UUID uuid : plot.getMembers()) {
this.addMember(uuid);
}
for (UUID uuid : this.getDenied()) {
- b.addDenied(uuid);
+ plot.addDenied(uuid);
}
- for (UUID uuid : b.getDenied()) {
+ for (UUID uuid : plot.getDenied()) {
this.addDenied(uuid);
}
}
@@ -2302,7 +2293,7 @@ public class Plot {
Location pos1 = this.getTopAbs().add(1, 0, 1);
Location pos2 = other.getBottomAbs().subtract(1, 0, 1);
pos1.setY(0);
- pos2.setY(256);
+ pos2.setY(MAX_HEIGHT);
ChunkManager.manager.regenerateRegion(pos1, pos2, true, null);
} else {
this.area.getPlotManager().removeRoadSouthEast(this.area, this);
@@ -2310,7 +2301,7 @@ public class Plot {
}
/**
- * Get the plot in a relative location
+ * Gets the plot in a relative location
* Note: May be null if the partial plot area does not include the relative location
*
* @param x
@@ -2326,7 +2317,7 @@ public class Plot {
}
/**
- * Get the plot in a relative direction
+ * Gets the plot in a relative direction
* 0 = north
* 1 = east
* 2 = south
@@ -2341,7 +2332,7 @@ public class Plot {
}
/**
- * Get a set of plots connected (and including) this plot
+ * Gets a set of plots connected (and including) this plot
* - This result is cached globally
*
* @return
@@ -2640,7 +2631,7 @@ public class Plot {
}
/**
- * Get all the corners of the plot (supports non-rectangular shapes).
+ * Gets all the corners of the plot (supports non-rectangular shapes).
*
* @return A list of the plot corners
*/
@@ -2722,7 +2713,7 @@ public class Plot {
}
/**
- * Set a component for a plot to the provided blocks
+ * Sets a component for a plot to the provided blocks
* - E.g. floor, wall, border etc.
* - The available components depend on the generator being used
*
diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotId.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotId.java
index 113495512..821a22327 100644
--- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotId.java
+++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/object/PlotId.java
@@ -1,5 +1,6 @@
package com.github.intellectualsites.plotsquared.plot.object;
+import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public class PlotId {
@@ -30,22 +31,13 @@ public class PlotId {
* @param string to create id from
* @return null if the string is invalid
*/
- public static PlotId fromString(String string) {
- if (string == null) {
- return null;
- }
+ public static PlotId fromString(@Nonnull String string) {
String[] parts = string.split("[;|,]");
if (parts.length < 2) {
- return null;
- }
- int x;
- int y;
- try {
- x = Integer.parseInt(parts[0]);
- y = Integer.parseInt(parts[1]);
- } catch (NumberFormatException ignored) {
- return null;
+ throw new IllegalArgumentException("Cannot create PlotID. String invalid.");
}
+ int x = Integer.parseInt(parts[0]);
+ int y = Integer.parseInt(parts[1]);
return new PlotId(x, y);
}
@@ -54,7 +46,7 @@ public class PlotId {
}
/**
- * Get the PlotId from the HashCode
+ * Gets the PlotId from the HashCode
* Note: Only accurate for small x,z values (short)
*
* @param hash