Fixes #768 (Plot clearing with given plot id)
This commit is contained in:
Jesse Boyd
2015-12-03 02:42:50 +11:00
parent 82ccca8f63
commit f102b2b448
8 changed files with 221 additions and 127 deletions

View File

@ -49,7 +49,6 @@ import com.intellectualcrafters.plot.util.TaskManager;
/**
* The plot class
*
*/
@SuppressWarnings("javadoc")
public class Plot {
@ -74,8 +73,9 @@ public class Plot {
public UUID owner;
/**
/**
* Plot creation timestamp (not accurate if the plot was created before this was implemented)<br>
* - Milliseconds since the epoch<br>
* Direct access is Deprecated: use {@link #getTimestamp() getTimestamp}
*/
@Deprecated
public long timestamp;
@ -171,6 +171,23 @@ public class Plot {
return MainUtil.getPlot(world, id);
}
public static Plot fromString(String defaultWorld, String string) {
final String[] split = string.split(";|,");
if (split.length == 2) {
if (PS.get().isPlotWorld(defaultWorld)) {
PlotId id = PlotId.fromString(split[0] + ";" + split[1]);
return Plot.getPlot(defaultWorld, id);
}
} else if (split.length == 3) {
defaultWorld = split[0];
if (PS.get().isPlotWorld(defaultWorld)) {
PlotId id = PlotId.fromString(split[1] + ";" + split[2]);
return Plot.getPlot(defaultWorld, id);
}
}
return null;
}
/**
* Return a new/cached plot object at a given location
*
@ -250,7 +267,9 @@ public class Plot {
}
/**
* Get the metadata for a key<br>
* <br>
* For persistent metadata use the flag system
* @param key
* @return
*/
@ -275,7 +294,7 @@ public class Plot {
/**
* Get the cluster this plot is associated with
/**
* @return the PlotCluster object, or null
*/
public PlotCluster getCluster() {
if (!Settings.ENABLE_CLUSTERS) {
@ -311,8 +330,10 @@ public class Plot {
}
/**
/**
* Efficiently get the players currently inside this plot<br>
* - Will return an empty list if no players are in the plot<br>
* - Remember, you can cast a PlotPlayer to it's respective implementation (BukkitPlayer, SpongePlayer) to obtain the player object
* @return list of PlotPlayer(s) or an empty list
*/
public List<PlotPlayer> getPlayersInPlot() {
return MainUtil.getPlayersInPlot(this);
@ -327,6 +348,11 @@ public class Plot {
return owner != null;
}
/**
* Check if a UUID is a plot owner (merged plots may have multiple owners)
* @param uuid
* @return
*/
public boolean isOwner(final UUID uuid) {
return PlotHandler.isOwner(this, uuid);
}
@ -370,7 +396,7 @@ public class Plot {
/**
* Get the plot world object for this plot<br>
/**
* - The generic PlotWorld object can be casted to its respective class for more control (e.g. HybridPlotWorld)
* @return PlotWorld
*/
public PlotWorld getWorld() {
@ -379,7 +405,7 @@ public class Plot {
/**
* Get 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)
* @return PlotManager
*/
public PlotManager getManager() {
@ -450,7 +476,7 @@ public class Plot {
}
/**
* Check if the plot is merged in any direction
* @return
*/
public boolean isMerged() {
@ -461,7 +487,9 @@ public class Plot {
}
/**
* Get the timestamp of when the plot was created (unreliable)<br>
* - not accurate if the plot was created before this was implemented<br>
* - Milliseconds since the epoch<br>
* @return
*/
public long getTimestamp() {
@ -472,9 +500,21 @@ public class Plot {
}
/**
* Get if the plot is merged in a direction<br>
* ------- Actual -------<br>
* 0 = north<br>
* 1 = east<br>
* 2 = south<br>
* 3 = west<br>
* ----- Artificial -----<br>
* 4 = north-east<br>
* 5 = south-east<br>
* 6 = south-west<br>
* 7 = north-west<br>
* ----------<br>
* Note: A plot that is merged north and east will not be merged northeast if the northeast plot is not part of the same group<br>
* @param direction
* Get if the plot is merged in a direction
* @return true if merged in that direction
*/
public boolean getMerged(final int direction) {
if (settings == null) {
@ -536,7 +576,6 @@ public class Plot {
/**
* Deny someone (updates database as well)
/**
* @param uuid
*/
public void addDenied(final UUID uuid) {
@ -903,13 +942,13 @@ public class Plot {
}
/**
/**
* Returns the top and bottom connected plot.<br>
* Returns the top and bottom location.<br>
* - If the plot is not connected, it will return its own corners<br>
* - the returned locations will not necessarily correspond to claimed plots if the connected plots do not form a rectangular shape
* @deprecated as merged plots no longer need to be rectangular
* @param plot
* @deprecated as merged plots no longer need to be rectangular
* @param plot
* @return new Location[] { bottom, top }
* @see MainUtil#getCorners(Plot)
*/
@Deprecated
public Location[] getCorners() {
@ -917,7 +956,21 @@ public class Plot {
}
/**
* Returns the top and bottom plot id.<br>
* - If the plot is not connected, it will return itself for the top/bottom<br>
* - the returned ids will not necessarily correspond to claimed plots if the connected plots do not form a rectangular shape
* @deprecated as merged plots no longer need to be rectangular
* @param plot
* @return new Plot[] { bottom, top }
* @see MainUtil#getCornerIds(Plot)
*/
@Deprecated
public PlotId[] getCornerIds() {
return MainUtil.getCornerIds(this);
}
/**
* @deprecated in favor of getCorners()[0];<br>
* @return
*/
@Deprecated
@ -945,8 +998,9 @@ public class Plot {
}
/**
/**
* This will combine each plot into effective rectangular regions<br>
* - This result is cached globally<br>
* - Useful for handling non rectangular shapes
* @see MainUtil#getRegions(Plot)
* @return
*/
@ -1005,8 +1059,8 @@ public class Plot {
}
/**
/**
* Remove a denied player (use DBFunc as well)<br>
* Using the * uuid will remove all users
* @param uuid
*/
public boolean removeDenied(final UUID uuid) {
@ -1021,8 +1075,8 @@ public class Plot {
}
/**
/**
* Remove a helper (use DBFunc as well)<br>
* Using the * uuid will remove all users
* @param uuid
*/
public boolean removeTrusted(final UUID uuid) {
@ -1037,8 +1091,8 @@ public class Plot {
}
/**
/**
* Remove a trusted user (use DBFunc as well)<br>
* Using the * uuid will remove all users
* @param uuid
*/
public boolean removeMember(final UUID uuid) {
@ -1098,7 +1152,7 @@ public class Plot {
}
/**
* Upload the plot as a schematic to the configured web interface
* @param whenDone value will be null if uploading fails
*/
public void upload(final RunnableVal<URL> whenDone) {
@ -1147,6 +1201,11 @@ public class Plot {
return id.hashCode();
}
/**
* Get the flags specific to this plot<br>
* - Does not take default flags into account<br>
* @return
*/
public HashMap<String, Flag> getFlags() {
if (settings == null) {
return new HashMap<>(0);
@ -1154,6 +1213,11 @@ public class Plot {
return settings.flags;
}
/**
* Get the plot Alias<br>
* - Returns an empty string if no alias is set
* @return
*/
public String getAlias() {
if (settings == null) {
return "";
@ -1163,8 +1227,16 @@ public class Plot {
/**
* Set the raw merge data<br>
/**
* Set the raw merge data<br>
* - Updates DB<br>
* - Does not modify terrain<br>
* Get if the plot is merged in a direction<br>
* ----------<br>
* 0 = north<br>
* 1 = east<br>
* 2 = south<br>
* 3 = west<br>
* ----------<br>
* Note: Diagonal merging (4-7) must be done by merging the corresponding plots.
* @param merged
*/
public void setMerged(boolean[] merged) {
@ -1180,8 +1252,14 @@ public class Plot {
/**
* Set the raw merge data<br>
/**
* Set the raw merge data<br>
* - Updates DB<br>
* - Does not modify terrain<br>
* ----------<br>
* 0 = north<br>
* 1 = east<br>
* 2 = south<br>
* 3 = west<br>
* ----------<br>
* @param merged
*/
public void setMerged(int direction, boolean value) {
@ -1208,6 +1286,10 @@ public class Plot {
}
}
/**
* Get the merged array
* @return boolean [ north, east, south, west ]
*/
public boolean[] getMerged() {
if (settings == null) {
return new boolean[] {false, false, false, false };
@ -1215,6 +1297,13 @@ public class Plot {
return settings.getMerged();
}
/**
* Get the set home location or 0,0,0 if no location is set<br>
* - Does not take the default home location into account
* @see MainUtil#getPlotHome(Plot)
* @see #getHome()
* @return
*/
public BlockLoc getPosition() {
if (settings == null) {
return new BlockLoc(0, 0, 0);

View File

@ -17,8 +17,8 @@ import com.plotsquared.general.commands.CommandCaller;
import com.plotsquared.listener.PlotListener;
/**
* Created 2015-02-20 for PlotSquared
*
* The PlotPlayer class<br>
* - Can cast to: BukkitPlayer / SpongePlayer, which are the current implementations<br>
*/
public abstract class PlotPlayer implements CommandCaller {
@ -28,7 +28,7 @@ public abstract class PlotPlayer implements CommandCaller {
private ConcurrentHashMap<String, Object> meta;
/**
/**
* Efficiently wrap a Player, or OfflinePlayer object to get a PlotPlayer (or fetch if it's already cached)<br>
* - Accepts sponge/bukkit Player (online)
* - Accepts player name (online)
* - Accepts UUID
@ -42,7 +42,7 @@ public abstract class PlotPlayer implements CommandCaller {
/**
* Get the cached PlotPlayer from a username<br>
* Get the cached PlotPlayer from a username<br>
* - This will return null if the player has not finished logging in or is not online
* @param name
* @return
*/