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

View File

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

View File

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

View File

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

View File

@@ -113,6 +113,7 @@ public class BallMessageInfo {
* @param <T> 对象类型
* @return Java 对象
*/
@NotNull
public <T> T getContentAs(@NotNull Class<T> 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.Data;
import lombok.NoArgsConstructor;
import org.jetbrains.annotations.NotNull;
import java.util.UUID;
@@ -10,7 +11,7 @@ import java.util.UUID;
* 玩家信息
*/
@Data
@NotNull
@NoArgsConstructor
@AllArgsConstructor
public class BallPlayerInfo {
/**