Skip to content

Commit

Permalink
fix: add invulnerability flag to cached user in map, close #728
Browse files Browse the repository at this point in the history
  • Loading branch information
WiIIiam278 committed Dec 13, 2024
1 parent 5d63899 commit 65aa93c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand All @@ -170,6 +172,7 @@ public void removeInvulnerabilityIfPermitted() {
bukkitPlayer.setInvulnerable(false);
}
bukkitPlayer.getPersistentDataContainer().remove(INVULNERABLE_KEY);
markedAsInvulnerable = false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -178,6 +178,7 @@ public void handleInvulnerability() {
}
player.setInvulnerable(true);
player.getCommandTags().add(INVULNERABLE_TAG);
markedAsInvulnerable = true;
plugin.runSyncDelayed(this::removeInvulnerabilityIfPermitted, this, invulnerableTicks);
}

Expand All @@ -187,6 +188,7 @@ public void removeInvulnerabilityIfPermitted() {
player.setInvulnerable(false);
}
player.removeCommandTag(INVULNERABLE_TAG);
markedAsInvulnerable = false;
}

@NotNull
Expand Down

0 comments on commit 65aa93c

Please sign in to comment.