fix: Send user-friendly message on join of denied plot (#3388)

Also refactor local variable `now` to a more fitting name
This commit is contained in:
Alex 2021-12-26 23:28:50 +01:00 committed by GitHub
parent e042566bb7
commit 7551450cf9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -417,8 +417,8 @@ public class PlayerEventListener extends PlotListener implements Listener {
.getHomeSynchronous() .getHomeSynchronous()
.equals(BukkitUtil.adaptComplete(to)))) { .equals(BukkitUtil.adaptComplete(to)))) {
pp.sendMessage( pp.sendMessage(
TranslatableCaption.of("permission.no_permission_event"), TranslatableCaption.of("deny.no_enter"),
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_ENTRY_DENIED)) Template.of("plot", plot.toString())
); );
event.setCancelled(true); event.setCancelled(true);
} }
@ -551,8 +551,8 @@ public class PlayerEventListener extends PlotListener implements Listener {
ForceFieldListener.handleForcefield(player, pp, now); ForceFieldListener.handleForcefield(player, pp, now);
} else if (!plotEntry(pp, now) && this.tmpTeleport) { } else if (!plotEntry(pp, now) && this.tmpTeleport) {
pp.sendMessage( pp.sendMessage(
TranslatableCaption.of("permission.no_permission_event"), TranslatableCaption.of("deny.no_enter"),
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_ENTRY_DENIED)) Template.of("plot", now.toString())
); );
this.tmpTeleport = false; this.tmpTeleport = false;
to.setX(from.getBlockX()); to.setX(from.getBlockX());
@ -612,13 +612,13 @@ public class PlayerEventListener extends PlotListener implements Listener {
} }
return; return;
} }
Plot now = area.getPlot(location); Plot plot = area.getPlot(location);
Plot lastPlot; Plot lastPlot;
try (final MetaDataAccess<Plot> lastPlotAccess = try (final MetaDataAccess<Plot> lastPlotAccess =
pp.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LAST_PLOT)) { pp.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LAST_PLOT)) {
lastPlot = lastPlotAccess.get().orElse(null); lastPlot = lastPlotAccess.get().orElse(null);
} }
if (now == null) { if (plot == null) {
try (final MetaDataAccess<Boolean> kickAccess = try (final MetaDataAccess<Boolean> kickAccess =
pp.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_KICK)) { pp.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_KICK)) {
if (lastPlot != null && !plotExit(pp, lastPlot) && this.tmpTeleport && !kickAccess.get().orElse(false)) { if (lastPlot != null && !plotExit(pp, lastPlot) && this.tmpTeleport && !kickAccess.get().orElse(false)) {
@ -637,12 +637,12 @@ public class PlayerEventListener extends PlotListener implements Listener {
return; return;
} }
} }
} else if (now.equals(lastPlot)) { } else if (plot.equals(lastPlot)) {
ForceFieldListener.handleForcefield(player, pp, now); ForceFieldListener.handleForcefield(player, pp, plot);
} else if (!plotEntry(pp, now) && this.tmpTeleport) { } else if (!plotEntry(pp, plot) && this.tmpTeleport) {
pp.sendMessage( pp.sendMessage(
TranslatableCaption.of("permission.no_permission_event"), TranslatableCaption.of("deny.no_enter"),
Template.of("node", String.valueOf(Permission.PERMISSION_ADMIN_ENTRY_DENIED)) Template.of("plot", plot.toString())
); );
this.tmpTeleport = false; this.tmpTeleport = false;
player.teleport(from); player.teleport(from);