Merge branch 'features/v5/internal-updates' into features/v5/async-load

This commit is contained in:
Alexander Söderberg
2020-04-07 22:13:42 +02:00
4 changed files with 40 additions and 10 deletions

View File

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

View File

@ -978,7 +978,6 @@ import java.util.concurrent.atomic.AtomicInteger;
}
public void createPlotSafe(final Plot plot, final Runnable success, final Runnable failure) {
final long timestamp = plot.getTimestamp();
addPlotTask(plot, new UniqueStatement("createPlotSafe_" + plot.hashCode()) {
@Override public void set(PreparedStatement statement) throws SQLException {
statement.setInt(1, plot.getId().x);

View File

@ -1709,6 +1709,9 @@ public class Plot {
public boolean claim(final PlotPlayer player, boolean teleport, String schematic) {
if (!canClaim(player)) {
PlotSquared.debug(Captions.PREFIX.getTranslated() +
String.format("Player %s attempted to claim plot %s, but was not allowed",
player.getName(), this.getId().toCommaSeparatedString()));
return false;
}
return claim(player, teleport, schematic, true);
@ -1719,6 +1722,9 @@ public class Plot {
if (updateDB) {
if (!create(player.getUUID(), true)) {
PlotSquared.debug(Captions.PREFIX.getTranslated() +
String.format("Player %s attempted to claim plot %s, but the database failed to update",
player.getName(), this.getId().toCommaSeparatedString()));
return false;
}
} else {
@ -1804,6 +1810,9 @@ public class Plot {
});
return true;
}
PlotSquared.get().getLogger().log(Captions.PREFIX.getTranslated() +
String.format("Failed to add plot %s to plot area %s", this.getId().toCommaSeparatedString(),
this.area.toString()));
return false;
}
@ -2346,7 +2355,13 @@ public class Plot {
return false;
}
}
return this.guessOwner() == null && !isMerged();
final UUID owner = this.guessOwner();
if (owner != null) {
if (player == null || !player.getUUID().equals(owner)) {
return false;
}
}
return !isMerged();
}
/**