Remove all direct access to Plot.owner

New methods were added for access to the absolute owner of a plot, and the documentation of the owner getters to clarify the purpose of the methods.
This commit is contained in:
Alexander Söderberg 2020-04-10 14:05:01 +02:00
parent 0d26111fa7
commit ce756411cf
14 changed files with 125 additions and 85 deletions

View File

@ -231,9 +231,9 @@ import java.util.UUID;
MainUtil.sendMessage(player, "&7 - Updating plot objects"); MainUtil.sendMessage(player, "&7 - Updating plot objects");
for (Plot plot : PlotSquared.get().getPlots()) { for (Plot plot : PlotSquared.get().getPlots()) {
UUID value = uCMap.get(plot.owner); UUID value = uCMap.get(plot.getOwnerAbs());
if (value != null) { if (value != null) {
plot.owner = value; plot.setOwnerAbs(value);
} }
plot.getTrusted().clear(); plot.getTrusted().clear();
plot.getMembers().clear(); plot.getMembers().clear();
@ -250,9 +250,9 @@ import java.util.UUID;
if (!result) { if (!result) {
MainUtil.sendMessage(player, "&cConversion failed! Attempting recovery"); MainUtil.sendMessage(player, "&cConversion failed! Attempting recovery");
for (Plot plot : PlotSquared.get().getPlots()) { for (Plot plot : PlotSquared.get().getPlots()) {
UUID value = uCReverse.get(plot.owner); UUID value = uCReverse.get(plot.getOwnerAbs());
if (value != null) { if (value != null) {
plot.owner = value; plot.setOwnerAbs(value);
} }
} }
DBFunc.createPlotsAndData(new ArrayList<>(PlotSquared.get().getPlots()), DBFunc.createPlotsAndData(new ArrayList<>(PlotSquared.get().getPlots()),

View File

@ -347,8 +347,8 @@ import java.util.zip.ZipInputStream;
UUIDHandler.add(new StringWrapper("*"), DBFunc.EVERYONE); UUIDHandler.add(new StringWrapper("*"), DBFunc.EVERYONE);
forEachPlotRaw(plot -> { forEachPlotRaw(plot -> {
if (plot.hasOwner() && plot.temp != -1) { if (plot.hasOwner() && plot.temp != -1) {
if (UUIDHandler.getName(plot.owner) == null) { if (UUIDHandler.getName(plot.getOwnerAbs()) == null) {
UUIDHandler.implementation.unknown.add(plot.owner); UUIDHandler.implementation.unknown.add(plot.getOwnerAbs());
} }
} }
}); });
@ -736,7 +736,7 @@ import java.util.zip.ZipInputStream;
} else { } else {
list = new ArrayList<>(input); list = new ArrayList<>(input);
} }
list.sort(Comparator.comparingLong(a -> ExpireManager.IMP.getTimestamp(a.owner))); list.sort(Comparator.comparingLong(a -> ExpireManager.IMP.getTimestamp(a.getOwnerAbs())));
return list; return list;
} }

View File

@ -138,7 +138,7 @@ public class Auto extends SubCommand {
return; return;
} }
whenDone.value = plot; whenDone.value = plot;
plot.owner = player.getUUID(); plot.setOwnerAbs(player.getUUID());
DBFunc.createPlotSafe(plot, whenDone, DBFunc.createPlotSafe(plot, whenDone,
() -> autoClaimFromDatabase(player, area, plot.getId(), whenDone)); () -> autoClaimFromDatabase(player, area, plot.getId(), whenDone));
} }

View File

