Skip to content

Commit

Permalink
Trial delaying scoreboard removal on death
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed Feb 1, 2023
1 parent 3b00f77 commit b21af8d
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions main/src/main/java/net/citizensnpcs/trait/ScoreboardTrait.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.scoreboard.Scoreboard;
import org.bukkit.scoreboard.Team;
Expand Down Expand Up @@ -90,15 +91,17 @@ public void onDespawn() {
npc.data().remove(NPC.Metadata.SCOREBOARD_FAKE_TEAM_NAME);
if (team == null || name == null || !team.hasEntry(name))
return;
if (team.getSize() == 1) {
for (Player player : Bukkit.getOnlinePlayers()) {
metadata.remove(player.getUniqueId(), team.getName());
NMS.sendTeamPacket(player, team, 1);
Bukkit.getScheduler().scheduleSyncDelayedTask(CitizensAPI.getPlugin(), () -> {
if (team.getSize() == 1) {
for (Player player : Bukkit.getOnlinePlayers()) {
metadata.remove(player.getUniqueId(), team.getName());
NMS.sendTeamPacket(player, team, 1);
}
team.unregister();
} else {
team.removeEntry(name);
}
team.unregister();
} else {
team.removeEntry(name);
}
}, npc.getEntity() instanceof LivingEntity ? 20 : 2);
}

@Override
Expand Down

0 comments on commit b21af8d

Please sign in to comment.