Tweak concurrency handling

This commit is contained in:
William 2023-02-24 18:29:35 +00:00
parent be1756fa9b
commit 0fb1a3146a
No known key found for this signature in database
2 changed files with 13 additions and 15 deletions

View File

@ -8,18 +8,18 @@ import net.william278.velocitab.Velocitab;
import net.william278.velocitab.player.TabPlayer;
import org.jetbrains.annotations.NotNull;
import java.util.HashMap;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
public class ScoreboardManager {
private final Velocitab plugin;
private final HashMap<UUID, String> fauxTeams;
private final ConcurrentHashMap<UUID, String> fauxTeams;
public ScoreboardManager(@NotNull Velocitab velocitab) {
this.plugin = velocitab;
this.fauxTeams = new HashMap<>();
this.fauxTeams = new ConcurrentHashMap<>();
}
public void registerPacket() {
@ -48,14 +48,14 @@ public class ScoreboardManager {
public void removeTeam(@NotNull Player member) {
final UUID uuid = member.getUniqueId();
if (!fauxTeams.containsKey(uuid)) {
return;
}
final UpdateTeamsPacket removeTeamPacket = UpdateTeamsPacket.remove(fauxTeams.get(uuid));
final String teamName = fauxTeams.getOrDefault(uuid, null);
if (teamName != null) {
final UpdateTeamsPacket removeTeamPacket = UpdateTeamsPacket.remove(teamName);
plugin.getServer().getAllPlayers().stream()
.map(Player::getUniqueId)
.map(Protocolize.playerProvider()::player)
.forEach(protocolPlayer -> protocolPlayer.sendPacket(removeTeamPacket));
}
fauxTeams.remove(uuid);
}

View File

@ -60,12 +60,10 @@ public class PlayerTabList {
public void updatePlayer(@NotNull TabPlayer tabPlayer) {
plugin.getServer().getScheduler()
.buildTask(plugin, () -> {
synchronized (this) {
// Update the player's team sorting
players.remove(tabPlayer);
players.add(tabPlayer);
}
// Update the player's team sorting
plugin.getScoreboardManager().setPlayerTeam(tabPlayer);
updateList();