From a3b50a0bf5093f2a382eec7063c75eed1d8b69be Mon Sep 17 00:00:00 2001 From: William Date: Mon, 6 May 2024 16:48:15 +0100 Subject: [PATCH] fix: advancement messages being improperly canceled --- .../husksync/listener/BukkitEventListener.java | 12 ------------ .../husksync/listener/PaperEventListener.java | 11 +++++++---- 2 files changed, 7 insertions(+), 16 deletions(-) diff --git a/bukkit/src/main/java/net/william278/husksync/listener/BukkitEventListener.java b/bukkit/src/main/java/net/william278/husksync/listener/BukkitEventListener.java index 00bde227..21c282bf 100644 --- a/bukkit/src/main/java/net/william278/husksync/listener/BukkitEventListener.java +++ b/bukkit/src/main/java/net/william278/husksync/listener/BukkitEventListener.java @@ -29,7 +29,6 @@ import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.entity.PlayerDeathEvent; -import org.bukkit.event.player.PlayerAdvancementDoneEvent; import org.bukkit.event.player.PlayerCommandPreprocessEvent; import org.bukkit.event.server.MapInitializeEvent; import org.bukkit.event.world.WorldSaveEvent; @@ -103,10 +102,6 @@ public void handlePlayerDeath(@NotNull PlayerDeathEvent event) { super.saveOnPlayerDeath(user, BukkitData.Items.ItemArray.adapt(event.getDrops())); } - // Handle advancement grant events (empty on Spigot due to missing message API) - protected void handleLockedAdvancementGrant(@NotNull @SuppressWarnings("unused") PlayerAdvancementDoneEvent event) { - } - @EventHandler(ignoreCancelled = true) public void onWorldSave(@NotNull WorldSaveEvent event) { if (!plugin.getSettings().getSynchronization().isSaveOnWorldSave()) { @@ -126,13 +121,6 @@ public void onMapInitialize(@NotNull MapInitializeEvent event) { } } - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public void onPlayerAdvancementDone(@NotNull PlayerAdvancementDoneEvent event) { - if (lockedHandler.cancelPlayerEvent(event.getPlayer().getUniqueId())) { - handleLockedAdvancementGrant(event); - } - } - // We handle commands here to allow specific command handling on ProtocolLib servers @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) public void onCommandProcessed(@NotNull PlayerCommandPreprocessEvent event) { diff --git a/paper/src/main/java/net/william278/husksync/listener/PaperEventListener.java b/paper/src/main/java/net/william278/husksync/listener/PaperEventListener.java index 6e4aff48..d3b988d9 100644 --- a/paper/src/main/java/net/william278/husksync/listener/PaperEventListener.java +++ b/paper/src/main/java/net/william278/husksync/listener/PaperEventListener.java @@ -24,6 +24,8 @@ import net.william278.husksync.data.BukkitData; import net.william278.husksync.user.BukkitUser; import net.william278.husksync.user.OnlineUser; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; import org.bukkit.event.entity.PlayerDeathEvent; import org.bukkit.event.player.PlayerAdvancementDoneEvent; import org.bukkit.inventory.ItemStack; @@ -69,10 +71,11 @@ public void handlePlayerDeath(@NotNull PlayerDeathEvent event) { super.saveOnPlayerDeath(user, BukkitData.Items.ItemArray.adapt(itemsToSave)); } - @Override - protected void handleLockedAdvancementGrant(@NotNull PlayerAdvancementDoneEvent event) { - // Disable advancement chat messages - event.message(null); + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onPlayerAdvancementDone(@NotNull PlayerAdvancementDoneEvent event) { + if (lockedHandler.cancelPlayerEvent(event.getPlayer().getUniqueId())) { + event.message(null); + } } @NotNull