Skip to content

Commit

Permalink
fix removeOnlinePlayer no thread safe
Browse files Browse the repository at this point in the history
  • Loading branch information
SenseiTarzan committed Dec 24, 2024
1 parent 843842f commit 849d85f
Showing 1 changed file with 2 additions and 13 deletions.
15 changes: 2 additions & 13 deletions src/main/java/org/sculk/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import java.nio.file.Paths;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;

import static org.sculk.Sculk.CODE_NAME;
import static org.sculk.Sculk.CODE_VERSION;
Expand Down Expand Up @@ -95,8 +96,7 @@ public class Server {
private final Config banByName;
private final Config banByIp;

private final Map<UUID, Player> playerList = new HashMap<>();
private final Map<SocketAddress, Player> players = new HashMap<>();
private final Map<UUID, Player> playerList = new ConcurrentHashMap<>();

@Getter
private String motd;
Expand Down Expand Up @@ -238,7 +238,6 @@ public CompletableFuture<Player> createPlayer(SculkServerSession session, Client
try {
Constructor<? extends Player> constructor = clazz.getConstructor(Server.class, SculkServerSession.class, ClientChainData.class, NbtMap.class);
player = constructor.newInstance(this, session, info, NbtMap.EMPTY);
this.addPlayer(session.getSocketAddress(), player);
} catch (NoSuchMethodException | InvocationTargetException | InstantiationException | IllegalAccessException e) {
this.logger.warn(FAILED_TO_CREATE_PLAYER, e);
throw new RuntimeException(e);
Expand All @@ -258,12 +257,6 @@ private Path createDirectories(String dataPath, String... directories) {
return Path.of(dataPath, directories[0]);
}

public void broadcastPacket(BedrockPacket packet) {
for (Player player : this.players.values()) {
player.sendDataPacket(packet);
}
}

public EventManager getEventManager() {
return eventManager;
}
Expand Down Expand Up @@ -347,10 +340,6 @@ public Operators getOperators() {
return this.operators;
}

public void addPlayer(SocketAddress socketAddress, Player player) {
this.players.put(socketAddress, player);
}

public boolean addOnlinePlayer(Player player) {
PlayerLoginEvent event = new PlayerLoginEvent(player, "Plugin reason");
event.call();
Expand Down

0 comments on commit 849d85f

Please sign in to comment.