Fix plot claiming

This commit is contained in:
Alexander Söderberg 2020-04-07 22:12:52 +02:00
parent 5e2e4a8631
commit e161209a46
3 changed files with 36 additions and 7 deletions

View File

@ -101,8 +101,12 @@ public class Claim extends SubCommand {
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) {
plot.claim(player, true, finalSchematic); if (!plot.claim(player, true, finalSchematic)) {
if (area.isAutoMerge()) { 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() PlotMergeEvent event = PlotSquared.get().getEventDispatcher()
.callMerge(plot, Direction.ALL, Integer.MAX_VALUE, player); .callMerge(plot, Direction.ALL, Integer.MAX_VALUE, player);
if (event.getEventResult() == Result.DENY) { 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; 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) { public void createPlotSafe(final Plot plot, final Runnable success, final Runnable failure) {
final long timestamp = plot.getTimestamp();
addPlotTask(plot, new UniqueStatement("createPlotSafe_" + plot.hashCode()) { addPlotTask(plot, new UniqueStatement("createPlotSafe_" + plot.hashCode()) {
@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);

View File

@ -1,7 +1,6 @@
package com.github.intellectualsites.plotsquared.plot.object; package com.github.intellectualsites.plotsquared.plot.object;
import com.github.intellectualsites.plotsquared.plot.PlotSquared; import com.github.intellectualsites.plotsquared.plot.PlotSquared;
import com.github.intellectualsites.plotsquared.plot.config.CaptionUtility;
import com.github.intellectualsites.plotsquared.plot.config.Captions; import com.github.intellectualsites.plotsquared.plot.config.Captions;
import com.github.intellectualsites.plotsquared.plot.config.Configuration; import com.github.intellectualsites.plotsquared.plot.config.Configuration;
import com.github.intellectualsites.plotsquared.plot.config.Settings; import com.github.intellectualsites.plotsquared.plot.config.Settings;
@ -19,7 +18,14 @@ import com.github.intellectualsites.plotsquared.plot.generator.SquarePlotWorld;
import com.github.intellectualsites.plotsquared.plot.listener.PlotListener; import com.github.intellectualsites.plotsquared.plot.listener.PlotListener;
import com.github.intellectualsites.plotsquared.plot.object.comment.PlotComment; import com.github.intellectualsites.plotsquared.plot.object.comment.PlotComment;
import com.github.intellectualsites.plotsquared.plot.object.schematic.Schematic; import com.github.intellectualsites.plotsquared.plot.object.schematic.Schematic;
import com.github.intellectualsites.plotsquared.plot.util.*; import com.github.intellectualsites.plotsquared.plot.util.ChunkManager;
import com.github.intellectualsites.plotsquared.plot.util.MainUtil;
import com.github.intellectualsites.plotsquared.plot.util.MathMan;
import com.github.intellectualsites.plotsquared.plot.util.Permissions;
import com.github.intellectualsites.plotsquared.plot.util.SchematicHandler;
import com.github.intellectualsites.plotsquared.plot.util.TaskManager;
import com.github.intellectualsites.plotsquared.plot.util.UUIDHandler;
import com.github.intellectualsites.plotsquared.plot.util.WorldUtil;
import com.github.intellectualsites.plotsquared.plot.util.block.GlobalBlockQueue; import com.github.intellectualsites.plotsquared.plot.util.block.GlobalBlockQueue;
import com.github.intellectualsites.plotsquared.plot.util.block.LocalBlockQueue; import com.github.intellectualsites.plotsquared.plot.util.block.LocalBlockQueue;
import com.github.intellectualsites.plotsquared.plot.util.expiry.ExpireManager; import com.github.intellectualsites.plotsquared.plot.util.expiry.ExpireManager;
@ -1581,6 +1587,9 @@ public class Plot {
public boolean claim(final PlotPlayer player, boolean teleport, String schematic) { public boolean claim(final PlotPlayer player, boolean teleport, String schematic) {
if (!canClaim(player)) { 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 false;
} }
return claim(player, teleport, schematic, true); return claim(player, teleport, schematic, true);
@ -1591,6 +1600,9 @@ public class Plot {
if (updateDB) { if (updateDB) {
if (!create(player.getUUID(), true)) { 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; return false;
} }
} else { } else {
@ -1676,6 +1688,9 @@ public class Plot {
}); });
return true; 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; return false;
} }
@ -2212,7 +2227,13 @@ public class Plot {
return false; 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();
} }
/** /**