Documentation and PlotId updates

minor code tweaks in the plot class too

Signed-off-by: matt <4009945+MattBDev@users.noreply.github.com>
This commit is contained in:
matt 2019-02-06 00:03:52 -05:00
parent 87547834ef
commit 0c780166e0
9 changed files with 184 additions and 182 deletions

View File

@ -180,8 +180,12 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
continue; continue;
} }
final PlotId id = PlotId.fromString(name); PlotId id;
if (id != null) { try {
id = PlotId.fromString(name);
} catch (IllegalArgumentException ignored) {
continue;
}
final Plot plot = area.getOwnedPlot(id); final Plot plot = area.getOwnedPlot(id);
if (plot != null) { if (plot != null) {
if (PlotPlayer.wrap(plot.owner) == null) { if (PlotPlayer.wrap(plot.owner) == null) {
@ -225,7 +229,6 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
} }
} }
} }
}
@Override public void onDisable() { @Override public void onDisable() {
PlotSquared.get().disable(); PlotSquared.get().disable();
@ -532,17 +535,17 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
} }
@Override @Nullable @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; final IndependentPlotGenerator result;
if (id != null && id.equalsIgnoreCase("single")) { if (id != null && id.equalsIgnoreCase("single")) {
result = new SingleWorldGenerator(); result = new SingleWorldGenerator();
} else { } else {
result = PlotSquared.get().IMP.getDefaultGenerator(); result = PlotSquared.get().IMP.getDefaultGenerator();
if (!PlotSquared.get().setupPlotWorld(world, id, result)) { if (!PlotSquared.get().setupPlotWorld(worldName, id, result)) {
return null; return null;
} }
} }
return (ChunkGenerator) result.specify(world); return (ChunkGenerator) result.specify(worldName);
} }
@Override public void registerPlayerEvents() { @Override public void registerPlayerEvents() {

View File

@ -37,7 +37,7 @@ import java.util.UUID;
@SuppressWarnings({"unused", "WeakerAccess"}) @NoArgsConstructor public class PlotAPI { @SuppressWarnings({"unused", "WeakerAccess"}) @NoArgsConstructor public class PlotAPI {
/** /**
* Get all plots. * Gets all plots.
* *
* @return all plots * @return all plots
* @see PlotSquared#getPlots() * @see PlotSquared#getPlots()
@ -77,7 +77,7 @@ import java.util.UUID;
} }
/** /**
* Get the PlotSquared storage file. * Gets the PlotSquared storage file.
* *
* @return storage configuration * @return storage configuration
* @see PlotSquared#storage * @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 * @return PlotSquared PlotSquared Main Class
* @see PlotSquared * @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 * @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 * @param world The world to check for plot areas
* @return A set of PlotAreas * @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.
* *
* <p><i>Please note that PlotSquared can be configured to provide * <p><i>Please note that PlotSquared can be configured to provide
* different UUIDs than bukkit</i> * different UUIDs than bukkit</i>
@ -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 * @param player the player to wrap
* @return a {@code PlotPlayer} * @return a {@code PlotPlayer}

View File

@ -288,7 +288,7 @@ import java.util.zip.ZipInputStream;
} }
/** /**
* Get an instance of PlotSquared. * Gets an instance of PlotSquared.
* *
* @return 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 * @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.
* <p> * <p>
* <p>This will be either <b>Bukkit</b> or <b>Sponge</b></p> * <p>This will be either <b>Bukkit</b> or <b>Sponge</b></p>
* *
@ -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). * the bottom plot).
* *
* @return Set of base Plots * @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 * @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 world the world
* @param player the plot owner * @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 area the PlotArea
* @param player the plot owner * @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 world the world
* @param player the plot owner * @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 area the PlotArea
* @param player the plot owner * @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 world the world
* @param uuid the plot owner * @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 area the {@code PlotArea}
* @param uuid the plot owner * @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 * @param player the player to retrieve the plots for
* @return Set of Plot * @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 * @param uuid the plot owner
* @return Set of Plot's owned by the player * @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 * @param uuid the UUID of the owner
* @return Set of Plot * @return Set of Plot
@ -1220,7 +1220,7 @@ import java.util.zip.ZipInputStream;
String name = split[0]; String name = split[0];
PlotId pos1 = PlotId.fromString(split[1]); PlotId pos1 = PlotId.fromString(split[1]);
PlotId pos2 = PlotId.fromString(split[2]); PlotId pos2 = PlotId.fromString(split[2]);
if (pos1 == null || pos2 == null || name.isEmpty()) { if (name.isEmpty()) {
throw new IllegalArgumentException("Invalid Area identifier: " + areaId throw new IllegalArgumentException("Invalid Area identifier: " + areaId
+ ". Expected form `<name>-<x1;z1>-<x2;z2>`"); + ". Expected form `<name>-<x1;z1>-<x2;z2>`");
} }
@ -1652,8 +1652,8 @@ import java.util.zip.ZipInputStream;
Settings.COMMIT = "https://github.com/IntellectualSites/PlotSquared/commit/" + Integer Settings.COMMIT = "https://github.com/IntellectualSites/PlotSquared/commit/" + Integer
.toHexString(version.hash); .toHexString(version.hash);
System.out.println("Version is " + this.version); System.out.println("Version is " + this.version);
} catch (Throwable ignore) { } catch (Throwable throwable) {
ignore.printStackTrace(); throwable.printStackTrace();
} }
Settings.save(configFile); Settings.save(configFile);
config = YamlConfiguration.loadConfiguration(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 * @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 * @param world the world
* @return Collection of PlotArea objects * @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.
* <ul> * <ul>
* <li>If there is only one plot area globally that will be returned. * <li>If there is only one plot area globally that will be returned.
* <li>If there is only one plot area in the world, it will return that. * <li>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.
* <ul> * <ul>
* <li>If the plot area does not contain a location, null * <li>If the plot area does not contain a location, null
* will be returned. * 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 alias to search plots
* @param worldname to filter alias to a specific world [optional] null means all worlds * @param worldname to filter alias to a specific world [optional] null means all worlds

View File

@ -84,10 +84,13 @@ import java.util.UUID;
if (currentClusters >= player.getAllowedPlots()) { if (currentClusters >= player.getAllowedPlots()) {
return sendMessage(player, C.CANT_CLAIM_MORE_CLUSTERS); return sendMessage(player, C.CANT_CLAIM_MORE_CLUSTERS);
} }
PlotId pos1;
PlotId pos2;
// check pos1 / pos2 // check pos1 / pos2
PlotId pos1 = PlotId.fromString(args[2]); try{
PlotId pos2 = PlotId.fromString(args[3]); pos1 = PlotId.fromString(args[2]);
if (pos1 == null || pos2 == null) { pos2 = PlotId.fromString(args[3]);
} catch (IllegalArgumentException ignored) {
MainUtil.sendMessage(player, C.NOT_VALID_PLOT_ID); MainUtil.sendMessage(player, C.NOT_VALID_PLOT_ID);
return false; return false;
} }
@ -209,10 +212,13 @@ import java.util.UUID;
"/plot cluster resize <pos1> <pos2>"); "/plot cluster resize <pos1> <pos2>");
return false; return false;
} }
PlotId pos1;
PlotId pos2;
// check pos1 / pos2 // check pos1 / pos2
PlotId pos1 = PlotId.fromString(args[1]); try{
PlotId pos2 = PlotId.fromString(args[2]); pos1 = PlotId.fromString(args[2]);
if (pos1 == null || pos2 == null) { pos2 = PlotId.fromString(args[3]);
} catch (IllegalArgumentException ignored) {
MainUtil.sendMessage(player, C.NOT_VALID_PLOT_ID); MainUtil.sendMessage(player, C.NOT_VALID_PLOT_ID);
return false; return false;
} }

View File

@ -33,7 +33,13 @@ public class Comment extends SubCommand {
return false; return false;
} }
Location loc = player.getLocation(); 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); Plot plot = MainUtil.getPlotFromString(player, args[1], false);
int index; int index;
if (plot == null) { if (plot == null) {

View File

@ -56,8 +56,9 @@ import java.util.UUID;
break; break;
case "plotid": case "plotid":
case "id": case "id":
try {
id = PlotId.fromString(split[1]); id = PlotId.fromString(split[1]);
if (id == null) { } catch (IllegalArgumentException ignored) {
C.NOT_VALID_PLOT_ID.send(player, split[1]); C.NOT_VALID_PLOT_ID.send(player, split[1]);
return false; return false;
} }

View File

@ -182,8 +182,9 @@ import java.util.Map.Entry;
MainUtil.sendMessage(player, "&6What should be the minimum Plot Id?"); MainUtil.sendMessage(player, "&6What should be the minimum Plot Id?");
break; break;
case 3: // min case 3: // min
try {
object.min = PlotId.fromString(args[0]); object.min = PlotId.fromString(args[0]);
if (object.min == null) { } catch (IllegalArgumentException ignored) {
MainUtil.sendMessage(player, "&cYou must choose a valid minimum PlotId!"); MainUtil.sendMessage(player, "&cYou must choose a valid minimum PlotId!");
return false; return false;
} }
@ -192,8 +193,10 @@ import java.util.Map.Entry;
break; break;
case 4: case 4:
// max // max
PlotId id = PlotId.fromString(args[0]); PlotId id;
if (id == null) { try {
id = PlotId.fromString(args[0]);
} catch (IllegalArgumentException ignored) {
MainUtil.sendMessage(player, "&cYou must choose a valid maximum PlotId!"); MainUtil.sendMessage(player, "&cYou must choose a valid maximum PlotId!");
return false; return false;
} }

View File

@ -41,14 +41,13 @@ import java.util.concurrent.ConcurrentHashMap;
*/ */
public class Plot { public class Plot {
private static final int MAX_HEIGHT = 256;
/** /**
* @deprecated raw access is deprecated * @deprecated raw access is deprecated
*/ */
@Deprecated private static HashSet<Plot> connected_cache; @Deprecated private static HashSet<Plot> connected_cache;
private static HashSet<RegionWrapper> regions_cache; private static HashSet<RegionWrapper> regions_cache;
/**
* The {@link PlotId}.
*/
private final PlotId id; private final PlotId id;
/** /**
* plot owner * plot owner
@ -91,9 +90,7 @@ public class Plot {
* - The methods are more likely to be left unchanged from version changes<br> * - The methods are more likely to be left unchanged from version changes<br>
*/ */
private PlotSettings settings; private PlotSettings settings;
/**
* The {@link PlotArea}.
*/
private PlotArea area; private PlotArea area;
/** /**
* Session only plot metadata (session is until the server stops)<br> * Session only plot metadata (session is until the server stops)<br>
@ -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 defaultArea If no area is specified
* @param string plot id/area + id * @param string plot id/area + id
@ -199,7 +196,7 @@ public class Plot {
if (split.length == 2) { if (split.length == 2) {
if (defaultArea != null) { if (defaultArea != null) {
PlotId id = PlotId.fromString(split[0] + ';' + split[1]); PlotId id = PlotId.fromString(split[0] + ';' + split[1]);
return id != null ? defaultArea.getPlotAbs(id) : null; return defaultArea.getPlotAbs(id);
} }
} else if (split.length == 3) { } else if (split.length == 3) {
PlotArea pa = PlotSquared.get().getPlotArea(split[0], null); PlotArea pa = PlotSquared.get().getPlotArea(split[0], null);
@ -253,7 +250,7 @@ public class Plot {
} }
/** /**
* Get the metadata for a key<br> * Gets the metadata for a key<br>
* <br> * <br>
* For persistent metadata use the flag system * 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 * @return the PlotCluster object, or null
*/ */
@ -299,9 +296,9 @@ public class Plot {
public List<PlotPlayer> getPlayersInPlot() { public List<PlotPlayer> getPlayersInPlot() {
ArrayList<PlotPlayer> players = new ArrayList<>(); ArrayList<PlotPlayer> players = new ArrayList<>();
for (Entry<String, PlotPlayer> entry : UUIDHandler.getPlayers().entrySet()) { for (Entry<String, PlotPlayer> entry : UUIDHandler.getPlayers().entrySet()) {
PlotPlayer pp = entry.getValue(); PlotPlayer plotPlayer = entry.getValue();
if (this.equals(pp.getCurrentPlot())) { if (this.equals(plotPlayer.getCurrentPlot())) {
players.add(pp); players.add(plotPlayer);
} }
} }
return players; return players;
@ -330,12 +327,7 @@ public class Plot {
return false; return false;
} }
Set<Plot> connected = getConnectedPlots(); Set<Plot> connected = getConnectedPlots();
for (Plot current : connected) { return connected.stream().anyMatch(current -> uuid.equals(current.owner));
if (uuid.equals(current.owner)) {
return true;
}
}
return false;
} }
public boolean isOwnerAbs(UUID uuid) { 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 * @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() { public PlotId getId() {
return this.id; return this.id;
} }
/** /**
* Get the plot world object for this plot<br> * Gets the plot world object for this plot<br>
* - The generic PlotArea object can be casted to its respective class for more control (e.g. HybridPlotWorld) * - The generic PlotArea object can be casted to its respective class for more control (e.g. HybridPlotWorld)
* *
* @return PlotArea * @return PlotArea
@ -441,7 +435,7 @@ public class Plot {
} }
/** /**
* Get the plot manager object for this plot<br> * Gets the plot manager object for this plot<br>
* - The generic PlotManager object can be casted to its respective class for more control (e.g. HybridPlotManager) * - The generic PlotManager object can be casted to its respective class for more control (e.g. HybridPlotManager)
* *
* @return PlotManager * @return PlotManager
@ -451,7 +445,7 @@ public class Plot {
} }
/** /**
* Get or create plot settings. * Gets or create plot settings.
* *
* @return PlotSettings * @return PlotSettings
* @deprecated use equivalent plot method; * @deprecated use equivalent plot method;
@ -518,7 +512,7 @@ public class Plot {
} }
/** /**
* Get the timestamp of when the plot was created (unreliable)<br> * Gets the timestamp of when the plot was created (unreliable)<br>
* - not accurate if the plot was created before this was implemented<br> * - not accurate if the plot was created before this was implemented<br>
* - Milliseconds since the epoch<br> * - Milliseconds since the epoch<br>
* *
@ -532,7 +526,7 @@ public class Plot {
} }
/** /**
* Get if the plot is merged in a direction<br> * Gets if the plot is merged in a direction<br>
* ------- Actual -------<br> * ------- Actual -------<br>
* 0 = north<br> * 0 = north<br>
* 1 = east<br> * 1 = east<br>
@ -586,7 +580,7 @@ public class Plot {
} }
/** /**
* Get the denied users. * Gets the denied users.
* *
* @return a set of 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 * @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 * @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 * @param uuids uuids to trust
*/ */
@ -650,7 +644,7 @@ public class Plot {
} }
/** /**
* Get the members * Gets the members
* *
* @return a set of 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 * @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 * @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 owner uuid to set as owner
* @param initiator player initiating set 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 biome The biome e.g. "forest"
* @param whenDone The task to run when finished, or null * @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 * @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 flag Flag to set
* @param value Flag value * @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 * @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 key the flag
* @param defaultValue if the key is null, the value to return * @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<br> * Gets the number of tracked running tasks for this plot<br>
* - Used to track/limit the number of things a player can do on the plot at once * - Used to track/limit the number of things a player can do on the plot at once
* *
* @return number of tasks (int) * @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 * @param location location to set as home
*/ */
@ -1235,7 +1229,7 @@ public class Plot {
} }
/** /**
* Get the default home location for a plot<br> * Gets the default home location for a plot<br>
* - Ignores any home location set for that specific plot * - Ignores any home location set for that specific plot
* *
* @return Location * @return Location
@ -1276,27 +1270,24 @@ public class Plot {
for (RegionWrapper region : getRegions()) { for (RegionWrapper region : getRegions()) {
count += count +=
(region.maxX - (double) region.minX + 1) * (region.maxZ - (double) region.minZ + 1) (region.maxX - (double) region.minX + 1) * (region.maxZ - (double) region.minZ + 1)
* 256; * MAX_HEIGHT;
} }
return count; 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 * @return average rating as double
*/ */
public double getAverageRating() { public double getAverageRating() {
double sum = 0;
Collection<Rating> ratings = this.getRatings().values(); Collection<Rating> ratings = this.getRatings().values();
for (Rating rating : ratings) { double sum = ratings.stream().mapToDouble(Rating::getAverageRating).sum();
sum += rating.getAverageRating();
}
return sum / ratings.size(); return sum / ratings.size();
} }
/** /**
* Set a rating for a user<br> * Sets a rating for a user<br>
* - If the user has already rated, the following will return false * - If the user has already rated, the following will return false
* *
* @param uuid uuid of rater * @param uuid uuid of rater
@ -1328,7 +1319,7 @@ public class Plot {
} }
/** /**
* Get the ratings associated with a plot<br> * Gets the ratings associated with a plot<br>
* - The rating object may contain multiple categories * - The rating object may contain multiple categories
* *
* @return Map of user who rated to the rating * @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() { public void setSign() {
if (this.owner == null) { 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) * (components are generator specific)
*/ */
public boolean setComponent(String component, String blocks) { public boolean setComponent(String component, String blocks) {
@ -1531,10 +1522,10 @@ public class Plot {
return top; return top;
} }
//TODO Better documentation needed.
/** /**
* Return the bottom location for the plot. * Return the bottom location for the plot.
* *
* @return
*/ */
public Location getBottomAbs() { public Location getBottomAbs() {
Location loc = this.area.getPlotManager().getPlotBottomLocAbs(this.area, this.id); 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 plot the plot to swap data with
* @param whenDone the task to run at the end of this method. * @param whenDone the task to run at the end of this method.
@ -1676,7 +1667,7 @@ public class Plot {
Location bot = other.getBottomAbs(); Location bot = other.getBottomAbs();
Location top = this.getTopAbs(); Location top = this.getTopAbs();
Location pos1 = new Location(this.getWorldName(), top.getX(), 0, bot.getZ()); 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); ChunkManager.manager.regenerateRegion(pos1, pos2, true, null);
} else { } else {
this.area.getPlotManager().removeRoadEast(this.area, this); 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 * @return alias if set, else id
*/ */
@ -1898,7 +1889,7 @@ public class Plot {
} }
/** /**
* Get the plot hashcode<br> * Gets the plot hashcode<br>
* Note: The hashcode is unique if:<br> * Note: The hashcode is unique if:<br>
* - Plots are in the same world<br> * - Plots are in the same world<br>
* - The x,z coordinates are between Short.MIN_VALUE and Short.MAX_VALUE<br> * - The x,z coordinates are between Short.MIN_VALUE and Short.MAX_VALUE<br>
@ -1910,7 +1901,7 @@ public class Plot {
} }
/** /**
* Get the flags specific to this plot<br> * Gets the flags specific to this plot<br>
* - Does not take default flags into account<br> * - Does not take default flags into account<br>
* *
* @return * @return
@ -1920,7 +1911,7 @@ public class Plot {
} }
/** /**
* Set a flag for this plot. * Sets a flag for this plot.
* *
* @param flags * @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 * - Returns an empty string if no alias is set
* *
* @return The plot alias * @return The plot alias
@ -1942,7 +1933,7 @@ public class Plot {
} }
/** /**
* Set the plot alias. * Sets the plot alias.
* *
* @param alias The alias * @param alias The alias
*/ */
@ -1961,7 +1952,7 @@ public class Plot {
} }
/** /**
* Set the raw merge data<br> * Sets the raw merge data<br>
* - Updates DB<br> * - Updates DB<br>
* - Does not modify terrain<br> * - Does not modify terrain<br>
* ----------<br> * ----------<br>
@ -1999,7 +1990,7 @@ public class Plot {
} }
/** /**
* Get the merged array. * Gets the merged array.
* *
* @return boolean [ north, east, south, west ] * @return boolean [ north, east, south, west ]
*/ */
@ -2008,10 +1999,10 @@ public class Plot {
} }
/** /**
* Set the raw merge data<br> * Sets the raw merge data<br>
* - Updates DB<br> * - Updates DB<br>
* - Does not modify terrain<br> * - Does not modify terrain<br>
* Get if the plot is merged in a direction<br> * Gets if the plot is merged in a direction<br>
* ----------<br> * ----------<br>
* 0 = north<br> * 0 = north<br>
* 1 = east<br> * 1 = east<br>
@ -2038,7 +2029,7 @@ public class Plot {
} }
/** /**
* Get the set home location or 0,0,0 if no location is set<br> * Gets the set home location or 0,0,0 if no location is set<br>
* - Does not take the default home location into account * - Does not take the default home location into account
* *
* @return * @return
@ -2145,7 +2136,7 @@ public class Plot {
Location bot = other.getBottomAbs(); Location bot = other.getBottomAbs();
Location top = this.getTopAbs(); Location top = this.getTopAbs();
Location pos1 = new Location(this.getWorldName(), bot.getX(), 0, top.getZ()); 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); ChunkManager.manager.regenerateRegion(pos1, pos2, true, null);
} else { } else {
this.getManager().removeRoadSouth(this.area, this); this.getManager().removeRoadSouth(this.area, this);
@ -2248,11 +2239,11 @@ public class Plot {
* Merge the plot settings<br> * Merge the plot settings<br>
* - Used when a plot is merged<br> * - Used when a plot is merged<br>
* *
* @param b * @param plot
*/ */
public void mergeData(Plot b) { public void mergeData(Plot plot) {
HashMap<Flag<?>, Object> flags1 = this.getFlags(); HashMap<Flag<?>, Object> flags1 = this.getFlags();
HashMap<Flag<?>, Object> flags2 = b.getFlags(); HashMap<Flag<?>, Object> flags2 = plot.getFlags();
if ((!flags1.isEmpty() || !flags2.isEmpty()) && !flags1.equals(flags2)) { if ((!flags1.isEmpty() || !flags2.isEmpty()) && !flags1.equals(flags2)) {
boolean greater = flags1.size() > flags2.size(); boolean greater = flags1.size() > flags2.size();
if (greater) { if (greater) {
@ -2262,30 +2253,30 @@ public class Plot {
} }
HashMap<Flag<?>, Object> net = (greater ? flags1 : flags2); HashMap<Flag<?>, Object> net = (greater ? flags1 : flags2);
this.setFlags(net); this.setFlags(net);
b.setFlags(net); plot.setFlags(net);
} }
if (!this.getAlias().isEmpty()) { if (!this.getAlias().isEmpty()) {
b.setAlias(this.getAlias()); plot.setAlias(this.getAlias());
} else if (!b.getAlias().isEmpty()) { } else if (!plot.getAlias().isEmpty()) {
this.setAlias(b.getAlias()); this.setAlias(plot.getAlias());
} }
for (UUID uuid : this.getTrusted()) { for (UUID uuid : this.getTrusted()) {
b.addTrusted(uuid); plot.addTrusted(uuid);
} }
for (UUID uuid : b.getTrusted()) { for (UUID uuid : plot.getTrusted()) {
this.addTrusted(uuid); this.addTrusted(uuid);
} }
for (UUID uuid : this.getMembers()) { for (UUID uuid : this.getMembers()) {
b.addMember(uuid); plot.addMember(uuid);
} }
for (UUID uuid : b.getMembers()) { for (UUID uuid : plot.getMembers()) {
this.addMember(uuid); this.addMember(uuid);
} }
for (UUID uuid : this.getDenied()) { for (UUID uuid : this.getDenied()) {
b.addDenied(uuid); plot.addDenied(uuid);
} }
for (UUID uuid : b.getDenied()) { for (UUID uuid : plot.getDenied()) {
this.addDenied(uuid); this.addDenied(uuid);
} }
} }
@ -2302,7 +2293,7 @@ public class Plot {
Location pos1 = this.getTopAbs().add(1, 0, 1); Location pos1 = this.getTopAbs().add(1, 0, 1);
Location pos2 = other.getBottomAbs().subtract(1, 0, 1); Location pos2 = other.getBottomAbs().subtract(1, 0, 1);
pos1.setY(0); pos1.setY(0);
pos2.setY(256); pos2.setY(MAX_HEIGHT);
ChunkManager.manager.regenerateRegion(pos1, pos2, true, null); ChunkManager.manager.regenerateRegion(pos1, pos2, true, null);
} else { } else {
this.area.getPlotManager().removeRoadSouthEast(this.area, this); this.area.getPlotManager().removeRoadSouthEast(this.area, this);
@ -2310,7 +2301,7 @@ public class Plot {
} }
/** /**
* Get the plot in a relative location<br> * Gets the plot in a relative location<br>
* Note: May be null if the partial plot area does not include the relative location * Note: May be null if the partial plot area does not include the relative location
* *
* @param x * @param x
@ -2326,7 +2317,7 @@ public class Plot {
} }
/** /**
* Get the plot in a relative direction<br> * Gets the plot in a relative direction<br>
* 0 = north<br> * 0 = north<br>
* 1 = east<br> * 1 = east<br>
* 2 = south<br> * 2 = south<br>
@ -2341,7 +2332,7 @@ public class Plot {
} }
/** /**
* Get a set of plots connected (and including) this plot<br> * Gets a set of plots connected (and including) this plot<br>
* - This result is cached globally * - This result is cached globally
* *
* @return * @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 * @return A list of the plot corners
*/ */
@ -2722,7 +2713,7 @@ public class Plot {
} }
/** /**
* Set a component for a plot to the provided blocks<br> * Sets a component for a plot to the provided blocks<br>
* - E.g. floor, wall, border etc.<br> * - E.g. floor, wall, border etc.<br>
* - The available components depend on the generator being used<br> * - The available components depend on the generator being used<br>
* *

View File

@ -1,5 +1,6 @@
package com.github.intellectualsites.plotsquared.plot.object; package com.github.intellectualsites.plotsquared.plot.object;
import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
public class PlotId { public class PlotId {
@ -30,22 +31,13 @@ public class PlotId {
* @param string to create id from * @param string to create id from
* @return null if the string is invalid * @return null if the string is invalid
*/ */
public static PlotId fromString(String string) { public static PlotId fromString(@Nonnull String string) {
if (string == null) {
return null;
}
String[] parts = string.split("[;|,]"); String[] parts = string.split("[;|,]");
if (parts.length < 2) { if (parts.length < 2) {
return null; throw new IllegalArgumentException("Cannot create PlotID. String invalid.");
}
int x;
int y;
try {
x = Integer.parseInt(parts[0]);
y = Integer.parseInt(parts[1]);
} catch (NumberFormatException ignored) {
return null;
} }
int x = Integer.parseInt(parts[0]);
int y = Integer.parseInt(parts[1]);
return new PlotId(x, y); return new PlotId(x, y);
} }
@ -54,7 +46,7 @@ public class PlotId {
} }
/** /**
* Get the PlotId from the HashCode<br> * Gets the PlotId from the HashCode<br>
* Note: Only accurate for small x,z values (short) * Note: Only accurate for small x,z values (short)
* *
* @param hash * @param hash