From 150939dc454d09e9ddbb2c2d69902e9ec55bf165 Mon Sep 17 00:00:00 2001 From: zhangyuheng Date: Thu, 22 Aug 2024 10:44:49 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BA=86=E9=A2=86=E5=9C=B0?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E5=91=98=E6=9D=83=E9=99=90=E7=BB=84=E5=8F=AF?= =?UTF-8?q?=E8=83=BD=E6=97=A0=E6=B3=95=E7=AE=A1=E7=90=86=E9=A2=86=E5=9C=B0?= =?UTF-8?q?=E7=8E=A9=E5=AE=B6=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle.kts | 2 +- .../dominion/controllers/MemberController.java | 14 +++++++++----- .../dominion/utils/ControllerUtils.java | 18 ++++++++++++++++++ 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 4d17208..716e98c 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -4,7 +4,7 @@ plugins { } group = "cn.lunadeer" -version = "2.2.1-beta" +version = "2.2.2-beta" java { toolchain.languageVersion.set(JavaLanguageVersion.of(21)) diff --git a/core/src/main/java/cn/lunadeer/dominion/controllers/MemberController.java b/core/src/main/java/cn/lunadeer/dominion/controllers/MemberController.java index 0796f01..adda408 100644 --- a/core/src/main/java/cn/lunadeer/dominion/controllers/MemberController.java +++ b/core/src/main/java/cn/lunadeer/dominion/controllers/MemberController.java @@ -2,8 +2,7 @@ package cn.lunadeer.dominion.controllers; import cn.lunadeer.dominion.dtos.*; -import static cn.lunadeer.dominion.utils.ControllerUtils.noAuthToChangeFlags; -import static cn.lunadeer.dominion.utils.ControllerUtils.notOwner; +import static cn.lunadeer.dominion.utils.ControllerUtils.*; public class MemberController { @@ -33,7 +32,7 @@ public class MemberController { operator.setResponse(FAIL.addMessage("玩家 %s 不是领地 %s 的成员", player_name, dominionName)); return; } - if (privilege.getAdmin() && notOwner(operator, dominion)) { + if (isAdmin(privilege) && notOwner(operator, dominion)) { operator.setResponse(FAIL.addMessage("你不是领地 %s 的拥有者,无法移除一个领地管理员", dominionName)); return; } @@ -69,7 +68,12 @@ public class MemberController { operator.setResponse(FAIL.addMessage("玩家 %s 不是领地 %s 的成员", player_name, dominionName)); return; } - if ((flag.equals("admin") || privilege.getAdmin()) && notOwner(operator, dominion)) { + GroupDTO group = GroupDTO.select(privilege.getGroupId()); + if (group != null) { + operator.setResponse(FAIL.addMessage("玩家 %s 属于 %s 权限组,无法单独设置权限", player_name, group.getName())); + return; + } + if ((flag.equals("admin") || isAdmin(privilege)) && notOwner(operator, dominion)) { operator.setResponse(FAIL.addMessage("你不是领地 %s 的拥有者,无法修改其他玩家管理员的权限", dominionName)); return; } @@ -141,7 +145,7 @@ public class MemberController { operator.setResponse(FAIL.addMessage("模板 %s 不存在", templateName)); return; } - if (notOwner(operator, dominion) && privilege.getAdmin()) { + if (notOwner(operator, dominion) && (isAdmin(privilege) || template.getAdmin())) { operator.setResponse(FAIL.addMessage("你不是领地 %s 的拥有者,无法修改其他管理员的权限", dominionName)); return; } diff --git a/core/src/main/java/cn/lunadeer/dominion/utils/ControllerUtils.java b/core/src/main/java/cn/lunadeer/dominion/utils/ControllerUtils.java index 3012112..1cf9cac 100644 --- a/core/src/main/java/cn/lunadeer/dominion/utils/ControllerUtils.java +++ b/core/src/main/java/cn/lunadeer/dominion/utils/ControllerUtils.java @@ -4,8 +4,10 @@ import cn.lunadeer.dominion.Cache; import cn.lunadeer.dominion.Dominion; import cn.lunadeer.dominion.controllers.AbstractOperator; import cn.lunadeer.dominion.dtos.DominionDTO; +import cn.lunadeer.dominion.dtos.GroupDTO; import cn.lunadeer.dominion.dtos.MemberDTO; import org.bukkit.Location; +import org.jetbrains.annotations.NotNull; public class ControllerUtils { @@ -51,4 +53,20 @@ public class ControllerUtils { } } + /** + * 检查一个成员是否是管理员 + * 此方法会同时尝试搜索玩家所在的权限组是否是管理员 + * + * @param member 成员权限 + * @return 是否是管理员 + */ + public static boolean isAdmin(@NotNull MemberDTO member) { + GroupDTO group = GroupDTO.select(member.getGroupId()); + if (group == null) { + return member.getAdmin(); + } else { + return group.getAdmin(); + } + } + }