From 622e240226b0a85c501ffb94e3a6f75be561703f Mon Sep 17 00:00:00 2001 From: Waiting Idly <25394029+WaitingIdly@users.noreply.github.com> Date: Sat, 22 Jun 2024 23:54:59 -0700 Subject: [PATCH 1/2] remove listener when logging out --- src/main/java/betterquesting/handlers/EventHandler.java | 6 ++++++ .../betterquesting/handlers/PlayerContainerListener.java | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/src/main/java/betterquesting/handlers/EventHandler.java b/src/main/java/betterquesting/handlers/EventHandler.java index 706f74538..2bf3aeb54 100644 --- a/src/main/java/betterquesting/handlers/EventHandler.java +++ b/src/main/java/betterquesting/handlers/EventHandler.java @@ -724,6 +724,12 @@ public void onEntityCreated(EntityJoinWorldEvent event) { PlayerContainerListener.refreshListener((EntityPlayer) event.getEntity()); } + @SubscribeEvent + public static void onPlayerLoggedOut(PlayerEvent.PlayerLoggedOutEvent event) { + if (event.player == null || event.player.world.isRemote) return; + PlayerContainerListener.removeListener(event.player); + } + @SubscribeEvent public void onMarkDirtyPlayer(MarkDirtyPlayerEvent event) { SaveLoadHandler.INSTANCE.addDirtyPlayers(event.getDirtyPlayerIDs()); diff --git a/src/main/java/betterquesting/handlers/PlayerContainerListener.java b/src/main/java/betterquesting/handlers/PlayerContainerListener.java index ef90eb88b..3354a9411 100644 --- a/src/main/java/betterquesting/handlers/PlayerContainerListener.java +++ b/src/main/java/betterquesting/handlers/PlayerContainerListener.java @@ -37,6 +37,11 @@ public static void refreshListener(@Nonnull EntityPlayer player) { } } + public static void removeListener(@Nonnull EntityPlayer player) { + UUID uuid = QuestingAPI.getQuestingUUID(player); + LISTEN_MAP.remove(uuid); + } + private EntityPlayer player; private PlayerContainerListener(@Nonnull EntityPlayer player) { From f2d428a6e71078a5473cf85a028376e7608299a9 Mon Sep 17 00:00:00 2001 From: Waiting Idly <25394029+WaitingIdly@users.noreply.github.com> Date: Thu, 10 Oct 2024 05:16:39 -0700 Subject: [PATCH 2/2] method cannot be static --- src/main/java/betterquesting/handlers/EventHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/betterquesting/handlers/EventHandler.java b/src/main/java/betterquesting/handlers/EventHandler.java index 2bf3aeb54..75af9384a 100644 --- a/src/main/java/betterquesting/handlers/EventHandler.java +++ b/src/main/java/betterquesting/handlers/EventHandler.java @@ -725,7 +725,7 @@ public void onEntityCreated(EntityJoinWorldEvent event) { } @SubscribeEvent - public static void onPlayerLoggedOut(PlayerEvent.PlayerLoggedOutEvent event) { + public void onPlayerLoggedOut(PlayerEvent.PlayerLoggedOutEvent event) { if (event.player == null || event.player.world.isRemote) return; PlayerContainerListener.removeListener(event.player); }