style: 优化代码

This commit is contained in:
2023-10-13 17:15:19 +08:00
parent 19bac34bfb
commit 433b6f2c05
6 changed files with 12 additions and 14 deletions

View File

@@ -39,6 +39,7 @@ public abstract class BallAPI {
/** /**
* API 实例 * API 实例
*/ */
@Getter
protected static BallAPI instance; protected static BallAPI instance;
@NotNull @NotNull
protected final Map<String, BallServerInfo> serverInfo; protected final Map<String, BallServerInfo> serverInfo;
@@ -131,15 +132,6 @@ public abstract class BallAPI {
enabled = false; enabled = false;
} }
/**
* 获取 API 实例
*
* @return API 实例
*/
public static BallAPI getInstance() {
return instance;
}
protected void enable() throws SQLException, InterruptedException { protected void enable() throws SQLException, InterruptedException {
if (enabled) { if (enabled) {
return; return;

View File

@@ -10,10 +10,8 @@ import org.jetbrains.annotations.NotNull;
public class BallConfig { public class BallConfig {
@NotNull @NotNull
private BallServerInfo localInfo; private BallServerInfo localInfo;
@NotNull @NotNull
private String host; private String host;
private int port; private int port;
private int eventLoopThread; private int eventLoopThread;
} }

View File

@@ -12,16 +12,19 @@ import org.jetbrains.annotations.NotNull;
@AllArgsConstructor @AllArgsConstructor
@SuppressWarnings("unused") @SuppressWarnings("unused")
public class BallBlockPos { public class BallBlockPos {
@NotNull
private String serverID; private String serverID;
@NotNull
private String worldName; private String worldName;
private int x; private int x;
private int y; private int y;
private int z; private int z;
public static BallBlockPos fromJson(String json) { public static BallBlockPos fromJson(@NotNull String json) {
return CoreAPI.getInstance().getGson().fromJson(json, BallBlockPos.class); return CoreAPI.getInstance().getGson().fromJson(json, BallBlockPos.class);
} }
@NotNull
public JsonElement toJson() { public JsonElement toJson() {
return CoreAPI.getInstance().getGson().toJsonTree(this); return CoreAPI.getInstance().getGson().toJsonTree(this);
} }

View File

@@ -12,7 +12,9 @@ import org.jetbrains.annotations.NotNull;
@AllArgsConstructor @AllArgsConstructor
@SuppressWarnings("unused") @SuppressWarnings("unused")
public class BallLocation { public class BallLocation {
@NotNull
private String serverID; private String serverID;
@NotNull
private String worldName; private String worldName;
private double x; private double x;
private double y; private double y;
@@ -21,10 +23,11 @@ public class BallLocation {
private float yaw; private float yaw;
private float pitch; private float pitch;
public static BallLocation fromJson(String json) { public static BallLocation fromJson(@NotNull String json) {
return CoreAPI.getInstance().getGson().fromJson(json, BallLocation.class); return CoreAPI.getInstance().getGson().fromJson(json, BallLocation.class);
} }
@NotNull
public JsonElement toJson() { public JsonElement toJson() {
return CoreAPI.getInstance().getGson().toJsonTree(this); return CoreAPI.getInstance().getGson().toJsonTree(this);
} }

View File

@@ -113,6 +113,7 @@ public class BallMessageInfo {
* @param <T> 对象类型 * @param <T> 对象类型
* @return Java 对象 * @return Java 对象
*/ */
@NotNull
public <T> T getContentAs(@NotNull Class<T> clazz) { public <T> T getContentAs(@NotNull Class<T> clazz) {
return CoreAPI.getInstance().getGson().fromJson(content, clazz); return CoreAPI.getInstance().getGson().fromJson(content, clazz);
} }

View File

@@ -2,6 +2,7 @@ package cn.hamster3.mc.plugin.ball.common.entity;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.util.UUID; import java.util.UUID;
@@ -10,7 +11,7 @@ import java.util.UUID;
* 玩家信息 * 玩家信息
*/ */
@Data @Data
@NotNull @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
public class BallPlayerInfo { public class BallPlayerInfo {
/** /**