forked from Upstream/Velocitab
Tweak concurrency handling
This commit is contained in:
parent
be1756fa9b
commit
0fb1a3146a
@ -8,18 +8,18 @@ import net.william278.velocitab.Velocitab;
|
|||||||
import net.william278.velocitab.player.TabPlayer;
|
import net.william278.velocitab.player.TabPlayer;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
public class ScoreboardManager {
|
public class ScoreboardManager {
|
||||||
|
|
||||||
private final Velocitab plugin;
|
private final Velocitab plugin;
|
||||||
|
|
||||||
private final HashMap<UUID, String> fauxTeams;
|
private final ConcurrentHashMap<UUID, String> fauxTeams;
|
||||||
|
|
||||||
public ScoreboardManager(@NotNull Velocitab velocitab) {
|
public ScoreboardManager(@NotNull Velocitab velocitab) {
|
||||||
this.plugin = velocitab;
|
this.plugin = velocitab;
|
||||||
this.fauxTeams = new HashMap<>();
|
this.fauxTeams = new ConcurrentHashMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void registerPacket() {
|
public void registerPacket() {
|
||||||
@ -48,14 +48,14 @@ public class ScoreboardManager {
|
|||||||
|
|
||||||
public void removeTeam(@NotNull Player member) {
|
public void removeTeam(@NotNull Player member) {
|
||||||
final UUID uuid = member.getUniqueId();
|
final UUID uuid = member.getUniqueId();
|
||||||
if (!fauxTeams.containsKey(uuid)) {
|
final String teamName = fauxTeams.getOrDefault(uuid, null);
|
||||||
return;
|
if (teamName != null) {
|
||||||
}
|
final UpdateTeamsPacket removeTeamPacket = UpdateTeamsPacket.remove(teamName);
|
||||||
final UpdateTeamsPacket removeTeamPacket = UpdateTeamsPacket.remove(fauxTeams.get(uuid));
|
|
||||||
plugin.getServer().getAllPlayers().stream()
|
plugin.getServer().getAllPlayers().stream()
|
||||||
.map(Player::getUniqueId)
|
.map(Player::getUniqueId)
|
||||||
.map(Protocolize.playerProvider()::player)
|
.map(Protocolize.playerProvider()::player)
|
||||||
.forEach(protocolPlayer -> protocolPlayer.sendPacket(removeTeamPacket));
|
.forEach(protocolPlayer -> protocolPlayer.sendPacket(removeTeamPacket));
|
||||||
|
}
|
||||||
fauxTeams.remove(uuid);
|
fauxTeams.remove(uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,12 +60,10 @@ public class PlayerTabList {
|
|||||||
public void updatePlayer(@NotNull TabPlayer tabPlayer) {
|
public void updatePlayer(@NotNull TabPlayer tabPlayer) {
|
||||||
plugin.getServer().getScheduler()
|
plugin.getServer().getScheduler()
|
||||||
.buildTask(plugin, () -> {
|
.buildTask(plugin, () -> {
|
||||||
synchronized (this) {
|
// Update the player's team sorting
|
||||||
players.remove(tabPlayer);
|
players.remove(tabPlayer);
|
||||||
players.add(tabPlayer);
|
players.add(tabPlayer);
|
||||||
}
|
|
||||||
|
|
||||||
// Update the player's team sorting
|
|
||||||
plugin.getScoreboardManager().setPlayerTeam(tabPlayer);
|
plugin.getScoreboardManager().setPlayerTeam(tabPlayer);
|
||||||
|
|
||||||
updateList();
|
updateList();
|
||||||
|
Loading…
Reference in New Issue
Block a user