feat: 完善功能
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package cn.hamster3.mc.plugin.ball.bukkit;
|
||||
|
||||
import cn.hamster3.mc.plugin.ball.bukkit.api.BallBukkitAPI;
|
||||
import cn.hamster3.mc.plugin.ball.bukkit.listener.BallBukkitListener;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
@@ -31,6 +32,14 @@ public class HamsterBallPlugin extends JavaPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
Logger logger = getLogger();
|
||||
Bukkit.getPluginManager().registerEvents(BallBukkitListener.INSTANCE, this);
|
||||
logger.info("已注册 BallBukkitListener.");
|
||||
logger.info("HamsterBall 已启动.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
try {
|
||||
|
@@ -14,6 +14,7 @@ import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.event.player.PlayerLoginEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -38,14 +39,21 @@ public class BallBukkitListener extends BallListener implements Listener {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDispatchGamePlayerCommand(@NotNull DispatchPlayerCommandEvent event) {
|
||||
public void onDispatchPlayerCommand(@NotNull DispatchPlayerCommandEvent event) {
|
||||
if (event.getType() != null && event.getType() != ServerType.GAME) {
|
||||
return;
|
||||
}
|
||||
if (event.getUuid() != null && Bukkit.getPlayer(event.getUuid()) == null) {
|
||||
if (event.getUuid() != null) {
|
||||
Player player = Bukkit.getPlayer(event.getUuid());
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
Bukkit.dispatchCommand(player, event.getCommand());
|
||||
return;
|
||||
}
|
||||
Bukkit.dispatchCommand(Bukkit.getPlayer(event.getUuid()), event.getCommand());
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
Bukkit.dispatchCommand(player, event.getCommand());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -84,4 +92,9 @@ public class BallBukkitListener extends BallListener implements Listener {
|
||||
player.teleport(location, PlayerTeleportEvent.TeleportCause.PLUGIN);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onAsyncPlayerChat(AsyncPlayerChatEvent event) {
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -1,18 +1,47 @@
|
||||
package cn.hamster3.mc.plugin.core.bungee;
|
||||
|
||||
import cn.hamster3.mc.plugin.core.bungee.api.BallBungeeCordAPI;
|
||||
import cn.hamster3.mc.plugin.core.bungee.listener.BallBungeeCordListener;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class HamsterBallPlugin extends Plugin {
|
||||
private static HamsterBallPlugin instance;
|
||||
|
||||
public static HamsterBallPlugin getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
instance = this;
|
||||
Logger logger = getLogger();
|
||||
BallBungeeCordAPI.init();
|
||||
logger.info("BallBukkitAPI 已初始化.");
|
||||
try {
|
||||
BallBungeeCordAPI.getInstance().enable();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
ProxyServer.getInstance().stop();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
Logger logger = getLogger();
|
||||
ProxyServer.getInstance().getPluginManager().registerListener(this, BallBungeeCordListener.INSTANCE);
|
||||
logger.info("已注册 BallBukkitListener.");
|
||||
logger.info("HamsterBall 已启动.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
super.onDisable();
|
||||
try {
|
||||
BallBungeeCordAPI.getInstance().disable();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,62 @@
|
||||
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.core.bungee.HamsterBallPlugin;
|
||||
import cn.hamster3.mc.plugin.core.bungee.listener.BallBungeeCordListener;
|
||||
import cn.hamster3.mc.plugin.core.bungee.util.BungeeCordUtils;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.config.ListenerInfo;
|
||||
import net.md_5.bungee.config.Configuration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Optional;
|
||||
|
||||
public class BallBungeeCordAPI extends BallAPI {
|
||||
public BallBungeeCordAPI(@NotNull BallConfig config) {
|
||||
super(config);
|
||||
}
|
||||
|
||||
public static BallBungeeCordAPI getInstance() {
|
||||
return (BallBungeeCordAPI) instance;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public static void init() {
|
||||
if (instance != null) {
|
||||
return;
|
||||
}
|
||||
HamsterBallPlugin plugin = HamsterBallPlugin.getInstance();
|
||||
Configuration pluginConfig = BungeeCordUtils.getPluginConfig(plugin);
|
||||
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(
|
||||
pluginConfig.getString("server-info.id"),
|
||||
pluginConfig.getString("server-info.name"),
|
||||
ServerType.GAME,
|
||||
host.isEmpty() ? "127.0.0.1" : host,
|
||||
pluginConfig.getInt("server-info.name.port", address.map(InetSocketAddress::getPort).orElse(25577))
|
||||
),
|
||||
pluginConfig.getString("ball-server.host"),
|
||||
pluginConfig.getInt("ball-server.port"),
|
||||
pluginConfig.getInt("ball-server.nio-thread")
|
||||
);
|
||||
instance = new BallBungeeCordAPI(config);
|
||||
instance.addListener(BallBungeeCordListener.INSTANCE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enable() throws SQLException, InterruptedException {
|
||||
super.enable();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disable() throws SQLException, InterruptedException {
|
||||
super.disable();
|
||||
}
|
||||
}
|
@@ -0,0 +1,160 @@
|
||||
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.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.data.Message;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.text.serializer.bungeecord.BungeeComponentSerializer;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
import net.md_5.bungee.api.chat.BaseComponent;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.event.*;
|
||||
import net.md_5.bungee.api.plugin.Listener;
|
||||
import net.md_5.bungee.event.EventHandler;
|
||||
import net.md_5.bungee.event.EventPriority;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public final class BallBungeeCordListener extends BallListener implements Listener {
|
||||
public static final BallBungeeCordListener INSTANCE = new BallBungeeCordListener();
|
||||
|
||||
private BallBungeeCordListener() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBroadcastPlayerMessage(@NotNull BroadcastPlayerMessageEvent event) {
|
||||
Message message = event.getMessage();
|
||||
Audience audience = CoreAPI.getInstance().getAudienceProvider().all();
|
||||
message.show(audience);
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
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)
|
||||
public void onPreLogin(PreLoginEvent event) {
|
||||
BallAPI.getInstance().sendBallMessage(
|
||||
BallAPI.BALL_CHANNEL,
|
||||
BallPlayerPreLoginEvent.ACTION,
|
||||
new BallPlayerPreLoginEvent(event.getConnection().getName())
|
||||
);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onLogin(LoginEvent event) {
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
BallAPI.getInstance().sendBallMessage(
|
||||
BallAPI.BALL_CHANNEL,
|
||||
BallPlayerLoginEvent.ACTION,
|
||||
new BallPlayerLoginEvent(new PlayerInfo(
|
||||
event.getConnection().getUniqueId(),
|
||||
event.getConnection().getName(),
|
||||
"",
|
||||
BallAPI.getInstance().getLocalServerId(),
|
||||
true
|
||||
))
|
||||
);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onPostLogin(PostLoginEvent event) {
|
||||
ProxiedPlayer player = event.getPlayer();
|
||||
BallAPI.getInstance().sendBallMessage(
|
||||
BallAPI.BALL_CHANNEL,
|
||||
BallPlayerPostLoginEvent.ACTION,
|
||||
new BallPlayerPostLoginEvent(BallBungeeCordUtils.getPlayerInfo(player, true))
|
||||
);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onServerConnect(ServerConnectEvent event) {
|
||||
ProxiedPlayer player = event.getPlayer();
|
||||
PlayerInfo playerInfo = BallBungeeCordUtils.getPlayerInfo(player, true);
|
||||
BallAPI.getInstance().sendBallMessage(
|
||||
BallAPI.BALL_CHANNEL,
|
||||
BallPlayerConnectServerEvent.ACTION,
|
||||
new BallPlayerConnectServerEvent(playerInfo, playerInfo.getGameServer(), event.getTarget().getName())
|
||||
);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onServerConnected(ServerConnectedEvent event) {
|
||||
ProxiedPlayer player = event.getPlayer();
|
||||
PlayerInfo playerInfo = BallBungeeCordUtils.getPlayerInfo(player, true);
|
||||
BallAPI.getInstance().sendBallMessage(
|
||||
BallAPI.BALL_CHANNEL,
|
||||
BallPlayerPostConnectServerEvent.ACTION,
|
||||
new BallPlayerPostConnectServerEvent(playerInfo)
|
||||
);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onServerSwitch(ServerSwitchEvent event) {
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onServerDisconnect(ServerDisconnectEvent event) {
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void onPlayerDisconnect(PlayerDisconnectEvent event) {
|
||||
ProxiedPlayer player = event.getPlayer();
|
||||
BallAPI.getInstance().sendBallMessage(
|
||||
BallAPI.BALL_CHANNEL,
|
||||
BallPlayerLogoutEvent.ACTION,
|
||||
new BallPlayerLogoutEvent(BallBungeeCordUtils.getPlayerInfo(player, false))
|
||||
);
|
||||
}
|
||||
}
|
@@ -0,0 +1,22 @@
|
||||
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 net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.connection.Server;
|
||||
|
||||
public final class BallBungeeCordUtils {
|
||||
private BallBungeeCordUtils() {
|
||||
}
|
||||
|
||||
public static PlayerInfo getPlayerInfo(ProxiedPlayer player, boolean online) {
|
||||
Server server = player.getServer();
|
||||
return new PlayerInfo(
|
||||
player.getUniqueId(),
|
||||
player.getName(),
|
||||
server == null ? "" : server.getInfo().getName(),
|
||||
BallAPI.getInstance().getLocalServerId(),
|
||||
online
|
||||
);
|
||||
}
|
||||
}
|
@@ -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() {
|
||||
|
@@ -1,8 +1,7 @@
|
||||
package cn.hamster3.mc.plugin.ball.server.connector;
|
||||
|
||||
import cn.hamster3.mc.plugin.ball.common.data.ServiceMessageInfo;
|
||||
import cn.hamster3.mc.plugin.ball.common.data.MessageInfo;
|
||||
import cn.hamster3.mc.plugin.ball.server.constant.ConstantObjects;
|
||||
import io.netty.channel.ChannelHandler;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.SimpleChannelInboundHandler;
|
||||
import org.slf4j.Logger;
|
||||
@@ -18,7 +17,7 @@ public class BallChannelHandler extends SimpleChannelInboundHandler<String> {
|
||||
@Override
|
||||
protected void channelRead0(ChannelHandlerContext context, String message) {
|
||||
try {
|
||||
ServiceMessageInfo messageInfo = ConstantObjects.GSON.fromJson(message, ServiceMessageInfo.class);
|
||||
MessageInfo messageInfo = ConstantObjects.GSON.fromJson(message, MessageInfo.class);
|
||||
LOGGER.info("从服务器 {} 上收到一条消息: \n {}", messageInfo.getSenderID(), messageInfo);
|
||||
BallChannelInitializer.broadcastMessage(messageInfo);
|
||||
} catch (Exception e) {
|
||||
|
@@ -1,6 +1,6 @@
|
||||
package cn.hamster3.mc.plugin.ball.server.connector;
|
||||
|
||||
import cn.hamster3.mc.plugin.ball.common.data.ServiceMessageInfo;
|
||||
import cn.hamster3.mc.plugin.ball.common.data.MessageInfo;
|
||||
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(ServiceMessageInfo messageInfo) {
|
||||
public static void broadcastMessage(MessageInfo messageInfo) {
|
||||
String string = messageInfo.toString();
|
||||
for (Channel channel : CHANNELS) {
|
||||
channel.writeAndFlush(string);
|
||||
|
Reference in New Issue
Block a user