Compare commits
No commits in common. "52b3a5016daa2572995c0ed1c4b36fe2a2e24fba" and "aebff1a12ad6f39e2489075ff868d4f159d888fc" have entirely different histories.
52b3a5016d
...
aebff1a12a
1 changed files with 26 additions and 26 deletions
|
@ -30,7 +30,9 @@ import java.io.File;
|
|||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
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.function.BiConsumer;
|
||||
import java.util.stream.Collectors;
|
||||
|
@ -162,12 +164,7 @@ public class TGBridge {
|
|||
out.add(String.format(fmt, server.getAllPlayers().size()));
|
||||
List<RegisteredServer> registeredServers = new ArrayList<>(server.getAllServers());
|
||||
for (RegisteredServer registeredServer : registeredServers) {
|
||||
LinkedList<Player> onServer = new LinkedList<>();
|
||||
for (Player player:registeredServer.getPlayersConnected()){
|
||||
if(!lastDisconnect.equals(player.getUsername())){
|
||||
onServer.add(player);
|
||||
}
|
||||
}
|
||||
List<Player> onServer = ImmutableList.copyOf(registeredServer.getPlayersConnected());
|
||||
if (!onServer.isEmpty()) {
|
||||
out.add(String.format("[%s] (%d): %s",
|
||||
registeredServer.getServerInfo().getName(),
|
||||
|
@ -231,29 +228,19 @@ public class TGBridge {
|
|||
public void onServerConnected(ServerConnectedEvent event) {
|
||||
if (event.getPreviousServer().isEmpty()) {
|
||||
if (!event.getPlayer().hasPermission("vtools.globalchat.bypassbridge.join")) {
|
||||
String username = event.getPlayer().getUsername();
|
||||
if(lastDisconnect.equals(username)){
|
||||
lastDisconnect="";
|
||||
}
|
||||
joinLeftAnnounce(String.format("%s joined the proxy", username));
|
||||
joinLeftAnnounce(String.format("%s joined the proxy", event.getPlayer().getUsername()));
|
||||
}
|
||||
}
|
||||
updateRequests.add(new UpdateRequest());
|
||||
}
|
||||
|
||||
private String lastDisconnect = "";
|
||||
@Subscribe
|
||||
public void onDisconnect(DisconnectEvent event) {
|
||||
if (!event.getPlayer().hasPermission("vtools.globalchat.bypassbridge.join")) {
|
||||
String username = event.getPlayer().getUsername();
|
||||
if(username!=null) {
|
||||
lastDisconnect = username;
|
||||
joinLeftAnnounce(String.format("%s left the proxy", event.getPlayer().getUsername()));
|
||||
}
|
||||
joinLeftAnnounce(String.format("%s left the proxy", username));
|
||||
updateRequests.add(new UpdateRequest(2));
|
||||
}
|
||||
updateRequests.add(new UpdateRequest());
|
||||
}
|
||||
|
||||
|
||||
@Subscribe
|
||||
public void onServerPostConnect(ServerPostConnectEvent event){
|
||||
|
@ -264,7 +251,17 @@ public class TGBridge {
|
|||
|
||||
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<>();
|
||||
|
||||
|
@ -275,22 +272,25 @@ public class TGBridge {
|
|||
setOnlineStatusNotAvailable();
|
||||
return;
|
||||
}
|
||||
int maxiterationNum = 0;
|
||||
UpdateRequest oldestRequest = null;
|
||||
try {
|
||||
oldestRequest = updateRequests.take();
|
||||
} catch (InterruptedException ignored) {}
|
||||
if (oldestRequest == null) {
|
||||
plugin.logger.warn("updateRequests.take() return a null value, why?");
|
||||
if (oldestRequest == null) continue;
|
||||
maxiterationNum = Math.max(maxiterationNum, oldestRequest.updateTimes - 1);
|
||||
while (!updateRequests.isEmpty()){
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
maxiterationNum = Math.max(maxiterationNum, updateRequests.take().updateTimes - 1);
|
||||
} catch (InterruptedException ignored) {}
|
||||
continue;
|
||||
}
|
||||
updateRequests.clear();
|
||||
|
||||
if (!updateOnlineStatus()) {
|
||||
updateRequests.add(oldestRequest); // 更新失败 回去吧您内
|
||||
}
|
||||
if(maxiterationNum>0){
|
||||
updateRequests.add(new UpdateRequest(maxiterationNum));
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
new Thread(()->{
|
||||
|
|
Loading…
Reference in a new issue