Skip to content

Commit

Permalink
Fix sending multiple messages of notify-enter and notify-leave flag w…
Browse files Browse the repository at this point in the history
…hen joining from foreign worlds (#4433)

* Fixed #3424 by combining Teleport and WorldChange

* re-added WorldEdit permission check

* Changed conditions for calling plotEntry
  • Loading branch information
Fameless9 authored Jun 16, 2024
1 parent 670f5a8 commit 67e69e3
Showing 1 changed file with 16 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -533,9 +533,9 @@ public void onTeleport(PlayerTeleportEvent event) {
// to is identical to the plot's home location, and untrusted-visit is true
// i.e. untrusted-visit can override deny-teleport
// this is acceptable, because otherwise it wouldn't make sense to have both flags set
if (!result && !(plot.getFlag(UntrustedVisitFlag.class) && plot
.getHomeSynchronous()
.equals(BukkitUtil.adaptComplete(to)))) {
if (result || (plot.getFlag(UntrustedVisitFlag.class) && plot.getHomeSynchronous().equals(BukkitUtil.adaptComplete(to)))) {
plotListener.plotEntry(pp, plot);
} else {
pp.sendMessage(
TranslatableCaption.of("deny.no_enter"),
TagResolver.resolver("plot", Tag.inserting(Component.text(plot.toString())))
Expand All @@ -548,6 +548,19 @@ public void onTeleport(PlayerTeleportEvent event) {
playerMove(event);
}

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onWorldChanged(PlayerChangedWorldEvent event) {
Player player = event.getPlayer();
BukkitPlayer pp = BukkitUtil.adapt(player);
if (this.worldEdit != null) {
if (!pp.hasPermission(Permission.PERMISSION_WORLDEDIT_BYPASS)) {
if (pp.getAttribute("worldedit")) {
pp.removeAttribute("worldedit");
}
}
}
}

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void vehicleMove(VehicleMoveEvent event)
throws IllegalAccessException {
Expand Down Expand Up @@ -887,40 +900,6 @@ public void onChat(AsyncPlayerChatEvent event) {
}
}

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onWorldChanged(PlayerChangedWorldEvent event) {
Player player = event.getPlayer();
BukkitPlayer pp = BukkitUtil.adapt(player);
// Delete last location
Plot plot;
try (final MetaDataAccess<Plot> lastPlotAccess =
pp.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LAST_PLOT)) {
plot = lastPlotAccess.remove();
}
try (final MetaDataAccess<Location> lastLocationAccess =
pp.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LOCATION)) {
lastLocationAccess.remove();
}
if (plot != null) {
plotListener.plotExit(pp, plot);
}
if (this.worldEdit != null) {
if (!pp.hasPermission(Permission.PERMISSION_WORLDEDIT_BYPASS)) {
if (pp.getAttribute("worldedit")) {
pp.removeAttribute("worldedit");
}
}
}
Location location = pp.getLocation();
PlotArea area = location.getPlotArea();
if (location.isPlotArea()) {
plot = location.getPlot();
if (plot != null) {
plotListener.plotEntry(pp, plot);
}
}
}

@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onInventoryClick(InventoryClickEvent event) {
Expand Down

0 comments on commit 67e69e3

Please sign in to comment.