mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-06-28 11:44:42 +02:00
restructure a couple things.
This commit is contained in:
@ -32,4 +32,9 @@ public class ChunkLoc {
|
||||
final ChunkLoc other = (ChunkLoc) obj;
|
||||
return ((x == other.x) && (z == other.z));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return x + "," + z;
|
||||
}
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ package com.intellectualcrafters.plot.object;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
@ -38,6 +39,7 @@ 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.object.comment.PlotComment;
|
||||
import com.intellectualcrafters.plot.util.BO3Handler;
|
||||
import com.intellectualcrafters.plot.util.BlockManager;
|
||||
import com.intellectualcrafters.plot.util.ChunkManager;
|
||||
@ -131,7 +133,8 @@ public class Plot {
|
||||
|
||||
/**
|
||||
* Constructor for a new plot<br>
|
||||
* (Only changes after plot.create() will be properly set in the database)
|
||||
* (Only changes after plot.create() will be properly set in the database)
|
||||
*
|
||||
* @see Plot#getPlot(String, PlotId) for existing plots
|
||||
* @see Plot#getPlot(Location) for existing plots
|
||||
*
|
||||
@ -143,6 +146,20 @@ public class Plot {
|
||||
this.world = world;
|
||||
this.id = id;
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -173,7 +190,7 @@ public class Plot {
|
||||
/**
|
||||
* 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)
|
||||
* Please note that some bulk plot management functions may still affect temporary plots (TODO: fix this)
|
||||
*
|
||||
* @see Plot#getPlot(String, PlotId) for existing plots
|
||||
*
|
||||
@ -190,7 +207,7 @@ public class Plot {
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor for a saved plots (Used by the database manager when plots are fetched)
|
||||
* Constructor for a saved plots (Used by the database manager when plots are fetched)
|
||||
*
|
||||
* @see Plot#getPlot(String, PlotId) for existing plots
|
||||
*
|
||||
@ -203,7 +220,7 @@ public class Plot {
|
||||
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, final long timestamp, final int temp) {
|
||||
this.id = id;
|
||||
this.world = world;
|
||||
this.world = world;
|
||||
this.owner = owner;
|
||||
settings = new PlotSettings();
|
||||
this.members = members;
|
||||
@ -354,20 +371,32 @@ public class Plot {
|
||||
public PlotId getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
/**
|
||||
* Get the plot world object for this plot<br>
|
||||
* - The generic PlotWorld object can be casted to it's respective class for more control
|
||||
* @return
|
||||
*/
|
||||
* @return PlotWorld
|
||||
*/
|
||||
public PlotWorld getWorld() {
|
||||
return PS.get().getPlotWorld(world);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the plot manager object for this plot<br>
|
||||
* - The generic PlotManager object can be casted to it's respective class for more control
|
||||
* @return PlotManager
|
||||
*/
|
||||
public PlotManager getManager() {
|
||||
return PS.get().getPlotManager(world);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get or create plot settings
|
||||
* @return PlotSettings
|
||||
* @deprecated use equivalent plot method;
|
||||
*/
|
||||
@Deprecated
|
||||
public PlotSettings getSettings() {
|
||||
public PlotSettings getSettings() {
|
||||
if (settings == null) {
|
||||
settings = new PlotSettings();
|
||||
}
|
||||
@ -377,10 +406,54 @@ public class Plot {
|
||||
/**
|
||||
* Returns true if the plot is not merged, or it is the base plot of multiple merged plots
|
||||
* @return
|
||||
*/
|
||||
*/
|
||||
public boolean isBasePlot() {
|
||||
if (settings == null || !isMerged()) {
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
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)) {
|
||||
return origin;
|
||||
}
|
||||
if (!isMerged()) {
|
||||
origin = this;
|
||||
return origin;
|
||||
}
|
||||
int min = Integer.MAX_VALUE;
|
||||
for (Plot plot : MainUtil.getConnectedPlots(this)) {
|
||||
if (plot.temp != -1) {
|
||||
if (plot.temp < min) {
|
||||
min = plot.temp;
|
||||
origin = plot;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (plot.hashCode() < min) {
|
||||
origin = plot;
|
||||
min = plot.hashCode();
|
||||
}
|
||||
}
|
||||
}
|
||||
for (Plot plot : MainUtil.getConnectedPlots(this)) {
|
||||
plot.origin = origin;
|
||||
}
|
||||
return origin;
|
||||
}
|
||||
@ -414,7 +487,25 @@ public class Plot {
|
||||
*/
|
||||
public boolean getMerged(final int direction) {
|
||||
if (settings == null) {
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
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;
|
||||
}
|
||||
@ -456,9 +547,7 @@ public class Plot {
|
||||
* Deny someone (updates database as well)
|
||||
*
|
||||
* @param uuid
|
||||
*/
|
||||
public void addDenied(final UUID uuid) {
|
||||
if (getDenied().add(uuid)) {
|
||||
*/
|
||||
public void addDenied(final UUID uuid) {
|
||||
PlotHandler.addDenied(this, uuid);
|
||||
}
|
||||
@ -467,9 +556,7 @@ public class Plot {
|
||||
* Add someone as a helper (updates database as well)
|
||||
*
|
||||
* @param uuid
|
||||
*/
|
||||
public void addTrusted(final UUID uuid) {
|
||||
if (getTrusted().add(uuid)) {
|
||||
*/
|
||||
public void addTrusted(final UUID uuid) {
|
||||
PlotHandler.addTrusted(this, uuid);
|
||||
}
|
||||
@ -478,9 +565,7 @@ public class Plot {
|
||||
* Add someone as a trusted user (updates database as well)
|
||||
*
|
||||
* @param uuid
|
||||
*/
|
||||
public void addMember(final UUID uuid) {
|
||||
if (getMembers().add(uuid)) {
|
||||
*/
|
||||
public void addMember(final UUID uuid) {
|
||||
PlotHandler.addMember(this, uuid);
|
||||
}
|
||||
@ -488,10 +573,7 @@ public class Plot {
|
||||
/**
|
||||
* Set the plot owner (and update the database)
|
||||
* @param owner
|
||||
*/
|
||||
public void setOwner(final UUID owner) {
|
||||
if (!this.owner.equals(owner)) {
|
||||
this.owner = owner;
|
||||
*/
|
||||
public void setOwner(final UUID owner) {
|
||||
PlotHandler.setOwner(this, owner);
|
||||
}
|
||||
@ -499,19 +581,7 @@ public class Plot {
|
||||
/**
|
||||
* Set the trusted users for this plot
|
||||
* @param uuids
|
||||
*/
|
||||
public void setTrusted(final Set<UUID> uuids) {
|
||||
if (uuids.size() == 0) {
|
||||
return;
|
||||
}
|
||||
if ((trusted != null) && (trusted.size() > 0)) {
|
||||
trusted.removeAll(uuids);
|
||||
for (final UUID uuid : trusted) {
|
||||
DBFunc.removeTrusted(this, uuid);
|
||||
}
|
||||
trusted.clear();
|
||||
}
|
||||
for (final UUID uuid : uuids) {
|
||||
*/
|
||||
public void setTrusted(final Set<UUID> uuids) {
|
||||
PlotHandler.setTrusted(this, uuids);
|
||||
}
|
||||
@ -519,19 +589,7 @@ public class Plot {
|
||||
/**
|
||||
* Set the members for this plot
|
||||
* @param uuids
|
||||
*/
|
||||
public void setMembers(final Set<UUID> uuids) {
|
||||
if (uuids.size() == 0) {
|
||||
return;
|
||||
}
|
||||
if ((members != null) && (members.size() > 0)) {
|
||||
members.removeAll(uuids);
|
||||
for (final UUID uuid : members) {
|
||||
DBFunc.removeMember(this, uuid);
|
||||
}
|
||||
members.clear();
|
||||
}
|
||||
for (final UUID uuid : uuids) {
|
||||
*/
|
||||
public void setMembers(final Set<UUID> uuids) {
|
||||
PlotHandler.setMembers(this, uuids);
|
||||
}
|
||||
@ -539,19 +597,7 @@ public class Plot {
|
||||
/**
|
||||
* Set the denied users for this plot
|
||||
* @param uuids
|
||||
*/
|
||||
public void setDenied(final Set<UUID> uuids) {
|
||||
if (uuids.size() == 0) {
|
||||
return;
|
||||
}
|
||||
if ((denied != null) && (denied.size() > 0)) {
|
||||
denied.removeAll(uuids);
|
||||
for (final UUID uuid : denied) {
|
||||
DBFunc.removeDenied(this, uuid);
|
||||
}
|
||||
denied.clear();
|
||||
}
|
||||
for (final UUID uuid : uuids) {
|
||||
*/
|
||||
public void setDenied(final Set<UUID> uuids) {
|
||||
PlotHandler.setDenied(this, uuids);
|
||||
}
|
||||
@ -586,6 +632,15 @@ public class Plot {
|
||||
*/
|
||||
public void setFlag(final String flag, final Object value) {
|
||||
FlagManager.addPlotFlag(this, new Flag(FlagManager.getFlag(flag), value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a flag for this plot
|
||||
* @param flag
|
||||
* @param value
|
||||
*/
|
||||
public void setFlags(Set<Flag> flags) {
|
||||
FlagManager.setPlotFlags(this, flags);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -607,25 +662,45 @@ public class Plot {
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public void deletePlot(final Runnable whenDone) {
|
||||
MainUtil.removeSign(this);
|
||||
MainUtil.clear(this, true, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (PS.get().removePlot(world, id, true)) {
|
||||
DBFunc.delete(Plot.this);
|
||||
* @see #clear(Runnable) to simply clear a plot
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
public boolean unclaim() {
|
||||
if (PS.get().removePlot(world, id, true)) {
|
||||
DBFunc.delete(Plot.this);
|
||||
return true;
|
||||
|
||||
public boolean unclaim() {
|
||||
return PlotHandler.unclaim(this);
|
||||
}
|
||||
@ -634,7 +709,7 @@ public class Plot {
|
||||
* Unlink a plot and remove the roads
|
||||
* @see MainUtil#unlinkPlot(Plot, boolean removeRoad)
|
||||
* @return true if plot was linked
|
||||
*/
|
||||
*/
|
||||
public boolean unlink() {
|
||||
return MainUtil.unlinkPlot(this, true, true);
|
||||
}
|
||||
@ -681,7 +756,7 @@ public class Plot {
|
||||
* Set the home location
|
||||
* @param loc
|
||||
*/
|
||||
public void setHome(final BlockLoc loc) {
|
||||
public void setHome(final BlockLoc loc) {
|
||||
final BlockLoc pos = getSettings().getPosition();
|
||||
if (((pos == null || pos.equals(new BlockLoc(0, 0, 0))) && (loc == null)) || ((pos != null) && pos.equals(loc))) {
|
||||
return;
|
||||
@ -746,8 +821,8 @@ public class Plot {
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
* @param removeRoads If to remove roads when merging
|
||||
*/
|
||||
public boolean autoMerge(final boolean removeRoads) {
|
||||
return MainUtil.autoMerge(this, -1, Integer.MAX_VALUE, owner, removeRoads);
|
||||
}
|
||||
@ -761,23 +836,27 @@ public class Plot {
|
||||
|
||||
/**
|
||||
* Set components such as border, wall, floor
|
||||
* (components are generator specific)
|
||||
*/
|
||||
* (components are generator specific)
|
||||
*/
|
||||
public boolean setComponent(final String component, final PlotBlock... blocks) {
|
||||
return MainUtil.setComponent(this, component, blocks);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set components such as border, wall, floor
|
||||
* (components are generator specific)
|
||||
*/
|
||||
* (components are generator specific)
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the biome (String)
|
||||
*/
|
||||
*/
|
||||
public String getBiome() {
|
||||
final Location loc = getBottomAbs();
|
||||
return BlockManager.manager.getBiome(loc.getWorld(), loc.getX(), loc.getZ());
|
||||
@ -785,32 +864,68 @@ public class Plot {
|
||||
|
||||
/**
|
||||
* Return the top location for the plot
|
||||
* @return
|
||||
*/
|
||||
* @return
|
||||
*/
|
||||
public Location getTopAbs() {
|
||||
return MainUtil.getPlotTopLocAbs(world, id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the bottom location for the plot
|
||||
* @return
|
||||
*/
|
||||
public Location getBottomAbs() {
|
||||
return MainUtil.getPlotBottomLocAbs(world, id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the top and bottom connected plot.<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 PlotId[] { bottom, top }
|
||||
* @see MainUtil#getCornerIds(Plot)
|
||||
*/
|
||||
@Deprecated
|
||||
public Location[] getCorners() {
|
||||
return MainUtil.getCorners(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated in favor of getCorners()[0];
|
||||
* @return
|
||||
*/
|
||||
*/
|
||||
@Deprecated
|
||||
public Location getBottom() {
|
||||
return getCorners()[0];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
/**
|
||||
* @deprecated in favor of getCorners()[1];
|
||||
* @return The bottom plot
|
||||
*/
|
||||
* @return
|
||||
*/
|
||||
@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 The bottom plot
|
||||
*/
|
||||
* @return
|
||||
*/
|
||||
public Set<Plot> getConnectedPlots() {
|
||||
return MainUtil.getConnectedPlots(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* This will combine each plot into effective rectangular regions
|
||||
* - This result is cached globally
|
||||
* @see MainUtil#getRegions(Plot)
|
||||
* @return
|
||||
*/
|
||||
public Set<RegionWrapper> getRegions() {
|
||||
return MainUtil.getRegions(this);
|
||||
}
|
||||
@ -819,13 +934,13 @@ public class Plot {
|
||||
* 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#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 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
|
||||
*/
|
||||
* @return boolean if swap was successful
|
||||
*/
|
||||
public boolean swap(final Plot destination, final Runnable whenDone) {
|
||||
return MainUtil.move(this, destination, whenDone, true);
|
||||
}
|
||||
@ -836,7 +951,7 @@ public class Plot {
|
||||
* @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(final Plot destination, final Runnable whenDone) {
|
||||
return MainUtil.move(this, destination, whenDone, false);
|
||||
}
|
||||
@ -846,8 +961,8 @@ public class Plot {
|
||||
* - 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
|
||||
*/
|
||||
* @return If the copy was successful
|
||||
*/
|
||||
public boolean copy(final Plot destination, final Runnable whenDone) {
|
||||
return MainUtil.copy(this, destination, whenDone);
|
||||
}
|
||||
@ -996,4 +1111,56 @@ public class Plot {
|
||||
*/
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return id.hashCode();
|
||||
}
|
||||
|
||||
public HashMap<String, Flag> getFlags() {
|
||||
if (settings == null) {
|
||||
return new HashMap<>(0);
|
||||
}
|
||||
return settings.flags;
|
||||
}
|
||||
|
||||
public String getAlias() {
|
||||
return getSettings().getAlias();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the raw merge data<br>
|
||||
* - Updates DB
|
||||
* - Does not modify terrain
|
||||
* @param merged
|
||||
*/
|
||||
public void setMerged(boolean[] merged) {
|
||||
getSettings().merged = merged;
|
||||
DBFunc.setMerged(this, merged);
|
||||
MainUtil.connected_cache = null;
|
||||
MainUtil.regions_cache = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the raw merge data<br>
|
||||
* - Updates DB
|
||||
* - Does not modify terrain
|
||||
* @param merged
|
||||
*/
|
||||
public void setMerged(int direction, boolean value) {
|
||||
if (getSettings().setMerged(direction, value)) {
|
||||
DBFunc.setMerged(this, getSettings().getMerged());
|
||||
MainUtil.connected_cache = null;
|
||||
MainUtil.regions_cache = null;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean[] getMerged() {
|
||||
if (settings == null) {
|
||||
return new boolean[] {false, false, false, false };
|
||||
}
|
||||
return settings.getMerged();
|
||||
}
|
||||
|
||||
public BlockLoc getPosition() {
|
||||
if (settings == null) {
|
||||
return new BlockLoc(0, 0, 0);
|
||||
}
|
||||
return settings.getPosition();
|
||||
|
@ -35,7 +35,7 @@ public class PlotCluster {
|
||||
this.pos1 = pos1;
|
||||
this.pos2 = pos2;
|
||||
this.owner = owner;
|
||||
settings = new PlotSettings(null);
|
||||
settings = new PlotSettings();
|
||||
}
|
||||
|
||||
public boolean isAdded(final UUID uuid) {
|
||||
|
@ -3,8 +3,10 @@ package com.intellectualcrafters.plot.object;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.intellectualcrafters.plot.PS;
|
||||
import com.intellectualcrafters.plot.database.DBFunc;
|
||||
import com.intellectualcrafters.plot.util.MainUtil;
|
||||
import com.intellectualcrafters.plot.util.UUIDHandler;
|
||||
@ -15,13 +17,14 @@ public class PlotHandler {
|
||||
return new HashSet<UUID>();
|
||||
}
|
||||
if (plot.isMerged()) {
|
||||
final HashSet<UUID> owners = new HashSet<UUID>();
|
||||
final Plot top = MainUtil.getTopPlot(plot);
|
||||
final ArrayList<PlotId> ids = MainUtil.getPlotSelectionIds(plot.id, top.id);
|
||||
for (final PlotId id : ids) {
|
||||
final UUID owner = MainUtil.getPlot(plot.world, id).owner;
|
||||
if (owner != null) {
|
||||
owners.add(owner);
|
||||
HashSet<Plot> plots = MainUtil.getConnectedPlots(plot);
|
||||
final HashSet<UUID> owners = new HashSet<UUID>(2);
|
||||
UUID last = plot.owner;
|
||||
owners.add(plot.owner);
|
||||
for (Plot current : plots) {
|
||||
if (last == null || current.owner.getMostSignificantBits() != last.getMostSignificantBits()) {
|
||||
owners.add(current.owner);
|
||||
last = current.owner;
|
||||
}
|
||||
}
|
||||
return owners;
|
||||
@ -33,37 +36,49 @@ public class PlotHandler {
|
||||
if (plot.owner == null) {
|
||||
return false;
|
||||
}
|
||||
if (plot.isMerged()) {
|
||||
final Plot top = MainUtil.getTopPlot(plot);
|
||||
final ArrayList<PlotId> ids = MainUtil.getPlotSelectionIds(plot.id, top.id);
|
||||
for (final PlotId id : ids) {
|
||||
final UUID owner = MainUtil.getPlot(plot.world, id).owner;
|
||||
if ((owner != null) && owner.equals(uuid)) {
|
||||
return true;
|
||||
}
|
||||
if (plot.owner.equals(uuid)) {
|
||||
return true;
|
||||
}
|
||||
if (!plot.isMerged()) {
|
||||
return false;
|
||||
}
|
||||
for (Plot current : MainUtil.getConnectedPlots(plot)) {
|
||||
if (current.owner.equals(uuid)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return plot.owner.equals(uuid);
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isOnline(final Plot plot) {
|
||||
if (plot.owner == null) {
|
||||
return false;
|
||||
}
|
||||
if (plot.isMerged()) {
|
||||
final Plot top = MainUtil.getTopPlot(plot);
|
||||
final ArrayList<PlotId> ids = MainUtil.getPlotSelectionIds(plot.id, top.id);
|
||||
for (final PlotId id : ids) {
|
||||
final UUID owner = MainUtil.getPlot(plot.world, id).owner;
|
||||
if (owner != null) {
|
||||
if (UUIDHandler.getPlayer(owner) != null) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
if (!plot.isMerged()) {
|
||||
return UUIDHandler.getPlayer(plot.owner) != null;
|
||||
}
|
||||
for (Plot current : MainUtil.getConnectedPlots(plot)) {
|
||||
if (current.owner != null && UUIDHandler.getPlayer(current.owner) != null) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void setOwner(Plot plot, UUID owner) {
|
||||
if (!plot.isMerged()) {
|
||||
if (!plot.owner.equals(owner)) {
|
||||
plot.owner = owner;
|
||||
DBFunc.setOwner(plot, owner);
|
||||
}
|
||||
return;
|
||||
}
|
||||
for (Plot current : MainUtil.getConnectedPlots(plot)) {
|
||||
if (!owner.equals(current.owner)) {
|
||||
current.owner = owner;
|
||||
DBFunc.setOwner(current, owner);
|
||||
}
|
||||
}
|
||||
return UUIDHandler.getPlayer(plot.owner) != null;
|
||||
}
|
||||
|
||||
public static boolean sameOwners(final Plot plot1, final Plot plot2) {
|
||||
@ -79,30 +94,116 @@ public class PlotHandler {
|
||||
if (plot.owner == null) {
|
||||
return false;
|
||||
}
|
||||
if (isOwner(plot, uuid)) {
|
||||
return true;
|
||||
}
|
||||
if (plot.getDenied().contains(uuid)) {
|
||||
return false;
|
||||
}
|
||||
if (plot.getTrusted().contains(uuid) || plot.getTrusted().contains(DBFunc.everyone)) {
|
||||
return true;
|
||||
}
|
||||
if (isOwner(plot, uuid)) {
|
||||
return true;
|
||||
}
|
||||
if (plot.getMembers().contains(uuid) || plot.getMembers().contains(DBFunc.everyone)) {
|
||||
if (PlotHandler.isOnline(plot)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (plot.isMerged()) {
|
||||
final Plot top = MainUtil.getTopPlot(plot);
|
||||
final ArrayList<PlotId> ids = MainUtil.getPlotSelectionIds(plot.id, top.id);
|
||||
for (final PlotId id : ids) {
|
||||
final UUID owner = MainUtil.getPlot(plot.world, id).owner;
|
||||
if ((owner != null) && owner.equals(uuid)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void setDenied(Plot plot, Set<UUID> uuids) {
|
||||
boolean larger = uuids.size() > plot.getDenied().size();
|
||||
HashSet<UUID> intersection = new HashSet<>(larger ? plot.getDenied() : uuids);
|
||||
intersection.retainAll(larger ? uuids : plot.getDenied());
|
||||
uuids.removeAll(intersection);
|
||||
HashSet<UUID> toRemove = new HashSet<>(plot.getDenied());
|
||||
toRemove.removeAll(intersection);
|
||||
for (UUID uuid : toRemove) {
|
||||
plot.removeDenied(uuid);
|
||||
}
|
||||
for (UUID uuid : uuids) {
|
||||
plot.addDenied(uuid);
|
||||
}
|
||||
}
|
||||
|
||||
public static void setTrusted(Plot plot, Set<UUID> uuids) {
|
||||
boolean larger = uuids.size() > plot.getTrusted().size();
|
||||
HashSet<UUID> intersection = new HashSet<>(larger ? plot.getTrusted() : uuids);
|
||||
intersection.retainAll(larger ? uuids : plot.getTrusted());
|
||||
uuids.removeAll(intersection);
|
||||
HashSet<UUID> toRemove = new HashSet<>(plot.getTrusted());
|
||||
toRemove.removeAll(intersection);
|
||||
for (UUID uuid : toRemove) {
|
||||
plot.removeTrusted(uuid);
|
||||
}
|
||||
for (UUID uuid : uuids) {
|
||||
plot.addTrusted(uuid);
|
||||
}
|
||||
}
|
||||
|
||||
public static void setMembers(Plot plot, Set<UUID> uuids) {
|
||||
boolean larger = uuids.size() > plot.getMembers().size();
|
||||
HashSet<UUID> intersection = new HashSet<>(larger ? plot.getMembers() : uuids);
|
||||
intersection.retainAll(larger ? uuids : plot.getMembers());
|
||||
uuids.removeAll(intersection);
|
||||
HashSet<UUID> toRemove = new HashSet<>(plot.getMembers());
|
||||
toRemove.removeAll(intersection);
|
||||
for (UUID uuid : toRemove) {
|
||||
plot.removeMember(uuid);
|
||||
}
|
||||
for (UUID uuid : uuids) {
|
||||
plot.addMember(uuid);
|
||||
}
|
||||
}
|
||||
|
||||
public static void set(Plot plot, Set<UUID> uuids) {
|
||||
boolean larger = uuids.size() > plot.getDenied().size();
|
||||
HashSet<UUID> intersection = new HashSet<>(larger ? plot.getDenied() : uuids);
|
||||
intersection.retainAll(larger ? uuids : plot.getDenied());
|
||||
uuids.removeAll(intersection);
|
||||
HashSet<UUID> toRemove = new HashSet<>(plot.getDenied());
|
||||
toRemove.removeAll(intersection);
|
||||
for (UUID uuid : toRemove) {
|
||||
plot.removeDenied(uuid);
|
||||
}
|
||||
for (UUID uuid : uuids) {
|
||||
plot.addDenied(uuid);
|
||||
}
|
||||
}
|
||||
|
||||
public static void addDenied(Plot plot, UUID uuid) {
|
||||
for (Plot current : MainUtil.getConnectedPlots(plot)) {
|
||||
if (current.getDenied().add(uuid)) {
|
||||
DBFunc.setDenied(current, uuid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void addMember(Plot plot, UUID uuid) {
|
||||
for (Plot current : MainUtil.getConnectedPlots(plot)) {
|
||||
if (current.getMembers().add(uuid)) {
|
||||
DBFunc.setMember(current, uuid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void addTrusted(Plot plot, UUID uuid) {
|
||||
for (Plot current : MainUtil.getConnectedPlots(plot)) {
|
||||
if (current.getTrusted().add(uuid)) {
|
||||
DBFunc.setTrusted(current, uuid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean unclaim(Plot plot) {
|
||||
if (plot.owner == null) {
|
||||
return false;
|
||||
}
|
||||
for (Plot current : MainUtil.getConnectedPlots(plot)) {
|
||||
current.settings = null;
|
||||
PS.get().removePlot(current.world, current.id, true);
|
||||
DBFunc.delete(current);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -33,24 +33,19 @@ import com.intellectualcrafters.plot.object.comment.PlotComment;
|
||||
* plot settings
|
||||
*
|
||||
|
||||
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public class PlotSettings {
|
||||
/**
|
||||
* Plot
|
||||
*/
|
||||
public class PlotSettings {
|
||||
/**
|
||||
* merged plots
|
||||
* merged plots
|
||||
*/
|
||||
public boolean[] merged = new boolean[] { false, false, false, false };
|
||||
/**
|
||||
* plot alias
|
||||
* plot alias
|
||||
*/
|
||||
public String alias = "";
|
||||
/**
|
||||
* Comments
|
||||
* Comments
|
||||
*/
|
||||
public List<PlotComment> comments = null;
|
||||
|
||||
@ -71,9 +66,7 @@ public class PlotSettings {
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param plot object
|
||||
*/
|
||||
public PlotSettings(final Plot plot) {
|
||||
* @param plot object
|
||||
*/
|
||||
public PlotSettings() {
|
||||
flags = new HashMap<>();
|
||||
@ -103,8 +96,12 @@ public class PlotSettings {
|
||||
|
||||
public void setMerged(final boolean[] merged) {
|
||||
this.merged = merged;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public boolean setMerged(final int direction, final boolean merged) {
|
||||
if (this.merged[direction] != merged) {
|
||||
this.merged[direction] = merged;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -131,8 +128,8 @@ public class PlotSettings {
|
||||
*/
|
||||
public void setAlias(final String alias) {
|
||||
this.alias = alias;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public String getJoinMessage(String world) {
|
||||
final Flag greeting = FlagManager.getSettingFlag(world, this, "greeting");
|
||||
if (greeting != null) {
|
||||
@ -144,8 +141,8 @@ public class PlotSettings {
|
||||
/**
|
||||
* Get the "farewell" flag value
|
||||
*
|
||||
* @return Farewell flag
|
||||
*/
|
||||
* @return Farewell flag
|
||||
*/
|
||||
public String getLeaveMessage(String world) {
|
||||
final Flag farewell = FlagManager.getSettingFlag(world, this, "farewell");
|
||||
if (farewell != null) {
|
||||
|
@ -63,80 +63,7 @@ public abstract class PlotWorld {
|
||||
public final static int MAX_BUILD_HEIGHT_DEFAULT = 256;
|
||||
public final static int MIN_BUILD_HEIGHT_DEFAULT = 1;
|
||||
public final static PlotGamemode GAMEMODE_DEFAULT = PlotGamemode.CREATIVE;
|
||||
// are plot clusters enabled
|
||||
// require claim in cluster
|
||||
// TODO make this configurable
|
||||
// make non static and static_default_valu + add config option
|
||||
public static int[] BLOCKS;
|
||||
static {
|
||||
BLOCKS = new int[] {
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
4,
|
||||
5,
|
||||
7,
|
||||
14,
|
||||
15,
|
||||
16,
|
||||
17,
|
||||
19,
|
||||
21,
|
||||
22,
|
||||
23,
|
||||
24,
|
||||
25,
|
||||
35,
|
||||
41,
|
||||
42,
|
||||
43,
|
||||
45,
|
||||
47,
|
||||
48,
|
||||
49,
|
||||
52,
|
||||
56,
|
||||
57,
|
||||
58,
|
||||
61,
|
||||
62,
|
||||
73,
|
||||
74,
|
||||
80,
|
||||
82,
|
||||
84,
|
||||
86,
|
||||
87,
|
||||
88,
|
||||
91,
|
||||
97,
|
||||
98,
|
||||
99,
|
||||
100,
|
||||
103,
|
||||
110,
|
||||
112,
|
||||
120,
|
||||
121,
|
||||
123,
|
||||
124,
|
||||
125,
|
||||
129,
|
||||
133,
|
||||
153,
|
||||
155,
|
||||
159,
|
||||
162,
|
||||
165,
|
||||
166,
|
||||
168,
|
||||
170,
|
||||
172,
|
||||
173,
|
||||
174,
|
||||
179,
|
||||
181 };
|
||||
}
|
||||
|
||||
public final String worldname;
|
||||
public int MAX_PLOT_MEMBERS;
|
||||
public boolean AUTO_MERGE;
|
||||
@ -183,6 +110,9 @@ public abstract class PlotWorld {
|
||||
return false;
|
||||
}
|
||||
final PlotWorld plotworld = (PlotWorld) obj;
|
||||
if (this.worldname.equals(plotworld.worldname)) {
|
||||
return true;
|
||||
}
|
||||
final ConfigurationSection section = PS.get().config.getConfigurationSection("worlds");
|
||||
for (final ConfigurationNode setting : plotworld.getSettingNodes()) {
|
||||
final Object constant = section.get(plotworld.worldname + "." + setting.getConstant());
|
||||
|
@ -39,7 +39,7 @@ public class Rating {
|
||||
|
||||
public List<String> getCategories() {
|
||||
if (ratingMap.size() == 1) {
|
||||
return new ArrayList<>();
|
||||
return new ArrayList<>(0);
|
||||
}
|
||||
return new ArrayList<>(ratingMap.keySet());
|
||||
}
|
||||
|
@ -33,4 +33,29 @@ public class RegionWrapper {
|
||||
public boolean isIn(final int x, final int z) {
|
||||
return ((x >= minX) && (x <= maxX) && (z >= minZ) && (z <= maxZ));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return minX + 13 * maxX + 23 * minZ + 39 * maxZ;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (obj == this) {
|
||||
return true;
|
||||
}
|
||||
if (obj instanceof RegionWrapper) {
|
||||
RegionWrapper other = (RegionWrapper) obj;
|
||||
return minX == other.minX && minZ == other.minZ && minY == other.minY && maxX == other.maxX && maxZ == other.maxZ && maxY == other.maxY;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return minX + "->" + maxX + "," + minZ + "->" + maxZ;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user