feat: 适配 HamsterCore 更新

This commit is contained in:
2023-08-21 00:23:06 +08:00
parent 2a11117b8c
commit 62d4b14492
6 changed files with 19 additions and 21 deletions

View File

@@ -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.util.CoreUtils;
import cn.hamster3.mc.plugin.core.common.api.CoreAPI;
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 CoreUtils.GSON.fromJson(json, BukkitBlockPos.class);
return CoreAPI.getInstance().getGson().fromJson(json, BukkitBlockPos.class);
}
@NotNull

View File

@@ -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.util.CoreUtils;
import cn.hamster3.mc.plugin.core.common.api.CoreAPI;
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 CoreUtils.GSON.fromJson(json, BukkitLocation.class);
return CoreAPI.getInstance().getGson().fromJson(json, BukkitLocation.class);
}
@NotNull

View File

@@ -10,7 +10,6 @@ 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.data.DisplayMessage;
import cn.hamster3.mc.plugin.core.common.util.CoreUtils;
import cn.hamster3.mc.plugin.core.lib.net.kyori.adventure.audience.Audience;
import cn.hamster3.mc.plugin.core.lib.net.kyori.adventure.text.TextReplacementConfig;
import lombok.AllArgsConstructor;
@@ -47,14 +46,14 @@ public class BallBukkitListener implements Listener, BallListener {
public void onMessageReceived(@NotNull BallMessageInfo info) {
switch (info.getAction()) {
case BroadcastPlayerMessageEvent.ACTION: {
BroadcastPlayerMessageEvent event = CoreUtils.GSON.fromJson(info.getContent(), BroadcastPlayerMessageEvent.class);
BroadcastPlayerMessageEvent event = CoreAPI.getInstance().getGson().fromJson(info.getContent(), BroadcastPlayerMessageEvent.class);
DisplayMessage message = event.getMessage();
Audience audience = CoreAPI.getInstance().getAudienceProvider().all();
message.show(audience);
break;
}
case DispatchConsoleCommandEvent.ACTION: {
DispatchConsoleCommandEvent event = CoreUtils.GSON.fromJson(info.getContent(), DispatchConsoleCommandEvent.class);
DispatchConsoleCommandEvent event = CoreAPI.getInstance().getGson().fromJson(info.getContent(), DispatchConsoleCommandEvent.class);
if (event.getType() != null && event.getType() != BallServerType.GAME) {
return;
}
@@ -65,7 +64,7 @@ public class BallBukkitListener implements Listener, BallListener {
break;
}
case DispatchPlayerCommandEvent.ACTION: {
DispatchPlayerCommandEvent event = CoreUtils.GSON.fromJson(info.getContent(), DispatchPlayerCommandEvent.class);
DispatchPlayerCommandEvent event = CoreAPI.getInstance().getGson().fromJson(info.getContent(), DispatchPlayerCommandEvent.class);
if (event.getType() != null && event.getType() != BallServerType.GAME) {
return;
}
@@ -83,7 +82,7 @@ public class BallBukkitListener implements Listener, BallListener {
break;
}
case SendPlayerToLocationEvent.ACTION: {
SendPlayerToLocationEvent event = CoreUtils.GSON.fromJson(info.getContent(), SendPlayerToLocationEvent.class);
SendPlayerToLocationEvent event = CoreAPI.getInstance().getGson().fromJson(info.getContent(), SendPlayerToLocationEvent.class);
BukkitLocation location = new BukkitLocation(event.getLocation());
if (BallAPI.getInstance().isLocalServer(location.getServerID())) {
for (UUID uuid : event.getSendPlayerUUID()) {
@@ -104,7 +103,7 @@ public class BallBukkitListener implements Listener, BallListener {
break;
}
case SendPlayerToPlayerEvent.ACTION: {
SendPlayerToPlayerEvent event = CoreUtils.GSON.fromJson(info.getContent(), SendPlayerToPlayerEvent.class);
SendPlayerToPlayerEvent event = CoreAPI.getInstance().getGson().fromJson(info.getContent(), SendPlayerToPlayerEvent.class);
Player toPlayer = Bukkit.getPlayer(event.getToPlayerUUID());
if (toPlayer == null) {
break;
@@ -200,7 +199,7 @@ public class BallBukkitListener implements Listener, BallListener {
statement.setString(1, uuid.toString());
try (ResultSet set = statement.executeQuery()) {
while (set.next()) {
DisplayMessage msg = CoreUtils.GSON.fromJson(set.getString("message"), DisplayMessage.class);
DisplayMessage msg = CoreAPI.getInstance().getGson().fromJson(set.getString("message"), DisplayMessage.class);
list.add(msg);
}
}