From 294f24f2788bbb572ef84a8512c4117e9143755f Mon Sep 17 00:00:00 2001 From: William Date: Sun, 10 Nov 2024 14:28:24 +0000 Subject: [PATCH] fix: ensure caching respects player state --- .../net/william278/huskhomes/listener/BukkitEventListener.java | 1 + .../java/net/william278/huskhomes/user/BukkitUserProvider.java | 2 +- .../java/net/william278/huskhomes/user/FabricUserProvider.java | 2 +- gradle.properties | 2 +- .../net/william278/huskhomes/listener/PaperEventListener.java | 1 + 5 files changed, 5 insertions(+), 3 deletions(-) diff --git a/bukkit/src/main/java/net/william278/huskhomes/listener/BukkitEventListener.java b/bukkit/src/main/java/net/william278/huskhomes/listener/BukkitEventListener.java index bc3cb167..b9e5de11 100644 --- a/bukkit/src/main/java/net/william278/huskhomes/listener/BukkitEventListener.java +++ b/bukkit/src/main/java/net/william278/huskhomes/listener/BukkitEventListener.java @@ -65,6 +65,7 @@ public void onPlayerRespawn(PlayerRespawnEvent event) { if (usePaperEvents) { return; } + getPlugin().getOnlineUserMap().remove(event.getPlayer().getUniqueId()); super.handlePlayerRespawn(getPlugin().getOnlineUser(event.getPlayer())); } diff --git a/bukkit/src/main/java/net/william278/huskhomes/user/BukkitUserProvider.java b/bukkit/src/main/java/net/william278/huskhomes/user/BukkitUserProvider.java index 6dcf32a1..b1162ecc 100644 --- a/bukkit/src/main/java/net/william278/huskhomes/user/BukkitUserProvider.java +++ b/bukkit/src/main/java/net/william278/huskhomes/user/BukkitUserProvider.java @@ -40,7 +40,7 @@ default BukkitUser getOnlineUser(@Nullable Player player) { throw new IllegalArgumentException("Player is not online"); } BukkitUser user = (BukkitUser) getOnlineUserMap().get(player.getUniqueId()); - if (user == null) { + if (user == null || !user.getPlayer().isOnline()) { user = BukkitUser.adapt(player, getPlugin()); getOnlineUserMap().put(player.getUniqueId(), user); return user; diff --git a/fabric/src/main/java/net/william278/huskhomes/user/FabricUserProvider.java b/fabric/src/main/java/net/william278/huskhomes/user/FabricUserProvider.java index 8cdf9752..fcaab767 100644 --- a/fabric/src/main/java/net/william278/huskhomes/user/FabricUserProvider.java +++ b/fabric/src/main/java/net/william278/huskhomes/user/FabricUserProvider.java @@ -40,7 +40,7 @@ default FabricUser getOnlineUser(@Nullable ServerPlayerEntity player) { throw new IllegalArgumentException("Player is not online"); } FabricUser user = (FabricUser) getOnlineUserMap().get(player.getUuid()); - if (user == null) { + if (user == null || user.getPlayer().isRemoved() || user.getPlayer().isDisconnected()) { user = FabricUser.adapt(player, getPlugin()); getOnlineUserMap().put(player.getUuid(), user); return user; diff --git a/gradle.properties b/gradle.properties index 04878c16..e2deb14c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,7 +4,7 @@ org.gradle.jvmargs='-Dfile.encoding=UTF-8' org.gradle.daemon=true # Plugin metadata -plugin_version=4.8.1 +plugin_version=4.8.2 plugin_archive=huskhomes plugin_description=The powerful & intuitive homes, warps, and teleportation suite diff --git a/paper/src/main/java/net/william278/huskhomes/listener/PaperEventListener.java b/paper/src/main/java/net/william278/huskhomes/listener/PaperEventListener.java index 86607a05..15cb22c1 100644 --- a/paper/src/main/java/net/william278/huskhomes/listener/PaperEventListener.java +++ b/paper/src/main/java/net/william278/huskhomes/listener/PaperEventListener.java @@ -65,6 +65,7 @@ public void onPlayerUpdateRespawnLocation(PlayerSetSpawnEvent event) { @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) @Override public void onPlayerRespawn(PlayerRespawnEvent event) { + getPlugin().getOnlineUserMap().remove(event.getPlayer().getUniqueId()); if (event.getRespawnReason() != PlayerRespawnEvent.RespawnReason.DEATH) { return; }