diff --git a/pom.xml b/pom.xml
index 891be6cf..0d3cce5d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
cn.lunadeer
Dominion
- 1.35.2-beta
+ 1.35.3-beta
jar
Dominion
diff --git a/src/main/java/cn/lunadeer/dominion/commands/Apis.java b/src/main/java/cn/lunadeer/dominion/commands/Apis.java
index cd946575..a26dc5ce 100644
--- a/src/main/java/cn/lunadeer/dominion/commands/Apis.java
+++ b/src/main/java/cn/lunadeer/dominion/commands/Apis.java
@@ -36,7 +36,7 @@ public static void sizeInfo(CommandSender sender, DominionDTO dominionDTO) {
Notification.info(sender, " 领地的对角点坐标: x1=%d y1=%d z1=%d, x2=%d y2=%d z2=%d", x1, y1, z1, x2, y2, z2);
}
- public static void autoPoints(Player player) {
+ public static Map autoPoints(Player player) {
Integer size = Dominion.config.getAutoCreateRadius();
Location location = player.getLocation();
Location location1 = new Location(location.getWorld(), location.getX() - size, location.getY() - size, location.getZ() - size);
@@ -49,6 +49,7 @@ public static void autoPoints(Player player) {
points.put(0, location1);
points.put(1, location2);
Dominion.pointsSelect.put(player.getUniqueId(), points);
+ return points;
}
public static boolean notOpOrConsole(CommandSender sender) {
diff --git a/src/main/java/cn/lunadeer/dominion/controllers/DominionController.java b/src/main/java/cn/lunadeer/dominion/controllers/DominionController.java
index 46c5ecd1..e12c20c0 100644
--- a/src/main/java/cn/lunadeer/dominion/controllers/DominionController.java
+++ b/src/main/java/cn/lunadeer/dominion/controllers/DominionController.java
@@ -12,6 +12,7 @@
import org.bukkit.World;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
+import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
@@ -70,12 +71,12 @@ public static void create(AbstractOperator operator, String name,
* @param name 领地名称
* @param loc1 位置1
* @param loc2 位置2
- * @param parent_dominion_name 父领地名称
+ * @param parent_dominion_name 父领地名称(留空表示为根领地)
* @param skipEco 是否跳过经济检查
*/
public static void create(AbstractOperator operator, String name,
Location loc1, Location loc2,
- String parent_dominion_name, boolean skipEco) {
+ @NotNull String parent_dominion_name, boolean skipEco) {
AbstractOperator.Result FAIL = new AbstractOperator.Result(AbstractOperator.Result.FAILURE, "创建领地失败");
if (name.isEmpty()) {
operator.setResponse(FAIL.addMessage("领地名称不能为空"));
@@ -109,12 +110,8 @@ public static void create(AbstractOperator operator, String name,
loc2.getBlockX(), loc2.getBlockY(), loc2.getBlockZ())) {
return;
}
- DominionDTO dominion = new DominionDTO(operator.getUniqueId(), name, loc1.getWorld().getName(),
- (int) Math.min(loc1.getX(), loc2.getX()), (int) Math.min(loc1.getY(), loc2.getY()),
- (int) Math.min(loc1.getZ(), loc2.getZ()), (int) Math.max(loc1.getX(), loc2.getX()),
- (int) Math.max(loc1.getY(), loc2.getY()), (int) Math.max(loc1.getZ(), loc2.getZ()));
DominionDTO parent_dominion;
- if (parent_dominion_name.isEmpty()) {
+ if (parent_dominion_name.isEmpty() || parent_dominion_name.equals("root")) {
parent_dominion = DominionDTO.select(-1);
} else {
parent_dominion = DominionDTO.select(parent_dominion_name);
@@ -133,6 +130,11 @@ public static void create(AbstractOperator operator, String name,
return;
}
}
+ // 创建 dominion (此步骤不会写入数据)
+ DominionDTO dominion = DominionDTO.create(operator.getUniqueId(), name, loc1.getWorld().getName(),
+ (int) Math.min(loc1.getX(), loc2.getX()), (int) Math.min(loc1.getY(), loc2.getY()),
+ (int) Math.min(loc1.getZ(), loc2.getZ()), (int) Math.max(loc1.getX(), loc2.getX()),
+ (int) Math.max(loc1.getY(), loc2.getY()), (int) Math.max(loc1.getZ(), loc2.getZ()), parent_dominion);
// 如果parent_dominion不为-1 检查是否在同一世界
if (parent_dominion.getId() != -1 && !parent_dominion.getWorld().equals(dominion.getWorld())) {
operator.setResponse(FAIL.addMessage("父领地与子领地不在同一世界。"));
@@ -176,7 +178,7 @@ public static void create(AbstractOperator operator, String name,
operator.setResponse(new AbstractOperator.Result(AbstractOperator.Result.SUCCESS, "已扣除 %.2f %s", price, VaultConnect.instance.currencyNamePlural()));
VaultConnect.instance.withdrawPlayer(operator.getPlayer(), price);
}
- dominion = DominionDTO.insert(dominion);
+ dominion = DominionDTO.insert(dominion); // 写入数据
if (dominion == null) {
operator.setResponse(FAIL.addMessage("创建领地失败,数据库错误,请联系管理员"));
return;
@@ -184,7 +186,6 @@ public static void create(AbstractOperator operator, String name,
if (operator instanceof BukkitPlayerOperator) {
ParticleRender.showBoxFace(Dominion.instance, operator.getPlayer(), loc1, loc2);
}
- dominion.setParentDomId(parent_dominion.getId());
operator.setResponse(new AbstractOperator.Result(AbstractOperator.Result.SUCCESS, "成功创建领地 %s", name));
}
diff --git a/src/main/java/cn/lunadeer/dominion/cuis/CreateDominion.java b/src/main/java/cn/lunadeer/dominion/cuis/CreateDominion.java
index a1560cd5..059ee255 100644
--- a/src/main/java/cn/lunadeer/dominion/cuis/CreateDominion.java
+++ b/src/main/java/cn/lunadeer/dominion/cuis/CreateDominion.java
@@ -30,12 +30,11 @@ public createDominionCB(Player sender) {
@Override
public void handleData(String input) {
XLogger.debug("createDominionCB.run: %s", input);
- autoPoints(sender);
+
BukkitPlayerOperator operator = BukkitPlayerOperator.create(sender);
Map points = Dominion.pointsSelect.get(sender.getUniqueId());
if (points == null || points.get(0) == null || points.get(1) == null) {
- Notification.error(sender, "自动选点失败");
- return;
+ points = autoPoints(sender);
}
operator.getResponse().thenAccept(result -> {
if (Objects.equals(result.getStatus(), AbstractOperator.Result.SUCCESS)) {
diff --git a/src/main/java/cn/lunadeer/dominion/dtos/DominionDTO.java b/src/main/java/cn/lunadeer/dominion/dtos/DominionDTO.java
index cd488f4c..c2c2a9e4 100644
--- a/src/main/java/cn/lunadeer/dominion/dtos/DominionDTO.java
+++ b/src/main/java/cn/lunadeer/dominion/dtos/DominionDTO.java
@@ -191,6 +191,11 @@ public DominionDTO(UUID owner, String name, String world,
this(null, owner, name, world, x1, y1, z1, x2, y2, z2, -1);
}
+ public static DominionDTO create(UUID owner, String name, String world,
+ Integer x1, Integer y1, Integer z1, Integer x2, Integer y2, Integer z2, DominionDTO parent) {
+ return new DominionDTO(null, owner, name, world, x1, y1, z1, x2, y2, z2, parent == null ? -1 : parent.getId());
+ }
+
private final Field id = new Field("id", FieldType.INT);
private final Field owner = new Field("owner", FieldType.STRING);
private final Field name = new Field("name", FieldType.STRING);
@@ -329,11 +334,6 @@ public Integer getParentDomId() {
return (Integer) parentDomId.value;
}
- public DominionDTO setParentDomId(Integer parentDomId) {
- this.parentDomId.value = parentDomId;
- return doUpdate(new UpdateRow().field(this.parentDomId));
- }
-
public String getJoinMessage() {
return (String) joinMessage.value;
}