feat: 适配Core更新
This commit is contained in:
@@ -2,7 +2,7 @@ package cn.hamster3.mc.plugin.ball.bukkit.data;
|
||||
|
||||
import cn.hamster3.mc.plugin.ball.common.api.BallAPI;
|
||||
import cn.hamster3.mc.plugin.ball.common.data.BallBlockPos;
|
||||
import cn.hamster3.mc.plugin.core.common.constant.CoreConstantObjects;
|
||||
import cn.hamster3.mc.plugin.core.common.util.CoreUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
@@ -51,7 +51,7 @@ public class BukkitBlockPos extends BallBlockPos {
|
||||
}
|
||||
|
||||
public static BukkitBlockPos fromJson(String json) {
|
||||
return CoreConstantObjects.GSON.fromJson(json, BukkitBlockPos.class);
|
||||
return CoreUtils.GSON.fromJson(json, BukkitBlockPos.class);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
@@ -2,7 +2,7 @@ package cn.hamster3.mc.plugin.ball.bukkit.data;
|
||||
|
||||
import cn.hamster3.mc.plugin.ball.common.api.BallAPI;
|
||||
import cn.hamster3.mc.plugin.ball.common.data.BallLocation;
|
||||
import cn.hamster3.mc.plugin.core.common.constant.CoreConstantObjects;
|
||||
import cn.hamster3.mc.plugin.core.common.util.CoreUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.Block;
|
||||
@@ -53,7 +53,7 @@ public class BukkitLocation extends BallLocation {
|
||||
}
|
||||
|
||||
public static BukkitLocation fromJson(String json) {
|
||||
return CoreConstantObjects.GSON.fromJson(json, BukkitLocation.class);
|
||||
return CoreUtils.GSON.fromJson(json, BukkitLocation.class);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
@@ -9,8 +9,8 @@ import cn.hamster3.mc.plugin.ball.common.event.operate.*;
|
||||
import cn.hamster3.mc.plugin.ball.common.listener.BallListener;
|
||||
import cn.hamster3.mc.plugin.core.bukkit.api.CoreBukkitAPI;
|
||||
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.DisplayMessage;
|
||||
import cn.hamster3.mc.plugin.core.common.util.CoreUtils;
|
||||
import cn.hamster3.mc.plugin.core.common.util.Pair;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -43,14 +43,14 @@ public class BallBukkitListener implements Listener, BallListener {
|
||||
public void onMessageReceived(@NotNull BallMessageInfo info) {
|
||||
switch (info.getAction()) {
|
||||
case BroadcastPlayerMessageEvent.ACTION: {
|
||||
BroadcastPlayerMessageEvent event = CoreConstantObjects.GSON.fromJson(info.getContent(), BroadcastPlayerMessageEvent.class);
|
||||
BroadcastPlayerMessageEvent event = CoreUtils.GSON.fromJson(info.getContent(), BroadcastPlayerMessageEvent.class);
|
||||
DisplayMessage message = event.getMessage();
|
||||
Audience audience = CoreAPI.getInstance().getAudienceProvider().all();
|
||||
message.show(audience);
|
||||
break;
|
||||
}
|
||||
case DispatchConsoleCommandEvent.ACTION: {
|
||||
DispatchConsoleCommandEvent event = CoreConstantObjects.GSON.fromJson(info.getContent(), DispatchConsoleCommandEvent.class);
|
||||
DispatchConsoleCommandEvent event = CoreUtils.GSON.fromJson(info.getContent(), DispatchConsoleCommandEvent.class);
|
||||
if (event.getType() != null && event.getType() != BallServerType.GAME) {
|
||||
return;
|
||||
}
|
||||
@@ -61,7 +61,7 @@ public class BallBukkitListener implements Listener, BallListener {
|
||||
break;
|
||||
}
|
||||
case DispatchPlayerCommandEvent.ACTION: {
|
||||
DispatchPlayerCommandEvent event = CoreConstantObjects.GSON.fromJson(info.getContent(), DispatchPlayerCommandEvent.class);
|
||||
DispatchPlayerCommandEvent event = CoreUtils.GSON.fromJson(info.getContent(), DispatchPlayerCommandEvent.class);
|
||||
if (event.getType() != null && event.getType() != BallServerType.GAME) {
|
||||
return;
|
||||
}
|
||||
@@ -79,7 +79,7 @@ public class BallBukkitListener implements Listener, BallListener {
|
||||
break;
|
||||
}
|
||||
case SendPlayerToLocationEvent.ACTION: {
|
||||
SendPlayerToLocationEvent event = CoreConstantObjects.GSON.fromJson(info.getContent(), SendPlayerToLocationEvent.class);
|
||||
SendPlayerToLocationEvent event = CoreUtils.GSON.fromJson(info.getContent(), SendPlayerToLocationEvent.class);
|
||||
BukkitLocation location = new BukkitLocation(event.getLocation());
|
||||
if (BallAPI.getInstance().isLocalServer(location.getServerID())) {
|
||||
for (UUID uuid : event.getSendPlayerUUID()) {
|
||||
@@ -100,7 +100,7 @@ public class BallBukkitListener implements Listener, BallListener {
|
||||
break;
|
||||
}
|
||||
case SendPlayerToPlayerEvent.ACTION: {
|
||||
SendPlayerToPlayerEvent event = CoreConstantObjects.GSON.fromJson(info.getContent(), SendPlayerToPlayerEvent.class);
|
||||
SendPlayerToPlayerEvent event = CoreUtils.GSON.fromJson(info.getContent(), SendPlayerToPlayerEvent.class);
|
||||
Player toPlayer = Bukkit.getPlayer(event.getToPlayerUUID());
|
||||
if (toPlayer == null) {
|
||||
return;
|
||||
|
@@ -10,7 +10,7 @@ import cn.hamster3.mc.plugin.ball.common.listener.BallListener;
|
||||
import cn.hamster3.mc.plugin.core.bungee.HamsterBallPlugin;
|
||||
import cn.hamster3.mc.plugin.core.bungee.util.BallBungeeCordUtils;
|
||||
import cn.hamster3.mc.plugin.core.common.api.CoreAPI;
|
||||
import cn.hamster3.mc.plugin.core.common.constant.CoreConstantObjects;
|
||||
import cn.hamster3.mc.plugin.core.common.util.CoreUtils;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.text.serializer.bungeecord.BungeeComponentSerializer;
|
||||
import net.md_5.bungee.api.ProxyServer;
|
||||
@@ -35,7 +35,7 @@ public final class BallBungeeCordListener implements Listener, BallListener {
|
||||
public void onMessageReceived(@NotNull BallMessageInfo info) {
|
||||
switch (info.getAction()) {
|
||||
case DispatchConsoleCommandEvent.ACTION: {
|
||||
DispatchConsoleCommandEvent event = CoreConstantObjects.GSON.fromJson(info.getContent(), DispatchConsoleCommandEvent.class);
|
||||
DispatchConsoleCommandEvent event = CoreUtils.GSON.fromJson(info.getContent(), DispatchConsoleCommandEvent.class);
|
||||
if (event.getType() != null && event.getType() != BallServerType.PROXY) {
|
||||
return;
|
||||
}
|
||||
@@ -47,7 +47,7 @@ public final class BallBungeeCordListener implements Listener, BallListener {
|
||||
break;
|
||||
}
|
||||
case DispatchPlayerCommandEvent.ACTION: {
|
||||
DispatchPlayerCommandEvent event = CoreConstantObjects.GSON.fromJson(info.getContent(), DispatchPlayerCommandEvent.class);
|
||||
DispatchPlayerCommandEvent event = CoreUtils.GSON.fromJson(info.getContent(), DispatchPlayerCommandEvent.class);
|
||||
if (event.getType() != null && event.getType() != BallServerType.GAME) {
|
||||
return;
|
||||
}
|
||||
@@ -66,14 +66,14 @@ public final class BallBungeeCordListener implements Listener, BallListener {
|
||||
break;
|
||||
}
|
||||
case KickPlayerEvent.ACTION: {
|
||||
KickPlayerEvent event = CoreConstantObjects.GSON.fromJson(info.getContent(), KickPlayerEvent.class);
|
||||
KickPlayerEvent event = CoreUtils.GSON.fromJson(info.getContent(), KickPlayerEvent.class);
|
||||
ProxiedPlayer player = ProxyServer.getInstance().getPlayer(event.getUuid());
|
||||
BaseComponent[] components = BungeeComponentSerializer.get().serialize(event.getReason());
|
||||
player.disconnect(components);
|
||||
break;
|
||||
}
|
||||
case SendMessageToPlayerEvent.ACTION: {
|
||||
SendMessageToPlayerEvent event = CoreConstantObjects.GSON.fromJson(info.getContent(), SendMessageToPlayerEvent.class);
|
||||
SendMessageToPlayerEvent event = CoreUtils.GSON.fromJson(info.getContent(), SendMessageToPlayerEvent.class);
|
||||
for (UUID receiver : event.getReceivers()) {
|
||||
Audience audience = CoreAPI.getInstance().getAudienceProvider().player(receiver);
|
||||
event.getMessage().show(audience);
|
||||
@@ -81,7 +81,7 @@ public final class BallBungeeCordListener implements Listener, BallListener {
|
||||
break;
|
||||
}
|
||||
case SendPlayerToLocationEvent.ACTION: {
|
||||
SendPlayerToLocationEvent event = CoreConstantObjects.GSON.fromJson(info.getContent(), SendPlayerToLocationEvent.class);
|
||||
SendPlayerToLocationEvent event = CoreUtils.GSON.fromJson(info.getContent(), SendPlayerToLocationEvent.class);
|
||||
String serverID = event.getLocation().getServerID();
|
||||
ServerInfo serverInfo = ProxyServer.getInstance().getServerInfo(serverID);
|
||||
if (serverInfo == null) {
|
||||
|
@@ -4,7 +4,7 @@ import cn.hamster3.mc.plugin.ball.common.api.BallAPI;
|
||||
import cn.hamster3.mc.plugin.ball.common.entity.BallPlayerInfo;
|
||||
import cn.hamster3.mc.plugin.ball.common.event.player.BallPlayerInfoUpdateEvent;
|
||||
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.util.CoreUtils;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.connection.Server;
|
||||
|
||||
@@ -28,7 +28,7 @@ public final class BallBungeeCordUtils {
|
||||
}
|
||||
|
||||
public static void uploadPlayerInfo(BallPlayerInfo playerInfo) {
|
||||
CoreConstantObjects.WORKER_EXECUTOR.execute(() -> {
|
||||
CoreUtils.WORKER_EXECUTOR.execute(() -> {
|
||||
try (Connection connection = CoreAPI.getInstance().getConnection()) {
|
||||
PreparedStatement statement = connection.prepareStatement("REPLACE INTO `hamster_ball_player_info` VALUES(?, ?, ?, ?, ?);");
|
||||
statement.setString(1, playerInfo.getUuid().toString());
|
||||
|
@@ -15,8 +15,8 @@ import cn.hamster3.mc.plugin.ball.common.event.server.ServerOnlineEvent;
|
||||
import cn.hamster3.mc.plugin.ball.common.listener.BallListener;
|
||||
import cn.hamster3.mc.plugin.ball.common.listener.ListenerPriority;
|
||||
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.DisplayMessage;
|
||||
import cn.hamster3.mc.plugin.core.common.util.CoreUtils;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonPrimitive;
|
||||
import io.netty.bootstrap.Bootstrap;
|
||||
@@ -337,7 +337,7 @@ public abstract class BallAPI {
|
||||
* @param message 消息
|
||||
*/
|
||||
public void broadcastPlayerMessage(@NotNull String message) {
|
||||
broadcastPlayerMessage(DisplayMessage.message(message));
|
||||
broadcastPlayerMessage(new DisplayMessage().setMessage(message));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -352,7 +352,7 @@ public abstract class BallAPI {
|
||||
null,
|
||||
BallServerType.PROXY,
|
||||
BroadcastPlayerMessageEvent.ACTION,
|
||||
CoreConstantObjects.GSON.toJsonTree(
|
||||
CoreUtils.GSON.toJsonTree(
|
||||
new BroadcastPlayerMessageEvent(message)
|
||||
)
|
||||
));
|
||||
@@ -372,7 +372,7 @@ public abstract class BallAPI {
|
||||
null,
|
||||
BallServerType.GAME,
|
||||
DispatchConsoleCommandEvent.ACTION,
|
||||
CoreConstantObjects.GSON.toJsonTree(
|
||||
CoreUtils.GSON.toJsonTree(
|
||||
new DispatchConsoleCommandEvent(type, serverID, command)
|
||||
)
|
||||
));
|
||||
@@ -392,7 +392,7 @@ public abstract class BallAPI {
|
||||
null,
|
||||
BallServerType.GAME,
|
||||
DispatchPlayerCommandEvent.ACTION,
|
||||
CoreConstantObjects.GSON.toJsonTree(
|
||||
CoreUtils.GSON.toJsonTree(
|
||||
new DispatchPlayerCommandEvent(type, uuid, command)
|
||||
)
|
||||
));
|
||||
@@ -421,7 +421,7 @@ public abstract class BallAPI {
|
||||
null,
|
||||
BallServerType.PROXY,
|
||||
KickPlayerEvent.ACTION,
|
||||
CoreConstantObjects.GSON.toJsonTree(
|
||||
CoreUtils.GSON.toJsonTree(
|
||||
new KickPlayerEvent(uuid, reason)
|
||||
)
|
||||
));
|
||||
@@ -443,7 +443,7 @@ public abstract class BallAPI {
|
||||
try (Connection connection = CoreAPI.getInstance().getConnection()) {
|
||||
PreparedStatement statement = connection.prepareStatement("INSERT INTO `hamster_ball_cached_message` VALUES(?, ?);");
|
||||
statement.setString(1, receiver.toString());
|
||||
statement.setString(2, message.saveToJson().toString());
|
||||
statement.setString(2, message.toJson().toString());
|
||||
statement.executeUpdate();
|
||||
statement.close();
|
||||
} catch (Exception e) {
|
||||
@@ -457,7 +457,7 @@ public abstract class BallAPI {
|
||||
null,
|
||||
BallServerType.PROXY,
|
||||
SendMessageToPlayerEvent.ACTION,
|
||||
CoreConstantObjects.GSON.toJsonTree(
|
||||
CoreUtils.GSON.toJsonTree(
|
||||
new SendMessageToPlayerEvent(Collections.singleton(receiver), message)
|
||||
)
|
||||
));
|
||||
@@ -480,7 +480,7 @@ public abstract class BallAPI {
|
||||
try (Connection connection = CoreAPI.getInstance().getConnection()) {
|
||||
PreparedStatement statement = connection.prepareStatement("INSERT INTO `hamster_ball_cached_message` VALUES(?, ?);");
|
||||
statement.setString(1, receiver.toString());
|
||||
statement.setString(2, message.saveToJson().toString());
|
||||
statement.setString(2, message.toJson().toString());
|
||||
statement.executeUpdate();
|
||||
statement.close();
|
||||
} catch (Exception e) {
|
||||
@@ -494,7 +494,7 @@ public abstract class BallAPI {
|
||||
null,
|
||||
BallServerType.PROXY,
|
||||
SendMessageToPlayerEvent.ACTION,
|
||||
CoreConstantObjects.GSON.toJsonTree(
|
||||
CoreUtils.GSON.toJsonTree(
|
||||
new SendMessageToPlayerEvent(new HashSet<>(receivers), message)
|
||||
)
|
||||
));
|
||||
@@ -634,7 +634,7 @@ public abstract class BallAPI {
|
||||
getLogger().warning("由于服务不可用,有一条消息发送失败了: " + messageInfo);
|
||||
return;
|
||||
}
|
||||
ChannelFuture future = channel.writeAndFlush(CoreConstantObjects.GSON.toJson(messageInfo));
|
||||
ChannelFuture future = channel.writeAndFlush(CoreUtils.GSON.toJson(messageInfo));
|
||||
if (block) {
|
||||
try {
|
||||
future.await();
|
||||
@@ -659,7 +659,7 @@ public abstract class BallAPI {
|
||||
statement.setString(1, uuid.toString());
|
||||
ResultSet set = statement.executeQuery();
|
||||
while (set.next()) {
|
||||
DisplayMessage msg = CoreConstantObjects.GSON.fromJson(set.getString("msg"), DisplayMessage.class);
|
||||
DisplayMessage msg = CoreUtils.GSON.fromJson(set.getString("msg"), DisplayMessage.class);
|
||||
list.add(msg);
|
||||
}
|
||||
statement.close();
|
||||
|
@@ -6,7 +6,7 @@ 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 cn.hamster3.mc.plugin.core.common.util.CoreUtils;
|
||||
import io.netty.channel.ChannelHandler;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.SimpleChannelInboundHandler;
|
||||
@@ -27,7 +27,7 @@ public class BallChannelHandler extends SimpleChannelInboundHandler<String> {
|
||||
if ("pong".equals(message)) {
|
||||
return;
|
||||
}
|
||||
BallMessageInfo info = CoreConstantObjects.GSON.fromJson(message, BallMessageInfo.class);
|
||||
BallMessageInfo info = CoreUtils.GSON.fromJson(message, BallMessageInfo.class);
|
||||
for (BallListener listener : BallAPI.getInstance().getListeners()) {
|
||||
try {
|
||||
listener.onMessageReceived(info);
|
||||
@@ -40,7 +40,7 @@ public class BallChannelHandler extends SimpleChannelInboundHandler<String> {
|
||||
}
|
||||
switch (info.getAction()) {
|
||||
case BallPlayerPreLoginEvent.ACTION: {
|
||||
BallPlayerPreLoginEvent event = CoreConstantObjects.GSON.fromJson(info.getContent(), BallPlayerPreLoginEvent.class);
|
||||
BallPlayerPreLoginEvent event = CoreUtils.GSON.fromJson(info.getContent(), BallPlayerPreLoginEvent.class);
|
||||
for (BallListener listener : BallAPI.getInstance().getListeners()) {
|
||||
try {
|
||||
listener.onBallPlayerPreLogin(event);
|
||||
@@ -51,7 +51,7 @@ public class BallChannelHandler extends SimpleChannelInboundHandler<String> {
|
||||
break;
|
||||
}
|
||||
case BallPlayerLoginEvent.ACTION: {
|
||||
BallPlayerLoginEvent event = CoreConstantObjects.GSON.fromJson(info.getContent(), BallPlayerLoginEvent.class);
|
||||
BallPlayerLoginEvent event = CoreUtils.GSON.fromJson(info.getContent(), BallPlayerLoginEvent.class);
|
||||
for (BallListener listener : BallAPI.getInstance().getListeners()) {
|
||||
try {
|
||||
listener.onBallPlayerLogin(event);
|
||||
@@ -62,7 +62,7 @@ public class BallChannelHandler extends SimpleChannelInboundHandler<String> {
|
||||
break;
|
||||
}
|
||||
case BallPlayerPostLoginEvent.ACTION: {
|
||||
BallPlayerPostLoginEvent event = CoreConstantObjects.GSON.fromJson(info.getContent(), BallPlayerPostLoginEvent.class);
|
||||
BallPlayerPostLoginEvent event = CoreUtils.GSON.fromJson(info.getContent(), BallPlayerPostLoginEvent.class);
|
||||
for (BallListener listener : BallAPI.getInstance().getListeners()) {
|
||||
try {
|
||||
listener.onBallPlayerPostLogin(event);
|
||||
@@ -73,7 +73,7 @@ public class BallChannelHandler extends SimpleChannelInboundHandler<String> {
|
||||
break;
|
||||
}
|
||||
case BallPlayerPreConnectServerEvent.ACTION: {
|
||||
BallPlayerPreConnectServerEvent event = CoreConstantObjects.GSON.fromJson(info.getContent(), BallPlayerPreConnectServerEvent.class);
|
||||
BallPlayerPreConnectServerEvent event = CoreUtils.GSON.fromJson(info.getContent(), BallPlayerPreConnectServerEvent.class);
|
||||
for (BallListener listener : BallAPI.getInstance().getListeners()) {
|
||||
try {
|
||||
listener.onBallPlayerPreConnectServer(event);
|
||||
@@ -84,7 +84,7 @@ public class BallChannelHandler extends SimpleChannelInboundHandler<String> {
|
||||
break;
|
||||
}
|
||||
case BallPlayerConnectServerEvent.ACTION: {
|
||||
BallPlayerConnectServerEvent event = CoreConstantObjects.GSON.fromJson(info.getContent(), BallPlayerConnectServerEvent.class);
|
||||
BallPlayerConnectServerEvent event = CoreUtils.GSON.fromJson(info.getContent(), BallPlayerConnectServerEvent.class);
|
||||
for (BallListener listener : BallAPI.getInstance().getListeners()) {
|
||||
try {
|
||||
listener.onBallPlayerConnectServer(event);
|
||||
@@ -95,7 +95,7 @@ public class BallChannelHandler extends SimpleChannelInboundHandler<String> {
|
||||
break;
|
||||
}
|
||||
case BallPlayerPostConnectServerEvent.ACTION: {
|
||||
BallPlayerPostConnectServerEvent event = CoreConstantObjects.GSON.fromJson(info.getContent(), BallPlayerPostConnectServerEvent.class);
|
||||
BallPlayerPostConnectServerEvent event = CoreUtils.GSON.fromJson(info.getContent(), BallPlayerPostConnectServerEvent.class);
|
||||
for (BallListener listener : BallAPI.getInstance().getListeners()) {
|
||||
try {
|
||||
listener.onBallPlayerPostConnectServer(event);
|
||||
@@ -106,7 +106,7 @@ public class BallChannelHandler extends SimpleChannelInboundHandler<String> {
|
||||
break;
|
||||
}
|
||||
case BallPlayerLogoutEvent.ACTION: {
|
||||
BallPlayerLogoutEvent event = CoreConstantObjects.GSON.fromJson(info.getContent(), BallPlayerLogoutEvent.class);
|
||||
BallPlayerLogoutEvent event = CoreUtils.GSON.fromJson(info.getContent(), BallPlayerLogoutEvent.class);
|
||||
for (BallListener listener : BallAPI.getInstance().getListeners()) {
|
||||
try {
|
||||
listener.onBallPlayerLogout(event);
|
||||
@@ -117,7 +117,7 @@ public class BallChannelHandler extends SimpleChannelInboundHandler<String> {
|
||||
break;
|
||||
}
|
||||
case BallPlayerInfoUpdateEvent.ACTION: {
|
||||
BallPlayerInfoUpdateEvent event = CoreConstantObjects.GSON.fromJson(info.getContent(), BallPlayerInfoUpdateEvent.class);
|
||||
BallPlayerInfoUpdateEvent event = CoreUtils.GSON.fromJson(info.getContent(), BallPlayerInfoUpdateEvent.class);
|
||||
for (BallListener listener : BallAPI.getInstance().getListeners()) {
|
||||
try {
|
||||
listener.onBallPlayerInfoUpdate(event);
|
||||
@@ -128,7 +128,7 @@ public class BallChannelHandler extends SimpleChannelInboundHandler<String> {
|
||||
break;
|
||||
}
|
||||
case BallPlayerChatEvent.ACTION: {
|
||||
BallPlayerChatEvent event = CoreConstantObjects.GSON.fromJson(info.getContent(), BallPlayerChatEvent.class);
|
||||
BallPlayerChatEvent event = CoreUtils.GSON.fromJson(info.getContent(), BallPlayerChatEvent.class);
|
||||
for (BallListener listener : BallAPI.getInstance().getListeners()) {
|
||||
try {
|
||||
listener.onBallPlayerChat(event);
|
||||
@@ -139,7 +139,7 @@ public class BallChannelHandler extends SimpleChannelInboundHandler<String> {
|
||||
break;
|
||||
}
|
||||
case ServerOfflineEvent.ACTION: {
|
||||
ServerOfflineEvent event = CoreConstantObjects.GSON.fromJson(info.getContent(), ServerOfflineEvent.class);
|
||||
ServerOfflineEvent event = CoreUtils.GSON.fromJson(info.getContent(), ServerOfflineEvent.class);
|
||||
for (BallListener listener : BallAPI.getInstance().getListeners()) {
|
||||
try {
|
||||
listener.onServerOffline(event);
|
||||
@@ -150,7 +150,7 @@ public class BallChannelHandler extends SimpleChannelInboundHandler<String> {
|
||||
break;
|
||||
}
|
||||
case ServerOnlineEvent.ACTION: {
|
||||
ServerOnlineEvent event = CoreConstantObjects.GSON.fromJson(info.getContent(), ServerOnlineEvent.class);
|
||||
ServerOnlineEvent event = CoreUtils.GSON.fromJson(info.getContent(), ServerOnlineEvent.class);
|
||||
for (BallListener listener : BallAPI.getInstance().getListeners()) {
|
||||
try {
|
||||
listener.onServerOnline(event);
|
||||
|
@@ -1,6 +1,6 @@
|
||||
package cn.hamster3.mc.plugin.ball.common.data;
|
||||
|
||||
import cn.hamster3.mc.plugin.core.common.constant.CoreConstantObjects;
|
||||
import cn.hamster3.mc.plugin.core.common.util.CoreUtils;
|
||||
import com.google.gson.JsonElement;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
@@ -19,11 +19,11 @@ public class BallBlockPos {
|
||||
private int z;
|
||||
|
||||
public static BallBlockPos fromJson(String json) {
|
||||
return CoreConstantObjects.GSON.fromJson(json, BallBlockPos.class);
|
||||
return CoreUtils.GSON.fromJson(json, BallBlockPos.class);
|
||||
}
|
||||
|
||||
public JsonElement toJson() {
|
||||
return CoreConstantObjects.GSON.toJsonTree(this);
|
||||
return CoreUtils.GSON.toJsonTree(this);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
@@ -1,6 +1,6 @@
|
||||
package cn.hamster3.mc.plugin.ball.common.data;
|
||||
|
||||
import cn.hamster3.mc.plugin.core.common.constant.CoreConstantObjects;
|
||||
import cn.hamster3.mc.plugin.core.common.util.CoreUtils;
|
||||
import com.google.gson.JsonElement;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
@@ -22,11 +22,11 @@ public class BallLocation {
|
||||
private float pitch;
|
||||
|
||||
public static BallLocation fromJson(String json) {
|
||||
return CoreConstantObjects.GSON.fromJson(json, BallLocation.class);
|
||||
return CoreUtils.GSON.fromJson(json, BallLocation.class);
|
||||
}
|
||||
|
||||
public JsonElement toJson() {
|
||||
return CoreConstantObjects.GSON.toJsonTree(this);
|
||||
return CoreUtils.GSON.toJsonTree(this);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
@@ -2,7 +2,7 @@ package cn.hamster3.mc.plugin.ball.common.data;
|
||||
|
||||
import cn.hamster3.mc.plugin.ball.common.api.BallAPI;
|
||||
import cn.hamster3.mc.plugin.ball.common.entity.BallServerType;
|
||||
import cn.hamster3.mc.plugin.core.common.constant.CoreConstantObjects;
|
||||
import cn.hamster3.mc.plugin.core.common.util.CoreUtils;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
@@ -21,11 +21,6 @@ import java.util.UUID;
|
||||
@Data
|
||||
@SuppressWarnings("unused")
|
||||
public class BallMessageInfo {
|
||||
/**
|
||||
* 消息的频道
|
||||
*/
|
||||
@NotNull
|
||||
private String channel;
|
||||
/**
|
||||
* 消息发送者
|
||||
*/
|
||||
@@ -49,11 +44,17 @@ public class BallMessageInfo {
|
||||
*/
|
||||
@Nullable
|
||||
private BallServerType receiverType;
|
||||
/**
|
||||
* 消息的频道
|
||||
*/
|
||||
@NotNull
|
||||
private String channel;
|
||||
/**
|
||||
* 消息动作
|
||||
* <p>
|
||||
* 一般用这个来判断插件应该如何处理这条消息
|
||||
*/
|
||||
@NotNull
|
||||
private String action;
|
||||
/**
|
||||
* 消息内容
|
||||
@@ -62,34 +63,35 @@ public class BallMessageInfo {
|
||||
*/
|
||||
private JsonElement content;
|
||||
|
||||
public BallMessageInfo(@NotNull String channel, String action) {
|
||||
this.channel = channel;
|
||||
public BallMessageInfo(@NotNull String channel, @NotNull String action) {
|
||||
senderID = BallAPI.getInstance().getLocalServerId();
|
||||
this.channel = channel;
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
public BallMessageInfo(@NotNull String channel, String action, String content) {
|
||||
this.channel = channel;
|
||||
public BallMessageInfo(@NotNull String channel, @NotNull String action, String content) {
|
||||
senderID = BallAPI.getInstance().getLocalServerId();
|
||||
this.channel = channel;
|
||||
this.action = action;
|
||||
this.content = new JsonPrimitive(content);
|
||||
}
|
||||
|
||||
public BallMessageInfo(@NotNull String channel, String action, JsonElement content) {
|
||||
public BallMessageInfo(@NotNull String channel, @NotNull String action, JsonElement content) {
|
||||
this.channel = channel;
|
||||
senderID = BallAPI.getInstance().getLocalServerId();
|
||||
this.action = action;
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public BallMessageInfo(@NotNull String channel, String action, Object content) {
|
||||
public BallMessageInfo(@NotNull String channel, @NotNull String action, Object content) {
|
||||
this.channel = channel;
|
||||
senderID = BallAPI.getInstance().getLocalServerId();
|
||||
this.action = action;
|
||||
this.content = CoreConstantObjects.GSON.toJsonTree(content);
|
||||
this.content = CoreUtils.GSON.toJsonTree(content);
|
||||
}
|
||||
|
||||
public BallMessageInfo(@NotNull String channel, @NotNull String senderID, @Nullable String receiverID, @Nullable BallServerType receiverType, String action, JsonElement content) {
|
||||
public BallMessageInfo(@NotNull String channel, @NotNull String senderID, @Nullable String receiverID,
|
||||
@Nullable BallServerType receiverType, @NotNull String action, @Nullable JsonElement content) {
|
||||
this.channel = channel;
|
||||
this.senderID = senderID;
|
||||
this.receiverID = receiverID;
|
||||
@@ -126,8 +128,8 @@ public class BallMessageInfo {
|
||||
* @param <T> 对象类型
|
||||
* @return Java 对象
|
||||
*/
|
||||
public <T> T getContentAs(Class<T> clazz) {
|
||||
return CoreConstantObjects.GSON.fromJson(content, clazz);
|
||||
public <T> T getContentAs(@NotNull Class<T> clazz) {
|
||||
return CoreUtils.GSON.fromJson(content, clazz);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -135,6 +137,7 @@ public class BallMessageInfo {
|
||||
*
|
||||
* @return 消息内容
|
||||
*/
|
||||
@NotNull
|
||||
public String getContentAsString() {
|
||||
return content.getAsString();
|
||||
}
|
||||
@@ -151,14 +154,17 @@ public class BallMessageInfo {
|
||||
return content.getAsLong();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public BigInteger getContentAsBigInteger() {
|
||||
return content.getAsBigInteger();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public BigDecimal getContentAsBigDecimal() {
|
||||
return content.getAsBigDecimal();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public UUID getContentAsUUID() {
|
||||
return UUID.fromString(content.getAsString());
|
||||
}
|
||||
@@ -168,6 +174,7 @@ public class BallMessageInfo {
|
||||
*
|
||||
* @return 消息内容
|
||||
*/
|
||||
@NotNull
|
||||
public JsonObject getContentAsJsonObject() {
|
||||
return content.getAsJsonObject();
|
||||
}
|
||||
@@ -177,6 +184,7 @@ public class BallMessageInfo {
|
||||
*
|
||||
* @return 消息内容
|
||||
*/
|
||||
@NotNull
|
||||
public JsonArray getContentAsJsonArray() {
|
||||
return content.getAsJsonArray();
|
||||
}
|
||||
|
Reference in New Issue
Block a user