diff --git a/build.gradle b/build.gradle index ff98f87..4e08378 100644 --- a/build.gradle +++ b/build.gradle @@ -3,6 +3,7 @@ plugins { } group 'cn.hamster3.mc.plugin' +version = '1.0.0-SNAPSHOT' subprojects { apply plugin: 'java-library' diff --git a/hamster-ball-bukkit/build.gradle b/hamster-ball-bukkit/build.gradle index 2f726ba..a081688 100644 --- a/hamster-ball-bukkit/build.gradle +++ b/hamster-ball-bukkit/build.gradle @@ -1,4 +1,3 @@ -version = '1.0.0' setArchivesBaseName("HamsterBall-Bukkit") evaluationDependsOn(':hamster-ball-common') @@ -9,6 +8,8 @@ dependencies { } compileOnly 'org.spigotmc:spigot-api:1.12.2-R0.1-SNAPSHOT' + + compileOnly "cn.hamster3.mc.plugin:hamster-core-bukkit:${hamster_core_version}" } processResources { diff --git a/hamster-ball-bukkit/src/main/java/cn/hamster3/mc/plugin/ball/bukkit/api/BallBukkitAPI.java b/hamster-ball-bukkit/src/main/java/cn/hamster3/mc/plugin/ball/bukkit/api/BallBukkitAPI.java index 1cfadca..0322123 100644 --- a/hamster-ball-bukkit/src/main/java/cn/hamster3/mc/plugin/ball/bukkit/api/BallBukkitAPI.java +++ b/hamster-ball-bukkit/src/main/java/cn/hamster3/mc/plugin/ball/bukkit/api/BallBukkitAPI.java @@ -4,8 +4,8 @@ import cn.hamster3.mc.plugin.ball.bukkit.HamsterBallPlugin; import cn.hamster3.mc.plugin.ball.bukkit.listener.BallBukkitListener; import cn.hamster3.mc.plugin.ball.common.api.BallAPI; import cn.hamster3.mc.plugin.ball.common.config.BallConfig; -import cn.hamster3.mc.plugin.ball.common.entity.ServerInfo; -import cn.hamster3.mc.plugin.ball.common.entity.ServerType; +import cn.hamster3.mc.plugin.ball.common.entity.BallServerInfo; +import cn.hamster3.mc.plugin.ball.common.entity.BallServerType; import org.bukkit.Bukkit; import org.bukkit.configuration.file.FileConfiguration; import org.jetbrains.annotations.NotNull; @@ -31,10 +31,10 @@ public class BallBukkitAPI extends BallAPI { String host = pluginConfig.getString("server-info.name.host", Bukkit.getIp()); BallConfig config = new BallConfig( - new ServerInfo( + new BallServerInfo( pluginConfig.getString("server-info.id"), pluginConfig.getString("server-info.name"), - ServerType.GAME, + BallServerType.GAME, host.isEmpty() ? "127.0.0.1" : host, pluginConfig.getInt("server-info.name.port", Bukkit.getPort()) ), diff --git a/hamster-ball-bukkit/src/main/java/cn/hamster3/mc/plugin/ball/bukkit/data/BukkitBlockPos.java b/hamster-ball-bukkit/src/main/java/cn/hamster3/mc/plugin/ball/bukkit/data/BukkitBlockPos.java index 74c0405..b5ccbb3 100644 --- a/hamster-ball-bukkit/src/main/java/cn/hamster3/mc/plugin/ball/bukkit/data/BukkitBlockPos.java +++ b/hamster-ball-bukkit/src/main/java/cn/hamster3/mc/plugin/ball/bukkit/data/BukkitBlockPos.java @@ -1,7 +1,7 @@ package cn.hamster3.mc.plugin.ball.bukkit.data; import cn.hamster3.mc.plugin.ball.common.api.BallAPI; -import cn.hamster3.mc.plugin.ball.common.data.ServiceBlockPos; +import cn.hamster3.mc.plugin.ball.common.data.BallBlockPos; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.block.Block; @@ -9,7 +9,7 @@ import org.bukkit.entity.Entity; import org.jetbrains.annotations.NotNull; @SuppressWarnings("unused") -public class BukkitBlockPos extends ServiceBlockPos { +public class BukkitBlockPos extends BallBlockPos { public BukkitBlockPos(@NotNull String serverID, @NotNull String worldName, int x, int y, int z) { super(serverID, worldName, x, y, z); } @@ -32,7 +32,7 @@ public class BukkitBlockPos extends ServiceBlockPos { ); } - public BukkitBlockPos(@NotNull ServiceBlockPos location) { + public BukkitBlockPos(@NotNull BallBlockPos location) { super( BallAPI.getInstance().getLocalServerId(), location.getWorldName(), diff --git a/hamster-ball-bukkit/src/main/java/cn/hamster3/mc/plugin/ball/bukkit/data/BukkitLocation.java b/hamster-ball-bukkit/src/main/java/cn/hamster3/mc/plugin/ball/bukkit/data/BukkitLocation.java index c49b5cf..eb16d04 100644 --- a/hamster-ball-bukkit/src/main/java/cn/hamster3/mc/plugin/ball/bukkit/data/BukkitLocation.java +++ b/hamster-ball-bukkit/src/main/java/cn/hamster3/mc/plugin/ball/bukkit/data/BukkitLocation.java @@ -1,7 +1,7 @@ package cn.hamster3.mc.plugin.ball.bukkit.data; import cn.hamster3.mc.plugin.ball.common.api.BallAPI; -import cn.hamster3.mc.plugin.ball.common.data.ServiceLocation; +import cn.hamster3.mc.plugin.ball.common.data.BallLocation; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.block.Block; @@ -9,7 +9,7 @@ import org.bukkit.entity.Entity; import org.jetbrains.annotations.NotNull; @SuppressWarnings("unused") -public class BukkitLocation extends ServiceLocation { +public class BukkitLocation extends BallLocation { public BukkitLocation(@NotNull String serverID, @NotNull String worldName, double x, double y, double z) { super(serverID, worldName, x, y, z, 0, 0); } @@ -38,7 +38,7 @@ public class BukkitLocation extends ServiceLocation { ); } - public BukkitLocation(@NotNull ServiceLocation location) { + public BukkitLocation(@NotNull BallLocation location) { super( location.getServerID(), location.getWorldName(), diff --git a/hamster-ball-bukkit/src/main/java/cn/hamster3/mc/plugin/ball/bukkit/listener/BallBukkitListener.java b/hamster-ball-bukkit/src/main/java/cn/hamster3/mc/plugin/ball/bukkit/listener/BallBukkitListener.java index ec528cf..416d470 100644 --- a/hamster-ball-bukkit/src/main/java/cn/hamster3/mc/plugin/ball/bukkit/listener/BallBukkitListener.java +++ b/hamster-ball-bukkit/src/main/java/cn/hamster3/mc/plugin/ball/bukkit/listener/BallBukkitListener.java @@ -2,13 +2,15 @@ package cn.hamster3.mc.plugin.ball.bukkit.listener; import cn.hamster3.mc.plugin.ball.bukkit.data.BukkitLocation; import cn.hamster3.mc.plugin.ball.common.api.BallAPI; -import cn.hamster3.mc.plugin.ball.common.data.ServiceLocation; -import cn.hamster3.mc.plugin.ball.common.entity.ServerType; +import cn.hamster3.mc.plugin.ball.common.data.BallLocation; +import cn.hamster3.mc.plugin.ball.common.data.BallMessageInfo; +import cn.hamster3.mc.plugin.ball.common.entity.BallServerType; import cn.hamster3.mc.plugin.ball.common.event.operate.DispatchConsoleCommandEvent; import cn.hamster3.mc.plugin.ball.common.event.operate.DispatchPlayerCommandEvent; import cn.hamster3.mc.plugin.ball.common.event.operate.SendPlayerToLocationEvent; import cn.hamster3.mc.plugin.ball.common.event.operate.SendPlayerToPlayerEvent; import cn.hamster3.mc.plugin.ball.common.listener.BallListener; +import cn.hamster3.mc.plugin.core.common.constant.CoreConstantObjects; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.entity.Player; @@ -28,56 +30,7 @@ public class BallBukkitListener extends BallListener implements Listener { private final HashMap playerToLocation = new HashMap<>(); - @Override - public void onDispatchConsoleCommand(@NotNull DispatchConsoleCommandEvent event) { - if (event.getType() != null && event.getType() != ServerType.GAME) { - return; - } - if (event.getServerID() != null && !BallAPI.getInstance().isLocalServer(event.getServerID())) { - return; - } - Bukkit.dispatchCommand(Bukkit.getConsoleSender(), event.getCommand()); - } - - @Override - public void onDispatchPlayerCommand(@NotNull DispatchPlayerCommandEvent event) { - if (event.getType() != null && event.getType() != ServerType.GAME) { - return; - } - if (event.getUuid() != null) { - Player player = Bukkit.getPlayer(event.getUuid()); - if (player == null) { - return; - } - Bukkit.dispatchCommand(player, event.getCommand()); - return; - } - for (Player player : Bukkit.getOnlinePlayers()) { - Bukkit.dispatchCommand(player, event.getCommand()); - } - } - - @Override - public void onSendPlayerToLocation(@NotNull SendPlayerToLocationEvent event) { - ServiceLocation location = event.getLocation(); - if (!BallAPI.getInstance().isLocalServer(location.getServerID())) { - return; - } - for (UUID uuid : event.getSendPlayerUUID()) { - playerToLocation.put(uuid, new BukkitLocation(location).toBukkitLocation()); - } - } - - @Override - public void onSendPlayerToPlayer(@NotNull SendPlayerToPlayerEvent event) { - Player player = Bukkit.getPlayer(event.getToPlayerUUID()); - if (player == null) { - return; - } - Location location = player.getLocation(); - for (UUID uuid : event.getSendPlayerUUID()) { - playerToLocation.put(uuid, location); - } + private BallBukkitListener() { } @Override @@ -85,6 +38,63 @@ public class BallBukkitListener extends BallListener implements Listener { Bukkit.shutdown(); } + @Override + public void onMessageReceived(@NotNull BallMessageInfo info) { + switch (info.getAction()) { + case DispatchConsoleCommandEvent.ACTION: { + DispatchConsoleCommandEvent event = CoreConstantObjects.GSON.fromJson(info.getContent(), DispatchConsoleCommandEvent.class); + if (event.getType() != null && event.getType() != BallServerType.GAME) { + return; + } + if (event.getServerID() != null && !BallAPI.getInstance().isLocalServer(event.getServerID())) { + return; + } + Bukkit.dispatchCommand(Bukkit.getConsoleSender(), event.getCommand()); + break; + } + case DispatchPlayerCommandEvent.ACTION: { + DispatchPlayerCommandEvent event = CoreConstantObjects.GSON.fromJson(info.getContent(), DispatchPlayerCommandEvent.class); + if (event.getType() != null && event.getType() != BallServerType.GAME) { + return; + } + if (event.getUuid() != null) { + Player player = Bukkit.getPlayer(event.getUuid()); + if (player == null) { + return; + } + Bukkit.dispatchCommand(player, event.getCommand()); + return; + } + for (Player player : Bukkit.getOnlinePlayers()) { + Bukkit.dispatchCommand(player, event.getCommand()); + } + break; + } + case SendPlayerToLocationEvent.ACTION: { + SendPlayerToLocationEvent event = CoreConstantObjects.GSON.fromJson(info.getContent(), SendPlayerToLocationEvent.class); + BallLocation location = event.getLocation(); + if (BallAPI.getInstance().isLocalServer(location.getServerID())) { + for (UUID uuid : event.getSendPlayerUUID()) { + playerToLocation.put(uuid, new BukkitLocation(location).toBukkitLocation()); + } + } + break; + } + case SendPlayerToPlayerEvent.ACTION: { + SendPlayerToPlayerEvent event = CoreConstantObjects.GSON.fromJson(info.getContent(), SendPlayerToPlayerEvent.class); + Player player = Bukkit.getPlayer(event.getToPlayerUUID()); + if (player == null) { + return; + } + Location location = player.getLocation(); + for (UUID uuid : event.getSendPlayerUUID()) { + playerToLocation.put(uuid, location); + } + break; + } + } + } + @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH) public void onPlayerLogin(PlayerLoginEvent event) { Player player = event.getPlayer(); diff --git a/hamster-ball-bungeecord/build.gradle b/hamster-ball-bungeecord/build.gradle index 1e95ddc..31ad948 100644 --- a/hamster-ball-bungeecord/build.gradle +++ b/hamster-ball-bungeecord/build.gradle @@ -1,4 +1,3 @@ -version = '1.0.0' setArchivesBaseName("HamsterBall-BungeeCord") evaluationDependsOn(':hamster-ball-common') @@ -8,7 +7,7 @@ dependencies { exclude group: "*" } - compileOnly 'net.md-5:bungeecord-api:1.17-R0.1-SNAPSHOT' + compileOnly 'net.md-5:bungeecord-api:1.19-R0.1-SNAPSHOT' compileOnly "cn.hamster3.mc.plugin:hamster-core-bungeecord:${hamster_core_version}" } diff --git a/hamster-ball-bungeecord/src/main/java/cn/hamster3/mc/plugin/core/bungee/api/BallBungeeCordAPI.java b/hamster-ball-bungeecord/src/main/java/cn/hamster3/mc/plugin/core/bungee/api/BallBungeeCordAPI.java index 1c0665f..c2d2a5c 100644 --- a/hamster-ball-bungeecord/src/main/java/cn/hamster3/mc/plugin/core/bungee/api/BallBungeeCordAPI.java +++ b/hamster-ball-bungeecord/src/main/java/cn/hamster3/mc/plugin/core/bungee/api/BallBungeeCordAPI.java @@ -2,8 +2,8 @@ package cn.hamster3.mc.plugin.core.bungee.api; import cn.hamster3.mc.plugin.ball.common.api.BallAPI; import cn.hamster3.mc.plugin.ball.common.config.BallConfig; -import cn.hamster3.mc.plugin.ball.common.entity.ServerInfo; -import cn.hamster3.mc.plugin.ball.common.entity.ServerType; +import cn.hamster3.mc.plugin.ball.common.entity.BallServerInfo; +import cn.hamster3.mc.plugin.ball.common.entity.BallServerType; import cn.hamster3.mc.plugin.core.bungee.HamsterBallPlugin; import cn.hamster3.mc.plugin.core.bungee.listener.BallBungeeCordListener; import cn.hamster3.mc.plugin.core.bungee.util.BungeeCordUtils; @@ -35,10 +35,10 @@ public class BallBungeeCordAPI extends BallAPI { Optional address = ProxyServer.getInstance().getConfig().getListeners().stream().findFirst().map(ListenerInfo::getHost); String host = pluginConfig.getString("server-info.name.host", address.map(InetSocketAddress::getHostName).orElse("")); BallConfig config = new BallConfig( - new ServerInfo( + new BallServerInfo( pluginConfig.getString("server-info.id"), pluginConfig.getString("server-info.name"), - ServerType.GAME, + BallServerType.GAME, host.isEmpty() ? "127.0.0.1" : host, pluginConfig.getInt("server-info.name.port", address.map(InetSocketAddress::getPort).orElse(25577)) ), diff --git a/hamster-ball-bungeecord/src/main/java/cn/hamster3/mc/plugin/core/bungee/listener/BallBungeeCordListener.java b/hamster-ball-bungeecord/src/main/java/cn/hamster3/mc/plugin/core/bungee/listener/BallBungeeCordListener.java index d6f67be..c227a38 100644 --- a/hamster-ball-bungeecord/src/main/java/cn/hamster3/mc/plugin/core/bungee/listener/BallBungeeCordListener.java +++ b/hamster-ball-bungeecord/src/main/java/cn/hamster3/mc/plugin/core/bungee/listener/BallBungeeCordListener.java @@ -1,13 +1,15 @@ package cn.hamster3.mc.plugin.core.bungee.listener; import cn.hamster3.mc.plugin.ball.common.api.BallAPI; -import cn.hamster3.mc.plugin.ball.common.entity.PlayerInfo; -import cn.hamster3.mc.plugin.ball.common.entity.ServerType; +import cn.hamster3.mc.plugin.ball.common.data.BallMessageInfo; +import cn.hamster3.mc.plugin.ball.common.entity.BallPlayerInfo; +import cn.hamster3.mc.plugin.ball.common.entity.BallServerType; import cn.hamster3.mc.plugin.ball.common.event.operate.*; import cn.hamster3.mc.plugin.ball.common.event.player.*; import cn.hamster3.mc.plugin.ball.common.listener.BallListener; import cn.hamster3.mc.plugin.core.bungee.util.BallBungeeCordUtils; import cn.hamster3.mc.plugin.core.common.api.CoreAPI; +import cn.hamster3.mc.plugin.core.common.constant.CoreConstantObjects; import cn.hamster3.mc.plugin.core.common.data.Message; import net.kyori.adventure.audience.Audience; import net.kyori.adventure.text.serializer.bungeecord.BungeeComponentSerializer; @@ -29,56 +31,67 @@ public final class BallBungeeCordListener extends BallListener implements Listen } @Override - public void onBroadcastPlayerMessage(@NotNull BroadcastPlayerMessageEvent event) { - Message message = event.getMessage(); - Audience audience = CoreAPI.getInstance().getAudienceProvider().all(); - message.show(audience); + public void onReconnectFailed() { + ProxyServer.getInstance().stop(); } @Override - public void onDispatchConsoleCommand(@NotNull DispatchConsoleCommandEvent event) { - if (event.getType() != null && event.getType() != ServerType.PROXY) { - return; - } - if (event.getServerID() != null && !BallAPI.getInstance().isLocalServer(event.getServerID())) { - return; - } - ProxyServer server = ProxyServer.getInstance(); - server.getPluginManager().dispatchCommand(server.getConsole(), event.getCommand()); - } - - @Override - public void onDispatchPlayerCommand(@NotNull DispatchPlayerCommandEvent event) { - if (event.getType() != null && event.getType() != ServerType.GAME) { - return; - } - ProxyServer server = ProxyServer.getInstance(); - if (event.getUuid() != null) { - ProxiedPlayer player = server.getPlayer(event.getUuid()); - if (player == null) { - return; + public void onMessageReceived(@NotNull BallMessageInfo info) { + switch (info.getAction()) { + case BroadcastPlayerMessageEvent.ACTION: { + BroadcastPlayerMessageEvent event = CoreConstantObjects.GSON.fromJson(info.getContent(), BroadcastPlayerMessageEvent.class); + Message message = event.getMessage(); + Audience audience = CoreAPI.getInstance().getAudienceProvider().all(); + message.show(audience); + break; + } + case DispatchConsoleCommandEvent.ACTION: { + DispatchConsoleCommandEvent event = CoreConstantObjects.GSON.fromJson(info.getContent(), DispatchConsoleCommandEvent.class); + if (event.getType() != null && event.getType() != BallServerType.PROXY) { + return; + } + if (event.getServerID() != null && !BallAPI.getInstance().isLocalServer(event.getServerID())) { + return; + } + ProxyServer server = ProxyServer.getInstance(); + server.getPluginManager().dispatchCommand(server.getConsole(), event.getCommand()); + break; + } + case DispatchPlayerCommandEvent.ACTION: { + DispatchPlayerCommandEvent event = CoreConstantObjects.GSON.fromJson(info.getContent(), DispatchPlayerCommandEvent.class); + if (event.getType() != null && event.getType() != BallServerType.GAME) { + return; + } + ProxyServer server = ProxyServer.getInstance(); + if (event.getUuid() != null) { + ProxiedPlayer player = server.getPlayer(event.getUuid()); + if (player == null) { + return; + } + server.getPluginManager().dispatchCommand(player, event.getCommand()); + return; + } + for (ProxiedPlayer player : server.getPlayers()) { + server.getPluginManager().dispatchCommand(player, event.getCommand()); + } + break; + } + case KickPlayerEvent.ACTION: { + KickPlayerEvent event = CoreConstantObjects.GSON.fromJson(info.getContent(), KickPlayerEvent.class); + ProxiedPlayer player = ProxyServer.getInstance().getPlayer(event.getUuid()); + BaseComponent[] components = BungeeComponentSerializer.get().serialize(event.getReason()); + player.disconnect(components); + break; + } + case SendMessageToPlayerEvent.ACTION: { + SendMessageToPlayerEvent event = CoreConstantObjects.GSON.fromJson(info.getContent(), SendMessageToPlayerEvent.class); + for (UUID uuid : event.getReceiver()) { + Audience audience = CoreAPI.getInstance().getAudienceProvider().player(uuid); + event.getMessage().show(audience); + } + break; } - server.getPluginManager().dispatchCommand(player, event.getCommand()); - return; } - for (ProxiedPlayer player : server.getPlayers()) { - server.getPluginManager().dispatchCommand(player, event.getCommand()); - } - } - - @Override - public void onSendMessageToPlayer(@NotNull SendMessageToPlayerEvent event) { - for (UUID uuid : event.getReceiver()) { - Audience audience = CoreAPI.getInstance().getAudienceProvider().player(uuid); - event.getMessage().show(audience); - } - } - - @Override - public void onKickPlayer(@NotNull KickPlayerEvent event) { - ProxiedPlayer player = ProxyServer.getInstance().getPlayer(event.getUuid()); - BaseComponent[] components = BungeeComponentSerializer.get().serialize(event.getReason()); - player.disconnect(components); } @EventHandler(priority = EventPriority.HIGH) @@ -98,7 +111,7 @@ public final class BallBungeeCordListener extends BallListener implements Listen BallAPI.getInstance().sendBallMessage( BallAPI.BALL_CHANNEL, BallPlayerLoginEvent.ACTION, - new BallPlayerLoginEvent(new PlayerInfo( + new BallPlayerLoginEvent(new BallPlayerInfo( event.getConnection().getUniqueId(), event.getConnection().getName(), "", @@ -121,7 +134,7 @@ public final class BallBungeeCordListener extends BallListener implements Listen @EventHandler(priority = EventPriority.HIGH) public void onServerConnect(ServerConnectEvent event) { ProxiedPlayer player = event.getPlayer(); - PlayerInfo playerInfo = BallBungeeCordUtils.getPlayerInfo(player, true); + BallPlayerInfo playerInfo = BallBungeeCordUtils.getPlayerInfo(player, true); BallAPI.getInstance().sendBallMessage( BallAPI.BALL_CHANNEL, BallPlayerConnectServerEvent.ACTION, @@ -132,7 +145,7 @@ public final class BallBungeeCordListener extends BallListener implements Listen @EventHandler(priority = EventPriority.HIGH) public void onServerConnected(ServerConnectedEvent event) { ProxiedPlayer player = event.getPlayer(); - PlayerInfo playerInfo = BallBungeeCordUtils.getPlayerInfo(player, true); + BallPlayerInfo playerInfo = BallBungeeCordUtils.getPlayerInfo(player, true); BallAPI.getInstance().sendBallMessage( BallAPI.BALL_CHANNEL, BallPlayerPostConnectServerEvent.ACTION, diff --git a/hamster-ball-bungeecord/src/main/java/cn/hamster3/mc/plugin/core/bungee/util/BallBungeeCordUtils.java b/hamster-ball-bungeecord/src/main/java/cn/hamster3/mc/plugin/core/bungee/util/BallBungeeCordUtils.java index cd32613..46f3d1e 100644 --- a/hamster-ball-bungeecord/src/main/java/cn/hamster3/mc/plugin/core/bungee/util/BallBungeeCordUtils.java +++ b/hamster-ball-bungeecord/src/main/java/cn/hamster3/mc/plugin/core/bungee/util/BallBungeeCordUtils.java @@ -1,7 +1,7 @@ package cn.hamster3.mc.plugin.core.bungee.util; import cn.hamster3.mc.plugin.ball.common.api.BallAPI; -import cn.hamster3.mc.plugin.ball.common.entity.PlayerInfo; +import cn.hamster3.mc.plugin.ball.common.entity.BallPlayerInfo; import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.connection.Server; @@ -9,9 +9,9 @@ public final class BallBungeeCordUtils { private BallBungeeCordUtils() { } - public static PlayerInfo getPlayerInfo(ProxiedPlayer player, boolean online) { + public static BallPlayerInfo getPlayerInfo(ProxiedPlayer player, boolean online) { Server server = player.getServer(); - return new PlayerInfo( + return new BallPlayerInfo( player.getUniqueId(), player.getName(), server == null ? "" : server.getInfo().getName(), diff --git a/hamster-ball-common/build.gradle b/hamster-ball-common/build.gradle index 1ee7518..d6c5264 100644 --- a/hamster-ball-common/build.gradle +++ b/hamster-ball-common/build.gradle @@ -1,4 +1,3 @@ -version = '1.0.0' setArchivesBaseName("HamsterBall-Common") dependencies { diff --git a/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/api/BallAPI.java b/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/api/BallAPI.java index fa2e655..3b97243 100644 --- a/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/api/BallAPI.java +++ b/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/api/BallAPI.java @@ -3,11 +3,11 @@ package cn.hamster3.mc.plugin.ball.common.api; import cn.hamster3.mc.plugin.ball.common.config.BallConfig; import cn.hamster3.mc.plugin.ball.common.connector.BallChannelInitializer; import cn.hamster3.mc.plugin.ball.common.constant.BallCommonConstants; -import cn.hamster3.mc.plugin.ball.common.data.MessageInfo; -import cn.hamster3.mc.plugin.ball.common.data.ServiceLocation; -import cn.hamster3.mc.plugin.ball.common.entity.PlayerInfo; -import cn.hamster3.mc.plugin.ball.common.entity.ServerInfo; -import cn.hamster3.mc.plugin.ball.common.entity.ServerType; +import cn.hamster3.mc.plugin.ball.common.data.BallLocation; +import cn.hamster3.mc.plugin.ball.common.data.BallMessageInfo; +import cn.hamster3.mc.plugin.ball.common.entity.BallPlayerInfo; +import cn.hamster3.mc.plugin.ball.common.entity.BallServerInfo; +import cn.hamster3.mc.plugin.ball.common.entity.BallServerType; import cn.hamster3.mc.plugin.ball.common.event.operate.*; import cn.hamster3.mc.plugin.ball.common.event.player.*; import cn.hamster3.mc.plugin.ball.common.event.server.ServerOfflineEvent; @@ -34,6 +34,7 @@ import java.sql.*; import java.util.*; import java.util.concurrent.ConcurrentHashMap; +@SuppressWarnings("unused") public abstract class BallAPI { /** * API 使用的通信频道 @@ -44,9 +45,9 @@ public abstract class BallAPI { */ protected static BallAPI instance; @NotNull - protected final ConcurrentHashMap serverInfo; + protected final ConcurrentHashMap serverInfo; @NotNull - protected final ConcurrentHashMap playerInfo; + protected final ConcurrentHashMap playerInfo; @NotNull private final BallConfig config; @@ -82,37 +83,37 @@ public abstract class BallAPI { @Override public void onBallPlayerConnectServer(@NotNull BallPlayerConnectServerEvent event) { - PlayerInfo info = event.getPlayerInfo(); + BallPlayerInfo info = event.getPlayerInfo(); playerInfo.put(info.getUuid(), info); } @Override public void onBallPlayerLogout(@NotNull BallPlayerLogoutEvent event) { - PlayerInfo info = event.getPlayerInfo(); + BallPlayerInfo info = event.getPlayerInfo(); playerInfo.put(info.getUuid(), info); } @Override public void onBallPlayerLogin(@NotNull BallPlayerLoginEvent event) { - PlayerInfo info = event.getPlayerInfo(); + BallPlayerInfo info = event.getPlayerInfo(); playerInfo.put(info.getUuid(), info); } @Override public void onBallPlayerPostConnectServer(@NotNull BallPlayerPostConnectServerEvent event) { - PlayerInfo info = event.getPlayerInfo(); + BallPlayerInfo info = event.getPlayerInfo(); playerInfo.put(info.getUuid(), info); } @Override public void onBallPlayerPostLogin(@NotNull BallPlayerPostLoginEvent event) { - PlayerInfo info = event.getPlayerInfo(); + BallPlayerInfo info = event.getPlayerInfo(); playerInfo.put(info.getUuid(), info); } @Override public void onBallPlayerPreConnectServer(@NotNull BallPlayerPreConnectServerEvent event) { - PlayerInfo info = event.getPlayerInfo(); + BallPlayerInfo info = event.getPlayerInfo(); playerInfo.put(info.getUuid(), info); } @@ -124,7 +125,7 @@ public abstract class BallAPI { @Override public void onServerOnline(@NotNull ServerOnlineEvent event) { - ServerInfo info = event.getServerInfo(); + BallServerInfo info = event.getServerInfo(); serverInfo.put(info.getId(), info); } @@ -149,7 +150,7 @@ public abstract class BallAPI { return; } enable = true; - ServerInfo localInfo = getLocalServerInfo(); + BallServerInfo localInfo = getLocalServerInfo(); connect(); @@ -194,10 +195,10 @@ public abstract class BallAPI { ResultSet set = statement.executeQuery(); while (set.next()) { String serverID = set.getString("id"); - serverInfo.put(serverID, new ServerInfo( + serverInfo.put(serverID, new BallServerInfo( serverID, set.getString("name"), - ServerType.valueOf(set.getString("type")), + BallServerType.valueOf(set.getString("type")), set.getString("host"), set.getInt("port") )); @@ -211,7 +212,7 @@ public abstract class BallAPI { ResultSet set = statement.executeQuery(); while (set.next()) { UUID uuid = UUID.fromString(set.getString("uuid")); - playerInfo.put(uuid, new PlayerInfo(uuid, + playerInfo.put(uuid, new BallPlayerInfo(uuid, set.getString("name"), set.getString("game_server"), set.getString("proxy_server"), @@ -238,6 +239,9 @@ public abstract class BallAPI { ChannelFuture future = bootstrap.connect(config.getHost(), config.getPort()).await(); if (future.isSuccess()) { channel = future.channel(); + for (BallListener listener : listeners) { + listener.onConnectActive(); + } } } @@ -299,7 +303,7 @@ public abstract class BallAPI { * @param info 服务器信息 * @return true 代表该服务器信息是本服服务器 */ - public boolean isLocalServer(@NotNull ServerInfo info) { + public boolean isLocalServer(@NotNull BallServerInfo info) { return getLocalServerInfo().equals(info); } @@ -330,7 +334,7 @@ public abstract class BallAPI { public void broadcastPlayerMessage(@NotNull Message message) { sendBallMessage( BALL_CHANNEL, - ServerType.PROXY, + BallServerType.PROXY, BroadcastPlayerMessageEvent.ACTION, new BroadcastPlayerMessageEvent(message) ); @@ -343,10 +347,10 @@ public abstract class BallAPI { * @param serverID 执行对象的 ID * @param command 命令内容 */ - public void dispatchConsoleCommand(@Nullable ServerType type, @Nullable String serverID, @NotNull String command) { + public void dispatchConsoleCommand(@Nullable BallServerType type, @Nullable String serverID, @NotNull String command) { sendBallMessage( BALL_CHANNEL, - ServerType.GAME, + BallServerType.GAME, DispatchConsoleCommandEvent.ACTION, new DispatchConsoleCommandEvent(type, serverID, command) @@ -360,10 +364,10 @@ public abstract class BallAPI { * @param uuid 执行对象的 UUID * @param command 命令内容 */ - public void dispatchPlayerCommand(@Nullable ServerType type, @Nullable UUID uuid, @NotNull String command) { + public void dispatchPlayerCommand(@Nullable BallServerType type, @Nullable UUID uuid, @NotNull String command) { sendBallMessage( BALL_CHANNEL, - ServerType.GAME, + BallServerType.GAME, DispatchPlayerCommandEvent.ACTION, new DispatchPlayerCommandEvent(type, uuid, command) @@ -389,7 +393,7 @@ public abstract class BallAPI { public void kickPlayer(@NotNull UUID uuid, @NotNull Component reason) { sendBallMessage( BALL_CHANNEL, - ServerType.PROXY, + BallServerType.PROXY, KickPlayerEvent.ACTION, new KickPlayerEvent(uuid, reason) @@ -404,7 +408,7 @@ public abstract class BallAPI { * @param cache 当玩家不在线时,是否缓存消息等待玩家上线再发送 */ public void sendMessageToPlayer(@NotNull UUID uuid, @NotNull Message message, boolean cache) { - PlayerInfo info = getPlayerInfo(uuid); + BallPlayerInfo info = getPlayerInfo(uuid); if (info == null || !info.isOnline()) { if (!cache) { return; @@ -422,7 +426,7 @@ public abstract class BallAPI { } sendBallMessage( BALL_CHANNEL, - ServerType.PROXY, + BallServerType.PROXY, SendMessageToPlayerEvent.ACTION, new SendMessageToPlayerEvent(Collections.singleton(uuid), message) @@ -438,7 +442,7 @@ public abstract class BallAPI { */ public void sendMessageToPlayer(@NotNull Set receiver, @NotNull Message message, boolean cache) { for (UUID uuid : receiver) { - PlayerInfo info = getPlayerInfo(uuid); + BallPlayerInfo info = getPlayerInfo(uuid); if (info == null || !info.isOnline()) { if (!cache) { return; @@ -457,7 +461,7 @@ public abstract class BallAPI { } sendBallMessage( BALL_CHANNEL, - ServerType.PROXY, + BallServerType.PROXY, SendMessageToPlayerEvent.ACTION, new SendMessageToPlayerEvent(receiver, message) ); @@ -475,7 +479,7 @@ public abstract class BallAPI { * @param location 坐标 * @param doneMessage 传送完成后显示的消息 */ - public void sendPlayerToLocation(@NotNull UUID sendPlayerUUID, @NotNull ServiceLocation location, @Nullable Message doneMessage) { + public void sendPlayerToLocation(@NotNull UUID sendPlayerUUID, @NotNull BallLocation location, @Nullable Message doneMessage) { sendBallMessage( BALL_CHANNEL, SendPlayerToLocationEvent.ACTION, @@ -494,7 +498,7 @@ public abstract class BallAPI { * @param location 坐标 * @param doneMessage 传送完成后显示的消息 */ - public void sendPlayerToLocation(@NotNull HashSet sendPlayerUUID, @NotNull ServiceLocation location, @Nullable Message doneMessage) { + public void sendPlayerToLocation(@NotNull HashSet sendPlayerUUID, @NotNull BallLocation location, @Nullable Message doneMessage) { sendBallMessage( BALL_CHANNEL, SendPlayerToLocationEvent.ACTION, @@ -542,7 +546,7 @@ public abstract class BallAPI { * @param action 执行动作 */ public void sendBallMessage(@NotNull String channel, @NotNull String action) { - sendBallMessage(new MessageInfo(channel, getLocalServerId(), null, null, action, null)); + sendBallMessage(new BallMessageInfo(channel, getLocalServerId(), null, null, action, null)); } /** @@ -553,7 +557,7 @@ public abstract class BallAPI { * @param content 附加参数 */ public void sendBallMessage(@NotNull String channel, @NotNull String action, @NotNull String content) { - sendBallMessage(new MessageInfo(channel, getLocalServerId(), null, null, action, new JsonPrimitive(content))); + sendBallMessage(new BallMessageInfo(channel, getLocalServerId(), null, null, action, new JsonPrimitive(content))); } /** @@ -564,7 +568,7 @@ public abstract class BallAPI { * @param content 附加参数 */ public void sendBallMessage(@NotNull String channel, @NotNull String action, @NotNull JsonElement content) { - sendBallMessage(new MessageInfo(channel, getLocalServerId(), null, null, action, content)); + sendBallMessage(new BallMessageInfo(channel, getLocalServerId(), null, null, action, content)); } /** @@ -575,7 +579,7 @@ public abstract class BallAPI { * @param content 附加参数 */ public void sendBallMessage(@NotNull String channel, @NotNull String action, @NotNull Object content) { - sendBallMessage(new MessageInfo(channel, getLocalServerId(), null, null, action, CoreConstantObjects.GSON.toJsonTree(content))); + sendBallMessage(new BallMessageInfo(channel, getLocalServerId(), null, null, action, CoreConstantObjects.GSON.toJsonTree(content))); } /** @@ -585,8 +589,8 @@ public abstract class BallAPI { * @param action 执行动作 * @param content 附加参数 */ - public void sendBallMessage(@NotNull String channel, @Nullable ServerType receiverType, @NotNull String action, @NotNull JsonElement content) { - sendBallMessage(new MessageInfo(channel, getLocalServerId(), null, receiverType, action, content)); + public void sendBallMessage(@NotNull String channel, @Nullable BallServerType receiverType, @NotNull String action, @NotNull JsonElement content) { + sendBallMessage(new BallMessageInfo(channel, getLocalServerId(), null, receiverType, action, content)); } /** @@ -596,8 +600,8 @@ public abstract class BallAPI { * @param action 执行动作 * @param content 附加参数 */ - public void sendBallMessage(@NotNull String channel, @Nullable ServerType receiverType, @NotNull String action, @NotNull Object content) { - sendBallMessage(new MessageInfo(channel, getLocalServerId(), null, receiverType, action, CoreConstantObjects.GSON.toJsonTree(content))); + public void sendBallMessage(@NotNull String channel, @Nullable BallServerType receiverType, @NotNull String action, @NotNull Object content) { + sendBallMessage(new BallMessageInfo(channel, getLocalServerId(), null, receiverType, action, CoreConstantObjects.GSON.toJsonTree(content))); } /** @@ -605,7 +609,7 @@ public abstract class BallAPI { * * @param messageInfo 消息内容 */ - public void sendBallMessage(@NotNull MessageInfo messageInfo) { + public void sendBallMessage(@NotNull BallMessageInfo messageInfo) { sendBallMessage(messageInfo, false); } @@ -615,7 +619,7 @@ public abstract class BallAPI { * @param messageInfo 消息内容 * @param block 是否阻塞(设置为 true 则必须等待消息写入网络的操作完成后,该方法才会退出) */ - public void sendBallMessage(@NotNull MessageInfo messageInfo, boolean block) { + public void sendBallMessage(@NotNull BallMessageInfo messageInfo, boolean block) { if (channel == null || !channel.isWritable()) { return; } @@ -676,7 +680,7 @@ public abstract class BallAPI { * @return 服务器ID */ @NotNull - public ServerInfo getLocalServerInfo() { + public BallServerInfo getLocalServerInfo() { return config.getLocalInfo(); } @@ -691,7 +695,7 @@ public abstract class BallAPI { * @param serverID 服务器ID * @return 可能为 null */ - public ServerInfo getServerInfo(@NotNull String serverID) { + public BallServerInfo getServerInfo(@NotNull String serverID) { return serverInfo.get(serverID); } @@ -701,7 +705,7 @@ public abstract class BallAPI { * @param uuid 玩家的 UUID * @return 玩家信息 */ - public PlayerInfo getPlayerInfo(@NotNull UUID uuid) { + public BallPlayerInfo getPlayerInfo(@NotNull UUID uuid) { return playerInfo.get(uuid); } @@ -711,7 +715,7 @@ public abstract class BallAPI { * @param playerName 玩家名称 * @return 玩家信息 */ - public PlayerInfo getPlayerInfo(@NotNull String playerName) { + public BallPlayerInfo getPlayerInfo(@NotNull String playerName) { return playerInfo.searchValues(Long.MAX_VALUE, info -> { if (info.getName().equalsIgnoreCase(playerName)) { return info; @@ -721,12 +725,12 @@ public abstract class BallAPI { } @NotNull - public ConcurrentHashMap getAllServerInfo() { + public ConcurrentHashMap getAllServerInfo() { return serverInfo; } @NotNull - public ConcurrentHashMap getAllPlayerInfo() { + public ConcurrentHashMap getAllPlayerInfo() { return playerInfo; } diff --git a/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/config/BallConfig.java b/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/config/BallConfig.java index fc5fe28..d8fec80 100644 --- a/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/config/BallConfig.java +++ b/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/config/BallConfig.java @@ -1,6 +1,6 @@ package cn.hamster3.mc.plugin.ball.common.config; -import cn.hamster3.mc.plugin.ball.common.entity.ServerInfo; +import cn.hamster3.mc.plugin.ball.common.entity.BallServerInfo; import lombok.AllArgsConstructor; import lombok.Data; import org.jetbrains.annotations.NotNull; @@ -9,7 +9,7 @@ import org.jetbrains.annotations.NotNull; @AllArgsConstructor public class BallConfig { @NotNull - private ServerInfo localInfo; + private BallServerInfo localInfo; @NotNull private String host; diff --git a/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/connector/BallChannelInboundHandler.java b/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/connector/BallChannelInboundHandler.java index 7682026..b65e9ab 100644 --- a/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/connector/BallChannelInboundHandler.java +++ b/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/connector/BallChannelInboundHandler.java @@ -1,8 +1,7 @@ package cn.hamster3.mc.plugin.ball.common.connector; import cn.hamster3.mc.plugin.ball.common.api.BallAPI; -import cn.hamster3.mc.plugin.ball.common.data.MessageInfo; -import cn.hamster3.mc.plugin.ball.common.event.operate.*; +import cn.hamster3.mc.plugin.ball.common.data.BallMessageInfo; import cn.hamster3.mc.plugin.ball.common.event.player.*; import cn.hamster3.mc.plugin.ball.common.event.server.ServerOfflineEvent; import cn.hamster3.mc.plugin.ball.common.event.server.ServerOnlineEvent; @@ -20,7 +19,7 @@ public class BallChannelInboundHandler extends SimpleChannelInboundHandler diff --git a/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/entity/PlayerInfo.java b/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/entity/BallPlayerInfo.java similarity index 92% rename from hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/entity/PlayerInfo.java rename to hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/entity/BallPlayerInfo.java index 474c086..4364117 100644 --- a/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/entity/PlayerInfo.java +++ b/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/entity/BallPlayerInfo.java @@ -12,7 +12,7 @@ import java.util.UUID; @Data @NotNull @AllArgsConstructor -public class PlayerInfo { +public class BallPlayerInfo { /** * 玩家的uuid */ @@ -47,7 +47,7 @@ public class PlayerInfo { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; - PlayerInfo that = (PlayerInfo) o; + BallPlayerInfo that = (BallPlayerInfo) o; return uuid.equals(that.uuid); } diff --git a/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/entity/ServerInfo.java b/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/entity/BallServerInfo.java similarity index 89% rename from hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/entity/ServerInfo.java rename to hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/entity/BallServerInfo.java index 3b2e3bd..89f003d 100644 --- a/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/entity/ServerInfo.java +++ b/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/entity/BallServerInfo.java @@ -12,7 +12,7 @@ import java.util.Objects; @Data @NoArgsConstructor @AllArgsConstructor -public class ServerInfo { +public class BallServerInfo { /** * 服务器 ID *

@@ -28,7 +28,7 @@ public class ServerInfo { /** * 服务器类型 */ - private ServerType type; + private BallServerType type; /** * 服务器主机名 *

@@ -44,7 +44,7 @@ public class ServerInfo { public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; - ServerInfo that = (ServerInfo) o; + BallServerInfo that = (BallServerInfo) o; return id.equals(that.id); } diff --git a/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/entity/ServerType.java b/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/entity/BallServerType.java similarity index 91% rename from hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/entity/ServerType.java rename to hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/entity/BallServerType.java index 263488f..d6b4ba2 100644 --- a/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/entity/ServerType.java +++ b/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/entity/BallServerType.java @@ -4,7 +4,7 @@ package cn.hamster3.mc.plugin.ball.common.entity; * Service 接入者的类型 */ @SuppressWarnings("unused") -public enum ServerType { +public enum BallServerType { /** * 游戏服务器 */ diff --git a/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/event/operate/DispatchConsoleCommandEvent.java b/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/event/operate/DispatchConsoleCommandEvent.java index a1c0d00..a27e40e 100644 --- a/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/event/operate/DispatchConsoleCommandEvent.java +++ b/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/event/operate/DispatchConsoleCommandEvent.java @@ -1,6 +1,6 @@ package cn.hamster3.mc.plugin.ball.common.event.operate; -import cn.hamster3.mc.plugin.ball.common.entity.ServerType; +import cn.hamster3.mc.plugin.ball.common.entity.BallServerType; import lombok.AllArgsConstructor; import lombok.Data; import org.jetbrains.annotations.NotNull; @@ -12,7 +12,7 @@ public class DispatchConsoleCommandEvent { public static final String ACTION = "DispatchConsoleCommand"; @Nullable - private final ServerType type; + private final BallServerType type; @Nullable private final String serverID; @NotNull diff --git a/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/event/operate/DispatchPlayerCommandEvent.java b/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/event/operate/DispatchPlayerCommandEvent.java index 2ff635b..e13018b 100644 --- a/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/event/operate/DispatchPlayerCommandEvent.java +++ b/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/event/operate/DispatchPlayerCommandEvent.java @@ -1,6 +1,6 @@ package cn.hamster3.mc.plugin.ball.common.event.operate; -import cn.hamster3.mc.plugin.ball.common.entity.ServerType; +import cn.hamster3.mc.plugin.ball.common.entity.BallServerType; import lombok.AllArgsConstructor; import lombok.Data; import org.jetbrains.annotations.NotNull; @@ -14,7 +14,7 @@ public class DispatchPlayerCommandEvent { public static final String ACTION = "DispatchPlayerCommand"; @Nullable - private final ServerType type; + private final BallServerType type; @Nullable private final UUID uuid; @NotNull diff --git a/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/event/operate/SendPlayerToLocationEvent.java b/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/event/operate/SendPlayerToLocationEvent.java index 0cd2518..aa3ef39 100644 --- a/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/event/operate/SendPlayerToLocationEvent.java +++ b/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/event/operate/SendPlayerToLocationEvent.java @@ -1,6 +1,6 @@ package cn.hamster3.mc.plugin.ball.common.event.operate; -import cn.hamster3.mc.plugin.ball.common.data.ServiceLocation; +import cn.hamster3.mc.plugin.ball.common.data.BallLocation; import cn.hamster3.mc.plugin.core.common.data.Message; import lombok.AllArgsConstructor; import lombok.Data; @@ -18,7 +18,7 @@ public class SendPlayerToLocationEvent { @NotNull private final Set sendPlayerUUID; @NotNull - private final ServiceLocation location; + private final BallLocation location; @Nullable private final Message doneMessage; diff --git a/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/event/player/BallPlayerConnectServerEvent.java b/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/event/player/BallPlayerConnectServerEvent.java index f7d705f..38c64c4 100644 --- a/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/event/player/BallPlayerConnectServerEvent.java +++ b/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/event/player/BallPlayerConnectServerEvent.java @@ -1,6 +1,6 @@ package cn.hamster3.mc.plugin.ball.common.event.player; -import cn.hamster3.mc.plugin.ball.common.entity.PlayerInfo; +import cn.hamster3.mc.plugin.ball.common.entity.BallPlayerInfo; import lombok.AllArgsConstructor; import lombok.Data; import org.jetbrains.annotations.NotNull; @@ -15,7 +15,7 @@ public class BallPlayerConnectServerEvent { public static final String ACTION = "PlayerConnectServer"; @NotNull - private final PlayerInfo playerInfo; + private final BallPlayerInfo playerInfo; @Nullable private final String from; @NotNull diff --git a/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/event/player/BallPlayerLoginEvent.java b/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/event/player/BallPlayerLoginEvent.java index 46d0ea9..8605061 100644 --- a/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/event/player/BallPlayerLoginEvent.java +++ b/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/event/player/BallPlayerLoginEvent.java @@ -1,6 +1,6 @@ package cn.hamster3.mc.plugin.ball.common.event.player; -import cn.hamster3.mc.plugin.ball.common.entity.PlayerInfo; +import cn.hamster3.mc.plugin.ball.common.entity.BallPlayerInfo; import lombok.AllArgsConstructor; import lombok.Data; import org.jetbrains.annotations.NotNull; @@ -14,6 +14,6 @@ public class BallPlayerLoginEvent { public static final String ACTION = "PlayerLogin"; @NotNull - private final PlayerInfo playerInfo; + private final BallPlayerInfo playerInfo; } diff --git a/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/event/player/BallPlayerLogoutEvent.java b/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/event/player/BallPlayerLogoutEvent.java index eaffbca..fdca0b3 100644 --- a/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/event/player/BallPlayerLogoutEvent.java +++ b/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/event/player/BallPlayerLogoutEvent.java @@ -1,6 +1,6 @@ package cn.hamster3.mc.plugin.ball.common.event.player; -import cn.hamster3.mc.plugin.ball.common.entity.PlayerInfo; +import cn.hamster3.mc.plugin.ball.common.entity.BallPlayerInfo; import lombok.AllArgsConstructor; import lombok.Data; import org.jetbrains.annotations.NotNull; @@ -14,5 +14,5 @@ public class BallPlayerLogoutEvent { public static final String ACTION = "PlayerLogout"; @NotNull - private PlayerInfo playerInfo; + private BallPlayerInfo playerInfo; } diff --git a/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/event/player/BallPlayerPostConnectServerEvent.java b/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/event/player/BallPlayerPostConnectServerEvent.java index 4958a06..5171347 100644 --- a/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/event/player/BallPlayerPostConnectServerEvent.java +++ b/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/event/player/BallPlayerPostConnectServerEvent.java @@ -1,6 +1,6 @@ package cn.hamster3.mc.plugin.ball.common.event.player; -import cn.hamster3.mc.plugin.ball.common.entity.PlayerInfo; +import cn.hamster3.mc.plugin.ball.common.entity.BallPlayerInfo; import lombok.AllArgsConstructor; import lombok.Data; import org.jetbrains.annotations.NotNull; @@ -14,5 +14,5 @@ public class BallPlayerPostConnectServerEvent { public static final String ACTION = "PlayerPostConnectServer"; @NotNull - private final PlayerInfo playerInfo; + private final BallPlayerInfo playerInfo; } diff --git a/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/event/player/BallPlayerPostLoginEvent.java b/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/event/player/BallPlayerPostLoginEvent.java index 4809f0c..299fa50 100644 --- a/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/event/player/BallPlayerPostLoginEvent.java +++ b/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/event/player/BallPlayerPostLoginEvent.java @@ -1,6 +1,6 @@ package cn.hamster3.mc.plugin.ball.common.event.player; -import cn.hamster3.mc.plugin.ball.common.entity.PlayerInfo; +import cn.hamster3.mc.plugin.ball.common.entity.BallPlayerInfo; import lombok.AllArgsConstructor; import lombok.Data; import org.jetbrains.annotations.NotNull; @@ -14,5 +14,5 @@ public class BallPlayerPostLoginEvent { public static final String ACTION = "PlayerPostLogin"; @NotNull - private final PlayerInfo playerInfo; + private final BallPlayerInfo playerInfo; } diff --git a/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/event/player/BallPlayerPreConnectServerEvent.java b/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/event/player/BallPlayerPreConnectServerEvent.java index d0a0b8e..6663575 100644 --- a/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/event/player/BallPlayerPreConnectServerEvent.java +++ b/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/event/player/BallPlayerPreConnectServerEvent.java @@ -1,6 +1,6 @@ package cn.hamster3.mc.plugin.ball.common.event.player; -import cn.hamster3.mc.plugin.ball.common.entity.PlayerInfo; +import cn.hamster3.mc.plugin.ball.common.entity.BallPlayerInfo; import lombok.AllArgsConstructor; import lombok.Data; import org.jetbrains.annotations.NotNull; @@ -17,7 +17,7 @@ public class BallPlayerPreConnectServerEvent { public static final String ACTION = "PlayerPreConnectServer"; @NotNull - private final PlayerInfo playerInfo; + private final BallPlayerInfo playerInfo; @Nullable private final String from; @NotNull diff --git a/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/event/server/ServerOnlineEvent.java b/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/event/server/ServerOnlineEvent.java index 3c0d3be..1fc203e 100644 --- a/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/event/server/ServerOnlineEvent.java +++ b/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/event/server/ServerOnlineEvent.java @@ -1,6 +1,6 @@ package cn.hamster3.mc.plugin.ball.common.event.server; -import cn.hamster3.mc.plugin.ball.common.entity.ServerInfo; +import cn.hamster3.mc.plugin.ball.common.entity.BallServerInfo; import lombok.AllArgsConstructor; import lombok.Data; import org.jetbrains.annotations.NotNull; @@ -14,6 +14,6 @@ public class ServerOnlineEvent { public static final String ACTION = "ServerOnline"; @NotNull - private final ServerInfo serverInfo; + private final BallServerInfo serverInfo; } diff --git a/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/listener/BallListener.java b/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/listener/BallListener.java index 6c89e96..d46de55 100644 --- a/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/listener/BallListener.java +++ b/hamster-ball-common/src/main/java/cn/hamster3/mc/plugin/ball/common/listener/BallListener.java @@ -1,12 +1,12 @@ package cn.hamster3.mc.plugin.ball.common.listener; -import cn.hamster3.mc.plugin.ball.common.data.MessageInfo; -import cn.hamster3.mc.plugin.ball.common.event.operate.*; +import cn.hamster3.mc.plugin.ball.common.data.BallMessageInfo; import cn.hamster3.mc.plugin.ball.common.event.player.*; import cn.hamster3.mc.plugin.ball.common.event.server.ServerOfflineEvent; import cn.hamster3.mc.plugin.ball.common.event.server.ServerOnlineEvent; import org.jetbrains.annotations.NotNull; +@SuppressWarnings("unused") public abstract class BallListener { /** * 该监听器的执行优先级 @@ -17,25 +17,16 @@ public abstract class BallListener { return ListenerPriority.NORMAL; } - public void onBroadcastPlayerMessage(@NotNull BroadcastPlayerMessageEvent event) { + public void onConnectActive() { } - public void onDispatchConsoleCommand(@NotNull DispatchConsoleCommandEvent event) { + public void onConnectInactive() { } - public void onDispatchPlayerCommand(@NotNull DispatchPlayerCommandEvent event) { + public void onConnectException(Throwable throwable) { } - public void onKickPlayer(@NotNull KickPlayerEvent event) { - } - - public void onSendMessageToPlayer(@NotNull SendMessageToPlayerEvent event) { - } - - public void onSendPlayerToLocation(@NotNull SendPlayerToLocationEvent event) { - } - - public void onSendPlayerToPlayer(@NotNull SendPlayerToPlayerEvent event) { + public void onReconnectFailed() { } public void onBallPlayerPreLogin(@NotNull BallPlayerPreLoginEvent event) { @@ -68,19 +59,10 @@ public abstract class BallListener { public void onServerOnline(@NotNull ServerOnlineEvent event) { } - public void onMessageSend(@NotNull MessageInfo event) { + public void onMessageSend(@NotNull BallMessageInfo event) { } - public void onMessageReceived(@NotNull MessageInfo event) { - } - - public void onConnectInactive() { - } - - public void onConnectException(Throwable throwable) { - } - - public void onReconnectFailed() { + public void onMessageReceived(@NotNull BallMessageInfo event) { } } diff --git a/hamster-ball-server/build.gradle b/hamster-ball-server/build.gradle index 2b8ab4c..855da42 100644 --- a/hamster-ball-server/build.gradle +++ b/hamster-ball-server/build.gradle @@ -1,4 +1,3 @@ -version = '1.0.0' setArchivesBaseName("HamsterBall-Server") evaluationDependsOn(':hamster-ball-common') diff --git a/hamster-ball-server/src/main/java/cn/hamster3/mc/plugin/ball/server/connector/BallChannelHandler.java b/hamster-ball-server/src/main/java/cn/hamster3/mc/plugin/ball/server/connector/BallChannelHandler.java index 4331e7f..f62f86c 100644 --- a/hamster-ball-server/src/main/java/cn/hamster3/mc/plugin/ball/server/connector/BallChannelHandler.java +++ b/hamster-ball-server/src/main/java/cn/hamster3/mc/plugin/ball/server/connector/BallChannelHandler.java @@ -1,6 +1,6 @@ package cn.hamster3.mc.plugin.ball.server.connector; -import cn.hamster3.mc.plugin.ball.common.data.MessageInfo; +import cn.hamster3.mc.plugin.ball.common.data.BallMessageInfo; import cn.hamster3.mc.plugin.ball.server.constant.ConstantObjects; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.SimpleChannelInboundHandler; @@ -17,7 +17,7 @@ public class BallChannelHandler extends SimpleChannelInboundHandler { @Override protected void channelRead0(ChannelHandlerContext context, String message) { try { - MessageInfo messageInfo = ConstantObjects.GSON.fromJson(message, MessageInfo.class); + BallMessageInfo messageInfo = ConstantObjects.GSON.fromJson(message, BallMessageInfo.class); LOGGER.info("从服务器 {} 上收到一条消息: \n {}", messageInfo.getSenderID(), messageInfo); BallChannelInitializer.broadcastMessage(messageInfo); } catch (Exception e) { diff --git a/hamster-ball-server/src/main/java/cn/hamster3/mc/plugin/ball/server/connector/BallChannelInitializer.java b/hamster-ball-server/src/main/java/cn/hamster3/mc/plugin/ball/server/connector/BallChannelInitializer.java index c252b66..3828ca7 100644 --- a/hamster-ball-server/src/main/java/cn/hamster3/mc/plugin/ball/server/connector/BallChannelInitializer.java +++ b/hamster-ball-server/src/main/java/cn/hamster3/mc/plugin/ball/server/connector/BallChannelInitializer.java @@ -1,6 +1,6 @@ package cn.hamster3.mc.plugin.ball.server.connector; -import cn.hamster3.mc.plugin.ball.common.data.MessageInfo; +import cn.hamster3.mc.plugin.ball.common.data.BallMessageInfo; import cn.hamster3.mc.plugin.ball.server.config.ServerConfig; import io.netty.channel.Channel; import io.netty.channel.ChannelInitializer; @@ -26,7 +26,7 @@ public class BallChannelInitializer extends ChannelInitializer private BallChannelInitializer() { } - public static void broadcastMessage(MessageInfo messageInfo) { + public static void broadcastMessage(BallMessageInfo messageInfo) { String string = messageInfo.toString(); for (Channel channel : CHANNELS) { channel.writeAndFlush(string);