forked from SteamWar/SteamWar
Synchronize access to skins map in PlayerSkinHandler to ensure thread safety and prevent race conditions.
This commit is contained in:
@@ -54,7 +54,7 @@ public class PlayerSkinHandler extends PacketHandler {
|
|||||||
VelocityCore.getProxy().getEventManager().register(VelocityCore.get(), this);
|
VelocityCore.getProxy().getEventManager().register(VelocityCore.get(), this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<UUID, SkinData> skins = new LinkedHashMap<>(maxCacheSize, 1, true) {
|
private final Map<UUID, SkinData> skins = new LinkedHashMap<>(maxCacheSize, 1, true) {
|
||||||
@Override
|
@Override
|
||||||
protected boolean removeEldestEntry(Map.Entry<UUID, SkinData> eldest) {
|
protected boolean removeEldestEntry(Map.Entry<UUID, SkinData> eldest) {
|
||||||
return size() > maxCacheSize;
|
return size() > maxCacheSize;
|
||||||
@@ -64,6 +64,7 @@ public class PlayerSkinHandler extends PacketHandler {
|
|||||||
@Handler
|
@Handler
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
public void handle(PlayerSkinRequestPacket packet) {
|
public void handle(PlayerSkinRequestPacket packet) {
|
||||||
|
synchronized (skins) {
|
||||||
if (skins.containsKey(packet.getUuid())) {
|
if (skins.containsKey(packet.getUuid())) {
|
||||||
SkinData skinData = skins.get(packet.getUuid());
|
SkinData skinData = skins.get(packet.getUuid());
|
||||||
NetworkSender.send(((ServerMetaInfo) packet.getMetaInfos()).sender().getServer(), new PlayerSkinResponsePacket(packet.getUuid(), skinData.skin, skinData.signature));
|
NetworkSender.send(((ServerMetaInfo) packet.getMetaInfos()).sender().getServer(), new PlayerSkinResponsePacket(packet.getUuid(), skinData.skin, skinData.signature));
|
||||||
@@ -98,6 +99,7 @@ public class PlayerSkinHandler extends PacketHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onPostLogin(PostLoginEvent event) {
|
public void onPostLogin(PostLoginEvent event) {
|
||||||
@@ -105,6 +107,8 @@ public class PlayerSkinHandler extends PacketHandler {
|
|||||||
GameProfile gameProfile = player.getGameProfile();
|
GameProfile gameProfile = player.getGameProfile();
|
||||||
GameProfile.Property property = gameProfile.getProperties().stream().filter(p -> p.getName().equals("textures")).findFirst().orElse(null);
|
GameProfile.Property property = gameProfile.getProperties().stream().filter(p -> p.getName().equals("textures")).findFirst().orElse(null);
|
||||||
if (property == null) return;
|
if (property == null) return;
|
||||||
|
|
||||||
|
synchronized (skins) {
|
||||||
skins.put(player.getUniqueId(), new SkinData(property.getValue(), property.getSignature()));
|
skins.put(player.getUniqueId(), new SkinData(property.getValue(), property.getSignature()));
|
||||||
|
|
||||||
Set<UUID> uuidSet = skins.keySet();
|
Set<UUID> uuidSet = skins.keySet();
|
||||||
@@ -114,6 +118,7 @@ public class PlayerSkinHandler extends PacketHandler {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public record SkinData(String skin, String signature) {}
|
public record SkinData(String skin, String signature) {}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user