完成了 GroupController i18n

This commit is contained in:
zhangyuheng 2024-09-03 01:27:00 +08:00
parent 8773fd35d2
commit 2ecab82905
4 changed files with 112 additions and 54 deletions

View File

@ -182,7 +182,7 @@ public class DominionController {
}
dominion = DominionDTO.insert(dominion);
if (dominion == null) {
operator.setResponse(FAIL.addMessage(Translation.Controller_CreateDominionDatabaseError));
operator.setResponse(FAIL.addMessage(Translation.Controller_DatabaseError));
return;
}
// 显示粒子效果

View File

@ -2,6 +2,7 @@ package cn.lunadeer.dominion.controllers;
import cn.lunadeer.dominion.dtos.DominionDTO;
import cn.lunadeer.dominion.dtos.Flag;
import cn.lunadeer.dominion.managers.Translation;
import cn.lunadeer.dominion.utils.ControllerUtils;
import static cn.lunadeer.dominion.utils.ControllerUtils.noAuthToChangeFlags;
@ -19,7 +20,7 @@ public class FlagsController {
DominionDTO dominion = ControllerUtils.getPlayerCurrentDominion(operator);
if (dominion == null) return;
setFlag(operator, flag, value, dominion.getName());
operator.setResponse(new AbstractOperator.Result(AbstractOperator.Result.SUCCESS, "设置领地权限 %s 为 %s", flag, value));
operator.setResponse(new AbstractOperator.Result(AbstractOperator.Result.SUCCESS, Translation.Controller_SetDominionFlagSuccess, flag, value));
}
/**
@ -33,16 +34,16 @@ public class FlagsController {
public static void setFlag(AbstractOperator operator, String flag, boolean value, String dominionName) {
DominionDTO dominion = DominionDTO.select(dominionName);
if (dominion == null) {
operator.setResponse(new AbstractOperator.Result(AbstractOperator.Result.FAILURE, "领地 %s 不存在", dominionName));
operator.setResponse(new AbstractOperator.Result(AbstractOperator.Result.FAILURE, Translation.Controller_DominionNotExist, dominionName));
return;
}
if (noAuthToChangeFlags(operator, dominion)) return;
Flag f = Flag.getFlag(flag);
if (f == null) {
operator.setResponse(new AbstractOperator.Result(AbstractOperator.Result.FAILURE, "未知的领地权限 %s", flag));
operator.setResponse(new AbstractOperator.Result(AbstractOperator.Result.FAILURE, Translation.Controller_UnknownFlag, flag));
return;
}
dominion.setFlagValue(f, value);
operator.setResponse(new AbstractOperator.Result(AbstractOperator.Result.SUCCESS, "设置领地权限 %s 为 %s", flag, value));
operator.setResponse(new AbstractOperator.Result(AbstractOperator.Result.SUCCESS, Translation.Controller_SetDominionFlagSuccess, flag, value));
}
}

View File

@ -1,6 +1,7 @@
package cn.lunadeer.dominion.controllers;
import cn.lunadeer.dominion.dtos.*;
import cn.lunadeer.dominion.managers.Translation;
import java.util.Objects;
@ -18,29 +19,29 @@ public class GroupController {
* @param nameColored 权限组名称带颜色
*/
public static void createGroup(AbstractOperator operator, String domName, String groupName, String nameColored) {
AbstractOperator.Result FAIL = new AbstractOperator.Result(AbstractOperator.Result.FAILURE, "创建权限组 %s 失败", groupName);
AbstractOperator.Result SUCCESS = new AbstractOperator.Result(AbstractOperator.Result.SUCCESS, "创建权限组 %s 成功", groupName);
AbstractOperator.Result FAIL = new AbstractOperator.Result(AbstractOperator.Result.FAILURE, Translation.Controller_CreateGroupFailed, groupName);
AbstractOperator.Result SUCCESS = new AbstractOperator.Result(AbstractOperator.Result.SUCCESS, Translation.Controller_CreateGroupSuccess, groupName);
if (groupName.contains(" ")) {
operator.setResponse(FAIL.addMessage("权限组名称不能包含空格"));
operator.setResponse(FAIL.addMessage(Translation.Controller_GroupNameInvalid));
return;
}
DominionDTO dominion = DominionDTO.select(domName);
if (dominion == null) {
operator.setResponse(FAIL.addMessage("领地 %s 不存在", domName));
operator.setResponse(FAIL.addMessage(Translation.Controller_DominionNotExist, domName));
return;
}
if (notOwner(operator, dominion)) {
operator.setResponse(FAIL.addMessage("你不是领地 %s 的拥有者,无法创建权限组", domName));
operator.setResponse(FAIL.addMessage(Translation.Controller_NotDominionOwner, domName));
return;
}
GroupDTO group = GroupDTO.select(dominion.getId(), groupName);
if (group != null) {
operator.setResponse(FAIL.addMessage("领地 %s 已存在名为 %s 的权限组", domName, groupName));
operator.setResponse(FAIL.addMessage(Translation.Controller_GroupNameExist, domName, groupName));
return;
}
group = GroupDTO.create(nameColored, dominion);
if (group == null) {
operator.setResponse(FAIL.addMessage("请联系服务器管理员"));
operator.setResponse(FAIL.addMessage(Translation.Controller_DatabaseError));
return;
}
operator.setResponse(SUCCESS);
@ -54,20 +55,20 @@ public class GroupController {
* @param groupName 权限组名称
*/
public static void deleteGroup(AbstractOperator operator, String domName, String groupName) {
AbstractOperator.Result FAIL = new AbstractOperator.Result(AbstractOperator.Result.FAILURE, "删除权限组 %s 失败", groupName);
AbstractOperator.Result SUCCESS = new AbstractOperator.Result(AbstractOperator.Result.SUCCESS, "删除权限组 %s 成功", groupName);
AbstractOperator.Result FAIL = new AbstractOperator.Result(AbstractOperator.Result.FAILURE, Translation.Controller_DeleteGroupFailed, groupName);
AbstractOperator.Result SUCCESS = new AbstractOperator.Result(AbstractOperator.Result.SUCCESS, Translation.Controller_DeleteGroupSuccess, groupName);
DominionDTO dominion = DominionDTO.select(domName);
if (dominion == null) {
operator.setResponse(FAIL.addMessage("领地 %s 不存在", domName));
operator.setResponse(FAIL.addMessage(Translation.Controller_DominionNotExist, domName));
return;
}
if (notOwner(operator, dominion)) {
operator.setResponse(FAIL.addMessage("你不是领地 %s 的拥有者,无法删除权限组", domName));
operator.setResponse(FAIL.addMessage(Translation.Controller_NotDominionOwner, domName));
return;
}
GroupDTO group = GroupDTO.select(dominion.getId(), groupName);
if (group == null) {
operator.setResponse(FAIL.addMessage("领地 %s 不存在名为 %s 的权限组", domName, groupName));
operator.setResponse(FAIL.addMessage(Translation.Controller_GroupNotExist, domName, groupName));
return;
}
group.delete();
@ -84,11 +85,11 @@ public class GroupController {
* @param value 权限值
*/
public static void setGroupFlag(AbstractOperator operator, String domName, String groupName, String flag, boolean value) {
AbstractOperator.Result FAIL = new AbstractOperator.Result(AbstractOperator.Result.FAILURE, "设置权限组 %s 的权限 %s 为 %s 失败", groupName, flag, value);
AbstractOperator.Result SUCCESS = new AbstractOperator.Result(AbstractOperator.Result.SUCCESS, "设置权限组 %s 的权限 %s 为 %s 成功", groupName, flag, value);
AbstractOperator.Result FAIL = new AbstractOperator.Result(AbstractOperator.Result.FAILURE, Translation.Controller_SetGroupFlagFailed, groupName, flag, value);
AbstractOperator.Result SUCCESS = new AbstractOperator.Result(AbstractOperator.Result.SUCCESS, Translation.Controller_SetGroupFlagSuccess, groupName, flag, value);
DominionDTO dominion = DominionDTO.select(domName);
if (dominion == null) {
operator.setResponse(FAIL.addMessage("领地 %s 不存在", domName));
operator.setResponse(FAIL.addMessage(Translation.Controller_DominionNotExist, domName));
return;
}
if (noAuthToChangeFlags(operator, dominion)) {
@ -96,11 +97,11 @@ public class GroupController {
}
GroupDTO group = GroupDTO.select(dominion.getId(), groupName);
if (group == null) {
operator.setResponse(FAIL.addMessage("领地 %s 不存在名为 %s 的权限组", domName, groupName));
operator.setResponse(FAIL.addMessage(Translation.Controller_GroupNotExist, domName, groupName));
return;
}
if ((flag.equals("admin") || group.getAdmin()) && notOwner(operator, dominion)) {
operator.setResponse(FAIL.addMessage("你不是领地 %s 的拥有者,无法修改管理员权限组权限", domName));
operator.setResponse(FAIL.addMessage(Translation.Controller_NotDominionOwnerForGroup, domName));
return;
}
if (flag.equals("admin")) {
@ -108,13 +109,13 @@ public class GroupController {
} else {
Flag f = Flag.getFlag(flag);
if (f == null) {
operator.setResponse(FAIL.addMessage("未知的权限 %s", flag));
operator.setResponse(FAIL.addMessage(Translation.Controller_UnknownFlag, flag));
return;
}
group = group.setFlagValue(f, value);
}
if (group == null) {
operator.setResponse(FAIL.addMessage("请联系服务器管理员"));
operator.setResponse(FAIL.addMessage(Translation.Controller_DatabaseError));
return;
}
operator.setResponse(SUCCESS);
@ -130,29 +131,29 @@ public class GroupController {
* @param nameColored 新名称带颜色
*/
public static void renameGroup(AbstractOperator operator, String domName, String oldName, String newName, String nameColored) {
AbstractOperator.Result FAIL = new AbstractOperator.Result(AbstractOperator.Result.FAILURE, "重命名权限组 %s 为 %s 失败", oldName, newName);
AbstractOperator.Result SUCCESS = new AbstractOperator.Result(AbstractOperator.Result.SUCCESS, "重命名权限组 %s 为 %s 成功", oldName, newName);
AbstractOperator.Result FAIL = new AbstractOperator.Result(AbstractOperator.Result.FAILURE, Translation.Controller_RenameGroupFailed, oldName, newName);
AbstractOperator.Result SUCCESS = new AbstractOperator.Result(AbstractOperator.Result.SUCCESS, Translation.Controller_RenameGroupSuccess, oldName, newName);
if (newName.contains(" ")) {
operator.setResponse(FAIL.addMessage("权限组名称不能包含空格"));
operator.setResponse(FAIL.addMessage(Translation.Controller_GroupNameInvalid));
return;
}
DominionDTO dominion = DominionDTO.select(domName);
if (dominion == null) {
operator.setResponse(FAIL.addMessage("领地 %s 不存在", domName));
operator.setResponse(FAIL.addMessage(Translation.Controller_DominionNotExist, domName));
return;
}
if (notOwner(operator, dominion)) {
operator.setResponse(FAIL.addMessage("你不是领地 %s 的拥有者,无法重命名权限组", domName));
operator.setResponse(FAIL.addMessage(Translation.Controller_NotDominionOwner, domName));
return;
}
GroupDTO group = GroupDTO.select(dominion.getId(), oldName);
if (group == null) {
operator.setResponse(FAIL.addMessage("领地 %s 不存在名为 %s 的权限组", domName, oldName));
operator.setResponse(FAIL.addMessage(Translation.Controller_GroupNotExist, domName, oldName));
return;
}
group = group.setName(nameColored);
if (group == null) {
operator.setResponse(FAIL.addMessage("请联系服务器管理员"));
operator.setResponse(FAIL.addMessage(Translation.Controller_DatabaseError));
return;
}
operator.setResponse(SUCCESS);
@ -167,47 +168,47 @@ public class GroupController {
* @param playerName 玩家名称
*/
public static void addMember(AbstractOperator operator, String domName, String groupName, String playerName) {
AbstractOperator.Result FAIL = new AbstractOperator.Result(AbstractOperator.Result.FAILURE, "添加成员 %s 到权限组 %s 失败", playerName, groupName);
AbstractOperator.Result SUCCESS = new AbstractOperator.Result(AbstractOperator.Result.SUCCESS, "添加成员 %s 到权限组 %s 成功", playerName, groupName);
AbstractOperator.Result FAIL = new AbstractOperator.Result(AbstractOperator.Result.FAILURE, Translation.Controller_AddGroupMemberFailed, playerName, groupName);
AbstractOperator.Result SUCCESS = new AbstractOperator.Result(AbstractOperator.Result.SUCCESS, Translation.Controller_AddGroupMemberSuccess, playerName, groupName);
DominionDTO dominion = DominionDTO.select(domName);
if (dominion == null) {
operator.setResponse(FAIL.addMessage("领地 %s 不存在", domName));
operator.setResponse(FAIL.addMessage(Translation.Controller_DominionNotExist, domName));
return;
}
GroupDTO group = GroupDTO.select(dominion.getId(), groupName);
if (group == null) {
operator.setResponse(FAIL.addMessage("领地 %s 不存在名为 %s 的权限组", domName, groupName));
operator.setResponse(FAIL.addMessage(Translation.Controller_GroupNotExist, domName, groupName));
return;
}
if (noAuthToChangeFlags(operator, dominion)) {
operator.setResponse(FAIL.addMessage("你没有权限修改领地 %s 的权限组 %s 成员", domName, groupName));
operator.setResponse(FAIL.addMessage(Translation.Controller_NoPermissionForGroupMember, domName, groupName));
return;
}
if (group.getAdmin() && notOwner(operator, dominion)) {
operator.setResponse(FAIL.addMessage("你不是领地 %s 的拥有者,无法添加成员到管理员权限组", domName));
operator.setResponse(FAIL.addMessage(Translation.Controller_NotDominionOwnerForGroupMember, domName));
return;
}
PlayerDTO player = PlayerDTO.select(playerName);
if (player == null) {
operator.setResponse(FAIL.addMessage("玩家 %s 不存在", playerName));
operator.setResponse(FAIL.addMessage(Translation.Controller_PlayerNotExist, playerName));
return;
}
MemberDTO privilege = MemberDTO.select(player.getUuid(), dominion.getId());
if (privilege == null) {
operator.setResponse(FAIL.addMessage("玩家 %s 不是领地 %s 的成员,无法直接加入权限组", playerName, domName));
operator.setResponse(FAIL.addMessage(Translation.Controller_PlayerNotDominionMember, playerName, domName));
return;
}
if (Objects.equals(privilege.getGroupId(), group.getId())) {
operator.setResponse(FAIL.addMessage("玩家 %s 已在权限组 %s 中", playerName, groupName));
operator.setResponse(FAIL.addMessage(Translation.Controller_PlayerAlreadyInGroup, playerName, groupName));
return;
}
if (notOwner(operator, dominion) && privilege.getAdmin()) {
operator.setResponse(FAIL.addMessage("%s 是管理员,你不是领地 %s 的拥有者,无法添加管理员到权限组", playerName, domName));
operator.setResponse(FAIL.addMessage(Translation.Controller_PlayerIsOwnerForGroupMember, playerName, domName));
return;
}
privilege = privilege.setGroupId(group.getId());
if (privilege == null) {
operator.setResponse(FAIL.addMessage("请联系服务器管理员"));
operator.setResponse(FAIL.addMessage(Translation.Controller_DatabaseError));
return;
}
operator.setResponse(SUCCESS);
@ -222,43 +223,43 @@ public class GroupController {
* @param playerName 玩家名称
*/
public static void removeMember(AbstractOperator operator, String domName, String groupName, String playerName) {
AbstractOperator.Result FAIL = new AbstractOperator.Result(AbstractOperator.Result.FAILURE, "从权限组 %s 移除成员 %s 失败", groupName, playerName);
AbstractOperator.Result SUCCESS = new AbstractOperator.Result(AbstractOperator.Result.SUCCESS, "从权限组 %s 移除成员 %s 成功", groupName, playerName);
AbstractOperator.Result FAIL = new AbstractOperator.Result(AbstractOperator.Result.FAILURE, Translation.Controller_RemoveGroupMemberFailed, groupName, playerName);
AbstractOperator.Result SUCCESS = new AbstractOperator.Result(AbstractOperator.Result.SUCCESS, Translation.Controller_RemoveGroupMemberSuccess, groupName, playerName);
DominionDTO dominion = DominionDTO.select(domName);
if (dominion == null) {
operator.setResponse(FAIL.addMessage("领地 %s 不存在", domName));
operator.setResponse(FAIL.addMessage(Translation.Controller_DominionNotExist, domName));
return;
}
GroupDTO group = GroupDTO.select(dominion.getId(), groupName);
if (group == null) {
operator.setResponse(FAIL.addMessage("领地 %s 不存在名为 %s 的权限组", domName, groupName));
operator.setResponse(FAIL.addMessage(Translation.Controller_GroupNotExist, domName, groupName));
return;
}
if (noAuthToChangeFlags(operator, dominion)) {
operator.setResponse(FAIL.addMessage("你没有权限移除领地 %s 的权限组 %s 成员", domName, groupName));
operator.setResponse(FAIL.addMessage(Translation.Controller_NoPermissionForRemoveGroupMember, domName, groupName));
return;
}
if (group.getAdmin() && notOwner(operator, dominion)) {
operator.setResponse(FAIL.addMessage("你不是领地 %s 的拥有者,无法从管理员权限组移除成员", domName));
operator.setResponse(FAIL.addMessage(Translation.Controller_NotDominionOwnerForRemoveGroupMember, domName));
return;
}
PlayerDTO player = PlayerDTO.select(playerName);
if (player == null) {
operator.setResponse(FAIL.addMessage("玩家 %s 不存在", playerName));
operator.setResponse(FAIL.addMessage(Translation.Controller_PlayerNotExist, playerName));
return;
}
MemberDTO privilege = MemberDTO.select(player.getUuid(), dominion.getId());
if (privilege == null) {
operator.setResponse(FAIL.addMessage("玩家 %s 不是领地 %s 的成员", playerName, domName));
operator.setResponse(FAIL.addMessage(Translation.Controller_PlayerNotMember, playerName, domName));
return;
}
if (!Objects.equals(privilege.getGroupId(), group.getId())) {
operator.setResponse(FAIL.addMessage("玩家 %s 不在权限组 %s 中", playerName, groupName));
operator.setResponse(FAIL.addMessage(Translation.Controller_PlayerNotInGroup, playerName, groupName));
return;
}
privilege = privilege.setGroupId(-1);
if (privilege == null) {
operator.setResponse(FAIL.addMessage("请联系服务器管理员"));
operator.setResponse(FAIL.addMessage(Translation.Controller_DatabaseError));
return;
}
operator.setResponse(SUCCESS);

View File

@ -243,8 +243,8 @@ public class Translation extends Localization {
public static i18n Controller_ConflictWithSpawnProtect;
@i18nField(defaultValue = "与领地 %s 冲突")
public static i18n Controller_ConflictWithDominion;
@i18nField(defaultValue = "创建领地失败,数据库错误,请联系管理员")
public static i18n Controller_CreateDominionDatabaseError;
@i18nField(defaultValue = "数据库错误,请联系管理员")
public static i18n Controller_DatabaseError;
@i18nField(defaultValue = "无法获取你所处的领地,请指定名称")
public static i18n Controller_CannotGetDominionAuto;
@i18nField(defaultValue = "扩展领地失败")
@ -356,6 +356,62 @@ public class Translation extends Localization {
@i18nField(defaultValue = "(子领地:%s)")
public static i18n Controller_SubDominionList;
@i18nField(defaultValue = "成功设置领地权限 %s 为 %s")
public static i18n Controller_SetDominionFlagSuccess;
@i18nField(defaultValue = "未知的权限 %s")
public static i18n Controller_UnknownFlag;
@i18nField(defaultValue = "创建权限组 %s 失败")
public static i18n Controller_CreateGroupFailed;
@i18nField(defaultValue = "创建权限组 %s 成功")
public static i18n Controller_CreateGroupSuccess;
@i18nField(defaultValue = "权限组名称不能包含空格")
public static i18n Controller_GroupNameInvalid;
@i18nField(defaultValue = "领地 %s 已存在名为 %s 的权限组")
public static i18n Controller_GroupNameExist;
@i18nField(defaultValue = "删除权限组 %s 失败")
public static i18n Controller_DeleteGroupFailed;
@i18nField(defaultValue = "删除权限组 %s 成功")
public static i18n Controller_DeleteGroupSuccess;
@i18nField(defaultValue = "领地 %s 不存在名为 %s 的权限组")
public static i18n Controller_GroupNotExist;
@i18nField(defaultValue = "设置权限组 %s 的权限 %s 为 %s 失败")
public static i18n Controller_SetGroupFlagFailed;
@i18nField(defaultValue = "设置权限组 %s 的权限 %s 为 %s 成功")
public static i18n Controller_SetGroupFlagSuccess;
@i18nField(defaultValue = "你不是领地 %s 的拥有者,无法修改管理员权限组权限")
public static i18n Controller_NotDominionOwnerForGroup;
@i18nField(defaultValue = "重命名权限组 %s 为 %s 失败")
public static i18n Controller_RenameGroupFailed;
@i18nField(defaultValue = "重命名权限组 %s 为 %s 成功")
public static i18n Controller_RenameGroupSuccess;
@i18nField(defaultValue = "添加成员 %s 到权限组 %s 失败")
public static i18n Controller_AddGroupMemberFailed;
@i18nField(defaultValue = "添加成员 %s 到权限组 %s 成功")
public static i18n Controller_AddGroupMemberSuccess;
@i18nField(defaultValue = "你没有权限修改领地 %s 的权限组 %s 成员")
public static i18n Controller_NoPermissionForGroupMember;
@i18nField(defaultValue = "你不是领地 %s 的拥有者,无法添加成员到管理员权限组")
public static i18n Controller_NotDominionOwnerForGroupMember;
@i18nField(defaultValue = "玩家 %s 不是领地 %s 的成员,无法直接加入权限组")
public static i18n Controller_PlayerNotDominionMember;
@i18nField(defaultValue = "玩家 %s 已在权限组 %s 中")
public static i18n Controller_PlayerAlreadyInGroup;
@i18nField(defaultValue = "%s 是管理员,你不是领地 %s 的拥有者,无法添加管理员到权限组")
public static i18n Controller_PlayerIsOwnerForGroupMember;
@i18nField(defaultValue = "从权限组 %s 移除成员 %s 失败")
public static i18n Controller_RemoveGroupMemberFailed;
@i18nField(defaultValue = "从权限组 %s 移除成员 %s 成功")
public static i18n Controller_RemoveGroupMemberSuccess;
@i18nField(defaultValue = "你没有权限移除领地 %s 的权限组 %s 成员")
public static i18n Controller_NoPermissionForRemoveGroupMember;
@i18nField(defaultValue = "你不是领地 %s 的拥有者,无法从管理员权限组移除成员")
public static i18n Controller_NotDominionOwnerForRemoveGroupMember;
@i18nField(defaultValue = "玩家 %s 不是领地 %s 的成员")
public static i18n Controller_PlayerNotMember;
@i18nField(defaultValue = "玩家 %s 不在权限组 %s 中")
public static i18n Controller_PlayerNotInGroup;
@i18nField(defaultValue = "AutoCreateRadius 不能等于 0已重置为 10")
public static i18n Config_AutoCreateRadiusError;
@i18nField(defaultValue = "AutoCleanAfterDays 不能等于 0已重置为 180")