From d1f9dc803d93066f0df9852839adb54c6bccec3d Mon Sep 17 00:00:00 2001 From: Sodium-Aluminate Date: Mon, 29 May 2023 00:12:32 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8D=E4=BC=98=E9=9B=85=E7=9A=84fix=20bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../de/strifel/VTools/listeners/TGBridge.java | 52 +++++++++---------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/src/main/java/de/strifel/VTools/listeners/TGBridge.java b/src/main/java/de/strifel/VTools/listeners/TGBridge.java index e5fada4..ec89215 100644 --- a/src/main/java/de/strifel/VTools/listeners/TGBridge.java +++ b/src/main/java/de/strifel/VTools/listeners/TGBridge.java @@ -30,9 +30,7 @@ import java.io.File; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.concurrent.LinkedBlockingQueue; import java.util.function.BiConsumer; import java.util.stream.Collectors; @@ -164,7 +162,12 @@ public class TGBridge { out.add(String.format(fmt, server.getAllPlayers().size())); List registeredServers = new ArrayList<>(server.getAllServers()); for (RegisteredServer registeredServer : registeredServers) { - List onServer = ImmutableList.copyOf(registeredServer.getPlayersConnected()); + LinkedList onServer = new LinkedList<>(); + for (Player player:registeredServer.getPlayersConnected()){ + if(!lastDisconnect.equals(player.getUsername())){ + onServer.add(player); + } + } if (!onServer.isEmpty()) { out.add(String.format("[%s] (%d): %s", registeredServer.getServerInfo().getName(), @@ -228,20 +231,30 @@ public class TGBridge { public void onServerConnected(ServerConnectedEvent event) { if (event.getPreviousServer().isEmpty()) { if (!event.getPlayer().hasPermission("vtools.globalchat.bypassbridge.join")) { - joinLeftAnnounce(String.format("%s joined the proxy", event.getPlayer().getUsername())); + String username = event.getPlayer().getUsername(); + if(lastDisconnect.equals(username)){ + lastDisconnect=""; + } + joinLeftAnnounce(String.format("%s joined the proxy", username)); } } updateRequests.add(new UpdateRequest()); } + private String lastDisconnect = ""; @Subscribe public void onDisconnect(DisconnectEvent event) { if (!event.getPlayer().hasPermission("vtools.globalchat.bypassbridge.join")) { - joinLeftAnnounce(String.format("%s left the proxy", event.getPlayer().getUsername())); + String username = event.getPlayer().getUsername(); + if(username!=null) { + lastDisconnect = username; + } + joinLeftAnnounce(String.format("%s left the proxy", username)); } - updateRequests.add(new UpdateRequest(2)); + updateRequests.add(new UpdateRequest()); } + @Subscribe public void onServerPostConnect(ServerPostConnectEvent event){ updateRequests.add(new UpdateRequest()); @@ -251,17 +264,7 @@ public class TGBridge { private boolean PROXY_SHUT_DOWN = false; - private static class UpdateRequest { - int updateTimes; - - UpdateRequest() { - this(1); - } - - UpdateRequest(int updateTimes) { - this.updateTimes = updateTimes; - } - } + private static class UpdateRequest {} private LinkedBlockingQueue updateRequests = new LinkedBlockingQueue<>(); @@ -272,25 +275,22 @@ public class TGBridge { setOnlineStatusNotAvailable(); return; } - int maxiterationNum = 0; UpdateRequest oldestRequest = null; try { oldestRequest = updateRequests.take(); } catch (InterruptedException ignored) {} - if (oldestRequest == null) continue; - maxiterationNum = Math.max(maxiterationNum, oldestRequest.updateTimes - 1); - while (!updateRequests.isEmpty()){ + if (oldestRequest == null) { + plugin.logger.warn("updateRequests.take() return a null value, why?"); try { - maxiterationNum = Math.max(maxiterationNum, updateRequests.take().updateTimes - 1); + Thread.sleep(1000); } catch (InterruptedException ignored) {} + continue; } + updateRequests.clear(); if (!updateOnlineStatus()) { updateRequests.add(oldestRequest); // 更新失败 回去吧您内 } - if(maxiterationNum>0){ - updateRequests.add(new UpdateRequest(maxiterationNum)); - } } }).start(); new Thread(()->{