fix: more weird kind of "fixes"

This commit is contained in:
ChomeNS
2024-12-05 11:27:51 +07:00
parent d0d28cc55b
commit 55f4d1fece
3 changed files with 38 additions and 36 deletions

View File

@@ -1 +1 @@
1178
1186

View File

@@ -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<String> 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<String> 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?

View File

@@ -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<Team> teams = new ArrayList<>();
public final List<Team> 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;
}