2014-11-08 20:27:09 +01: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 /
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
2014-11-16 10:48:18 +01:00
|
|
|
package com.intellectualcrafters.plot.object;
|
2014-09-22 13:02:14 +02:00
|
|
|
|
2015-01-13 17:38:15 +01:00
|
|
|
import java.util.ArrayList;
|
2015-06-23 23:44:44 +02:00
|
|
|
import java.util.Collection;
|
2015-07-10 05:17:32 +02:00
|
|
|
import java.util.HashMap;
|
2015-01-13 17:38:15 +01:00
|
|
|
import java.util.HashSet;
|
2015-07-17 12:48:13 +02:00
|
|
|
import java.util.List;
|
2015-07-10 05:17:32 +02:00
|
|
|
import java.util.Map.Entry;
|
2015-01-13 17:38:15 +01:00
|
|
|
import java.util.UUID;
|
2015-01-06 17:08:29 +01:00
|
|
|
|
2015-07-17 12:48:13 +02:00
|
|
|
import sun.awt.SunHints.Value;
|
|
|
|
|
2015-07-04 08:37:33 +02:00
|
|
|
import com.intellectualcrafters.plot.PS;
|
2015-01-13 17:38:15 +01:00
|
|
|
import com.intellectualcrafters.plot.database.DBFunc;
|
|
|
|
import com.intellectualcrafters.plot.flag.Flag;
|
2015-07-17 12:48:13 +02:00
|
|
|
import com.intellectualcrafters.plot.flag.FlagManager;
|
2015-07-04 08:37:33 +02:00
|
|
|
import com.intellectualcrafters.plot.util.ChunkManager;
|
|
|
|
import com.intellectualcrafters.plot.util.MainUtil;
|
2014-09-22 13:02:14 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The plot class
|
2014-10-11 09:33:10 +02:00
|
|
|
*
|
2014-09-22 13:02:14 +02:00
|
|
|
* @author Citymonstret
|
2014-11-19 17:46:30 +01:00
|
|
|
* @author Empire92
|
2014-09-22 13:02:14 +02:00
|
|
|
*/
|
2015-02-20 07:34:19 +01:00
|
|
|
@SuppressWarnings("javadoc")
|
|
|
|
public class Plot implements Cloneable {
|
2014-11-05 04:42:08 +01:00
|
|
|
/**
|
|
|
|
* plot ID
|
|
|
|
*/
|
2014-12-18 03:15:11 +01:00
|
|
|
public final PlotId id;
|
2014-11-05 04:42:08 +01:00
|
|
|
/**
|
|
|
|
* plot world
|
|
|
|
*/
|
2014-12-18 03:15:11 +01:00
|
|
|
public final String world;
|
2014-11-05 04:42:08 +01:00
|
|
|
/**
|
|
|
|
* plot owner
|
|
|
|
*/
|
2015-03-20 05:11:02 +01:00
|
|
|
public UUID owner;
|
2014-11-05 04:42:08 +01:00
|
|
|
/**
|
2015-05-14 14:55:57 +02:00
|
|
|
* List of trusted (with plot permissions)
|
2014-11-05 04:42:08 +01:00
|
|
|
*/
|
2015-07-17 05:48:23 +02:00
|
|
|
public HashSet<UUID> trusted;
|
2014-11-05 04:42:08 +01:00
|
|
|
/**
|
2015-05-14 14:55:57 +02:00
|
|
|
* List of members users (with plot permissions)
|
2014-11-05 04:42:08 +01:00
|
|
|
*/
|
2015-07-17 05:48:23 +02:00
|
|
|
public HashSet<UUID> members;
|
2014-11-05 04:42:08 +01:00
|
|
|
/**
|
|
|
|
* List of denied players
|
|
|
|
*/
|
2015-07-17 05:48:23 +02:00
|
|
|
public HashSet<UUID> denied;
|
2014-11-05 04:42:08 +01:00
|
|
|
/**
|
2015-07-10 05:17:32 +02:00
|
|
|
* 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>
|
2014-11-05 04:42:08 +01:00
|
|
|
*/
|
2014-12-18 03:15:11 +01:00
|
|
|
public PlotSettings settings;
|
2014-11-05 04:42:08 +01:00
|
|
|
/**
|
|
|
|
* Has the plot changed since the last save cycle?
|
|
|
|
*/
|
2014-12-18 03:15:11 +01:00
|
|
|
public boolean hasChanged = false;
|
|
|
|
public boolean countsTowardsMax = true;
|
2015-07-04 08:37:33 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* If this plot is temporary i.e. not stored in the DB
|
|
|
|
*/
|
|
|
|
public final boolean temp;
|
2015-02-23 02:32:27 +01:00
|
|
|
|
2014-11-19 17:46:30 +01:00
|
|
|
/**
|
2015-07-04 08:37:33 +02:00
|
|
|
* Constructor for a new plot
|
|
|
|
*
|
|
|
|
* @param world
|
2014-11-19 17:46:30 +01:00
|
|
|
* @param id
|
|
|
|
* @param owner
|
|
|
|
*/
|
2015-07-04 08:37:33 +02:00
|
|
|
public Plot(String world, PlotId id, UUID owner) {
|
|
|
|
this.world = world;
|
2014-11-19 17:46:30 +01:00
|
|
|
this.id = id;
|
2015-03-20 05:11:02 +01:00
|
|
|
this.owner = owner;
|
2015-07-04 08:37:33 +02:00
|
|
|
this.settings = new PlotSettings(this);
|
2015-07-17 05:48:23 +02:00
|
|
|
this.trusted = new HashSet<>();
|
|
|
|
this.members = new HashSet<>();
|
|
|
|
this.denied = new HashSet<>();
|
2015-07-04 08:37:33 +02:00
|
|
|
this.temp = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor for a temporary plot
|
|
|
|
*
|
|
|
|
* @param world
|
|
|
|
* @param id
|
|
|
|
* @param owner
|
|
|
|
* @param temp
|
|
|
|
*/
|
|
|
|
public Plot(String world, PlotId id, UUID owner, boolean temp) {
|
2014-11-19 17:46:30 +01:00
|
|
|
this.world = world;
|
2015-07-04 08:37:33 +02:00
|
|
|
this.id = id;
|
|
|
|
this.owner = owner;
|
|
|
|
this.settings = new PlotSettings(this);
|
2015-07-17 05:48:23 +02:00
|
|
|
this.trusted = new HashSet<>();
|
|
|
|
this.members = new HashSet<>();
|
|
|
|
this.denied = new HashSet<>();
|
2015-07-04 08:37:33 +02:00
|
|
|
this.temp = temp;
|
2014-11-19 17:46:30 +01:00
|
|
|
}
|
2015-07-04 08:37:33 +02:00
|
|
|
|
2014-11-19 17:46:30 +01:00
|
|
|
/**
|
2015-07-04 08:37:33 +02:00
|
|
|
* Constructor for a saved plots
|
2014-11-19 17:46:30 +01:00
|
|
|
*
|
|
|
|
* @param id
|
|
|
|
* @param owner
|
2015-05-14 14:55:57 +02:00
|
|
|
* @param trusted
|
2014-11-19 17:46:30 +01:00
|
|
|
* @param denied
|
|
|
|
* @param merged
|
|
|
|
*/
|
2015-07-17 05:48:23 +02:00
|
|
|
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, final Collection<Flag> flags, final String world, final boolean[] merged) {
|
2014-11-19 17:46:30 +01:00
|
|
|
this.id = id;
|
|
|
|
this.settings = new PlotSettings(this);
|
2015-03-20 05:11:02 +01:00
|
|
|
this.owner = owner;
|
2015-05-14 14:55:57 +02:00
|
|
|
this.members = members;
|
2014-11-19 17:46:30 +01:00
|
|
|
this.trusted = trusted;
|
|
|
|
this.denied = denied;
|
|
|
|
this.settings.setAlias(alias);
|
|
|
|
this.settings.setPosition(position);
|
|
|
|
this.settings.setMerged(merged);
|
|
|
|
if (flags != null) {
|
2015-06-23 23:44:44 +02:00
|
|
|
for (Flag flag : flags) {
|
|
|
|
this.settings.flags.put(flag.getKey(), flag);
|
|
|
|
}
|
2014-11-19 17:46:30 +01:00
|
|
|
}
|
|
|
|
this.world = world;
|
2015-07-04 08:37:33 +02:00
|
|
|
this.temp = false;
|
2014-11-19 17:46:30 +01:00
|
|
|
}
|
2015-02-23 02:32:27 +01:00
|
|
|
|
2014-11-05 04:42:08 +01:00
|
|
|
/**
|
|
|
|
* Check if the plot has a set owner
|
|
|
|
*
|
|
|
|
* @return false if there is no owner
|
|
|
|
*/
|
|
|
|
public boolean hasOwner() {
|
2015-03-20 05:11:02 +01:00
|
|
|
return this.owner != null;
|
2014-11-05 04:42:08 +01:00
|
|
|
}
|
2015-03-20 04:00:02 +01:00
|
|
|
|
|
|
|
public boolean isOwner(UUID uuid) {
|
|
|
|
return PlotHandler.isOwner(this, uuid);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a list of owner UUIDs for a plot (supports multi-owner mega-plots)
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public HashSet<UUID> getOwners() {
|
|
|
|
return PlotHandler.getOwners(this);
|
|
|
|
}
|
2015-02-23 02:32:27 +01:00
|
|
|
|
2014-11-05 04:42:08 +01:00
|
|
|
/**
|
2015-05-14 14:55:57 +02:00
|
|
|
* Check if the player is either the owner or on the trusted list
|
2014-11-05 04:42:08 +01:00
|
|
|
*
|
2015-03-13 08:02:48 +01:00
|
|
|
* @param uuid
|
2014-12-18 03:15:11 +01:00
|
|
|
*
|
2014-11-05 04:42:08 +01:00
|
|
|
* @return true if the player is added as a helper or is the owner
|
|
|
|
*/
|
2015-02-20 07:09:53 +01:00
|
|
|
public boolean isAdded(final UUID uuid) {
|
2015-03-20 04:00:02 +01:00
|
|
|
return PlotHandler.isAdded(this, uuid);
|
2014-11-05 04:42:08 +01:00
|
|
|
}
|
2015-02-23 02:32:27 +01:00
|
|
|
|
2014-11-05 04:42:08 +01:00
|
|
|
/**
|
|
|
|
* Should the player be allowed to enter?
|
|
|
|
*
|
2015-03-13 08:02:48 +01:00
|
|
|
* @param uuid
|
2014-12-18 03:15:11 +01:00
|
|
|
*
|
2015-03-13 08:02:48 +01:00
|
|
|
* @return boolean false if the player is allowed to enter
|
2014-11-05 04:42:08 +01:00
|
|
|
*/
|
2015-02-20 07:09:53 +01:00
|
|
|
public boolean isDenied(final UUID uuid) {
|
|
|
|
return (this.denied != null) && ((this.denied.contains(DBFunc.everyone) && !this.isAdded(uuid)) || (!this.isAdded(uuid) && this.denied.contains(uuid)));
|
2014-11-05 04:42:08 +01:00
|
|
|
}
|
2015-02-23 02:32:27 +01:00
|
|
|
|
2014-11-05 04:42:08 +01:00
|
|
|
/**
|
|
|
|
* Get the plot ID
|
|
|
|
*/
|
|
|
|
public PlotId getId() {
|
|
|
|
return this.id;
|
|
|
|
}
|
2015-02-23 02:32:27 +01:00
|
|
|
|
2014-11-05 04:42:08 +01:00
|
|
|
/**
|
|
|
|
* Get a clone of the plot
|
|
|
|
*
|
2015-03-13 08:02:48 +01:00
|
|
|
* @return Plot
|
2014-11-05 04:42:08 +01:00
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
public Object clone() throws CloneNotSupportedException {
|
2014-12-16 06:03:20 +01:00
|
|
|
final Plot p = (Plot) super.clone();
|
|
|
|
if (!p.equals(this) || (p != this)) {
|
2015-06-23 23:44:44 +02:00
|
|
|
return new Plot(this.id, this.owner, this.trusted, this.members, this.denied, this.settings.getAlias(), this.settings.getPosition(), this.settings.flags.values(), this.world, this.settings.getMerged());
|
2014-11-05 04:42:08 +01:00
|
|
|
}
|
2014-11-09 17:02:45 +01:00
|
|
|
return p;
|
2014-11-05 04:42:08 +01:00
|
|
|
}
|
2015-02-23 02:32:27 +01:00
|
|
|
|
2014-11-05 04:42:08 +01:00
|
|
|
/**
|
|
|
|
* Deny someone (use DBFunc.addDenied() as well)
|
|
|
|
*
|
|
|
|
* @param uuid
|
|
|
|
*/
|
|
|
|
public void addDenied(final UUID uuid) {
|
2015-07-04 08:37:33 +02:00
|
|
|
if (this.denied.add(uuid)) DBFunc.setDenied(this, uuid);
|
2014-11-05 04:42:08 +01:00
|
|
|
}
|
2015-02-23 02:32:27 +01:00
|
|
|
|
2014-11-05 04:42:08 +01:00
|
|
|
/**
|
|
|
|
* Add someone as a helper (use DBFunc as well)
|
|
|
|
*
|
|
|
|
* @param uuid
|
|
|
|
*/
|
2015-05-14 14:55:57 +02:00
|
|
|
public void addTrusted(final UUID uuid) {
|
2015-07-04 08:37:33 +02:00
|
|
|
if (this.trusted.add(uuid)) DBFunc.setTrusted(this, uuid);
|
2014-11-05 04:42:08 +01:00
|
|
|
}
|
2015-02-23 02:32:27 +01:00
|
|
|
|
2014-11-05 04:42:08 +01:00
|
|
|
/**
|
|
|
|
* Add someone as a trusted user (use DBFunc as well)
|
|
|
|
*
|
|
|
|
* @param uuid
|
|
|
|
*/
|
2015-05-14 14:55:57 +02:00
|
|
|
public void addMember(final UUID uuid) {
|
2015-07-04 08:37:33 +02:00
|
|
|
if (this.members.add(uuid)) DBFunc.setMember(this, uuid);
|
2014-11-05 04:42:08 +01:00
|
|
|
}
|
2015-07-04 08:37:33 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the plot owner
|
|
|
|
* @param owner
|
|
|
|
*/
|
|
|
|
public void setOwner(final UUID owner) {
|
|
|
|
if (!this.owner.equals(owner)) {
|
|
|
|
this.owner = owner;
|
|
|
|
DBFunc.setOwner(this, owner);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clear a plot
|
|
|
|
* @see MainUtil#clear(Plot, boolean, Runnable)
|
|
|
|
* @see MainUtil#clearAsPlayer(Plot, boolean, Runnable)
|
|
|
|
* @see #delete() to clear and delete a plot
|
|
|
|
* @param whenDone A runnable to execute when clearing finishes, or null
|
|
|
|
*/
|
|
|
|
public void clear(Runnable whenDone) {
|
|
|
|
MainUtil.clear(this, false, whenDone);
|
|
|
|
}
|
|
|
|
|
2015-07-17 12:48:13 +02:00
|
|
|
/**
|
|
|
|
* This will return null if the plot hasn't been analyzed
|
|
|
|
* @return analysis of plot
|
|
|
|
*/
|
|
|
|
public PlotAnalysis getComplexity() {
|
|
|
|
return PlotAnalysis.getAnalysis(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void analyze(RunnableVal<PlotAnalysis> whenDone) {
|
|
|
|
PlotAnalysis.analyzePlot(this, whenDone);
|
|
|
|
}
|
|
|
|
|
2015-07-04 08:37:33 +02:00
|
|
|
/**
|
|
|
|
* Delete a plot
|
|
|
|
* @see PS#removePlot(String, PlotId, boolean)
|
|
|
|
* @see #clear(Runnable) to simply clear a plot
|
|
|
|
*/
|
|
|
|
public void delete() {
|
|
|
|
MainUtil.removeSign(this);
|
|
|
|
MainUtil.clear(this, true, new Runnable() {
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
if (PS.get().removePlot(world, id, true)) {
|
|
|
|
DBFunc.delete(Plot.this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public void unclaim() {
|
|
|
|
if (PS.get().removePlot(world, id, true)) {
|
|
|
|
DBFunc.delete(Plot.this);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unlink a plot and remove the roads
|
|
|
|
* @see MainUtil#unlinkPlot(Plot)
|
|
|
|
* @return true if plot was linked
|
|
|
|
*/
|
|
|
|
public boolean unlink() {
|
|
|
|
return MainUtil.unlinkPlot(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the home location for the plot
|
|
|
|
* @see MainUtil#getPlotHome(Plot)
|
|
|
|
* @return Home location
|
|
|
|
*/
|
|
|
|
public Location getHome() {
|
|
|
|
return MainUtil.getPlotHome(this);
|
|
|
|
}
|
|
|
|
|
2015-07-10 05:17:32 +02: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
|
|
|
|
*/
|
|
|
|
public HashMap<UUID, Rating> getRatings() {
|
|
|
|
HashMap<UUID, Rating> map = new HashMap<UUID, Rating>();
|
|
|
|
for (Entry<UUID, Integer> entry : settings.ratings.entrySet()) {
|
|
|
|
map.put(entry.getKey(), new Rating(entry.getValue()));
|
|
|
|
}
|
|
|
|
return map;
|
|
|
|
}
|
|
|
|
|
2015-07-04 08:37:33 +02:00
|
|
|
/**
|
|
|
|
* Set the home location
|
|
|
|
* @param loc
|
|
|
|
*/
|
|
|
|
public void setHome(BlockLoc loc) {
|
|
|
|
BlockLoc pos = this.settings.getPosition();
|
|
|
|
if ((pos == null && loc == null) || (pos != null && pos.equals(loc))) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.settings.setPosition(loc);
|
|
|
|
if (this.settings.getPosition() == null) {
|
|
|
|
DBFunc.setPosition(this, "");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
DBFunc.setPosition(this, this.settings.getPosition().toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the plot alias
|
|
|
|
* @param alias
|
|
|
|
*/
|
|
|
|
public void setAlias(String alias) {
|
|
|
|
String name = this.settings.getAlias();
|
|
|
|
if (alias == null) {
|
|
|
|
alias = "";
|
|
|
|
}
|
|
|
|
if (name.equals(alias)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.settings.setAlias(alias);
|
|
|
|
DBFunc.setAlias(this, alias);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resend all chunks inside the plot to nearby players<br>
|
|
|
|
* This should not need to be called
|
|
|
|
* @see MainUtil#update(Plot)
|
|
|
|
*/
|
|
|
|
public void refreshChunks() {
|
|
|
|
MainUtil.update(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove the plot sign if it is set
|
|
|
|
*/
|
|
|
|
public void removeSign() {
|
|
|
|
MainUtil.removeSign(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the plot sign if plot signs are enabled
|
|
|
|
*/
|
|
|
|
public void setSign() {
|
|
|
|
MainUtil.setSign(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Register a plot and create it in the database<br>
|
|
|
|
* - The plot will not be created if the owner is null<br>
|
|
|
|
* - This will not save any trusted etc in the DB, those should be set after plot creation
|
|
|
|
* @return true if plot was created successfully
|
|
|
|
*/
|
|
|
|
public boolean create() {
|
|
|
|
return MainUtil.createPlot(owner, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Auto merge the plot with any adjacent plots of the same owner
|
|
|
|
* @see MainUtil#autoMerge(Plot, UUID) to specify the owner
|
|
|
|
*/
|
|
|
|
public void autoMerge() {
|
|
|
|
MainUtil.autoMerge(this, owner);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the plot biome
|
|
|
|
*/
|
|
|
|
public void setBiome(String biome) {
|
|
|
|
MainUtil.setBiome(this, biome);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the top location for the plot
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public Location getTop() {
|
|
|
|
return MainUtil.getPlotTopLoc(world, id);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the bottom location for the plot
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public Location getBottom() {
|
|
|
|
return MainUtil.getPlotBottomLoc(world, id);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the top plot, or this plot if it is not part of a mega plot
|
|
|
|
* @return The bottom plot
|
|
|
|
*/
|
|
|
|
public Plot getTopPlot() {
|
|
|
|
return MainUtil.getTopPlot(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the bottom plot, or this plot if it is not part of a mega plot
|
|
|
|
* @return The bottom plot
|
|
|
|
*/
|
|
|
|
public Plot getBottomPlot() {
|
|
|
|
return MainUtil.getBottomPlot(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
* @param other The other plot id to swap with
|
|
|
|
* @param whenDone A task to run when finished, or null
|
|
|
|
* @see MainUtil#swapData(String, PlotId, PlotId, Runnable)
|
|
|
|
* @return boolean if swap was successful
|
|
|
|
*/
|
|
|
|
public boolean swap(PlotId destination, Runnable whenDone) {
|
|
|
|
return MainUtil.swap(world, id, destination, whenDone);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
public boolean move(Plot destination, Runnable whenDone) {
|
|
|
|
return MainUtil.move(this, destination, whenDone);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
public boolean copy(PlotId destination, Runnable whenDone) {
|
|
|
|
return MainUtil.copy(world, id, destination, whenDone);
|
|
|
|
}
|
|
|
|
|
2014-11-05 04:42:08 +01:00
|
|
|
/**
|
|
|
|
* Get plot display name
|
|
|
|
*
|
|
|
|
* @return alias if set, else id
|
|
|
|
*/
|
2015-02-20 07:34:19 +01:00
|
|
|
@Override
|
2015-01-06 17:08:29 +01:00
|
|
|
public String toString() {
|
2014-11-05 04:42:08 +01:00
|
|
|
if (this.settings.getAlias().length() > 1) {
|
|
|
|
return this.settings.getAlias();
|
|
|
|
}
|
2015-01-06 17:08:29 +01:00
|
|
|
return this.world + ";" + this.getId().x + ";" + this.getId().y;
|
2014-11-05 04:42:08 +01:00
|
|
|
}
|
2015-02-23 02:32:27 +01:00
|
|
|
|
2014-11-05 04:42:08 +01:00
|
|
|
/**
|
|
|
|
* Remove a denied player (use DBFunc as well)
|
|
|
|
*
|
|
|
|
* @param uuid
|
|
|
|
*/
|
2015-07-04 08:37:33 +02:00
|
|
|
public boolean removeDenied(final UUID uuid) {
|
|
|
|
if (this.denied.remove(uuid)) {
|
|
|
|
DBFunc.removeDenied(this, uuid);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2014-11-05 04:42:08 +01:00
|
|
|
}
|
2015-02-23 02:32:27 +01:00
|
|
|
|
2014-11-05 04:42:08 +01:00
|
|
|
/**
|
|
|
|
* Remove a helper (use DBFunc as well)
|
|
|
|
*
|
|
|
|
* @param uuid
|
|
|
|
*/
|
2015-07-04 08:37:33 +02:00
|
|
|
public boolean removeTrusted(final UUID uuid) {
|
|
|
|
if (this.trusted.remove(uuid)) {
|
|
|
|
DBFunc.removeTrusted(this, uuid);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2014-11-05 04:42:08 +01:00
|
|
|
}
|
2015-02-23 02:32:27 +01:00
|
|
|
|
2014-11-05 04:42:08 +01:00
|
|
|
/**
|
|
|
|
* Remove a trusted user (use DBFunc as well)
|
|
|
|
*
|
|
|
|
* @param uuid
|
|
|
|
*/
|
2015-07-04 08:37:33 +02:00
|
|
|
public boolean removeMember(final UUID uuid) {
|
|
|
|
if (this.members.remove(uuid)) {
|
|
|
|
DBFunc.removeMember(this, uuid);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2014-11-05 04:42:08 +01:00
|
|
|
}
|
2015-06-24 05:31:13 +02:00
|
|
|
|
2014-11-11 03:23:45 +01:00
|
|
|
@Override
|
|
|
|
public boolean equals(final Object obj) {
|
|
|
|
if (this == obj) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (obj == null) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (getClass() != obj.getClass()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
final Plot other = (Plot) obj;
|
|
|
|
return ((this.id.x.equals(other.id.x)) && (this.id.y.equals(other.id.y)) && (this.world.equals(other.world)));
|
|
|
|
}
|
2015-02-23 02:32:27 +01:00
|
|
|
|
2015-04-27 11:07:42 +02:00
|
|
|
|
2014-11-06 09:37:46 +01:00
|
|
|
/**
|
|
|
|
* Get the plot hashcode
|
|
|
|
*
|
2015-03-13 08:26:08 +01:00
|
|
|
* @return integer. You can easily make this a character array <br> xI = c[0] x = c[1 -> xI...] yI = c[xI ... + 1] y
|
|
|
|
* = c[xI ... + 2 -> yI ...]
|
2014-11-06 09:37:46 +01:00
|
|
|
*/
|
2014-11-06 09:29:49 +01:00
|
|
|
@Override
|
|
|
|
public int hashCode() {
|
2015-04-27 11:07:42 +02:00
|
|
|
return this.id.hashCode();
|
2014-11-06 09:29:49 +01:00
|
|
|
}
|
2014-09-22 13:02:14 +02:00
|
|
|
}
|