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
commit 7fdb7961ce
4 changed files with 40 additions and 10 deletions

View file

@ -39,7 +39,7 @@ public class EntitySpawnListener implements Listener {
private static boolean hasPlotArea = false; private static boolean hasPlotArea = false;
private static String areaName = null; private static String areaName = null;
public static void testNether(Entity entity) { public static void testNether(final Entity entity) {
@NotNull World world = entity.getWorld(); @NotNull World world = entity.getWorld();
if (world.getEnvironment() != World.Environment.NETHER if (world.getEnvironment() != World.Environment.NETHER
&& world.getEnvironment() != World.Environment.THE_END) { && world.getEnvironment() != World.Environment.THE_END) {
@ -48,15 +48,16 @@ public class EntitySpawnListener implements Listener {
test(entity); test(entity);
} }
public static void testCreate(Entity entity) { public static void testCreate(final Entity entity) {
@NotNull World world = entity.getWorld(); @NotNull World world = entity.getWorld();
if (areaName == world.getName()) { if (areaName == world.getName()) {
} else { } else {
areaName = world.getName(); areaName = world.getName();
hasPlotArea = PlotSquared.get().hasPlotArea(areaName); hasPlotArea = PlotSquared.get().hasPlotArea(areaName);
} }
if (!hasPlotArea) if (!hasPlotArea) {
return; return;
}
test(entity); test(entity);
} }
@ -76,15 +77,21 @@ public class EntitySpawnListener implements Listener {
if (!world.getName().equalsIgnoreCase(originWorld + "_the_end")) { if (!world.getName().equalsIgnoreCase(originWorld + "_the_end")) {
try { try {
ignoreTP = true; ignoreTP = true;
PaperLib.teleportAsync(entity,origin); PaperLib.teleportAsync(entity, origin);
} finally { } finally {
ignoreTP = false; ignoreTP = false;
} }
if (entity.getType() == EntityType.PLAYER) {
return;
}
if (entity.getLocation().getWorld().equals(world)) { if (entity.getLocation().getWorld().equals(world)) {
entity.remove(); entity.remove();
} }
} }
} else { } else {
if (entity.getType() == EntityType.PLAYER) {
return;
}
entity.remove(); entity.remove();
} }
} }
@ -136,7 +143,7 @@ public class EntitySpawnListener implements Listener {
@EventHandler public void onChunkLoad(ChunkLoadEvent event) { @EventHandler public void onChunkLoad(ChunkLoadEvent event) {
@NotNull Chunk chunk = event.getChunk(); @NotNull Chunk chunk = event.getChunk();
for (Entity entity : chunk.getEntities()) { for (final Entity entity : chunk.getEntities()) {
testCreate(entity); testCreate(entity);
} }
} }

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

@ -1709,6 +1709,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);
@ -1719,6 +1722,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 {
@ -1804,6 +1810,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;
} }
@ -2346,7 +2355,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();
} }
/** /**