mirror of
https://github.com/ColdeZhang/Dominion.git
synced 2024-10-19 02:46:49 +08:00
优化dominion dto内容结构,将原始变量合并到Field中
This commit is contained in:
parent
6f0b97f458
commit
abab7967b0
@ -5,6 +5,7 @@ import cn.lunadeer.dominion.Dominion;
|
|||||||
import cn.lunadeer.minecraftpluginutils.XLogger;
|
import cn.lunadeer.minecraftpluginutils.XLogger;
|
||||||
import cn.lunadeer.minecraftpluginutils.databse.DatabaseManager;
|
import cn.lunadeer.minecraftpluginutils.databse.DatabaseManager;
|
||||||
import cn.lunadeer.minecraftpluginutils.databse.Field;
|
import cn.lunadeer.minecraftpluginutils.databse.Field;
|
||||||
|
import cn.lunadeer.minecraftpluginutils.databse.FieldType;
|
||||||
import cn.lunadeer.minecraftpluginutils.databse.syntax.InsertRow;
|
import cn.lunadeer.minecraftpluginutils.databse.syntax.InsertRow;
|
||||||
import cn.lunadeer.minecraftpluginutils.databse.syntax.UpdateRow;
|
import cn.lunadeer.minecraftpluginutils.databse.syntax.UpdateRow;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
@ -118,22 +119,15 @@ public class DominionDTO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static DominionDTO insert(DominionDTO dominion) {
|
public static DominionDTO insert(DominionDTO dominion) {
|
||||||
Field owner = new Field("owner", dominion.getOwner().toString());
|
|
||||||
Field name = new Field("name", dominion.getName());
|
|
||||||
Field world = new Field("world", dominion.getWorld());
|
|
||||||
Field x1 = new Field("x1", dominion.getX1());
|
|
||||||
Field y1 = new Field("y1", dominion.getY1());
|
|
||||||
Field z1 = new Field("z1", dominion.getZ1());
|
|
||||||
Field x2 = new Field("x2", dominion.getX2());
|
|
||||||
Field y2 = new Field("y2", dominion.getY2());
|
|
||||||
Field z2 = new Field("z2", dominion.getZ2());
|
|
||||||
Field parentDomId = new Field("parent_dom_id", dominion.getParentDomId());
|
|
||||||
Field joinMessage = new Field("join_message", "欢迎来到 ${DOM_NAME}!");
|
|
||||||
Field leaveMessage = new Field("leave_message", "你正在离开 ${DOM_NAME},欢迎下次光临~");
|
|
||||||
Field tpLocation = new Field("tp_location", "default");
|
|
||||||
InsertRow insert = new InsertRow().returningAll().table("dominion").onConflictDoNothing(new Field("id", null));
|
InsertRow insert = new InsertRow().returningAll().table("dominion").onConflictDoNothing(new Field("id", null));
|
||||||
insert.field(owner).field(name).field(world).field(x1).field(y1).field(z1).field(x2).field(y2).field(z2)
|
insert.field(dominion.owner)
|
||||||
.field(parentDomId).field(joinMessage).field(leaveMessage).field(tpLocation);
|
.field(dominion.name)
|
||||||
|
.field(dominion.world)
|
||||||
|
.field(dominion.x1).field(dominion.y1).field(dominion.z1)
|
||||||
|
.field(dominion.x2).field(dominion.y2).field(dominion.z2)
|
||||||
|
.field(dominion.parentDomId)
|
||||||
|
.field(dominion.joinMessage).field(dominion.leaveMessage)
|
||||||
|
.field(dominion.tp_location);
|
||||||
for (Flag f : Flag.getDominionFlagsEnabled()) {
|
for (Flag f : Flag.getDominionFlagsEnabled()) {
|
||||||
insert.field(new Field(f.getFlagName(), f.getDefaultValue()));
|
insert.field(new Field(f.getFlagName(), f.getDefaultValue()));
|
||||||
}
|
}
|
||||||
@ -160,39 +154,39 @@ public class DominionDTO {
|
|||||||
Map<Flag, Boolean> flags,
|
Map<Flag, Boolean> flags,
|
||||||
String tp_location,
|
String tp_location,
|
||||||
String color) {
|
String color) {
|
||||||
this.id = id;
|
this.id.value = id;
|
||||||
this.owner = owner;
|
this.owner.value = owner;
|
||||||
this.name = name;
|
this.name.value = name;
|
||||||
this.world = world;
|
this.world.value = world;
|
||||||
this.x1 = x1;
|
this.x1.value = x1;
|
||||||
this.y1 = y1;
|
this.y1.value = y1;
|
||||||
this.z1 = z1;
|
this.z1.value = z1;
|
||||||
this.x2 = x2;
|
this.x2.value = x2;
|
||||||
this.y2 = y2;
|
this.y2.value = y2;
|
||||||
this.z2 = z2;
|
this.z2.value = z2;
|
||||||
this.parentDomId = parentDomId;
|
this.parentDomId.value = parentDomId;
|
||||||
this.joinMessage = joinMessage;
|
this.joinMessage.value = joinMessage;
|
||||||
this.leaveMessage = leaveMessage;
|
this.leaveMessage.value = leaveMessage;
|
||||||
this.flags.putAll(flags);
|
this.flags.putAll(flags);
|
||||||
this.tp_location = tp_location;
|
this.tp_location.value = tp_location;
|
||||||
this.color = color;
|
this.color.value = color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private DominionDTO(Integer id, UUID owner, String name, String world,
|
private DominionDTO(Integer id, UUID owner, String name, String world,
|
||||||
Integer x1, Integer y1, Integer z1, Integer x2, Integer y2, Integer z2,
|
Integer x1, Integer y1, Integer z1, Integer x2, Integer y2, Integer z2,
|
||||||
Integer parentDomId) {
|
Integer parentDomId) {
|
||||||
this.id = id;
|
this.id.value = id;
|
||||||
this.owner = owner;
|
this.owner.value = owner;
|
||||||
this.name = name;
|
this.name.value = name;
|
||||||
this.world = world;
|
this.world.value = world;
|
||||||
this.x1 = x1;
|
this.x1.value = x1;
|
||||||
this.y1 = y1;
|
this.y1.value = y1;
|
||||||
this.z1 = z1;
|
this.z1.value = z1;
|
||||||
this.x2 = x2;
|
this.x2.value = x2;
|
||||||
this.y2 = y2;
|
this.y2.value = y2;
|
||||||
this.z2 = z2;
|
this.z2.value = z2;
|
||||||
this.parentDomId = parentDomId;
|
this.parentDomId.value = parentDomId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DominionDTO(UUID owner, String name, String world,
|
public DominionDTO(UUID owner, String name, String world,
|
||||||
@ -200,30 +194,31 @@ public class DominionDTO {
|
|||||||
this(null, owner, name, world, x1, y1, z1, x2, y2, z2, -1);
|
this(null, owner, name, world, x1, y1, z1, x2, y2, z2, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Integer id;
|
private final Field id = new Field("id", FieldType.INT);
|
||||||
private UUID owner;
|
private final Field owner = new Field("owner", FieldType.STRING);
|
||||||
private String name;
|
private final Field name = new Field("name", FieldType.STRING);
|
||||||
private final String world;
|
private final Field world = new Field("world", FieldType.STRING);
|
||||||
private Integer x1;
|
private final Field x1 = new Field("x1", FieldType.INT);
|
||||||
private Integer y1;
|
private final Field y1 = new Field("y1", FieldType.INT);
|
||||||
private Integer z1;
|
private final Field z1 = new Field("z1", FieldType.INT);
|
||||||
private Integer x2;
|
private final Field x2 = new Field("x2", FieldType.INT);
|
||||||
private Integer y2;
|
private final Field y2 = new Field("y2", FieldType.INT);
|
||||||
private Integer z2;
|
private final Field z2 = new Field("z2", FieldType.INT);
|
||||||
private Integer parentDomId = -1;
|
private final Field parentDomId = new Field("parent_dom_id", -1);
|
||||||
private String joinMessage = "欢迎";
|
private final Field joinMessage = new Field("join_message", "欢迎来到 ${DOM_NAME}!");
|
||||||
private String leaveMessage = "再见";
|
private final Field leaveMessage = new Field("leave_message", "你正在离开 ${DOM_NAME},欢迎下次光临~");
|
||||||
private final Map<Flag, Boolean> flags = new HashMap<>();
|
private final Map<Flag, Boolean> flags = new HashMap<>();
|
||||||
private String tp_location;
|
private final Field tp_location = new Field("tp_location", "default");
|
||||||
private String color;
|
private final Field color = new Field("color", "#00BFFF");
|
||||||
|
|
||||||
|
|
||||||
// getters and setters
|
// getters and setters
|
||||||
public Integer getId() {
|
public Integer getId() {
|
||||||
return id;
|
return (Integer) id.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public UUID getOwner() {
|
public UUID getOwner() {
|
||||||
return owner;
|
return UUID.fromString((String) owner.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
private DominionDTO doUpdate(UpdateRow updateRow) {
|
private DominionDTO doUpdate(UpdateRow updateRow) {
|
||||||
@ -243,133 +238,122 @@ public class DominionDTO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public DominionDTO setOwner(UUID owner) {
|
public DominionDTO setOwner(UUID owner) {
|
||||||
this.owner = owner;
|
this.owner.value = owner.toString();
|
||||||
Field ownerField = new Field("owner", owner.toString());
|
return doUpdate(new UpdateRow().field(this.owner));
|
||||||
return doUpdate(new UpdateRow().field(ownerField));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return (String) name.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DominionDTO setName(String name) {
|
public DominionDTO setName(String name) {
|
||||||
this.name = name;
|
this.name.value = name;
|
||||||
Field nameField = new Field("name", name);
|
return doUpdate(new UpdateRow().field(this.name));
|
||||||
return doUpdate(new UpdateRow().field(nameField));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getWorld() {
|
public String getWorld() {
|
||||||
return world;
|
return (String) world.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getX1() {
|
public Integer getX1() {
|
||||||
return x1;
|
return (Integer) x1.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DominionDTO setX1(Integer x1) {
|
public DominionDTO setX1(Integer x1) {
|
||||||
this.x1 = x1;
|
this.x1.value = x1;
|
||||||
Field x1Field = new Field("x1", x1);
|
return doUpdate(new UpdateRow().field(this.x1));
|
||||||
return doUpdate(new UpdateRow().field(x1Field));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getY1() {
|
public Integer getY1() {
|
||||||
return y1;
|
return (Integer) y1.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DominionDTO setY1(Integer y1) {
|
public DominionDTO setY1(Integer y1) {
|
||||||
this.y1 = y1;
|
this.y1.value = y1;
|
||||||
Field y1Field = new Field("y1", y1);
|
return doUpdate(new UpdateRow().field(this.y1));
|
||||||
return doUpdate(new UpdateRow().field(y1Field));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getZ1() {
|
public Integer getZ1() {
|
||||||
return z1;
|
return (Integer) z1.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DominionDTO setZ1(Integer z1) {
|
public DominionDTO setZ1(Integer z1) {
|
||||||
this.z1 = z1;
|
this.z1.value = z1;
|
||||||
Field z1Field = new Field("z1", z1);
|
return doUpdate(new UpdateRow().field(this.z1));
|
||||||
return doUpdate(new UpdateRow().field(z1Field));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getX2() {
|
public Integer getX2() {
|
||||||
return x2;
|
return (Integer) x2.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DominionDTO setX2(Integer x2) {
|
public DominionDTO setX2(Integer x2) {
|
||||||
this.x2 = x2;
|
this.x2.value = x2;
|
||||||
Field x2Field = new Field("x2", x2);
|
return doUpdate(new UpdateRow().field(this.x2));
|
||||||
return doUpdate(new UpdateRow().field(x2Field));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getY2() {
|
public Integer getY2() {
|
||||||
return y2;
|
return (Integer) y2.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DominionDTO setY2(Integer y2) {
|
public DominionDTO setY2(Integer y2) {
|
||||||
this.y2 = y2;
|
this.y2.value = y2;
|
||||||
Field y2Field = new Field("y2", y2);
|
return doUpdate(new UpdateRow().field(this.y2));
|
||||||
return doUpdate(new UpdateRow().field(y2Field));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getZ2() {
|
public Integer getZ2() {
|
||||||
return z2;
|
return (Integer) z2.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DominionDTO setZ2(Integer z2) {
|
public DominionDTO setZ2(Integer z2) {
|
||||||
this.z2 = z2;
|
this.z2.value = z2;
|
||||||
Field z2Field = new Field("z2", z2);
|
return doUpdate(new UpdateRow().field(this.z2));
|
||||||
return doUpdate(new UpdateRow().field(z2Field));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getSquare() {
|
public Integer getSquare() {
|
||||||
return (x2 - x1 + 1) * (z2 - z1 + 1);
|
return (getX2() - getX1() + 1) * (getZ2() - getZ1() + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getVolume() {
|
public Integer getVolume() {
|
||||||
return getSquare() * (y2 - y1 + 1);
|
return getSquare() * (getY2() - getY1() + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getWidthX() {
|
public Integer getWidthX() {
|
||||||
return x2 - x1 + 1;
|
return getX2() - getX1() + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getHeight() {
|
public Integer getHeight() {
|
||||||
return y2 - y1 + 1;
|
return getY2() - getY1() + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getWidthZ() {
|
public Integer getWidthZ() {
|
||||||
return z2 - z1 + 1;
|
return getZ2() - getZ1() + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Integer getParentDomId() {
|
public Integer getParentDomId() {
|
||||||
return parentDomId;
|
return (Integer) parentDomId.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DominionDTO setParentDomId(Integer parentDomId) {
|
public DominionDTO setParentDomId(Integer parentDomId) {
|
||||||
this.parentDomId = parentDomId;
|
this.parentDomId.value = parentDomId;
|
||||||
Field parentDomIdField = new Field("parent_dom_id", parentDomId);
|
return doUpdate(new UpdateRow().field(this.parentDomId));
|
||||||
return doUpdate(new UpdateRow().field(parentDomIdField));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getJoinMessage() {
|
public String getJoinMessage() {
|
||||||
return joinMessage;
|
return (String) joinMessage.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DominionDTO setJoinMessage(String joinMessage) {
|
public DominionDTO setJoinMessage(String joinMessage) {
|
||||||
this.joinMessage = joinMessage;
|
this.joinMessage.value = joinMessage;
|
||||||
Field joinMessageField = new Field("join_message", joinMessage);
|
return doUpdate(new UpdateRow().field(this.joinMessage));
|
||||||
return doUpdate(new UpdateRow().field(joinMessageField));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getLeaveMessage() {
|
public String getLeaveMessage() {
|
||||||
return leaveMessage;
|
return (String) leaveMessage.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DominionDTO setLeaveMessage(String leaveMessage) {
|
public DominionDTO setLeaveMessage(String leaveMessage) {
|
||||||
this.leaveMessage = leaveMessage;
|
this.leaveMessage.value = leaveMessage;
|
||||||
Field leaveMessageField = new Field("leave_message", leaveMessage);
|
return doUpdate(new UpdateRow().field(this.leaveMessage));
|
||||||
return doUpdate(new UpdateRow().field(leaveMessageField));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Boolean getFlagValue(Flag flag) {
|
public Boolean getFlagValue(Flag flag) {
|
||||||
@ -384,19 +368,13 @@ public class DominionDTO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public DominionDTO setXYZ(Integer x1, Integer y1, Integer z1, Integer x2, Integer y2, Integer z2) {
|
public DominionDTO setXYZ(Integer x1, Integer y1, Integer z1, Integer x2, Integer y2, Integer z2) {
|
||||||
this.x1 = x1;
|
this.x1.value = x1;
|
||||||
this.y1 = y1;
|
this.y1.value = y1;
|
||||||
this.z1 = z1;
|
this.z1.value = z1;
|
||||||
this.x2 = x2;
|
this.x2.value = x2;
|
||||||
this.y2 = y2;
|
this.y2.value = y2;
|
||||||
this.z2 = z2;
|
this.z2.value = z2;
|
||||||
Field x1Field = new Field("x1", x1);
|
return doUpdate(new UpdateRow().field(this.x1).field(this.y1).field(this.z1).field(this.x2).field(this.y2).field(this.z2));
|
||||||
Field y1Field = new Field("y1", y1);
|
|
||||||
Field z1Field = new Field("z1", z1);
|
|
||||||
Field x2Field = new Field("x2", x2);
|
|
||||||
Field y2Field = new Field("y2", y2);
|
|
||||||
Field z2Field = new Field("z2", z2);
|
|
||||||
return doUpdate(new UpdateRow().field(x1Field).field(y1Field).field(z1Field).field(x2Field).field(y2Field).field(z2Field));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Location getTpLocation() {
|
public Location getTpLocation() {
|
||||||
@ -404,8 +382,8 @@ public class DominionDTO {
|
|||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
// 0:0:0
|
// 0:0:0
|
||||||
String[] loc = tp_location.split(":");
|
String[] loc = ((String) tp_location.value).split(":");
|
||||||
World w = Dominion.instance.getServer().getWorld(world);
|
World w = Dominion.instance.getServer().getWorld(getWorld());
|
||||||
if (loc.length == 3 && w != null) {
|
if (loc.length == 3 && w != null) {
|
||||||
return new Location(w, Integer.parseInt(loc[0]), Integer.parseInt(loc[1]), Integer.parseInt(loc[2]));
|
return new Location(w, Integer.parseInt(loc[0]), Integer.parseInt(loc[1]), Integer.parseInt(loc[2]));
|
||||||
} else {
|
} else {
|
||||||
@ -417,38 +395,36 @@ public class DominionDTO {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public DominionDTO setTpLocation(Location loc) {
|
public DominionDTO setTpLocation(Location loc) {
|
||||||
this.tp_location = loc.getBlockX() + ":" + loc.getBlockY() + ":" + loc.getBlockZ();
|
this.tp_location.value = loc.getBlockX() + ":" + loc.getBlockY() + ":" + loc.getBlockZ();
|
||||||
Field tpLocationField = new Field("tp_location", tp_location);
|
return doUpdate(new UpdateRow().field(tp_location));
|
||||||
return doUpdate(new UpdateRow().field(tpLocationField));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Location getLocation1() {
|
public Location getLocation1() {
|
||||||
return new Location(Dominion.instance.getServer().getWorld(world), x1, y1, z1);
|
return new Location(Dominion.instance.getServer().getWorld(getWorld()), getX1(), getY1(), getZ1());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Location getLocation2() {
|
public Location getLocation2() {
|
||||||
return new Location(Dominion.instance.getServer().getWorld(world), x2, y2, z2);
|
return new Location(Dominion.instance.getServer().getWorld(getWorld()), getX2(), getY2(), getZ2());
|
||||||
}
|
}
|
||||||
|
|
||||||
public DominionDTO setColor(String color) {
|
public DominionDTO setColor(String color) {
|
||||||
this.color = color;
|
this.color.value = color;
|
||||||
Field colorField = new Field("color", color);
|
return doUpdate(new UpdateRow().field(this.color));
|
||||||
return doUpdate(new UpdateRow().field(colorField));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getColorR() {
|
public int getColorR() {
|
||||||
return Integer.valueOf(color.substring(1, 3), 16);
|
return Integer.valueOf(getColor().substring(1, 3), 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getColorG() {
|
public int getColorG() {
|
||||||
return Integer.valueOf(color.substring(3, 5), 16);
|
return Integer.valueOf(getColor().substring(3, 5), 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getColorB() {
|
public int getColorB() {
|
||||||
return Integer.valueOf(color.substring(5, 7), 16);
|
return Integer.valueOf(getColor().substring(5, 7), 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getColor() {
|
public String getColor() {
|
||||||
return color;
|
return (String) color.value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user