feat: 适配 HamsterCore 更新

This commit is contained in:
2023-08-20 22:50:35 +08:00
parent b45ef40af2
commit 6aac1fafd6
8 changed files with 30 additions and 40 deletions

View File

@@ -14,8 +14,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.BallMessageListener;
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.data.DisplayMessage;
import cn.hamster3.mc.plugin.core.common.util.CoreUtils;
import cn.hamster3.mc.plugin.core.lib.net.kyori.adventure.text.Component;
import lombok.Getter;
import org.jetbrains.annotations.NotNull;
@@ -277,7 +277,7 @@ public abstract class BallAPI {
null,
BallServerType.PROXY,
BroadcastPlayerMessageEvent.ACTION,
CoreUtils.GSON.toJsonTree(
CoreAPI.getInstance().getGson().toJsonTree(
new BroadcastPlayerMessageEvent(message)
)
));
@@ -297,7 +297,7 @@ public abstract class BallAPI {
null,
BallServerType.GAME,
DispatchConsoleCommandEvent.ACTION,
CoreUtils.GSON.toJsonTree(
CoreAPI.getInstance().getGson().toJsonTree(
new DispatchConsoleCommandEvent(type, serverID, command)
)
));
@@ -317,7 +317,7 @@ public abstract class BallAPI {
null,
BallServerType.GAME,
DispatchPlayerCommandEvent.ACTION,
CoreUtils.GSON.toJsonTree(
CoreAPI.getInstance().getGson().toJsonTree(
new DispatchPlayerCommandEvent(type, uuid, command)
)
));
@@ -346,7 +346,7 @@ public abstract class BallAPI {
null,
BallServerType.PROXY,
KickPlayerEvent.ACTION,
CoreUtils.GSON.toJsonTree(
CoreAPI.getInstance().getGson().toJsonTree(
new KickPlayerEvent(uuid, reason)
)
));
@@ -384,7 +384,7 @@ public abstract class BallAPI {
null,
BallServerType.PROXY,
SendMessageToPlayerEvent.ACTION,
CoreUtils.GSON.toJsonTree(
CoreAPI.getInstance().getGson().toJsonTree(
new SendMessageToPlayerEvent(Collections.singleton(receiver), message)
)
));
@@ -423,7 +423,7 @@ public abstract class BallAPI {
null,
BallServerType.PROXY,
SendMessageToPlayerEvent.ACTION,
CoreUtils.GSON.toJsonTree(
CoreAPI.getInstance().getGson().toJsonTree(
new SendMessageToPlayerEvent(new HashSet<>(receivers), message)
)
));
@@ -540,7 +540,7 @@ public abstract class BallAPI {
* @param block 是否阻塞(设置为 true 则必须等待消息写入网络的操作完成后,该方法才会退出)
*/
public void sendBallMessage(@NotNull BallMessageInfo messageInfo, boolean block) {
String string = CoreUtils.GSON.toJson(messageInfo);
String string = CoreAPI.getInstance().getGson().toJson(messageInfo);
RTopic topic = getRedissonClient().getTopic(BallAPI.BALL_CHANNEL, StringCodec.INSTANCE);
if (block) {
topic.publish(string);

View File

@@ -1,7 +1,7 @@
package cn.hamster3.mc.plugin.ball.common.codec;
import cn.hamster3.mc.plugin.ball.common.data.BallMessageInfo;
import cn.hamster3.mc.plugin.core.common.util.CoreUtils;
import cn.hamster3.mc.plugin.core.common.api.CoreAPI;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import io.netty.util.CharsetUtil;
@@ -22,7 +22,7 @@ public class BallMessageInfoCodec extends BaseCodec implements JsonCodec<BallMes
private final Decoder<Object> decoder = (buf, state) -> {
String str = buf.toString(CharsetUtil.UTF_8);
buf.readerIndex(buf.readableBytes());
return CoreUtils.GSON.fromJson(str, BallMessageInfo.class);
return CoreAPI.getInstance().getGson().fromJson(str, BallMessageInfo.class);
};
private BallMessageInfoCodec() {

View File

@@ -1,6 +1,6 @@
package cn.hamster3.mc.plugin.ball.common.data;
import cn.hamster3.mc.plugin.core.common.util.CoreUtils;
import cn.hamster3.mc.plugin.core.common.api.CoreAPI;
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 CoreUtils.GSON.fromJson(json, BallBlockPos.class);
return CoreAPI.getInstance().getGson().fromJson(json, BallBlockPos.class);
}
public JsonElement toJson() {
return CoreUtils.GSON.toJsonTree(this);
return CoreAPI.getInstance().getGson().toJsonTree(this);
}
@NotNull

View File

@@ -1,6 +1,6 @@
package cn.hamster3.mc.plugin.ball.common.data;
import cn.hamster3.mc.plugin.core.common.util.CoreUtils;
import cn.hamster3.mc.plugin.core.common.api.CoreAPI;
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 CoreUtils.GSON.fromJson(json, BallLocation.class);
return CoreAPI.getInstance().getGson().fromJson(json, BallLocation.class);
}
public JsonElement toJson() {
return CoreUtils.GSON.toJsonTree(this);
return CoreAPI.getInstance().getGson().toJsonTree(this);
}
@NotNull

View File

@@ -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.util.CoreUtils;
import cn.hamster3.mc.plugin.core.common.api.CoreAPI;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
@@ -72,7 +72,7 @@ public class BallMessageInfo {
this.channel = channel;
senderID = BallAPI.getInstance().getLocalServerId();
this.action = action;
this.content = CoreUtils.GSON.toJsonTree(content);
this.content = CoreAPI.getInstance().getGson().toJsonTree(content);
}
public BallMessageInfo(@NotNull String channel, @NotNull String senderID, @Nullable String receiverID,
@@ -114,7 +114,7 @@ public class BallMessageInfo {
* @return Java 对象
*/
public <T> T getContentAs(@NotNull Class<T> clazz) {
return CoreUtils.GSON.fromJson(content, clazz);
return CoreAPI.getInstance().getGson().fromJson(content, clazz);
}
/**

View File

@@ -5,7 +5,7 @@ import cn.hamster3.mc.plugin.ball.common.data.BallMessageInfo;
import cn.hamster3.mc.plugin.ball.common.event.player.*;
import cn.hamster3.mc.plugin.ball.common.event.server.ServerOfflineEvent;
import cn.hamster3.mc.plugin.ball.common.event.server.ServerOnlineEvent;
import cn.hamster3.mc.plugin.core.common.util.CoreUtils;
import cn.hamster3.mc.plugin.core.common.api.CoreAPI;
import org.redisson.api.listener.MessageListener;
public class BallMessageListener implements MessageListener<BallMessageInfo> {
@@ -28,7 +28,7 @@ public class BallMessageListener implements MessageListener<BallMessageInfo> {
}
switch (info.getAction()) {
case BallPlayerPreLoginEvent.ACTION: {
BallPlayerPreLoginEvent event = CoreUtils.GSON.fromJson(info.getContent(), BallPlayerPreLoginEvent.class);
BallPlayerPreLoginEvent event = CoreAPI.getInstance().getGson().fromJson(info.getContent(), BallPlayerPreLoginEvent.class);
for (BallListener listener : BallAPI.getInstance().getListeners()) {
try {
listener.onBallPlayerPreLogin(event);
@@ -39,7 +39,7 @@ public class BallMessageListener implements MessageListener<BallMessageInfo> {
break;
}
case BallPlayerLoginEvent.ACTION: {
BallPlayerLoginEvent event = CoreUtils.GSON.fromJson(info.getContent(), BallPlayerLoginEvent.class);
BallPlayerLoginEvent event = CoreAPI.getInstance().getGson().fromJson(info.getContent(), BallPlayerLoginEvent.class);
for (BallListener listener : BallAPI.getInstance().getListeners()) {
try {
listener.onBallPlayerLogin(event);
@@ -50,7 +50,7 @@ public class BallMessageListener implements MessageListener<BallMessageInfo> {
break;
}
case BallPlayerPostLoginEvent.ACTION: {
BallPlayerPostLoginEvent event = CoreUtils.GSON.fromJson(info.getContent(), BallPlayerPostLoginEvent.class);
BallPlayerPostLoginEvent event = CoreAPI.getInstance().getGson().fromJson(info.getContent(), BallPlayerPostLoginEvent.class);
for (BallListener listener : BallAPI.getInstance().getListeners()) {
try {
listener.onBallPlayerPostLogin(event);
@@ -61,7 +61,7 @@ public class BallMessageListener implements MessageListener<BallMessageInfo> {
break;
}
case BallPlayerPreConnectServerEvent.ACTION: {
BallPlayerPreConnectServerEvent event = CoreUtils.GSON.fromJson(info.getContent(), BallPlayerPreConnectServerEvent.class);
BallPlayerPreConnectServerEvent event = CoreAPI.getInstance().getGson().fromJson(info.getContent(), BallPlayerPreConnectServerEvent.class);
for (BallListener listener : BallAPI.getInstance().getListeners()) {
try {
listener.onBallPlayerPreConnectServer(event);
@@ -72,7 +72,7 @@ public class BallMessageListener implements MessageListener<BallMessageInfo> {
break;
}
case BallPlayerConnectServerEvent.ACTION: {
BallPlayerConnectServerEvent event = CoreUtils.GSON.fromJson(info.getContent(), BallPlayerConnectServerEvent.class);
BallPlayerConnectServerEvent event = CoreAPI.getInstance().getGson().fromJson(info.getContent(), BallPlayerConnectServerEvent.class);
for (BallListener listener : BallAPI.getInstance().getListeners()) {
try {
listener.onBallPlayerConnectServer(event);
@@ -83,7 +83,7 @@ public class BallMessageListener implements MessageListener<BallMessageInfo> {
break;
}
case BallPlayerPostConnectServerEvent.ACTION: {
BallPlayerPostConnectServerEvent event = CoreUtils.GSON.fromJson(info.getContent(), BallPlayerPostConnectServerEvent.class);
BallPlayerPostConnectServerEvent event = CoreAPI.getInstance().getGson().fromJson(info.getContent(), BallPlayerPostConnectServerEvent.class);
for (BallListener listener : BallAPI.getInstance().getListeners()) {
try {
listener.onBallPlayerPostConnectServer(event);
@@ -94,7 +94,7 @@ public class BallMessageListener implements MessageListener<BallMessageInfo> {
break;
}
case BallPlayerLogoutEvent.ACTION: {
BallPlayerLogoutEvent event = CoreUtils.GSON.fromJson(info.getContent(), BallPlayerLogoutEvent.class);
BallPlayerLogoutEvent event = CoreAPI.getInstance().getGson().fromJson(info.getContent(), BallPlayerLogoutEvent.class);
for (BallListener listener : BallAPI.getInstance().getListeners()) {
try {
listener.onBallPlayerLogout(event);
@@ -105,7 +105,7 @@ public class BallMessageListener implements MessageListener<BallMessageInfo> {
break;
}
case BallPlayerInfoUpdateEvent.ACTION: {
BallPlayerInfoUpdateEvent event = CoreUtils.GSON.fromJson(info.getContent(), BallPlayerInfoUpdateEvent.class);
BallPlayerInfoUpdateEvent event = CoreAPI.getInstance().getGson().fromJson(info.getContent(), BallPlayerInfoUpdateEvent.class);
for (BallListener listener : BallAPI.getInstance().getListeners()) {
try {
listener.onBallPlayerInfoUpdate(event);
@@ -116,7 +116,7 @@ public class BallMessageListener implements MessageListener<BallMessageInfo> {
break;
}
case ServerOfflineEvent.ACTION: {
ServerOfflineEvent event = CoreUtils.GSON.fromJson(info.getContent(), ServerOfflineEvent.class);
ServerOfflineEvent event = CoreAPI.getInstance().getGson().fromJson(info.getContent(), ServerOfflineEvent.class);
for (BallListener listener : BallAPI.getInstance().getListeners()) {
try {
listener.onServerOffline(event);
@@ -127,7 +127,7 @@ public class BallMessageListener implements MessageListener<BallMessageInfo> {
break;
}
case ServerOnlineEvent.ACTION: {
ServerOnlineEvent event = CoreUtils.GSON.fromJson(info.getContent(), ServerOnlineEvent.class);
ServerOnlineEvent event = CoreAPI.getInstance().getGson().fromJson(info.getContent(), ServerOnlineEvent.class);
for (BallListener listener : BallAPI.getInstance().getListeners()) {
try {
listener.onServerOnline(event);