feat: 完善功能
This commit is contained in:
@@ -3,8 +3,8 @@ 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.data.ServiceMessageInfo;
|
||||
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;
|
||||
@@ -80,37 +80,37 @@ public abstract class BallAPI {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerConnectServer(@NotNull PlayerConnectServerEvent event) {
|
||||
public void onBallPlayerConnectServer(@NotNull BallPlayerConnectServerEvent event) {
|
||||
PlayerInfo info = event.getPlayerInfo();
|
||||
playerInfo.put(info.getUuid(), info);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerDisconnect(@NotNull PlayerDisconnectEvent event) {
|
||||
PlayerInfo info = playerInfo.get(event.getPlayerUUID());
|
||||
info.setOnline(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerLogin(@NotNull PlayerLoginEvent event) {
|
||||
public void onBallPlayerLogout(@NotNull BallPlayerLogoutEvent event) {
|
||||
PlayerInfo info = event.getPlayerInfo();
|
||||
playerInfo.put(info.getUuid(), info);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerPostConnectServer(@NotNull PlayerPostConnectServerEvent event) {
|
||||
public void onBallPlayerLogin(@NotNull BallPlayerLoginEvent event) {
|
||||
PlayerInfo info = event.getPlayerInfo();
|
||||
playerInfo.put(info.getUuid(), info);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerPostLogin(@NotNull PlayerPostLoginEvent event) {
|
||||
public void onBallPlayerPostConnectServer(@NotNull BallPlayerPostConnectServerEvent event) {
|
||||
PlayerInfo info = event.getPlayerInfo();
|
||||
playerInfo.put(info.getUuid(), info);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerPreConnectServer(@NotNull PlayerPreConnectServerEvent event) {
|
||||
public void onBallPlayerPostLogin(@NotNull BallPlayerPostLoginEvent event) {
|
||||
PlayerInfo info = event.getPlayerInfo();
|
||||
playerInfo.put(info.getUuid(), info);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBallPlayerPreConnectServer(@NotNull BallPlayerPreConnectServerEvent event) {
|
||||
PlayerInfo info = event.getPlayerInfo();
|
||||
playerInfo.put(info.getUuid(), info);
|
||||
}
|
||||
@@ -159,7 +159,6 @@ public abstract class BallAPI {
|
||||
statement.execute("CREATE TABLE IF NOT EXISTS " + BallCommonConstants.SQL.PLAYER_INFO_TABLE + "(" +
|
||||
"`uuid` CHAR(36) PRIMARY KEY," +
|
||||
"`name` VARCHAR(16) NOT NULL," +
|
||||
"`profile` TEXT NOT NULL," +
|
||||
"`game_server` VARCHAR(32) NOT NULL," +
|
||||
"`proxy_server` VARCHAR(32) NOT NULL," +
|
||||
"`online` BOOLEAN NOT NULL" +
|
||||
@@ -213,7 +212,6 @@ public abstract class BallAPI {
|
||||
UUID uuid = UUID.fromString(set.getString("uuid"));
|
||||
playerInfo.put(uuid, new PlayerInfo(uuid,
|
||||
set.getString("name"),
|
||||
CoreConstantObjects.JSON_PARSER.parse(set.getString("profile")).getAsJsonObject(),
|
||||
set.getString("game_server"),
|
||||
set.getString("proxy_server"),
|
||||
set.getBoolean("online")
|
||||
@@ -225,7 +223,7 @@ public abstract class BallAPI {
|
||||
|
||||
}
|
||||
|
||||
sendMessagingMessage(
|
||||
sendBallMessage(
|
||||
BALL_CHANNEL,
|
||||
ServerOnlineEvent.ACTION,
|
||||
new ServerOnlineEvent(localInfo)
|
||||
@@ -277,7 +275,7 @@ public abstract class BallAPI {
|
||||
}
|
||||
enable = false;
|
||||
|
||||
sendMessagingMessage(
|
||||
sendBallMessage(
|
||||
BALL_CHANNEL,
|
||||
ServerOfflineEvent.ACTION,
|
||||
new ServerOfflineEvent(getLocalServerId())
|
||||
@@ -329,7 +327,7 @@ public abstract class BallAPI {
|
||||
* @param message 消息
|
||||
*/
|
||||
public void broadcastPlayerMessage(@NotNull Message message) {
|
||||
sendMessagingMessage(
|
||||
sendBallMessage(
|
||||
BALL_CHANNEL,
|
||||
ServerType.PROXY,
|
||||
BroadcastPlayerMessageEvent.ACTION,
|
||||
@@ -345,7 +343,7 @@ public abstract class BallAPI {
|
||||
* @param command 命令内容
|
||||
*/
|
||||
public void dispatchConsoleCommand(@Nullable ServerType type, @Nullable String serverID, @NotNull String command) {
|
||||
sendMessagingMessage(
|
||||
sendBallMessage(
|
||||
BALL_CHANNEL,
|
||||
ServerType.GAME,
|
||||
DispatchConsoleCommandEvent.ACTION,
|
||||
@@ -362,7 +360,7 @@ public abstract class BallAPI {
|
||||
* @param command 命令内容
|
||||
*/
|
||||
public void dispatchPlayerCommand(@Nullable ServerType type, @Nullable UUID uuid, @NotNull String command) {
|
||||
sendMessagingMessage(
|
||||
sendBallMessage(
|
||||
BALL_CHANNEL,
|
||||
ServerType.GAME,
|
||||
DispatchPlayerCommandEvent.ACTION,
|
||||
@@ -388,7 +386,7 @@ public abstract class BallAPI {
|
||||
* @param reason 原因
|
||||
*/
|
||||
public void kickPlayer(@NotNull UUID uuid, @NotNull Component reason) {
|
||||
sendMessagingMessage(
|
||||
sendBallMessage(
|
||||
BALL_CHANNEL,
|
||||
ServerType.PROXY,
|
||||
KickPlayerEvent.ACTION,
|
||||
@@ -397,26 +395,6 @@ public abstract class BallAPI {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 给玩家发送一条消息
|
||||
*
|
||||
* @param uuid 玩家
|
||||
* @param message 消息
|
||||
*/
|
||||
public void sendMessageToPlayer(@NotNull UUID uuid, @NotNull String message) {
|
||||
sendMessageToPlayer(uuid, new Message().message(message), false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 给玩家发送一条消息
|
||||
*
|
||||
* @param uuid 玩家
|
||||
* @param message 消息
|
||||
*/
|
||||
public void sendMessageToPlayer(@NotNull UUID uuid, @NotNull Component message) {
|
||||
sendMessageToPlayer(uuid, new Message().message(message), false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 给玩家发送一条消息
|
||||
*
|
||||
@@ -441,33 +419,50 @@ public abstract class BallAPI {
|
||||
}
|
||||
return;
|
||||
}
|
||||
sendMessagingMessage(
|
||||
sendBallMessage(
|
||||
BALL_CHANNEL,
|
||||
ServerType.PROXY,
|
||||
SendMessageToPlayerEvent.ACTION,
|
||||
new SendMessageToPlayerEvent(uuid, message)
|
||||
new SendMessageToPlayerEvent(Collections.singleton(uuid), message)
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 把玩家传送到一个位置
|
||||
* <p>
|
||||
* 如果目标位置不在当前服务器
|
||||
* <p>
|
||||
* 则会先尝试将玩家连接至目标服务器再进行传送
|
||||
* 给玩家发送一条消息
|
||||
*
|
||||
* @param sendPlayerUUID 玩家的uuid
|
||||
* @param location 坐标
|
||||
* @param receiver 玩家
|
||||
* @param message 消息
|
||||
* @param cache 当玩家不在线时,是否缓存消息等待玩家上线再发送
|
||||
*/
|
||||
public void sendPlayerToLocation(@NotNull UUID sendPlayerUUID, @NotNull ServiceLocation location) {
|
||||
sendMessagingMessage(
|
||||
public void sendMessageToPlayer(@NotNull Set<UUID> receiver, @NotNull Message message, boolean cache) {
|
||||
for (UUID uuid : receiver) {
|
||||
PlayerInfo info = getPlayerInfo(uuid);
|
||||
if (info == null || !info.isOnline()) {
|
||||
if (!cache) {
|
||||
return;
|
||||
}
|
||||
try (Connection connection = CoreAPI.getInstance().getConnection()) {
|
||||
PreparedStatement statement = connection.prepareStatement("INSERT INTO " + BallCommonConstants.SQL.CACHED_MESSAGE_TABLE + " VALUES(?, ?);");
|
||||
statement.setString(1, uuid.toString());
|
||||
statement.setString(2, message.saveToJson().toString());
|
||||
statement.executeUpdate();
|
||||
statement.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
sendBallMessage(
|
||||
BALL_CHANNEL,
|
||||
SendPlayerToLocationEvent.ACTION,
|
||||
new SendPlayerToLocationEvent(Collections.singleton(sendPlayerUUID), location, null)
|
||||
ServerType.PROXY,
|
||||
SendMessageToPlayerEvent.ACTION,
|
||||
new SendMessageToPlayerEvent(receiver, message)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 把玩家传送到一个位置
|
||||
* <p>
|
||||
@@ -480,7 +475,7 @@ public abstract class BallAPI {
|
||||
* @param doneMessage 传送完成后显示的消息
|
||||
*/
|
||||
public void sendPlayerToLocation(@NotNull UUID sendPlayerUUID, @NotNull ServiceLocation location, @Nullable Message doneMessage) {
|
||||
sendMessagingMessage(
|
||||
sendBallMessage(
|
||||
BALL_CHANNEL,
|
||||
SendPlayerToLocationEvent.ACTION,
|
||||
new SendPlayerToLocationEvent(Collections.singleton(sendPlayerUUID), location, doneMessage)
|
||||
@@ -494,33 +489,15 @@ public abstract class BallAPI {
|
||||
* <p>
|
||||
* 则会先尝试将玩家连接至目标服务器再进行传送
|
||||
*
|
||||
* @param uuidSet 玩家的uuid
|
||||
* @param location 坐标
|
||||
* @param sendPlayerUUID 玩家的uuid
|
||||
* @param location 坐标
|
||||
* @param doneMessage 传送完成后显示的消息
|
||||
*/
|
||||
public void sendPlayerToLocation(@NotNull HashSet<UUID> uuidSet, @NotNull ServiceLocation location) {
|
||||
sendMessagingMessage(
|
||||
public void sendPlayerToLocation(@NotNull HashSet<UUID> sendPlayerUUID, @NotNull ServiceLocation location, @Nullable Message doneMessage) {
|
||||
sendBallMessage(
|
||||
BALL_CHANNEL,
|
||||
SendPlayerToLocationEvent.ACTION,
|
||||
new SendPlayerToLocationEvent(uuidSet, location, null)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 把玩家传送到一个位置
|
||||
* <p>
|
||||
* 如果目标位置不在当前服务器
|
||||
* <p>
|
||||
* 则会先尝试将玩家连接至目标服务器再进行传送
|
||||
*
|
||||
* @param uuidSet 玩家的uuid
|
||||
* @param location 坐标
|
||||
* @param doneMessage 传送完成后显示的消息
|
||||
*/
|
||||
public void sendPlayerToLocation(@NotNull HashSet<UUID> uuidSet, @NotNull ServiceLocation location, @Nullable Message doneMessage) {
|
||||
sendMessagingMessage(
|
||||
BALL_CHANNEL,
|
||||
SendPlayerToLocationEvent.ACTION,
|
||||
new SendPlayerToLocationEvent(uuidSet, location, doneMessage)
|
||||
new SendPlayerToLocationEvent(sendPlayerUUID, location, doneMessage)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -532,11 +509,11 @@ public abstract class BallAPI {
|
||||
* @param sendPlayerUUID 被传送的玩家
|
||||
* @param toPlayerUUID 传送的目标玩家
|
||||
*/
|
||||
public void sendPlayerToPlayer(@NotNull UUID sendPlayerUUID, @NotNull UUID toPlayerUUID) {
|
||||
sendMessagingMessage(
|
||||
public void sendPlayerToPlayer(@NotNull UUID sendPlayerUUID, @NotNull UUID toPlayerUUID, @Nullable Message doneMessage, @Nullable Message doneTargetMessage) {
|
||||
sendBallMessage(
|
||||
BALL_CHANNEL,
|
||||
SendPlayerToPlayerEvent.ACTION,
|
||||
new SendPlayerToPlayerEvent(Collections.singleton(sendPlayerUUID), toPlayerUUID, null, null)
|
||||
new SendPlayerToPlayerEvent(Collections.singleton(sendPlayerUUID), toPlayerUUID, doneMessage, doneTargetMessage)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -549,44 +526,11 @@ public abstract class BallAPI {
|
||||
* @param toPlayerUUID 传送的目标玩家
|
||||
* @param doneMessage 传送完成后显示的消息
|
||||
*/
|
||||
public void sendPlayerToPlayer(@NotNull UUID sendPlayerUUID, @NotNull UUID toPlayerUUID, @Nullable Message doneMessage) {
|
||||
sendMessagingMessage(
|
||||
public void sendPlayerToPlayer(@NotNull HashSet<UUID> sendPlayerUUID, @NotNull UUID toPlayerUUID, @Nullable Message doneMessage, @Nullable Message doneTargetMessage) {
|
||||
sendBallMessage(
|
||||
BALL_CHANNEL,
|
||||
SendPlayerToPlayerEvent.ACTION,
|
||||
new SendPlayerToPlayerEvent(Collections.singleton(sendPlayerUUID), toPlayerUUID, doneMessage, null)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 把玩家传送到另一个玩家身边
|
||||
* <p>
|
||||
* 支持跨服传送
|
||||
*
|
||||
* @param sendPlayers 被传送的玩家
|
||||
* @param toPlayerUUID 传送的目标玩家
|
||||
*/
|
||||
public void sendPlayerToPlayer(@NotNull HashSet<UUID> sendPlayers, @NotNull UUID toPlayerUUID) {
|
||||
sendMessagingMessage(
|
||||
BALL_CHANNEL,
|
||||
SendPlayerToPlayerEvent.ACTION,
|
||||
new SendPlayerToPlayerEvent(sendPlayers, toPlayerUUID, null, null)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 把玩家传送到另一个玩家身边
|
||||
* <p>
|
||||
* 支持跨服传送
|
||||
*
|
||||
* @param sendPlayers 被传送的玩家
|
||||
* @param toPlayerUUID 传送的目标玩家
|
||||
* @param doneMessage 传送完成后显示的消息
|
||||
*/
|
||||
public void sendPlayerToPlayer(@NotNull HashSet<UUID> sendPlayers, @NotNull UUID toPlayerUUID, @Nullable Message doneMessage, @Nullable Message doneTargetMessage) {
|
||||
sendMessagingMessage(
|
||||
BALL_CHANNEL,
|
||||
SendPlayerToPlayerEvent.ACTION,
|
||||
new SendPlayerToPlayerEvent(sendPlayers, toPlayerUUID, doneMessage, doneTargetMessage)
|
||||
new SendPlayerToPlayerEvent(sendPlayerUUID, toPlayerUUID, doneMessage, doneTargetMessage)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -596,8 +540,8 @@ public abstract class BallAPI {
|
||||
* @param channel 消息标签
|
||||
* @param action 执行动作
|
||||
*/
|
||||
public void sendMessagingMessage(@NotNull String channel, @NotNull String action) {
|
||||
sendMessagingMessage(new ServiceMessageInfo(channel, getLocalServerId(), null, null, action, null));
|
||||
public void sendBallMessage(@NotNull String channel, @NotNull String action) {
|
||||
sendBallMessage(new MessageInfo(channel, getLocalServerId(), null, null, action, null));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -607,8 +551,8 @@ public abstract class BallAPI {
|
||||
* @param action 执行动作
|
||||
* @param content 附加参数
|
||||
*/
|
||||
public void sendMessagingMessage(@NotNull String channel, @NotNull String action, @NotNull String content) {
|
||||
sendMessagingMessage(new ServiceMessageInfo(channel, getLocalServerId(), null, null, action, new JsonPrimitive(content)));
|
||||
public void sendBallMessage(@NotNull String channel, @NotNull String action, @NotNull String content) {
|
||||
sendBallMessage(new MessageInfo(channel, getLocalServerId(), null, null, action, new JsonPrimitive(content)));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -618,8 +562,8 @@ public abstract class BallAPI {
|
||||
* @param action 执行动作
|
||||
* @param content 附加参数
|
||||
*/
|
||||
public void sendMessagingMessage(@NotNull String channel, @NotNull String action, @NotNull JsonElement content) {
|
||||
sendMessagingMessage(new ServiceMessageInfo(channel, getLocalServerId(), null, null, action, content));
|
||||
public void sendBallMessage(@NotNull String channel, @NotNull String action, @NotNull JsonElement content) {
|
||||
sendBallMessage(new MessageInfo(channel, getLocalServerId(), null, null, action, content));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -629,8 +573,8 @@ public abstract class BallAPI {
|
||||
* @param action 执行动作
|
||||
* @param content 附加参数
|
||||
*/
|
||||
public void sendMessagingMessage(@NotNull String channel, @NotNull String action, @NotNull Object content) {
|
||||
sendMessagingMessage(new ServiceMessageInfo(channel, getLocalServerId(), null, null, action, CoreConstantObjects.GSON.toJsonTree(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)));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -640,8 +584,8 @@ public abstract class BallAPI {
|
||||
* @param action 执行动作
|
||||
* @param content 附加参数
|
||||
*/
|
||||
public void sendMessagingMessage(@NotNull String channel, @Nullable ServerType receiverType, @NotNull String action, @NotNull JsonElement content) {
|
||||
sendMessagingMessage(new ServiceMessageInfo(channel, getLocalServerId(), null, receiverType, action, 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));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -651,8 +595,8 @@ public abstract class BallAPI {
|
||||
* @param action 执行动作
|
||||
* @param content 附加参数
|
||||
*/
|
||||
public void sendMessagingMessage(@NotNull String channel, @Nullable ServerType receiverType, @NotNull String action, @NotNull Object content) {
|
||||
sendMessagingMessage(new ServiceMessageInfo(channel, getLocalServerId(), null, receiverType, action, CoreConstantObjects.GSON.toJsonTree(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)));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -660,8 +604,8 @@ public abstract class BallAPI {
|
||||
*
|
||||
* @param messageInfo 消息内容
|
||||
*/
|
||||
public void sendMessagingMessage(@NotNull ServiceMessageInfo messageInfo) {
|
||||
sendMessagingMessage(messageInfo, false);
|
||||
public void sendBallMessage(@NotNull MessageInfo messageInfo) {
|
||||
sendBallMessage(messageInfo, false);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -670,7 +614,7 @@ public abstract class BallAPI {
|
||||
* @param messageInfo 消息内容
|
||||
* @param block 是否阻塞(设置为 true 则必须等待消息写入网络的操作完成后,该方法才会退出)
|
||||
*/
|
||||
public void sendMessagingMessage(@NotNull ServiceMessageInfo messageInfo, boolean block) {
|
||||
public void sendBallMessage(@NotNull MessageInfo messageInfo, boolean block) {
|
||||
if (channel == null || !channel.isWritable()) {
|
||||
return;
|
||||
}
|
||||
|
@@ -1,7 +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.ServiceMessageInfo;
|
||||
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.event.player.*;
|
||||
import cn.hamster3.mc.plugin.ball.common.event.server.ServerOfflineEvent;
|
||||
@@ -20,7 +20,7 @@ public class BallChannelInboundHandler extends SimpleChannelInboundHandler<Strin
|
||||
|
||||
@Override
|
||||
protected void channelRead0(ChannelHandlerContext context, String message) {
|
||||
ServiceMessageInfo info = CoreConstantObjects.GSON.fromJson(message, ServiceMessageInfo.class);
|
||||
MessageInfo info = CoreConstantObjects.GSON.fromJson(message, MessageInfo.class);
|
||||
for (BallListener listener : BallAPI.getInstance().getListeners()) {
|
||||
try {
|
||||
listener.onMessageReceived(info);
|
||||
@@ -58,7 +58,7 @@ public class BallChannelInboundHandler extends SimpleChannelInboundHandler<Strin
|
||||
DispatchPlayerCommandEvent event = CoreConstantObjects.GSON.fromJson(info.getContent(), DispatchPlayerCommandEvent.class);
|
||||
for (BallListener listener : BallAPI.getInstance().getListeners()) {
|
||||
try {
|
||||
listener.onDispatchGamePlayerCommand(event);
|
||||
listener.onDispatchPlayerCommand(event);
|
||||
} catch (Exception | Error e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -109,8 +109,8 @@ public class BallChannelInboundHandler extends SimpleChannelInboundHandler<Strin
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PlayerChatEvent.ACTION: {
|
||||
PlayerChatEvent event = CoreConstantObjects.GSON.fromJson(info.getContent(), PlayerChatEvent.class);
|
||||
case BallPlayerChatEvent.ACTION: {
|
||||
BallPlayerChatEvent event = CoreConstantObjects.GSON.fromJson(info.getContent(), BallPlayerChatEvent.class);
|
||||
for (BallListener listener : BallAPI.getInstance().getListeners()) {
|
||||
try {
|
||||
listener.onPlayerChat(event);
|
||||
@@ -120,77 +120,77 @@ public class BallChannelInboundHandler extends SimpleChannelInboundHandler<Strin
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PlayerConnectServerEvent.ACTION: {
|
||||
PlayerConnectServerEvent event = CoreConstantObjects.GSON.fromJson(info.getContent(), PlayerConnectServerEvent.class);
|
||||
case BallPlayerConnectServerEvent.ACTION: {
|
||||
BallPlayerConnectServerEvent event = CoreConstantObjects.GSON.fromJson(info.getContent(), BallPlayerConnectServerEvent.class);
|
||||
for (BallListener listener : BallAPI.getInstance().getListeners()) {
|
||||
try {
|
||||
listener.onPlayerConnectServer(event);
|
||||
listener.onBallPlayerConnectServer(event);
|
||||
} catch (Exception | Error e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PlayerDisconnectEvent.ACTION: {
|
||||
PlayerDisconnectEvent event = CoreConstantObjects.GSON.fromJson(info.getContent(), PlayerDisconnectEvent.class);
|
||||
case BallPlayerLogoutEvent.ACTION: {
|
||||
BallPlayerLogoutEvent event = CoreConstantObjects.GSON.fromJson(info.getContent(), BallPlayerLogoutEvent.class);
|
||||
for (BallListener listener : BallAPI.getInstance().getListeners()) {
|
||||
try {
|
||||
listener.onPlayerDisconnect(event);
|
||||
listener.onBallPlayerLogout(event);
|
||||
} catch (Exception | Error e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PlayerLoginEvent.ACTION: {
|
||||
PlayerLoginEvent event = CoreConstantObjects.GSON.fromJson(info.getContent(), PlayerLoginEvent.class);
|
||||
case BallPlayerLoginEvent.ACTION: {
|
||||
BallPlayerLoginEvent event = CoreConstantObjects.GSON.fromJson(info.getContent(), BallPlayerLoginEvent.class);
|
||||
for (BallListener listener : BallAPI.getInstance().getListeners()) {
|
||||
try {
|
||||
listener.onPlayerLogin(event);
|
||||
listener.onBallPlayerLogin(event);
|
||||
} catch (Exception | Error e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PlayerPostConnectServerEvent.ACTION: {
|
||||
PlayerPostConnectServerEvent event = CoreConstantObjects.GSON.fromJson(info.getContent(), PlayerPostConnectServerEvent.class);
|
||||
case BallPlayerPostConnectServerEvent.ACTION: {
|
||||
BallPlayerPostConnectServerEvent event = CoreConstantObjects.GSON.fromJson(info.getContent(), BallPlayerPostConnectServerEvent.class);
|
||||
for (BallListener listener : BallAPI.getInstance().getListeners()) {
|
||||
try {
|
||||
listener.onPlayerPostConnectServer(event);
|
||||
listener.onBallPlayerPostConnectServer(event);
|
||||
} catch (Exception | Error e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PlayerPostLoginEvent.ACTION: {
|
||||
PlayerPostLoginEvent event = CoreConstantObjects.GSON.fromJson(info.getContent(), PlayerPostLoginEvent.class);
|
||||
case BallPlayerPostLoginEvent.ACTION: {
|
||||
BallPlayerPostLoginEvent event = CoreConstantObjects.GSON.fromJson(info.getContent(), BallPlayerPostLoginEvent.class);
|
||||
for (BallListener listener : BallAPI.getInstance().getListeners()) {
|
||||
try {
|
||||
listener.onPlayerPostLogin(event);
|
||||
listener.onBallPlayerPostLogin(event);
|
||||
} catch (Exception | Error e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PlayerPreConnectServerEvent.ACTION: {
|
||||
PlayerPreConnectServerEvent event = CoreConstantObjects.GSON.fromJson(info.getContent(), PlayerPreConnectServerEvent.class);
|
||||
case BallPlayerPreConnectServerEvent.ACTION: {
|
||||
BallPlayerPreConnectServerEvent event = CoreConstantObjects.GSON.fromJson(info.getContent(), BallPlayerPreConnectServerEvent.class);
|
||||
for (BallListener listener : BallAPI.getInstance().getListeners()) {
|
||||
try {
|
||||
listener.onPlayerPreConnectServer(event);
|
||||
listener.onBallPlayerPreConnectServer(event);
|
||||
} catch (Exception | Error e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PlayerPreLoginEvent.ACTION: {
|
||||
PlayerPreLoginEvent event = CoreConstantObjects.GSON.fromJson(info.getContent(), PlayerPreLoginEvent.class);
|
||||
case BallPlayerPreLoginEvent.ACTION: {
|
||||
BallPlayerPreLoginEvent event = CoreConstantObjects.GSON.fromJson(info.getContent(), BallPlayerPreLoginEvent.class);
|
||||
for (BallListener listener : BallAPI.getInstance().getListeners()) {
|
||||
try {
|
||||
listener.onPlayerPreLogin(event);
|
||||
listener.onBallPlayerPreLogin(event);
|
||||
} catch (Exception | Error e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@@ -22,7 +22,7 @@ import java.util.UUID;
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@SuppressWarnings("unused")
|
||||
public class ServiceMessageInfo {
|
||||
public class MessageInfo {
|
||||
/**
|
||||
* 消息的频道
|
||||
*/
|
@@ -1,6 +1,5 @@
|
||||
package cn.hamster3.mc.plugin.ball.common.entity;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -24,11 +23,6 @@ public class PlayerInfo {
|
||||
*/
|
||||
@NotNull
|
||||
private String name;
|
||||
/**
|
||||
* 玩家的档案(包含皮肤等信息)
|
||||
*/
|
||||
@NotNull
|
||||
private JsonElement profile;
|
||||
/**
|
||||
* 玩家所在的游戏服务器 ID
|
||||
* <p>
|
||||
|
@@ -5,6 +5,7 @@ import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
@Data
|
||||
@@ -13,7 +14,7 @@ public class SendMessageToPlayerEvent {
|
||||
public static final String ACTION = "SendMessageToPlayer";
|
||||
|
||||
@NotNull
|
||||
private final UUID uuid;
|
||||
private final Set<UUID> receiver;
|
||||
@NotNull
|
||||
private final Message message;
|
||||
}
|
||||
|
@@ -12,7 +12,7 @@ import java.util.UUID;
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class PlayerChatEvent {
|
||||
public class BallPlayerChatEvent {
|
||||
public static final String ACTION = "PlayerChat";
|
||||
|
||||
@NotNull
|
@@ -11,7 +11,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class PlayerConnectServerEvent {
|
||||
public class BallPlayerConnectServerEvent {
|
||||
public static final String ACTION = "PlayerConnectServer";
|
||||
|
||||
@NotNull
|
@@ -6,11 +6,11 @@ import lombok.Data;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* 玩家连接到服务器
|
||||
* 玩家连接到代理服务器
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class PlayerLoginEvent {
|
||||
public class BallPlayerLoginEvent {
|
||||
public static final String ACTION = "PlayerLogin";
|
||||
|
||||
@NotNull
|
@@ -0,0 +1,18 @@
|
||||
package cn.hamster3.mc.plugin.ball.common.event.player;
|
||||
|
||||
import cn.hamster3.mc.plugin.ball.common.entity.PlayerInfo;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* 玩家与代理服务器断开连接
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class BallPlayerLogoutEvent {
|
||||
public static final String ACTION = "PlayerLogout";
|
||||
|
||||
@NotNull
|
||||
private PlayerInfo playerInfo;
|
||||
}
|
@@ -4,20 +4,15 @@ import cn.hamster3.mc.plugin.ball.common.entity.PlayerInfo;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* 玩家已进入子服
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class PlayerPostConnectServerEvent {
|
||||
public class BallPlayerPostConnectServerEvent {
|
||||
public static final String ACTION = "PlayerPostConnectServer";
|
||||
|
||||
@NotNull
|
||||
private final PlayerInfo playerInfo;
|
||||
@Nullable
|
||||
private final String from;
|
||||
@NotNull
|
||||
private final String to;
|
||||
}
|
@@ -6,11 +6,11 @@ import lombok.Data;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* 玩家已连接到服务器
|
||||
* 玩家已连接到代理服务器
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class PlayerPostLoginEvent {
|
||||
public class BallPlayerPostLoginEvent {
|
||||
public static final String ACTION = "PlayerPostLogin";
|
||||
|
||||
@NotNull
|
@@ -11,7 +11,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class PlayerPreConnectServerEvent {
|
||||
public class BallPlayerPreConnectServerEvent {
|
||||
public static final String ACTION = "PlayerPreConnectServer";
|
||||
|
||||
@NotNull
|
@@ -9,7 +9,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class PlayerPreLoginEvent {
|
||||
public class BallPlayerPreLoginEvent {
|
||||
public static final String ACTION = "PlayerPreLogin";
|
||||
|
||||
@NotNull
|
@@ -1,20 +0,0 @@
|
||||
package cn.hamster3.mc.plugin.ball.common.event.player;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* 玩家与服务器断开连接
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class PlayerDisconnectEvent {
|
||||
public static final String ACTION = "PlayerDisconnect";
|
||||
|
||||
@NotNull
|
||||
private final UUID playerUUID;
|
||||
private final String serverID;
|
||||
}
|
@@ -1,6 +1,6 @@
|
||||
package cn.hamster3.mc.plugin.ball.common.listener;
|
||||
|
||||
import cn.hamster3.mc.plugin.ball.common.data.ServiceMessageInfo;
|
||||
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.event.player.*;
|
||||
import cn.hamster3.mc.plugin.ball.common.event.server.ServerOfflineEvent;
|
||||
@@ -25,7 +25,7 @@ public abstract class BallListener {
|
||||
public void onDispatchConsoleCommand(@NotNull DispatchConsoleCommandEvent event) {
|
||||
}
|
||||
|
||||
public void onDispatchGamePlayerCommand(@NotNull DispatchPlayerCommandEvent event) {
|
||||
public void onDispatchPlayerCommand(@NotNull DispatchPlayerCommandEvent event) {
|
||||
}
|
||||
|
||||
public void onKickPlayer(@NotNull KickPlayerEvent event) {
|
||||
@@ -40,28 +40,28 @@ public abstract class BallListener {
|
||||
public void onSendPlayerToPlayer(@NotNull SendPlayerToPlayerEvent event) {
|
||||
}
|
||||
|
||||
public void onPlayerChat(@NotNull PlayerChatEvent event) {
|
||||
public void onBallPlayerPreLogin(@NotNull BallPlayerPreLoginEvent event) {
|
||||
}
|
||||
|
||||
public void onPlayerConnectServer(@NotNull PlayerConnectServerEvent event) {
|
||||
public void onBallPlayerLogin(@NotNull BallPlayerLoginEvent event) {
|
||||
}
|
||||
|
||||
public void onPlayerDisconnect(@NotNull PlayerDisconnectEvent event) {
|
||||
public void onBallPlayerPostLogin(@NotNull BallPlayerPostLoginEvent event) {
|
||||
}
|
||||
|
||||
public void onPlayerLogin(@NotNull PlayerLoginEvent event) {
|
||||
public void onBallPlayerPreConnectServer(@NotNull BallPlayerPreConnectServerEvent event) {
|
||||
}
|
||||
|
||||
public void onPlayerPostConnectServer(@NotNull PlayerPostConnectServerEvent event) {
|
||||
public void onBallPlayerConnectServer(@NotNull BallPlayerConnectServerEvent event) {
|
||||
}
|
||||
|
||||
public void onPlayerPostLogin(@NotNull PlayerPostLoginEvent event) {
|
||||
public void onBallPlayerPostConnectServer(@NotNull BallPlayerPostConnectServerEvent event) {
|
||||
}
|
||||
|
||||
public void onPlayerPreConnectServer(@NotNull PlayerPreConnectServerEvent event) {
|
||||
public void onBallPlayerLogout(@NotNull BallPlayerLogoutEvent event) {
|
||||
}
|
||||
|
||||
public void onPlayerPreLogin(@NotNull PlayerPreLoginEvent event) {
|
||||
public void onPlayerChat(@NotNull BallPlayerChatEvent event) {
|
||||
}
|
||||
|
||||
public void onServerOffline(@NotNull ServerOfflineEvent event) {
|
||||
@@ -70,10 +70,10 @@ public abstract class BallListener {
|
||||
public void onServerOnline(@NotNull ServerOnlineEvent event) {
|
||||
}
|
||||
|
||||
public void onMessageReceived(@NotNull ServiceMessageInfo event) {
|
||||
public void onMessageReceived(@NotNull MessageInfo event) {
|
||||
}
|
||||
|
||||
public void onMessageSend(@NotNull ServiceMessageInfo event) {
|
||||
public void onMessageSend(@NotNull MessageInfo event) {
|
||||
}
|
||||
|
||||
public void onConnectInactive() {
|
||||
|
Reference in New Issue
Block a user