diff --git a/build-number.txt b/build-number.txt index ac2fca59..95fa1c9d 100644 --- a/build-number.txt +++ b/build-number.txt @@ -1 +1 @@ -1178 \ No newline at end of file +1186 \ No newline at end of file diff --git a/src/main/java/me/chayapak1/chomens_bot/plugins/PlayersPersistentDataPlugin.java b/src/main/java/me/chayapak1/chomens_bot/plugins/PlayersPersistentDataPlugin.java index 878df6a9..3d315f58 100644 --- a/src/main/java/me/chayapak1/chomens_bot/plugins/PlayersPersistentDataPlugin.java +++ b/src/main/java/me/chayapak1/chomens_bot/plugins/PlayersPersistentDataPlugin.java @@ -29,43 +29,47 @@ public class PlayersPersistentDataPlugin extends PlayersPlugin.Listener { public synchronized void playerJoined(PlayerEntry target) { lock.lock(); - final JsonNode originalElement = playersObject.get(target.profile.getName()); + try { + final JsonNode originalElement = playersObject.get(target.profile.getName()); - ObjectNode object; + ObjectNode object; - if (originalElement == null || originalElement.isNull()) { - object = JsonNodeFactory.instance.objectNode(); - object.put("uuid", target.profile.getIdAsString()); - object.set("ips", JsonNodeFactory.instance.objectNode()); - } else if (originalElement instanceof ObjectNode) { - object = (ObjectNode) originalElement; - } else { - lock.unlock(); - return; - } - - lock.unlock(); - - bot.executorService.submit(() -> { - final CompletableFuture future = bot.players.getPlayerIP(target); - - if (future == null) { - setPersistentEntry(target, object); + if (originalElement == null || originalElement.isNull()) { + object = JsonNodeFactory.instance.objectNode(); + object.put("uuid", target.profile.getIdAsString()); + object.set("ips", JsonNodeFactory.instance.objectNode()); + } else if (originalElement instanceof ObjectNode) { + object = (ObjectNode) originalElement; + } else { + lock.unlock(); return; } - future.completeOnTimeout(null, 5, TimeUnit.SECONDS); + lock.unlock(); - future.thenApplyAsync(output -> { - if (output != null) { - ((ObjectNode) object.get("ips")).put(bot.host + ":" + bot.port, output); + bot.executorService.submit(() -> { + final CompletableFuture future = bot.players.getPlayerIP(target); + + if (future == null) { + setPersistentEntry(target, object); + return; } - setPersistentEntry(target, object); + future.completeOnTimeout(null, 5, TimeUnit.SECONDS); - return output; + future.thenApplyAsync(output -> { + if (output != null) { + ((ObjectNode) object.get("ips")).put(bot.host + ":" + bot.port, output); + } + + setPersistentEntry(target, object); + + return output; + }); }); - }); + } catch (Exception e) { + e.printStackTrace(); + } } // is this bad? diff --git a/src/main/java/me/chayapak1/chomens_bot/plugins/TeamPlugin.java b/src/main/java/me/chayapak1/chomens_bot/plugins/TeamPlugin.java index 8604095a..badffb85 100644 --- a/src/main/java/me/chayapak1/chomens_bot/plugins/TeamPlugin.java +++ b/src/main/java/me/chayapak1/chomens_bot/plugins/TeamPlugin.java @@ -6,27 +6,25 @@ import org.geysermc.mcprotocollib.network.Session; import org.geysermc.mcprotocollib.network.packet.Packet; import org.geysermc.mcprotocollib.protocol.packet.ingame.clientbound.scoreboard.ClientboundSetPlayerTeamPacket; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; +import java.util.*; public class TeamPlugin extends Bot.Listener { - public final List teams = new ArrayList<>(); + public final List teams = Collections.synchronizedList(new ArrayList<>()); public TeamPlugin (Bot bot) { bot.addListener(this); } - public Team findTeamByName (String name) { - for (Team team : teams) { + public synchronized Team findTeamByName (String name) { + for (Team team : new ArrayList<>(teams)) { if (team.teamName.equals(name)) return team; } return null; } - public Team findTeamByMember (String member) { - for (Team team : teams) { + public synchronized Team findTeamByMember (String member) { + for (Team team : new ArrayList<>(teams)) { if (team.players.contains(member)) return team; }