feat: 添加工具方法
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package cn.hamster3.mc.plugin.ball.common.data;
|
||||
|
||||
import cn.hamster3.mc.plugin.core.common.constant.CoreConstantObjects;
|
||||
import com.google.gson.JsonElement;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
@@ -16,6 +18,14 @@ public class BallBlockPos {
|
||||
private int y;
|
||||
private int z;
|
||||
|
||||
public static BallBlockPos fromJson(String json) {
|
||||
return CoreConstantObjects.GSON.fromJson(json, BallBlockPos.class);
|
||||
}
|
||||
|
||||
public JsonElement toJson() {
|
||||
return CoreConstantObjects.GSON.toJsonTree(this);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public BallLocation toServiceLocation() {
|
||||
return new BallLocation(getServerID(), getWorldName(), getX(), getY(), getZ(), 0, 0);
|
||||
|
@@ -1,5 +1,7 @@
|
||||
package cn.hamster3.mc.plugin.ball.common.data;
|
||||
|
||||
import cn.hamster3.mc.plugin.core.common.constant.CoreConstantObjects;
|
||||
import com.google.gson.JsonElement;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
@@ -19,6 +21,19 @@ public class BallLocation {
|
||||
private float yaw;
|
||||
private float pitch;
|
||||
|
||||
public static BallLocation fromJson(String json) {
|
||||
return CoreConstantObjects.GSON.fromJson(json, BallLocation.class);
|
||||
}
|
||||
|
||||
public JsonElement toJson() {
|
||||
return CoreConstantObjects.GSON.toJsonTree(this);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public BallBlockPos toServiceBlockPos() {
|
||||
return new BallBlockPos(getServerID(), getWorldName(), getBlockX(), getBlockY(), getBlockZ());
|
||||
}
|
||||
|
||||
public int getBlockX() {
|
||||
return (int) x;
|
||||
}
|
||||
@@ -30,9 +45,4 @@ public class BallLocation {
|
||||
public int getBlockZ() {
|
||||
return (int) z;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public BallBlockPos toServiceBlockPos() {
|
||||
return new BallBlockPos(getServerID(), getWorldName(), getBlockX(), getBlockY(), getBlockZ());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user