1
0
Fork 0
forked from mc/VTools

Compare commits

..

No commits in common. "52b3a5016daa2572995c0ed1c4b36fe2a2e24fba" and "aebff1a12ad6f39e2489075ff868d4f159d888fc" have entirely different histories.

View file

@ -30,7 +30,9 @@ import java.io.File;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.*; import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.LinkedBlockingQueue;
import java.util.function.BiConsumer; import java.util.function.BiConsumer;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -162,12 +164,7 @@ public class TGBridge {
out.add(String.format(fmt, server.getAllPlayers().size())); out.add(String.format(fmt, server.getAllPlayers().size()));
List<RegisteredServer> registeredServers = new ArrayList<>(server.getAllServers()); List<RegisteredServer> registeredServers = new ArrayList<>(server.getAllServers());
for (RegisteredServer registeredServer : registeredServers) { for (RegisteredServer registeredServer : registeredServers) {
LinkedList<Player> onServer = new LinkedList<>(); List<Player> onServer = ImmutableList.copyOf(registeredServer.getPlayersConnected());
for (Player player:registeredServer.getPlayersConnected()){
if(!lastDisconnect.equals(player.getUsername())){
onServer.add(player);
}
}
if (!onServer.isEmpty()) { if (!onServer.isEmpty()) {
out.add(String.format("[%s] (%d): %s", out.add(String.format("[%s] (%d): %s",
registeredServer.getServerInfo().getName(), registeredServer.getServerInfo().getName(),
@ -231,30 +228,20 @@ public class TGBridge {
public void onServerConnected(ServerConnectedEvent event) { public void onServerConnected(ServerConnectedEvent event) {
if (event.getPreviousServer().isEmpty()) { if (event.getPreviousServer().isEmpty()) {
if (!event.getPlayer().hasPermission("vtools.globalchat.bypassbridge.join")) { if (!event.getPlayer().hasPermission("vtools.globalchat.bypassbridge.join")) {
String username = event.getPlayer().getUsername(); joinLeftAnnounce(String.format("%s joined the proxy", event.getPlayer().getUsername()));
if(lastDisconnect.equals(username)){
lastDisconnect="";
}
joinLeftAnnounce(String.format("%s joined the proxy", username));
} }
} }
updateRequests.add(new UpdateRequest()); updateRequests.add(new UpdateRequest());
} }
private String lastDisconnect = "";
@Subscribe @Subscribe
public void onDisconnect(DisconnectEvent event) { public void onDisconnect(DisconnectEvent event) {
if (!event.getPlayer().hasPermission("vtools.globalchat.bypassbridge.join")) { if (!event.getPlayer().hasPermission("vtools.globalchat.bypassbridge.join")) {
String username = event.getPlayer().getUsername(); joinLeftAnnounce(String.format("%s left the proxy", event.getPlayer().getUsername()));
if(username!=null) {
lastDisconnect = username;
}
joinLeftAnnounce(String.format("%s left the proxy", username));
} }
updateRequests.add(new UpdateRequest()); updateRequests.add(new UpdateRequest(2));
} }
@Subscribe @Subscribe
public void onServerPostConnect(ServerPostConnectEvent event){ public void onServerPostConnect(ServerPostConnectEvent event){
updateRequests.add(new UpdateRequest()); updateRequests.add(new UpdateRequest());
@ -264,7 +251,17 @@ public class TGBridge {
private boolean PROXY_SHUT_DOWN = false; private boolean PROXY_SHUT_DOWN = false;
private static class UpdateRequest {} private static class UpdateRequest {
int updateTimes;
UpdateRequest() {
this(1);
}
UpdateRequest(int updateTimes) {
this.updateTimes = updateTimes;
}
}
private LinkedBlockingQueue<UpdateRequest> updateRequests = new LinkedBlockingQueue<>(); private LinkedBlockingQueue<UpdateRequest> updateRequests = new LinkedBlockingQueue<>();
@ -275,22 +272,25 @@ public class TGBridge {
setOnlineStatusNotAvailable(); setOnlineStatusNotAvailable();
return; return;
} }
int maxiterationNum = 0;
UpdateRequest oldestRequest = null; UpdateRequest oldestRequest = null;
try { try {
oldestRequest = updateRequests.take(); oldestRequest = updateRequests.take();
} catch (InterruptedException ignored) {} } catch (InterruptedException ignored) {}
if (oldestRequest == null) { if (oldestRequest == null) continue;
plugin.logger.warn("updateRequests.take() return a null value, why?"); maxiterationNum = Math.max(maxiterationNum, oldestRequest.updateTimes - 1);
while (!updateRequests.isEmpty()){
try { try {
Thread.sleep(1000); maxiterationNum = Math.max(maxiterationNum, updateRequests.take().updateTimes - 1);
} catch (InterruptedException ignored) {} } catch (InterruptedException ignored) {}
continue;
} }
updateRequests.clear();
if (!updateOnlineStatus()) { if (!updateOnlineStatus()) {
updateRequests.add(oldestRequest); // 更新失败 回去吧您内 updateRequests.add(oldestRequest); // 更新失败 回去吧您内
} }
if(maxiterationNum>0){
updateRequests.add(new UpdateRequest(maxiterationNum));
}
} }
}).start(); }).start();
new Thread(()->{ new Thread(()->{