From 407eb7a4689ce88128a1e3a0004952f585f66480 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Thu, 8 Sep 2022 21:44:50 +0200 Subject: [PATCH] Add Quit Listener --- .../steamwar/schematicsystem/SchematicSystem.java | 4 ++++ .../commands/SchematicCommandUtils.java | 5 +++++ .../listener/PlayerEventListener.java | 14 ++++++++++++++ 3 files changed, 23 insertions(+) create mode 100644 SchematicSystem_Core/src/de/steamwar/schematicsystem/listener/PlayerEventListener.java diff --git a/SchematicSystem_Core/src/de/steamwar/schematicsystem/SchematicSystem.java b/SchematicSystem_Core/src/de/steamwar/schematicsystem/SchematicSystem.java index 844fc99..7df1177 100644 --- a/SchematicSystem_Core/src/de/steamwar/schematicsystem/SchematicSystem.java +++ b/SchematicSystem_Core/src/de/steamwar/schematicsystem/SchematicSystem.java @@ -22,6 +22,8 @@ package de.steamwar.schematicsystem; import de.steamwar.message.Message; import de.steamwar.schematicsystem.commands.DownloadCommand; import de.steamwar.schematicsystem.commands.SchematicCommand; +import de.steamwar.schematicsystem.listener.PlayerEventListener; +import org.bukkit.Bukkit; import org.bukkit.plugin.java.JavaPlugin; public class SchematicSystem extends JavaPlugin { @@ -35,6 +37,8 @@ public class SchematicSystem extends JavaPlugin { new SchematicCommand(); new DownloadCommand(); + + Bukkit.getPluginManager().registerEvents(new PlayerEventListener(), this); } public static SchematicSystem getInstance() { diff --git a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommandUtils.java b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommandUtils.java index 419a8b3..de97a90 100644 --- a/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommandUtils.java +++ b/SchematicSystem_Core/src/de/steamwar/schematicsystem/commands/SchematicCommandUtils.java @@ -472,6 +472,11 @@ public class SchematicCommandUtils { inv.open(); } + public static void quitPlayer(Player player) { + CACHED_LISTS.remove(player); + PUBLIC_TOGGLED.remove(player); + } + @AllArgsConstructor @With static class CachedSchematicList { diff --git a/SchematicSystem_Core/src/de/steamwar/schematicsystem/listener/PlayerEventListener.java b/SchematicSystem_Core/src/de/steamwar/schematicsystem/listener/PlayerEventListener.java new file mode 100644 index 0000000..7b55277 --- /dev/null +++ b/SchematicSystem_Core/src/de/steamwar/schematicsystem/listener/PlayerEventListener.java @@ -0,0 +1,14 @@ +package de.steamwar.schematicsystem.listener; + +import de.steamwar.schematicsystem.commands.SchematicCommandUtils; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.player.PlayerQuitEvent; + +public class PlayerEventListener implements Listener { + + @EventHandler + public void onPlayerQuit(PlayerQuitEvent event) { + SchematicCommandUtils.quitPlayer(event.getPlayer()); + } +}