@ -59,8 +59,8 @@ public class Buy extends Command {
confirm.run(this, () -> { confirm.run(this, () -> {
Captions.REMOVED_BALANCE.send(player, price); Captions.REMOVED_BALANCE.send(player, price);
EconHandler.manager EconHandler.manager
.depositMoney(UUIDHandler.getUUIDWrapper().getOfflinePlayer(plot.owner), price); .depositMoney(UUIDHandler.getUUIDWrapper().getOfflinePlayer(plot.getOwnerAbs()), price);
PlotPlayer owner = UUIDHandler.getPlayer(plot.owner); PlotPlayer owner = UUIDHandler.getPlayer(plot.getOwnerAbs());
if (owner != null) { if (owner != null) {
Captions.PLOT_SOLD.send(owner, plot.getId(), player.getName(), price); Captions.PLOT_SOLD.send(owner, plot.getId(), player.getName(), price);
} }

View File

@ -97,7 +97,7 @@ public class Claim extends SubCommand {
if (border != Integer.MAX_VALUE && plot.getDistanceFromOrigin() > border && !force) { if (border != Integer.MAX_VALUE && plot.getDistanceFromOrigin() > border && !force) {
return !sendMessage(player, Captions.BORDER); return !sendMessage(player, Captions.BORDER);
} }
plot.owner = player.getUUID(); plot.setOwnerAbs(player.getUUID());
final String finalSchematic = schematic; final String finalSchematic = schematic;
DBFunc.createPlotSafe(plot, () -> TaskManager.IMP.sync(new RunnableVal<Object>() { DBFunc.createPlotSafe(plot, () -> TaskManager.IMP.sync(new RunnableVal<Object>() {
@Override public void run(Object value) { @Override public void run(Object value) {
@ -105,7 +105,7 @@ public class Claim extends SubCommand {
PlotSquared.get().getLogger().log(Captions.PREFIX.getTranslated() + PlotSquared.get().getLogger().log(Captions.PREFIX.getTranslated() +
String.format("Failed to claim plot %s", plot.getId().toCommaSeparatedString())); String.format("Failed to claim plot %s", plot.getId().toCommaSeparatedString()));
sendMessage(player, Captions.PLOT_NOT_CLAIMED); sendMessage(player, Captions.PLOT_NOT_CLAIMED);
plot.owner = null; plot.setOwnerAbs(null);
} else if (area.isAutoMerge()) { } else if (area.isAutoMerge()) {
PlotMergeEvent event = PlotSquared.get().getEventDispatcher() PlotMergeEvent event = PlotSquared.get().getEventDispatcher()
.callMerge(plot, Direction.ALL, Integer.MAX_VALUE, player); .callMerge(plot, Direction.ALL, Integer.MAX_VALUE, player);
@ -120,7 +120,7 @@ public class Claim extends SubCommand {
PlotSquared.get().getLogger().log(Captions.PREFIX.getTranslated() + PlotSquared.get().getLogger().log(Captions.PREFIX.getTranslated() +
String.format("Failed to add plot %s to the database", plot.getId().toCommaSeparatedString())); String.format("Failed to add plot %s to the database", plot.getId().toCommaSeparatedString()));
sendMessage(player, Captions.PLOT_NOT_CLAIMED); sendMessage(player, Captions.PLOT_NOT_CLAIMED);
plot.owner = null; plot.setOwnerAbs(null);
}); });
return true; return true;
} }

View File

@ -49,7 +49,7 @@ public class Owner extends SetCommand {
uuid = null; uuid = null;
} }
PlotChangeOwnerEvent event = PlotSquared.get().getEventDispatcher() PlotChangeOwnerEvent event = PlotSquared.get().getEventDispatcher()
.callOwnerChange(player, plot, plot.hasOwner() ? plot.owner : null, uuid, .callOwnerChange(player, plot, plot.hasOwner() ? plot.getOwnerAbs() : null, uuid,
plot.hasOwner()); plot.hasOwner());
if (event.getEventResult() == Result.DENY) { if (event.getEventResult() == Result.DENY) {
sendMessage(player, Captions.EVENT_DENIED, "Owner change"); sendMessage(player, Captions.EVENT_DENIED, "Owner change");

View File

@ -121,7 +121,7 @@ public class Purge extends SubCommand {
if (added != null && !plot.isAdded(added)) { if (added != null && !plot.isAdded(added)) {
continue; continue;
} }
if (unknown && UUIDHandler.getName(plot.owner) != null) { if (unknown && UUIDHandler.getName(plot.getOwnerAbs()) != null) {
continue; continue;
} }
toDelete.addAll(plot.getConnectedPlots()); toDelete.addAll(plot.getConnectedPlots());
@ -144,7 +144,7 @@ public class Purge extends SubCommand {
if (added != null && !plot.isAdded(added)) { if (added != null && !plot.isAdded(added)) {
continue; continue;
} }
if (unknown && UUIDHandler.getName(plot.owner) != null) { if (unknown && UUIDHandler.getName(plot.getOwnerAbs()) != null) {
continue; continue;
} }
toDelete.add(plot); toDelete.add(plot);

View File

@ -718,7 +718,7 @@ import java.util.concurrent.atomic.AtomicInteger;
stmt.setInt(i * 5 + 1, plot.getId().x); stmt.setInt(i * 5 + 1, plot.getId().x);
stmt.setInt(i * 5 + 2, plot.getId().y); stmt.setInt(i * 5 + 2, plot.getId().y);
try { try {
stmt.setString(i * 5 + 3, plot.owner.toString()); stmt.setString(i * 5 + 3, plot.getOwnerAbs().toString());
} catch (SQLException ignored) { } catch (SQLException ignored) {
stmt.setString(i * 5 + 3, everyone.toString()); stmt.setString(i * 5 + 3, everyone.toString());
} }
@ -732,7 +732,7 @@ import java.util.concurrent.atomic.AtomicInteger;
stmt.setInt(i * 6 + 2, plot.getId().x); stmt.setInt(i * 6 + 2, plot.getId().x);
stmt.setInt(i * 6 + 3, plot.getId().y); stmt.setInt(i * 6 + 3, plot.getId().y);
try { try {
stmt.setString(i * 6 + 4, plot.owner.toString()); stmt.setString(i * 6 + 4, plot.getOwnerAbs().toString());
} catch (SQLException ignored) { } catch (SQLException ignored) {
stmt.setString(i * 6 + 4, everyone.toString()); stmt.setString(i * 6 + 4, everyone.toString());
} }
@ -743,7 +743,7 @@ import java.util.concurrent.atomic.AtomicInteger;
@Override public void setSQL(PreparedStatement stmt, Plot plot) throws SQLException { @Override public void setSQL(PreparedStatement stmt, Plot plot) throws SQLException {
stmt.setInt(1, plot.getId().x); stmt.setInt(1, plot.getId().x);
stmt.setInt(2, plot.getId().y); stmt.setInt(2, plot.getId().y);
stmt.setString(3, plot.owner.toString()); stmt.setString(3, plot.getOwnerAbs().toString());
stmt.setString(4, plot.getArea().toString()); stmt.setString(4, plot.getArea().toString());
stmt.setTimestamp(5, new Timestamp(plot.getTimestamp())); stmt.setTimestamp(5, new Timestamp(plot.getTimestamp()));
@ -982,7 +982,7 @@ import java.util.concurrent.atomic.AtomicInteger;
@Override public void set(PreparedStatement statement) throws SQLException { @Override public void set(PreparedStatement statement) throws SQLException {
statement.setInt(1, plot.getId().x); statement.setInt(1, plot.getId().x);
statement.setInt(2, plot.getId().y); statement.setInt(2, plot.getId().y);
statement.setString(3, plot.owner.toString()); statement.setString(3, plot.getOwnerAbs().toString());
statement.setString(4, plot.getArea().toString()); statement.setString(4, plot.getArea().toString());
statement.setTimestamp(5, new Timestamp(plot.getTimestamp())); statement.setTimestamp(5, new Timestamp(plot.getTimestamp()));
statement.setString(6, plot.getArea().toString()); statement.setString(6, plot.getArea().toString());
@ -1051,7 +1051,7 @@ import java.util.concurrent.atomic.AtomicInteger;
@Override public void set(PreparedStatement statement) throws SQLException { @Override public void set(PreparedStatement statement) throws SQLException {
statement.setInt(1, plot.getId().x); statement.setInt(1, plot.getId().x);
statement.setInt(2, plot.getId().y); statement.setInt(2, plot.getId().y);
statement.setString(3, plot.owner.toString()); statement.setString(3, plot.getOwnerAbs().toString());
statement.setString(4, plot.getArea().toString()); statement.setString(4, plot.getArea().toString());
statement.setTimestamp(5, new Timestamp(plot.getTimestamp())); statement.setTimestamp(5, new Timestamp(plot.getTimestamp()));
} }
@ -1356,7 +1356,7 @@ import java.util.concurrent.atomic.AtomicInteger;
@Override public void delete(final Plot plot) { @Override public void delete(final Plot plot) {
PlotSquared.debug( PlotSquared.debug(
"Deleting plot... Id: " + plot.getId() + " World: " + plot.getWorldName() + " Owner: " "Deleting plot... Id: " + plot.getId() + " World: " + plot.getWorldName() + " Owner: "
+ plot.owner + " Index: " + plot.temp); + plot.getOwnerAbs() + " Index: " + plot.temp);
deleteSettings(plot); deleteSettings(plot);
deleteDenied(plot); deleteDenied(plot);
deleteHelpers(plot); deleteHelpers(plot);
@ -1384,7 +1384,7 @@ import java.util.concurrent.atomic.AtomicInteger;
@Override public void createPlotSettings(final int id, Plot plot) { @Override public void createPlotSettings(final int id, Plot plot) {
PlotSquared.debug( PlotSquared.debug(
"Creating plot... Id: " + plot.getId() + " World: " + plot.getWorldName() + " Owner: " "Creating plot... Id: " + plot.getId() + " World: " + plot.getWorldName() + " Owner: "
+ plot.owner + " Index: " + id); + plot.getOwnerAbs() + " Index: " + id);
addPlotTask(plot, new UniqueStatement("createPlotSettings") { addPlotTask(plot, new UniqueStatement("createPlotSettings") {
@Override public void set(PreparedStatement statement) throws SQLException { @Override public void set(PreparedStatement statement) throws SQLException {
statement.setInt(1, id); statement.setInt(1, id);
@ -3002,10 +3002,10 @@ import java.util.concurrent.atomic.AtomicInteger;
continue; continue;
} }
// owner // owner
if (!plot.owner.equals(dataPlot.owner)) { if (!plot.getOwnerAbs().equals(dataPlot.getOwnerAbs())) {
PlotSquared PlotSquared
.debug("&8 - &7Setting owner: " + plot + " -> " + MainUtil.getName(plot.owner)); .debug("&8 - &7Setting owner: " + plot + " -> " + MainUtil.getName(plot.getOwnerAbs()));
setOwner(plot, plot.owner); setOwner(plot, plot.getOwnerAbs());
} }
// trusted // trusted
if (!plot.getTrusted().equals(dataPlot.getTrusted())) { if (!plot.getTrusted().equals(dataPlot.getTrusted())) {

View File

@ -98,7 +98,7 @@ public class Plot {
* *
* @deprecated * @deprecated
*/ */
@Deprecated public UUID owner; private UUID owner;
/** /**
* Has the plot changed since the last save cycle? * Has the plot changed since the last save cycle?
@ -286,6 +286,34 @@ public class Plot {
return null; return null;
} }
/**
* Get the owner of this exact plot, as it is
* stored in the database.
*
* If the plot is a mega-plot, then the method returns
* the owner of this particular subplot.
*
* Unlike {@link #getOwner()} this method does not
* consider factors such as {@link com.github.intellectualsites.plotsquared.plot.flags.implementations.ServerPlotFlag}
* that could alter the de facto owner of the plot.
*
* @return The plot owner of this particular (sub-)plot
* as stored in the database, if one exists. Else, null.
*/
@Nullable public UUID getOwnerAbs() {
return this.owner;
}
/**
* Set the owner of this exact sub-plot. This does
* not update the database.
*
* @param owner The new owner of this particular sub-plot.
*/
public void setOwnerAbs(@Nullable final UUID owner) {
this.owner = owner;
}
public String getWorldName() { public String getWorldName() {
return area.getWorldName(); return area.getWorldName();
} }
@ -366,7 +394,7 @@ public class Plot {
* @return false if there is no owner * @return false if there is no owner
*/ */
public boolean hasOwner() { public boolean hasOwner() {
return this.owner != null; return this.getOwnerAbs() != null;
} }
/** /**
@ -386,7 +414,10 @@ public class Plot {
return connected.stream().anyMatch(current -> uuid.equals(current.getOwner())); return connected.stream().anyMatch(current -> uuid.equals(current.getOwner()));
} }
public boolean isOwnerAbs(UUID uuid) { public boolean isOwnerAbs(@Nullable final UUID uuid) {
if (uuid == null) {
return false;
}
return uuid.equals(this.getOwner()); return uuid.equals(this.getOwner());
} }
@ -395,13 +426,16 @@ public class Plot {
* (Merged plots can have multiple owners) * (Merged plots can have multiple owners)
* Direct access is Deprecated: use getOwners() * Direct access is Deprecated: use getOwners()
* *
* @deprecated * @deprecated A mega-plot may have multiple owners
* and this method only considers the
* owner of this particular sub-plot.
* @see #getOwnerAbs() getOwnerAbs() to get the owner as stored in the database
*/ */
@Deprecated public UUID getOwner() { @Deprecated public UUID getOwner() {
if (MainUtil.isServerOwned(this)) { if (MainUtil.isServerOwned(this)) {
return DBFunc.SERVER; return DBFunc.SERVER;
} }
return this.owner; return this.getOwnerAbs();
} }
/** /**
@ -411,20 +445,20 @@ public class Plot {
*/ */
public void setOwner(UUID owner) { public void setOwner(UUID owner) {
if (!hasOwner()) { if (!hasOwner()) {
this.owner = owner; this.setOwnerAbs(owner);
create(); create();
return; return;
} }
if (!isMerged()) { if (!isMerged()) {
if (!this.owner.equals(owner)) { if (!owner.equals(this.getOwnerAbs())) {
this.owner = owner; this.setOwnerAbs(owner);
DBFunc.setOwner(this, owner); DBFunc.setOwner(this, owner);
} }
return; return;
} }
for (Plot current : getConnectedPlots()) { for (Plot current : getConnectedPlots()) {
if (!owner.equals(current.owner)) { if (!owner.equals(current.getOwnerAbs())) {
current.owner = owner; current.setOwnerAbs(owner);
DBFunc.setOwner(current, owner); DBFunc.setOwner(current, owner);
} }
} }
@ -467,7 +501,7 @@ public class Plot {
* @return true if the player is added/trusted or is the owner * @return true if the player is added/trusted or is the owner
*/ */
public boolean isAdded(UUID uuid) { public boolean isAdded(UUID uuid) {
if (this.owner == null || getDenied().contains(uuid)) { if (this.getOwnerAbs() == null || getDenied().contains(uuid)) {
return false; return false;
} }
if (isOwner(uuid)) { if (isOwner(uuid)) {
@ -832,20 +866,20 @@ public class Plot {
*/ */
public boolean setOwner(UUID owner, PlotPlayer initiator) { public boolean setOwner(UUID owner, PlotPlayer initiator) {
if (!hasOwner()) { if (!hasOwner()) {
this.owner = owner; this.setOwnerAbs(owner);
create(); create();
return true; return true;
} }
if (!isMerged()) { if (!isMerged()) {
if (!this.owner.equals(owner)) { if (!owner.equals(this.getOwnerAbs())) {
this.owner = owner; this.setOwnerAbs(owner);
DBFunc.setOwner(this, owner); DBFunc.setOwner(this, owner);
} }
return true; return true;
} }
for (Plot current : getConnectedPlots()) { for (final Plot current : getConnectedPlots()) {
if (!owner.equals(current.owner)) { if (!owner.equals(current.getOwnerAbs())) {
current.owner = owner; current.setOwnerAbs(owner);
DBFunc.setOwner(current, owner); DBFunc.setOwner(current, owner);
} }
} }
@ -891,7 +925,7 @@ public class Plot {
TaskManager.runTask(whenDone); TaskManager.runTask(whenDone);
}; };
for (Plot current : plots) { for (Plot current : plots) {
if (isDelete || current.owner == null) { if (isDelete || current.getOwnerAbs() == null) {
manager.unClaimPlot(current, null); manager.unClaimPlot(current, null);
} else { } else {
manager.claimPlot(current); manager.claimPlot(current);
@ -1023,7 +1057,7 @@ public class Plot {
if (createSign) { if (createSign) {
GlobalBlockQueue.IMP.addEmptyTask(() -> { GlobalBlockQueue.IMP.addEmptyTask(() -> {
for (Plot current : plots) { for (Plot current : plots) {
current.setSign(MainUtil.getName(current.owner)); current.setSign(MainUtil.getName(current.getOwnerAbs()));
} }
}); });
} }
@ -1291,7 +1325,7 @@ public class Plot {
* @return false if the Plot has no owner, otherwise true. * @return false if the Plot has no owner, otherwise true.
*/ */
public boolean unclaim() { public boolean unclaim() {
if (this.owner == null) { if (this.getOwnerAbs() == null) {
return false; return false;
} }
for (Plot current : getConnectedPlots()) { for (Plot current : getConnectedPlots()) {
@ -1301,7 +1335,7 @@ public class Plot {
} }
getArea().removePlot(getId()); getArea().removePlot(getId());
DBFunc.delete(current); DBFunc.delete(current);
current.owner = null; current.setOwnerAbs(null);
current.settings = null; current.settings = null;
for (PlotPlayer pp : players) { for (PlotPlayer pp : players) {
PlotListener.plotEntry(pp, current); PlotListener.plotEntry(pp, current);
@ -1677,11 +1711,11 @@ public class Plot {
* Sets the plot sign if plot signs are enabled. * Sets the plot sign if plot signs are enabled.
*/ */
public void setSign() { public void setSign() {
if (this.owner == null) { if (this.getOwnerAbs() == null) {
this.setSign("unknown"); this.setSign("unknown");
return; return;
} }
String name = UUIDHandler.getName(this.owner); String name = UUIDHandler.getName(this.getOwnerAbs());
if (name == null) { if (name == null) {
this.setSign("unknown"); this.setSign("unknown");
} else { } else {
@ -1771,7 +1805,7 @@ public class Plot {
* @return true if plot was created successfully * @return true if plot was created successfully
*/ */
public boolean create(@NotNull UUID uuid, final boolean notify) { public boolean create(@NotNull UUID uuid, final boolean notify) {
this.owner = uuid; this.setOwnerAbs(uuid);
Plot existing = this.area.getOwnedPlotAbs(this.id); Plot existing = this.area.getOwnedPlotAbs(this.id);
if (existing != null) { if (existing != null) {
throw new IllegalStateException("Plot already exists!"); throw new IllegalStateException("Plot already exists!");
@ -1870,7 +1904,7 @@ public class Plot {
* @return Future containing the result * @return Future containing the result
*/ */
public CompletableFuture<Boolean> swapData(Plot plot) { public CompletableFuture<Boolean> swapData(Plot plot) {
if (this.owner == null) { if (this.getOwnerAbs() == null) {
if (plot != null && plot.hasOwner()) { if (plot != null && plot.hasOwner()) {
plot.moveData(this, null); plot.moveData(this, null);
return CompletableFuture.completedFuture(true); return CompletableFuture.completedFuture(true);
@ -1905,7 +1939,7 @@ public class Plot {
* @return * @return
*/ */
public boolean moveData(Plot plot, Runnable whenDone) { public boolean moveData(Plot plot, Runnable whenDone) {
if (this.owner == null) { if (this.getOwnerAbs() == null) {
PlotSquared.debug(plot + " is unowned (single)"); PlotSquared.debug(plot + " is unowned (single)");
TaskManager.runTask(whenDone); TaskManager.runTask(whenDone);
return false; return false;
@ -2159,7 +2193,7 @@ public class Plot {
} else { } else {
TaskManager.runTaskAsync(() -> { TaskManager.runTaskAsync(() -> {
String name = Plot.this.id + "," + Plot.this.area + ',' + MainUtil String name = Plot.this.id + "," + Plot.this.area + ',' + MainUtil
.getName(Plot.this.owner); .getName(Plot.this.getOwnerAbs());
boolean result = SchematicHandler.manager.save(value, boolean result = SchematicHandler.manager.save(value,
Settings.Paths.SCHEMATICS + File.separator + name + ".schem"); Settings.Paths.SCHEMATICS + File.separator + name + ".schem");
if (whenDone != null) { if (whenDone != null) {
@ -2366,7 +2400,7 @@ public class Plot {
*/ */
public UUID guessOwner() { public UUID guessOwner() {
if (this.hasOwner()) { if (this.hasOwner()) {
return this.owner; return this.getOwnerAbs();
} }
if (!this.area.allowSigns() || !Settings.Enabled_Components.GUESS_PLOT_OWNER) { if (!this.area.allowSigns() || !Settings.Enabled_Components.GUESS_PLOT_OWNER) {
return null; return null;
@ -2400,7 +2434,7 @@ public class Plot {
} }
UUID owner = UUIDHandler.getUUID(name, null); UUID owner = UUIDHandler.getUUID(name, null);
if (owner != null) { if (owner != null) {
this.owner = owner; this.setOwnerAbs(owner);
break; break;
} }
if (lines[i - 1].length() == 15) { if (lines[i - 1].length() == 15) {
@ -2408,19 +2442,19 @@ public class Plot {
for (Entry<StringWrapper, UUID> entry : map.entrySet()) { for (Entry<StringWrapper, UUID> entry : map.entrySet()) {
String key = entry.getKey().value; String key = entry.getKey().value;
if (key.length() > name.length() && key.startsWith(name)) { if (key.length() > name.length() && key.startsWith(name)) {
this.owner = entry.getValue(); this.setOwnerAbs(entry.getValue());
break loop; break loop;
} }
} }
} }
this.owner = UUID.nameUUIDFromBytes( this.setOwnerAbs(UUID.nameUUIDFromBytes(
("OfflinePlayer:" + name).getBytes(StandardCharsets.UTF_8)); ("OfflinePlayer:" + name).getBytes(StandardCharsets.UTF_8)));
break; break;
} }
if (this.hasOwner()) { if (this.hasOwner()) {
this.create(); this.create();
} }
return this.owner; return this.getOwnerAbs();
} catch (IllegalArgumentException ignored) { } catch (IllegalArgumentException ignored) {
return null; return null;
} }
@ -2454,7 +2488,7 @@ public class Plot {
*/ */
public boolean autoMerge(Direction dir, int max, UUID uuid, boolean removeRoads) { public boolean autoMerge(Direction dir, int max, UUID uuid, boolean removeRoads) {
//Ignore merging if there is no owner for the plot //Ignore merging if there is no owner for the plot
if (this.owner == null) { if (this.getOwnerAbs() == null) {
return false; return false;
} }
Set<Plot> connected = this.getConnectedPlots(); Set<Plot> connected = this.getConnectedPlots();
@ -2689,7 +2723,7 @@ public class Plot {
if (!tmp.getMerged(Direction.SOUTH)) { if (!tmp.getMerged(Direction.SOUTH)) {
// invalid merge // invalid merge
PlotSquared.debug("Fixing invalid merge: " + this); PlotSquared.debug("Fixing invalid merge: " + this);
if (tmp.isOwnerAbs(this.owner)) { if (tmp.isOwnerAbs(this.getOwnerAbs())) {
tmp.getSettings().setMerged(Direction.SOUTH, true); tmp.getSettings().setMerged(Direction.SOUTH, true);
DBFunc.setMerged(tmp, tmp.getSettings().getMerged()); DBFunc.setMerged(tmp, tmp.getSettings().getMerged());
} else { } else {
@ -2702,10 +2736,11 @@ public class Plot {
} }
if (this.getMerged(Direction.EAST)) { if (this.getMerged(Direction.EAST)) {
tmp = this.area.getPlotAbs(this.id.getRelative(Direction.EAST)); tmp = this.area.getPlotAbs(this.id.getRelative(Direction.EAST));
assert tmp != null;
if (!tmp.getMerged(Direction.WEST)) { if (!tmp.getMerged(Direction.WEST)) {
// invalid merge // invalid merge
PlotSquared.debug("Fixing invalid merge: " + this); PlotSquared.debug("Fixing invalid merge: " + this);
if (tmp.isOwnerAbs(this.owner)) { if (tmp.isOwnerAbs(this.getOwnerAbs())) {
tmp.getSettings().setMerged(Direction.WEST, true); tmp.getSettings().setMerged(Direction.WEST, true);
DBFunc.setMerged(tmp, tmp.getSettings().getMerged()); DBFunc.setMerged(tmp, tmp.getSettings().getMerged());
} else { } else {
@ -2718,10 +2753,11 @@ public class Plot {
} }
if (this.getMerged(Direction.SOUTH)) { if (this.getMerged(Direction.SOUTH)) {
tmp = this.area.getPlotAbs(this.id.getRelative(Direction.SOUTH)); tmp = this.area.getPlotAbs(this.id.getRelative(Direction.SOUTH));
assert tmp != null;
if (!tmp.getMerged(Direction.NORTH)) { if (!tmp.getMerged(Direction.NORTH)) {
// invalid merge // invalid merge
PlotSquared.debug("Fixing invalid merge: " + this); PlotSquared.debug("Fixing invalid merge: " + this);
if (tmp.isOwnerAbs(this.owner)) { if (tmp.isOwnerAbs(this.getOwnerAbs())) {
tmp.getSettings().setMerged(Direction.NORTH, true); tmp.getSettings().setMerged(Direction.NORTH, true);
DBFunc.setMerged(tmp, tmp.getSettings().getMerged()); DBFunc.setMerged(tmp, tmp.getSettings().getMerged());
} else { } else {
@ -2737,7 +2773,7 @@ public class Plot {
if (!tmp.getMerged(Direction.EAST)) { if (!tmp.getMerged(Direction.EAST)) {
// invalid merge // invalid merge
PlotSquared.debug("Fixing invalid merge: " + this); PlotSquared.debug("Fixing invalid merge: " + this);
if (tmp.isOwnerAbs(this.owner)) { if (tmp.isOwnerAbs(this.getOwnerAbs())) {
tmp.getSettings().setMerged(Direction.EAST, true); tmp.getSettings().setMerged(Direction.EAST, true);
DBFunc.setMerged(tmp, tmp.getSettings().getMerged()); DBFunc.setMerged(tmp, tmp.getSettings().getMerged());
} else { } else {
@ -2750,11 +2786,11 @@ public class Plot {
} }
Plot current; Plot current;
while ((current = frontier.poll()) != null) { while ((current = frontier.poll()) != null) {
if (current.owner == null || current.settings == null) { if (current.getOwnerAbs() == null || current.settings == null) {
// Invalid plot // Invalid plot
// merged onto unclaimed plot // merged onto unclaimed plot
PlotSquared PlotSquared
.debug("Ignoring invalid merged plot: " + current + " | " + current.owner); .debug("Ignoring invalid merged plot: " + current + " | " + current.getOwnerAbs());
continue; continue;
} }
tmpSet.add(current); tmpSet.add(current);
@ -3054,14 +3090,14 @@ public class Plot {
* @return true if the owner of the Plot is online * @return true if the owner of the Plot is online
*/ */
public boolean isOnline() { public boolean isOnline() {
if (this.owner == null) { if (this.getOwnerAbs() == null) {
return false; return false;
} }
if (!isMerged()) { if (!isMerged()) {
return UUIDHandler.getPlayer(this.owner) != null; return UUIDHandler.getPlayer(this.getOwnerAbs()) != null;
} }
for (Plot current : getConnectedPlots()) { for (final Plot current : getConnectedPlots()) {
if (current.hasOwner() && UUIDHandler.getPlayer(current.owner) != null) { if (current.hasOwner() && UUIDHandler.getPlayer(current.getOwnerAbs()) != null) {
return true; return true;
} }
} }
@ -3183,7 +3219,7 @@ public class Plot {
Location ob = this.getBottomAbs(); Location ob = this.getBottomAbs();
final int offsetX = db.getX() - ob.getX(); final int offsetX = db.getX() - ob.getX();
final int offsetZ = db.getZ() - ob.getZ(); final int offsetZ = db.getZ() - ob.getZ();
if (this.owner == null) { if (this.getOwnerAbs() == null) {
TaskManager.runTaskLater(whenDone, 1); TaskManager.runTaskLater(whenDone, 1);
return CompletableFuture.completedFuture(false); return CompletableFuture.completedFuture(false);
} }
@ -3301,7 +3337,7 @@ public class Plot {
Location ob = this.getBottomAbs(); Location ob = this.getBottomAbs();
final int offsetX = db.getX() - ob.getX(); final int offsetX = db.getX() - ob.getX();
final int offsetZ = db.getZ() - ob.getZ(); final int offsetZ = db.getZ() - ob.getZ();
if (this.owner == null) { if (this.getOwnerAbs() == null) {
TaskManager.runTaskLater(whenDone, 1); TaskManager.runTaskLater(whenDone, 1);
return false; return false;
} }

View File

@ -503,7 +503,7 @@ public abstract class PlotArea {
} }
final HashSet<Plot> myPlots = new HashSet<>(); final HashSet<Plot> myPlots = new HashSet<>();
forEachPlotAbs(value -> { forEachPlotAbs(value -> {
if (uuid.equals(value.owner)) { if (uuid.equals(value.getOwnerAbs())) {
myPlots.add(value); myPlots.add(value);
} }
}); });

View File

@ -1,11 +1,14 @@
package com.github.intellectualsites.plotsquared.plot.object; package com.github.intellectualsites.plotsquared.plot.object;
import org.jetbrains.annotations.NotNull;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
public class PlotHandler { public class PlotHandler {
public static boolean sameOwners(final Plot plot1, final Plot plot2) {
if (plot1.owner == null || plot2.owner == null) { public static boolean sameOwners(@NotNull final Plot plot1, @NotNull final Plot plot2) {
if (plot1.getOwnerAbs() == null || plot2.getOwnerAbs() == null) {
return false; return false;
} }
final Set<UUID> owners = plot1.getOwners(); final Set<UUID> owners = plot1.getOwners();
@ -16,4 +19,5 @@ public class PlotHandler {
} }
return false; return false;
} }
} }

View File

@ -171,7 +171,7 @@ public class SinglePlotArea extends GridPlotWorld {
PlotSettings s = p.getSettings(); PlotSettings s = p.getSettings();
final FlagContainer oldContainer = p.getFlagContainer(); final FlagContainer oldContainer = p.getFlagContainer();
p = new SinglePlot(p.getId(), p.owner, p.getTrusted(), p.getMembers(), p.getDenied(), p = new SinglePlot(p.getId(), p.getOwnerAbs(), p.getTrusted(), p.getMembers(), p.getDenied(),
s.getAlias(), s.getPosition(), null, this, s.getMerged(), p.getTimestamp(), p.temp); s.getAlias(), s.getPosition(), null, this, s.getMerged(), p.getTimestamp(), p.temp);
p.getFlagContainer().addAll(oldContainer); p.getFlagContainer().addAll(oldContainer);

View File

@ -61,7 +61,7 @@ public class UUIDHandler {
final HashSet<UUID> uuids = new HashSet<>(); final HashSet<UUID> uuids = new HashSet<>();
PlotSquared.get().forEachPlotRaw(plot -> { PlotSquared.get().forEachPlotRaw(plot -> {
if (plot.hasOwner()) { if (plot.hasOwner()) {
uuids.add(plot.owner); uuids.add(plot.getOwnerAbs());
uuids.addAll(plot.getTrusted()); uuids.addAll(plot.getTrusted());
uuids.addAll(plot.getMembers()); uuids.addAll(plot.getMembers());
uuids.addAll(plot.getDenied()); uuids.addAll(plot.getDenied());
@ -107,8 +107,8 @@ public class UUIDHandler {
return implementation.getName(uuid); return implementation.getName(uuid);
} }
public static PlotPlayer getPlayer(UUID uuid) { @Nullable public static PlotPlayer getPlayer(@Nullable final UUID uuid) {
if (implementation == null) { if (implementation == null || uuid == null) {
return null; return null;
} }
return check(implementation.getPlayer(uuid)); return check(implementation.getPlayer(uuid));

View File

@ -130,8 +130,8 @@ public abstract class UUIDHandlerImplementation {
UUIDHandlerImplementation.this.unknown.remove(offline); UUIDHandlerImplementation.this.unknown.remove(offline);
Set<Plot> plots = PlotSquared.get().getPlotsAbs(offline); Set<Plot> plots = PlotSquared.get().getPlotsAbs(offline);
if (!plots.isEmpty()) { if (!plots.isEmpty()) {
for (Plot plot : plots) { for (final Plot plot : plots) {
plot.owner = uuid; plot.setOwnerAbs(uuid);
} }
DBFunc.replaceUUID(offline, uuid); DBFunc.replaceUUID(offline, uuid);
PlotSquared.debug("&cDetected invalid UUID stored for: " + name.value); PlotSquared.debug("&cDetected invalid UUID stored for: " + name.value);
@ -152,8 +152,8 @@ public abstract class UUIDHandlerImplementation {
UUIDHandlerImplementation.this.unknown.remove(offlineUpper); UUIDHandlerImplementation.this.unknown.remove(offlineUpper);
Set<Plot> plots = PlotSquared.get().getPlotsAbs(offlineUpper); Set<Plot> plots = PlotSquared.get().getPlotsAbs(offlineUpper);
if (!plots.isEmpty()) { if (!plots.isEmpty()) {
for (Plot plot : plots) { for (final Plot plot : plots) {
plot.owner = uuid; plot.setOwnerAbs(uuid);
} }
replace(offlineUpper, uuid, name.value); replace(offlineUpper, uuid, name.value);
} }
@ -166,8 +166,8 @@ public abstract class UUIDHandlerImplementation {
if (!existing.equals(uuid)) { if (!existing.equals(uuid)) {
Set<Plot> plots = PlotSquared.get().getPlots(existing); Set<Plot> plots = PlotSquared.get().getPlots(existing);
if (!plots.isEmpty()) { if (!plots.isEmpty()) {
for (Plot plot : plots) { for (final Plot plot : plots) {
plot.owner = uuid; plot.setOwnerAbs(uuid);
} }
replace(existing, uuid, name.value); replace(existing, uuid, name.value);
} }