2015-09-11 20:09:22 +10:00
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// PlotSquared - A plot manager and world generator for the Bukkit API /
|
|
|
|
// Copyright (c) 2014 IntellectualSites/IntellectualCrafters /
|
|
|
|
// /
|
|
|
|
// 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, write to the Free Software Foundation, /
|
|
|
|
// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA /
|
|
|
|
// /
|
|
|
|
// You can contact us via: support@intellectualsites.com /
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
package com.intellectualcrafters.plot.object;
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.net.URL;
|
|
|
|
import java.util.Collection;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map.Entry;
|
|
|
|
import java.util.Set;
|
|
|
|
import java.util.UUID;
|
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
|
|
|
|
import com.intellectualcrafters.jnbt.CompoundTag;
|
|
|
|
import com.intellectualcrafters.plot.PS;
|
|
|
|
import com.intellectualcrafters.plot.config.Configuration;
|
|
|
|
import com.intellectualcrafters.plot.config.Settings;
|
|
|
|
import com.intellectualcrafters.plot.database.DBFunc;
|
|
|
|
import com.intellectualcrafters.plot.flag.Flag;
|
|
|
|
import com.intellectualcrafters.plot.flag.FlagManager;
|
|
|
|
import com.intellectualcrafters.plot.util.BO3Handler;
|
|
|
|
import com.intellectualcrafters.plot.util.BlockManager;
|
|
|
|
import com.intellectualcrafters.plot.util.ChunkManager;
|
|
|
|
import com.intellectualcrafters.plot.util.ClusterManager;
|
|
|
|
import com.intellectualcrafters.plot.util.MainUtil;
|
|
|
|
import com.intellectualcrafters.plot.util.SchematicHandler;
|
|
|
|
import com.intellectualcrafters.plot.util.StringMan;
|
|
|
|
import com.intellectualcrafters.plot.util.TaskManager;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The plot class
|
|
|
|
*/
|
|
|
|
@SuppressWarnings("javadoc")
|
2015-09-13 14:04:31 +10:00
|
|
|
public class Plot {
|
2015-09-11 20:09:22 +10:00
|
|
|
/**
|
|
|
|
* plot ID
|
|
|
|
* Direct access is Deprecated: use getId()
|
|
|
|
*/
|
|
|
|
@Deprecated
|
|
|
|
public final PlotId id;
|
|
|
|
/**
|
|
|
|
* plot world
|
|
|
|
* Direct access is Deprecated: use getWorld()
|
|
|
|
*/
|
|
|
|
@Deprecated
|
|
|
|
public final String world;
|
|
|
|
/**
|
|
|
|
* plot owner
|
|
|
|
* (Merged plots can have multiple owners)
|
|
|
|
* Direct access is Deprecated: use getOwners()
|
|
|
|
*/
|
|
|
|
@Deprecated
|
|
|
|
public UUID owner;
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-09-11 20:09:22 +10:00
|
|
|
/**
|
2015-12-03 02:42:50 +11:00
|
|
|
* 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}
|
2015-09-11 20:09:22 +10:00
|
|
|
*/
|
|
|
|
@Deprecated
|
|
|
|
public long timestamp;
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-09-11 20:09:22 +10:00
|
|
|
/**
|
|
|
|
* List of trusted (with plot permissions)
|
|
|
|
* Direct access is Deprecated: use getTrusted()
|
|
|
|
*/
|
|
|
|
@Deprecated
|
|
|
|
public HashSet<UUID> trusted;
|
|
|
|
/**
|
|
|
|
* List of members users (with plot permissions)
|
|
|
|
* Direct access is Deprecated: use getMembers()
|
|
|
|
*/
|
|
|
|
@Deprecated
|
|
|
|
public HashSet<UUID> members;
|
|
|
|
/**
|
|
|
|
* List of denied players
|
|
|
|
* Direct access is Deprecated: use getDenied()
|
|
|
|
*/
|
|
|
|
@Deprecated
|
|
|
|
public HashSet<UUID> denied;
|
|
|
|
/**
|
|
|
|
* External settings class<br>
|
|
|
|
* - Please favor the methods over direct access to this class<br>
|
|
|
|
* - The methods are more likely to be left unchanged from version changes<br>
|
|
|
|
* Direct access is Deprecated: use getSettings()
|
|
|
|
*/
|
|
|
|
@Deprecated
|
|
|
|
public PlotSettings settings;
|
|
|
|
/**
|
|
|
|
* Has the plot changed since the last save cycle?
|
|
|
|
*/
|
|
|
|
public boolean countsTowardsMax = true;
|
|
|
|
/**
|
|
|
|
* Represents whatever the database manager needs it to: <br>
|
|
|
|
* - A value of -1 usually indicates the plot will not be stored in the DB<br>
|
|
|
|
* - A value of 0 usually indicates that the DB manager hasn't set a value<br>
|
|
|
|
* @deprecated magical
|
|
|
|
*/
|
|
|
|
@Deprecated
|
|
|
|
public int temp;
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-09-11 20:09:22 +10:00
|
|
|
/**
|
|
|
|
* Session only plot metadata (session is until the server stops)<br>
|
|
|
|
* <br>
|
|
|
|
* For persistent metadata use the flag system
|
|
|
|
* @see FlagManager
|
|
|
|
*/
|
|
|
|
private ConcurrentHashMap<String, Object> meta;
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-09-11 20:09:22 +10:00
|
|
|
/**
|
|
|
|
* Constructor for a new plot<br>
|
|
|
|
* (Only changes after plot.create() will be properly set in the database)
|
|
|
|
*
|
2015-09-22 23:23:28 +10:00
|
|
|
* @see Plot#getPlot(String, PlotId) for existing plots
|
|
|
|
* @see Plot#getPlot(Location) for existing plots
|
2015-09-11 20:09:22 +10:00
|
|
|
*
|
|
|
|
* @param world
|
|
|
|
* @param id
|
|
|
|
* @param owner
|
|
|
|
*/
|
2015-09-13 14:04:31 +10:00
|
|
|
public Plot(final String world, final PlotId id, final UUID owner) {
|
2015-09-11 20:09:22 +10:00
|
|
|
this.world = world;
|
|
|
|
this.id = id;
|
|
|
|
this.owner = owner;
|
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-09-22 23:23:28 +10:00
|
|
|
/**
|
|
|
|
* Constructor for an unowned plot<br>
|
|
|
|
* (Only changes after plot.create() will be properly set in the database)
|
|
|
|
*
|
|
|
|
* @see Plot#getPlot(String, PlotId) for existing plots
|
|
|
|
*
|
|
|
|
* @param world
|
|
|
|
* @param id
|
|
|
|
*/
|
|
|
|
public Plot(final String world, final PlotId id) {
|
|
|
|
this.world = world;
|
|
|
|
this.id = id;
|
|
|
|
}
|
|
|
|
|
2015-09-11 20:09:22 +10:00
|
|
|
/**
|
|
|
|
* Return a new/cached plot object at a given world/plot id
|
2015-09-13 01:19:39 +10:00
|
|
|
*
|
2015-09-11 20:09:22 +10:00
|
|
|
* @see MainUtil#getPlotSelectionOwned(String world, PlotId bottom, PlotId top) return a list of owned plots between (inclusive) two plot ids.
|
2015-09-13 01:19:39 +10:00
|
|
|
*
|
2015-09-11 20:09:22 +10:00
|
|
|
* @param world
|
|
|
|
* @param id
|
|
|
|
* @return
|
|
|
|
*/
|
2015-09-13 14:04:31 +10:00
|
|
|
public static Plot getPlot(final String world, final PlotId id) {
|
2015-09-11 20:09:22 +10:00
|
|
|
return MainUtil.getPlot(world, id);
|
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-12-03 02:42:50 +11:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2015-09-11 20:09:22 +10:00
|
|
|
/**
|
|
|
|
* Return a new/cached plot object at a given location
|
2015-09-13 01:19:39 +10:00
|
|
|
*
|
2015-09-11 20:09:22 +10:00
|
|
|
* @see PlotPlayer#getCurrentPlot() if a player is expected here.
|
2015-09-13 01:19:39 +10:00
|
|
|
*
|
2015-09-11 20:09:22 +10:00
|
|
|
* @param loc
|
|
|
|
* @return
|
|
|
|
*/
|
2015-09-13 14:04:31 +10:00
|
|
|
public static Plot getPlot(final Location loc) {
|
2015-09-11 20:09:22 +10:00
|
|
|
return MainUtil.getPlot(loc);
|
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-09-11 20:09:22 +10:00
|
|
|
/**
|
|
|
|
* Constructor for a temporary plot (use -1 for temp)<br>
|
|
|
|
* The database will ignore any queries regarding temporary plots.
|
|
|
|
* Please note that some bulk plot management functions may still affect temporary plots (TODO: fix this)
|
|
|
|
*
|
2015-09-22 23:23:28 +10:00
|
|
|
* @see Plot#getPlot(String, PlotId) for existing plots
|
2015-09-11 20:09:22 +10:00
|
|
|
*
|
|
|
|
* @param world
|
|
|
|
* @param id
|
|
|
|
* @param owner
|
|
|
|
* @param temp
|
|
|
|
*/
|
2015-09-13 14:04:31 +10:00
|
|
|
public Plot(final String world, final PlotId id, final UUID owner, final int temp) {
|
2015-09-11 20:09:22 +10:00
|
|
|
this.world = world;
|
|
|
|
this.id = id;
|
|
|
|
this.owner = owner;
|
|
|
|
this.temp = temp;
|
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-09-11 20:09:22 +10:00
|
|
|
/**
|
|
|
|
* Constructor for a saved plots (Used by the database manager when plots are fetched)
|
2015-09-13 01:19:39 +10:00
|
|
|
*
|
2015-09-22 23:23:28 +10:00
|
|
|
* @see Plot#getPlot(String, PlotId) for existing plots
|
2015-09-11 20:09:22 +10:00
|
|
|
*
|
|
|
|
* @param id
|
|
|
|
* @param owner
|
|
|
|
* @param trusted
|
|
|
|
* @param denied
|
|
|
|
* @param merged
|
|
|
|
*/
|
|
|
|
public Plot(final PlotId id, final UUID owner, final HashSet<UUID> trusted, final HashSet<UUID> members, final HashSet<UUID> denied, final String alias, final BlockLoc position,
|
2015-09-13 14:04:31 +10:00
|
|
|
final Collection<Flag> flags, final String world, final boolean[] merged, final long timestamp, final int temp) {
|
2015-09-11 20:09:22 +10:00
|
|
|
this.id = id;
|
|
|
|
this.world = world;
|
|
|
|
this.owner = owner;
|
2015-09-22 23:23:28 +10:00
|
|
|
settings = new PlotSettings();
|
2015-09-11 20:09:22 +10:00
|
|
|
this.members = members;
|
|
|
|
this.trusted = trusted;
|
|
|
|
this.denied = denied;
|
|
|
|
settings.setAlias(alias);
|
|
|
|
settings.setPosition(position);
|
|
|
|
settings.setMerged(merged);
|
2015-09-13 14:04:31 +10:00
|
|
|
if (flags != null) {
|
|
|
|
for (final Flag flag : flags) {
|
2015-09-11 20:09:22 +10:00
|
|
|
settings.flags.put(flag.getKey(), flag);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.timestamp = timestamp;
|
|
|
|
this.temp = temp;
|
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-09-11 20:09:22 +10:00
|
|
|
/**
|
|
|
|
* Session only plot metadata (session is until the server stops)<br>
|
|
|
|
* <br>
|
|
|
|
* For persistent metadata use the flag system
|
|
|
|
* @see FlagManager
|
|
|
|
* @param key
|
|
|
|
* @param value
|
|
|
|
*/
|
2015-09-13 14:04:31 +10:00
|
|
|
public void setMeta(final String key, final Object value) {
|
|
|
|
if (meta == null) {
|
2015-09-11 20:09:22 +10:00
|
|
|
meta = new ConcurrentHashMap<String, Object>();
|
|
|
|
}
|
|
|
|
meta.put(key, value);
|
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-09-11 20:09:22 +10:00
|
|
|
/**
|
2015-12-03 02:42:50 +11:00
|
|
|
* Get the metadata for a key<br>
|
|
|
|
* <br>
|
|
|
|
* For persistent metadata use the flag system
|
2015-09-11 20:09:22 +10:00
|
|
|
* @param key
|
|
|
|
* @return
|
|
|
|
*/
|
2015-09-13 14:04:31 +10:00
|
|
|
public Object getMeta(final String key) {
|
|
|
|
if (meta != null) {
|
|
|
|
return meta.get(key);
|
|
|
|
}
|
2015-09-11 20:09:22 +10:00
|
|
|
return null;
|
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-09-11 20:09:22 +10:00
|
|
|
/**
|
|
|
|
* Delete the metadata for a key<br>
|
|
|
|
* - metadata is session only
|
|
|
|
* - deleting other plugin's metadata may cause issues
|
|
|
|
* @param key
|
|
|
|
*/
|
2015-09-13 14:04:31 +10:00
|
|
|
public void deleteMeta(final String key) {
|
|
|
|
if (meta != null) {
|
2015-09-11 20:09:22 +10:00
|
|
|
meta.remove(key);
|
|
|
|
}
|
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-09-11 20:09:22 +10:00
|
|
|
/**
|
|
|
|
* Get the cluster this plot is associated with
|
2015-12-03 02:42:50 +11:00
|
|
|
* @return the PlotCluster object, or null
|
2015-09-11 20:09:22 +10:00
|
|
|
*/
|
2015-09-13 14:04:31 +10:00
|
|
|
public PlotCluster getCluster() {
|
|
|
|
if (!Settings.ENABLE_CLUSTERS) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
if (owner == null) {
|
|
|
|
return ClusterManager.getCluster(this);
|
|
|
|
}
|
2015-10-07 17:33:33 +11:00
|
|
|
Flag flag = FlagManager.getPlotFlagRaw(this, "cluster");
|
2015-09-13 14:04:31 +10:00
|
|
|
if (flag != null) {
|
2015-09-11 20:09:22 +10:00
|
|
|
PlotCluster cluster = (PlotCluster) flag.getValue();
|
|
|
|
cluster = ClusterManager.getCluster(cluster.world, cluster.getName());
|
2015-09-13 14:04:31 +10:00
|
|
|
if (cluster != null) {
|
|
|
|
return cluster;
|
|
|
|
}
|
2015-09-11 20:09:22 +10:00
|
|
|
cluster = ClusterManager.getCluster(this);
|
2015-09-13 14:04:31 +10:00
|
|
|
if (cluster == null) {
|
2015-09-11 20:09:22 +10:00
|
|
|
FlagManager.removePlotFlag(this, "cluster");
|
|
|
|
return null;
|
2015-09-13 14:04:31 +10:00
|
|
|
} else {
|
2015-09-11 20:09:22 +10:00
|
|
|
flag = new Flag(flag.getAbstractFlag(), cluster);
|
|
|
|
FlagManager.addPlotFlag(this, flag);
|
|
|
|
return cluster;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
final PlotCluster cluster = ClusterManager.getCluster(this);
|
2015-09-13 14:04:31 +10:00
|
|
|
if (cluster != null) {
|
2015-09-11 20:09:22 +10:00
|
|
|
flag = new Flag(FlagManager.getFlag("cluster"), cluster);
|
|
|
|
FlagManager.addPlotFlag(this, flag);
|
|
|
|
return cluster;
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-09-11 20:09:22 +10:00
|
|
|
/**
|
2015-12-03 02:42:50 +11:00
|
|
|
* 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
|
2015-09-11 20:09:22 +10:00
|
|
|
*/
|
2015-09-13 14:04:31 +10:00
|
|
|
public List<PlotPlayer> getPlayersInPlot() {
|
2015-09-11 20:09:22 +10:00
|
|
|
return MainUtil.getPlayersInPlot(this);
|
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-09-11 20:09:22 +10:00
|
|
|
/**
|
|
|
|
* Check if the plot has a set owner
|
|
|
|
*
|
|
|
|
* @return false if there is no owner
|
|
|
|
*/
|
2015-09-13 14:04:31 +10:00
|
|
|
public boolean hasOwner() {
|
2015-09-11 20:09:22 +10:00
|
|
|
return owner != null;
|
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-12-03 02:42:50 +11:00
|
|
|
/**
|
|
|
|
* Check if a UUID is a plot owner (merged plots may have multiple owners)
|
|
|
|
* @param uuid
|
|
|
|
* @return
|
|
|
|
*/
|
2015-09-13 14:04:31 +10:00
|
|
|
public boolean isOwner(final UUID uuid) {
|
2015-09-11 20:09:22 +10:00
|
|
|
return PlotHandler.isOwner(this, uuid);
|
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-09-11 20:09:22 +10:00
|
|
|
/**
|
|
|
|
* Get a list of owner UUIDs for a plot (supports multi-owner mega-plots)
|
|
|
|
* @return
|
|
|
|
*/
|
2015-09-13 14:04:31 +10:00
|
|
|
public HashSet<UUID> getOwners() {
|
2015-09-11 20:09:22 +10:00
|
|
|
return PlotHandler.getOwners(this);
|
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-09-11 20:09:22 +10:00
|
|
|
/**
|
|
|
|
* Check if the player is either the owner or on the trusted/added list
|
|
|
|
*
|
|
|
|
* @param uuid
|
|
|
|
*
|
|
|
|
* @return true if the player is added/trusted or is the owner
|
|
|
|
*/
|
2015-09-13 14:04:31 +10:00
|
|
|
public boolean isAdded(final UUID uuid) {
|
2015-09-11 20:09:22 +10:00
|
|
|
return PlotHandler.isAdded(this, uuid);
|
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-09-11 20:09:22 +10:00
|
|
|
/**
|
|
|
|
* Should the player be denied from entering?
|
|
|
|
*
|
|
|
|
* @param uuid
|
|
|
|
*
|
|
|
|
* @return boolean false if the player is allowed to enter
|
|
|
|
*/
|
2015-09-13 14:04:31 +10:00
|
|
|
public boolean isDenied(final UUID uuid) {
|
2015-09-11 20:09:22 +10:00
|
|
|
return (getDenied() != null) && ((denied.contains(DBFunc.everyone) && !isAdded(uuid)) || (!isAdded(uuid) && denied.contains(uuid)));
|
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-09-11 20:09:22 +10:00
|
|
|
/**
|
|
|
|
* Get the plot ID
|
|
|
|
*/
|
2015-09-13 14:04:31 +10:00
|
|
|
public PlotId getId() {
|
2015-09-11 20:09:22 +10:00
|
|
|
return id;
|
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-09-11 20:09:22 +10:00
|
|
|
/**
|
2015-09-22 23:23:28 +10:00
|
|
|
* Get the plot world object for this plot<br>
|
2015-12-03 02:42:50 +11:00
|
|
|
* - The generic PlotWorld object can be casted to its respective class for more control (e.g. HybridPlotWorld)
|
2015-09-22 23:23:28 +10:00
|
|
|
* @return PlotWorld
|
|
|
|
*/
|
|
|
|
public PlotWorld getWorld() {
|
|
|
|
return PS.get().getPlotWorld(world);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the plot manager object for this plot<br>
|
2015-12-03 02:42:50 +11:00
|
|
|
* - The generic PlotManager object can be casted to its respective class for more control (e.g. HybridPlotManager)
|
2015-09-22 23:23:28 +10:00
|
|
|
* @return PlotManager
|
2015-09-11 20:09:22 +10:00
|
|
|
*/
|
2015-09-22 23:23:28 +10:00
|
|
|
public PlotManager getManager() {
|
|
|
|
return PS.get().getPlotManager(world);
|
2015-09-11 20:09:22 +10:00
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-09-11 20:09:22 +10:00
|
|
|
/**
|
|
|
|
* Get or create plot settings
|
|
|
|
* @return PlotSettings
|
2015-09-22 23:23:28 +10:00
|
|
|
* @deprecated use equivalent plot method;
|
2015-09-11 20:09:22 +10:00
|
|
|
*/
|
2015-09-22 23:23:28 +10:00
|
|
|
@Deprecated
|
2015-09-13 14:04:31 +10:00
|
|
|
public PlotSettings getSettings() {
|
|
|
|
if (settings == null) {
|
2015-09-22 23:23:28 +10:00
|
|
|
settings = new PlotSettings();
|
2015-09-11 20:09:22 +10:00
|
|
|
}
|
|
|
|
return settings;
|
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-09-11 20:09:22 +10:00
|
|
|
/**
|
|
|
|
* Returns true if the plot is not merged, or it is the base plot of multiple merged plots
|
|
|
|
* @return
|
|
|
|
*/
|
2015-09-13 14:04:31 +10:00
|
|
|
public boolean isBasePlot() {
|
2015-09-22 23:23:28 +10:00
|
|
|
if (settings == null || !isMerged()) {
|
2015-09-13 14:04:31 +10:00
|
|
|
return true;
|
|
|
|
}
|
2015-09-22 23:23:28 +10:00
|
|
|
return equals(getBasePlot(false));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The cached origin plot<br>
|
|
|
|
* - The origin plot is used for plot grouping and relational data
|
|
|
|
*/
|
|
|
|
private Plot origin;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The base plot is an arbitrary but specific connected plot. It is useful for the following:<br>
|
|
|
|
* - Merged plots need to be treated as a single plot for most purposes<br>
|
|
|
|
* - Some data such as home location needs to be associated with the group rather than each plot<br>
|
|
|
|
* - If the plot is not merged it will return itself.<br>
|
|
|
|
* - The result is cached locally
|
|
|
|
* @return base Plot
|
|
|
|
*/
|
|
|
|
public Plot getBasePlot(boolean recalculate) {
|
|
|
|
if ((origin != null && !recalculate)) {
|
2015-09-29 16:29:28 +10:00
|
|
|
if (this.equals(origin)) {
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
return origin.getBasePlot(false);
|
2015-09-22 23:23:28 +10:00
|
|
|
}
|
|
|
|
if (!isMerged()) {
|
|
|
|
origin = this;
|
|
|
|
return origin;
|
|
|
|
}
|
2015-09-29 16:29:28 +10:00
|
|
|
origin = this;
|
|
|
|
PlotId min = id;
|
2015-09-22 23:23:28 +10:00
|
|
|
for (Plot plot : MainUtil.getConnectedPlots(this)) {
|
2015-09-29 16:29:28 +10:00
|
|
|
if (plot.id.y < min.y || (plot.id.y == min.y && plot.id.x < min.x)) {
|
|
|
|
origin = plot;
|
|
|
|
min = plot.id;
|
2015-09-22 23:23:28 +10:00
|
|
|
}
|
|
|
|
}
|
|
|
|
for (Plot plot : MainUtil.getConnectedPlots(this)) {
|
|
|
|
plot.origin = origin;
|
|
|
|
}
|
|
|
|
return origin;
|
2015-09-11 20:09:22 +10:00
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-09-11 20:09:22 +10:00
|
|
|
/**
|
2015-12-03 02:42:50 +11:00
|
|
|
* Check if the plot is merged in any direction
|
2015-09-11 20:09:22 +10:00
|
|
|
* @return
|
|
|
|
*/
|
2015-09-13 14:04:31 +10:00
|
|
|
public boolean isMerged() {
|
|
|
|
if (settings == null) {
|
|
|
|
return false;
|
|
|
|
}
|
2015-09-11 20:09:22 +10:00
|
|
|
return settings.getMerged(0) || settings.getMerged(2) || settings.getMerged(1) || settings.getMerged(3);
|
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-09-11 20:09:22 +10:00
|
|
|
/**
|
2015-12-03 02:42:50 +11:00
|
|
|
* 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>
|
2015-09-11 20:09:22 +10:00
|
|
|
* @return
|
|
|
|
*/
|
2015-09-13 14:04:31 +10:00
|
|
|
public long getTimestamp() {
|
|
|
|
if (timestamp == 0) {
|
2015-09-11 20:09:22 +10:00
|
|
|
timestamp = System.currentTimeMillis();
|
|
|
|
}
|
|
|
|
return timestamp;
|
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-09-11 20:09:22 +10:00
|
|
|
/**
|
2015-12-03 02:42:50 +11:00
|
|
|
* 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>
|
2015-09-11 20:09:22 +10:00
|
|
|
* @param direction
|
2015-12-03 02:42:50 +11:00
|
|
|
* @return true if merged in that direction
|
2015-09-11 20:09:22 +10:00
|
|
|
*/
|
2015-09-13 14:04:31 +10:00
|
|
|
public boolean getMerged(final int direction) {
|
|
|
|
if (settings == null) {
|
|
|
|
return false;
|
|
|
|
}
|
2015-09-22 23:23:28 +10:00
|
|
|
switch (direction) {
|
|
|
|
case 0:
|
|
|
|
case 1:
|
|
|
|
case 2:
|
|
|
|
case 3:
|
|
|
|
return settings.getMerged(direction);
|
|
|
|
case 7:
|
|
|
|
int i = direction - 4;
|
|
|
|
int i2 = 0;
|
|
|
|
return settings.getMerged(i2) && settings.getMerged(i) && MainUtil.getPlotAbs(world, MainUtil.getPlotIdRelative(id, i)).getMerged(i2) && settings.getMerged(i) && settings.getMerged(i2) && MainUtil.getPlotAbs(world, MainUtil.getPlotIdRelative(id, i2)).getMerged(i);
|
|
|
|
case 4:
|
|
|
|
case 5:
|
|
|
|
case 6:
|
|
|
|
i = direction - 4;
|
|
|
|
i2 = direction - 3;
|
|
|
|
return settings.getMerged(i2) && settings.getMerged(i) && MainUtil.getPlotAbs(world, MainUtil.getPlotIdRelative(id, i)).getMerged(i2) && settings.getMerged(i) && settings.getMerged(i2) && MainUtil.getPlotAbs(world, MainUtil.getPlotIdRelative(id, i2)).getMerged(i);
|
|
|
|
|
|
|
|
}
|
|
|
|
return false;
|
2015-09-11 20:09:22 +10:00
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-09-11 20:09:22 +10:00
|
|
|
/**
|
|
|
|
* Get the denied users
|
|
|
|
* @return
|
|
|
|
*/
|
2015-09-13 14:04:31 +10:00
|
|
|
public HashSet<UUID> getDenied() {
|
|
|
|
if (denied == null) {
|
2015-09-11 20:09:22 +10:00
|
|
|
denied = new HashSet<>();
|
|
|
|
}
|
|
|
|
return denied;
|
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-09-11 20:09:22 +10:00
|
|
|
/**
|
|
|
|
* Get the trusted users
|
|
|
|
* @return
|
|
|
|
*/
|
2015-09-13 14:04:31 +10:00
|
|
|
public HashSet<UUID> getTrusted() {
|
|
|
|
if (trusted == null) {
|
2015-09-11 20:09:22 +10:00
|
|
|
trusted = new HashSet<>();
|
|
|
|
}
|
|
|
|
return trusted;
|
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-09-11 20:09:22 +10:00
|
|
|
/**
|
|
|
|
* Get the members
|
|
|
|
* @return
|
|
|
|
*/
|
2015-09-13 14:04:31 +10:00
|
|
|
public HashSet<UUID> getMembers() {
|
|
|
|
if (members == null) {
|
2015-09-11 20:09:22 +10:00
|
|
|
members = new HashSet<>();
|
|
|
|
}
|
|
|
|
return members;
|
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-09-11 20:09:22 +10:00
|
|
|
/**
|
|
|
|
* Deny someone (updates database as well)
|
|
|
|
* @param uuid
|
|
|
|
*/
|
2015-09-13 14:04:31 +10:00
|
|
|
public void addDenied(final UUID uuid) {
|
2015-09-22 23:23:28 +10:00
|
|
|
PlotHandler.addDenied(this, uuid);
|
2015-09-11 20:09:22 +10:00
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-09-11 20:09:22 +10:00
|
|
|
/**
|
|
|
|
* Add someone as a helper (updates database as well)
|
|
|
|
*
|
|
|
|
* @param uuid
|
|
|
|
*/
|
2015-09-13 14:04:31 +10:00
|
|
|
public void addTrusted(final UUID uuid) {
|
2015-09-22 23:23:28 +10:00
|
|
|
PlotHandler.addTrusted(this, uuid);
|
2015-09-11 20:09:22 +10:00
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-09-11 20:09:22 +10:00
|
|
|
/**
|
|
|
|
* Add someone as a trusted user (updates database as well)
|
|
|
|
*
|
|
|
|
* @param uuid
|
|
|
|
*/
|
2015-09-13 14:04:31 +10:00
|
|
|
public void addMember(final UUID uuid) {
|
2015-09-22 23:23:28 +10:00
|
|
|
PlotHandler.addMember(this, uuid);
|
2015-09-11 20:09:22 +10:00
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-09-11 20:09:22 +10:00
|
|
|
/**
|
|
|
|
* Set the plot owner (and update the database)
|
|
|
|
* @param owner
|
|
|
|
*/
|
2015-09-13 14:04:31 +10:00
|
|
|
public void setOwner(final UUID owner) {
|
2015-09-22 23:23:28 +10:00
|
|
|
PlotHandler.setOwner(this, owner);
|
2015-09-11 20:09:22 +10:00
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-09-11 20:09:22 +10:00
|
|
|
/**
|
|
|
|
* Set the trusted users for this plot
|
|
|
|
* @param uuids
|
|
|
|
*/
|
2015-09-13 14:04:31 +10:00
|
|
|
public void setTrusted(final Set<UUID> uuids) {
|
2015-09-22 23:23:28 +10:00
|
|
|
PlotHandler.setTrusted(this, uuids);
|
2015-09-11 20:09:22 +10:00
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-09-11 20:09:22 +10:00
|
|
|
/**
|
|
|
|
* Set the members for this plot
|
|
|
|
* @param uuids
|
|
|
|
*/
|
2015-09-13 14:04:31 +10:00
|
|
|
public void setMembers(final Set<UUID> uuids) {
|
2015-09-22 23:23:28 +10:00
|
|
|
PlotHandler.setMembers(this, uuids);
|
2015-09-11 20:09:22 +10:00
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-09-11 20:09:22 +10:00
|
|
|
/**
|
|
|
|
* Set the denied users for this plot
|
|
|
|
* @param uuids
|
|
|
|
*/
|
2015-09-13 14:04:31 +10:00
|
|
|
public void setDenied(final Set<UUID> uuids) {
|
2015-09-22 23:23:28 +10:00
|
|
|
PlotHandler.setDenied(this, uuids);
|
2015-09-11 20:09:22 +10:00
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-09-11 20:09:22 +10:00
|
|
|
/**
|
|
|
|
* Clear a plot
|
|
|
|
* @see MainUtil#clear(Plot, boolean, Runnable)
|
|
|
|
* @see MainUtil#clearAsPlayer(Plot, boolean, Runnable)
|
|
|
|
* @see #deletePlot() to clear and delete a plot
|
|
|
|
* @param whenDone A runnable to execute when clearing finishes, or null
|
|
|
|
*/
|
2015-09-13 14:04:31 +10:00
|
|
|
public void clear(final Runnable whenDone) {
|
2015-09-11 20:09:22 +10:00
|
|
|
MainUtil.clear(this, false, whenDone);
|
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-09-11 20:09:22 +10:00
|
|
|
/**
|
|
|
|
* This will return null if the plot hasn't been analyzed
|
|
|
|
* @return analysis of plot
|
|
|
|
*/
|
2015-09-13 14:04:31 +10:00
|
|
|
public PlotAnalysis getComplexity() {
|
2015-09-11 20:09:22 +10:00
|
|
|
return PlotAnalysis.getAnalysis(this);
|
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
|
|
|
public void analyze(final RunnableVal<PlotAnalysis> whenDone) {
|
2015-09-11 20:09:22 +10:00
|
|
|
PlotAnalysis.analyzePlot(this, whenDone);
|
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-09-11 20:09:22 +10:00
|
|
|
/**
|
|
|
|
* Set a flag for this plot
|
|
|
|
* @param flag
|
|
|
|
* @param value
|
|
|
|
*/
|
2015-09-13 14:04:31 +10:00
|
|
|
public void setFlag(final String flag, final Object value) {
|
2015-09-11 20:09:22 +10:00
|
|
|
FlagManager.addPlotFlag(this, new Flag(FlagManager.getFlag(flag), value));
|
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-09-22 23:23:28 +10:00
|
|
|
/**
|
|
|
|
* Set a flag for this plot
|
|
|
|
* @param flag
|
|
|
|
* @param value
|
|
|
|
*/
|
|
|
|
public void setFlags(Set<Flag> flags) {
|
|
|
|
FlagManager.setPlotFlags(this, flags);
|
|
|
|
}
|
|
|
|
|
2015-09-11 20:09:22 +10:00
|
|
|
/**
|
|
|
|
* Remove a flag from this plot
|
|
|
|
* @param flag
|
|
|
|
*/
|
2015-09-13 14:04:31 +10:00
|
|
|
public void removeFlag(final String flag) {
|
2015-09-11 20:09:22 +10:00
|
|
|
FlagManager.removePlotFlag(this, flag);
|
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-09-11 20:09:22 +10:00
|
|
|
/**
|
|
|
|
* Get the flag for a given key
|
|
|
|
* @param flag
|
|
|
|
*/
|
2015-09-13 14:04:31 +10:00
|
|
|
public Flag getFlag(final String key) {
|
2015-10-07 17:33:33 +11:00
|
|
|
return FlagManager.getPlotFlagRaw(this, key);
|
2015-09-11 20:09:22 +10:00
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-09-11 20:09:22 +10:00
|
|
|
/**
|
|
|
|
* Delete a plot (use null for the runnable if you don't need to be notified on completion)
|
|
|
|
* @see PS#removePlot(String, PlotId, boolean)
|
|
|
|
* @see #clear(Runnable) to simply clear a plot
|
|
|
|
*/
|
2015-09-22 23:23:28 +10:00
|
|
|
public boolean deletePlot(final Runnable whenDone) {
|
|
|
|
boolean result = MainUtil.delete(this, whenDone);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if a previous task was running
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public int addRunning() {
|
|
|
|
int value = getRunning();
|
|
|
|
for (Plot plot : getConnectedPlots()) {
|
|
|
|
MainUtil.runners.put(plot, value + 1);
|
|
|
|
}
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int removeRunning() {
|
|
|
|
int value = getRunning();
|
|
|
|
if (value < 2) {
|
|
|
|
for (Plot plot : getConnectedPlots()) {
|
|
|
|
MainUtil.runners.remove(plot);
|
2015-09-11 20:09:22 +10:00
|
|
|
}
|
2015-09-22 23:23:28 +10:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
for (Plot plot : getConnectedPlots()) {
|
|
|
|
MainUtil.runners.put(plot, value - 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getRunning() {
|
|
|
|
Integer value = MainUtil.runners.get(this);
|
|
|
|
return value == null ? 0 : value;
|
2015-09-11 20:09:22 +10:00
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
|
|
|
public boolean unclaim() {
|
2015-09-22 23:23:28 +10:00
|
|
|
return PlotHandler.unclaim(this);
|
2015-09-11 20:09:22 +10:00
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-09-11 20:09:22 +10:00
|
|
|
/**
|
|
|
|
* Unlink a plot and remove the roads
|
|
|
|
* @see MainUtil#unlinkPlot(Plot, boolean removeRoad)
|
|
|
|
* @return true if plot was linked
|
|
|
|
*/
|
2015-09-13 14:04:31 +10:00
|
|
|
public boolean unlink() {
|
2015-09-22 23:23:28 +10:00
|
|
|
return MainUtil.unlinkPlot(this, true, true);
|
2015-09-11 20:09:22 +10:00
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-09-11 20:09:22 +10:00
|
|
|
/**
|
|
|
|
* Return the home location for the plot
|
|
|
|
* @see MainUtil#getPlotHome(Plot)
|
|
|
|
* @return Home location
|
|
|
|
*/
|
2015-09-13 14:04:31 +10:00
|
|
|
public Location getHome() {
|
2015-09-11 20:09:22 +10:00
|
|
|
return MainUtil.getPlotHome(this);
|
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-09-11 20:09:22 +10:00
|
|
|
/**
|
2015-10-24 21:55:34 +11:00
|
|
|
* Get the average rating of the plot. This is the value displayed in /plot info
|
2015-09-11 20:09:22 +10:00
|
|
|
* @return average rating as double
|
|
|
|
*/
|
2015-09-13 14:04:31 +10:00
|
|
|
public double getAverageRating() {
|
2015-09-11 20:09:22 +10:00
|
|
|
double sum = 0;
|
2015-11-28 22:46:10 +11:00
|
|
|
final Collection<Rating> ratings = getRatings().values();
|
2015-09-13 14:04:31 +10:00
|
|
|
for (final Rating rating : ratings) {
|
2015-09-11 20:09:22 +10:00
|
|
|
sum += rating.getAverageRating();
|
|
|
|
}
|
|
|
|
return (sum / ratings.size());
|
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-10-27 10:57:34 +11:00
|
|
|
/**
|
|
|
|
* Set a rating for a user<br>
|
|
|
|
* - If the user has already rated, the following will return false
|
|
|
|
* @param uuid
|
|
|
|
* @param rating
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public boolean addRating(UUID uuid, Rating rating) {
|
|
|
|
Plot base = getBasePlot(false);
|
|
|
|
PlotSettings baseSettings = base.getSettings();
|
|
|
|
if (baseSettings.getRatings().containsKey(uuid)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
baseSettings.getRatings().put(uuid, rating.getAggregate());
|
|
|
|
DBFunc.setRating(base, uuid, temp);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clear the ratings for this plot
|
|
|
|
*/
|
|
|
|
public void clearRatings() {
|
|
|
|
Plot base = getBasePlot(false);
|
|
|
|
PlotSettings baseSettings = base.getSettings();
|
|
|
|
if (baseSettings.ratings != null && baseSettings.ratings.size() > 0) {
|
|
|
|
DBFunc.deleteRatings(base);
|
|
|
|
baseSettings.ratings = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-11 20:09:22 +10:00
|
|
|
/**
|
|
|
|
* Get the ratings associated with a plot<br>
|
|
|
|
* - The rating object may contain multiple categories
|
|
|
|
* @return Map of user who rated to the rating
|
|
|
|
*/
|
2015-09-13 14:04:31 +10:00
|
|
|
public HashMap<UUID, Rating> getRatings() {
|
2015-10-27 10:57:34 +11:00
|
|
|
Plot base = getBasePlot(false);
|
2015-09-11 20:09:22 +10:00
|
|
|
final HashMap<UUID, Rating> map = new HashMap<UUID, Rating>();
|
2015-10-27 10:57:34 +11:00
|
|
|
if (base.getSettings().ratings == null) {
|
2015-09-13 14:04:31 +10:00
|
|
|
return map;
|
|
|
|
}
|
2015-10-27 10:57:34 +11:00
|
|
|
for (final Entry<UUID, Integer> entry : base.getSettings().ratings.entrySet()) {
|
2015-09-11 20:09:22 +10:00
|
|
|
map.put(entry.getKey(), new Rating(entry.getValue()));
|
|
|
|
}
|
|
|
|
return map;
|
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-09-11 20:09:22 +10:00
|
|
|
/**
|
|
|
|
* Set the home location
|
|
|
|
* @param loc
|
|
|
|
*/
|
2015-09-13 14:04:31 +10:00
|
|
|
public void setHome(final BlockLoc loc) {
|
2015-09-11 20:09:22 +10:00
|
|
|
final BlockLoc pos = getSettings().getPosition();
|
2015-09-22 23:23:28 +10:00
|
|
|
if (((pos == null || pos.equals(new BlockLoc(0, 0, 0))) && (loc == null)) || ((pos != null) && pos.equals(loc))) {
|
2015-09-13 14:04:31 +10:00
|
|
|
return;
|
|
|
|
}
|
2015-09-11 20:09:22 +10:00
|
|
|
getSettings().setPosition(loc);
|
2015-09-13 14:04:31 +10:00
|
|
|
if (getSettings().getPosition() == null) {
|
2015-09-11 20:09:22 +10:00
|
|
|
DBFunc.setPosition(this, "");
|
2015-09-13 14:04:31 +10:00
|
|
|
} else {
|
2015-09-11 20:09:22 +10:00
|
|
|
DBFunc.setPosition(this, getSettings().getPosition().toString());
|
|
|
|
}
|
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-09-11 20:09:22 +10:00
|
|
|
/**
|
|
|
|
* Set the plot alias
|
|
|
|
* @param alias
|
|
|
|
*/
|
2015-09-13 14:04:31 +10:00
|
|
|
public void setAlias(String alias) {
|
2015-09-29 16:29:28 +10:00
|
|
|
for (Plot current : getConnectedPlots()) {
|
|
|
|
final String name = getSettings().getAlias();
|
|
|
|
if (alias == null) {
|
|
|
|
alias = "";
|
|
|
|
}
|
|
|
|
if (name.equals(alias)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
current.getSettings().setAlias(alias);
|
|
|
|
DBFunc.setAlias(current, alias);
|
2015-09-13 14:04:31 +10:00
|
|
|
}
|
2015-09-11 20:09:22 +10:00
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-09-11 20:09:22 +10:00
|
|
|
/**
|
|
|
|
* Resend all chunks inside the plot to nearby players<br>
|
|
|
|
* This should not need to be called
|
|
|
|
* @see MainUtil#update(Plot)
|
|
|
|
*/
|
2015-09-13 14:04:31 +10:00
|
|
|
public void refreshChunks() {
|
2015-09-11 20:09:22 +10:00
|
|
|
MainUtil.update(this);
|
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-09-11 20:09:22 +10:00
|
|
|
/**
|
|
|
|
* Remove the plot sign if it is set
|
|
|
|
*/
|
2015-09-13 14:04:31 +10:00
|
|
|
public void removeSign() {
|
2015-09-11 20:09:22 +10:00
|
|
|
MainUtil.removeSign(this);
|
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-09-11 20:09:22 +10:00
|
|
|
/**
|
|
|
|
* Set the plot sign if plot signs are enabled
|
|
|
|
*/
|
2015-09-13 14:04:31 +10:00
|
|
|
public void setSign() {
|
2015-09-11 20:09:22 +10:00
|
|
|
MainUtil.setSign(this);
|
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-09-11 20:09:22 +10:00
|
|
|
/**
|
|
|
|
* Register a plot and create it in the database<br>
|
|
|
|
* - The plot will not be created if the owner is null<br>
|
2015-09-13 01:19:39 +10:00
|
|
|
* - Any setting from before plot creation will not be saved until the server is stopped properly. i.e. Set any values/options after plot creation.
|
2015-09-11 20:09:22 +10:00
|
|
|
* @return true if plot was created successfully
|
|
|
|
*/
|
2015-09-13 14:04:31 +10:00
|
|
|
public boolean create() {
|
2015-09-11 20:09:22 +10:00
|
|
|
return MainUtil.createPlot(owner, this);
|
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-09-11 20:09:22 +10:00
|
|
|
/**
|
|
|
|
* Auto merge the plot with any adjacent plots of the same owner
|
|
|
|
* @see MainUtil#autoMerge(Plot, UUID) to specify the owner
|
|
|
|
* @param removeRoads If to remove roads when merging
|
|
|
|
*/
|
2015-09-22 23:23:28 +10:00
|
|
|
public boolean autoMerge(final boolean removeRoads) {
|
|
|
|
return MainUtil.autoMerge(this, -1, Integer.MAX_VALUE, owner, removeRoads);
|
2015-09-11 20:09:22 +10:00
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-09-11 20:09:22 +10:00
|
|
|
/**
|
|
|
|
* Set the plot biome (this does not set the terrain, @see BiomeGenerator plugin for terrain)
|
|
|
|
*/
|
2015-09-13 14:04:31 +10:00
|
|
|
public void setBiome(final String biome, final Runnable whenDone) {
|
2015-09-11 20:09:22 +10:00
|
|
|
MainUtil.setBiome(this, biome, whenDone);
|
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-09-11 20:09:22 +10:00
|
|
|
/**
|
|
|
|
* Set components such as border, wall, floor
|
|
|
|
* (components are generator specific)
|
|
|
|
*/
|
2015-09-22 23:23:28 +10:00
|
|
|
public boolean setComponent(final String component, final PlotBlock... blocks) {
|
|
|
|
return MainUtil.setComponent(this, component, blocks);
|
2015-09-11 20:09:22 +10:00
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-09-11 20:09:22 +10:00
|
|
|
/**
|
|
|
|
* Set components such as border, wall, floor
|
|
|
|
* (components are generator specific)
|
|
|
|
*/
|
2015-09-22 23:23:28 +10:00
|
|
|
public boolean setComponent(final String component, final String blocks) {
|
|
|
|
PlotBlock[] parsed = Configuration.BLOCKLIST.parseString(blocks);
|
|
|
|
if (parsed == null || parsed.length == 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return MainUtil.setComponent(this, component, parsed);
|
2015-09-11 20:09:22 +10:00
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-09-11 20:09:22 +10:00
|
|
|
/**
|
|
|
|
* Get the biome (String)
|
|
|
|
*/
|
2015-09-13 14:04:31 +10:00
|
|
|
public String getBiome() {
|
2015-09-22 23:23:28 +10:00
|
|
|
final Location loc = getBottomAbs();
|
2015-09-11 20:09:22 +10:00
|
|
|
return BlockManager.manager.getBiome(loc.getWorld(), loc.getX(), loc.getZ());
|
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-09-11 20:09:22 +10:00
|
|
|
/**
|
|
|
|
* Return the top location for the plot
|
|
|
|
* @return
|
|
|
|
*/
|
2015-09-22 23:23:28 +10:00
|
|
|
public Location getTopAbs() {
|
|
|
|
return MainUtil.getPlotTopLocAbs(world, id);
|
2015-09-11 20:09:22 +10:00
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-09-11 20:09:22 +10:00
|
|
|
/**
|
|
|
|
* Return the bottom location for the plot
|
|
|
|
* @return
|
|
|
|
*/
|
2015-09-22 23:23:28 +10:00
|
|
|
public Location getBottomAbs() {
|
|
|
|
return MainUtil.getPlotBottomLocAbs(world, id);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-12-03 02:42:50 +11:00
|
|
|
* 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
|
2015-09-22 23:23:28 +10:00
|
|
|
* @deprecated as merged plots no longer need to be rectangular
|
|
|
|
* @param plot
|
2015-12-03 02:42:50 +11:00
|
|
|
* @return new Location[] { bottom, top }
|
|
|
|
* @see MainUtil#getCorners(Plot)
|
2015-09-22 23:23:28 +10:00
|
|
|
*/
|
|
|
|
@Deprecated
|
|
|
|
public Location[] getCorners() {
|
|
|
|
return MainUtil.getCorners(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-12-03 02:42:50 +11:00
|
|
|
* 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>
|
2015-09-22 23:23:28 +10:00
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
@Deprecated
|
2015-09-13 14:04:31 +10:00
|
|
|
public Location getBottom() {
|
2015-09-22 23:23:28 +10:00
|
|
|
return getCorners()[0];
|
2015-09-11 20:09:22 +10:00
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-09-11 20:09:22 +10:00
|
|
|
/**
|
2015-09-22 23:23:28 +10:00
|
|
|
* @deprecated in favor of getCorners()[1];
|
|
|
|
* @return
|
2015-09-11 20:09:22 +10:00
|
|
|
*/
|
2015-09-22 23:23:28 +10:00
|
|
|
@Deprecated
|
|
|
|
public Location getTop() {
|
|
|
|
return getCorners()[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a set of plots connected (and including) this plot<br>
|
|
|
|
* - This result is cached globally
|
|
|
|
* @see MainUtil#getConnectedPlots(Plot)
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public Set<Plot> getConnectedPlots() {
|
|
|
|
return MainUtil.getConnectedPlots(this);
|
2015-09-11 20:09:22 +10:00
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-09-11 20:09:22 +10:00
|
|
|
/**
|
2015-12-03 02:42:50 +11:00
|
|
|
* This will combine each plot into effective rectangular regions<br>
|
|
|
|
* - This result is cached globally<br>
|
|
|
|
* - Useful for handling non rectangular shapes
|
2015-09-22 23:23:28 +10:00
|
|
|
* @see MainUtil#getRegions(Plot)
|
|
|
|
* @return
|
2015-09-11 20:09:22 +10:00
|
|
|
*/
|
2015-09-22 23:23:28 +10:00
|
|
|
public Set<RegionWrapper> getRegions() {
|
|
|
|
return MainUtil.getRegions(this);
|
2015-09-11 20:09:22 +10:00
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-09-11 20:09:22 +10:00
|
|
|
/**
|
|
|
|
* Swap the plot contents and settings with another location<br>
|
|
|
|
* - The destination must correspond to a valid plot of equal dimensions
|
|
|
|
* @see ChunkManager#swap(String, bot1, top1, bot2, top2) to swap terrain
|
|
|
|
* @see MainUtil#getPlotSelectionIds(PlotId, PlotId) to get the plots inside a selection
|
|
|
|
* @see MainUtil#swapData(String, PlotId, PlotId, Runnable) to swap plot settings
|
2015-09-22 23:23:28 +10:00
|
|
|
* @param other The other plot to swap with
|
2015-09-11 20:09:22 +10:00
|
|
|
* @param whenDone A task to run when finished, or null
|
|
|
|
* @see MainUtil#swapData(String, PlotId, PlotId, Runnable)
|
|
|
|
* @return boolean if swap was successful
|
|
|
|
*/
|
2015-09-22 23:23:28 +10:00
|
|
|
public boolean swap(final Plot destination, final Runnable whenDone) {
|
|
|
|
return MainUtil.move(this, destination, whenDone, true);
|
2015-09-11 20:09:22 +10:00
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-09-11 20:09:22 +10:00
|
|
|
/**
|
|
|
|
* Move the plot to an empty location<br>
|
|
|
|
* - The location must be empty
|
|
|
|
* @param destination Where to move the plot
|
|
|
|
* @param whenDone A task to run when done, or null
|
|
|
|
* @return if the move was successful
|
|
|
|
*/
|
2015-09-13 14:04:31 +10:00
|
|
|
public boolean move(final Plot destination, final Runnable whenDone) {
|
2015-09-22 23:23:28 +10:00
|
|
|
return MainUtil.move(this, destination, whenDone, false);
|
2015-09-11 20:09:22 +10:00
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-09-11 20:09:22 +10:00
|
|
|
/**
|
|
|
|
* Copy the plot contents and settings to another location<br>
|
|
|
|
* - The destination must correspond to an empty location
|
|
|
|
* @param destination The location to copy to
|
|
|
|
* @param whenDone The task to run when done
|
|
|
|
* @return If the copy was successful
|
|
|
|
*/
|
2015-09-22 23:23:28 +10:00
|
|
|
public boolean copy(final Plot destination, final Runnable whenDone) {
|
|
|
|
return MainUtil.copy(this, destination, whenDone);
|
2015-09-11 20:09:22 +10:00
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-09-11 20:09:22 +10:00
|
|
|
/**
|
|
|
|
* Get plot display name
|
|
|
|
*
|
|
|
|
* @return alias if set, else id
|
|
|
|
*/
|
|
|
|
@Override
|
2015-09-13 14:04:31 +10:00
|
|
|
public String toString() {
|
|
|
|
if ((settings != null) && (settings.getAlias().length() > 1)) {
|
|
|
|
return settings.getAlias();
|
|
|
|
}
|
2015-09-11 20:09:22 +10:00
|
|
|
return world + ";" + getId().x + ";" + getId().y;
|
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-09-11 20:09:22 +10:00
|
|
|
/**
|
2015-12-03 02:42:50 +11:00
|
|
|
* Remove a denied player (use DBFunc as well)<br>
|
|
|
|
* Using the * uuid will remove all users
|
2015-09-11 20:09:22 +10:00
|
|
|
* @param uuid
|
|
|
|
*/
|
2015-09-13 14:04:31 +10:00
|
|
|
public boolean removeDenied(final UUID uuid) {
|
2015-10-27 10:57:34 +11:00
|
|
|
if (uuid == DBFunc.everyone) {
|
|
|
|
boolean result = false;
|
2015-11-15 13:30:52 +11:00
|
|
|
for (UUID other : new HashSet<>(getDenied())) {
|
2015-10-27 10:57:34 +11:00
|
|
|
result = result || PlotHandler.removeDenied(this, other);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
2015-10-18 22:20:12 +11:00
|
|
|
return PlotHandler.removeDenied(this, uuid);
|
2015-09-11 20:09:22 +10:00
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-09-11 20:09:22 +10:00
|
|
|
/**
|
2015-12-03 02:42:50 +11:00
|
|
|
* Remove a helper (use DBFunc as well)<br>
|
|
|
|
* Using the * uuid will remove all users
|
2015-09-11 20:09:22 +10:00
|
|
|
* @param uuid
|
|
|
|
*/
|
2015-09-13 14:04:31 +10:00
|
|
|
public boolean removeTrusted(final UUID uuid) {
|
2015-10-27 10:57:34 +11:00
|
|
|
if (uuid == DBFunc.everyone) {
|
|
|
|
boolean result = false;
|
2015-11-15 13:30:52 +11:00
|
|
|
for (UUID other : new HashSet<>(getTrusted())) {
|
2015-10-27 10:57:34 +11:00
|
|
|
result = result || PlotHandler.removeTrusted(this, other);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
2015-10-18 22:20:12 +11:00
|
|
|
return PlotHandler.removeTrusted(this, uuid);
|
2015-09-11 20:09:22 +10:00
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-09-11 20:09:22 +10:00
|
|
|
/**
|
2015-12-03 02:42:50 +11:00
|
|
|
* Remove a trusted user (use DBFunc as well)<br>
|
|
|
|
* Using the * uuid will remove all users
|
2015-09-11 20:09:22 +10:00
|
|
|
* @param uuid
|
|
|
|
*/
|
2015-09-13 14:04:31 +10:00
|
|
|
public boolean removeMember(final UUID uuid) {
|
2015-10-27 10:57:34 +11:00
|
|
|
if (uuid == DBFunc.everyone) {
|
|
|
|
boolean result = false;
|
2015-11-15 13:30:52 +11:00
|
|
|
for (UUID other : new HashSet<>(getMembers())) {
|
2015-10-27 10:57:34 +11:00
|
|
|
result = result || PlotHandler.removeMember(this, other);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
2015-10-18 22:20:12 +11:00
|
|
|
return PlotHandler.removeMember(this, uuid);
|
2015-09-11 20:09:22 +10:00
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-09-11 20:09:22 +10:00
|
|
|
/**
|
|
|
|
* Export the plot as a schematic to the configured output directory
|
|
|
|
* @return
|
|
|
|
*/
|
2015-09-13 14:04:31 +10:00
|
|
|
public void export(final RunnableVal<Boolean> whenDone) {
|
|
|
|
SchematicHandler.manager.getCompoundTag(world, id, new RunnableVal<CompoundTag>() {
|
2015-09-11 20:09:22 +10:00
|
|
|
@Override
|
2015-09-13 14:04:31 +10:00
|
|
|
public void run() {
|
|
|
|
if (value == null) {
|
|
|
|
if (whenDone != null) {
|
2015-09-11 20:09:22 +10:00
|
|
|
whenDone.value = false;
|
|
|
|
TaskManager.runTask(whenDone);
|
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
} else {
|
|
|
|
TaskManager.runTaskAsync(new Runnable() {
|
2015-09-11 20:09:22 +10:00
|
|
|
@Override
|
2015-09-13 14:04:31 +10:00
|
|
|
public void run() {
|
2015-09-11 20:09:22 +10:00
|
|
|
final String name = id + "," + world + "," + MainUtil.getName(owner);
|
|
|
|
final boolean result = SchematicHandler.manager.save(value, Settings.SCHEMATIC_SAVE_PATH + File.separator + name + ".schematic");
|
2015-09-13 14:04:31 +10:00
|
|
|
if (whenDone != null) {
|
2015-09-11 20:09:22 +10:00
|
|
|
whenDone.value = result;
|
|
|
|
TaskManager.runTask(whenDone);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-09-11 20:09:22 +10:00
|
|
|
/**
|
|
|
|
* Export the plot as a BO3 object<br>
|
|
|
|
* - bedrock, floor and main block are ignored in their respective sections
|
|
|
|
* - air is ignored
|
|
|
|
* - The center is considered to be on top of the plot in the center
|
|
|
|
* @param whenDone value will be false if exporting fails
|
|
|
|
*/
|
2015-09-13 14:04:31 +10:00
|
|
|
public void exportBO3(final RunnableVal<Boolean> whenDone) {
|
2015-09-11 20:09:22 +10:00
|
|
|
final boolean result = BO3Handler.saveBO3(this);
|
2015-09-13 14:04:31 +10:00
|
|
|
if (whenDone != null) {
|
2015-09-11 20:09:22 +10:00
|
|
|
whenDone.value = result;
|
|
|
|
}
|
|
|
|
TaskManager.runTask(whenDone);
|
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-09-11 20:09:22 +10:00
|
|
|
/**
|
2015-12-03 02:42:50 +11:00
|
|
|
* Upload the plot as a schematic to the configured web interface
|
2015-09-11 20:09:22 +10:00
|
|
|
* @param whenDone value will be null if uploading fails
|
|
|
|
*/
|
2015-09-13 14:04:31 +10:00
|
|
|
public void upload(final RunnableVal<URL> whenDone) {
|
|
|
|
SchematicHandler.manager.getCompoundTag(world, id, new RunnableVal<CompoundTag>() {
|
2015-09-11 20:09:22 +10:00
|
|
|
@Override
|
2015-09-13 14:04:31 +10:00
|
|
|
public void run() {
|
|
|
|
TaskManager.runTaskAsync(new Runnable() {
|
2015-09-11 20:09:22 +10:00
|
|
|
@Override
|
2015-09-13 14:04:31 +10:00
|
|
|
public void run() {
|
2015-09-11 20:09:22 +10:00
|
|
|
final URL url = SchematicHandler.manager.upload(value, null, null);
|
2015-09-13 14:04:31 +10:00
|
|
|
if (whenDone != null) {
|
2015-09-11 20:09:22 +10:00
|
|
|
whenDone.value = url;
|
|
|
|
}
|
|
|
|
TaskManager.runTask(whenDone);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-09-11 20:09:22 +10:00
|
|
|
@Override
|
2015-09-13 14:04:31 +10:00
|
|
|
public boolean equals(final Object obj) {
|
|
|
|
if (this == obj) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (obj == null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (getClass() != obj.getClass()) {
|
|
|
|
return false;
|
|
|
|
}
|
2015-09-11 20:09:22 +10:00
|
|
|
final Plot other = (Plot) obj;
|
2015-09-13 14:04:31 +10:00
|
|
|
if (hashCode() != other.hashCode()) {
|
|
|
|
return false;
|
|
|
|
}
|
2015-09-11 20:09:22 +10:00
|
|
|
return ((id.x.equals(other.id.x)) && (id.y.equals(other.id.y)) && (StringMan.isEqual(world, other.world)));
|
|
|
|
}
|
2015-09-13 14:04:31 +10:00
|
|
|
|
2015-09-11 20:09:22 +10:00
|
|
|
/**
|
|
|
|
* Get the plot hashcode
|
|
|
|
*
|
|
|
|
* @return integer.
|
|
|
|
*/
|
|
|
|
@Override
|
2015-09-13 14:04:31 +10:00
|
|
|
public int hashCode() {
|
2015-09-11 20:09:22 +10:00
|
|
|
return id.hashCode();
|
|
|
|
}
|
2015-09-22 23:23:28 +10:00
|
|
|
|
2015-12-03 02:42:50 +11:00
|
|
|
/**
|
|
|
|
* Get the flags specific to this plot<br>
|
|
|
|
* - Does not take default flags into account<br>
|
|
|
|
* @return
|
|
|
|
*/
|
2015-09-22 23:23:28 +10:00
|
|
|
public HashMap<String, Flag> getFlags() {
|
|
|
|
if (settings == null) {
|
|
|
|
return new HashMap<>(0);
|
|
|
|
}
|
|
|
|
return settings.flags;
|
|
|
|
}
|
|
|
|
|
2015-12-03 02:42:50 +11:00
|
|
|
/**
|
|
|
|
* Get the plot Alias<br>
|
|
|
|
* - Returns an empty string if no alias is set
|
|
|
|
* @return
|
|
|
|
*/
|
2015-09-22 23:23:28 +10:00
|
|
|
public String getAlias() {
|
2015-09-29 16:29:28 +10:00
|
|
|
if (settings == null) {
|
|
|
|
return "";
|
|
|
|
}
|
2015-09-22 23:23:28 +10:00
|
|
|
return getSettings().getAlias();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the raw merge data<br>
|
2015-12-03 02:42:50 +11:00
|
|
|
* - 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.
|
2015-09-22 23:23:28 +10:00
|
|
|
* @param merged
|
|
|
|
*/
|
|
|
|
public void setMerged(boolean[] merged) {
|
|
|
|
getSettings().merged = merged;
|
|
|
|
DBFunc.setMerged(this, merged);
|
|
|
|
MainUtil.connected_cache = null;
|
|
|
|
MainUtil.regions_cache = null;
|
2015-09-29 16:29:28 +10:00
|
|
|
if (origin != null) {
|
|
|
|
origin.origin = null;
|
|
|
|
origin = null;
|
|
|
|
}
|
2015-09-22 23:23:28 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the raw merge data<br>
|
2015-12-03 02:42:50 +11:00
|
|
|
* - Updates DB<br>
|
|
|
|
* - Does not modify terrain<br>
|
|
|
|
* ----------<br>
|
|
|
|
* 0 = north<br>
|
|
|
|
* 1 = east<br>
|
|
|
|
* 2 = south<br>
|
|
|
|
* 3 = west<br>
|
|
|
|
* ----------<br>
|
2015-09-22 23:23:28 +10:00
|
|
|
* @param merged
|
|
|
|
*/
|
|
|
|
public void setMerged(int direction, boolean value) {
|
|
|
|
if (getSettings().setMerged(direction, value)) {
|
2015-09-29 16:29:28 +10:00
|
|
|
if (value) {
|
|
|
|
Plot other = MainUtil.getPlotRelative(this, direction).getBasePlot(false);
|
|
|
|
if (!other.equals(getBasePlot(false))) {
|
|
|
|
Plot base = ((other.id.y < id.y) || ((other.id.y == id.y) && (other.id.x < id.x))) ? other : origin;
|
|
|
|
origin.origin = base;
|
|
|
|
other.origin = base;
|
|
|
|
origin = base;
|
|
|
|
MainUtil.connected_cache = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (origin != null) {
|
|
|
|
origin.origin = null;
|
|
|
|
origin = null;
|
|
|
|
}
|
|
|
|
MainUtil.connected_cache = null;
|
|
|
|
}
|
2015-09-22 23:23:28 +10:00
|
|
|
DBFunc.setMerged(this, getSettings().getMerged());
|
|
|
|
MainUtil.regions_cache = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-03 02:42:50 +11:00
|
|
|
/**
|
|
|
|
* Get the merged array
|
|
|
|
* @return boolean [ north, east, south, west ]
|
|
|
|
*/
|
2015-09-22 23:23:28 +10:00
|
|
|
public boolean[] getMerged() {
|
|
|
|
if (settings == null) {
|
|
|
|
return new boolean[] {false, false, false, false };
|
|
|
|
}
|
|
|
|
return settings.getMerged();
|
|
|
|
}
|
|
|
|
|
2015-12-03 02:42:50 +11:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2015-09-22 23:23:28 +10:00
|
|
|
public BlockLoc getPosition() {
|
|
|
|
if (settings == null) {
|
|
|
|
return new BlockLoc(0, 0, 0);
|
|
|
|
}
|
|
|
|
return settings.getPosition();
|
|
|
|
}
|
2015-09-11 20:09:22 +10:00
|
|
|
}
|