Merge pull request 'master' (#1) from mc/VTools:master into master
Reviewed-on: #1
This commit is contained in:
commit
52b3a5016d
1 changed files with 26 additions and 26 deletions
|
@ -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<RegisteredServer> registeredServers = new ArrayList<>(server.getAllServers());
|
||||
for (RegisteredServer registeredServer : registeredServers) {
|
||||
List<Player> onServer = ImmutableList.copyOf(registeredServer.getPlayersConnected());
|
||||
LinkedList<Player> 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<UpdateRequest> 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(()->{
|
||||
|
|
Loading…
Reference in a new issue