From 93df2d0b0e8c82e471b4adebe3fb2779e149c36d Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Sun, 7 Jul 2024 02:59:06 +0000 Subject: [PATCH] Format code [skip actions] --- .../java/emu/grasscutter/Grasscutter.java | 15 ++++---- .../java/emu/grasscutter/net/IKcpSession.java | 11 ++---- .../grasscutter/net/INetworkTransport.java | 9 +++-- .../grasscutter/net/impl/KcpSessionImpl.java | 9 ++--- .../net/impl/NetworkTransportImpl.java | 34 +++++++++---------- .../scripts/SceneScriptManager.java | 3 +- .../grasscutter/server/game/GameServer.java | 8 ++--- .../grasscutter/server/game/GameSession.java | 13 ++++--- .../grasscutter/server/game/IGameSession.java | 8 ++--- 9 files changed, 50 insertions(+), 60 deletions(-) diff --git a/src/main/java/emu/grasscutter/Grasscutter.java b/src/main/java/emu/grasscutter/Grasscutter.java index 0c64a3d4b..544667c22 100644 --- a/src/main/java/emu/grasscutter/Grasscutter.java +++ b/src/main/java/emu/grasscutter/Grasscutter.java @@ -78,13 +78,14 @@ public final class Grasscutter { mongoLogger.setLevel(Level.OFF); // Configure the reflector. - reflector = new Reflections( - new ConfigurationBuilder() - .forPackage("emu.grasscutter") - .filterInputsBy(new FilterBuilder() - .includePackage("emu.grasscutter") - .excludePackage("emu.grasscutter.net.proto")) - ); + reflector = + new Reflections( + new ConfigurationBuilder() + .forPackage("emu.grasscutter") + .filterInputsBy( + new FilterBuilder() + .includePackage("emu.grasscutter") + .excludePackage("emu.grasscutter.net.proto"))); // Load server configuration. Grasscutter.loadConfig(); diff --git a/src/main/java/emu/grasscutter/net/IKcpSession.java b/src/main/java/emu/grasscutter/net/IKcpSession.java index f30c0fbbc..f442485e6 100644 --- a/src/main/java/emu/grasscutter/net/IKcpSession.java +++ b/src/main/java/emu/grasscutter/net/IKcpSession.java @@ -1,12 +1,9 @@ package emu.grasscutter.net; +import java.net.InetSocketAddress; import org.slf4j.Logger; -import java.net.InetSocketAddress; - -/** - * This is most closely related to the previous `KcpTunnel` interface. - */ +/** This is most closely related to the previous `KcpTunnel` interface. */ public interface IKcpSession { /** * @return The session's unique logger. @@ -18,9 +15,7 @@ public interface IKcpSession { */ InetSocketAddress getAddress(); - /** - * Closes the server's connection to the client. - */ + /** Closes the server's connection to the client. */ void close(); /** diff --git a/src/main/java/emu/grasscutter/net/INetworkTransport.java b/src/main/java/emu/grasscutter/net/INetworkTransport.java index 12495b325..eb63d581a 100644 --- a/src/main/java/emu/grasscutter/net/INetworkTransport.java +++ b/src/main/java/emu/grasscutter/net/INetworkTransport.java @@ -2,13 +2,12 @@ package emu.grasscutter.net; import emu.grasscutter.Grasscutter; import emu.grasscutter.server.game.GameServer; - import java.net.InetSocketAddress; public interface INetworkTransport { /** - * Waits for the server to be active. - * This should be used to ensure that the server is ready to accept connections. + * Waits for the server to be active. This should be used to ensure that the server is ready to + * accept connections. */ default GameServer waitForServer() throws InterruptedException { int depth = 0; @@ -32,8 +31,8 @@ public interface INetworkTransport { void start(InetSocketAddress listening); /** - * This is invoked when the transport should stop listening for incoming connections. - * This should also close all active connections. + * This is invoked when the transport should stop listening for incoming connections. This should + * also close all active connections. */ void shutdown(); } diff --git a/src/main/java/emu/grasscutter/net/impl/KcpSessionImpl.java b/src/main/java/emu/grasscutter/net/impl/KcpSessionImpl.java index e980a5d97..fa97b228b 100644 --- a/src/main/java/emu/grasscutter/net/impl/KcpSessionImpl.java +++ b/src/main/java/emu/grasscutter/net/impl/KcpSessionImpl.java @@ -1,19 +1,16 @@ package emu.grasscutter.net.impl; import emu.grasscutter.net.IKcpSession; -import emu.grasscutter.net.INetworkTransport; import io.netty.buffer.Unpooled; +import java.net.InetSocketAddress; import kcp.highway.Ukcp; import lombok.Getter; -import lombok.RequiredArgsConstructor; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.net.InetSocketAddress; - /** - * This is the default implementation of a KCP session. - * It uses {@link Ukcp} as the underlying wrapper. + * This is the default implementation of a KCP session. It uses {@link Ukcp} as the underlying + * wrapper. */ @Getter public class KcpSessionImpl implements IKcpSession { diff --git a/src/main/java/emu/grasscutter/net/impl/NetworkTransportImpl.java b/src/main/java/emu/grasscutter/net/impl/NetworkTransportImpl.java index afdb91ecc..8f5625353 100644 --- a/src/main/java/emu/grasscutter/net/impl/NetworkTransportImpl.java +++ b/src/main/java/emu/grasscutter/net/impl/NetworkTransportImpl.java @@ -1,26 +1,25 @@ package emu.grasscutter.net.impl; +import static emu.grasscutter.config.Configuration.GAME_INFO; + import emu.grasscutter.net.INetworkTransport; import emu.grasscutter.server.game.GameSession; import emu.grasscutter.utils.Utils; import io.netty.buffer.ByteBuf; import io.netty.channel.DefaultEventLoop; import io.netty.channel.EventLoop; +import java.net.InetSocketAddress; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.TimeUnit; import kcp.highway.ChannelConfig; import kcp.highway.KcpListener; import kcp.highway.KcpServer; import kcp.highway.Ukcp; import lombok.extern.slf4j.Slf4j; -import java.net.InetSocketAddress; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.TimeUnit; - -import static emu.grasscutter.config.Configuration.GAME_INFO; - /** - * The default implementation of a {@link INetworkTransport}. - * Uses {@link KcpServer} as the underlying transport. + * The default implementation of a {@link INetworkTransport}. Uses {@link KcpServer} as the + * underlying transport. */ @Slf4j public class NetworkTransportImpl extends KcpServer implements INetworkTransport { @@ -87,15 +86,16 @@ public class NetworkTransportImpl extends KcpServer implements INetworkTransport // Copy the buffer to avoid reference issues. var data = Utils.byteBufToArray(byteBuf); - transport.networkLoop.submit(() -> { - // Fun fact: if we don't catch exceptions here, - // we run the risk of locking the entire network loop. - try { - session.onReceived(data); - } catch (Exception ex) { - session.getLogger().warn("Unable to handle received data.", ex); - } - }); + transport.networkLoop.submit( + () -> { + // Fun fact: if we don't catch exceptions here, + // we run the risk of locking the entire network loop. + try { + session.onReceived(data); + } catch (Exception ex) { + session.getLogger().warn("Unable to handle received data.", ex); + } + }); } catch (Exception ex) { NetworkTransportImpl.log.warn("Unable to handle received data.", ex); } diff --git a/src/main/java/emu/grasscutter/scripts/SceneScriptManager.java b/src/main/java/emu/grasscutter/scripts/SceneScriptManager.java index 3ef0d17ff..3bbcf1180 100644 --- a/src/main/java/emu/grasscutter/scripts/SceneScriptManager.java +++ b/src/main/java/emu/grasscutter/scripts/SceneScriptManager.java @@ -508,8 +508,7 @@ public class SceneScriptManager { block -> { block.load(sceneId, meta.context); if (block.groups == null) { - Grasscutter.getLogger() - .error("block.groups null for block {}", block.id); + Grasscutter.getLogger().error("block.groups null for block {}", block.id); return; } diff --git a/src/main/java/emu/grasscutter/server/game/GameServer.java b/src/main/java/emu/grasscutter/server/game/GameServer.java index ccc5ef625..a8a20cbb4 100644 --- a/src/main/java/emu/grasscutter/server/game/GameServer.java +++ b/src/main/java/emu/grasscutter/server/game/GameServer.java @@ -56,9 +56,7 @@ import org.jetbrains.annotations.*; @Getter @Slf4j public final class GameServer implements Iterable { - /** - * This can be set by plugins to change the network transport implementation. - */ + /** This can be set by plugins to change the network transport implementation. */ @Setter private static Class transport = NetworkTransportImpl.class; // Game server base @@ -145,9 +143,7 @@ public final class GameServer implements Iterable { // Create the network transport. INetworkTransport transport; try { - transport = GameServer.transport - .getDeclaredConstructor() - .newInstance(); + transport = GameServer.transport.getDeclaredConstructor().newInstance(); } catch (Exception ex) { log.error("Failed to create network transport.", ex); transport = new NetworkTransportImpl(); diff --git a/src/main/java/emu/grasscutter/server/game/GameSession.java b/src/main/java/emu/grasscutter/server/game/GameSession.java index f035eca21..d78bdfee6 100644 --- a/src/main/java/emu/grasscutter/server/game/GameSession.java +++ b/src/main/java/emu/grasscutter/server/game/GameSession.java @@ -74,8 +74,9 @@ public class GameSession implements IGameSession { } public void logPacket(String sendOrRecv, int opcode, byte[] payload) { - this.session.getLogger().info("{}: {} ({})", - sendOrRecv, PacketOpcodesUtils.getOpcodeName(opcode), opcode); + this.session + .getLogger() + .info("{}: {} ({})", sendOrRecv, PacketOpcodesUtils.getOpcodeName(opcode), opcode); if (GAME_INFO.isShowPacketPayload) System.out.println(Utils.bytesToHex(payload)); } @@ -151,7 +152,9 @@ public class GameSession implements IGameSession { int const1 = packet.readShort(); if (const1 != 17767) { if (allDebug) { - this.session.getLogger().error("Invalid packet header received: got {}, expected 17767", const1); + this.session + .getLogger() + .error("Invalid packet header received: got {}, expected 17767", const1); } return; // Bad packet } @@ -169,7 +172,9 @@ public class GameSession implements IGameSession { int const2 = packet.readShort(); if (const2 != -30293) { if (allDebug) { - this.session.getLogger().error("Invalid packet footer received: got {}, expected -30293", const2); + this.session + .getLogger() + .error("Invalid packet footer received: got {}, expected -30293", const2); } return; // Bad packet } diff --git a/src/main/java/emu/grasscutter/server/game/IGameSession.java b/src/main/java/emu/grasscutter/server/game/IGameSession.java index dca3efe54..d2f61bdd8 100644 --- a/src/main/java/emu/grasscutter/server/game/IGameSession.java +++ b/src/main/java/emu/grasscutter/server/game/IGameSession.java @@ -3,14 +3,12 @@ package emu.grasscutter.server.game; public interface IGameSession { /** * Invoked when the server establishes a connection to the client. - *

- * This is invoked after the KCP handshake is completed. + * + *

This is invoked after the KCP handshake is completed. */ void onConnected(); - /** - * Invoked when the server loses connection to the client. - */ + /** Invoked when the server loses connection to the client. */ void onDisconnected(); /**