From ce0fe6242814ff530da4cb1b5a2d25bacdcb6dff Mon Sep 17 00:00:00 2001 From: Tarek Date: Wed, 12 Dec 2018 19:54:14 +0100 Subject: [PATCH 1/4] reformat code --- .../api/player/PermissionProvider.java | 8 ++-- .../de/dytanic/cloudnetcore/CloudConfig.java | 4 +- .../de/dytanic/cloudnetcore/CloudNet.java | 10 ++--- .../cloudnetcore/command/CommandDebug.java | 6 ++- .../cloudnetcore/network/NetworkManager.java | 38 ++++++++++--------- .../network/components/INetworkComponent.java | 10 ++--- .../src/main/resources/files/log.html | 1 + .../lib/network/NetworkConnection.java | 3 +- .../cloudnet/lib/server/ServerGroup.java | 1 - 9 files changed, 44 insertions(+), 37 deletions(-) diff --git a/cloudnet-api/cloudnet-api-core/src/main/java/de/dytanic/cloudnet/api/player/PermissionProvider.java b/cloudnet-api/cloudnet-api-core/src/main/java/de/dytanic/cloudnet/api/player/PermissionProvider.java index 122227633..f23318cc0 100644 --- a/cloudnet-api/cloudnet-api-core/src/main/java/de/dytanic/cloudnet/api/player/PermissionProvider.java +++ b/cloudnet-api/cloudnet-api-core/src/main/java/de/dytanic/cloudnet/api/player/PermissionProvider.java @@ -175,7 +175,7 @@ public static String getGroupPrefix(String groupName) final PermissionPool permissionPool = CloudAPI.getInstance().getPermissionPool(); if (permissionPool.getGroups().containsKey(groupName)) return permissionPool.getGroups().get(groupName).getPrefix(); - + return null; } @@ -193,7 +193,7 @@ public static String getGroupSuffix(String groupName) final PermissionPool permissionPool = CloudAPI.getInstance().getPermissionPool(); if (permissionPool.getGroups().containsKey(groupName)) return permissionPool.getGroups().get(groupName).getSuffix(); - + return null; } @@ -222,7 +222,7 @@ public static String getGroupDisplay(String groupName) final PermissionPool permissionPool = CloudAPI.getInstance().getPermissionPool(); if (permissionPool.getGroups().containsKey(groupName)) return permissionPool.getGroups().get(groupName).getDisplay(); - + return null; } @@ -239,7 +239,7 @@ public static Collection getImplementedGroups(String groupName) final PermissionPool permissionPool = CloudAPI.getInstance().getPermissionPool(); if (permissionPool.getGroups().containsKey(groupName)) return Collections.unmodifiableCollection(permissionPool.getGroups().get(groupName).getImplementGroups()); - + return null; } diff --git a/cloudnet-core/src/main/java/de/dytanic/cloudnetcore/CloudConfig.java b/cloudnet-core/src/main/java/de/dytanic/cloudnetcore/CloudConfig.java index 9c5adae4f..a511b90f4 100644 --- a/cloudnet-core/src/main/java/de/dytanic/cloudnetcore/CloudConfig.java +++ b/cloudnet-core/src/main/java/de/dytanic/cloudnetcore/CloudConfig.java @@ -201,7 +201,7 @@ public CloudConfig load() throws Exception ); this.formatSplitter = configuration.getString("general.server-name-splitter"); this.networkProperties = configuration.getSection("networkproperties").self; - + if (!configuration.getSection("general").self.containsKey("disabled-modules")) { configuration.set("general.disabled-modules", new ArrayList<>()); @@ -232,7 +232,7 @@ public CloudConfig load() throws Exception }.getType()); this.userDocument = Document.loadDocument(usersPath); - + return this; } diff --git a/cloudnet-core/src/main/java/de/dytanic/cloudnetcore/CloudNet.java b/cloudnet-core/src/main/java/de/dytanic/cloudnetcore/CloudNet.java index a06269731..4315e7055 100644 --- a/cloudnet-core/src/main/java/de/dytanic/cloudnetcore/CloudNet.java +++ b/cloudnet-core/src/main/java/de/dytanic/cloudnetcore/CloudNet.java @@ -129,7 +129,7 @@ public boolean bootstrap() throws Exception System.out.println("Loading Modules..."); moduleManager.loadModules(); } - + for (WrapperMeta wrapperMeta : config.getWrappers()) { System.out.println("Loading Wrapper " + wrapperMeta.getId() + " @ " + wrapperMeta.getHostName()); @@ -137,7 +137,7 @@ public boolean bootstrap() throws Exception } this.users = config.getUsers(); - + NetworkUtils.addAll(this.serverGroups, config.getServerGroups(), new Acceptable() { @Override public boolean isAccepted(ServerGroup value) @@ -177,7 +177,7 @@ public boolean isAccepted(ProxyGroup value) RUNNING = true; Runtime.getRuntime().addShutdownHook(new Thread(this)); - + { if (!optionSet.has("onlyConsole")) { @@ -240,9 +240,9 @@ public void reload() throws Exception this.users.clear(); this.serverGroups.clear(); this.proxyGroups.clear(); - + this.config.load(); - + this.users = config.getUsers(); NetworkUtils.addAll(this.serverGroups, config.getServerGroups(), new Acceptable() { diff --git a/cloudnet-core/src/main/java/de/dytanic/cloudnetcore/command/CommandDebug.java b/cloudnet-core/src/main/java/de/dytanic/cloudnetcore/command/CommandDebug.java index 2f5e4cbad..34371b4df 100644 --- a/cloudnet-core/src/main/java/de/dytanic/cloudnetcore/command/CommandDebug.java +++ b/cloudnet-core/src/main/java/de/dytanic/cloudnetcore/command/CommandDebug.java @@ -22,9 +22,11 @@ public CommandDebug() public void onExecuteCommand(CommandSender sender, String[] args) { CloudNet.getLogger().setDebugging(!CloudNet.getLogger().isDebugging()); - if (CloudNet.getLogger().isDebugging()) { + if (CloudNet.getLogger().isDebugging()) + { sender.sendMessage("debugging was enabled"); - } else { + } else + { sender.sendMessage("debugging was disabled"); } } diff --git a/cloudnet-core/src/main/java/de/dytanic/cloudnetcore/network/NetworkManager.java b/cloudnet-core/src/main/java/de/dytanic/cloudnetcore/network/NetworkManager.java index d8cac4d31..bff6965ca 100644 --- a/cloudnet-core/src/main/java/de/dytanic/cloudnetcore/network/NetworkManager.java +++ b/cloudnet-core/src/main/java/de/dytanic/cloudnetcore/network/NetworkManager.java @@ -101,12 +101,14 @@ public void handlePlayerLoginRequest(ProxyServer proxyServer, PlayerConnection c OfflinePlayer offlinePlayer = null; CloudNet.getLogger().debug("player login request " + cloudPlayerConnection.getName() + "#" + uniqueId + " database contains"); - if (!playerDatabase.containsPlayer(cloudPlayerConnection.getUniqueId())) { + if (!playerDatabase.containsPlayer(cloudPlayerConnection.getUniqueId())) + { CloudNet.getLogger().debug("player login request " + cloudPlayerConnection.getName() + "#" + uniqueId + " database register"); offlinePlayer = playerDatabase.registerPlayer(cloudPlayerConnection); } - if (offlinePlayer == null) { + if (offlinePlayer == null) + { CloudNet.getLogger().debug("player login request " + cloudPlayerConnection.getName() + "#" + uniqueId + " database get"); offlinePlayer = playerDatabase.getPlayer(cloudPlayerConnection.getUniqueId()); } @@ -115,7 +117,8 @@ public void handlePlayerLoginRequest(ProxyServer proxyServer, PlayerConnection c CloudPlayer cloudPlayer = new CloudPlayer(offlinePlayer, cloudPlayerConnection, proxyServer.getServerId()); cloudPlayer.setPlayerExecutor(CorePlayerExecutor.INSTANCE); - if (cloudPlayer.getFirstLogin() == null) { + if (cloudPlayer.getFirstLogin() == null) + { CloudNet.getLogger().debug("player login request " + cloudPlayerConnection.getName() + "#" + uniqueId + " set firstLogin"); cloudPlayer.setFirstLogin(System.currentTimeMillis()); } @@ -351,24 +354,25 @@ public boolean accept(INetworkComponent networkComponent) public NetworkManager sendAll(Packet packet, ChannelFilter filter) { this.executorService.submit(() -> { - for (Wrapper cn : CloudNet.getInstance().getWrappers().values()) - { - if (cn.getChannel() != null && filter.accept(cn)) - cn.sendPacket(packet); + for (Wrapper cn : CloudNet.getInstance().getWrappers().values()) + { + if (cn.getChannel() != null && filter.accept(cn)) + cn.sendPacket(packet); - for (ProxyServer proxyServer : cn.getProxys().values()) - if (proxyServer.getChannel() != null && filter.accept(proxyServer)) - proxyServer.sendPacket(packet); + for (ProxyServer proxyServer : cn.getProxys().values()) + if (proxyServer.getChannel() != null && filter.accept(proxyServer)) + proxyServer.sendPacket(packet); - for (MinecraftServer minecraftServer : cn.getServers().values()) - if (minecraftServer.getChannel() != null && filter.accept(minecraftServer)) - minecraftServer.sendPacket(packet); + for (MinecraftServer minecraftServer : cn.getServers().values()) + if (minecraftServer.getChannel() != null && filter.accept(minecraftServer)) + minecraftServer.sendPacket(packet); - for (CloudServer cloudServer : cn.getCloudServers().values()) - if (cloudServer.getChannel() != null && filter.accept(cloudServer)) - cloudServer.sendPacket(packet); + for (CloudServer cloudServer : cn.getCloudServers().values()) + if (cloudServer.getChannel() != null && filter.accept(cloudServer)) + cloudServer.sendPacket(packet); - }}); + } + }); return this; } diff --git a/cloudnet-core/src/main/java/de/dytanic/cloudnetcore/network/components/INetworkComponent.java b/cloudnet-core/src/main/java/de/dytanic/cloudnetcore/network/components/INetworkComponent.java index b71b74c57..714571be0 100644 --- a/cloudnet-core/src/main/java/de/dytanic/cloudnetcore/network/components/INetworkComponent.java +++ b/cloudnet-core/src/main/java/de/dytanic/cloudnetcore/network/components/INetworkComponent.java @@ -10,6 +10,7 @@ import de.dytanic.cloudnet.lib.network.protocol.packet.Packet; import de.dytanic.cloudnet.lib.network.protocol.packet.PacketSender; import de.dytanic.cloudnetcore.CloudNet; +import io.netty.channel.ChannelFutureListener; /** * Created by Tareko on 27.05.2017. @@ -35,8 +36,8 @@ default void sendPacket(Packet packet) { try { - getChannel().writeAndFlush(packet); - } catch (Exception ex) + getChannel().writeAndFlush(packet).addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE); + } catch (Exception ignored) { } } else @@ -47,10 +48,9 @@ public void run() { try { - getChannel().writeAndFlush(packet); - } catch (Exception ex) + getChannel().writeAndFlush(packet).addListener(ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE); + } catch (Exception ignored) { - } } }); diff --git a/cloudnet-core/src/main/resources/files/log.html b/cloudnet-core/src/main/resources/files/log.html index dda6fe538..f704a42b7 100644 --- a/cloudnet-core/src/main/resources/files/log.html +++ b/cloudnet-core/src/main/resources/files/log.html @@ -26,6 +26,7 @@ + diff --git a/cloudnet-lib/src/main/java/de/dytanic/cloudnet/lib/network/NetworkConnection.java b/cloudnet-lib/src/main/java/de/dytanic/cloudnet/lib/network/NetworkConnection.java index 66355ed7f..2231b3c1e 100644 --- a/cloudnet-lib/src/main/java/de/dytanic/cloudnet/lib/network/NetworkConnection.java +++ b/cloudnet-lib/src/main/java/de/dytanic/cloudnet/lib/network/NetworkConnection.java @@ -67,7 +67,8 @@ public boolean tryConnect(boolean ssl, SimpleChannelInboundHandler defau { try { - if (ssl) sslContext = SslContextBuilder.forClient().trustManager(InsecureTrustManagerFactory.INSTANCE).build(); + if (ssl) + sslContext = SslContextBuilder.forClient().trustManager(InsecureTrustManagerFactory.INSTANCE).build(); Bootstrap bootstrap = new Bootstrap() .option(ChannelOption.AUTO_READ, true) diff --git a/cloudnet-lib/src/main/java/de/dytanic/cloudnet/lib/server/ServerGroup.java b/cloudnet-lib/src/main/java/de/dytanic/cloudnet/lib/server/ServerGroup.java index 07ef9112f..5edf2c385 100644 --- a/cloudnet-lib/src/main/java/de/dytanic/cloudnet/lib/server/ServerGroup.java +++ b/cloudnet-lib/src/main/java/de/dytanic/cloudnet/lib/server/ServerGroup.java @@ -13,7 +13,6 @@ import java.lang.reflect.Type; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.Collections; From d4a865c574ba8fa656a81b89b1a272a6ae0b0d13 Mon Sep 17 00:00:00 2001 From: Tarek Date: Wed, 12 Dec 2018 20:33:52 +0100 Subject: [PATCH 2/4] try to fix finally the screen system OutOfMemory bug and include the Tsunami screen system --- .../dytanic/cloudnetwrapper/screen/AbstractScreenService.java | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 cloudnet-wrapper/src/main/java/de/dytanic/cloudnetwrapper/screen/AbstractScreenService.java diff --git a/cloudnet-wrapper/src/main/java/de/dytanic/cloudnetwrapper/screen/AbstractScreenService.java b/cloudnet-wrapper/src/main/java/de/dytanic/cloudnetwrapper/screen/AbstractScreenService.java new file mode 100644 index 000000000..a1464b74d --- /dev/null +++ b/cloudnet-wrapper/src/main/java/de/dytanic/cloudnetwrapper/screen/AbstractScreenService.java @@ -0,0 +1,4 @@ +package de.dytanic.cloudnetwrapper.screen; + +public class AbstractScreenService { +} From 5707852f7b4b1cce4e93df0b4ae7b0f77b302cbf Mon Sep 17 00:00:00 2001 From: Tarek Date: Wed, 12 Dec 2018 20:35:09 +0100 Subject: [PATCH 3/4] try to fix finally the screen system OutOfMemory bug and include the Tsunami screen system --- Jenkinsfile | 2 +- .../cloudnetcore/network/NetworkManager.java | 33 +++++++------ .../serverlog/ServerLogManager.java | 2 +- .../handlers/ReadConsoleLogHandler.java | 49 +++++++++---------- .../network/packet/in/PacketInScreen.java | 22 ++++++--- .../screen/AbstractScreenService.java | 49 ++++++++++++++++++- .../cloudnetwrapper/server/BungeeCord.java | 5 +- .../server/CloudGameServer.java | 5 +- .../cloudnetwrapper/server/GameServer.java | 5 +- pom.xml | 2 +- 10 files changed, 115 insertions(+), 59 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 6bb6bf1d2..d5257e1f4 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -15,7 +15,7 @@ pipeline { } stage('Version') { steps { - sh 'mvn versions:set -DnewVersion=2.1.14.1' + sh 'mvn versions:set -DnewVersion=2.1.14.2' } } stage('Compile') { diff --git a/cloudnet-core/src/main/java/de/dytanic/cloudnetcore/network/NetworkManager.java b/cloudnet-core/src/main/java/de/dytanic/cloudnetcore/network/NetworkManager.java index bff6965ca..c91ddf269 100644 --- a/cloudnet-core/src/main/java/de/dytanic/cloudnetcore/network/NetworkManager.java +++ b/cloudnet-core/src/main/java/de/dytanic/cloudnetcore/network/NetworkManager.java @@ -14,6 +14,7 @@ import de.dytanic.cloudnet.lib.player.OfflinePlayer; import de.dytanic.cloudnet.lib.player.PlayerCommandExecution; import de.dytanic.cloudnet.lib.player.PlayerConnection; +import de.dytanic.cloudnet.lib.scheduler.TaskScheduler; import de.dytanic.cloudnet.lib.server.ServerGroup; import de.dytanic.cloudnet.lib.server.ServerGroupMode; import de.dytanic.cloudnet.lib.server.SimpleServerGroup; @@ -45,7 +46,6 @@ import java.util.Collection; import java.util.LinkedList; import java.util.UUID; -import java.util.concurrent.ExecutorService; /** * Created by Tareko on 19.07.2017. @@ -56,7 +56,6 @@ public final class NetworkManager { private java.util.Map waitingPlayers = NetworkUtils.newConcurrentHashMap(); private java.util.Map onlinePlayers = NetworkUtils.newConcurrentHashMap(); private Document moduleProperties = new Document(); - private ExecutorService executorService = java.util.concurrent.Executors.newFixedThreadPool(4); private MessageConfig messageConfig; @@ -353,24 +352,28 @@ public boolean accept(INetworkComponent networkComponent) public NetworkManager sendAll(Packet packet, ChannelFilter filter) { - this.executorService.submit(() -> { - for (Wrapper cn : CloudNet.getInstance().getWrappers().values()) + TaskScheduler.runtimeScheduler().schedule(new Runnable() { + @Override + public void run() { - if (cn.getChannel() != null && filter.accept(cn)) - cn.sendPacket(packet); + for (Wrapper cn : CloudNet.getInstance().getWrappers().values()) + { + if (cn.getChannel() != null && filter.accept(cn)) + cn.sendPacket(packet); - for (ProxyServer proxyServer : cn.getProxys().values()) - if (proxyServer.getChannel() != null && filter.accept(proxyServer)) - proxyServer.sendPacket(packet); + for (ProxyServer proxyServer : cn.getProxys().values()) + if (proxyServer.getChannel() != null && filter.accept(proxyServer)) + proxyServer.sendPacket(packet); - for (MinecraftServer minecraftServer : cn.getServers().values()) - if (minecraftServer.getChannel() != null && filter.accept(minecraftServer)) - minecraftServer.sendPacket(packet); + for (MinecraftServer minecraftServer : cn.getServers().values()) + if (minecraftServer.getChannel() != null && filter.accept(minecraftServer)) + minecraftServer.sendPacket(packet); - for (CloudServer cloudServer : cn.getCloudServers().values()) - if (cloudServer.getChannel() != null && filter.accept(cloudServer)) - cloudServer.sendPacket(packet); + for (CloudServer cloudServer : cn.getCloudServers().values()) + if (cloudServer.getChannel() != null && filter.accept(cloudServer)) + cloudServer.sendPacket(packet); + } } }); return this; diff --git a/cloudnet-core/src/main/java/de/dytanic/cloudnetcore/serverlog/ServerLogManager.java b/cloudnet-core/src/main/java/de/dytanic/cloudnetcore/serverlog/ServerLogManager.java index c67b8d8d8..d706cb6f7 100644 --- a/cloudnet-core/src/main/java/de/dytanic/cloudnetcore/serverlog/ServerLogManager.java +++ b/cloudnet-core/src/main/java/de/dytanic/cloudnetcore/serverlog/ServerLogManager.java @@ -62,7 +62,7 @@ public void appendScreenData(Collection screenInfos) { this.screenInfos.getS(key).addAll(screenInfos); - while (this.screenInfos.getS(key).size() > 64) + while (this.screenInfos.getS(key).size() >= 64) this.screenInfos.getS(key).poll(); } } diff --git a/cloudnet-wrapper/src/main/java/de/dytanic/cloudnetwrapper/handlers/ReadConsoleLogHandler.java b/cloudnet-wrapper/src/main/java/de/dytanic/cloudnetwrapper/handlers/ReadConsoleLogHandler.java index 7c49d16b5..59f3964f2 100644 --- a/cloudnet-wrapper/src/main/java/de/dytanic/cloudnetwrapper/handlers/ReadConsoleLogHandler.java +++ b/cloudnet-wrapper/src/main/java/de/dytanic/cloudnetwrapper/handlers/ReadConsoleLogHandler.java @@ -1,16 +1,13 @@ package de.dytanic.cloudnetwrapper.handlers; -import de.dytanic.cloudnet.lib.server.screen.ScreenInfo; import de.dytanic.cloudnetwrapper.CloudNetWrapper; -import de.dytanic.cloudnetwrapper.network.packet.out.PacketOutSendScreenLine; +import de.dytanic.cloudnetwrapper.screen.AbstractScreenService; import de.dytanic.cloudnetwrapper.server.BungeeCord; import de.dytanic.cloudnetwrapper.server.CloudGameServer; import de.dytanic.cloudnetwrapper.server.GameServer; -import de.dytanic.cloudnetwrapper.server.process.ServerDispatcher; import java.io.InputStream; import java.nio.charset.StandardCharsets; -import java.util.Collections; public final class ReadConsoleLogHandler implements IWrapperHandler { @@ -18,8 +15,6 @@ public final class ReadConsoleLogHandler implements IWrapperHandler { private final byte[] buffer = new byte[1024]; - private int len; - @Override public void run(CloudNetWrapper obj) { @@ -36,32 +31,36 @@ public void run(CloudNetWrapper obj) readConsoleLog(gameServer); } - private synchronized void readConsoleLog(ServerDispatcher server) + private synchronized void readConsoleLog(AbstractScreenService server) { if (server.getInstance().isAlive() && server.getInstance().getInputStream() != null) { - try - { + readStream(server, server.getInstance().getInputStream()); + readStream(server, server.getInstance().getErrorStream()); + } + } - InputStream inputStream = server.getInstance().getInputStream(); + private synchronized void readStream(AbstractScreenService screenService, InputStream inputStream) + { + try + { + int len; + while (inputStream.available() > 0 && (len = inputStream.read(buffer, 0, buffer.length)) != -1) + stringBuffer.append(new String(buffer, 0, len, StandardCharsets.UTF_8)); + + String stringText = stringBuffer.toString(); + if (!stringText.contains("\n") && !stringText.contains("\r")) return; - while (inputStream.available() > 0 && (len = inputStream.read(buffer, 0, buffer.length)) != -1) - stringBuffer.append(new String(buffer, 0, len, StandardCharsets.UTF_8)); + for (String input : stringText.split("\r")) + for (String text : input.split("\n")) + if (!text.trim().isEmpty()) + screenService.addCachedItem(text); - for (String input : stringBuffer.toString().split("\r")) - for (String text : input.split("\n")) - if (!text.trim().isEmpty()) - { - CloudNetWrapper.getInstance().getNetworkConnection() - .sendPacket(new PacketOutSendScreenLine(Collections.singletonList(new ScreenInfo(server.getServiceId(), input)))); - } + stringBuffer.setLength(0); - } catch (Exception ignored) - { - } finally - { - stringBuffer.setLength(0); - } + } catch (Exception ignored) + { + stringBuffer.setLength(0); } } diff --git a/cloudnet-wrapper/src/main/java/de/dytanic/cloudnetwrapper/network/packet/in/PacketInScreen.java b/cloudnet-wrapper/src/main/java/de/dytanic/cloudnetwrapper/network/packet/in/PacketInScreen.java index 85da11c83..f0dd4be66 100644 --- a/cloudnet-wrapper/src/main/java/de/dytanic/cloudnetwrapper/network/packet/in/PacketInScreen.java +++ b/cloudnet-wrapper/src/main/java/de/dytanic/cloudnetwrapper/network/packet/in/PacketInScreen.java @@ -4,16 +4,22 @@ package de.dytanic.cloudnetwrapper.network.packet.in; +import com.google.gson.reflect.TypeToken; +import de.dytanic.cloudnet.lib.DefaultType; import de.dytanic.cloudnet.lib.network.protocol.packet.PacketInHandler; import de.dytanic.cloudnet.lib.network.protocol.packet.PacketSender; +import de.dytanic.cloudnet.lib.server.info.ProxyInfo; +import de.dytanic.cloudnet.lib.server.info.ServerInfo; import de.dytanic.cloudnet.lib.utility.document.Document; +import de.dytanic.cloudnetwrapper.CloudNetWrapper; +import de.dytanic.cloudnetwrapper.server.BungeeCord; +import de.dytanic.cloudnetwrapper.server.GameServer; public final class PacketInScreen extends PacketInHandler { @Override public void handleInput(Document data, PacketSender packetSender) { - /* if (data.getObject("type", DefaultType.class) != DefaultType.BUNGEE_CORD) { ServerInfo server = data.getObject("serverInfo", new TypeToken() { @@ -21,10 +27,11 @@ public void handleInput(Document data, PacketSender packetSender) if (CloudNetWrapper.getInstance().getServers().containsKey(server.getServiceId().getServerId())) { GameServer gameServer = CloudNetWrapper.getInstance().getServers().get(server.getServiceId().getServerId()); + if (data.getBoolean("enable")) - CloudNetWrapper.getInstance().getScreenProvider().putScreenRequest(gameServer); + gameServer.enableScreenSystem(); else - CloudNetWrapper.getInstance().getScreenProvider().cancel(gameServer); + gameServer.disableScreenSystem(); } } else { @@ -32,13 +39,12 @@ public void handleInput(Document data, PacketSender packetSender) }.getType()); if (CloudNetWrapper.getInstance().getProxys().containsKey(server.getServiceId().getServerId())) { - BungeeCord gameServer = CloudNetWrapper.getInstance().getProxys().get(server.getServiceId().getServerId()); + BungeeCord bungee = CloudNetWrapper.getInstance().getProxys().get(server.getServiceId().getServerId()); if (data.getBoolean("enable")) - CloudNetWrapper.getInstance().getScreenProvider().putScreenRequest(gameServer); - else if (CloudNetWrapper.getInstance().getScreenProvider().contains(gameServer)) - CloudNetWrapper.getInstance().getScreenProvider().cancel(gameServer); + bungee.enableScreenSystem(); + else + bungee.disableScreenSystem(); } } - */ } } \ No newline at end of file diff --git a/cloudnet-wrapper/src/main/java/de/dytanic/cloudnetwrapper/screen/AbstractScreenService.java b/cloudnet-wrapper/src/main/java/de/dytanic/cloudnetwrapper/screen/AbstractScreenService.java index a1464b74d..c1bc9ef69 100644 --- a/cloudnet-wrapper/src/main/java/de/dytanic/cloudnetwrapper/screen/AbstractScreenService.java +++ b/cloudnet-wrapper/src/main/java/de/dytanic/cloudnetwrapper/screen/AbstractScreenService.java @@ -1,4 +1,49 @@ package de.dytanic.cloudnetwrapper.screen; -public class AbstractScreenService { -} +import de.dytanic.cloudnet.lib.server.screen.ScreenInfo; +import de.dytanic.cloudnetwrapper.CloudNetWrapper; +import de.dytanic.cloudnetwrapper.network.packet.out.PacketOutSendScreenLine; +import lombok.Getter; + +import java.util.Collections; +import java.util.Queue; +import java.util.concurrent.ConcurrentLinkedQueue; + +public abstract class AbstractScreenService implements Screenable { + + @Getter + protected final Queue cachedLogMessages = new ConcurrentLinkedQueue<>(); + + @Getter + protected volatile boolean screenSystemEnabled; + + public void addCachedItem(String text) + { + if (text == null) return; + + while (cachedLogMessages.size() >= 64) + cachedLogMessages.poll(); + + cachedLogMessages.offer(text); + + if (this.screenSystemEnabled) this.sendScreenLine0(text); + } + + public void enableScreenSystem() + { + for (String text : this.cachedLogMessages) + this.sendScreenLine0(text); + + this.screenSystemEnabled = true; + } + + public void disableScreenSystem() + { + this.screenSystemEnabled = false; + } + + private void sendScreenLine0(String text) + { + CloudNetWrapper.getInstance().getNetworkConnection().sendPacket(new PacketOutSendScreenLine(Collections.singletonList(new ScreenInfo(getServiceId(), text)))); + } +} \ No newline at end of file diff --git a/cloudnet-wrapper/src/main/java/de/dytanic/cloudnetwrapper/server/BungeeCord.java b/cloudnet-wrapper/src/main/java/de/dytanic/cloudnetwrapper/server/BungeeCord.java index 551ca8fc8..06e56478f 100644 --- a/cloudnet-wrapper/src/main/java/de/dytanic/cloudnetwrapper/server/BungeeCord.java +++ b/cloudnet-wrapper/src/main/java/de/dytanic/cloudnetwrapper/server/BungeeCord.java @@ -23,6 +23,7 @@ import de.dytanic.cloudnetwrapper.CloudNetWrapper; import de.dytanic.cloudnetwrapper.network.packet.out.PacketOutAddProxy; import de.dytanic.cloudnetwrapper.network.packet.out.PacketOutRemoveProxy; +import de.dytanic.cloudnetwrapper.screen.AbstractScreenService; import de.dytanic.cloudnetwrapper.server.process.ServerDispatcher; import de.dytanic.cloudnetwrapper.util.FileUtility; import lombok.EqualsAndHashCode; @@ -39,9 +40,9 @@ import java.nio.file.Paths; import java.util.LinkedList; -@EqualsAndHashCode @Getter -public class BungeeCord implements ServerDispatcher { +@EqualsAndHashCode(callSuper = false) +public class BungeeCord extends AbstractScreenService implements ServerDispatcher { private ProxyProcessMeta proxyProcessMeta; diff --git a/cloudnet-wrapper/src/main/java/de/dytanic/cloudnetwrapper/server/CloudGameServer.java b/cloudnet-wrapper/src/main/java/de/dytanic/cloudnetwrapper/server/CloudGameServer.java index 091bbfc55..6377d1ffc 100644 --- a/cloudnet-wrapper/src/main/java/de/dytanic/cloudnetwrapper/server/CloudGameServer.java +++ b/cloudnet-wrapper/src/main/java/de/dytanic/cloudnetwrapper/server/CloudGameServer.java @@ -18,6 +18,7 @@ import de.dytanic.cloudnetwrapper.CloudNetWrapper; import de.dytanic.cloudnetwrapper.network.packet.out.PacketOutAddCloudServer; import de.dytanic.cloudnetwrapper.network.packet.out.PacketOutRemoveCloudServer; +import de.dytanic.cloudnetwrapper.screen.AbstractScreenService; import de.dytanic.cloudnetwrapper.server.process.ServerDispatcher; import de.dytanic.cloudnetwrapper.util.FileUtility; import de.dytanic.cloudnetwrapper.util.MasterTemplateDeploy; @@ -44,9 +45,9 @@ /** * Created by Tareko on 17.10.2017. */ -@EqualsAndHashCode @Getter -public class CloudGameServer implements ServerDispatcher { +@EqualsAndHashCode(callSuper = false) +public class CloudGameServer extends AbstractScreenService implements ServerDispatcher { private CloudServerMeta cloudServerMeta; diff --git a/cloudnet-wrapper/src/main/java/de/dytanic/cloudnetwrapper/server/GameServer.java b/cloudnet-wrapper/src/main/java/de/dytanic/cloudnetwrapper/server/GameServer.java index ad02c278f..5794d3c78 100644 --- a/cloudnet-wrapper/src/main/java/de/dytanic/cloudnetwrapper/server/GameServer.java +++ b/cloudnet-wrapper/src/main/java/de/dytanic/cloudnetwrapper/server/GameServer.java @@ -24,6 +24,7 @@ import de.dytanic.cloudnetwrapper.CloudNetWrapper; import de.dytanic.cloudnetwrapper.network.packet.out.PacketOutAddServer; import de.dytanic.cloudnetwrapper.network.packet.out.PacketOutRemoveServer; +import de.dytanic.cloudnetwrapper.screen.AbstractScreenService; import de.dytanic.cloudnetwrapper.server.process.ServerDispatcher; import de.dytanic.cloudnetwrapper.server.process.ServerProcess; import de.dytanic.cloudnetwrapper.util.FileUtility; @@ -44,9 +45,9 @@ import java.util.Enumeration; import java.util.Properties; -@EqualsAndHashCode @Getter -public class GameServer implements ServerDispatcher { +@EqualsAndHashCode(callSuper = false) +public class GameServer extends AbstractScreenService implements ServerDispatcher { private ServerProcess serverProcess; diff --git a/pom.xml b/pom.xml index f833c236b..0773c32f9 100644 --- a/pom.xml +++ b/pom.xml @@ -18,7 +18,7 @@ 1.8 UTF-8 UTF-8 - 2.1.14.1 + 2.1.14.2 RELEASE 1.18.4 From 99649e187076ca20b2d12feed132dea9b7104a8c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" Date: Thu, 13 Dec 2018 06:49:06 +0000 Subject: [PATCH 4/4] Bump maven-jar-plugin from 3.1.0 to 3.1.1 Bumps [maven-jar-plugin](https://github.com/apache/maven-jar-plugin) from 3.1.0 to 3.1.1. - [Release notes](https://github.com/apache/maven-jar-plugin/releases) - [Commits](https://github.com/apache/maven-jar-plugin/compare/maven-jar-plugin-3.1.0...maven-jar-plugin-3.1.1) Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 0773c32f9..afc7a748b 100644 --- a/pom.xml +++ b/pom.xml @@ -36,7 +36,7 @@ 3.2.1 3.0.1 - 3.1.0 + 3.1.1 3.1.0 1.8