Initial commit
This commit is contained in:
19
hamster-ball-common/build.gradle
Normal file
19
hamster-ball-common/build.gradle
Normal file
@@ -0,0 +1,19 @@
|
||||
version = '1.0.0'
|
||||
setArchivesBaseName("HamsterBall-Common")
|
||||
|
||||
dependencies {
|
||||
// https://mvnrepository.com/artifact/com.google.code.gson/gson
|
||||
//noinspection GradlePackageUpdate
|
||||
compileOnly 'com.google.code.gson:gson:2.8.0'
|
||||
// https://mvnrepository.com/artifact/io.netty/netty-all
|
||||
compileOnly 'io.netty:netty-all:4.1.84.Final'
|
||||
|
||||
compileOnly "cn.hamster3.mc.plugin:hamster-core-common:1.0.0"
|
||||
|
||||
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.0'
|
||||
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.9.0'
|
||||
}
|
||||
|
||||
test {
|
||||
useJUnitPlatform()
|
||||
}
|
@@ -0,0 +1,792 @@
|
||||
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.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;
|
||||
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;
|
||||
import cn.hamster3.mc.plugin.ball.common.event.server.ServerOnlineEvent;
|
||||
import cn.hamster3.mc.plugin.ball.common.listener.BallListener;
|
||||
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 com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import io.netty.bootstrap.Bootstrap;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelFuture;
|
||||
import io.netty.channel.ChannelOption;
|
||||
import io.netty.channel.nio.NioEventLoopGroup;
|
||||
import io.netty.channel.socket.nio.NioSocketChannel;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public abstract class BallAPI {
|
||||
/**
|
||||
* API 使用的通信频道
|
||||
*/
|
||||
public static final String BALL_CHANNEL = "HamsterBall";
|
||||
/**
|
||||
* API 实例
|
||||
*/
|
||||
protected static BallAPI instance;
|
||||
@NotNull
|
||||
protected final ConcurrentHashMap<String, ServerInfo> serverInfo;
|
||||
@NotNull
|
||||
protected final ConcurrentHashMap<UUID, PlayerInfo> playerInfo;
|
||||
|
||||
@NotNull
|
||||
private final BallConfig config;
|
||||
@NotNull
|
||||
private final List<BallListener> listeners;
|
||||
|
||||
private final Bootstrap bootstrap;
|
||||
private final NioEventLoopGroup executors;
|
||||
|
||||
protected boolean enable;
|
||||
protected Channel channel;
|
||||
|
||||
protected BallAPI(@NotNull BallConfig config) {
|
||||
this.config = config;
|
||||
executors = new NioEventLoopGroup(config.getNioThread());
|
||||
|
||||
serverInfo = new ConcurrentHashMap<>();
|
||||
playerInfo = new ConcurrentHashMap<>();
|
||||
listeners = new ArrayList<>();
|
||||
|
||||
bootstrap = new Bootstrap();
|
||||
bootstrap.group(executors)
|
||||
.channel(NioSocketChannel.class)
|
||||
.option(ChannelOption.TCP_NODELAY, true)
|
||||
.option(ChannelOption.SO_KEEPALIVE, true)
|
||||
.handler(BallChannelInitializer.INSTANCE);
|
||||
|
||||
addListener(new BallListener() {
|
||||
@Override
|
||||
public int getPriority() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerConnectServer(@NotNull PlayerConnectServerEvent 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) {
|
||||
PlayerInfo info = event.getPlayerInfo();
|
||||
playerInfo.put(info.getUuid(), info);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerPostConnectServer(@NotNull PlayerPostConnectServerEvent event) {
|
||||
PlayerInfo info = event.getPlayerInfo();
|
||||
playerInfo.put(info.getUuid(), info);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerPostLogin(@NotNull PlayerPostLoginEvent event) {
|
||||
PlayerInfo info = event.getPlayerInfo();
|
||||
playerInfo.put(info.getUuid(), info);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerPreConnectServer(@NotNull PlayerPreConnectServerEvent event) {
|
||||
PlayerInfo info = event.getPlayerInfo();
|
||||
playerInfo.put(info.getUuid(), info);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onServerOffline(@NotNull ServerOfflineEvent event) {
|
||||
String serverID = event.getServerID();
|
||||
serverInfo.remove(serverID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onServerOnline(@NotNull ServerOnlineEvent event) {
|
||||
ServerInfo info = event.getServerInfo();
|
||||
serverInfo.put(info.getId(), info);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConnectInactive() {
|
||||
reconnect(5);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 API 实例
|
||||
*
|
||||
* @return API 实例
|
||||
*/
|
||||
public static BallAPI getInstance() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
protected void enable() throws SQLException, InterruptedException {
|
||||
if (enable) {
|
||||
return;
|
||||
}
|
||||
enable = true;
|
||||
ServerInfo localInfo = getLocalServerInfo();
|
||||
|
||||
connect();
|
||||
|
||||
try (Connection connection = CoreAPI.getInstance().getConnection()) {
|
||||
|
||||
{
|
||||
Statement statement = connection.createStatement();
|
||||
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" +
|
||||
") CHARSET utf8mb4;");
|
||||
statement.execute("CREATE TABLE IF NOT EXISTS " + BallCommonConstants.SQL.SERVER_INFO_TABLE + "(" +
|
||||
"`id` VARCHAR(32) PRIMARY KEY NOT NULL," +
|
||||
"`name` VARCHAR(32) NOT NULL," +
|
||||
"`type` VARCHAR(16) NOT NULL," +
|
||||
"`host` VARCHAR(32) NOT NULL," +
|
||||
"`port` INT NOT NULL" +
|
||||
") CHARSET utf8mb4;");
|
||||
statement.execute("CREATE TABLE IF NOT EXISTS " + BallCommonConstants.SQL.CACHED_MESSAGE_TABLE + "(" +
|
||||
"`uuid` CHAR(36) NOT NULL," +
|
||||
"`message` MEDIUMTEXT NOT NULL" +
|
||||
") CHARSET utf8mb4;");
|
||||
statement.close();
|
||||
}
|
||||
|
||||
{
|
||||
PreparedStatement statement = connection.prepareStatement("REPLACE INTO " + BallCommonConstants.SQL.SERVER_INFO_TABLE + " VALUES(?, ?, ?, ?, ?);");
|
||||
statement.setString(1, localInfo.getId());
|
||||
statement.setString(2, localInfo.getName());
|
||||
statement.setString(3, localInfo.getType().name());
|
||||
statement.setString(4, localInfo.getHost());
|
||||
statement.setInt(5, localInfo.getPort());
|
||||
statement.executeUpdate();
|
||||
statement.close();
|
||||
}
|
||||
|
||||
{
|
||||
PreparedStatement statement = connection.prepareStatement("SELECT * FROM " + BallCommonConstants.SQL.SERVER_INFO_TABLE + ";");
|
||||
ResultSet set = statement.executeQuery();
|
||||
while (set.next()) {
|
||||
String serverID = set.getString("id");
|
||||
serverInfo.put(serverID, new ServerInfo(
|
||||
serverID,
|
||||
set.getString("name"),
|
||||
ServerType.valueOf(set.getString("type")),
|
||||
set.getString("host"),
|
||||
set.getInt("port")
|
||||
));
|
||||
}
|
||||
set.close();
|
||||
statement.close();
|
||||
}
|
||||
|
||||
{
|
||||
PreparedStatement statement = connection.prepareStatement("SELECT * FROM " + BallCommonConstants.SQL.PLAYER_INFO_TABLE + ";");
|
||||
ResultSet set = statement.executeQuery();
|
||||
while (set.next()) {
|
||||
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")
|
||||
));
|
||||
}
|
||||
set.close();
|
||||
statement.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
sendMessagingMessage(
|
||||
BALL_CHANNEL,
|
||||
ServerOnlineEvent.ACTION,
|
||||
new ServerOnlineEvent(localInfo)
|
||||
);
|
||||
}
|
||||
|
||||
protected void connect() throws InterruptedException {
|
||||
if (!enable) {
|
||||
return;
|
||||
}
|
||||
ChannelFuture future = bootstrap.connect(config.getHost(), config.getPort()).await();
|
||||
if (future.isSuccess()) {
|
||||
channel = future.channel();
|
||||
}
|
||||
}
|
||||
|
||||
protected void reconnect(int ttl) {
|
||||
if (!enable) {
|
||||
return;
|
||||
}
|
||||
if (channel != null && channel.isOpen() && channel.isRegistered() && channel.isActive() && channel.isWritable()) {
|
||||
return;
|
||||
}
|
||||
channel = null;
|
||||
if (ttl <= 0) {
|
||||
for (BallListener listener : getListeners()) {
|
||||
try {
|
||||
listener.onReconnectFailed();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
try {
|
||||
connect();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (channel != null) {
|
||||
return;
|
||||
}
|
||||
reconnect(ttl - 1);
|
||||
}
|
||||
|
||||
protected void disable() throws SQLException, InterruptedException {
|
||||
if (!enable) {
|
||||
return;
|
||||
}
|
||||
enable = false;
|
||||
|
||||
sendMessagingMessage(
|
||||
BALL_CHANNEL,
|
||||
ServerOfflineEvent.ACTION,
|
||||
new ServerOfflineEvent(getLocalServerId())
|
||||
);
|
||||
|
||||
try (Connection connection = CoreAPI.getInstance().getConnection()) {
|
||||
PreparedStatement statement = connection.prepareStatement("DELETE FROM " + BallCommonConstants.SQL.SERVER_INFO_TABLE + " WHERE `id`=?;");
|
||||
statement.setString(1, getLocalServerId());
|
||||
statement.executeUpdate();
|
||||
statement.close();
|
||||
}
|
||||
|
||||
channel = null;
|
||||
executors.shutdownGracefully().await();
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断该服务器信息是否为本服
|
||||
*
|
||||
* @param info 服务器信息
|
||||
* @return true 代表该服务器信息是本服服务器
|
||||
*/
|
||||
public boolean isLocalServer(@NotNull ServerInfo info) {
|
||||
return getLocalServerInfo().equals(info);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断该服务器信息是否为本服
|
||||
*
|
||||
* @param serverID 服务器ID
|
||||
* @return true 代表该服务器信息是本服服务器
|
||||
*/
|
||||
public boolean isLocalServer(@NotNull String serverID) {
|
||||
return getLocalServerId().equalsIgnoreCase(serverID);
|
||||
}
|
||||
|
||||
/**
|
||||
* 给服务器的在线玩家广播一条消息
|
||||
*
|
||||
* @param message 消息
|
||||
*/
|
||||
public void broadcastPlayerMessage(@NotNull String message) {
|
||||
broadcastPlayerMessage(new Message().message(message));
|
||||
}
|
||||
|
||||
/**
|
||||
* 给服务器的在线玩家广播一条消息
|
||||
*
|
||||
* @param message 消息
|
||||
*/
|
||||
public void broadcastPlayerMessage(@NotNull Message message) {
|
||||
sendMessagingMessage(
|
||||
BALL_CHANNEL,
|
||||
ServerType.PROXY,
|
||||
BroadcastPlayerMessageEvent.ACTION,
|
||||
new BroadcastPlayerMessageEvent(message)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 强制控制台执行命令
|
||||
*
|
||||
* @param type 执行对象的服务端类型
|
||||
* @param serverID 执行对象的 ID
|
||||
* @param command 命令内容
|
||||
*/
|
||||
public void dispatchConsoleCommand(@Nullable ServerType type, @Nullable String serverID, @NotNull String command) {
|
||||
sendMessagingMessage(
|
||||
BALL_CHANNEL,
|
||||
ServerType.GAME,
|
||||
DispatchConsoleCommandEvent.ACTION,
|
||||
new DispatchConsoleCommandEvent(type, serverID, command)
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 强制玩家执行命令
|
||||
*
|
||||
* @param type 执行对象的服务端类型
|
||||
* @param uuid 执行对象的 UUID
|
||||
* @param command 命令内容
|
||||
*/
|
||||
public void dispatchPlayerCommand(@Nullable ServerType type, @Nullable UUID uuid, @NotNull String command) {
|
||||
sendMessagingMessage(
|
||||
BALL_CHANNEL,
|
||||
ServerType.GAME,
|
||||
DispatchPlayerCommandEvent.ACTION,
|
||||
new DispatchPlayerCommandEvent(type, uuid, command)
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 踢出玩家
|
||||
*
|
||||
* @param uuid 玩家
|
||||
* @param reason 原因
|
||||
*/
|
||||
public void kickPlayer(@NotNull UUID uuid, @NotNull String reason) {
|
||||
kickPlayer(uuid, Component.text(reason));
|
||||
}
|
||||
|
||||
/**
|
||||
* 踢出玩家
|
||||
*
|
||||
* @param uuid 玩家
|
||||
* @param reason 原因
|
||||
*/
|
||||
public void kickPlayer(@NotNull UUID uuid, @NotNull Component reason) {
|
||||
sendMessagingMessage(
|
||||
BALL_CHANNEL,
|
||||
ServerType.PROXY,
|
||||
KickPlayerEvent.ACTION,
|
||||
new KickPlayerEvent(uuid, reason)
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 给玩家发送一条消息
|
||||
*
|
||||
* @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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 给玩家发送一条消息
|
||||
*
|
||||
* @param uuid 玩家
|
||||
* @param message 消息
|
||||
* @param cache 当玩家不在线时,是否缓存消息等待玩家上线再发送
|
||||
*/
|
||||
public void sendMessageToPlayer(@NotNull UUID uuid, @NotNull Message message, boolean cache) {
|
||||
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;
|
||||
}
|
||||
sendMessagingMessage(
|
||||
BALL_CHANNEL,
|
||||
ServerType.PROXY,
|
||||
SendMessageToPlayerEvent.ACTION,
|
||||
new SendMessageToPlayerEvent(uuid, message)
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 把玩家传送到一个位置
|
||||
* <p>
|
||||
* 如果目标位置不在当前服务器
|
||||
* <p>
|
||||
* 则会先尝试将玩家连接至目标服务器再进行传送
|
||||
*
|
||||
* @param sendPlayerUUID 玩家的uuid
|
||||
* @param location 坐标
|
||||
*/
|
||||
public void sendPlayerToLocation(@NotNull UUID sendPlayerUUID, @NotNull ServiceLocation location) {
|
||||
sendMessagingMessage(
|
||||
BALL_CHANNEL,
|
||||
SendPlayerToLocationEvent.ACTION,
|
||||
new SendPlayerToLocationEvent(Collections.singleton(sendPlayerUUID), location, null)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 把玩家传送到一个位置
|
||||
* <p>
|
||||
* 如果目标位置不在当前服务器
|
||||
* <p>
|
||||
* 则会先尝试将玩家连接至目标服务器再进行传送
|
||||
*
|
||||
* @param sendPlayerUUID 玩家的uuid
|
||||
* @param location 坐标
|
||||
* @param doneMessage 传送完成后显示的消息
|
||||
*/
|
||||
public void sendPlayerToLocation(@NotNull UUID sendPlayerUUID, @NotNull ServiceLocation location, @Nullable Message doneMessage) {
|
||||
sendMessagingMessage(
|
||||
BALL_CHANNEL,
|
||||
SendPlayerToLocationEvent.ACTION,
|
||||
new SendPlayerToLocationEvent(Collections.singleton(sendPlayerUUID), location, doneMessage)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 把玩家传送到一个位置
|
||||
* <p>
|
||||
* 如果目标位置不在当前服务器
|
||||
* <p>
|
||||
* 则会先尝试将玩家连接至目标服务器再进行传送
|
||||
*
|
||||
* @param uuidSet 玩家的uuid
|
||||
* @param location 坐标
|
||||
*/
|
||||
public void sendPlayerToLocation(@NotNull HashSet<UUID> uuidSet, @NotNull ServiceLocation location) {
|
||||
sendMessagingMessage(
|
||||
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)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 把玩家传送到另一个玩家身边
|
||||
* <p>
|
||||
* 支持跨服传送
|
||||
*
|
||||
* @param sendPlayerUUID 被传送的玩家
|
||||
* @param toPlayerUUID 传送的目标玩家
|
||||
*/
|
||||
public void sendPlayerToPlayer(@NotNull UUID sendPlayerUUID, @NotNull UUID toPlayerUUID) {
|
||||
sendMessagingMessage(
|
||||
BALL_CHANNEL,
|
||||
SendPlayerToPlayerEvent.ACTION,
|
||||
new SendPlayerToPlayerEvent(Collections.singleton(sendPlayerUUID), toPlayerUUID, null, null)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 把玩家传送到另一个玩家身边
|
||||
* <p>
|
||||
* 支持跨服传送
|
||||
*
|
||||
* @param sendPlayerUUID 被传送的玩家
|
||||
* @param toPlayerUUID 传送的目标玩家
|
||||
* @param doneMessage 传送完成后显示的消息
|
||||
*/
|
||||
public void sendPlayerToPlayer(@NotNull UUID sendPlayerUUID, @NotNull UUID toPlayerUUID, @Nullable Message doneMessage) {
|
||||
sendMessagingMessage(
|
||||
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)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送一条服务消息
|
||||
*
|
||||
* @param channel 消息标签
|
||||
* @param action 执行动作
|
||||
*/
|
||||
public void sendMessagingMessage(@NotNull String channel, @NotNull String action) {
|
||||
sendMessagingMessage(new ServiceMessageInfo(channel, getLocalServerId(), null, null, action, null));
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送一条有附加参数的服务消息
|
||||
*
|
||||
* @param channel 消息标签
|
||||
* @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)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送一条有附加参数的消息
|
||||
*
|
||||
* @param channel 消息频道
|
||||
* @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));
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送一条有附加参数的服务消息
|
||||
*
|
||||
* @param channel 消息标签
|
||||
* @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)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送一条有附加参数的消息
|
||||
*
|
||||
* @param channel 消息频道
|
||||
* @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));
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送一条有附加参数的服务消息
|
||||
*
|
||||
* @param channel 消息标签
|
||||
* @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)));
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送自定义消息
|
||||
*
|
||||
* @param messageInfo 消息内容
|
||||
*/
|
||||
public void sendMessagingMessage(@NotNull ServiceMessageInfo messageInfo) {
|
||||
sendMessagingMessage(messageInfo, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 自定义服务消息信息并发送
|
||||
*
|
||||
* @param messageInfo 消息内容
|
||||
* @param block 是否阻塞(设置为 true 则必须等待消息写入网络的操作完成后,该方法才会退出)
|
||||
*/
|
||||
public void sendMessagingMessage(@NotNull ServiceMessageInfo messageInfo, boolean block) {
|
||||
if (channel == null || !channel.isWritable()) {
|
||||
return;
|
||||
}
|
||||
ChannelFuture future = channel.write(CoreConstantObjects.GSON.toJsonTree(messageInfo));
|
||||
if (block) {
|
||||
try {
|
||||
future.await();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
for (BallListener listener : BallAPI.getInstance().getListeners()) {
|
||||
try {
|
||||
listener.onMessageSend(messageInfo);
|
||||
} catch (Exception | Error e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<Message> getCachedPlayerMessage(@NotNull UUID uuid) throws SQLException {
|
||||
ArrayList<Message> list = new ArrayList<>();
|
||||
try (Connection connection = CoreAPI.getInstance().getConnection()) {
|
||||
PreparedStatement statement = connection.prepareStatement("SELECT message FROM " + BallCommonConstants.SQL.CACHED_MESSAGE_TABLE + " WHERE `uuid`=?;");
|
||||
statement.setString(1, uuid.toString());
|
||||
ResultSet set = statement.executeQuery();
|
||||
while (set.next()) {
|
||||
JsonObject object = CoreConstantObjects.JSON_PARSER.parse(set.getString("msg")).getAsJsonObject();
|
||||
list.add(new Message().json(object));
|
||||
}
|
||||
statement.close();
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public void removeCachedPlayerMessage(@NotNull UUID uuid) throws SQLException {
|
||||
try (Connection connection = CoreAPI.getInstance().getConnection()) {
|
||||
PreparedStatement statement = connection.prepareStatement("DELETE FROM " + BallCommonConstants.SQL.CACHED_MESSAGE_TABLE + " WHERE `uuid`=?;");
|
||||
statement.setString(1, uuid.toString());
|
||||
statement.executeUpdate();
|
||||
statement.close();
|
||||
}
|
||||
}
|
||||
|
||||
public void addListener(@NotNull BallListener listener) {
|
||||
listeners.add(listener);
|
||||
listeners.sort(Comparator.comparingInt(BallListener::getPriority));
|
||||
}
|
||||
|
||||
public void removeListener(@NotNull BallListener listener) {
|
||||
listeners.remove(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取本地服务器ID
|
||||
*
|
||||
* @return 服务器ID
|
||||
*/
|
||||
@NotNull
|
||||
public ServerInfo getLocalServerInfo() {
|
||||
return config.getLocalInfo();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getLocalServerId() {
|
||||
return config.getLocalInfo().getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取服务器信息
|
||||
*
|
||||
* @param serverID 服务器ID
|
||||
* @return 可能为 null
|
||||
*/
|
||||
public ServerInfo getServerInfo(@NotNull String serverID) {
|
||||
return serverInfo.get(serverID);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取玩家信息
|
||||
*
|
||||
* @param uuid 玩家的 UUID
|
||||
* @return 玩家信息
|
||||
*/
|
||||
public PlayerInfo getPlayerInfo(@NotNull UUID uuid) {
|
||||
return playerInfo.get(uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取玩家信息
|
||||
*
|
||||
* @param playerName 玩家名称
|
||||
* @return 玩家信息
|
||||
*/
|
||||
public PlayerInfo getPlayerInfo(@NotNull String playerName) {
|
||||
return playerInfo.searchValues(Long.MAX_VALUE, info -> {
|
||||
if (info.getName().equalsIgnoreCase(playerName)) {
|
||||
return info;
|
||||
}
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ConcurrentHashMap<String, ServerInfo> getAllServerInfo() {
|
||||
return serverInfo;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ConcurrentHashMap<UUID, PlayerInfo> getAllPlayerInfo() {
|
||||
return playerInfo;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<BallListener> getListeners() {
|
||||
return listeners;
|
||||
}
|
||||
}
|
@@ -0,0 +1,19 @@
|
||||
package cn.hamster3.mc.plugin.ball.common.config;
|
||||
|
||||
import cn.hamster3.mc.plugin.ball.common.entity.ServerInfo;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class BallConfig {
|
||||
@NotNull
|
||||
private ServerInfo localInfo;
|
||||
|
||||
@NotNull
|
||||
private String host;
|
||||
private int port;
|
||||
|
||||
private int nioThread;
|
||||
}
|
@@ -0,0 +1,224 @@
|
||||
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.event.operate.*;
|
||||
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 cn.hamster3.mc.plugin.ball.common.listener.BallListener;
|
||||
import cn.hamster3.mc.plugin.core.common.constant.CoreConstantObjects;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.SimpleChannelInboundHandler;
|
||||
|
||||
public class BallChannelInboundHandler extends SimpleChannelInboundHandler<String> {
|
||||
public static final BallChannelInboundHandler INSTANCE = new BallChannelInboundHandler();
|
||||
|
||||
private BallChannelInboundHandler() {
|
||||
super(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void channelRead0(ChannelHandlerContext context, String message) {
|
||||
ServiceMessageInfo info = CoreConstantObjects.GSON.fromJson(message, ServiceMessageInfo.class);
|
||||
for (BallListener listener : BallAPI.getInstance().getListeners()) {
|
||||
try {
|
||||
listener.onMessageReceived(info);
|
||||
} catch (Exception | Error e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (!BallAPI.BALL_CHANNEL.equals(info.getChannel())) {
|
||||
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.onDispatchGamePlayerCommand(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 PlayerChatEvent.ACTION: {
|
||||
PlayerChatEvent event = CoreConstantObjects.GSON.fromJson(info.getContent(), PlayerChatEvent.class);
|
||||
for (BallListener listener : BallAPI.getInstance().getListeners()) {
|
||||
try {
|
||||
listener.onPlayerChat(event);
|
||||
} catch (Exception | Error e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PlayerConnectServerEvent.ACTION: {
|
||||
PlayerConnectServerEvent event = CoreConstantObjects.GSON.fromJson(info.getContent(), PlayerConnectServerEvent.class);
|
||||
for (BallListener listener : BallAPI.getInstance().getListeners()) {
|
||||
try {
|
||||
listener.onPlayerConnectServer(event);
|
||||
} catch (Exception | Error e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PlayerDisconnectEvent.ACTION: {
|
||||
PlayerDisconnectEvent event = CoreConstantObjects.GSON.fromJson(info.getContent(), PlayerDisconnectEvent.class);
|
||||
for (BallListener listener : BallAPI.getInstance().getListeners()) {
|
||||
try {
|
||||
listener.onPlayerDisconnect(event);
|
||||
} catch (Exception | Error e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PlayerLoginEvent.ACTION: {
|
||||
PlayerLoginEvent event = CoreConstantObjects.GSON.fromJson(info.getContent(), PlayerLoginEvent.class);
|
||||
for (BallListener listener : BallAPI.getInstance().getListeners()) {
|
||||
try {
|
||||
listener.onPlayerLogin(event);
|
||||
} catch (Exception | Error e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PlayerPostConnectServerEvent.ACTION: {
|
||||
PlayerPostConnectServerEvent event = CoreConstantObjects.GSON.fromJson(info.getContent(), PlayerPostConnectServerEvent.class);
|
||||
for (BallListener listener : BallAPI.getInstance().getListeners()) {
|
||||
try {
|
||||
listener.onPlayerPostConnectServer(event);
|
||||
} catch (Exception | Error e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PlayerPostLoginEvent.ACTION: {
|
||||
PlayerPostLoginEvent event = CoreConstantObjects.GSON.fromJson(info.getContent(), PlayerPostLoginEvent.class);
|
||||
for (BallListener listener : BallAPI.getInstance().getListeners()) {
|
||||
try {
|
||||
listener.onPlayerPostLogin(event);
|
||||
} catch (Exception | Error e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PlayerPreConnectServerEvent.ACTION: {
|
||||
PlayerPreConnectServerEvent event = CoreConstantObjects.GSON.fromJson(info.getContent(), PlayerPreConnectServerEvent.class);
|
||||
for (BallListener listener : BallAPI.getInstance().getListeners()) {
|
||||
try {
|
||||
listener.onPlayerPreConnectServer(event);
|
||||
} catch (Exception | Error e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case PlayerPreLoginEvent.ACTION: {
|
||||
PlayerPreLoginEvent event = CoreConstantObjects.GSON.fromJson(info.getContent(), PlayerPreLoginEvent.class);
|
||||
for (BallListener listener : BallAPI.getInstance().getListeners()) {
|
||||
try {
|
||||
listener.onPlayerPreLogin(event);
|
||||
} catch (Exception | Error e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ServerOfflineEvent.ACTION: {
|
||||
ServerOfflineEvent event = CoreConstantObjects.GSON.fromJson(info.getContent(), ServerOfflineEvent.class);
|
||||
for (BallListener listener : BallAPI.getInstance().getListeners()) {
|
||||
try {
|
||||
listener.onServerOffline(event);
|
||||
} catch (Exception | Error e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
case ServerOnlineEvent.ACTION: {
|
||||
ServerOnlineEvent event = CoreConstantObjects.GSON.fromJson(info.getContent(), ServerOnlineEvent.class);
|
||||
for (BallListener listener : BallAPI.getInstance().getListeners()) {
|
||||
try {
|
||||
listener.onServerOnline(event);
|
||||
} catch (Exception | Error e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,55 @@
|
||||
package cn.hamster3.mc.plugin.ball.common.connector;
|
||||
|
||||
import cn.hamster3.mc.plugin.ball.common.api.BallAPI;
|
||||
import cn.hamster3.mc.plugin.ball.common.listener.BallListener;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelInitializer;
|
||||
import io.netty.channel.socket.nio.NioSocketChannel;
|
||||
import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
|
||||
import io.netty.handler.codec.LengthFieldPrepender;
|
||||
import io.netty.handler.codec.string.StringDecoder;
|
||||
import io.netty.handler.codec.string.StringEncoder;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class BallChannelInitializer extends ChannelInitializer<NioSocketChannel> {
|
||||
public static final BallChannelInitializer INSTANCE = new BallChannelInitializer();
|
||||
|
||||
private BallChannelInitializer() {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initChannel(@NotNull NioSocketChannel channel) {
|
||||
channel.pipeline()
|
||||
.addLast(new LengthFieldPrepender(8))
|
||||
.addLast(new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 8, 0, 8))
|
||||
.addLast(new StringDecoder(StandardCharsets.UTF_8))
|
||||
.addLast(new StringEncoder(StandardCharsets.UTF_8))
|
||||
.addLast(BallChannelInboundHandler.INSTANCE)
|
||||
;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelInactive(@NotNull ChannelHandlerContext context) {
|
||||
for (BallListener listener : BallAPI.getInstance().getListeners()) {
|
||||
try {
|
||||
listener.onConnectInactive();
|
||||
} catch (Exception | Error e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void exceptionCaught(ChannelHandlerContext context, Throwable cause) {
|
||||
for (BallListener listener : BallAPI.getInstance().getListeners()) {
|
||||
try {
|
||||
listener.onConnectException(cause);
|
||||
} catch (Exception | Error e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,9 @@
|
||||
package cn.hamster3.mc.plugin.ball.common.constant;
|
||||
|
||||
public interface BallCommonConstants {
|
||||
interface SQL {
|
||||
String PLAYER_INFO_TABLE = "hamster_ball_player_info";
|
||||
String SERVER_INFO_TABLE = "hamster_ball_server_info";
|
||||
String CACHED_MESSAGE_TABLE = "hamster_ball_cached_message";
|
||||
}
|
||||
}
|
@@ -0,0 +1,23 @@
|
||||
package cn.hamster3.mc.plugin.ball.common.data;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@SuppressWarnings("unused")
|
||||
public class ServiceBlockPos {
|
||||
private String serverID;
|
||||
private String worldName;
|
||||
private int x;
|
||||
private int y;
|
||||
private int z;
|
||||
|
||||
@NotNull
|
||||
public ServiceLocation toServiceLocation() {
|
||||
return new ServiceLocation(getServerID(), getWorldName(), getX(), getY(), getZ(), 0, 0);
|
||||
}
|
||||
}
|
@@ -0,0 +1,38 @@
|
||||
package cn.hamster3.mc.plugin.ball.common.data;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@SuppressWarnings("unused")
|
||||
public class ServiceLocation {
|
||||
private String serverID;
|
||||
private String worldName;
|
||||
private double x;
|
||||
private double y;
|
||||
private double z;
|
||||
|
||||
private float yaw;
|
||||
private float pitch;
|
||||
|
||||
public int getBlockX() {
|
||||
return (int) x;
|
||||
}
|
||||
|
||||
public int getBlockY() {
|
||||
return (int) y;
|
||||
}
|
||||
|
||||
public int getBlockZ() {
|
||||
return (int) z;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ServiceBlockPos toServiceBlockPos() {
|
||||
return new ServiceBlockPos(getServerID(), getWorldName(), getBlockX(), getBlockY(), getBlockZ());
|
||||
}
|
||||
}
|
@@ -0,0 +1,154 @@
|
||||
package cn.hamster3.mc.plugin.ball.common.data;
|
||||
|
||||
import cn.hamster3.mc.plugin.ball.common.entity.ServerType;
|
||||
import cn.hamster3.mc.plugin.core.common.constant.CoreConstantObjects;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* 服务消息
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@SuppressWarnings("unused")
|
||||
public class ServiceMessageInfo {
|
||||
/**
|
||||
* 消息的频道
|
||||
*/
|
||||
@NotNull
|
||||
private String channel;
|
||||
/**
|
||||
* 消息发送者
|
||||
*/
|
||||
@NotNull
|
||||
private String senderID;
|
||||
/**
|
||||
* 接受该消息的目标服务器ID
|
||||
* <p>
|
||||
* 若设定该值,则仅服务器名称匹配的子端才能接收到这条消息
|
||||
* <p>
|
||||
* 若不设定(即为 null),则该消息会广播给所有子端
|
||||
*/
|
||||
@Nullable
|
||||
private String receiverID;
|
||||
/**
|
||||
* 接受该消息的目标服务器类型
|
||||
* <p>
|
||||
* 若设定该值,则仅服务器类型匹配的子端才能接收到这条消息
|
||||
* <p>
|
||||
* 若不设定(值为null),则该消息会广播给所有子端
|
||||
*/
|
||||
@Nullable
|
||||
private ServerType receiverType;
|
||||
/**
|
||||
* 消息动作
|
||||
* <p>
|
||||
* 一般用这个来判断插件应该如何处理这条消息
|
||||
*/
|
||||
private String action;
|
||||
/**
|
||||
* 消息内容
|
||||
* <p>
|
||||
* 这里是消息的附加参数
|
||||
*/
|
||||
private JsonElement content;
|
||||
|
||||
/**
|
||||
* 序列化至 Json
|
||||
*
|
||||
* @return json对象
|
||||
*/
|
||||
@NotNull
|
||||
public JsonObject saveToJson() {
|
||||
JsonObject object = new JsonObject();
|
||||
object.addProperty("channel", channel);
|
||||
object.addProperty("senderID", senderID);
|
||||
if (receiverID != null) {
|
||||
object.addProperty("toServer", receiverID);
|
||||
}
|
||||
if (receiverType != null) {
|
||||
object.addProperty("toServer", receiverType.name());
|
||||
}
|
||||
object.addProperty("action", action);
|
||||
object.add("content", content);
|
||||
return object;
|
||||
}
|
||||
|
||||
/**
|
||||
* 以 Java 对象获取消息内容
|
||||
*
|
||||
* @param clazz 对象所属的类
|
||||
* @param <T> 对象类型
|
||||
* @return Java 对象
|
||||
*/
|
||||
public <T> T getContentAs(Class<T> clazz) {
|
||||
return CoreConstantObjects.GSON.fromJson(content, clazz);
|
||||
}
|
||||
|
||||
/**
|
||||
* 以字符串形式获取消息内容
|
||||
*
|
||||
* @return 消息内容
|
||||
*/
|
||||
public String getContentAsString() {
|
||||
return content.getAsString();
|
||||
}
|
||||
|
||||
public boolean getContentAsBoolean() {
|
||||
return content.getAsBoolean();
|
||||
}
|
||||
|
||||
public int getContentAsInt() {
|
||||
return content.getAsInt();
|
||||
}
|
||||
|
||||
public long getContentAsLong() {
|
||||
return content.getAsLong();
|
||||
}
|
||||
|
||||
public BigInteger getContentAsBigInteger() {
|
||||
return content.getAsBigInteger();
|
||||
}
|
||||
|
||||
public BigDecimal getContentAsBigDecimal() {
|
||||
return content.getAsBigDecimal();
|
||||
}
|
||||
|
||||
public UUID getContentAsUUID() {
|
||||
return UUID.fromString(content.getAsString());
|
||||
}
|
||||
|
||||
/**
|
||||
* 以 JsonObject 对象获取消息内容
|
||||
*
|
||||
* @return 消息内容
|
||||
*/
|
||||
public JsonObject getContentAsJsonObject() {
|
||||
return content.getAsJsonObject();
|
||||
}
|
||||
|
||||
/**
|
||||
* 以 JsonArray 对象获取消息内容
|
||||
*
|
||||
* @return 消息内容
|
||||
*/
|
||||
public JsonArray getContentAsJsonArray() {
|
||||
return content.getAsJsonArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return saveToJson().toString();
|
||||
}
|
||||
}
|
@@ -0,0 +1,65 @@
|
||||
package cn.hamster3.mc.plugin.ball.common.entity;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* 玩家信息
|
||||
*/
|
||||
@Data
|
||||
@NotNull
|
||||
@AllArgsConstructor
|
||||
public class PlayerInfo {
|
||||
/**
|
||||
* 玩家的uuid
|
||||
*/
|
||||
@NotNull
|
||||
private UUID uuid;
|
||||
/**
|
||||
* 玩家的名称
|
||||
*/
|
||||
@NotNull
|
||||
private String name;
|
||||
/**
|
||||
* 玩家的档案(包含皮肤等信息)
|
||||
*/
|
||||
@NotNull
|
||||
private JsonElement profile;
|
||||
/**
|
||||
* 玩家所在的游戏服务器 ID
|
||||
* <p>
|
||||
* 不应超过 32 个字符
|
||||
*/
|
||||
@NotNull
|
||||
private String gameServer;
|
||||
/**
|
||||
* 玩家所在的代理服务器 ID
|
||||
* <p>
|
||||
* 不应超过 32 个字符
|
||||
*/
|
||||
@NotNull
|
||||
private String proxyServer;
|
||||
/**
|
||||
* 玩家是否在线
|
||||
*/
|
||||
private boolean online;
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
PlayerInfo that = (PlayerInfo) o;
|
||||
|
||||
return uuid.equals(that.uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return uuid.hashCode();
|
||||
}
|
||||
}
|
@@ -0,0 +1,55 @@
|
||||
package cn.hamster3.mc.plugin.ball.common.entity;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 消息发送者信息
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class ServerInfo {
|
||||
/**
|
||||
* 服务器 ID
|
||||
* <p>
|
||||
* 不应超过 32 个字符
|
||||
*/
|
||||
private String id;
|
||||
/**
|
||||
* 服务器名称
|
||||
* <p>
|
||||
* 不应超过 32 个字符
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 服务器类型
|
||||
*/
|
||||
private ServerType type;
|
||||
/**
|
||||
* 服务器主机名
|
||||
* <p>
|
||||
* 不应超过 32 个字符
|
||||
*/
|
||||
private String host;
|
||||
/**
|
||||
* 服务器端口号
|
||||
*/
|
||||
private int port;
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
ServerInfo that = (ServerInfo) o;
|
||||
return id.equals(that.id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(id);
|
||||
}
|
||||
}
|
@@ -0,0 +1,24 @@
|
||||
package cn.hamster3.mc.plugin.ball.common.entity;
|
||||
|
||||
/**
|
||||
* Service 接入者的类型
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public enum ServerType {
|
||||
/**
|
||||
* 游戏服务器
|
||||
*/
|
||||
GAME,
|
||||
/**
|
||||
* 代理服务器
|
||||
*/
|
||||
PROXY,
|
||||
/**
|
||||
* 测试服务器
|
||||
*/
|
||||
TEST,
|
||||
/**
|
||||
* 其他类型的接入者
|
||||
*/
|
||||
OTHER
|
||||
}
|
@@ -0,0 +1,16 @@
|
||||
package cn.hamster3.mc.plugin.ball.common.event.operate;
|
||||
|
||||
import cn.hamster3.mc.plugin.core.common.data.Message;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class BroadcastPlayerMessageEvent {
|
||||
public static final String ACTION = "BroadcastPlayerMessage";
|
||||
|
||||
@NotNull
|
||||
private final Message message;
|
||||
|
||||
}
|
@@ -0,0 +1,20 @@
|
||||
package cn.hamster3.mc.plugin.ball.common.event.operate;
|
||||
|
||||
import cn.hamster3.mc.plugin.ball.common.entity.ServerType;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class DispatchConsoleCommandEvent {
|
||||
public static final String ACTION = "DispatchConsoleCommand";
|
||||
|
||||
@Nullable
|
||||
private final ServerType type;
|
||||
@Nullable
|
||||
private final String serverID;
|
||||
@NotNull
|
||||
private final String command;
|
||||
}
|
@@ -0,0 +1,22 @@
|
||||
package cn.hamster3.mc.plugin.ball.common.event.operate;
|
||||
|
||||
import cn.hamster3.mc.plugin.ball.common.entity.ServerType;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class DispatchPlayerCommandEvent {
|
||||
public static final String ACTION = "DispatchPlayerCommand";
|
||||
|
||||
@Nullable
|
||||
private final ServerType type;
|
||||
@Nullable
|
||||
private final UUID uuid;
|
||||
@NotNull
|
||||
private final String command;
|
||||
}
|
@@ -0,0 +1,20 @@
|
||||
package cn.hamster3.mc.plugin.ball.common.event.operate;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class KickPlayerEvent {
|
||||
public static final String ACTION = "KickPlayer";
|
||||
|
||||
@NotNull
|
||||
private final UUID uuid;
|
||||
@NotNull
|
||||
private final Component reason;
|
||||
|
||||
}
|
@@ -0,0 +1,19 @@
|
||||
package cn.hamster3.mc.plugin.ball.common.event.operate;
|
||||
|
||||
import cn.hamster3.mc.plugin.core.common.data.Message;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class SendMessageToPlayerEvent {
|
||||
public static final String ACTION = "SendMessageToPlayer";
|
||||
|
||||
@NotNull
|
||||
private final UUID uuid;
|
||||
@NotNull
|
||||
private final Message message;
|
||||
}
|
@@ -0,0 +1,26 @@
|
||||
package cn.hamster3.mc.plugin.ball.common.event.operate;
|
||||
|
||||
import cn.hamster3.mc.plugin.ball.common.data.ServiceLocation;
|
||||
import cn.hamster3.mc.plugin.core.common.data.Message;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class SendPlayerToLocationEvent {
|
||||
public static final String ACTION = "SendPlayerToLocation";
|
||||
|
||||
@NotNull
|
||||
private final Set<UUID> sendPlayerUUID;
|
||||
@NotNull
|
||||
private final ServiceLocation location;
|
||||
@Nullable
|
||||
private final Message doneMessage;
|
||||
|
||||
}
|
@@ -0,0 +1,27 @@
|
||||
package cn.hamster3.mc.plugin.ball.common.event.operate;
|
||||
|
||||
import cn.hamster3.mc.plugin.core.common.data.Message;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class SendPlayerToPlayerEvent {
|
||||
public static final String ACTION = "SendPlayerToPlayer";
|
||||
|
||||
@NotNull
|
||||
private final Set<UUID> sendPlayerUUID;
|
||||
@NotNull
|
||||
private final UUID toPlayerUUID;
|
||||
@Nullable
|
||||
private final Message doneMessage;
|
||||
@Nullable
|
||||
private final Message doneTargetMessage;
|
||||
|
||||
}
|
@@ -0,0 +1,25 @@
|
||||
package cn.hamster3.mc.plugin.ball.common.event.player;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* 玩家的聊天信息
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class PlayerChatEvent {
|
||||
public static final String ACTION = "PlayerChat";
|
||||
|
||||
@NotNull
|
||||
private final UUID playerUUID;
|
||||
@NotNull
|
||||
private final Component displayName;
|
||||
@NotNull
|
||||
private final Component message;
|
||||
|
||||
}
|
@@ -0,0 +1,23 @@
|
||||
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;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* 玩家进入子服
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class PlayerConnectServerEvent {
|
||||
public static final String ACTION = "PlayerConnectServer";
|
||||
|
||||
@NotNull
|
||||
private final PlayerInfo playerInfo;
|
||||
@Nullable
|
||||
private final String from;
|
||||
@NotNull
|
||||
private final String to;
|
||||
}
|
@@ -0,0 +1,20 @@
|
||||
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;
|
||||
}
|
@@ -0,0 +1,19 @@
|
||||
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 PlayerLoginEvent {
|
||||
public static final String ACTION = "PlayerLogin";
|
||||
|
||||
@NotNull
|
||||
private final PlayerInfo playerInfo;
|
||||
|
||||
}
|
@@ -0,0 +1,23 @@
|
||||
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;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* 玩家已进入子服
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class PlayerPostConnectServerEvent {
|
||||
public static final String ACTION = "PlayerPostConnectServer";
|
||||
|
||||
@NotNull
|
||||
private final PlayerInfo playerInfo;
|
||||
@Nullable
|
||||
private final String from;
|
||||
@NotNull
|
||||
private final String to;
|
||||
}
|
@@ -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 PlayerPostLoginEvent {
|
||||
public static final String ACTION = "PlayerPostLogin";
|
||||
|
||||
@NotNull
|
||||
private final PlayerInfo playerInfo;
|
||||
}
|
@@ -0,0 +1,24 @@
|
||||
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;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* 玩家准备进入子服
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class PlayerPreConnectServerEvent {
|
||||
public static final String ACTION = "PlayerPreConnectServer";
|
||||
|
||||
@NotNull
|
||||
private final PlayerInfo playerInfo;
|
||||
@Nullable
|
||||
private final String from;
|
||||
@NotNull
|
||||
private final String to;
|
||||
|
||||
}
|
@@ -0,0 +1,17 @@
|
||||
package cn.hamster3.mc.plugin.ball.common.event.player;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* 玩家准备连接到服务器
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class PlayerPreLoginEvent {
|
||||
public static final String ACTION = "PlayerPreLogin";
|
||||
|
||||
@NotNull
|
||||
private final String playerName;
|
||||
}
|
@@ -0,0 +1,17 @@
|
||||
package cn.hamster3.mc.plugin.ball.common.event.server;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* 服务器离线
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class ServerOfflineEvent {
|
||||
public static final String ACTION = "ServerOffline";
|
||||
|
||||
@NotNull
|
||||
private final String serverID;
|
||||
}
|
@@ -0,0 +1,19 @@
|
||||
package cn.hamster3.mc.plugin.ball.common.event.server;
|
||||
|
||||
import cn.hamster3.mc.plugin.ball.common.entity.ServerInfo;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* 服务器上线
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class ServerOnlineEvent {
|
||||
public static final String ACTION = "ServerOnline";
|
||||
|
||||
@NotNull
|
||||
private final ServerInfo serverInfo;
|
||||
|
||||
}
|
@@ -0,0 +1,88 @@
|
||||
package cn.hamster3.mc.plugin.ball.common.listener;
|
||||
|
||||
import cn.hamster3.mc.plugin.ball.common.data.ServiceMessageInfo;
|
||||
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;
|
||||
import cn.hamster3.mc.plugin.ball.common.event.server.ServerOnlineEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public abstract class BallListener {
|
||||
/**
|
||||
* 该监听器的执行优先级
|
||||
* <p>
|
||||
* 数字越低越先执行
|
||||
*
|
||||
* @return 优先级
|
||||
*/
|
||||
public int getPriority() {
|
||||
return 100;
|
||||
}
|
||||
|
||||
public void onBroadcastPlayerMessage(@NotNull BroadcastPlayerMessageEvent event) {
|
||||
}
|
||||
|
||||
public void onDispatchConsoleCommand(@NotNull DispatchConsoleCommandEvent event) {
|
||||
}
|
||||
|
||||
public void onDispatchGamePlayerCommand(@NotNull DispatchPlayerCommandEvent event) {
|
||||
}
|
||||
|
||||
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 onPlayerChat(@NotNull PlayerChatEvent event) {
|
||||
}
|
||||
|
||||
public void onPlayerConnectServer(@NotNull PlayerConnectServerEvent event) {
|
||||
}
|
||||
|
||||
public void onPlayerDisconnect(@NotNull PlayerDisconnectEvent event) {
|
||||
}
|
||||
|
||||
public void onPlayerLogin(@NotNull PlayerLoginEvent event) {
|
||||
}
|
||||
|
||||
public void onPlayerPostConnectServer(@NotNull PlayerPostConnectServerEvent event) {
|
||||
}
|
||||
|
||||
public void onPlayerPostLogin(@NotNull PlayerPostLoginEvent event) {
|
||||
}
|
||||
|
||||
public void onPlayerPreConnectServer(@NotNull PlayerPreConnectServerEvent event) {
|
||||
}
|
||||
|
||||
public void onPlayerPreLogin(@NotNull PlayerPreLoginEvent event) {
|
||||
}
|
||||
|
||||
public void onServerOffline(@NotNull ServerOfflineEvent event) {
|
||||
}
|
||||
|
||||
public void onServerOnline(@NotNull ServerOnlineEvent event) {
|
||||
}
|
||||
|
||||
public void onMessageReceived(@NotNull ServiceMessageInfo event) {
|
||||
}
|
||||
|
||||
public void onMessageSend(@NotNull ServiceMessageInfo event) {
|
||||
}
|
||||
|
||||
public void onConnectInactive() {
|
||||
}
|
||||
|
||||
public void onConnectException(Throwable throwable) {
|
||||
}
|
||||
|
||||
public void onReconnectFailed() {
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user