feat: 添加工具方法
This commit is contained in:
@@ -2,6 +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.api.BallAPI;
|
||||||
import cn.hamster3.mc.plugin.ball.common.data.BallBlockPos;
|
import cn.hamster3.mc.plugin.ball.common.data.BallBlockPos;
|
||||||
|
import cn.hamster3.mc.plugin.core.common.constant.CoreConstantObjects;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
@@ -42,6 +43,10 @@ public class BukkitBlockPos extends BallBlockPos {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static BukkitBlockPos fromJson(String json) {
|
||||||
|
return CoreConstantObjects.GSON.fromJson(json, BukkitBlockPos.class);
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Location toBukkitLocation() {
|
public Location toBukkitLocation() {
|
||||||
return new Location(Bukkit.getWorld(getWorldName()), getX(), getY(), getZ(), 0, 0);
|
return new Location(Bukkit.getWorld(getWorldName()), getX(), getY(), getZ(), 0, 0);
|
||||||
|
@@ -2,6 +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.api.BallAPI;
|
||||||
import cn.hamster3.mc.plugin.ball.common.data.BallLocation;
|
import cn.hamster3.mc.plugin.ball.common.data.BallLocation;
|
||||||
|
import cn.hamster3.mc.plugin.core.common.constant.CoreConstantObjects;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
@@ -50,6 +51,10 @@ public class BukkitLocation extends BallLocation {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static BukkitLocation fromJson(String json) {
|
||||||
|
return CoreConstantObjects.GSON.fromJson(json, BukkitLocation.class);
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Location toBukkitLocation() {
|
public Location toBukkitLocation() {
|
||||||
return new Location(Bukkit.getWorld(getWorldName()), getX(), getY(), getZ(), getYaw(), getPitch());
|
return new Location(Bukkit.getWorld(getWorldName()), getX(), getY(), getZ(), getYaw(), getPitch());
|
||||||
|
@@ -1,5 +1,7 @@
|
|||||||
package cn.hamster3.mc.plugin.ball.common.data;
|
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.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
@@ -16,6 +18,14 @@ public class BallBlockPos {
|
|||||||
private int y;
|
private int y;
|
||||||
private int z;
|
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
|
@NotNull
|
||||||
public BallLocation toServiceLocation() {
|
public BallLocation toServiceLocation() {
|
||||||
return new BallLocation(getServerID(), getWorldName(), getX(), getY(), getZ(), 0, 0);
|
return new BallLocation(getServerID(), getWorldName(), getX(), getY(), getZ(), 0, 0);
|
||||||
|
@@ -1,5 +1,7 @@
|
|||||||
package cn.hamster3.mc.plugin.ball.common.data;
|
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.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
@@ -19,6 +21,19 @@ public class BallLocation {
|
|||||||
private float yaw;
|
private float yaw;
|
||||||
private float pitch;
|
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() {
|
public int getBlockX() {
|
||||||
return (int) x;
|
return (int) x;
|
||||||
}
|
}
|
||||||
@@ -30,9 +45,4 @@ public class BallLocation {
|
|||||||
public int getBlockZ() {
|
public int getBlockZ() {
|
||||||
return (int) z;
|
return (int) z;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public BallBlockPos toServiceBlockPos() {
|
|
||||||
return new BallBlockPos(getServerID(), getWorldName(), getBlockX(), getBlockY(), getBlockZ());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user