feat: 添加了连接已启用的事件

This commit is contained in:
2022-10-28 02:12:45 +08:00
parent cfe5648a69
commit 02f613071f
34 changed files with 248 additions and 318 deletions

View File

@@ -3,6 +3,7 @@ plugins {
}
group 'cn.hamster3.mc.plugin'
version = '1.0.0-SNAPSHOT'
subprojects {
apply plugin: 'java-library'

View File

@@ -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 {

View File

@@ -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())
),

View File

@@ -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(),

View File

@@ -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(),

View File

@@ -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<UUID, Location> 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();

View File

@@ -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}"
}

View File

@@ -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<InetSocketAddress> 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))
),

View File

@@ -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,

View File

@@ -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(),

View File

@@ -1,4 +1,3 @@
version = '1.0.0'
setArchivesBaseName("HamsterBall-Common")
dependencies {

View File

@@ -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<String, ServerInfo> serverInfo;
protected final ConcurrentHashMap<String, BallServerInfo> serverInfo;
@NotNull
protected final ConcurrentHashMap<UUID, PlayerInfo> playerInfo;
protected final ConcurrentHashMap<UUID, BallPlayerInfo> 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<UUID> 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<UUID> sendPlayerUUID, @NotNull ServiceLocation location, @Nullable Message doneMessage) {
public void sendPlayerToLocation(@NotNull HashSet<UUID> 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<String, ServerInfo> getAllServerInfo() {
public ConcurrentHashMap<String, BallServerInfo> getAllServerInfo() {
return serverInfo;
}
@NotNull
public ConcurrentHashMap<UUID, PlayerInfo> getAllPlayerInfo() {
public ConcurrentHashMap<UUID, BallPlayerInfo> getAllPlayerInfo() {
return playerInfo;
}

View File

@@ -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;

View File

@@ -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<Strin
@Override
protected void channelRead0(ChannelHandlerContext context, String message) {
MessageInfo info = CoreConstantObjects.GSON.fromJson(message, MessageInfo.class);
BallMessageInfo info = CoreConstantObjects.GSON.fromJson(message, BallMessageInfo.class);
for (BallListener listener : BallAPI.getInstance().getListeners()) {
try {
listener.onMessageReceived(info);
@@ -32,83 +31,6 @@ public class BallChannelInboundHandler extends SimpleChannelInboundHandler<Strin
return;
}
switch (info.getAction()) {
case BroadcastPlayerMessageEvent.ACTION: {
BroadcastPlayerMessageEvent event = CoreConstantObjects.GSON.fromJson(info.getContent(), BroadcastPlayerMessageEvent.class);
for (BallListener listener : BallAPI.getInstance().getListeners()) {
try {
listener.onBroadcastPlayerMessage(event);
} catch (Exception | Error e) {
e.printStackTrace();
}
}
break;
}
case DispatchConsoleCommandEvent.ACTION: {
DispatchConsoleCommandEvent event = CoreConstantObjects.GSON.fromJson(info.getContent(), DispatchConsoleCommandEvent.class);
for (BallListener listener : BallAPI.getInstance().getListeners()) {
try {
listener.onDispatchConsoleCommand(event);
} catch (Exception | Error e) {
e.printStackTrace();
}
}
break;
}
case DispatchPlayerCommandEvent.ACTION: {
DispatchPlayerCommandEvent event = CoreConstantObjects.GSON.fromJson(info.getContent(), DispatchPlayerCommandEvent.class);
for (BallListener listener : BallAPI.getInstance().getListeners()) {
try {
listener.onDispatchPlayerCommand(event);
} catch (Exception | Error e) {
e.printStackTrace();
}
}
break;
}
case KickPlayerEvent.ACTION: {
KickPlayerEvent event = CoreConstantObjects.GSON.fromJson(info.getContent(), KickPlayerEvent.class);
for (BallListener listener : BallAPI.getInstance().getListeners()) {
try {
listener.onKickPlayer(event);
} catch (Exception | Error e) {
e.printStackTrace();
}
}
break;
}
case SendMessageToPlayerEvent.ACTION: {
SendMessageToPlayerEvent event = CoreConstantObjects.GSON.fromJson(info.getContent(), SendMessageToPlayerEvent.class);
for (BallListener listener : BallAPI.getInstance().getListeners()) {
try {
listener.onSendMessageToPlayer(event);
} catch (Exception | Error e) {
e.printStackTrace();
}
}
break;
}
case SendPlayerToLocationEvent.ACTION: {
SendPlayerToLocationEvent event = CoreConstantObjects.GSON.fromJson(info.getContent(), SendPlayerToLocationEvent.class);
for (BallListener listener : BallAPI.getInstance().getListeners()) {
try {
listener.onSendPlayerToLocation(event);
} catch (Exception | Error e) {
e.printStackTrace();
}
}
break;
}
case SendPlayerToPlayerEvent.ACTION: {
SendPlayerToPlayerEvent event = CoreConstantObjects.GSON.fromJson(info.getContent(), SendPlayerToPlayerEvent.class);
for (BallListener listener : BallAPI.getInstance().getListeners()) {
try {
listener.onSendPlayerToPlayer(event);
} catch (Exception | Error e) {
e.printStackTrace();
}
}
break;
}
case BallPlayerPreLoginEvent.ACTION: {
BallPlayerPreLoginEvent event = CoreConstantObjects.GSON.fromJson(info.getContent(), BallPlayerPreLoginEvent.class);
for (BallListener listener : BallAPI.getInstance().getListeners()) {

View File

@@ -9,7 +9,7 @@ import org.jetbrains.annotations.NotNull;
@NoArgsConstructor
@AllArgsConstructor
@SuppressWarnings("unused")
public class ServiceBlockPos {
public class BallBlockPos {
private String serverID;
private String worldName;
private int x;
@@ -17,7 +17,7 @@ public class ServiceBlockPos {
private int z;
@NotNull
public ServiceLocation toServiceLocation() {
return new ServiceLocation(getServerID(), getWorldName(), getX(), getY(), getZ(), 0, 0);
public BallLocation toServiceLocation() {
return new BallLocation(getServerID(), getWorldName(), getX(), getY(), getZ(), 0, 0);
}
}

View File

@@ -9,7 +9,7 @@ import org.jetbrains.annotations.NotNull;
@NoArgsConstructor
@AllArgsConstructor
@SuppressWarnings("unused")
public class ServiceLocation {
public class BallLocation {
private String serverID;
private String worldName;
private double x;
@@ -32,7 +32,7 @@ public class ServiceLocation {
}
@NotNull
public ServiceBlockPos toServiceBlockPos() {
return new ServiceBlockPos(getServerID(), getWorldName(), getBlockX(), getBlockY(), getBlockZ());
public BallBlockPos toServiceBlockPos() {
return new BallBlockPos(getServerID(), getWorldName(), getBlockX(), getBlockY(), getBlockZ());
}
}

View File

@@ -1,6 +1,6 @@
package cn.hamster3.mc.plugin.ball.common.data;
import cn.hamster3.mc.plugin.ball.common.entity.ServerType;
import cn.hamster3.mc.plugin.ball.common.entity.BallServerType;
import cn.hamster3.mc.plugin.core.common.constant.CoreConstantObjects;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
@@ -22,7 +22,7 @@ import java.util.UUID;
@NoArgsConstructor
@AllArgsConstructor
@SuppressWarnings("unused")
public class MessageInfo {
public class BallMessageInfo {
/**
* 消息的频道
*/
@@ -50,7 +50,7 @@ public class MessageInfo {
* 若不设定值为null则该消息会广播给所有子端
*/
@Nullable
private ServerType receiverType;
private BallServerType receiverType;
/**
* 消息动作
* <p>

View File

@@ -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);
}

View File

@@ -12,7 +12,7 @@ import java.util.Objects;
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ServerInfo {
public class BallServerInfo {
/**
* 服务器 ID
* <p>
@@ -28,7 +28,7 @@ public class ServerInfo {
/**
* 服务器类型
*/
private ServerType type;
private BallServerType type;
/**
* 服务器主机名
* <p>
@@ -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);
}

View File

@@ -4,7 +4,7 @@ package cn.hamster3.mc.plugin.ball.common.entity;
* Service 接入者的类型
*/
@SuppressWarnings("unused")
public enum ServerType {
public enum BallServerType {
/**
* 游戏服务器
*/

View File

@@ -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

View File

@@ -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

View File

@@ -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<UUID> sendPlayerUUID;
@NotNull
private final ServiceLocation location;
private final BallLocation location;
@Nullable
private final Message doneMessage;

View File

@@ -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

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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

View File

@@ -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;
}

View File

@@ -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) {
}
}

View File

@@ -1,4 +1,3 @@
version = '1.0.0'
setArchivesBaseName("HamsterBall-Server")
evaluationDependsOn(':hamster-ball-common')

View File

@@ -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<String> {
@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) {

View File

@@ -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<NioSocketChannel>
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);