diff --git a/pom.xml b/pom.xml
index 1b64962..4668646 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
cn.lunadeer
Dominion
- 1.29.1-beta
+ 1.30.3-beta
jar
Dominion
diff --git a/src/main/java/cn/lunadeer/dominion/Cache.java b/src/main/java/cn/lunadeer/dominion/Cache.java
index 3f0bcae..dad0b4e 100644
--- a/src/main/java/cn/lunadeer/dominion/Cache.java
+++ b/src/main/java/cn/lunadeer/dominion/Cache.java
@@ -250,6 +250,11 @@ public class Cache {
return player_uuid_to_privilege.get(player.getUniqueId()).get(dominion.getId());
}
+ public PlayerPrivilegeDTO getPlayerPrivilege(UUID player_uuid, DominionDTO dominion) {
+ if (!player_uuid_to_privilege.containsKey(player_uuid)) return null;
+ return player_uuid_to_privilege.get(player_uuid).get(dominion.getId());
+ }
+
private static boolean isInDominion(@Nullable DominionDTO dominion, Player player) {
if (dominion == null) return false;
if (!Objects.equals(dominion.getWorld(), player.getWorld().getName())) return false;
@@ -265,8 +270,7 @@ public class Cache {
return id_dominions.get(id);
}
- public int getPlayerDominionCount(Player player) {
- UUID player_uuid = player.getUniqueId();
+ public int getPlayerDominionCount(UUID player_uuid) {
int count = 0;
for (DominionDTO dominion : id_dominions.values()) {
if (dominion.getOwner().equals(player_uuid)) {
diff --git a/src/main/java/cn/lunadeer/dominion/DominionNode.java b/src/main/java/cn/lunadeer/dominion/DominionNode.java
index 1d62048..162d903 100644
--- a/src/main/java/cn/lunadeer/dominion/DominionNode.java
+++ b/src/main/java/cn/lunadeer/dominion/DominionNode.java
@@ -49,7 +49,7 @@ public class DominionNode {
return dominionNode == null ? null : dominionNode.dominion;
}
- private static boolean isInDominion(@Nullable DominionDTO dominion, Location location) {
+ public static boolean isInDominion(@Nullable DominionDTO dominion, Location location) {
if (dominion == null) return false;
if (!Objects.equals(dominion.getWorld(), location.getWorld().getName())) return false;
double x = location.getX();
diff --git a/src/main/java/cn/lunadeer/dominion/commands/DominionFlag.java b/src/main/java/cn/lunadeer/dominion/commands/DominionFlag.java
index a75a852..1ef2719 100644
--- a/src/main/java/cn/lunadeer/dominion/commands/DominionFlag.java
+++ b/src/main/java/cn/lunadeer/dominion/commands/DominionFlag.java
@@ -1,5 +1,6 @@
package cn.lunadeer.dominion.commands;
+import cn.lunadeer.dominion.controllers.BukkitPlayerOperator;
import cn.lunadeer.dominion.controllers.FlagsController;
import cn.lunadeer.dominion.tuis.DominionFlagInfo;
import cn.lunadeer.minecraftpluginutils.Notification;
@@ -20,29 +21,21 @@ public class DominionFlag {
public static void setDominionFlag(CommandSender sender, String[] args) {
Player player = playerOnly(sender);
if (player == null) return;
+ BukkitPlayerOperator operator = BukkitPlayerOperator.create(player);
if (args.length == 3) {
- if (FlagsController.setFlag(player, args[1], Boolean.parseBoolean(args[2])) == null) {
- Notification.error(sender, "设置领地权限失败");
- }
+ FlagsController.setFlag(operator, args[1], Boolean.parseBoolean(args[2]));
} else if (args.length == 4) {
- if (FlagsController.setFlag(player, args[1], Boolean.parseBoolean(args[2]), args[3]) == null) {
- Notification.error(sender, "设置领地权限失败");
- }
+ FlagsController.setFlag(operator, args[1], Boolean.parseBoolean(args[2]), args[3]);
} else if (args.length == 5) {
- if (FlagsController.setFlag(player, args[1], Boolean.parseBoolean(args[2]), args[3]) == null) {
- Notification.error(sender, "设置领地权限失败");
- }
+ FlagsController.setFlag(operator, args[1], Boolean.parseBoolean(args[2]), args[3]);
String[] newArgs = new String[3];
newArgs[0] = "flag_info";
newArgs[1] = args[3];
newArgs[2] = args[4];
DominionFlagInfo.show(sender, newArgs);
- return;
} else {
Notification.error(sender, "用法: /dominion set <权限名称> [领地名称]");
- return;
}
- Notification.info(sender, "设置领地权限 %s 为 %s", args[1], args[2]);
}
}
diff --git a/src/main/java/cn/lunadeer/dominion/commands/DominionOperate.java b/src/main/java/cn/lunadeer/dominion/commands/DominionOperate.java
index e5391e5..8030c9a 100644
--- a/src/main/java/cn/lunadeer/dominion/commands/DominionOperate.java
+++ b/src/main/java/cn/lunadeer/dominion/commands/DominionOperate.java
@@ -2,6 +2,8 @@ package cn.lunadeer.dominion.commands;
import cn.lunadeer.dominion.Cache;
import cn.lunadeer.dominion.Dominion;
+import cn.lunadeer.dominion.controllers.AbstractOperator;
+import cn.lunadeer.dominion.controllers.BukkitPlayerOperator;
import cn.lunadeer.dominion.controllers.DominionController;
import cn.lunadeer.dominion.dtos.DominionDTO;
import cn.lunadeer.dominion.dtos.Flag;
@@ -17,6 +19,7 @@ import org.bukkit.entity.Player;
import java.time.LocalDateTime;
import java.util.Map;
+import java.util.Objects;
import static cn.lunadeer.dominion.commands.Apis.*;
@@ -41,11 +44,8 @@ public class DominionOperate {
return;
}
String name = args[1];
- if (DominionController.create(player, name, points.get(0), points.get(1)) == null) {
- Notification.error(sender, "创建领地失败");
- return;
- }
- Notification.info(sender, "成功创建: %s", name);
+ BukkitPlayerOperator operator = BukkitPlayerOperator.create(player);
+ DominionController.create(operator, name, points.get(0), points.get(1));
}
/**
@@ -67,18 +67,12 @@ public class DominionOperate {
Notification.error(sender, "请先使用工具选择子领地的对角线两点,或使用 /dominion auto_create_sub <子领地名称> [父领地名称] 创建自动子领地");
return;
}
+ BukkitPlayerOperator operator = BukkitPlayerOperator.create(player);
if (args.length == 2) {
- if (DominionController.create(player, args[1], points.get(0), points.get(1)) != null) {
- Notification.info(sender, "成功创建子领地: %s", args[1]);
- return;
- }
+ DominionController.create(operator, args[1], points.get(0), points.get(1));
} else {
- if (DominionController.create(player, args[1], points.get(0), points.get(1), args[2]) != null) {
- Notification.info(sender, "成功创建子领地: %s", args[1]);
- return;
- }
+ DominionController.create(operator, args[1], points.get(0), points.get(1), args[2]);
}
- Notification.error(sender, "创建子领地失败");
}
/**
@@ -156,17 +150,11 @@ public class DominionOperate {
if (args.length == 3) {
name = args[2];
}
- DominionDTO dominionDTO;
+ BukkitPlayerOperator operator = BukkitPlayerOperator.create(player);
if (name.isEmpty()) {
- dominionDTO = DominionController.expand(player, size);
+ DominionController.expand(operator, size);
} else {
- dominionDTO = DominionController.expand(player, size, name);
- }
- if (dominionDTO == null) {
- Notification.error(sender, "扩展领地失败");
- } else {
- Notification.info(sender, "成功扩展领地: %s %d", dominionDTO.getName(), size);
- sizeInfo(sender, dominionDTO);
+ DominionController.expand(operator, size, name);
}
}
@@ -199,17 +187,11 @@ public class DominionOperate {
if (args.length == 3) {
name = args[2];
}
- DominionDTO dominionDTO;
+ BukkitPlayerOperator operator = BukkitPlayerOperator.create(player);
if (name.isEmpty()) {
- dominionDTO = DominionController.contract(player, size);
+ DominionController.contract(operator, size);
} else {
- dominionDTO = DominionController.contract(player, size, name);
- }
- if (dominionDTO == null) {
- Notification.error(sender, "缩小领地失败");
- } else {
- Notification.info(sender, "成功缩小领地: %s %d", dominionDTO.getName(), size);
- sizeInfo(sender, dominionDTO);
+ DominionController.contract(operator, size, name);
}
}
@@ -223,15 +205,16 @@ public class DominionOperate {
public static void deleteDominion(CommandSender sender, String[] args) {
Player player = playerOnly(sender);
if (player == null) return;
+ BukkitPlayerOperator operator = BukkitPlayerOperator.create(player);
if (args.length == 2) {
String name = args[1];
- DominionController.delete(player, name, false);
+ DominionController.delete(operator, name, false);
return;
}
if (args.length == 3) {
String name = args[1];
if (args[2].equals("force")) {
- DominionController.delete(player, name, true);
+ DominionController.delete(operator, name, true);
return;
}
}
@@ -248,12 +231,13 @@ public class DominionOperate {
public static void setEnterMessage(CommandSender sender, String[] args) {
Player player = playerOnly(sender);
if (player == null) return;
+ BukkitPlayerOperator operator = BukkitPlayerOperator.create(player);
if (args.length == 2) {
- DominionController.setJoinMessage(player, args[1]);
+ DominionController.setJoinMessage(operator, args[1]);
return;
}
if (args.length == 3) {
- DominionController.setJoinMessage(player, args[1], args[2]);
+ DominionController.setJoinMessage(operator, args[1], args[2]);
return;
}
Notification.error(sender, "用法: /dominion set_enter_msg <提示语> [领地名称]");
@@ -269,12 +253,13 @@ public class DominionOperate {
public static void setLeaveMessage(CommandSender sender, String[] args) {
Player player = playerOnly(sender);
if (player == null) return;
+ BukkitPlayerOperator operator = BukkitPlayerOperator.create(player);
if (args.length == 2) {
- DominionController.setLeaveMessage(player, args[1]);
+ DominionController.setLeaveMessage(operator, args[1]);
return;
}
if (args.length == 3) {
- DominionController.setLeaveMessage(player, args[1], args[2]);
+ DominionController.setLeaveMessage(operator, args[1], args[2]);
return;
}
Notification.error(sender, "用法: /dominion set_leave_msg <提示语> [领地名称]");
@@ -290,12 +275,16 @@ public class DominionOperate {
public static void setTpLocation(CommandSender sender, String[] args) {
Player player = playerOnly(sender);
if (player == null) return;
+ BukkitPlayerOperator operator = BukkitPlayerOperator.create(player);
if (args.length == 1) {
- DominionController.setTpLocation(player);
+ DominionController.setTpLocation(operator,
+ player.getLocation().getBlockX(), player.getLocation().getBlockY(), player.getLocation().getBlockZ());
return;
}
if (args.length == 2) {
- DominionController.setTpLocation(player, args[1]);
+ DominionController.setTpLocation(operator,
+ player.getLocation().getBlockX(), player.getLocation().getBlockY(), player.getLocation().getBlockZ(),
+ args[1]);
return;
}
Notification.error(sender, "用法: /dominion set_tp_location [领地名称]");
@@ -311,11 +300,12 @@ public class DominionOperate {
public static void renameDominion(CommandSender sender, String[] args) {
Player player = playerOnly(sender);
if (player == null) return;
+ BukkitPlayerOperator operator = BukkitPlayerOperator.create(player);
if (args.length != 3) {
Notification.error(sender, "用法: /dominion rename <原领地名称> <新领地名称>");
return;
}
- DominionController.rename(player, args[1], args[2]);
+ DominionController.rename(operator, args[1], args[2]);
}
/**
@@ -328,17 +318,18 @@ public class DominionOperate {
public static void giveDominion(CommandSender sender, String[] args) {
Player player = playerOnly(sender);
if (player == null) return;
+ BukkitPlayerOperator operator = BukkitPlayerOperator.create(player);
if (args.length == 3) {
String dom_name = args[1];
String player_name = args[2];
- DominionController.give(player, dom_name, player_name, false);
+ DominionController.give(operator, dom_name, player_name, false);
return;
}
if (args.length == 4) {
String dom_name = args[1];
String player_name = args[2];
if (args[3].equals("force")) {
- DominionController.give(player, dom_name, player_name, true);
+ DominionController.give(operator, dom_name, player_name, true);
return;
}
}
diff --git a/src/main/java/cn/lunadeer/dominion/commands/OpenCUI.java b/src/main/java/cn/lunadeer/dominion/commands/OpenCUI.java
index 4b299ef..db1cfe3 100644
--- a/src/main/java/cn/lunadeer/dominion/commands/OpenCUI.java
+++ b/src/main/java/cn/lunadeer/dominion/commands/OpenCUI.java
@@ -1,6 +1,8 @@
package cn.lunadeer.dominion.commands;
import cn.lunadeer.dominion.Dominion;
+import cn.lunadeer.dominion.controllers.AbstractOperator;
+import cn.lunadeer.dominion.controllers.BukkitPlayerOperator;
import cn.lunadeer.dominion.controllers.DominionController;
import cn.lunadeer.dominion.controllers.PrivilegeController;
import cn.lunadeer.dominion.dtos.DominionDTO;
@@ -15,6 +17,7 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.Map;
+import java.util.Objects;
import static cn.lunadeer.dominion.commands.Apis.autoPoints;
import static cn.lunadeer.dominion.commands.Apis.playerOnly;
@@ -32,7 +35,8 @@ public class OpenCUI {
@Override
public void handleData(String input) {
XLogger.debug("renameDominionCB.run: %s", input);
- DominionController.rename(sender, oldName, input);
+ BukkitPlayerOperator operator = BukkitPlayerOperator.create(sender);
+ DominionController.rename(operator, oldName, input);
DominionManage.show(sender, new String[]{"manage", input});
}
}
@@ -49,7 +53,8 @@ public class OpenCUI {
@Override
public void handleData(String input) {
XLogger.debug("editJoinMessageCB.run: %s", input);
- DominionController.setJoinMessage(sender, input, dominionName);
+ BukkitPlayerOperator operator = BukkitPlayerOperator.create(sender);
+ DominionController.setJoinMessage(operator, input, dominionName);
DominionManage.show(sender, new String[]{"manage", dominionName});
}
}
@@ -66,7 +71,8 @@ public class OpenCUI {
@Override
public void handleData(String input) {
XLogger.debug("editLeaveMessageCB.run: %s", input);
- DominionController.setLeaveMessage(sender, input, dominionName);
+ BukkitPlayerOperator operator = BukkitPlayerOperator.create(sender);
+ DominionController.setLeaveMessage(operator, input, dominionName);
DominionManage.show(sender, new String[]{"manage", dominionName});
}
}
@@ -82,17 +88,18 @@ public class OpenCUI {
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;
}
- if (DominionController.create(sender, input, points.get(0), points.get(1)) != null) {
- Notification.info(sender, "成功创建: %s", input);
- DominionManage.show(sender, new String[]{"list"});
- } else {
- Notification.error(sender, "创建领地失败");
- }
+ operator.getResponse().thenAccept(result -> {
+ if (Objects.equals(result.getStatus(), AbstractOperator.Result.SUCCESS)){
+ DominionManage.show(sender, new String[]{"list"});
+ }
+ });
+ DominionController.create(operator, input, points.get(0), points.get(1));
}
}
@@ -108,11 +115,15 @@ public class OpenCUI {
@Override
public void handleData(String input) {
XLogger.debug("createPrivilegeCB.run: %s", input);
- if (PrivilegeController.createPrivilege(sender, input, dominionName)) {
- DominionPrivilegeList.show(sender, new String[]{"privilege_list", dominionName});
- } else {
- SelectPlayer.show(sender, new String[]{"select_player_create_privilege", dominionName});
- }
+ BukkitPlayerOperator operator = BukkitPlayerOperator.create(sender);
+ PrivilegeController.createPrivilege(operator, input, dominionName);
+ operator.getResponse().thenAccept(result -> {
+ if (Objects.equals(result.getStatus(), AbstractOperator.Result.SUCCESS)){
+ DominionPrivilegeList.show(sender, new String[]{"privilege_list", dominionName});
+ } else {
+ SelectPlayer.show(sender, new String[]{"select_player_create_privilege", dominionName});
+ }
+ });
}
}
diff --git a/src/main/java/cn/lunadeer/dominion/commands/PlayerPrivilege.java b/src/main/java/cn/lunadeer/dominion/commands/PlayerPrivilege.java
index 6b5b6d9..e1b8e12 100644
--- a/src/main/java/cn/lunadeer/dominion/commands/PlayerPrivilege.java
+++ b/src/main/java/cn/lunadeer/dominion/commands/PlayerPrivilege.java
@@ -1,5 +1,6 @@
package cn.lunadeer.dominion.commands;
+import cn.lunadeer.dominion.controllers.BukkitPlayerOperator;
import cn.lunadeer.dominion.tuis.DominionPrivilegeList;
import cn.lunadeer.dominion.tuis.PrivilegeInfo;
import cn.lunadeer.minecraftpluginutils.Notification;
@@ -21,22 +22,16 @@ public class PlayerPrivilege {
public static void createPlayerPrivilege(CommandSender sender, String[] args) {
Player player = playerOnly(sender);
if (player == null) return;
+ BukkitPlayerOperator operator = BukkitPlayerOperator.create(player);
if (args.length != 2 && args.length != 3 && args.length != 4) {
Notification.error(sender, "用法: /dominion create_privilege <玩家名称> [领地名称]");
return;
}
if (args.length == 2) {
- if (!createPrivilege(player, args[1])) {
- Notification.error(sender, "创建玩家特权失败");
- return;
- }
+ createPrivilege(operator, args[1]);
} else {
- if (!createPrivilege(player, args[1], args[2])) {
- Notification.error(sender, "创建玩家特权失败");
- return;
- }
+ createPrivilege(operator, args[1], args[2]);
}
- Notification.info(sender, "成功创建玩家特权 %s", args[1]);
if (args.length == 4) {
String[] newArgs = new String[2];
newArgs[0] = "privilege_list";
@@ -55,34 +50,22 @@ public class PlayerPrivilege {
public static void setPlayerPrivilege(CommandSender sender, String[] args) {
Player player = playerOnly(sender);
if (player == null) return;
-
+ BukkitPlayerOperator operator = BukkitPlayerOperator.create(player);
if (args.length == 4) {
- if (!setPrivilege(player, args[1], args[2], Boolean.parseBoolean(args[3]))) {
- Notification.error(sender, "设置玩家权限失败");
- return;
- }
+ setPrivilege(operator, args[1], args[2], Boolean.parseBoolean(args[3]));
} else if (args.length == 5) {
- if (!setPrivilege(player, args[1], args[2], Boolean.parseBoolean(args[3]), args[4])) {
- Notification.error(sender, "设置玩家权限失败");
- return;
- }
+ setPrivilege(operator, args[1], args[2], Boolean.parseBoolean(args[3]), args[4]);
} else if (args.length == 6) {
- if (!setPrivilege(player, args[1], args[2], Boolean.parseBoolean(args[3]), args[4])) {
- Notification.error(sender, "设置玩家权限失败");
- return;
- }
+ setPrivilege(operator, args[1], args[2], Boolean.parseBoolean(args[3]), args[4]);
String[] newArgs = new String[4];
newArgs[0] = "privilege_info";
newArgs[1] = args[1];
newArgs[2] = args[4];
newArgs[3] = args[5];
PrivilegeInfo.show(sender, newArgs);
- return;
} else {
Notification.error(sender, "用法: /dominion set_privilege <玩家名称> <权限名称> [领地名称]");
- return;
}
- Notification.info(sender, "设置玩家的 %s 权限为 %s", args[2], args[3]);
}
/**
@@ -95,22 +78,16 @@ public class PlayerPrivilege {
public static void clearPlayerPrivilege(CommandSender sender, String[] args) {
Player player = playerOnly(sender);
if (player == null) return;
+ BukkitPlayerOperator operator = BukkitPlayerOperator.create(player);
if (args.length != 2 && args.length != 3 && args.length != 4) {
Notification.error(sender, "用法: /dominion clear_privilege <玩家名称> [领地名称]");
return;
}
if (args.length == 2) {
- if (!clearPrivilege(player, args[1])) {
- Notification.error(sender, "重置玩家权限失败");
- return;
- }
+ clearPrivilege(operator, args[1]);
} else {
- if (!clearPrivilege(player, args[1], args[2])) {
- Notification.error(sender, "重置玩家权限失败");
- return;
- }
+ clearPrivilege(operator, args[1], args[2]);
}
- Notification.info(sender, "成功清除玩家 %s 的权限", args[1]);
if (args.length == 4) {
String[] newArgs = new String[3];
newArgs[0] = "privilege_list";
diff --git a/src/main/java/cn/lunadeer/dominion/controllers/AbstractOperator.java b/src/main/java/cn/lunadeer/dominion/controllers/AbstractOperator.java
new file mode 100644
index 0000000..7b9ea0e
--- /dev/null
+++ b/src/main/java/cn/lunadeer/dominion/controllers/AbstractOperator.java
@@ -0,0 +1,59 @@
+package cn.lunadeer.dominion.controllers;
+
+import org.bukkit.Location;
+import org.bukkit.block.BlockFace;
+import org.bukkit.entity.Player;
+
+import javax.annotation.Nullable;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+
+public interface AbstractOperator {
+
+ public static class Result {
+ public static final Integer SUCCESS = 0;
+ public static final Integer WARNING = 1;
+ public static final Integer FAILURE = 2;
+
+ private Integer success;
+ private String message;
+
+ public Result(Integer success, String message, Object... args) {
+ this.success = success;
+ this.message = String.format(message, args);
+ }
+
+ public Result setMessage(String message, Object... args) {
+ this.message = String.format(message, args);
+ return this;
+ }
+
+ public Result appendMessage(String message, Object... args) {
+ this.message += " ";
+ this.message += String.format(message, args);
+ return this;
+ }
+
+ public Integer getStatus() {
+ return success;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+ }
+
+ public UUID getUniqueId();
+
+ public boolean isOp();
+
+ public void setResponse(Result result);
+
+ public @Nullable Location getLocation();
+
+ public Player getPlayer();
+
+ public BlockFace getDirection();
+
+ public CompletableFuture getResponse();
+}
diff --git a/src/main/java/cn/lunadeer/dominion/controllers/Apis.java b/src/main/java/cn/lunadeer/dominion/controllers/Apis.java
index 2f74a40..0ef6c8f 100644
--- a/src/main/java/cn/lunadeer/dominion/controllers/Apis.java
+++ b/src/main/java/cn/lunadeer/dominion/controllers/Apis.java
@@ -1,5 +1,6 @@
package cn.lunadeer.dominion.controllers;
+import cn.lunadeer.dominion.Cache;
import cn.lunadeer.dominion.dtos.DominionDTO;
import cn.lunadeer.dominion.dtos.PlayerPrivilegeDTO;
import cn.lunadeer.minecraftpluginutils.Notification;
@@ -11,19 +12,17 @@ import java.util.List;
public class Apis {
- public static boolean notOwner(Player player, DominionDTO dominion) {
+ public static boolean notOwner(AbstractOperator player, DominionDTO dominion) {
if (player.isOp()) return false;
- if (dominion.getOwner().equals(player.getUniqueId())) return false;
- Notification.error(player, "你不是领地 %s 的拥有者,无法执行此操作", dominion.getName());
- return true;
+ return !dominion.getOwner().equals(player.getUniqueId());
}
- public static boolean noAuthToChangeFlags(Player player, DominionDTO dominion) {
+ public static boolean noAuthToChangeFlags(AbstractOperator player, DominionDTO dominion) {
if (player.isOp()) return false;
if (!dominion.getOwner().equals(player.getUniqueId())) {
PlayerPrivilegeDTO privileges = PlayerPrivilegeDTO.select(player.getUniqueId(), dominion.getId());
if (privileges == null || !privileges.getAdmin()) {
- Notification.error(player, "你不是领地 %s 的拥有者或管理员,无权修改权限", dominion.getName());
+ player.setResponse(new AbstractOperator.Result(AbstractOperator.Result.FAILURE, "你不是领地 %s 的拥有者或管理员,无权修改权限", dominion.getName()));
return true;
}
}
@@ -37,40 +36,19 @@ public class Apis {
* @param player 玩家
* @return 当前所在的领地
*/
- public static DominionDTO getPlayerCurrentDominion(Player player, boolean show_warning) {
+ public static DominionDTO getPlayerCurrentDominion(AbstractOperator player) {
Location location = player.getLocation();
- List dominions = DominionDTO.selectByLocation(location.getWorld().getName(),
- (int) location.getX(), (int) location.getY(), (int) location.getZ());
- if (dominions.size() != 1) {
- if (show_warning) {
- Notification.error(player, "你不在一个领地内或在子领地内,无法确定你要操作的领地,请手动指定要操作的领地名称");
- }
+ if (location == null) {
+ player.setResponse(new AbstractOperator.Result(AbstractOperator.Result.FAILURE, "无法获取你的位置信息"));
return null;
}
- return dominions.get(0);
- }
-
- public static DominionDTO getPlayerCurrentDominion(Player player) {
- return getPlayerCurrentDominion(player, true);
- }
-
- public static BlockFace getFace(Player player) {
- float yaw = player.getYaw();
- float pitch = player.getPitch();
- if (pitch > -45 && pitch < 45) {
- if (yaw > -45 && yaw < 45) {
- return BlockFace.SOUTH;
- } else if (yaw > 135 || yaw < -135) {
- return BlockFace.NORTH;
- } else if (yaw > 45 && yaw < 135) {
- return BlockFace.WEST;
- } else {
- return BlockFace.EAST;
- }
- } else if (pitch > 45) {
- return BlockFace.DOWN;
+ DominionDTO dominion = Cache.instance.getDominion(location);
+ if (dominion == null || dominion.getParentDomId() != -1) {
+ return dominion;
} else {
- return BlockFace.UP;
+ player.setResponse(new AbstractOperator.Result(AbstractOperator.Result.FAILURE, "你当前在子领地内,请指定要操作的领地名称"));
+ return null;
}
}
+
}
diff --git a/src/main/java/cn/lunadeer/dominion/controllers/BukkitPlayerOperator.java b/src/main/java/cn/lunadeer/dominion/controllers/BukkitPlayerOperator.java
new file mode 100644
index 0000000..791c17c
--- /dev/null
+++ b/src/main/java/cn/lunadeer/dominion/controllers/BukkitPlayerOperator.java
@@ -0,0 +1,85 @@
+package cn.lunadeer.dominion.controllers;
+
+import cn.lunadeer.minecraftpluginutils.Notification;
+import org.bukkit.Location;
+import org.bukkit.block.BlockFace;
+import org.bukkit.entity.Player;
+
+import java.util.Objects;
+import java.util.UUID;
+import java.util.concurrent.CompletableFuture;
+
+public class BukkitPlayerOperator implements AbstractOperator {
+
+ private final org.bukkit.entity.Player player;
+ private final CompletableFuture response = new CompletableFuture<>();
+
+ public BukkitPlayerOperator(org.bukkit.entity.Player player) {
+ this.player = player;
+ }
+
+ @Override
+ public UUID getUniqueId() {
+ return player.getUniqueId();
+ }
+
+ @Override
+ public boolean isOp() {
+ return player.isOp();
+ }
+
+ @Override
+ public void setResponse(Result result) {
+ response.complete(result);
+ }
+
+ @Override
+ public Location getLocation() {
+ return player.getLocation();
+ }
+
+ @Override
+ public Player getPlayer() {
+ return player;
+ }
+
+ @Override
+ public BlockFace getDirection() {
+ float yaw = player.getYaw();
+ float pitch = player.getPitch();
+ if (pitch > -45 && pitch < 45) {
+ if (yaw > -45 && yaw < 45) {
+ return BlockFace.SOUTH;
+ } else if (yaw > 135 || yaw < -135) {
+ return BlockFace.NORTH;
+ } else if (yaw > 45 && yaw < 135) {
+ return BlockFace.WEST;
+ } else {
+ return BlockFace.EAST;
+ }
+ } else if (pitch > 45) {
+ return BlockFace.DOWN;
+ } else {
+ return BlockFace.UP;
+ }
+ }
+
+ @Override
+ public CompletableFuture getResponse() {
+ return response;
+ }
+
+ public static BukkitPlayerOperator create(org.bukkit.entity.Player player) {
+ BukkitPlayerOperator operator = new BukkitPlayerOperator(player);
+ operator.getResponse().thenAccept(result -> {
+ if (Objects.equals(result.getStatus(), BukkitPlayerOperator.Result.SUCCESS)) {
+ Notification.info(player, result.getMessage());
+ } else if (Objects.equals(result.getStatus(), BukkitPlayerOperator.Result.WARNING)) {
+ Notification.warn(player, result.getMessage());
+ } else {
+ Notification.error(player, result.getMessage());
+ }
+ });
+ return operator;
+ }
+}
diff --git a/src/main/java/cn/lunadeer/dominion/controllers/DominionController.java b/src/main/java/cn/lunadeer/dominion/controllers/DominionController.java
index fb1fc72..4982a51 100644
--- a/src/main/java/cn/lunadeer/dominion/controllers/DominionController.java
+++ b/src/main/java/cn/lunadeer/dominion/controllers/DominionController.java
@@ -2,13 +2,15 @@ package cn.lunadeer.dominion.controllers;
import cn.lunadeer.dominion.Cache;
import cn.lunadeer.dominion.Dominion;
+import cn.lunadeer.dominion.DominionNode;
+import cn.lunadeer.dominion.commands.OpenCUI;
import cn.lunadeer.dominion.dtos.DominionDTO;
import cn.lunadeer.dominion.dtos.PlayerDTO;
-import cn.lunadeer.dominion.utils.Time;
import cn.lunadeer.minecraftpluginutils.Notification;
import cn.lunadeer.minecraftpluginutils.ParticleRender;
import cn.lunadeer.minecraftpluginutils.XLogger;
import org.bukkit.Location;
+import org.bukkit.World;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
@@ -16,6 +18,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
+import static cn.lunadeer.dominion.DominionNode.isInDominion;
import static cn.lunadeer.dominion.controllers.Apis.*;
public class DominionController {
@@ -31,69 +34,68 @@ public class DominionController {
/**
* 创建领地
*
- * @param owner 拥有者
- * @param name 领地名称
- * @param loc1 位置1
- * @param loc2 位置2
+ * @param operator 拥有者
+ * @param name 领地名称
+ * @param loc1 位置1
+ * @param loc2 位置2
* @return 创建的领地
*/
- public static DominionDTO create(Player owner, String name, Location loc1, Location loc2) {
- DominionDTO parent = getPlayerCurrentDominion(owner, false);
+ public static void create(AbstractOperator operator, String name, Location loc1, Location loc2) {
+ DominionDTO parent = getPlayerCurrentDominion(operator);
if (parent == null) {
- return create(owner, name, loc1, loc2, "");
+ create(operator, name, loc1, loc2, "");
} else {
- return create(owner, name, loc1, loc2, parent.getName());
+ create(operator, name, loc1, loc2, parent.getName());
}
}
/**
* 创建子领地
*
- * @param owner 拥有者
+ * @param operator 拥有者
* @param name 领地名称
* @param loc1 位置1
* @param loc2 位置2
* @param parent_dominion_name 父领地名称
* @return 创建的领地
*/
- public static DominionDTO create(Player owner, String name,
- Location loc1, Location loc2,
- String parent_dominion_name) {
+ public static void create(AbstractOperator operator, String name,
+ Location loc1, Location loc2,
+ String parent_dominion_name) {
+ AbstractOperator.Result FAIL = new AbstractOperator.Result(AbstractOperator.Result.FAILURE, "创建领地失败");
if (name.isEmpty()) {
- Notification.error(owner, "领地名称不能为空");
- return null;
+ operator.setResponse(FAIL.appendMessage("领地名称不能为空"));
+ return;
}
if (name.contains(" ")) {
- Notification.error(owner, "领地名称不能包含空格");
- return null;
+ operator.setResponse(FAIL.appendMessage("领地名称不能包含空格"));
+ return;
}
if (DominionDTO.select(name) != null) {
- Notification.error(owner, "已经存在名称为 %s 的领地", name);
- return null;
+ operator.setResponse(FAIL.appendMessage("已经存在名称为 %s 的领地", name));
+ return;
}
if (!loc1.getWorld().equals(loc2.getWorld())) {
- Notification.error(owner, "禁止跨世界操作");
- return null;
- }
- if (!owner.getWorld().equals(loc1.getWorld())) {
- Notification.error(owner, "禁止跨世界操作");
- return null;
+ operator.setResponse(FAIL.appendMessage("选点世界不一致"));
+ return;
}
// 检查世界是否可以创建
- if (worldNotValid(owner)) {
- return null;
+ if (worldNotValid(operator, loc1.getWorld().getName())) {
+ operator.setResponse(FAIL.appendMessage("禁止在世界 %s 创建领地", loc1.getWorld().getName()));
+ return;
}
// 检查领地数量是否达到上限
- if (amountNotValid(owner)) {
- return null;
+ if (amountNotValid(operator)) {
+ operator.setResponse(FAIL.appendMessage("你的领地数量已达上限(%d个)", Dominion.config.getLimitAmount()));
+ return;
}
// 检查领地大小是否合法
- if (sizeNotValid(owner,
+ if (sizeNotValid(operator,
loc1.getBlockX(), loc1.getBlockY(), loc1.getBlockZ(),
loc2.getBlockX(), loc2.getBlockY(), loc2.getBlockZ())) {
- return null;
+ return;
}
- DominionDTO dominion = new DominionDTO(owner.getUniqueId(), name, owner.getWorld().getName(),
+ 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()));
@@ -104,39 +106,40 @@ public class DominionController {
parent_dominion = DominionDTO.select(parent_dominion_name);
}
if (parent_dominion == null) {
- Notification.error(owner, "父领地 %s 不存在", parent_dominion_name);
+ operator.setResponse(FAIL.appendMessage("父领地 %s 不存在", parent_dominion_name));
if (parent_dominion_name.isEmpty()) {
XLogger.err("根领地丢失!");
}
- return null;
+ return;
}
// 是否是父领地的拥有者
if (parent_dominion.getId() != -1) {
- if (notOwner(owner, parent_dominion)) {
- return null;
+ if (notOwner(operator, parent_dominion)) {
+ operator.setResponse(FAIL.appendMessage("你不是父领地 %s 的拥有者,无法创建子领地", parent_dominion_name));
+ return;
}
}
// 如果parent_dominion不为-1 检查是否在同一世界
if (parent_dominion.getId() != -1 && !parent_dominion.getWorld().equals(dominion.getWorld())) {
- Notification.error(owner, "禁止跨世界操作");
- return null;
+ operator.setResponse(FAIL.appendMessage("父领地与子领地不在同一世界。"));
+ return;
}
// 检查深度是否达到上限
- if (depthNotValid(owner, parent_dominion)) {
- return null;
+ if (depthNotValid(operator, parent_dominion)) {
+ return;
}
// 检查是否超出父领地范围
if (!isContained(dominion, parent_dominion)) {
- Notification.error(owner, "超出父领地 %s 范围", parent_dominion.getName());
- return null;
+ operator.setResponse(FAIL.appendMessage("超出父领地 %s 范围", parent_dominion.getName()));
+ return;
}
// 获取此领地的所有同级领地
List sub_dominions = DominionDTO.selectByParentId(dominion.getWorld(), parent_dominion.getId());
// 检查是否与其他子领地冲突
for (DominionDTO sub_dominion : sub_dominions) {
if (isIntersect(sub_dominion, dominion)) {
- Notification.error(owner, "与领地 %s 冲突", sub_dominion.getName());
- return null;
+ operator.setResponse(FAIL.appendMessage("与领地 %s 冲突", sub_dominion.getName()));
+ return;
}
}
// 检查经济
@@ -148,20 +151,23 @@ public class DominionController {
count = (loc2.getBlockX() - loc1.getBlockX() + 1) * (loc2.getBlockY() - loc1.getBlockY() + 1) * (loc2.getBlockZ() - loc1.getBlockZ() + 1);
}
float price = count * Dominion.config.getEconomyPrice();
- if (Dominion.vault.getEconomy().getBalance(owner) < price) {
- Notification.error(owner, "你的余额不足,创建此领地需要 %.2f %s", price, Dominion.vault.getEconomy().currencyNamePlural());
- return null;
+ if (Dominion.vault.getEconomy().getBalance(operator.getPlayer()) < price) {
+ operator.setResponse(FAIL.appendMessage("你的余额不足,创建此领地需要 %.2f %s", price, Dominion.vault.getEconomy().currencyNamePlural()));
+ return;
}
- Notification.info(owner, "已扣除 %.2f %s", price, Dominion.vault.getEconomy().currencyNamePlural());
- Dominion.vault.getEconomy().withdrawPlayer(owner, price);
+ operator.setResponse(new AbstractOperator.Result(AbstractOperator.Result.SUCCESS, "已扣除 %.2f %s", price, Dominion.vault.getEconomy().currencyNamePlural()));
+ Dominion.vault.getEconomy().withdrawPlayer(operator.getPlayer(), price);
}
dominion = DominionDTO.insert(dominion);
if (dominion == null) {
- Notification.error(owner, "创建失败,详细错误请联系管理员查询日志(当前时间:%s)", Time.nowStr());
- return null;
+ operator.setResponse(FAIL.appendMessage("创建领地失败,数据库错误,请联系管理员"));
+ return;
}
- ParticleRender.showBoxFace(Dominion.instance, owner, loc1, loc2);
- return dominion.setParentDomId(parent_dominion.getId());
+ 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));
}
/**
@@ -173,12 +179,13 @@ public class DominionController {
* @param size 扩展的大小
* @return 扩展后的领地
*/
- public static DominionDTO expand(Player operator, Integer size) {
+ public static void expand(AbstractOperator operator, Integer size) {
DominionDTO dominion = getPlayerCurrentDominion(operator);
if (dominion == null) {
- return null;
+ operator.setResponse(new AbstractOperator.Result(AbstractOperator.Result.FAILURE, "无法获取你所处的领地,请指定名称"));
+ return;
}
- return expand(operator, size, dominion.getName());
+ expand(operator, size, dominion.getName());
}
/**
@@ -189,16 +196,19 @@ public class DominionController {
* @param dominion_name 领地名称
* @return 扩展后的领地
*/
- public static DominionDTO expand(Player operator, Integer size, String dominion_name) {
+ public static void expand(AbstractOperator operator, Integer size, String dominion_name) {
+ AbstractOperator.Result FAIL = new AbstractOperator.Result(AbstractOperator.Result.FAILURE, "扩展领地失败");
Location location = operator.getLocation();
- BlockFace face = getFace(operator);
+ BlockFace face = operator.getDirection();
DominionDTO dominion = getExistDomAndIsOwner(operator, dominion_name);
if (dominion == null) {
- return null;
+ return;
}
- if (!location.getWorld().getName().equals(dominion.getWorld())) {
- Notification.error(operator, "禁止跨世界操作");
- return null;
+ if (location != null) {
+ if (!location.getWorld().getName().equals(dominion.getWorld())) {
+ operator.setResponse(FAIL.appendMessage("禁止跨世界操作"));
+ return;
+ }
}
Integer x1 = dominion.getX1();
Integer y1 = dominion.getY1();
@@ -226,21 +236,21 @@ public class DominionController {
y1 -= size;
break;
default:
- Notification.error(operator, "无效的方向");
- return null;
+ operator.setResponse(FAIL.appendMessage("无效的方向"));
+ return;
}
if (sizeNotValid(operator, x1, y1, z1, x2, y2, z2)) {
- return null;
+ return;
}
// 校验是否超出父领地范围
DominionDTO parent_dominion = DominionDTO.select(dominion.getParentDomId());
if (parent_dominion == null) {
- Notification.error(operator, "父领地丢失");
- return null;
+ operator.setResponse(FAIL.appendMessage("父领地丢失"));
+ return;
}
if (!isContained(x1, y1, z1, x2, y2, z2, parent_dominion)) {
- Notification.error(operator, "超出父领地 %s 范围", parent_dominion.getName());
- return null;
+ operator.setResponse(FAIL.appendMessage("超出父领地 %s 范围", parent_dominion.getName()));
+ return;
}
// 获取同世界下的所有同级领地
List exist_dominions = DominionDTO.selectByParentId(dominion.getWorld(), dominion.getParentDomId());
@@ -248,10 +258,11 @@ public class DominionController {
if (isIntersect(exist_dominion, x1, y1, z1, x2, y2, z2)) {
// 如果是自己,跳过
if (exist_dominion.getId().equals(dominion.getId())) continue;
- Notification.error(operator, "与 %s 冲突", exist_dominion.getName());
- return null;
+ operator.setResponse(FAIL.appendMessage("与领地 %s 冲突", exist_dominion.getName()));
+ return;
}
}
+ AbstractOperator.Result SUCCESS = new AbstractOperator.Result(AbstractOperator.Result.SUCCESS, "成功扩展领地 %s %d格", dominion_name, size);
// 检查经济
if (Dominion.config.getEconomyEnable()) {
int count;
@@ -261,17 +272,21 @@ public class DominionController {
count = (x2 - x1 + 1) * (y2 - y1 + 1) * (z2 - z1 + 1) - dominion.getVolume();
}
float price = count * Dominion.config.getEconomyPrice();
- if (Dominion.vault.getEconomy().getBalance(operator) < price) {
- Notification.error(operator, "你的余额不足,扩展此领地需要 %.2f %s", price, Dominion.vault.getEconomy().currencyNamePlural());
- return null;
+ if (Dominion.vault.getEconomy().getBalance(operator.getPlayer()) < price) {
+ operator.setResponse(FAIL.appendMessage("你的余额不足,扩展此领地需要 %.2f %s", price, Dominion.vault.getEconomy().currencyNamePlural()));
+ return;
}
- Notification.info(operator, "已扣除 %.2f %s", price, Dominion.vault.getEconomy().currencyNamePlural());
- Dominion.vault.getEconomy().withdrawPlayer(operator, price);
+ SUCCESS.appendMessage("已扣除 %.2f %s", price, Dominion.vault.getEconomy().currencyNamePlural());
+ Dominion.vault.getEconomy().withdrawPlayer(operator.getPlayer(), price);
}
- ParticleRender.showBoxFace(Dominion.instance, operator,
- new Location(location.getWorld(), x1, y1, z1),
- new Location(location.getWorld(), x2, y2, z2));
- return dominion.setXYZ(x1, y1, z1, x2, y2, z2);
+ if (operator instanceof BukkitPlayerOperator) {
+ World world = Dominion.instance.getServer().getWorld(dominion.getWorld());
+ ParticleRender.showBoxFace(Dominion.instance, operator.getPlayer(),
+ new Location(world, x1, y1, z1),
+ new Location(world, x2, y2, z2));
+ }
+ dominion.setXYZ(x1, y1, z1, x2, y2, z2);
+ operator.setResponse(SUCCESS);
}
/**
@@ -283,12 +298,13 @@ public class DominionController {
* @param size 缩小的大小
* @return 缩小后的领地
*/
- public static DominionDTO contract(Player operator, Integer size) {
+ public static void contract(AbstractOperator operator, Integer size) {
DominionDTO dominion = getPlayerCurrentDominion(operator);
if (dominion == null) {
- return null;
+ operator.setResponse(new AbstractOperator.Result(AbstractOperator.Result.FAILURE, "无法获取你所处的领地,请指定名称"));
+ return;
}
- return contract(operator, size, dominion.getName());
+ contract(operator, size, dominion.getName());
}
/**
@@ -299,16 +315,19 @@ public class DominionController {
* @param dominion_name 领地名称
* @return 缩小后的领地
*/
- public static DominionDTO contract(Player operator, Integer size, String dominion_name) {
+ public static void contract(AbstractOperator operator, Integer size, String dominion_name) {
+ AbstractOperator.Result FAIL = new AbstractOperator.Result(AbstractOperator.Result.FAILURE, "缩小领地失败");
Location location = operator.getLocation();
- BlockFace face = getFace(operator);
+ BlockFace face = operator.getDirection();
DominionDTO dominion = getExistDomAndIsOwner(operator, dominion_name);
if (dominion == null) {
- return null;
+ return;
}
- if (!location.getWorld().getName().equals(dominion.getWorld())) {
- Notification.error(operator, "禁止跨世界操作");
- return null;
+ if (location != null) {
+ if (!location.getWorld().getName().equals(dominion.getWorld())) {
+ operator.setResponse(FAIL.appendMessage("禁止跨世界操作"));
+ return;
+ }
}
Integer x1 = dominion.getX1();
Integer y1 = dominion.getY1();
@@ -336,25 +355,26 @@ public class DominionController {
y1 += size;
break;
default:
- Notification.error(operator, "无效的方向");
- return null;
+ operator.setResponse(FAIL.appendMessage("无效的方向"));
+ return;
}
// 校验第二组坐标是否小于第一组坐标
if (x1 >= x2 || y1 >= y2 || z1 >= z2) {
- Notification.error(operator, "缩小后的领地无效");
- return null;
+ operator.setResponse(FAIL.appendMessage("缩小后的领地大小无效"));
+ return;
}
if (sizeNotValid(operator, x1, y1, z1, x2, y2, z2)) {
- return null;
+ return;
}
// 获取所有的子领地
List sub_dominions = DominionDTO.selectByParentId(dominion.getWorld(), dominion.getId());
for (DominionDTO sub_dominion : sub_dominions) {
if (!isContained(sub_dominion, x1, y1, z1, x2, y2, z2)) {
- Notification.error(operator, "缩小后的领地 %s 无法包含子领地 %s", dominion_name, sub_dominion.getName());
- return null;
+ operator.setResponse(FAIL.appendMessage("缩小后的领地无法包含子领地 %s", sub_dominion.getName()));
+ return;
}
}
+ AbstractOperator.Result SUCCESS = new AbstractOperator.Result(AbstractOperator.Result.SUCCESS, "成功缩小领地 %s %d格", dominion_name, size);
// 退还经济
if (Dominion.config.getEconomyEnable()) {
int count;
@@ -364,13 +384,17 @@ public class DominionController {
count = dominion.getVolume() - (x2 - x1 + 1) * (y2 - y1 + 1) * (z2 - z1 + 1);
}
float refund = count * Dominion.config.getEconomyPrice() * Dominion.config.getEconomyRefund();
- Dominion.vault.getEconomy().depositPlayer(operator, refund);
- Notification.info(operator, "已经退还 %.2f %s", refund, Dominion.vault.getEconomy().currencyNamePlural());
+ Dominion.vault.getEconomy().depositPlayer(operator.getPlayer(), refund);
+ SUCCESS.appendMessage("已退还 %.2f %s", refund, Dominion.vault.getEconomy().currencyNamePlural());
}
- ParticleRender.showBoxFace(Dominion.instance, operator,
- new Location(location.getWorld(), x1, y1, z1),
- new Location(location.getWorld(), x2, y2, z2));
- return dominion.setXYZ(x1, y1, z1, x2, y2, z2);
+ if (operator instanceof BukkitPlayerOperator) {
+ World world = Dominion.instance.getServer().getWorld(dominion.getWorld());
+ ParticleRender.showBoxFace(Dominion.instance, operator.getPlayer(),
+ new Location(world, x1, y1, z1),
+ new Location(world, x2, y2, z2));
+ }
+ dominion.setXYZ(x1, y1, z1, x2, y2, z2);
+ operator.setResponse(SUCCESS);
}
/**
@@ -380,26 +404,30 @@ public class DominionController {
* @param dominion_name 领地名称
* @param force 是否强制删除
*/
- public static void delete(Player operator, String dominion_name, boolean force) {
+ public static void delete(AbstractOperator operator, String dominion_name, boolean force) {
DominionDTO dominion = getExistDomAndIsOwner(operator, dominion_name);
if (dominion == null) {
return;
}
List sub_dominions = getSubDominionsRecursive(dominion);
if (!force) {
- Notification.warn(operator, "删除领地 %s 会同时删除其所有子领地,是否继续?", dominion_name);
+ AbstractOperator.Result WARNING = new AbstractOperator.Result(AbstractOperator.Result.WARNING, "删除领地 %s 会同时删除其所有子领地,是否继续?", dominion_name);
String sub_names = "";
for (DominionDTO sub_dominion : sub_dominions) {
sub_names = sub_dominion.getName() + ", ";
}
if (sub_dominions.size() > 0) {
sub_names = sub_names.substring(0, sub_names.length() - 2);
- Notification.warn(operator, "当前子领地:" + sub_names);
+ WARNING.appendMessage("(子领地:%s)", sub_names);
}
- Notification.warn(operator, "输入 /dominion delete %s force 确认删除", dominion_name);
+ if (operator instanceof BukkitPlayerOperator) {
+ Notification.warn(operator.getPlayer(), "输入 /dominion delete %s force 确认删除", dominion_name);
+ }
+ operator.setResponse(WARNING);
return;
}
DominionDTO.delete(dominion);
+ AbstractOperator.Result SUCCESS = new AbstractOperator.Result(AbstractOperator.Result.SUCCESS, "领地 %s 及其所有子领地已删除", dominion_name);
// 退还经济
if (Dominion.config.getEconomyEnable()) {
int count = 0;
@@ -413,10 +441,10 @@ public class DominionController {
}
}
float refund = count * Dominion.config.getEconomyPrice() * Dominion.config.getEconomyRefund();
- Dominion.vault.getEconomy().depositPlayer(operator, refund);
- Notification.info(operator, "已经退还 %.2f %s", refund, Dominion.vault.getEconomy().currencyNamePlural());
+ Dominion.vault.getEconomy().depositPlayer(operator.getPlayer(), refund);
+ SUCCESS.appendMessage("已退还 %.2f %s", refund, Dominion.vault.getEconomy().currencyNamePlural());
}
- Notification.info(operator, "领地 %s 及其所有子领地已删除", dominion_name);
+ operator.setResponse(SUCCESS);
}
/**
@@ -425,7 +453,7 @@ public class DominionController {
* @param operator 操作者
* @param message 消息
*/
- public static void setJoinMessage(Player operator, String message) {
+ public static void setJoinMessage(AbstractOperator operator, String message) {
DominionDTO dominion = getPlayerCurrentDominion(operator);
if (dominion == null) {
return;
@@ -440,13 +468,13 @@ public class DominionController {
* @param dominion_name 领地名称
* @param message 消息
*/
- public static void setJoinMessage(Player operator, String message, String dominion_name) {
+ public static void setJoinMessage(AbstractOperator operator, String message, String dominion_name) {
DominionDTO dominion = getExistDomAndIsOwner(operator, dominion_name);
if (dominion == null) {
return;
}
dominion.setJoinMessage(message);
- Notification.info(operator, "成功设置领地 %s 的进入消息", dominion_name);
+ operator.setResponse(new AbstractOperator.Result(AbstractOperator.Result.SUCCESS, "成功设置领地 %s 的进入消息", dominion_name));
}
/**
@@ -455,7 +483,7 @@ public class DominionController {
* @param operator 操作者
* @param message 消息
*/
- public static void setLeaveMessage(Player operator, String message) {
+ public static void setLeaveMessage(AbstractOperator operator, String message) {
DominionDTO dominion = getPlayerCurrentDominion(operator);
if (dominion == null) {
return;
@@ -470,13 +498,13 @@ public class DominionController {
* @param dominion_name 领地名称
* @param message 消息
*/
- public static void setLeaveMessage(Player operator, String message, String dominion_name) {
+ public static void setLeaveMessage(AbstractOperator operator, String message, String dominion_name) {
DominionDTO dominion = getExistDomAndIsOwner(operator, dominion_name);
if (dominion == null) {
return;
}
dominion.setLeaveMessage(message);
- Notification.info(operator, "成功设置领地 %s 的离开消息", dominion_name);
+ operator.setResponse(new AbstractOperator.Result(AbstractOperator.Result.SUCCESS, "成功设置领地 %s 的离开消息", dominion_name));
}
/**
@@ -484,12 +512,12 @@ public class DominionController {
*
* @param operator 操作者
*/
- public static void setTpLocation(Player operator) {
+ public static void setTpLocation(AbstractOperator operator, int x, int y, int z) {
DominionDTO dominion = getPlayerCurrentDominion(operator);
if (dominion == null) {
return;
}
- setTpLocation(operator, dominion.getName());
+ setTpLocation(operator, x, y, z, dominion.getName());
}
/**
@@ -498,26 +526,27 @@ public class DominionController {
* @param operator 操作者
* @param dominion_name 领地名称
*/
- public static void setTpLocation(Player operator, String dominion_name) {
+ public static void setTpLocation(AbstractOperator operator, int x, int y, int z, String dominion_name) {
DominionDTO dominion = getExistDomAndIsOwner(operator, dominion_name);
if (dominion == null) {
+ operator.setResponse(new AbstractOperator.Result(AbstractOperator.Result.FAILURE, "领地 %s 不存在", dominion_name));
return;
}
+ World world = Dominion.instance.getServer().getWorld(dominion.getWorld());
+ if (world == null) {
+ operator.setResponse(new AbstractOperator.Result(AbstractOperator.Result.FAILURE, "世界 %s 不存在", dominion.getWorld()));
+ return;
+ }
+ Location loc = new Location(world, x, y, z);
// 检查是否在领地内
- if (operator.getWorld().getName().equals(dominion.getWorld()) &&
- operator.getLocation().getBlockX() >= dominion.getX1() &&
- operator.getLocation().getBlockX() <= dominion.getX2() &&
- operator.getLocation().getBlockY() >= dominion.getY1() &&
- operator.getLocation().getBlockY() <= dominion.getY2() &&
- operator.getLocation().getBlockZ() >= dominion.getZ1() &&
- operator.getLocation().getBlockZ() <= dominion.getZ2()) {
- Location loc = operator.getLocation();
+ if (isInDominion(dominion, loc)) {
loc.setY(loc.getY() + 1.5);
dominion.setTpLocation(loc);
- Notification.info(operator, "成功设置领地 %s 的传送点,坐标:%d %d %d",
- dominion_name, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
+ operator.setResponse(new AbstractOperator.Result(AbstractOperator.Result.SUCCESS,
+ "成功设置领地 %s 的传送点 %d %d %d", dominion_name
+ , loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()));
} else {
- Notification.error(operator, "你不在领地 %s 内,无法设置传送点", dominion_name);
+ operator.setResponse(new AbstractOperator.Result(AbstractOperator.Result.FAILURE, "传送点不在领地 %s 内", dominion_name));
}
}
@@ -528,17 +557,18 @@ public class DominionController {
* @param old_name 旧名称
* @param new_name 新名称
*/
- public static void rename(Player operator, String old_name, String new_name) {
+ public static void rename(AbstractOperator operator, String old_name, String new_name) {
+ AbstractOperator.Result FAIL = new AbstractOperator.Result(AbstractOperator.Result.FAILURE, "重命名领地失败");
if (new_name.isEmpty()) {
- Notification.error(operator, "新名称不能为空");
+ operator.setResponse(FAIL.appendMessage("新名称不能为空"));
return;
}
if (new_name.contains(" ")) {
- Notification.error(operator, "领地名称不能包含空格");
+ operator.setResponse(FAIL.appendMessage("领地名称不能包含空格"));
return;
}
if (Objects.equals(old_name, new_name)) {
- Notification.error(operator, "新名称与旧名称相同");
+ operator.setResponse(FAIL.appendMessage("新名称与旧名称相同"));
return;
}
DominionDTO dominion = getExistDomAndIsOwner(operator, old_name);
@@ -546,11 +576,11 @@ public class DominionController {
return;
}
if (DominionDTO.select(new_name) != null) {
- Notification.error(operator, "已经存在名称为 %s 的领地", new_name);
+ operator.setResponse(FAIL.appendMessage("已经存在名称为 %s 的领地", new_name));
return;
}
dominion.setName(new_name);
- Notification.info(operator, "成功将领地 %s 重命名为 %s", old_name, new_name);
+ operator.setResponse(new AbstractOperator.Result(AbstractOperator.Result.SUCCESS, "成功将领地 %s 重命名为 %s", old_name, new_name));
}
/**
@@ -561,9 +591,15 @@ public class DominionController {
* @param player_name 玩家名称
* @param force 是否强制转让
*/
- public static void give(Player operator, String dom_name, String player_name, boolean force) {
- if (Objects.equals(player_name, operator.getName())) {
- Notification.error(operator, "你不能将领地转让给自己");
+ public static void give(AbstractOperator operator, String dom_name, String player_name, boolean force) {
+ AbstractOperator.Result FAIL = new AbstractOperator.Result(AbstractOperator.Result.FAILURE, "转让领地失败");
+ PlayerDTO operatorDTO = PlayerDTO.select(operator.getUniqueId());
+ if (operatorDTO == null) {
+ operator.setResponse(FAIL.appendMessage("操作者信息丢失,请联系管理员"));
+ return;
+ }
+ if (Objects.equals(player_name, operatorDTO.getLastKnownName())) {
+ operator.setResponse(FAIL.appendMessage("不能将领地转让给自己"));
return;
}
DominionDTO dominion = getExistDomAndIsOwner(operator, dom_name);
@@ -572,32 +608,35 @@ public class DominionController {
}
PlayerDTO player = PlayerController.getPlayerDTO(player_name);
if (player == null) {
- Notification.error(operator, "玩家 %s 不存在", player_name);
+ operator.setResponse(FAIL.appendMessage("玩家 %s 不存在", player_name));
return;
}
if (dominion.getParentDomId() != -1) {
- Notification.error(operator, "子领地无法转让,你可以通过将玩家设置为管理员来让其管理子领地");
+ operator.setResponse(FAIL.appendMessage("子领地无法转让,你可以通过将 %s 设置为管理员来让其管理领地 %s ", player_name, dom_name));
return;
}
List sub_dominions = getSubDominionsRecursive(dominion);
if (!force) {
- Notification.warn(operator, "转让领地 %s 给 %s 会同时转让其所有子领地,是否继续?", dom_name, player_name);
+ AbstractOperator.Result WARNING = new AbstractOperator.Result(AbstractOperator.Result.WARNING, "转让领地 %s 给 %s 会同时转让其所有子领地,是否继续?", dom_name, player_name);
String sub_names = "";
for (DominionDTO sub_dominion : sub_dominions) {
sub_names = sub_dominion.getName() + ", ";
}
if (sub_dominions.size() > 0) {
sub_names = sub_names.substring(0, sub_names.length() - 2);
- Notification.warn(operator, "当前子领地:%s", sub_names);
+ WARNING.appendMessage("(子领地:%s)", sub_names);
}
- Notification.warn(operator, "输入 /dominion give %s %s force 确认转让", dom_name, player_name);
+ if (operator instanceof BukkitPlayerOperator) {
+ Notification.warn(operator.getPlayer(), "输入 /dominion give %s %s force 确认转让", dom_name, player_name);
+ }
+ operator.setResponse(WARNING);
return;
}
dominion.setOwner(player.getUuid());
for (DominionDTO sub_dominion : sub_dominions) {
sub_dominion.setOwner(player.getUuid());
}
- Notification.info(operator, "成功将领地 %s 及其所有子领地转让给 %s", dom_name, player_name);
+ operator.setResponse(new AbstractOperator.Result(AbstractOperator.Result.SUCCESS, "成功将领地 %s 及其所有子领地转让给 %s", dom_name, player_name));
}
/**
@@ -652,7 +691,8 @@ public class DominionController {
return sub_dominions;
}
- private static boolean sizeNotValid(Player operator, int x1, int y1, int z1, int x2, int y2, int z2) {
+ private static boolean sizeNotValid(AbstractOperator operator, int x1, int y1, int z1, int x2, int y2, int z2) {
+ AbstractOperator.Result FAIL = new AbstractOperator.Result(AbstractOperator.Result.FAILURE, "尺寸不合法");
if (operator.isOp() && Dominion.config.getLimitOpBypass()) {
return false;
}
@@ -676,33 +716,34 @@ public class DominionController {
int y_length = y2 - y1;
int z_length = z2 - z1;
if (x_length < 4 || y_length < 4 || z_length < 4) {
- Notification.error(operator, "领地的任意一边长度不得小于4");
+ operator.setResponse(FAIL.appendMessage("领地的任意一边长度不得小于4"));
return true;
}
if (x_length > Dominion.config.getLimitSizeX() && Dominion.config.getLimitSizeX() > 0) {
- Notification.error(operator, "领地X方向长度不能超过 %s", Dominion.config.getLimitSizeX());
+ operator.setResponse(FAIL.appendMessage("领地X方向长度不能超过 %s", Dominion.config.getLimitSizeX()));
return true;
}
if (y_length > Dominion.config.getLimitSizeY() && Dominion.config.getLimitSizeY() > 0) {
- Notification.error(operator, "领地Y方向高度不能超过 %s", Dominion.config.getLimitSizeY());
+ operator.setResponse(FAIL.appendMessage("领地Y方向高度不能超过 %s", Dominion.config.getLimitSizeY()));
return true;
}
if (z_length > Dominion.config.getLimitSizeZ() && Dominion.config.getLimitSizeZ() > 0) {
- Notification.error(operator, "领地Z方向长度不能超过 %s", Dominion.config.getLimitSizeZ());
+ operator.setResponse(FAIL.appendMessage("领地Z方向长度不能超过 %s", Dominion.config.getLimitSizeZ()));
return true;
}
if (y2 > Dominion.config.getLimitMaxY()) {
- Notification.error(operator, "领地Y坐标不能超过 %s", Dominion.config.getLimitMaxY());
+ operator.setResponse(FAIL.appendMessage("领地Y坐标不能超过 %s", Dominion.config.getLimitMaxY()));
return true;
}
if (y1 < Dominion.config.getLimitMinY()) {
- Notification.error(operator, "领地Y坐标不能低于 %s", Dominion.config.getLimitMinY());
+ operator.setResponse(FAIL.appendMessage("领地Y坐标不能低于 %s", Dominion.config.getLimitMinY()));
return true;
}
return false;
}
- private static boolean depthNotValid(Player operator, DominionDTO parent_dom) {
+ private static boolean depthNotValid(AbstractOperator operator, DominionDTO parent_dom) {
+ AbstractOperator.Result FAIL = new AbstractOperator.Result(AbstractOperator.Result.FAILURE, "子领地深度不合法");
if (operator.isOp() && Dominion.config.getLimitOpBypass()) {
return false;
}
@@ -710,7 +751,7 @@ public class DominionController {
return false;
}
if (parent_dom.getId() != -1 && Dominion.config.getLimitDepth() == 0) {
- Notification.error(operator, "不允许创建子领地");
+ operator.setResponse(FAIL.appendMessage("不允许创建子领地"));
return true;
}
if (parent_dom.getId() == -1) {
@@ -722,42 +763,35 @@ public class DominionController {
level++;
}
if (level >= Dominion.config.getLimitDepth()) {
- Notification.error(operator, "子领地嵌套深度不能超过 %s", Dominion.config.getLimitDepth());
+ operator.setResponse(FAIL.appendMessage("子领地嵌套深度不能超过 %s", Dominion.config.getLimitDepth()));
return true;
}
return false;
}
- private static boolean amountNotValid(Player operator) {
+ private static boolean amountNotValid(AbstractOperator operator) {
if (operator.isOp() && Dominion.config.getLimitOpBypass()) {
return false;
}
- if (Cache.instance.getPlayerDominionCount(operator) >= Dominion.config.getLimitAmount() && Dominion.config.getLimitAmount() != -1) {
- Notification.error(operator, "你的领地数量已达上限,当前上限为 %s", Dominion.config.getLimitAmount());
- return true;
- }
- return false;
+ return Cache.instance.getPlayerDominionCount(operator.getUniqueId()) >= Dominion.config.getLimitAmount() && Dominion.config.getLimitAmount() != -1;
}
- private static boolean worldNotValid(Player operator) {
+ private static boolean worldNotValid(AbstractOperator operator, String world) {
if (operator.isOp() && Dominion.config.getLimitOpBypass()) {
return false;
}
- if (Dominion.config.getWorldBlackList().contains(operator.getWorld().getName())) {
- Notification.error(operator, "禁止在世界 %s 创建领地", operator.getWorld().getName());
- return true;
- }
- return false;
+ return Dominion.config.getWorldBlackList().contains(world);
}
- private static DominionDTO getExistDomAndIsOwner(Player operator, String dominion_name) {
+ private static DominionDTO getExistDomAndIsOwner(AbstractOperator operator, String dominion_name) {
+ AbstractOperator.Result FAIL = new AbstractOperator.Result(AbstractOperator.Result.FAILURE, "");
DominionDTO dominion = DominionDTO.select(dominion_name);
if (dominion == null) {
- Notification.error(operator, "领地 %s 不存在", dominion_name);
+ operator.setResponse(FAIL.setMessage("领地 %s 不存在", dominion_name));
return null;
}
if (notOwner(operator, dominion)) {
- Notification.error(operator, "你不是领地 %s 的拥有者,无法执行此操作", dominion_name);
+ operator.setResponse(FAIL.setMessage("你不是领地 %s 的拥有者", dominion_name));
return null;
}
return dominion;
diff --git a/src/main/java/cn/lunadeer/dominion/controllers/FlagsController.java b/src/main/java/cn/lunadeer/dominion/controllers/FlagsController.java
index 90ab241..6a6848d 100644
--- a/src/main/java/cn/lunadeer/dominion/controllers/FlagsController.java
+++ b/src/main/java/cn/lunadeer/dominion/controllers/FlagsController.java
@@ -17,10 +17,11 @@ public class FlagsController {
* @param value 权限值
* @return 设置后的领地信息
*/
- public static DominionDTO setFlag(Player operator, String flag, boolean value) {
+ public static void setFlag(AbstractOperator operator, String flag, boolean value) {
DominionDTO dominion = Apis.getPlayerCurrentDominion(operator);
- if (dominion == null) return null;
- return setFlag(operator, flag, value, dominion.getName());
+ if (dominion == null) return;
+ setFlag(operator, flag, value, dominion.getName());
+ operator.setResponse(new AbstractOperator.Result(AbstractOperator.Result.SUCCESS, "设置领地权限 %s 为 %s", flag, value));
}
/**
@@ -32,18 +33,19 @@ public class FlagsController {
* @param dominionName 领地名称
* @return 设置后的领地信息
*/
- public static DominionDTO setFlag(Player operator, String flag, boolean value, String dominionName) {
+ public static void setFlag(AbstractOperator operator, String flag, boolean value, String dominionName) {
DominionDTO dominion = DominionDTO.select(dominionName);
if (dominion == null) {
- Notification.error(operator, "领地 %s 不存在", dominionName);
- return null;
+ operator.setResponse(new AbstractOperator.Result(AbstractOperator.Result.FAILURE, "领地 %s 不存在", dominionName));
+ return;
}
- if (noAuthToChangeFlags(operator, dominion)) return null;
+ if (noAuthToChangeFlags(operator, dominion)) return;
Flag f = Flag.getFlag(flag);
if (f == null) {
- Notification.error(operator, "未知的领地权限 %s", flag);
- return null;
+ operator.setResponse(new AbstractOperator.Result(AbstractOperator.Result.FAILURE, "未知的领地权限 %s", flag));
+ return;
}
- return dominion.setFlagValue(f, value);
+ dominion.setFlagValue(f, value);
+ operator.setResponse(new AbstractOperator.Result(AbstractOperator.Result.SUCCESS, "设置领地权限 %s 为 %s", flag, value));
}
}
diff --git a/src/main/java/cn/lunadeer/dominion/controllers/PrivilegeController.java b/src/main/java/cn/lunadeer/dominion/controllers/PrivilegeController.java
index 250e5c0..9ccf367 100644
--- a/src/main/java/cn/lunadeer/dominion/controllers/PrivilegeController.java
+++ b/src/main/java/cn/lunadeer/dominion/controllers/PrivilegeController.java
@@ -1,5 +1,6 @@
package cn.lunadeer.dominion.controllers;
+import cn.lunadeer.dominion.Cache;
import cn.lunadeer.dominion.dtos.DominionDTO;
import cn.lunadeer.dominion.dtos.Flag;
import cn.lunadeer.dominion.dtos.PlayerDTO;
@@ -16,47 +17,57 @@ import static cn.lunadeer.dominion.controllers.Apis.notOwner;
public class PrivilegeController {
/**
- * 清空玩家特权
+ * 清空玩家成员权限
*
* @param operator 操作者
* @param player_name 玩家
* @return 是否清空成功
*/
- public static boolean clearPrivilege(Player operator, String player_name) {
+ public static void clearPrivilege(AbstractOperator operator, String player_name) {
DominionDTO dominion = Apis.getPlayerCurrentDominion(operator);
if (dominion == null) {
- Notification.error(operator, "你不在任何领地内,请指定领地名称 /dominion clear_privilege <玩家名称> <领地名称>");
- return false;
+ operator.setResponse(new AbstractOperator.Result(AbstractOperator.Result.FAILURE, "你不在任何领地内,请指定领地名称 /dominion clear_privilege <玩家名称> <领地名称>"));
+ return;
}
- return clearPrivilege(operator, player_name, dominion.getName());
+ clearPrivilege(operator, player_name, dominion.getName());
}
/**
- * 清空玩家特权
+ * 清空玩家成员权限
*
* @param operator 操作者
* @param player_name 玩家
* @param dominionName 领地名称
* @return 是否清空成功
*/
- public static boolean clearPrivilege(Player operator, String player_name, String dominionName) {
+ public static void clearPrivilege(AbstractOperator operator, String player_name, String dominionName) {
+ AbstractOperator.Result FAIL = new AbstractOperator.Result(AbstractOperator.Result.FAILURE, "清空玩家 %s 在领地 %s 的权限失败", player_name, dominionName);
DominionDTO dominion = DominionDTO.select(dominionName);
if (dominion == null) {
- Notification.error(operator, "领地 %s 不存在", dominionName);
- return false;
+ operator.setResponse(FAIL.appendMessage("领地 %s 不存在", dominionName));
+ return;
}
- if (noAuthToChangeFlags(operator, dominion)) return false;
+ if (noAuthToChangeFlags(operator, dominion)) return;
PlayerDTO player = PlayerController.getPlayerDTO(player_name);
if (player == null) {
- Notification.error(operator, "玩家 %s 不存在或没有登录过", player_name);
- return false;
+ operator.setResponse(FAIL.appendMessage("玩家 %s 不存在或没有登录过", player_name));
+ return;
+ }
+ PlayerPrivilegeDTO privilege = PlayerPrivilegeDTO.select(player.getUuid(), dominion.getId());
+ if (privilege == null) {
+ operator.setResponse(FAIL.appendMessage("玩家 %s 不是领地 %s 的成员", player_name, dominionName));
+ return;
+ }
+ if (privilege.getAdmin() && notOwner(operator, dominion)) {
+ operator.setResponse(FAIL.appendMessage("你不是领地 %s 的拥有者,无法移除一个领地管理员", dominionName));
+ return;
}
PlayerPrivilegeDTO.delete(player.getUuid(), dominion.getId());
- return true;
+ operator.setResponse(new AbstractOperator.Result(AbstractOperator.Result.SUCCESS, "清空玩家 %s 在领地 %s 的权限成功", player_name, dominionName));
}
/**
- * 设置玩家特权
+ * 设置玩家成员权限
*
* @param operator 操作者
* @param player_name 玩家
@@ -64,17 +75,17 @@ public class PrivilegeController {
* @param value 权限值
* @return 是否设置成功
*/
- public static boolean setPrivilege(Player operator, String player_name, String flag, boolean value) {
+ public static void setPrivilege(AbstractOperator operator, String player_name, String flag, boolean value) {
DominionDTO dominion = Apis.getPlayerCurrentDominion(operator);
if (dominion == null) {
- Notification.error(operator, "你不在任何领地内,请指定领地名称 /dominion set_privilege <玩家名称> <权限名称> [领地名称]");
- return false;
+ operator.setResponse(new AbstractOperator.Result(AbstractOperator.Result.FAILURE, "你不在任何领地内,请指定领地名称 /dominion set_privilege <玩家名称> <权限名称> [领地名称]"));
+ return;
}
- return setPrivilege(operator, player_name, flag, value, dominion.getName());
+ setPrivilege(operator, player_name, flag, value, dominion.getName());
}
/**
- * 设置玩家特权
+ * 设置玩家成员权限
*
* @param operator 操作者
* @param player_name 玩家
@@ -83,75 +94,82 @@ public class PrivilegeController {
* @param dominionName 领地名称
* @return 是否设置成功
*/
- public static boolean setPrivilege(Player operator, String player_name, String flag, boolean value, String dominionName) {
+ public static void setPrivilege(AbstractOperator operator, String player_name, String flag, boolean value, String dominionName) {
+ AbstractOperator.Result FAIL = new AbstractOperator.Result(AbstractOperator.Result.FAILURE, "设置玩家 %s 在领地 %s 的权限 %s 为 %s 失败", player_name, dominionName, flag, value);
DominionDTO dominion = DominionDTO.select(dominionName);
if (dominion == null) {
- Notification.error(operator, "领地 %s 不存在,无法设置特权", dominionName);
- return false;
+ operator.setResponse(FAIL.appendMessage("领地 %s 不存在", dominionName));
+ return;
}
- if (noAuthToChangeFlags(operator, dominion)) return false;
+ if (noAuthToChangeFlags(operator, dominion)) return;
PlayerDTO player = PlayerController.getPlayerDTO(player_name);
if (player == null) {
- Notification.error(operator, "玩家 %s 不存在或没有登录过", player_name);
- return false;
+ operator.setResponse(FAIL.appendMessage("玩家 %s 不存在或没有登录过", player_name));
+ return;
}
PlayerPrivilegeDTO privilege = PlayerPrivilegeDTO.select(player.getUuid(), dominion.getId());
if (privilege == null) {
privilege = createPlayerPrivilege(operator, player.getUuid(), dominion);
- if (privilege == null) return false;
+ if (privilege == null) return;
}
if (flag.equals("admin")) {
if (notOwner(operator, dominion)) {
- Notification.error(operator, "你不是领地 %s 的拥有者,无法设置其他玩家为管理员", dominionName);
- return false;
+ operator.setResponse(FAIL.appendMessage("你不是领地 %s 的拥有者,无法设置/取消其他玩家为管理员", dominionName));
+ return;
}
privilege.setAdmin(value);
} else {
Flag f = Flag.getFlag(flag);
if (f == null) {
- Notification.error(operator, "未知的领地权限 %s", flag);
- return false;
+ operator.setResponse(FAIL.appendMessage("未知的领地权限 %s", flag));
+ return;
}
privilege.setFlagValue(f, value);
}
- Notification.info(operator, "设置玩家在领地 %s 的权限 %s 为 %s", dominionName, flag, value);
- return true;
+ operator.setResponse(new AbstractOperator.Result(AbstractOperator.Result.SUCCESS, "设置玩家 %s 在领地 %s 的权限 %s 为 %s 成功", player_name, dominionName, flag, value));
}
- public static boolean createPrivilege(Player operator, String player_name) {
+ public static void createPrivilege(AbstractOperator operator, String player_name) {
DominionDTO dominion = Apis.getPlayerCurrentDominion(operator);
if (dominion == null) {
- Notification.error(operator, "你不在任何领地内,请指定领地名称 /dominion create_privilege <玩家名称> <领地名称>");
- return false;
+ operator.setResponse(new AbstractOperator.Result(AbstractOperator.Result.FAILURE, "你不在任何领地内,请指定领地名称 /dominion create_privilege <玩家名称> <领地名称>"));
+ return;
}
- return createPrivilege(operator, player_name, dominion.getName());
+ createPrivilege(operator, player_name, dominion.getName());
}
- public static boolean createPrivilege(Player operator, String player_name, String dominionName) {
+ public static void createPrivilege(AbstractOperator operator, String player_name, String dominionName) {
DominionDTO dominion = DominionDTO.select(dominionName);
if (dominion == null) {
- Notification.error(operator, "领地 %s 不存在,无法创建特权", dominionName);
- return false;
+ operator.setResponse(new AbstractOperator.Result(AbstractOperator.Result.FAILURE, "领地 %s 不存在,无法创建成员权限", dominionName));
+ return;
}
- if (noAuthToChangeFlags(operator, dominion)) return false;
+ if (noAuthToChangeFlags(operator, dominion)) return;
PlayerDTO player = PlayerController.getPlayerDTO(player_name);
if (player == null) {
- Notification.error(operator, "玩家 %s 不存在或没有登录过", player_name);
- return false;
+ operator.setResponse(new AbstractOperator.Result(AbstractOperator.Result.FAILURE, "玩家 %s 不存在或没有登录过", player_name));
+ return;
+ }
+ if (createPlayerPrivilege(operator, player.getUuid(), dominion) != null) {
+ operator.setResponse(new AbstractOperator.Result(AbstractOperator.Result.SUCCESS, "创建玩家 %s 在领地 %s 的成员权限成功", player_name, dominionName));
}
- return createPlayerPrivilege(operator, player.getUuid(), dominion) != null;
}
- private static PlayerPrivilegeDTO createPlayerPrivilege(Player operator, UUID player, DominionDTO dom) {
+ private static PlayerPrivilegeDTO createPlayerPrivilege(AbstractOperator operator, UUID player, DominionDTO dom) {
XLogger.debug("operator: " + operator.getUniqueId() + " player: " + player);
if (operator.getUniqueId().equals(player)) {
- Notification.error(operator, "你不能给自己设置特权");
+ operator.setResponse(new AbstractOperator.Result(AbstractOperator.Result.FAILURE, "你不能给自己设置成员权限"));
return null;
}
- PlayerPrivilegeDTO privilege = new PlayerPrivilegeDTO(player, dom);
- privilege = PlayerPrivilegeDTO.insert(privilege);
+ PlayerDTO playerDTO = PlayerDTO.select(player);
+ PlayerPrivilegeDTO privilege = Cache.instance.getPlayerPrivilege(player, dom);
+ if (privilege != null) {
+ operator.setResponse(new AbstractOperator.Result(AbstractOperator.Result.FAILURE, "创建玩家成员权限失败,玩家 %s 已经是领地 %s 的成员", playerDTO.getLastKnownName(), dom.getName()));
+ return null;
+ }
+ privilege = PlayerPrivilegeDTO.insert(new PlayerPrivilegeDTO(player, dom));
if (privilege == null) {
- Notification.error(operator, "创建玩家特权失败,可能是此玩家已存在特权");
+ operator.setResponse(new AbstractOperator.Result(AbstractOperator.Result.FAILURE, "创建玩家成员权限失败,请联系管理员"));
return null;
}
return privilege;
diff --git a/src/main/java/cn/lunadeer/dominion/tuis/Apis.java b/src/main/java/cn/lunadeer/dominion/tuis/Apis.java
index 7ca3519..e4f8564 100644
--- a/src/main/java/cn/lunadeer/dominion/tuis/Apis.java
+++ b/src/main/java/cn/lunadeer/dominion/tuis/Apis.java
@@ -1,5 +1,6 @@
package cn.lunadeer.dominion.tuis;
+import cn.lunadeer.dominion.Cache;
import cn.lunadeer.dominion.dtos.DominionDTO;
import cn.lunadeer.dominion.dtos.PlayerPrivilegeDTO;
import cn.lunadeer.minecraftpluginutils.Notification;
@@ -38,7 +39,7 @@ public class Apis {
if (args.length >= 2) {
return DominionDTO.select(args[1]);
} else {
- return getPlayerCurrentDominion(player);
+ return Cache.instance.getPlayerCurrentDominion(player);
}
}
@@ -54,7 +55,7 @@ public class Apis {
if (args.length >= 3) {
return DominionDTO.select(args[2]);
} else {
- return getPlayerCurrentDominion(player);
+ return Cache.instance.getPlayerCurrentDominion(player);
}
}
diff --git a/src/main/java/cn/lunadeer/dominion/tuis/DominionPrivilegeList.java b/src/main/java/cn/lunadeer/dominion/tuis/DominionPrivilegeList.java
index 14bbc5a..488d059 100644
--- a/src/main/java/cn/lunadeer/dominion/tuis/DominionPrivilegeList.java
+++ b/src/main/java/cn/lunadeer/dominion/tuis/DominionPrivilegeList.java
@@ -48,11 +48,12 @@ public class DominionPrivilegeList {
for (PlayerPrivilegeDTO privilege : privileges) {
PlayerDTO p_player = PlayerDTO.select(privilege.getPlayerUUID());
if (p_player == null) continue;
- view.add(Line.create()
+ Line line = Line.create()
.append(p_player.getLastKnownName())
- .append(Button.createGreen("配置权限").setExecuteCommand("/dominion privilege_info " + p_player.getLastKnownName() + " " + dominion.getName()).build())
- .append(Button.createRed("移除成员").setExecuteCommand("/dominion clear_privilege " + p_player.getLastKnownName() + " " + dominion.getName() + " b").build())
- );
+ .append(Button.createGreen("配置权限").setExecuteCommand("/dominion privilege_info " + p_player.getLastKnownName() + " " + dominion.getName()).build());
+ if (!player.getName().equals(p_player.getLastKnownName()) && !privilege.getAdmin())
+ line.append(Button.createRed("移除成员").setExecuteCommand("/dominion clear_privilege " + p_player.getLastKnownName() + " " + dominion.getName() + " b").build());
+ view.add(line);
}
view.showOn(player, page);
}
diff --git a/src/main/java/cn/lunadeer/dominion/tuis/ListDominion.java b/src/main/java/cn/lunadeer/dominion/tuis/ListDominion.java
index b7bad99..8245ab8 100644
--- a/src/main/java/cn/lunadeer/dominion/tuis/ListDominion.java
+++ b/src/main/java/cn/lunadeer/dominion/tuis/ListDominion.java
@@ -33,7 +33,7 @@ public class ListDominion {
view.add(Line.create().append(Component.text("-= 以下为你拥有管理员权限的领地 =-", ViewStyles.main_color)));
for (String dominion : admin_dominions) {
TextComponent manage = Button.createGreen("管理").setExecuteCommand("/dominion manage " + dominion).build();
- view.add(Line.create().append(dominion).append(manage));
+ view.add(Line.create().append(manage).append(dominion));
}
view.showOn(player, page);
}
@@ -47,7 +47,7 @@ public class ListDominion {
for (DominionNode node : dominionTree) {
TextComponent manage = Button.createGreen("管理").setExecuteCommand("/dominion manage " + node.dominion.getName()).build();
TextComponent delete = Button.createRed("删除").setExecuteCommand("/dominion delete " + node.dominion.getName()).build();
- Line line = Line.create().append(prefix + node.dominion.getName()).append(manage).append(delete);
+ Line line = Line.create().append(delete).append(manage).append(prefix + node.dominion.getName());
lines.add(line);
lines.addAll(BuildTreeLines(node.children, depth + 1));
}