1
0
Fork 0
forked from mc/VTools

master #1

Merged
NaAlOH4 merged 3 commits from mc/VTools:master into master 2023-10-28 15:23:28 +08:00
Showing only changes of commit d1f9dc803d - Show all commits

View file

@ -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,19 +231,29 @@ 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;
}
updateRequests.add(new UpdateRequest(2));
joinLeftAnnounce(String.format("%s left the proxy", username));
}
updateRequests.add(new UpdateRequest());
}
@Subscribe
public void onServerPostConnect(ServerPostConnectEvent event){
@ -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(()->{