From 65aa93c3dada1ea550446d41f6e18e1890fc4540 Mon Sep 17 00:00:00 2001 From: William Date: Fri, 13 Dec 2024 17:50:41 +0000 Subject: [PATCH] fix: add invulnerability flag to cached user in map, close #728 --- .../main/java/net/william278/huskhomes/user/BukkitUser.java | 5 ++++- .../main/java/net/william278/huskhomes/user/OnlineUser.java | 1 + .../main/java/net/william278/huskhomes/user/FabricUser.java | 4 +++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/bukkit/src/main/java/net/william278/huskhomes/user/BukkitUser.java b/bukkit/src/main/java/net/william278/huskhomes/user/BukkitUser.java index 5de78ffd..b7ac17f9 100644 --- a/bukkit/src/main/java/net/william278/huskhomes/user/BukkitUser.java +++ b/bukkit/src/main/java/net/william278/huskhomes/user/BukkitUser.java @@ -150,7 +150,8 @@ public boolean isVanished() { @Override public boolean hasInvulnerability() { - return bukkitPlayer.getPersistentDataContainer().has(INVULNERABLE_KEY, PersistentDataType.INTEGER); + return markedAsInvulnerable || bukkitPlayer.getPersistentDataContainer() + .has(INVULNERABLE_KEY, PersistentDataType.INTEGER); } @Override @@ -159,6 +160,7 @@ public void handleInvulnerability() { if (invulnerableTicks <= 0) { return; } + markedAsInvulnerable = true; bukkitPlayer.getPersistentDataContainer().set(INVULNERABLE_KEY, PersistentDataType.INTEGER, 1); bukkitPlayer.setInvulnerable(true); plugin.runSyncDelayed(this::removeInvulnerabilityIfPermitted, this, invulnerableTicks); @@ -170,6 +172,7 @@ public void removeInvulnerabilityIfPermitted() { bukkitPlayer.setInvulnerable(false); } bukkitPlayer.getPersistentDataContainer().remove(INVULNERABLE_KEY); + markedAsInvulnerable = false; } } diff --git a/common/src/main/java/net/william278/huskhomes/user/OnlineUser.java b/common/src/main/java/net/william278/huskhomes/user/OnlineUser.java index d3559e1c..3d86cbed 100644 --- a/common/src/main/java/net/william278/huskhomes/user/OnlineUser.java +++ b/common/src/main/java/net/william278/huskhomes/user/OnlineUser.java @@ -45,6 +45,7 @@ public abstract class OnlineUser extends User implements Teleportable, CommandUser { protected final HuskHomes plugin; + protected boolean markedAsInvulnerable = false; protected OnlineUser(@NotNull UUID uuid, @NotNull String username, @NotNull HuskHomes plugin) { super(uuid, username); diff --git a/fabric/src/main/java/net/william278/huskhomes/user/FabricUser.java b/fabric/src/main/java/net/william278/huskhomes/user/FabricUser.java index da142b45..d224027b 100644 --- a/fabric/src/main/java/net/william278/huskhomes/user/FabricUser.java +++ b/fabric/src/main/java/net/william278/huskhomes/user/FabricUser.java @@ -167,7 +167,7 @@ public boolean isVanished() { @Override public boolean hasInvulnerability() { - return player.getCommandTags().contains(INVULNERABLE_TAG); + return markedAsInvulnerable || player.getCommandTags().contains(INVULNERABLE_TAG); } @Override @@ -178,6 +178,7 @@ public void handleInvulnerability() { } player.setInvulnerable(true); player.getCommandTags().add(INVULNERABLE_TAG); + markedAsInvulnerable = true; plugin.runSyncDelayed(this::removeInvulnerabilityIfPermitted, this, invulnerableTicks); } @@ -187,6 +188,7 @@ public void removeInvulnerabilityIfPermitted() { player.setInvulnerable(false); } player.removeCommandTag(INVULNERABLE_TAG); + markedAsInvulnerable = false; } @NotNull