修复了领地管理员权限组可能无法管理领地玩家的问题
All checks were successful
Java CI-CD with Gradle / build (push) Successful in 5m11s

This commit is contained in:
zhangyuheng 2024-08-22 10:44:49 +08:00
parent 0cb2ac81d4
commit 150939dc45
3 changed files with 28 additions and 6 deletions

View File

@ -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))

View File

@ -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;
}

View File

@ -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();
}
}
}