Merge branch 'master' into global-teleportation

# Conflicts:
#	pom.xml
#	src/main/java/cn/lunadeer/dominion/Cache.java
#	src/main/java/cn/lunadeer/dominion/commands/DominionOperate.java
#	src/main/java/cn/lunadeer/dominion/controllers/DominionController.java
#	src/main/java/cn/lunadeer/dominion/managers/DatabaseTables.java
This commit is contained in:
zhangyuheng 2024-07-03 15:21:14 +08:00
commit 4184816569
64 changed files with 2782 additions and 932 deletions

View File

@ -39,6 +39,7 @@
- 支持经济系统(需要 Vault 前置);
- 领地区域可视化;
- 管理员可在游戏内使用TUI配置领地系统
- 支持[从 Residence 迁移](https://ssl.lunadeer.cn:14448/doc/73/)领地数据1.33.7+
<div style="text-align: center;">

View File

@ -6,7 +6,7 @@
<groupId>cn.lunadeer</groupId>
<artifactId>Dominion</artifactId>
<version>1.33.7-global-tp-beta</version>
<version>1.35.0-global-tp-beta</version>
<packaging>jar</packaging>
<name>Dominion</name>
@ -90,5 +90,10 @@
<version>v2.6.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>2.0</version>
</dependency>
</dependencies>
</project>

View File

@ -1,5 +1,7 @@
package cn.lunadeer.dominion;
import cn.lunadeer.dominion.dtos.*;
import cn.lunadeer.dominion.utils.ResMigration;
import cn.lunadeer.dominion.dtos.DominionDTO;
import cn.lunadeer.dominion.dtos.Flag;
import cn.lunadeer.dominion.dtos.PlayerDTO;
@ -27,7 +29,8 @@ public class Cache {
public Cache() {
player_current_dominion_id = new HashMap<>();
loadDominions();
loadPlayerPrivileges();
loadMembers();
loadGroups();
}
/**
@ -106,56 +109,101 @@ public class Cache {
*
* @param player_uuid 玩家UUID
*/
public void loadPlayerPrivileges(UUID player_uuid) {
if (_last_update_privilege.get() + UPDATE_INTERVAL < System.currentTimeMillis()) {
XLogger.debug("run loadPlayerPrivilegesExecution directly");
loadPlayerPrivilegesExecution(player_uuid);
public void loadMembers(UUID player_uuid) {
if (_last_update_member.get() + UPDATE_INTERVAL < System.currentTimeMillis()) {
XLogger.debug("run loadMembersExecution directly");
loadMembersExecution(player_uuid);
} else {
if (_update_privilege_is_scheduled.get()) return;
XLogger.debug("schedule loadPlayerPrivilegesExecution");
_update_privilege_is_scheduled.set(true);
long delay_tick = (UPDATE_INTERVAL - (System.currentTimeMillis() - _last_update_privilege.get())) / 1000 * 20L;
if (_update_member_is_scheduled.get()) return;
XLogger.debug("schedule loadMembersExecution");
_update_member_is_scheduled.set(true);
long delay_tick = (UPDATE_INTERVAL - (System.currentTimeMillis() - _last_update_member.get())) / 1000 * 20L;
Scheduler.runTaskLaterAsync(() -> {
XLogger.debug("run loadPlayerPrivilegesExecution scheduled");
loadPlayerPrivilegesExecution(player_uuid);
_update_privilege_is_scheduled.set(false);
XLogger.debug("run loadMembersExecution scheduled");
loadMembersExecution(player_uuid);
_update_member_is_scheduled.set(false);
},
delay_tick);
}
}
public void loadPlayerPrivileges() {
loadPlayerPrivileges(null);
public void loadMembers() {
loadMembers(null);
}
private void loadPlayerPrivilegesExecution(UUID player_to_update) {
private void loadMembersExecution(UUID player_to_update) {
Scheduler.runTaskAsync(() -> {
long start = System.currentTimeMillis();
List<PlayerPrivilegeDTO> all_privileges;
List<MemberDTO> all_privileges;
if (player_to_update == null) {
all_privileges = PlayerPrivilegeDTO.selectAll();
player_uuid_to_privilege = new ConcurrentHashMap<>();
all_privileges = MemberDTO.selectAll();
player_uuid_to_member = new ConcurrentHashMap<>();
} else {
all_privileges = PlayerPrivilegeDTO.selectAll(player_to_update);
if (!player_uuid_to_privilege.containsKey(player_to_update)) {
player_uuid_to_privilege.put(player_to_update, new ConcurrentHashMap<>());
all_privileges = MemberDTO.selectAll(player_to_update);
if (!player_uuid_to_member.containsKey(player_to_update)) {
player_uuid_to_member.put(player_to_update, new ConcurrentHashMap<>());
}
player_uuid_to_privilege.get(player_to_update).clear();
player_uuid_to_member.get(player_to_update).clear();
}
for (PlayerPrivilegeDTO privilege : all_privileges) {
for (MemberDTO privilege : all_privileges) {
UUID player_uuid = privilege.getPlayerUUID();
if (!player_uuid_to_privilege.containsKey(player_uuid)) {
player_uuid_to_privilege.put(player_uuid, new ConcurrentHashMap<>());
if (!player_uuid_to_member.containsKey(player_uuid)) {
player_uuid_to_member.put(player_uuid, new ConcurrentHashMap<>());
}
player_uuid_to_privilege.get(player_uuid).put(privilege.getDomID(), privilege);
player_uuid_to_member.get(player_uuid).put(privilege.getDomID(), privilege);
}
recheckPlayerState = true;
_last_update_privilege.set(System.currentTimeMillis());
XLogger.debug("loadPlayerPrivilegesExecution cost: %d ms for %d privileges"
_last_update_member.set(System.currentTimeMillis());
XLogger.debug("loadMembersExecution cost: %d ms for %d privileges"
, System.currentTimeMillis() - start, all_privileges.size());
});
}
public void loadGroups() {
loadGroups(null);
}
public void loadGroups(Integer groupId) {
if (_last_update_group.get() + UPDATE_INTERVAL < System.currentTimeMillis()) {
XLogger.debug("run loadGroupsExecution directly");
loadGroupExecution(groupId);
} else {
if (_update_group_is_scheduled.get()) return;
XLogger.debug("schedule loadGroupsExecution");
_update_group_is_scheduled.set(true);
long delay_tick = (UPDATE_INTERVAL - (System.currentTimeMillis() - _last_update_group.get())) / 1000 * 20L;
Scheduler.runTaskLaterAsync(() -> {
XLogger.debug("run loadGroupsExecution scheduled");
loadGroupExecution(groupId);
_update_group_is_scheduled.set(false);
},
delay_tick);
}
}
private void loadGroupExecution(Integer groupId) {
Scheduler.runTaskAsync(() -> {
long start = System.currentTimeMillis();
if (groupId == null) {
id_groups = new ConcurrentHashMap<>();
List<GroupDTO> groups = GroupDTO.selectAll();
for (GroupDTO group : groups) {
id_groups.put(group.getId(), group);
}
} else {
GroupDTO group = GroupDTO.select(groupId);
if (group == null && id_groups.containsKey(groupId)) {
id_groups.remove(groupId);
} else if (group != null) {
id_groups.put(groupId, group);
}
}
recheckPlayerState = true;
_last_update_group.set(System.currentTimeMillis());
XLogger.debug("loadGroupsExecution cost: %d ms", System.currentTimeMillis() - start);
});
}
/**
* 获取玩家当前所在领地
* 此方法会先判断缓存中是否有玩家当前所在领地如果没有则遍历所有领地判断玩家所在位置
@ -240,9 +288,18 @@ public class Cache {
player.setGlowing(false);
return;
}
PlayerPrivilegeDTO privilege = getPlayerPrivilege(player, dominion);
MemberDTO privilege = getMember(player, dominion);
if (privilege != null) {
player.setGlowing(privilege.getFlagValue(Flag.GLOW));
if (privilege.getGroupId() == -1) {
player.setGlowing(privilege.getFlagValue(Flag.GLOW));
} else {
GroupDTO group = getGroup(privilege.getGroupId());
if (group != null) {
player.setGlowing(group.getFlagValue(Flag.GLOW));
} else {
player.setGlowing(dominion.getFlagValue(Flag.GLOW));
}
}
} else {
player.setGlowing(dominion.getFlagValue(Flag.GLOW));
}
@ -268,9 +325,18 @@ public class Cache {
player.setAllowFlight(false);
return;
}
PlayerPrivilegeDTO privilege = getPlayerPrivilege(player, dominion);
MemberDTO privilege = getMember(player, dominion);
if (privilege != null) {
player.setAllowFlight(privilege.getFlagValue(Flag.FLY));
if (privilege.getGroupId() == -1) {
player.setAllowFlight(privilege.getFlagValue(Flag.FLY));
} else {
GroupDTO group = getGroup(privilege.getGroupId());
if (group != null) {
player.setAllowFlight(group.getFlagValue(Flag.FLY));
} else {
player.setAllowFlight(dominion.getFlagValue(Flag.FLY));
}
}
} else {
player.setAllowFlight(dominion.getFlagValue(Flag.FLY));
}
@ -302,6 +368,10 @@ public class Cache {
return dominionTree;
}
public GroupDTO getGroup(Integer id) {
return id_groups.get(id);
}
/**
* 获取玩家在指定领地的特权
* 如果玩家不存在特权则返回null
@ -310,14 +380,14 @@ public class Cache {
* @param dominion 领地
* @return 特权表
*/
public PlayerPrivilegeDTO getPlayerPrivilege(Player player, DominionDTO dominion) {
if (!player_uuid_to_privilege.containsKey(player.getUniqueId())) return null;
return player_uuid_to_privilege.get(player.getUniqueId()).get(dominion.getId());
public MemberDTO getMember(Player player, DominionDTO dominion) {
if (!player_uuid_to_member.containsKey(player.getUniqueId())) return null;
return player_uuid_to_member.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());
public MemberDTO getMember(UUID player_uuid, DominionDTO dominion) {
if (!player_uuid_to_member.containsKey(player_uuid)) return null;
return player_uuid_to_member.get(player_uuid).get(dominion.getId());
}
private static boolean isInDominion(@Nullable DominionDTO dominion, Player player) {
@ -345,6 +415,25 @@ public class Cache {
return count;
}
public List<ResMigration.ResidenceNode> getResidenceData(UUID player_uuid) {
if (residence_data == null) {
residence_data = new HashMap<>();
List<ResMigration.ResidenceNode> residences = ResMigration.extractFromResidence(Dominion.instance);
for (ResMigration.ResidenceNode node : residences) {
if (node == null) {
continue;
}
if (!residence_data.containsKey(node.owner)) {
XLogger.debug("residence_data put %s", node.owner);
residence_data.put(node.owner, new ArrayList<>());
}
residence_data.get(node.owner).add(node);
}
XLogger.debug("residence_data: %d", residence_data.size());
}
return residence_data.get(player_uuid);
}
public List<DominionDTO> getDominions() {
return new ArrayList<>(id_dominions.values());
}
@ -352,14 +441,19 @@ public class Cache {
public static Cache instance;
private ConcurrentHashMap<Integer, DominionDTO> id_dominions;
private ConcurrentHashMap<String, List<DominionNode>> world_dominion_tree;
private ConcurrentHashMap<UUID, ConcurrentHashMap<Integer, PlayerPrivilegeDTO>> player_uuid_to_privilege; // 玩家所有的特权
private ConcurrentHashMap<Integer, GroupDTO> id_groups;
private ConcurrentHashMap<UUID, ConcurrentHashMap<Integer, MemberDTO>> player_uuid_to_member; // 玩家所有的特权
private final Map<UUID, Integer> player_current_dominion_id; // 玩家当前所在领地
private ConcurrentHashMap<Integer, List<Integer>> dominion_children;
private final AtomicLong _last_update_dominion = new AtomicLong(0);
private final AtomicBoolean _update_dominion_is_scheduled = new AtomicBoolean(false);
private final AtomicLong _last_update_privilege = new AtomicLong(0);
private final AtomicBoolean _update_privilege_is_scheduled = new AtomicBoolean(false);
private final AtomicLong _last_update_member = new AtomicLong(0);
private final AtomicBoolean _update_member_is_scheduled = new AtomicBoolean(false);
private final AtomicLong _last_update_group = new AtomicLong(0);
private final AtomicBoolean _update_group_is_scheduled = new AtomicBoolean(false);
private static final long UPDATE_INTERVAL = 1000 * 4;
private boolean recheckPlayerState = false; // 是否需要重新检查玩家状态发光飞行
public final Map<UUID, LocalDateTime> NextTimeAllowTeleport = new java.util.HashMap<>();
private Map<UUID, List<ResMigration.ResidenceNode>> residence_data = null;
}

View File

@ -5,7 +5,15 @@ import cn.lunadeer.dominion.controllers.PlayerController;
import cn.lunadeer.dominion.cuis.*;
import cn.lunadeer.dominion.dtos.DominionDTO;
import cn.lunadeer.dominion.dtos.PlayerDTO;
import cn.lunadeer.dominion.tuis.*;
import cn.lunadeer.dominion.tuis.AllDominion;
import cn.lunadeer.dominion.tuis.Menu;
import cn.lunadeer.dominion.tuis.MigrateList;
import cn.lunadeer.dominion.tuis.SysConfig;
import cn.lunadeer.dominion.tuis.dominion.DominionList;
import cn.lunadeer.dominion.tuis.dominion.DominionManage;
import cn.lunadeer.dominion.tuis.dominion.manage.EnvSetting;
import cn.lunadeer.dominion.tuis.dominion.manage.GuestSetting;
import cn.lunadeer.dominion.tuis.dominion.manage.SizeInfo;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
@ -20,24 +28,6 @@ import java.util.List;
import static cn.lunadeer.dominion.commands.Helper.*;
public class Commands implements TabExecutor {
/*
创建领地 /dominion create <领地名称>
自动创建领地 /dominion auto_create <领地名称>
创建子领地 /dominion create_sub <子领地名称> [父领地名称]
自动创建子领地 /dominion auto_create_sub <子领地名称> [父领地名称]
扩张领地 /dominion expand [大小] [领地名称]
缩小领地 /dominion contract [大小] [领地名称]
删除领地 /dominion delete <领地名称> [force]
设置领地权限 /dominion set <权限名称> <true/false> [领地名称]
设置玩家权限 /dominion set_privilege <玩家名称> <权限名称> <true/false> [领地名称]
重置玩家权限 /dominion clear_privilege <玩家名称> [领地名称]
创建权限组 /dominion create_group <权限组名称>
删除权限组 /dominion delete_group <权限组名称>
设置权限组权限 /dominion set_group <权限组名称> <权限名称> <true/false>
设置玩家在某个领地归属的权限组 /dominion add_player <玩家名称> <权限组名称> [领地名称]
删除玩家在某个领地归属的权限组 /dominion remove_player <玩家名称> <权限组名称> [领地名称]
*/
/**
* Executes the given command, returning its success.
@ -62,19 +52,19 @@ public class Commands implements TabExecutor {
Menu.show(sender, args);
break;
case "list":
ListDominion.show(sender, args);
DominionList.show(sender, args);
break;
case "help":
cn.lunadeer.dominion.tuis.Apis.printHelp(sender, args);
break;
case "info":
DominionSizeInfo.show(sender, args);
SizeInfo.show(sender, args);
break;
case "manage":
DominionManage.show(sender, args);
break;
case "flag_info":
DominionFlagInfo.show(sender, args);
case "guest_setting":
GuestSetting.show(sender, args);
break;
case "create":
DominionOperate.createDominion(sender, args);
@ -100,24 +90,6 @@ public class Commands implements TabExecutor {
case "set":
DominionFlag.setDominionFlag(sender, args);
break;
case "create_privilege":
PlayerPrivilege.createPlayerPrivilege(sender, args);
break;
case "set_privilege":
PlayerPrivilege.setPlayerPrivilege(sender, args);
break;
case "clear_privilege":
PlayerPrivilege.clearPlayerPrivilege(sender, args);
break;
case "privilege_list":
DominionPrivilegeList.show(sender, args);
break;
case "privilege_info":
PrivilegeInfo.show(sender, args);
break;
case "select_player_create_privilege":
SelectPlayer.show(sender, args);
break;
case "set_enter_msg":
DominionOperate.setEnterMessage(sender, args);
break;
@ -145,8 +117,8 @@ public class Commands implements TabExecutor {
case "export_mca":
Operator.exportMca(sender, args);
break;
case "config":
DominionConfig.show(sender, args);
case "sys_config":
SysConfig.show(sender, args);
break;
case "set_config":
SetConfig.handler(sender, args);
@ -154,32 +126,27 @@ public class Commands implements TabExecutor {
case "all_dominion":
AllDominion.show(sender, args);
break;
case "template_list":
TemplateList.show(sender, args);
case "migrate_list":
MigrateList.show(sender, args);
break;
case "template_manage":
TemplateManage.show(sender, args);
break;
case "template_delete":
Template.deleteTemplate(sender, args);
break;
case "template_create":
Template.createTemplate(sender, args);
break;
case "template_set_flag":
Template.setTemplateFlag(sender, args);
break;
case "apply_template":
PlayerPrivilege.applyTemplate(sender, args);
break;
case "select_template":
SelectTemplate.show(sender, args);
case "migrate":
Migration.migrate(sender, args);
break;
case "set_map_color":
DominionOperate.setMapColor(sender, args);
break;
case "env_info":
DominionEnvInfo.show(sender, args);
case "env_setting":
EnvSetting.show(sender, args);
break;
// ---=== Sub Command ===---
case "member":
Member.handle(sender, args);
break;
case "group":
Group.handle(sender, args);
break;
case "template":
Template.handle(sender, args);
break;
// ---=== CUI ===---
case "cui_rename":
@ -194,8 +161,8 @@ public class Commands implements TabExecutor {
case "cui_create":
CreateDominion.open(sender, args);
break;
case "cui_create_privilege":
CreatePrivilege.open(sender, args);
case "cui_member_add":
MemberAdd.open(sender, args);
break;
case "cui_template_create":
CreateTemplate.open(sender, args);
@ -203,6 +170,12 @@ public class Commands implements TabExecutor {
case "cui_set_map_color":
SetMapColor.open(sender, args);
break;
case "cui_create_group":
CreateGroup.open(sender, args);
break;
case "cui_rename_group":
RenameGroup.open(sender, args);
break;
default:
return false;
}
@ -225,9 +198,8 @@ public class Commands implements TabExecutor {
@Override
public @Nullable List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
if (args.length == 1) {
return Arrays.asList("menu", "help", "info", "manage", "flag_info", "privilege_list",
return Arrays.asList("menu", "help", "info", "manage", "guest_setting",
"create", "auto_create", "create_sub", "auto_create_sub", "expand", "contract", "delete", "set",
"create_privilege", "set_privilege", "clear_privilege", "list", "privilege_info",
"set_enter_msg",
"set_leave_msg",
"set_tp_location",
@ -237,32 +209,35 @@ public class Commands implements TabExecutor {
"reload_cache",
"reload_config",
"export_mca",
"config",
"apply_template",
"template_list",
"template_manage",
"template_delete",
"template_create",
"template_set_flag",
"sys_config",
"all_dominion",
"set_map_color"
"set_map_color",
"member",
"group",
"template"
);
}
if (args.length > 1 && args[0].equals("member")) {
return Member.handleTab(sender, args);
}
if (args.length > 1 && args[0].equals("group")) {
return Group.handleTab(sender, args);
}
if (args.length > 1 && args[0].equals("template")) {
return Template.handleTab(sender, args);
}
if (args.length == 2) {
switch (args[0]) {
case "help":
case "list":
case "config":
case "template_list":
return Collections.singletonList("页码(可选)");
case "sys_config":
case "create":
case "auto_create":
return Collections.singletonList("输入领地名称");
case "delete":
case "info":
case "manage":
case "flag_info":
case "privilege_list":
case "guest_setting":
case "rename":
case "give":
case "set_tp_location":
@ -271,12 +246,6 @@ public class Commands implements TabExecutor {
return DominionDTO.selectAllNames();
case "set":
return dominionFlags();
case "create_privilege":
case "set_privilege":
case "clear_privilege":
case "privilege_info":
case "apply_template":
return playerNames();
case "expand":
case "contract":
return Collections.singletonList("大小(整数)");
@ -287,12 +256,6 @@ public class Commands implements TabExecutor {
return Collections.singletonList("进入提示语内容");
case "set_leave_msg":
return Collections.singletonList("离开提示语内容");
case "template_manage":
case "template_delete":
case "template_set_flag":
return allTemplates(sender);
case "template_create":
return Collections.singletonList("输入模板名称");
case "set_map_color":
return Collections.singletonList("输入颜色(16进制)");
}
@ -301,48 +264,34 @@ public class Commands implements TabExecutor {
switch (args[0]) {
case "set":
return boolOptions();
case "set_privilege":
case "template_set_flag":
return playerPrivileges();
case "expand":
case "contract":
case "clear_privilege":
case "create_privilege":
case "privilege_info":
case "auto_create_sub":
case "create_sub":
case "set_enter_msg":
case "set_leave_msg":
case "apply_template":
case "set_map_color":
return playerDominions(sender);
case "rename":
return Collections.singletonList("输入新领地名称");
case "give":
return playerNames();
case "template_manage":
return Collections.singletonList("页码(可选)");
}
}
if (args.length == 4) {
switch (args[0]) {
case "set":
return playerDominions(sender);
case "set_privilege":
case "template_set_flag":
return boolOptions();
case "apply_template":
return allTemplates(sender);
}
}
return null;
}
private static List<String> boolOptions() {
public static List<String> boolOptions() {
return Arrays.asList("true", "false");
}
private static List<String> playerNames() {
public static List<String> playerNames() {
List<PlayerDTO> players = PlayerController.allPlayers();
List<String> names = new ArrayList<>();
for (PlayerDTO player : players) {

View File

@ -62,4 +62,8 @@ public class Apis {
return false;
}
public static String CommandParser(String command, Object... args) {
return String.format(command, args);
}
}

View File

@ -3,8 +3,8 @@ package cn.lunadeer.dominion.commands;
import cn.lunadeer.dominion.controllers.BukkitPlayerOperator;
import cn.lunadeer.dominion.controllers.FlagsController;
import cn.lunadeer.dominion.dtos.Flag;
import cn.lunadeer.dominion.tuis.DominionEnvInfo;
import cn.lunadeer.dominion.tuis.DominionFlagInfo;
import cn.lunadeer.dominion.tuis.dominion.manage.EnvSetting;
import cn.lunadeer.dominion.tuis.dominion.manage.GuestSetting;
import cn.lunadeer.minecraftpluginutils.Notification;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -35,9 +35,9 @@ public class DominionFlag {
newArgs[1] = args[3];
newArgs[2] = args[4];
if (Flag.isDominionOnlyFlag(args[1])) {
DominionEnvInfo.show(sender, newArgs);
EnvSetting.show(sender, newArgs);
} else {
DominionFlagInfo.show(sender, newArgs);
GuestSetting.show(sender, newArgs);
}
} else {

View File

@ -8,6 +8,7 @@ import cn.lunadeer.dominion.dtos.DominionDTO;
import cn.lunadeer.dominion.dtos.Flag;
import cn.lunadeer.dominion.dtos.PlayerPrivilegeDTO;
import cn.lunadeer.dominion.managers.GlobalTeleport;
import cn.lunadeer.dominion.dtos.MemberDTO;
import cn.lunadeer.minecraftpluginutils.Notification;
import cn.lunadeer.minecraftpluginutils.Scheduler;
import cn.lunadeer.minecraftpluginutils.Teleport;
@ -372,7 +373,7 @@ public class DominionOperate {
return;
}
PlayerPrivilegeDTO privilegeDTO = PlayerPrivilegeDTO.select(player.getUniqueId(), dominionDTO.getId());
MemberDTO privilegeDTO = MemberDTO.select(player.getUniqueId(), dominionDTO.getId());
if (!player.getUniqueId().equals(dominionDTO.getOwner())) { // 领地所有人可以传送到自己的领地
if (privilegeDTO == null) {
if (!dominionDTO.getFlagValue(Flag.TELEPORT)) {

View File

@ -0,0 +1,261 @@
package cn.lunadeer.dominion.commands;
import cn.lunadeer.dominion.controllers.BukkitPlayerOperator;
import cn.lunadeer.dominion.controllers.GroupController;
import cn.lunadeer.dominion.tuis.dominion.manage.group.GroupList;
import cn.lunadeer.dominion.tuis.dominion.manage.group.GroupSetting;
import cn.lunadeer.dominion.tuis.dominion.manage.group.SelectMember;
import cn.lunadeer.minecraftpluginutils.Notification;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import static cn.lunadeer.dominion.Commands.boolOptions;
import static cn.lunadeer.dominion.commands.Apis.playerOnly;
import static cn.lunadeer.dominion.commands.Helper.*;
import static cn.lunadeer.dominion.tuis.Apis.getPage;
public class Group {
/**
* /dominion group create <领地名称> <权限组名称>
*
* @param sender 命令发送者
* @param args 命令参数
*/
public static void createGroup(CommandSender sender, String[] args) {
try {
if (args.length < 4) {
Notification.error(sender, "用法: /dominion group create <领地名称> <权限组名称>");
return;
}
Player player = playerOnly(sender);
if (player == null) return;
BukkitPlayerOperator operator = BukkitPlayerOperator.create(player);
String dominionName = args[2];
String groupName = args[3];
GroupController.createGroup(operator, dominionName, groupName);
GroupList.show(sender, dominionName);
} catch (Exception e) {
Notification.error(sender, e.getMessage());
}
}
/**
* /dominion group delete <领地名称> <权限组名称>
*
* @param sender 命令发送者
* @param args 命令参数
*/
public static void deleteGroup(CommandSender sender, String[] args) {
try {
if (args.length < 4) {
Notification.error(sender, "用法: /dominion group delete <领地名称> <权限组名称>");
return;
}
Player player = playerOnly(sender);
if (player == null) return;
BukkitPlayerOperator operator = BukkitPlayerOperator.create(player);
String dominionName = args[2];
String groupName = args[3];
GroupController.deleteGroup(operator, dominionName, groupName);
GroupList.show(sender, dominionName);
} catch (Exception e) {
Notification.error(sender, e.getMessage());
}
}
/**
* /dominion group rename <领地名称> <权限组旧名称> <新名称>
*
* @param sender 命令发送者
* @param args 命令参数
*/
public static void renameGroup(CommandSender sender, String[] args) {
try {
if (args.length < 5) {
Notification.error(sender, "用法: /dominion group rename <领地名称> <权限组旧名称> <新名称>");
return;
}
Player player = playerOnly(sender);
if (player == null) return;
BukkitPlayerOperator operator = BukkitPlayerOperator.create(player);
String dominionName = args[2];
String oldGroupName = args[3];
String newGroupName = args[4];
GroupController.renameGroup(operator, dominionName, oldGroupName, newGroupName);
GroupSetting.show(sender, dominionName, newGroupName);
} catch (Exception e) {
Notification.error(sender, e.getMessage());
}
}
/**
* /dominion group set_flag <领地名称> <权限组名称> <权限名称> <true|false>
*
* @param sender 命令发送者
* @param args 命令参数
*/
public static void setGroupFlag(CommandSender sender, String[] args) {
try {
if (args.length < 6) {
Notification.error(sender, "用法: /dominion group set_flag <领地名称> <权限组名称> <权限名称> <true|false>");
return;
}
Player player = playerOnly(sender);
if (player == null) return;
BukkitPlayerOperator operator = BukkitPlayerOperator.create(player);
String dominionName = args[2];
String groupName = args[3];
String flag = args[4];
boolean value = Boolean.parseBoolean(args[5]);
int page = getPage(args, 6);
GroupController.setGroupFlag(operator, dominionName, groupName, flag, value);
GroupSetting.show(sender, dominionName, groupName, page);
} catch (Exception e) {
Notification.error(sender, e.getMessage());
}
}
/**
* /dominion group add_member <领地名称> <权限组名称> <玩家名称>
*
* @param sender 命令发送者
* @param args 命令参数
*/
public static void addMember(CommandSender sender, String[] args) {
try {
if (args.length < 5) {
Notification.error(sender, "用法: /dominion group add_member <领地名称> <权限组名称> <玩家名称>");
return;
}
Player player = playerOnly(sender);
if (player == null) return;
BukkitPlayerOperator operator = BukkitPlayerOperator.create(player);
String dominionName = args[2];
String groupName = args[3];
String playerName = args[4];
int page = getPage(args, 5);
GroupController.addMember(operator, dominionName, groupName, playerName);
GroupList.show(sender, dominionName, page);
} catch (Exception e) {
Notification.error(sender, e.getMessage());
}
}
/**
* /dominion group remove_member <领地名称> <权限组名称> <玩家名称>
*
* @param sender 命令发送者
* @param args 命令参数
*/
public static void removeMember(CommandSender sender, String[] args) {
try {
if (args.length < 5) {
Notification.error(sender, "用法: /dominion group remove_member <领地名称> <权限组名称> <玩家名称>");
return;
}
Player player = playerOnly(sender);
if (player == null) return;
BukkitPlayerOperator operator = BukkitPlayerOperator.create(player);
String dominionName = args[2];
String groupName = args[3];
String playerName = args[4];
int page = getPage(args, 5);
GroupController.removeMember(operator, dominionName, groupName, playerName);
GroupList.show(sender, dominionName, page);
} catch (Exception e) {
Notification.error(sender, e.getMessage());
}
}
public static void handle(@NotNull CommandSender sender, @NotNull String[] args) {
switch (args[1]) {
case "create":
createGroup(sender, args);
break;
case "delete":
deleteGroup(sender, args);
break;
case "rename":
renameGroup(sender, args);
break;
case "set_flag":
setGroupFlag(sender, args);
break;
case "add_member":
addMember(sender, args);
break;
case "remove_member":
removeMember(sender, args);
break;
case "select_member":
SelectMember.show(sender, args);
break;
case "setting":
GroupSetting.show(sender, args);
break;
case "list":
GroupList.show(sender, args);
break;
}
}
public static @Nullable List<String> handleTab(@NotNull CommandSender sender, @NotNull String[] args) {
if (args.length == 2) {
return Arrays.asList("create", "delete", "rename", "set_flag", "add_member", "remove_member",
"select_member", "list");
}
if (args.length == 3) {
switch (args[1]) {
case "create":
case "delete":
case "rename":
case "set_flag":
case "add_member":
case "remove_member":
case "select_member":
case "setting":
case "list":
return playerDominions(sender);
}
}
if (args.length == 4) {
switch (args[1]) {
case "create":
return Collections.singletonList("新权限组名称");
case "delete":
case "rename":
case "set_flag":
case "add_member":
case "remove_member":
case "select_member":
case "setting":
return dominionGroups(args[2]);
}
}
if (args.length == 5) {
switch (args[1]) {
case "rename":
return Collections.singletonList("权限组新名称");
case "set_flag":
return playerPrivileges();
case "remove_member":
return groupPlayers(args[2], args[3]);
}
}
if (args.length == 6) {
switch (args[1]) {
case "set_flag":
return boolOptions();
}
}
return null;
}
}

View File

@ -1,10 +1,7 @@
package cn.lunadeer.dominion.commands;
import cn.lunadeer.dominion.controllers.DominionController;
import cn.lunadeer.dominion.dtos.DominionDTO;
import cn.lunadeer.dominion.dtos.Flag;
import cn.lunadeer.dominion.dtos.PlayerPrivilegeDTO;
import cn.lunadeer.dominion.dtos.PrivilegeTemplateDTO;
import cn.lunadeer.dominion.dtos.*;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -41,6 +38,32 @@ public class Helper {
return dominions_name;
}
public static List<String> dominionGroups(String dominionName) {
List<String> groups_name = new ArrayList<>();
DominionDTO dominion = DominionDTO.select(dominionName);
if (dominion == null) return groups_name;
List<GroupDTO> groups = GroupDTO.selectByDominionId(dominion.getId());
for (GroupDTO group : groups) {
groups_name.add(group.getName());
}
return groups_name;
}
public static List<String> groupPlayers(String domName, String groupName) {
List<String> players_name = new ArrayList<>();
DominionDTO dominion = DominionDTO.select(domName);
if (dominion == null) return players_name;
GroupDTO group = GroupDTO.select(dominion.getId(), groupName);
if (group == null) return players_name;
List<MemberDTO> privileges = MemberDTO.selectByDomGroupId(dominion.getId(), group.getId());
for (MemberDTO privilege : privileges) {
PlayerDTO player = PlayerDTO.select(privilege.getPlayerUUID());
if (player == null) continue;
players_name.add(player.getLastKnownName());
}
return players_name;
}
public static List<String> playerOwnDominions(CommandSender sender) {
List<String> dominions_name = new ArrayList<>();
Player player = playerOnly(sender);
@ -56,8 +79,8 @@ public class Helper {
List<String> dominions_name = new ArrayList<>();
Player player = playerOnly(sender);
if (player == null) return dominions_name;
List<PlayerPrivilegeDTO> dominions_admin = PlayerPrivilegeDTO.selectAll(player.getUniqueId());
for (PlayerPrivilegeDTO privilege : dominions_admin) {
List<MemberDTO> dominions_admin = MemberDTO.selectAll(player.getUniqueId());
for (MemberDTO privilege : dominions_admin) {
if (privilege.getAdmin()) {
DominionDTO dom = DominionDTO.select(privilege.getDomID());
if (dom == null) continue;

View File

@ -0,0 +1,210 @@
package cn.lunadeer.dominion.commands;
import cn.lunadeer.dominion.controllers.BukkitPlayerOperator;
import cn.lunadeer.dominion.controllers.MemberController;
import cn.lunadeer.dominion.tuis.dominion.manage.member.MemberList;
import cn.lunadeer.dominion.tuis.dominion.manage.member.MemberSetting;
import cn.lunadeer.dominion.tuis.dominion.manage.member.SelectPlayer;
import cn.lunadeer.dominion.tuis.dominion.manage.member.SelectTemplate;
import cn.lunadeer.minecraftpluginutils.Notification;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import static cn.lunadeer.dominion.Commands.boolOptions;
import static cn.lunadeer.dominion.Commands.playerNames;
import static cn.lunadeer.dominion.commands.Apis.playerOnly;
import static cn.lunadeer.dominion.commands.Helper.*;
public class Member {
/**
* 创建玩家特权
* /dominion member add <领地名称> <玩家名称>
*
* @param sender 命令发送者
* @param args 命令参数
*/
public static void member_add(CommandSender sender, String[] args) {
try {
if (args.length < 4) {
Notification.error(sender, "用法: /dominion member add <领地名称> <玩家名称>");
return;
}
Player player = playerOnly(sender);
if (player == null) return;
BukkitPlayerOperator operator = BukkitPlayerOperator.create(player);
String dominionName = args[2];
String playerName = args[3];
MemberController.memberAdd(operator, dominionName, playerName);
MemberList.show(sender, dominionName);
} catch (Exception e) {
Notification.error(sender, e.getMessage());
}
}
/**
* 设置玩家权限
* /dominion member set_flag <领地名称> <玩家名称> <权限名称> <true/false>
*
* @param sender 命令发送者
* @param args 命令参数
*/
public static void member_set_flag(CommandSender sender, String[] args) {
try {
if (args.length < 6) {
Notification.error(sender, "用法: /dominion member set_flag <领地名称> <玩家名称> <权限名称> <true/false>");
return;
}
Player player = playerOnly(sender);
if (player == null) return;
BukkitPlayerOperator operator = BukkitPlayerOperator.create(player);
String dominionName = args[2];
String playerName = args[3];
String flagName = args[4];
boolean flagValue = Boolean.parseBoolean(args[5]);
Integer page = args.length == 7 ? Integer.parseInt(args[6]) : 1;
MemberController.setMemberFlag(operator, dominionName, playerName, flagName, flagValue);
MemberSetting.show(sender, dominionName, playerName, page);
} catch (Exception e) {
Notification.error(sender, e.getMessage());
}
}
/**
* 重置玩家权限
* /dominion member remove <领地名称> <玩家名称>
*
* @param sender 命令发送者
* @param args 命令参数
*/
public static void member_remove(CommandSender sender, String[] args) {
try {
if (args.length < 4) {
Notification.error(sender, "用法: /dominion member remove <领地名称> <玩家名称>");
return;
}
Player player = playerOnly(sender);
if (player == null) return;
BukkitPlayerOperator operator = BukkitPlayerOperator.create(player);
String dominionName = args[2];
String playerName = args[3];
MemberController.memberRemove(operator, dominionName, playerName);
MemberList.show(sender, dominionName);
} catch (Exception e) {
Notification.error(sender, e.getMessage());
}
}
/**
* 应用权限模板
* /dominion member apply_template <领地名称> <玩家名称> <模板名称>
*
* @param sender 命令发送者
* @param args 命令参数
*/
public static void member_apply_template(CommandSender sender, String[] args) {
try {
if (args.length < 5) {
Notification.error(sender, "用法: /dominion member apply_template <领地名称> <玩家名称> <模板名称>");
return;
}
Player player = playerOnly(sender);
if (player == null) return;
BukkitPlayerOperator operator = BukkitPlayerOperator.create(player);
String dominionName = args[2];
String playerName = args[3];
String templateName = args[4];
MemberController.applyTemplate(operator, dominionName, playerName, templateName);
MemberSetting.show(sender, dominionName, playerName);
} catch (Exception e) {
Notification.error(sender, e.getMessage());
}
}
public static void handle(@NotNull CommandSender sender, @NotNull String[] args) {
switch (args[1]) {
case "add":
Member.member_add(sender, args);
break;
case "set_flag":
Member.member_set_flag(sender, args);
break;
case "remove":
Member.member_remove(sender, args);
break;
case "apply_template":
Member.member_apply_template(sender, args);
break;
case "list":
MemberList.show(sender, args);
break;
case "setting":
MemberSetting.show(sender, args);
break;
case "select_player":
SelectPlayer.show(sender, args);
break;
case "select_template":
SelectTemplate.show(sender, args);
break;
}
}
public static @Nullable List<String> handleTab(@NotNull CommandSender sender, @NotNull String[] args) {
if (args.length == 2) {
return Arrays.asList("add", "set_flag", "remove", "apply_template", "list", "setting", "select_player", "select_template");
}
if (args.length == 3) {
switch (args[1]) {
case "add":
case "remove":
case "list":
case "setting":
case "set_flag":
case "apply_template":
case "select_player":
case "select_template":
return playerDominions(sender);
}
}
if (args.length == 4) {
switch (args[1]) {
case "add":
case "remove":
case "set_flag":
case "apply_template":
case "setting":
case "select_template":
case "select_player":
return playerNames();
case "list":
return Collections.singletonList("页码(可选)");
}
}
if (args.length == 5) {
switch (args[1]) {
case "set_flag":
return playerPrivileges();
case "apply_template":
return allTemplates(sender);
case "setting":
case "select_template":
return Collections.singletonList("页码(可选)");
}
}
if (args.length == 6) {
switch (args[1]) {
case "set_flag":
return boolOptions();
}
}
return null;
}
}

View File

@ -0,0 +1,95 @@
package cn.lunadeer.dominion.commands;
import cn.lunadeer.dominion.Cache;
import cn.lunadeer.dominion.Dominion;
import cn.lunadeer.dominion.controllers.BukkitPlayerOperator;
import cn.lunadeer.dominion.controllers.DominionController;
import cn.lunadeer.dominion.dtos.DominionDTO;
import cn.lunadeer.dominion.tuis.MigrateList;
import cn.lunadeer.dominion.utils.ResMigration;
import cn.lunadeer.minecraftpluginutils.Notification;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.List;
import java.util.Objects;
import static cn.lunadeer.dominion.commands.Apis.playerOnly;
public class Migration {
public static void migrate(CommandSender sender, String[] args) {
try {
Player player = playerOnly(sender);
if (player == null) return;
if (!Dominion.config.getResidenceMigration()) {
Notification.error(sender, "Residence 迁移功能没有开启");
return;
}
if (args.length < 2) {
Notification.error(sender, "用法: /dominion migrate <res领地名称>");
return;
}
String resName = args[1];
List<ResMigration.ResidenceNode> res_data = Cache.instance.getResidenceData(player.getUniqueId());
if (res_data == null) {
Notification.error(sender, "你没有可迁移的数据");
return;
}
ResMigration.ResidenceNode resNode = res_data.stream().filter(node -> node.name.equals(resName)).findFirst().orElse(null);
if (resNode == null) {
Notification.error(sender, "未找到指定的 Residence 领地");
return;
}
if (!resNode.owner.equals(player.getUniqueId())) {
Notification.error(sender, "你不是该领地的所有者,无法迁移此领地");
return;
}
create(player, resNode, "");
if (args.length == 3 ) {
int parentId = Integer.parseInt(args[2]);
String[] newArgs = new String[2];
newArgs[0] = "migrate_list";
newArgs[1] = String.valueOf(parentId);
MigrateList.show(sender, newArgs);
}
} catch (Exception e) {
Notification.error(sender, "迁移失败: " + e.getMessage());
}
}
private static void create(Player player, ResMigration.ResidenceNode node, String parentName) {
BukkitPlayerOperator operator = new BukkitPlayerOperator(player);
operator.getResponse().thenAccept(result -> {
if (Objects.equals(result.getStatus(), BukkitPlayerOperator.Result.SUCCESS)) {
DominionDTO dominion = DominionDTO.select(node.name);
if (dominion == null) {
return;
}
dominion.setTpLocation(node.tpLoc)
.setJoinMessage(node.joinMessage)
.setLeaveMessage(node.leaveMessage);
for (String msg : result.getMessages()) {
Notification.info(player, msg);
}
Notification.info(player, "领地 " + node.name + " 已从 Residence 迁移至 Dominion");
if (node.children != null) {
for (ResMigration.ResidenceNode child : node.children) {
create(player, child, node.name);
}
}
} else if (Objects.equals(result.getStatus(), BukkitPlayerOperator.Result.WARNING)) {
for (String msg : result.getMessages()) {
Notification.warn(player, msg);
}
} else {
for (String msg : result.getMessages()) {
Notification.error(player, msg);
}
}
});
DominionController.create(operator, node.name, node.loc1, node.loc2, parentName, true);
}
}

View File

@ -28,9 +28,14 @@ public class Operator {
});
Scheduler.runTaskAsync(() -> {
Notification.info(sender, "正在从数据库重新加载玩家权限缓存...");
Cache.instance.loadPlayerPrivileges();
Cache.instance.loadMembers();
Notification.info(sender, "玩家权限缓存已重新加载");
});
Scheduler.runTaskAsync(() -> {
Notification.info(sender, "正在从数据库重新加载权限组缓存...");
Cache.instance.loadGroups();
Notification.info(sender, "权限组缓存已重新加载");
});
}
public static void exportMca(CommandSender sender, String[] args) {

View File

@ -1,128 +0,0 @@
package cn.lunadeer.dominion.commands;
import cn.lunadeer.dominion.controllers.BukkitPlayerOperator;
import cn.lunadeer.dominion.controllers.PrivilegeController;
import cn.lunadeer.dominion.tuis.DominionPrivilegeList;
import cn.lunadeer.dominion.tuis.PrivilegeInfo;
import cn.lunadeer.minecraftpluginutils.Notification;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import static cn.lunadeer.dominion.commands.Apis.playerOnly;
import static cn.lunadeer.dominion.controllers.PrivilegeController.*;
public class PlayerPrivilege {
/**
* 创建玩家特权
* /dominion create_privilege <玩家名称> [领地名称]
*
* @param sender 命令发送者
* @param args 命令参数
*/
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) {
createPrivilege(operator, args[1]);
} else {
createPrivilege(operator, args[1], args[2]);
}
if (args.length == 4) {
String[] newArgs = new String[2];
newArgs[0] = "privilege_list";
newArgs[1] = args[2];
DominionPrivilegeList.show(sender, newArgs);
}
}
/**
* 设置玩家权限
* /dominion set_privilege <玩家名称> <权限名称> <true/false> [领地名称]
*
* @param sender 命令发送者
* @param args 命令参数
*/
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) {
setPrivilege(operator, args[1], args[2], Boolean.parseBoolean(args[3]));
} else if (args.length == 5) {
setPrivilege(operator, args[1], args[2], Boolean.parseBoolean(args[3]), args[4]);
} else if (args.length == 6) {
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);
} else {
Notification.error(sender, "用法: /dominion set_privilege <玩家名称> <权限名称> <true/false> [领地名称]");
}
}
/**
* 重置玩家权限
* /dominion clear_privilege <玩家名称> [领地名称]
*
* @param sender 命令发送者
* @param args 命令参数
*/
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) {
clearPrivilege(operator, args[1]);
} else {
clearPrivilege(operator, args[1], args[2]);
}
if (args.length == 4) {
String[] newArgs = new String[3];
newArgs[0] = "privilege_list";
newArgs[1] = args[2];
DominionPrivilegeList.show(sender, newArgs);
}
}
/**
* 应用权限模板
* /dominion apply_template <玩家名称> <领地名称> <模板名称>
*
* @param sender 命令发送者
* @param args 命令参数
*/
public static void applyTemplate(CommandSender sender, String[] args) {
Player player = playerOnly(sender);
if (player == null) return;
if (args.length < 4) {
Notification.error(sender, "用法: /dominion apply_template <玩家名称> <领地名称> <模板名称>");
return;
}
BukkitPlayerOperator operator = BukkitPlayerOperator.create(player);
String playerName = args[1];
String dominionName = args[2];
String templateName = args[3];
PrivilegeController.applyTemplate(operator, dominionName, playerName, templateName);
if (args.length == 5) {
String[] newArgs = new String[3];
newArgs[0] = "privilege_list";
newArgs[1] = dominionName;
newArgs[2] = args[4];
DominionPrivilegeList.show(sender, newArgs);
}
}
}

View File

@ -1,7 +1,7 @@
package cn.lunadeer.dominion.commands;
import cn.lunadeer.dominion.Dominion;
import cn.lunadeer.dominion.tuis.DominionConfig;
import cn.lunadeer.dominion.tuis.SysConfig;
import cn.lunadeer.minecraftpluginutils.Notification;
import org.bukkit.command.CommandSender;
@ -67,6 +67,9 @@ public class SetConfig {
case "economy_refund":
setEconomyRefund(sender, args);
break;
case "residence_migration":
setResidenceMigration(sender, args);
break;
default:
Notification.error(sender, "未知参数");
}
@ -78,7 +81,7 @@ public class SetConfig {
String[] newArgs = new String[2];
newArgs[0] = "config";
newArgs[1] = String.valueOf(page);
DominionConfig.show(sender, newArgs);
SysConfig.show(sender, newArgs);
}
}
@ -250,4 +253,10 @@ public class SetConfig {
Dominion.config.setEconomyRefund(economyRefund);
}
}
private static void setResidenceMigration(CommandSender sender, String[] args) {
boolean residenceMigration = Boolean.parseBoolean(args[2]);
Dominion.config.setResidenceMigration(residenceMigration);
refreshPageOrNot(sender, args);
}
}

View File

@ -2,98 +2,150 @@ package cn.lunadeer.dominion.commands;
import cn.lunadeer.dominion.controllers.BukkitPlayerOperator;
import cn.lunadeer.dominion.controllers.TemplateController;
import cn.lunadeer.dominion.tuis.TemplateList;
import cn.lunadeer.dominion.tuis.TemplateManage;
import cn.lunadeer.dominion.tuis.template.TemplateList;
import cn.lunadeer.dominion.tuis.template.TemplateSetting;
import cn.lunadeer.minecraftpluginutils.Notification;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import static cn.lunadeer.dominion.Commands.boolOptions;
import static cn.lunadeer.dominion.commands.Apis.playerOnly;
import static cn.lunadeer.dominion.commands.Helper.allTemplates;
import static cn.lunadeer.dominion.commands.Helper.playerPrivileges;
import static cn.lunadeer.dominion.tuis.Apis.getPage;
public class Template {
/**
* 删除权限模板
* /dominion template_delete <模板名称> [页码]
*
* @param sender 命令发送者
* @param args 命令参数
*/
public static void deleteTemplate(CommandSender sender, String[] args) {
Player player = playerOnly(sender);
if (player == null) return;
BukkitPlayerOperator operator = BukkitPlayerOperator.create(player);
if (args.length < 2) {
Notification.error(sender, "用法: /dominion template_delete <模板名称>");
return;
}
TemplateController.deleteTemplate(operator, args[1]);
String[] newArgs = new String[2];
newArgs[0] = "template_list";
if (args.length == 3) {
newArgs[1] = args[2];
} else {
newArgs[1] = "1";
}
TemplateList.show(sender, newArgs);
}
/**
* 创建权限模板
* /dominion template_create <模板名称> [页码]
* /dominion template create <模板名称> [页码]
*
* @param sender 命令发送者
* @param args 命令参数
*/
public static void createTemplate(CommandSender sender, String[] args) {
Player player = playerOnly(sender);
if (player == null) return;
BukkitPlayerOperator operator = BukkitPlayerOperator.create(player);
if (args.length < 2) {
Notification.error(sender, "用法: /dominion template_create <模板名称>");
return;
try {
if (args.length < 3) {
Notification.error(sender, "用法: /dominion template create <模板名称>");
return;
}
Player player = playerOnly(sender);
if (player == null) return;
BukkitPlayerOperator operator = BukkitPlayerOperator.create(player);
TemplateController.createTemplate(operator, args[2]);
TemplateList.show(sender);
} catch (Exception e) {
Notification.error(sender, e.getMessage());
}
}
/**
* 删除权限模板
* /dominion template delete <模板名称> [页码]
*
* @param sender 命令发送者
* @param args 命令参数
*/
public static void deleteTemplate(CommandSender sender, String[] args) {
try {
if (args.length < 3) {
Notification.error(sender, "用法: /dominion template delete <模板名称>");
return;
}
Player player = playerOnly(sender);
if (player == null) return;
BukkitPlayerOperator operator = BukkitPlayerOperator.create(player);
TemplateController.deleteTemplate(operator, args[2]);
TemplateList.show(sender, getPage(args, 3));
} catch (Exception e) {
Notification.error(sender, e.getMessage());
}
TemplateController.createTemplate(operator, args[1]);
String[] newArgs = new String[2];
newArgs[0] = "template_list";
newArgs[1] = "1";
TemplateList.show(sender, newArgs);
}
/**
* 编辑模板
* /dominion template_set_flag <模板名称> <权限名称> <true/false> [页码]
* /dominion template set_flag <模板名称> <权限名称> <true/false> [页码]
*
* @param sender 命令发送者
* @param args 命令参数
*/
public static void setTemplateFlag(CommandSender sender, String[] args) {
Player player = playerOnly(sender);
if (player == null) return;
BukkitPlayerOperator operator = BukkitPlayerOperator.create(player);
if (args.length < 4) {
Notification.error(sender, "用法: /dominion template_set_flag <模板名称> <权限名称> <true/false>");
return;
try {
if (args.length < 5) {
Notification.error(sender, "用法: /dominion template set_flag <模板名称> <权限名称> <true/false>");
return;
}
Player player = playerOnly(sender);
if (player == null) return;
BukkitPlayerOperator operator = BukkitPlayerOperator.create(player);
String templateName = args[2];
String flagName = args[3];
boolean value = Boolean.parseBoolean(args[4]);
TemplateController.setTemplateFlag(operator, templateName, flagName, value);
TemplateSetting.show(sender, templateName, getPage(args, 5));
} catch (Exception e) {
Notification.error(sender, e.getMessage());
}
boolean value;
if (args[3].equalsIgnoreCase("true")) {
value = true;
} else if (args[3].equalsIgnoreCase("false")) {
value = false;
} else {
Notification.error(sender, "权限值必须是true或false");
return;
}
public static void handle(@NotNull CommandSender sender, @NotNull String[] args) {
switch (args[1]) {
case "list":
TemplateList.show(sender, args);
break;
case "setting":
TemplateSetting.show(sender, args);
break;
case "delete":
Template.deleteTemplate(sender, args);
break;
case "create":
Template.createTemplate(sender, args);
break;
case "set_flag":
Template.setTemplateFlag(sender, args);
break;
}
}
public static @Nullable List<String> handleTab(@NotNull CommandSender sender, @NotNull String[] args) {
if (args.length == 2) {
return Arrays.asList("list", "setting", "delete", "create", "set_flag");
}
if (args.length == 3) {
switch (args[1]) {
case "create":
return Collections.singletonList("输入模板名称");
case "delete":
case "set_flag":
case "setting":
return allTemplates(sender);
case "list":
return Collections.singletonList("页码(可选)");
}
}
if (args.length == 4) {
switch (args[1]) {
case "set_flag":
return playerPrivileges();
case "setting":
return Collections.singletonList("页码(可选)");
}
}
TemplateController.setTemplateFlag(operator, args[1], args[2], value);
String[] newArgs = new String[3];
newArgs[0] = "template_manage";
newArgs[1] = args[1];
if (args.length == 5) {
newArgs[2] = args[4];
} else {
newArgs[2] = "1";
switch (args[1]) {
case "set_flag":
return boolOptions();
}
}
TemplateManage.show(sender, newArgs);
return null;
}
}

View File

@ -2,7 +2,7 @@ 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.dominion.dtos.MemberDTO;
import org.bukkit.Location;
public class Apis {
@ -15,7 +15,7 @@ public class Apis {
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());
MemberDTO privileges = MemberDTO.select(player.getUniqueId(), dominion.getId());
if (privileges == null || !privileges.getAdmin()) {
player.setResponse(new AbstractOperator.Result(AbstractOperator.Result.FAILURE, "你不是领地 %s 的拥有者或管理员,无权修改权限", dominion.getName()));
return true;

View File

@ -59,6 +59,22 @@ public class DominionController {
public static void create(AbstractOperator operator, String name,
Location loc1, Location loc2,
String parent_dominion_name) {
create(operator, name, loc1, loc2, parent_dominion_name, false);
}
/**
* 创建子领地
*
* @param operator 拥有者
* @param name 领地名称
* @param loc1 位置1
* @param loc2 位置2
* @param parent_dominion_name 父领地名称
* @param skipEco 是否跳过经济检查
*/
public static void create(AbstractOperator operator, String name,
Location loc1, Location loc2,
String parent_dominion_name, boolean skipEco) {
AbstractOperator.Result FAIL = new AbstractOperator.Result(AbstractOperator.Result.FAILURE, "创建领地失败");
AbstractOperator.Result SUCCESS = new AbstractOperator.Result(AbstractOperator.Result.SUCCESS, "成功创建领地 %s", name);
if (name.isEmpty()) {

View File

@ -0,0 +1,218 @@
package cn.lunadeer.dominion.controllers;
import cn.lunadeer.dominion.dtos.*;
import java.util.Objects;
import static cn.lunadeer.dominion.controllers.Apis.noAuthToChangeFlags;
import static cn.lunadeer.dominion.controllers.Apis.notOwner;
public class GroupController {
public static void createGroup(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);
if (groupName.contains(" ")) {
operator.setResponse(FAIL.addMessage("权限组名称不能包含空格"));
return;
}
DominionDTO dominion = DominionDTO.select(domName);
if (dominion == null) {
operator.setResponse(FAIL.addMessage("领地 %s 不存在", domName));
return;
}
if (notOwner(operator, dominion)) {
operator.setResponse(FAIL.addMessage("你不是领地 %s 的拥有者,无法创建权限组", domName));
return;
}
GroupDTO group = GroupDTO.select(dominion.getId(), groupName);
if (group != null) {
operator.setResponse(FAIL.addMessage("领地 %s 已存在名为 %s 的权限组", domName, groupName));
return;
}
group = GroupDTO.create(groupName, dominion);
if (group == null) {
operator.setResponse(FAIL.addMessage("请联系服务器管理员"));
return;
}
operator.setResponse(SUCCESS);
}
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);
DominionDTO dominion = DominionDTO.select(domName);
if (dominion == null) {
operator.setResponse(FAIL.addMessage("领地 %s 不存在", domName));
return;
}
if (notOwner(operator, dominion)) {
operator.setResponse(FAIL.addMessage("你不是领地 %s 的拥有者,无法删除权限组", domName));
return;
}
GroupDTO group = GroupDTO.select(dominion.getId(), groupName);
if (group == null) {
operator.setResponse(FAIL.addMessage("领地 %s 不存在名为 %s 的权限组", domName, groupName));
return;
}
group.delete();
operator.setResponse(SUCCESS);
}
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);
DominionDTO dominion = DominionDTO.select(domName);
if (dominion == null) {
operator.setResponse(FAIL.addMessage("领地 %s 不存在", domName));
return;
}
if (noAuthToChangeFlags(operator, dominion)) {
return;
}
GroupDTO group = GroupDTO.select(dominion.getId(), groupName);
if (group == null) {
operator.setResponse(FAIL.addMessage("领地 %s 不存在名为 %s 的权限组", domName, groupName));
return;
}
if ((flag.equals("admin") || group.getAdmin()) && notOwner(operator, dominion)) {
operator.setResponse(FAIL.addMessage("你不是领地 %s 的拥有者,无法修改管理员权限组权限", domName));
return;
}
if (flag.equals("admin")) {
group = group.setAdmin(value);
} else {
Flag f = Flag.getFlag(flag);
if (f == null) {
operator.setResponse(FAIL.addMessage("未知的权限 %s", flag));
return;
}
group = group.setFlagValue(f, value);
}
if (group == null) {
operator.setResponse(FAIL.addMessage("请联系服务器管理员"));
return;
}
operator.setResponse(SUCCESS);
}
public static void renameGroup(AbstractOperator operator, String domName, String oldName, String newName) {
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);
if (newName.contains(" ")) {
operator.setResponse(FAIL.addMessage("权限组名称不能包含空格"));
return;
}
DominionDTO dominion = DominionDTO.select(domName);
if (dominion == null) {
operator.setResponse(FAIL.addMessage("领地 %s 不存在", domName));
return;
}
if (notOwner(operator, dominion)) {
operator.setResponse(FAIL.addMessage("你不是领地 %s 的拥有者,无法重命名权限组", domName));
return;
}
GroupDTO group = GroupDTO.select(dominion.getId(), oldName);
if (group == null) {
operator.setResponse(FAIL.addMessage("领地 %s 不存在名为 %s 的权限组", domName, oldName));
return;
}
group = group.setName(newName);
if (group == null) {
operator.setResponse(FAIL.addMessage("请联系服务器管理员"));
return;
}
operator.setResponse(SUCCESS);
}
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);
DominionDTO dominion = DominionDTO.select(domName);
if (dominion == null) {
operator.setResponse(FAIL.addMessage("领地 %s 不存在", domName));
return;
}
GroupDTO group = GroupDTO.select(dominion.getId(), groupName);
if (group == null) {
operator.setResponse(FAIL.addMessage("领地 %s 不存在名为 %s 的权限组", domName, groupName));
return;
}
if (noAuthToChangeFlags(operator, dominion)) {
operator.setResponse(FAIL.addMessage("你没有权限修改领地 %s 的权限组 %s 成员", domName, groupName));
return;
}
if (group.getAdmin() && notOwner(operator, dominion)) {
operator.setResponse(FAIL.addMessage("你不是领地 %s 的拥有者,无法添加成员到管理员权限组", domName));
return;
}
PlayerDTO player = PlayerDTO.select(playerName);
if (player == null) {
operator.setResponse(FAIL.addMessage("玩家 %s 不存在", playerName));
return;
}
MemberDTO privilege = MemberDTO.select(player.getUuid(), dominion.getId());
if (privilege == null) {
operator.setResponse(FAIL.addMessage("玩家 %s 不是领地 %s 的成员,无法直接加入权限组", playerName, domName));
return;
}
if (Objects.equals(privilege.getGroupId(), group.getId())) {
operator.setResponse(FAIL.addMessage("玩家 %s 已在权限组 %s 中", playerName, groupName));
return;
}
if (notOwner(operator, dominion) && privilege.getAdmin()) {
operator.setResponse(FAIL.addMessage("%s 是管理员,你不是领地 %s 的拥有者,无法添加管理员到权限组", playerName, domName));
return;
}
privilege = privilege.setGroupId(group.getId());
if (privilege == null) {
operator.setResponse(FAIL.addMessage("请联系服务器管理员"));
return;
}
operator.setResponse(SUCCESS);
}
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);
DominionDTO dominion = DominionDTO.select(domName);
if (dominion == null) {
operator.setResponse(FAIL.addMessage("领地 %s 不存在", domName));
return;
}
GroupDTO group = GroupDTO.select(dominion.getId(), groupName);
if (group == null) {
operator.setResponse(FAIL.addMessage("领地 %s 不存在名为 %s 的权限组", domName, groupName));
return;
}
if (noAuthToChangeFlags(operator, dominion)) {
operator.setResponse(FAIL.addMessage("你没有权限移除领地 %s 的权限组 %s 成员", domName, groupName));
return;
}
if (group.getAdmin() && notOwner(operator, dominion)) {
operator.setResponse(FAIL.addMessage("你不是领地 %s 的拥有者,无法从管理员权限组移除成员", domName));
return;
}
PlayerDTO player = PlayerDTO.select(playerName);
if (player == null) {
operator.setResponse(FAIL.addMessage("玩家 %s 不存在", playerName));
return;
}
MemberDTO privilege = MemberDTO.select(player.getUuid(), dominion.getId());
if (privilege == null) {
operator.setResponse(FAIL.addMessage("玩家 %s 不是领地 %s 的成员", playerName, domName));
return;
}
if (!Objects.equals(privilege.getGroupId(), group.getId())) {
operator.setResponse(FAIL.addMessage("玩家 %s 不在权限组 %s 中", playerName, groupName));
return;
}
privilege = privilege.setGroupId(-1);
if (privilege == null) {
operator.setResponse(FAIL.addMessage("请联系服务器管理员"));
return;
}
operator.setResponse(SUCCESS);
}
}

View File

@ -1,30 +1,11 @@
package cn.lunadeer.dominion.controllers;
import cn.lunadeer.dominion.Cache;
import cn.lunadeer.dominion.dtos.*;
import cn.lunadeer.minecraftpluginutils.XLogger;
import java.util.UUID;
import static cn.lunadeer.dominion.controllers.Apis.noAuthToChangeFlags;
import static cn.lunadeer.dominion.controllers.Apis.notOwner;
public class PrivilegeController {
/**
* 清空玩家成员权限
*
* @param operator 操作者
* @param player_name 玩家
*/
public static void clearPrivilege(AbstractOperator operator, String player_name) {
DominionDTO dominion = Apis.getPlayerCurrentDominion(operator);
if (dominion == null) {
operator.setResponse(new AbstractOperator.Result(AbstractOperator.Result.FAILURE, "你不在任何领地内,请指定领地名称 /dominion clear_privilege <玩家名称> <领地名称>"));
return;
}
clearPrivilege(operator, player_name, dominion.getName());
}
public class MemberController {
/**
* 清空玩家成员权限
@ -33,8 +14,9 @@ public class PrivilegeController {
* @param player_name 玩家
* @param 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);
public static void memberRemove(AbstractOperator operator, String dominionName, String player_name) {
AbstractOperator.Result FAIL = new AbstractOperator.Result(AbstractOperator.Result.FAILURE, "将玩家 %s 从领地 %s 移除失败", player_name, dominionName);
AbstractOperator.Result SUCCESS = new AbstractOperator.Result(AbstractOperator.Result.SUCCESS, "将玩家 %s 从领地 %s 移除成功", player_name, dominionName);
DominionDTO dominion = DominionDTO.select(dominionName);
if (dominion == null) {
operator.setResponse(FAIL.addMessage("领地 %s 不存在", dominionName));
@ -46,7 +28,7 @@ public class PrivilegeController {
operator.setResponse(FAIL.addMessage("玩家 %s 不存在或没有登录过", player_name));
return;
}
PlayerPrivilegeDTO privilege = PlayerPrivilegeDTO.select(player.getUuid(), dominion.getId());
MemberDTO privilege = MemberDTO.select(player.getUuid(), dominion.getId());
if (privilege == null) {
operator.setResponse(FAIL.addMessage("玩家 %s 不是领地 %s 的成员", player_name, dominionName));
return;
@ -55,25 +37,8 @@ public class PrivilegeController {
operator.setResponse(FAIL.addMessage("你不是领地 %s 的拥有者,无法移除一个领地管理员", dominionName));
return;
}
PlayerPrivilegeDTO.delete(player.getUuid(), dominion.getId());
operator.setResponse(new AbstractOperator.Result(AbstractOperator.Result.SUCCESS, "清空玩家 %s 在领地 %s 的权限成功", player_name, dominionName));
}
/**
* 设置玩家成员权限
*
* @param operator 操作者
* @param player_name 玩家
* @param flag 权限名称
* @param value 权限值
*/
public static void setPrivilege(AbstractOperator operator, String player_name, String flag, boolean value) {
DominionDTO dominion = Apis.getPlayerCurrentDominion(operator);
if (dominion == null) {
operator.setResponse(new AbstractOperator.Result(AbstractOperator.Result.FAILURE, "你不在任何领地内,请指定领地名称 /dominion set_privilege <玩家名称> <权限名称> <true/false> [领地名称]"));
return;
}
setPrivilege(operator, player_name, flag, value, dominion.getName());
MemberDTO.delete(player.getUuid(), dominion.getId());
operator.setResponse(SUCCESS);
}
/**
@ -85,8 +50,9 @@ public class PrivilegeController {
* @param value 权限值
* @param dominionName 领地名称
*/
public static void setPrivilege(AbstractOperator operator, String player_name, String flag, boolean value, String dominionName) {
public static void setMemberFlag(AbstractOperator operator, String dominionName, String player_name, String flag, boolean value) {
AbstractOperator.Result FAIL = new AbstractOperator.Result(AbstractOperator.Result.FAILURE, "设置玩家 %s 在领地 %s 的权限 %s 为 %s 失败", player_name, dominionName, flag, value);
AbstractOperator.Result SUCCESS = new AbstractOperator.Result(AbstractOperator.Result.SUCCESS, "设置玩家 %s 在领地 %s 的权限 %s 为 %s 成功", player_name, dominionName, flag, value);
DominionDTO dominion = DominionDTO.select(dominionName);
if (dominion == null) {
operator.setResponse(FAIL.addMessage("领地 %s 不存在", dominionName));
@ -98,10 +64,10 @@ public class PrivilegeController {
operator.setResponse(FAIL.addMessage("玩家 %s 不存在或没有登录过", player_name));
return;
}
PlayerPrivilegeDTO privilege = PlayerPrivilegeDTO.select(player.getUuid(), dominion.getId());
MemberDTO privilege = MemberDTO.select(player.getUuid(), dominion.getId());
if (privilege == null) {
privilege = createPlayerPrivilege(operator, player.getUuid(), dominion);
if (privilege == null) return;
operator.setResponse(FAIL.addMessage("玩家 %s 不是领地 %s 的成员", player_name, dominionName));
return;
}
if ((flag.equals("admin") || privilege.getAdmin()) && notOwner(operator, dominion)) {
operator.setResponse(FAIL.addMessage("你不是领地 %s 的拥有者,无法修改其他玩家管理员的权限", dominionName));
@ -110,10 +76,6 @@ public class PrivilegeController {
if (flag.equals("admin")) {
privilege.setAdmin(value);
} else {
if (privilege.getAdmin()) {
operator.setResponse(FAIL.addMessage("管理员拥有所有权限,无需单独设置权限"));
return;
}
Flag f = Flag.getFlag(flag);
if (f == null) {
operator.setResponse(FAIL.addMessage("未知的领地权限 %s", flag));
@ -121,53 +83,34 @@ public class PrivilegeController {
}
privilege.setFlagValue(f, value);
}
operator.setResponse(new AbstractOperator.Result(AbstractOperator.Result.SUCCESS, "设置玩家 %s 在领地 %s 的权限 %s 为 %s 成功", player_name, dominionName, flag, value));
operator.setResponse(SUCCESS);
}
public static void createPrivilege(AbstractOperator operator, String player_name) {
DominionDTO dominion = Apis.getPlayerCurrentDominion(operator);
if (dominion == null) {
operator.setResponse(new AbstractOperator.Result(AbstractOperator.Result.FAILURE, "你不在任何领地内,请指定领地名称 /dominion create_privilege <玩家名称> <领地名称>"));
return;
}
createPrivilege(operator, player_name, dominion.getName());
}
public static void createPrivilege(AbstractOperator operator, String player_name, String dominionName) {
public static void memberAdd(AbstractOperator operator, String dominionName, String player_name) {
AbstractOperator.Result FAIL = new AbstractOperator.Result(AbstractOperator.Result.FAILURE, "将玩家 %s 添加到领地成员 %s 失败", player_name, dominionName);
AbstractOperator.Result SUCCESS = new AbstractOperator.Result(AbstractOperator.Result.SUCCESS, "将玩家 %s 添加到领地成员 %s 成功", player_name, dominionName);
DominionDTO dominion = DominionDTO.select(dominionName);
if (dominion == null) {
operator.setResponse(new AbstractOperator.Result(AbstractOperator.Result.FAILURE, "领地 %s 不存在,无法创建成员权限", dominionName));
operator.setResponse(FAIL.addMessage("领地 %s 不存在", dominionName));
return;
}
if (noAuthToChangeFlags(operator, dominion)) return;
PlayerDTO player = PlayerController.getPlayerDTO(player_name);
if (player == null) {
operator.setResponse(new AbstractOperator.Result(AbstractOperator.Result.FAILURE, "玩家 %s 不存在或没有登录过", player_name));
operator.setResponse(FAIL.addMessage("玩家 %s 不存在或没有登录过", player_name));
return;
}
if (createPlayerPrivilege(operator, player.getUuid(), dominion) != null) {
operator.setResponse(new AbstractOperator.Result(AbstractOperator.Result.SUCCESS, "创建玩家 %s 在领地 %s 的成员权限成功", player_name, dominionName));
}
}
private static PlayerPrivilegeDTO createPlayerPrivilege(AbstractOperator operator, UUID player, DominionDTO dom) {
XLogger.debug("operator: " + operator.getUniqueId() + " player: " + player);
if (operator.getUniqueId().equals(player)) {
operator.setResponse(new AbstractOperator.Result(AbstractOperator.Result.FAILURE, "你不能给自己设置成员权限"));
return null;
}
PlayerDTO playerDTO = PlayerDTO.select(player);
PlayerPrivilegeDTO privilege = Cache.instance.getPlayerPrivilege(player, dom);
MemberDTO privilege = MemberDTO.select(player.getUuid(), dominion.getId());
if (privilege != null) {
operator.setResponse(new AbstractOperator.Result(AbstractOperator.Result.FAILURE, "创建玩家成员权限失败,玩家 %s 已经是领地 %s 的成员", playerDTO.getLastKnownName(), dom.getName()));
return null;
operator.setResponse(FAIL.addMessage("玩家 %s 已经是领地 %s 的成员", player_name, dominionName));
return;
}
privilege = PlayerPrivilegeDTO.insert(new PlayerPrivilegeDTO(player, dom));
privilege = MemberDTO.insert(new MemberDTO(player.getUuid(), dominion));
if (privilege == null) {
operator.setResponse(new AbstractOperator.Result(AbstractOperator.Result.FAILURE, "创建玩家成员权限失败,请联系管理员"));
return null;
operator.setResponse(FAIL);
} else {
operator.setResponse(SUCCESS);
}
return privilege;
}
public static void applyTemplate(AbstractOperator operator, String dominionName, String playerName, String templateName) {
@ -184,7 +127,7 @@ public class PrivilegeController {
operator.setResponse(FAIL.addMessage("玩家 %s 不存在或没有登录过", playerName));
return;
}
PlayerPrivilegeDTO privilege = PlayerPrivilegeDTO.select(player.getUuid(), dominion.getId());
MemberDTO privilege = MemberDTO.select(player.getUuid(), dominion.getId());
if (privilege == null) {
operator.setResponse(FAIL.addMessage("玩家 %s 不是领地 %s 的成员", playerName, dominionName));
return;

View File

@ -10,10 +10,14 @@ public class TemplateController {
public static void createTemplate(AbstractOperator operator, String templateName) {
AbstractOperator.Result SUCCESS = new AbstractOperator.Result(AbstractOperator.Result.SUCCESS, "创建成功");
AbstractOperator.Result FAIL = new AbstractOperator.Result(AbstractOperator.Result.FAILURE, "创建失败");
if (templateName.contains(" ")) {
operator.setResponse(FAIL.addMessage("模板名称不能包含空格"));
return;
}
List<PrivilegeTemplateDTO> templates = PrivilegeTemplateDTO.selectAll(operator.getUniqueId());
for (PrivilegeTemplateDTO template : templates) {
if (template.getName().equals(templateName)) {
operator.setResponse(FAIL.addMessage("已经存在名为" + templateName + "的权限模板"));
operator.setResponse(FAIL.addMessage("已经存在名为 %s 的权限模板", templateName));
return;
}
}
@ -22,7 +26,7 @@ public class TemplateController {
operator.setResponse(FAIL.addMessage("可能是数据库错误,请联系管理员"));
return;
}
operator.setResponse(SUCCESS.addMessage("成功创建名为" + templateName + "的权限模板"));
operator.setResponse(SUCCESS.addMessage("成功创建名为 %s 的权限模板", templateName));
}
public static void deleteTemplate(AbstractOperator operator, String templateName) {

View File

@ -4,7 +4,7 @@ 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.tuis.DominionManage;
import cn.lunadeer.dominion.tuis.dominion.DominionManage;
import cn.lunadeer.minecraftpluginutils.Notification;
import cn.lunadeer.minecraftpluginutils.XLogger;
import cn.lunadeer.minecraftpluginutils.scui.CuiTextInput;

View File

@ -0,0 +1,50 @@
package cn.lunadeer.dominion.cuis;
import cn.lunadeer.dominion.controllers.BukkitPlayerOperator;
import cn.lunadeer.dominion.controllers.GroupController;
import cn.lunadeer.dominion.dtos.DominionDTO;
import cn.lunadeer.dominion.tuis.dominion.manage.group.GroupList;
import cn.lunadeer.minecraftpluginutils.Notification;
import cn.lunadeer.minecraftpluginutils.XLogger;
import cn.lunadeer.minecraftpluginutils.scui.CuiTextInput;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import static cn.lunadeer.dominion.commands.Apis.playerOnly;
public class CreateGroup {
private static class createGroupCB implements CuiTextInput.InputCallback {
private final Player sender;
private final String dominionName;
public createGroupCB(Player sender, String dominionName) {
this.sender = sender;
this.dominionName = dominionName;
}
@Override
public void handleData(String input) {
XLogger.debug("createGroupCB.run: %s", input);
BukkitPlayerOperator operator = BukkitPlayerOperator.create(sender);
GroupController.createGroup(operator, dominionName, input);
GroupList.show(sender, dominionName);
}
}
public static void open(CommandSender sender, String[] args) {
Player player = playerOnly(sender);
if (player == null) return;
DominionDTO dominion = DominionDTO.select(args[1]);
if (dominion == null) {
Notification.error(sender, "领地不存在");
return;
}
CuiTextInput.InputCallback createGroupCB = new createGroupCB(player, dominion.getName());
CuiTextInput view = CuiTextInput.create(createGroupCB).setText("未命名权限组").title("输入要创建的权限组名称");
view.setSuggestCommand("/dominion group create <领地名称> <权限组名称>");
view.open(player);
}
}

View File

@ -2,7 +2,7 @@ package cn.lunadeer.dominion.cuis;
import cn.lunadeer.dominion.controllers.BukkitPlayerOperator;
import cn.lunadeer.dominion.controllers.TemplateController;
import cn.lunadeer.dominion.tuis.TemplateList;
import cn.lunadeer.dominion.tuis.template.TemplateList;
import cn.lunadeer.minecraftpluginutils.XLogger;
import cn.lunadeer.minecraftpluginutils.scui.CuiTextInput;
import org.bukkit.command.CommandSender;
@ -23,10 +23,8 @@ public class CreateTemplate {
public void handleData(String input) {
XLogger.debug("createTemplateCB.run: %s", input);
BukkitPlayerOperator operator = BukkitPlayerOperator.create(sender);
operator.getResponse().thenAccept(result -> {
TemplateList.show(sender, new String[]{"template_list"});
});
TemplateController.createTemplate(operator, input);
TemplateList.show(sender);
}
}
@ -35,7 +33,7 @@ public class CreateTemplate {
if (player == null) return;
CuiTextInput.InputCallback createTemplateCB = new createTemplateCB(player);
CuiTextInput view = CuiTextInput.create(createTemplateCB).setText("未命名模板").title("输入模板名称");
view.setSuggestCommand("/dominion template_create <模板名称>");
view.setSuggestCommand("/dominion template create <模板名称>");
view.open(player);
}

View File

@ -3,7 +3,7 @@ package cn.lunadeer.dominion.cuis;
import cn.lunadeer.dominion.controllers.BukkitPlayerOperator;
import cn.lunadeer.dominion.controllers.DominionController;
import cn.lunadeer.dominion.dtos.DominionDTO;
import cn.lunadeer.dominion.tuis.DominionManage;
import cn.lunadeer.dominion.tuis.dominion.DominionManage;
import cn.lunadeer.minecraftpluginutils.Notification;
import cn.lunadeer.minecraftpluginutils.XLogger;
import cn.lunadeer.minecraftpluginutils.scui.CuiTextInput;

View File

@ -3,7 +3,7 @@ package cn.lunadeer.dominion.cuis;
import cn.lunadeer.dominion.controllers.BukkitPlayerOperator;
import cn.lunadeer.dominion.controllers.DominionController;
import cn.lunadeer.dominion.dtos.DominionDTO;
import cn.lunadeer.dominion.tuis.DominionManage;
import cn.lunadeer.dominion.tuis.dominion.DominionManage;
import cn.lunadeer.minecraftpluginutils.Notification;
import cn.lunadeer.minecraftpluginutils.XLogger;
import cn.lunadeer.minecraftpluginutils.scui.CuiTextInput;

View File

@ -2,10 +2,10 @@ package cn.lunadeer.dominion.cuis;
import cn.lunadeer.dominion.controllers.AbstractOperator;
import cn.lunadeer.dominion.controllers.BukkitPlayerOperator;
import cn.lunadeer.dominion.controllers.PrivilegeController;
import cn.lunadeer.dominion.controllers.MemberController;
import cn.lunadeer.dominion.dtos.DominionDTO;
import cn.lunadeer.dominion.tuis.DominionPrivilegeList;
import cn.lunadeer.dominion.tuis.SelectPlayer;
import cn.lunadeer.dominion.tuis.dominion.manage.member.MemberList;
import cn.lunadeer.dominion.tuis.dominion.manage.member.SelectPlayer;
import cn.lunadeer.minecraftpluginutils.Notification;
import cn.lunadeer.minecraftpluginutils.XLogger;
import cn.lunadeer.minecraftpluginutils.scui.CuiTextInput;
@ -16,13 +16,13 @@ import java.util.Objects;
import static cn.lunadeer.dominion.commands.Apis.playerOnly;
public class CreatePrivilege {
public class MemberAdd {
private static class createPrivilegeCB implements CuiTextInput.InputCallback {
private static class memberAddCB implements CuiTextInput.InputCallback {
private final Player sender;
private final String dominionName;
public createPrivilegeCB(Player sender, String dominionName) {
public memberAddCB(Player sender, String dominionName) {
this.sender = sender;
this.dominionName = dominionName;
}
@ -32,13 +32,13 @@ public class CreatePrivilege {
XLogger.debug("createPrivilegeCB.run: %s", input);
BukkitPlayerOperator operator = BukkitPlayerOperator.create(sender);
operator.getResponse().thenAccept(result -> {
if (Objects.equals(result.getStatus(), AbstractOperator.Result.SUCCESS)){
DominionPrivilegeList.show(sender, new String[]{"privilege_list", dominionName});
if (Objects.equals(result.getStatus(), AbstractOperator.Result.SUCCESS)) {
MemberList.show(sender, dominionName);
} else {
SelectPlayer.show(sender, new String[]{"select_player_create_privilege", dominionName});
SelectPlayer.show(sender, dominionName, 1);
}
});
PrivilegeController.createPrivilege(operator, input, dominionName);
MemberController.memberAdd(operator, dominionName, input);
}
}
@ -50,9 +50,9 @@ public class CreatePrivilege {
Notification.error(sender, "领地不存在");
return;
}
CuiTextInput.InputCallback createPrivilegeCB = new createPrivilegeCB(player, dominion.getName());
CuiTextInput.InputCallback createPrivilegeCB = new memberAddCB(player, dominion.getName());
CuiTextInput view = CuiTextInput.create(createPrivilegeCB).setText("Steve").title("输入玩家名称以添加为成员");
view.setSuggestCommand("/dominion create_privilege <玩家名称> [领地名称]");
view.setSuggestCommand("/dominion member add <领地名称> <玩家名称>");
view.open(player);
}

View File

@ -2,7 +2,7 @@ package cn.lunadeer.dominion.cuis;
import cn.lunadeer.dominion.controllers.BukkitPlayerOperator;
import cn.lunadeer.dominion.controllers.DominionController;
import cn.lunadeer.dominion.tuis.DominionManage;
import cn.lunadeer.dominion.tuis.dominion.DominionManage;
import cn.lunadeer.minecraftpluginutils.XLogger;
import cn.lunadeer.minecraftpluginutils.scui.CuiTextInput;
import org.bukkit.command.CommandSender;

View File

@ -0,0 +1,52 @@
package cn.lunadeer.dominion.cuis;
import cn.lunadeer.dominion.controllers.BukkitPlayerOperator;
import cn.lunadeer.dominion.controllers.GroupController;
import cn.lunadeer.dominion.dtos.DominionDTO;
import cn.lunadeer.dominion.tuis.dominion.manage.group.GroupSetting;
import cn.lunadeer.minecraftpluginutils.Notification;
import cn.lunadeer.minecraftpluginutils.XLogger;
import cn.lunadeer.minecraftpluginutils.scui.CuiTextInput;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import static cn.lunadeer.dominion.commands.Apis.playerOnly;
public class RenameGroup {
private static class renameGroupCB implements CuiTextInput.InputCallback {
private final Player sender;
private final String dominionName;
private final String oldName;
public renameGroupCB(Player sender, String dominionName, String oldName) {
this.sender = sender;
this.dominionName = dominionName;
this.oldName = oldName;
}
@Override
public void handleData(String input) {
XLogger.debug("renameGroupCB.run: %s", input);
BukkitPlayerOperator operator = BukkitPlayerOperator.create(sender);
GroupController.renameGroup(operator, dominionName, oldName, input);
GroupSetting.show(sender, dominionName, input);
}
}
public static void open(CommandSender sender, String[] args) {
Player player = playerOnly(sender);
if (player == null) return;
DominionDTO dominion = DominionDTO.select(args[1]);
if (dominion == null) {
Notification.error(sender, "领地不存在");
return;
}
CuiTextInput.InputCallback renameGroupCB = new renameGroupCB(player, dominion.getName(), args[2]);
CuiTextInput view = CuiTextInput.create(renameGroupCB).setText(args[2]).title("输入新的权限组名称");
view.setSuggestCommand("/dominion group rename <领地名称> <权限组旧名称> <新名称>");
view.open(player);
}
}

View File

@ -3,7 +3,7 @@ package cn.lunadeer.dominion.cuis;
import cn.lunadeer.dominion.controllers.BukkitPlayerOperator;
import cn.lunadeer.dominion.controllers.DominionController;
import cn.lunadeer.dominion.dtos.DominionDTO;
import cn.lunadeer.dominion.tuis.DominionManage;
import cn.lunadeer.dominion.tuis.dominion.DominionManage;
import cn.lunadeer.minecraftpluginutils.Notification;
import cn.lunadeer.minecraftpluginutils.XLogger;
import cn.lunadeer.minecraftpluginutils.scui.CuiTextInput;

View File

@ -28,6 +28,7 @@ public enum Flag {
CREEPER_EXPLODE("creeper_explode", "实体爆炸", "包含:苦力怕/凋零头颅/水晶爆炸", false, true, true),
COMPARER("comparer", "比较器交互", "是否可以修改比较器状态", false, false, true),
DOOR("door", "门交互", "是否可以使用各种材质的门(包括活板门)", false, false, true),
DRAGON_EGG("dragon_egg", "触碰龙蛋", "是否可以触碰龙蛋", false, false, true),
DYE("dye", "染色", "是否可以使用染料(对羊、狗项圈、猫项圈)染色", false, false, true),
EDIT_SIGN("edit_sign", "编辑告示牌", "是否可以编辑告示牌", false, false, true),
EGG("egg", "扔鸡蛋", "是否可以扔鸡蛋", false, false, true),

View File

@ -0,0 +1,180 @@
package cn.lunadeer.dominion.dtos;
import cn.lunadeer.dominion.Cache;
import cn.lunadeer.minecraftpluginutils.databse.DatabaseManager;
import cn.lunadeer.minecraftpluginutils.databse.Field;
import cn.lunadeer.minecraftpluginutils.databse.FieldType;
import cn.lunadeer.minecraftpluginutils.databse.syntax.InsertRow;
import cn.lunadeer.minecraftpluginutils.databse.syntax.UpdateRow;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class GroupDTO {
Field id = new Field("id", FieldType.INT);
Field domID = new Field("dom_id", FieldType.INT);
Field name = new Field("name", FieldType.STRING);
Field admin = new Field("admin", FieldType.BOOLEAN);
private final Map<Flag, Boolean> flags = new HashMap<>();
public Integer getId() {
return (Integer) id.value;
}
public Integer getDomID() {
return (Integer) domID.value;
}
public String getName() {
return (String) name.value;
}
public Boolean getAdmin() {
return (Boolean) admin.value;
}
public Boolean getFlagValue(Flag flag) {
if (!flags.containsKey(flag)) return flag.getDefaultValue();
return flags.get(flag);
}
public GroupDTO setName(String name) {
this.name.value = name;
UpdateRow updateRow = new UpdateRow().field(this.name);
return doUpdate(updateRow);
}
public GroupDTO setAdmin(Boolean admin) {
this.admin.value = admin;
UpdateRow updateRow = new UpdateRow().field(this.admin);
return doUpdate(updateRow);
}
public GroupDTO setFlagValue(Flag flag, Boolean value) {
flags.put(flag, value);
Field f = new Field(flag.getFlagName(), value);
UpdateRow updateRow = new UpdateRow().field(f);
return doUpdate(updateRow);
}
public static GroupDTO create(String name, DominionDTO dominionDTO) {
GroupDTO group = new GroupDTO(name, dominionDTO.getId());
InsertRow insertRow = new InsertRow().returningAll().onConflictDoNothing(new Field("id", null));
insertRow.table("dominion_group")
.field(group.domID)
.field(group.name)
.field(group.admin);
for (Flag f : Flag.getPrivilegeFlagsEnabled()) {
insertRow.field(new Field(f.getFlagName(), dominionDTO.getFlagValue(f)));
}
try (ResultSet rs = insertRow.execute()) {
List<GroupDTO> groups = getDTOFromRS(rs);
if (groups.size() == 0) return null;
Cache.instance.loadGroups(groups.get(0).getId());
return groups.get(0);
} catch (Exception e) {
DatabaseManager.handleDatabaseError("创建权限组失败: ", e, "");
return null;
}
}
public void delete() {
delete(getId());
}
public static void delete(Integer id) {
String sql = "DELETE FROM dominion_group WHERE id = ?;";
DatabaseManager.instance.query(sql, id);
Cache.instance.loadGroups(id);
List<MemberDTO> players = MemberDTO.selectByGroupId(id);
for (MemberDTO player : players) {
player.setGroupId(-1);
}
}
public static GroupDTO select(Integer id) {
String sql = "SELECT * FROM dominion_group WHERE id = ?;";
List<GroupDTO> groups = getDTOFromRS(DatabaseManager.instance.query(sql, id));
if (groups.size() == 0) return null;
return groups.get(0);
}
public static GroupDTO select(Integer domID, String name) {
String sql = "SELECT * FROM dominion_group WHERE dom_id = ? AND name = ?;";
List<GroupDTO> groups = getDTOFromRS(DatabaseManager.instance.query(sql, domID, name));
if (groups.size() == 0) return null;
return groups.get(0);
}
public static List<GroupDTO> selectAll() {
String sql = "SELECT * FROM dominion_group;";
return getDTOFromRS(DatabaseManager.instance.query(sql));
}
public static List<GroupDTO> selectByDominionId(Integer domID) {
String sql = "SELECT * FROM dominion_group WHERE dom_id = ?;";
return getDTOFromRS(DatabaseManager.instance.query(sql, domID));
}
private GroupDTO(String name, Integer domID) {
this.domID.value = domID;
this.name.value = name;
this.admin.value = false;
for (Flag f : Flag.getPrivilegeFlagsEnabled()) {
flags.put(f, f.getDefaultValue());
}
}
private GroupDTO(Integer id, Integer domID, String name, Boolean admin, Map<Flag, Boolean> flags) {
this.id.value = id;
this.domID.value = domID;
this.name.value = name;
this.admin.value = admin;
this.flags.putAll(flags);
}
private static List<GroupDTO> getDTOFromRS(ResultSet rs) {
List<GroupDTO> list = new ArrayList<>();
if (rs == null) return list;
try {
while (rs.next()) {
Map<Flag, Boolean> flags = new HashMap<>();
for (Flag f : Flag.getPrivilegeFlagsEnabled()) {
flags.put(f, rs.getBoolean(f.getFlagName()));
}
GroupDTO group = new GroupDTO(
rs.getInt("id"),
rs.getInt("dom_id"),
rs.getString("name"),
rs.getBoolean("admin"),
flags
);
list.add(group);
}
} catch (Exception e) {
DatabaseManager.handleDatabaseError("查询权限组失败: ", e, "");
}
return list;
}
private GroupDTO doUpdate(UpdateRow updateRow) {
updateRow.returningAll(id)
.table("dominion_group")
.where("id = ?", id.value);
try (ResultSet rs = updateRow.execute()) {
List<GroupDTO> groups = getDTOFromRS(rs);
if (groups.size() == 0) return null;
Cache.instance.loadGroups((Integer) id.value);
return groups.get(0);
} catch (Exception e) {
DatabaseManager.handleDatabaseError("更新权限组失败: ", e, "");
return null;
}
}
}

View File

@ -0,0 +1,204 @@
package cn.lunadeer.dominion.dtos;
import cn.lunadeer.dominion.Cache;
import cn.lunadeer.minecraftpluginutils.databse.DatabaseManager;
import cn.lunadeer.minecraftpluginutils.databse.Field;
import cn.lunadeer.minecraftpluginutils.databse.FieldType;
import cn.lunadeer.minecraftpluginutils.databse.syntax.InsertRow;
import cn.lunadeer.minecraftpluginutils.databse.syntax.UpdateRow;
import java.sql.ResultSet;
import java.util.*;
public class MemberDTO {
private static List<MemberDTO> query(String sql, Object... params) {
List<MemberDTO> players = new ArrayList<>();
try (ResultSet rs = DatabaseManager.instance.query(sql, params)) {
return getDTOFromRS(rs);
} catch (Exception e) {
DatabaseManager.handleDatabaseError("查询玩家权限失败: ", e, sql);
}
return players;
}
private static List<MemberDTO> getDTOFromRS(ResultSet rs) {
List<MemberDTO> players = new ArrayList<>();
if (rs == null) return players;
try {
while (rs.next()) {
Map<Flag, Boolean> flags = new HashMap<>();
for (Flag f : Flag.getPrivilegeFlagsEnabled()) {
flags.put(f, rs.getBoolean(f.getFlagName()));
}
MemberDTO player = new MemberDTO(
rs.getInt("id"),
UUID.fromString(rs.getString("player_uuid")),
rs.getBoolean("admin"),
rs.getInt("dom_id"),
flags,
rs.getInt("group_id")
);
players.add(player);
}
} catch (Exception e) {
DatabaseManager.handleDatabaseError("查询玩家权限失败: ", e, "");
}
return players;
}
private MemberDTO doUpdate(UpdateRow updateRow) {
updateRow.returningAll(id)
.table("dominion_member")
.where("id = ?", id.value);
try (ResultSet rs = updateRow.execute()) {
List<MemberDTO> players = getDTOFromRS(rs);
if (players.size() == 0) return null;
Cache.instance.loadMembers(getPlayerUUID());
return players.get(0);
} catch (Exception e) {
DatabaseManager.handleDatabaseError("更新玩家权限失败: ", e, "");
return null;
}
}
public static MemberDTO insert(MemberDTO player) {
InsertRow insertRow = new InsertRow().returningAll().onConflictDoNothing(new Field("id", null))
.table("dominion_member")
.field(player.playerUUID)
.field(player.admin)
.field(player.domID);
for (Flag f : Flag.getPrivilegeFlagsEnabled()) {
insertRow.field(new Field(f.getFlagName(), player.getFlagValue(f)));
}
try (ResultSet rs = insertRow.execute()) {
Cache.instance.loadMembers(player.getPlayerUUID());
List<MemberDTO> players = getDTOFromRS(rs);
if (players.size() == 0) return null;
return players.get(0);
} catch (Exception e) {
DatabaseManager.handleDatabaseError("插入玩家权限失败: ", e, "");
return null;
}
}
public static MemberDTO select(UUID playerUUID, Integer dom_id) {
String sql = "SELECT * FROM dominion_member WHERE player_uuid = ? AND dom_id = ?;";
List<MemberDTO> p = query(sql, playerUUID.toString(), dom_id);
if (p.size() == 0) return null;
return p.get(0);
}
public static List<MemberDTO> select(Integer dom_id) {
String sql = "SELECT * FROM dominion_member WHERE dom_id = ?;";
return query(sql, dom_id);
}
public static void delete(UUID player, Integer domID) {
String sql = "DELETE FROM dominion_member WHERE player_uuid = ? AND dom_id = ?;";
query(sql, player.toString(), domID);
Cache.instance.loadMembers(player);
}
public static List<MemberDTO> selectAll() {
String sql = "SELECT * FROM dominion_member;";
return query(sql);
}
public static List<MemberDTO> selectAll(UUID player) {
String sql = "SELECT * FROM dominion_member WHERE player_uuid = ?;";
return query(sql, player.toString());
}
public static List<MemberDTO> selectByGroupId(Integer groupId) {
String sql = "SELECT * FROM dominion_member WHERE group_id = ?;";
return query(sql, groupId);
}
public static List<MemberDTO> selectByDomGroupId(Integer domId, Integer groupId) {
String sql = "SELECT * FROM dominion_member WHERE group_id = ? AND dom_id = ?;";
return query(sql, groupId, domId);
}
Field id = new Field("id", FieldType.INT);
Field playerUUID = new Field("player_uuid", FieldType.STRING);
Field admin = new Field("admin", FieldType.BOOLEAN);
Field domID = new Field("dom_id", FieldType.INT);
Field groupId = new Field("group_id", FieldType.INT);
public Integer getId() {
return (Integer) id.value;
}
public UUID getPlayerUUID() {
return UUID.fromString((String) playerUUID.value);
}
public Boolean getAdmin() {
return (Boolean) admin.value;
}
public Integer getDomID() {
return (Integer) domID.value;
}
public Integer getGroupId() {
return (Integer) groupId.value;
}
private final Map<Flag, Boolean> flags = new HashMap<>();
public Boolean getFlagValue(Flag flag) {
if (!flags.containsKey(flag)) return flag.getDefaultValue();
return flags.get(flag);
}
public MemberDTO setFlagValue(Flag flag, Boolean value) {
flags.put(flag, value);
Field f = new Field(flag.getFlagName(), value);
UpdateRow updateRow = new UpdateRow().field(f);
return doUpdate(updateRow);
}
public MemberDTO setAdmin(Boolean admin) {
this.admin.value = admin;
UpdateRow updateRow = new UpdateRow().field(this.admin);
return doUpdate(updateRow);
}
public MemberDTO setGroupId(Integer groupId) {
this.groupId.value = groupId;
UpdateRow updateRow = new UpdateRow().field(this.groupId);
return doUpdate(updateRow);
}
public MemberDTO applyTemplate(PrivilegeTemplateDTO template) {
this.admin.value = template.getAdmin();
UpdateRow updateRow = new UpdateRow().field(admin);
for (Flag f : Flag.getPrivilegeFlagsEnabled()) {
this.flags.put(f, template.getFlagValue(f));
updateRow.field(new Field(f.getFlagName(), template.getFlagValue(f)));
}
return doUpdate(updateRow);
}
private MemberDTO(Integer id, UUID playerUUID, Boolean admin, Integer domID, Map<Flag, Boolean> flags, Integer groupId) {
this.id.value = id;
this.playerUUID.value = playerUUID.toString();
this.admin.value = admin;
this.domID.value = domID;
this.groupId.value = groupId;
this.flags.putAll(flags);
}
public MemberDTO(UUID playerUUID, DominionDTO dom) {
this.id.value = null;
this.playerUUID.value = playerUUID.toString();
this.admin.value = false;
this.domID.value = dom.getId();
for (Flag f : Flag.getPrivilegeFlagsEnabled()) {
this.flags.put(f, dom.getFlagValue(f));
}
}
}

View File

@ -4,8 +4,10 @@ import cn.lunadeer.minecraftpluginutils.databse.DatabaseManager;
import cn.lunadeer.minecraftpluginutils.databse.Field;
import cn.lunadeer.minecraftpluginutils.databse.syntax.InsertRow;
import cn.lunadeer.minecraftpluginutils.databse.syntax.UpdateRow;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import javax.annotation.Nullable;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
@ -24,6 +26,17 @@ public class PlayerDTO {
return re;
}
public static @Nullable PlayerDTO get(OfflinePlayer player) {
if (player.getName() == null) {
return null;
}
PlayerDTO re = select(player.getUniqueId());
if (re == null) {
re = insert(new PlayerDTO(player.getUniqueId(), player.getName(), System.currentTimeMillis()));
}
return re;
}
public static List<PlayerDTO> all() {
String sql = "SELECT * FROM player_name WHERE id > 0;";
return query(sql);

View File

@ -1,185 +0,0 @@
package cn.lunadeer.dominion.dtos;
import cn.lunadeer.dominion.Cache;
import cn.lunadeer.minecraftpluginutils.databse.DatabaseManager;
import cn.lunadeer.minecraftpluginutils.databse.Field;
import cn.lunadeer.minecraftpluginutils.databse.syntax.InsertRow;
import cn.lunadeer.minecraftpluginutils.databse.syntax.UpdateRow;
import java.sql.ResultSet;
import java.util.*;
public class PlayerPrivilegeDTO {
private static List<PlayerPrivilegeDTO> query(String sql, Object... params) {
List<PlayerPrivilegeDTO> players = new ArrayList<>();
try (ResultSet rs = DatabaseManager.instance.query(sql, params)) {
return getDTOFromRS(rs);
} catch (Exception e) {
DatabaseManager.handleDatabaseError("查询玩家权限失败: ", e, sql);
}
return players;
}
private static List<PlayerPrivilegeDTO> getDTOFromRS(ResultSet rs) {
List<PlayerPrivilegeDTO> players = new ArrayList<>();
if (rs == null) return players;
try {
while (rs.next()) {
Map<Flag, Boolean> flags = new HashMap<>();
for (Flag f : Flag.getPrivilegeFlagsEnabled()) {
flags.put(f, rs.getBoolean(f.getFlagName()));
}
PlayerPrivilegeDTO player = new PlayerPrivilegeDTO(
rs.getInt("id"),
UUID.fromString(rs.getString("player_uuid")),
rs.getBoolean("admin"),
rs.getInt("dom_id"),
flags
);
players.add(player);
}
} catch (Exception e) {
DatabaseManager.handleDatabaseError("查询玩家权限失败: ", e, "");
}
return players;
}
private PlayerPrivilegeDTO doUpdate(UpdateRow updateRow) {
Field id = new Field("id", this.id);
updateRow.returningAll(id)
.table("player_privilege")
.where("id = ?", id.value);
try (ResultSet rs = updateRow.execute()) {
List<PlayerPrivilegeDTO> players = getDTOFromRS(rs);
if (players.size() == 0) return null;
Cache.instance.loadPlayerPrivileges(playerUUID);
return players.get(0);
} catch (Exception e) {
DatabaseManager.handleDatabaseError("更新玩家权限失败: ", e, "");
return null;
}
}
public static PlayerPrivilegeDTO insert(PlayerPrivilegeDTO player) {
Field playerUUID = new Field("player_uuid", player.getPlayerUUID().toString());
Field admin = new Field("admin", player.getAdmin());
Field domID = new Field("dom_id", player.getDomID());
InsertRow insertRow = new InsertRow().returningAll().onConflictDoNothing(new Field("id", null))
.table("player_privilege")
.field(playerUUID)
.field(admin)
.field(domID);
for (Flag f : Flag.getPrivilegeFlagsEnabled()) {
insertRow.field(new Field(f.getFlagName(), player.getFlagValue(f)));
}
try (ResultSet rs = insertRow.execute()) {
Cache.instance.loadPlayerPrivileges(player.getPlayerUUID());
List<PlayerPrivilegeDTO> players = getDTOFromRS(rs);
if (players.size() == 0) return null;
return players.get(0);
} catch (Exception e) {
DatabaseManager.handleDatabaseError("插入玩家权限失败: ", e, "");
return null;
}
}
public static PlayerPrivilegeDTO select(UUID playerUUID, Integer dom_id) {
String sql = "SELECT * FROM player_privilege WHERE player_uuid = ? AND dom_id = ?;";
List<PlayerPrivilegeDTO> p = query(sql, playerUUID.toString(), dom_id);
if (p.size() == 0) return null;
return p.get(0);
}
public static List<PlayerPrivilegeDTO> select(Integer dom_id) {
String sql = "SELECT * FROM player_privilege WHERE dom_id = ?;";
return query(sql, dom_id);
}
public static void delete(UUID player, Integer domID) {
String sql = "DELETE FROM player_privilege WHERE player_uuid = ? AND dom_id = ?;";
query(sql, player.toString(), domID);
Cache.instance.loadPlayerPrivileges(player);
}
public static List<PlayerPrivilegeDTO> selectAll() {
String sql = "SELECT * FROM player_privilege;";
return query(sql);
}
public static List<PlayerPrivilegeDTO> selectAll(UUID player) {
String sql = "SELECT * FROM player_privilege WHERE player_uuid = ?;";
return query(sql, player.toString());
}
private final Integer id;
private final UUID playerUUID;
private Boolean admin;
private final Integer domID;
public Integer getId() {
return id;
}
public UUID getPlayerUUID() {
return playerUUID;
}
public Boolean getAdmin() {
return admin;
}
public Integer getDomID() {
return domID;
}
private final Map<Flag, Boolean> flags = new HashMap<>();
public Boolean getFlagValue(Flag flag) {
if (!flags.containsKey(flag)) return flag.getDefaultValue();
return flags.get(flag);
}
public PlayerPrivilegeDTO setFlagValue(Flag flag, Boolean value) {
flags.put(flag, value);
Field f = new Field(flag.getFlagName(), value);
UpdateRow updateRow = new UpdateRow().field(f);
return doUpdate(updateRow);
}
public PlayerPrivilegeDTO setAdmin(Boolean admin) {
this.admin = admin;
Field f = new Field("admin", admin);
UpdateRow updateRow = new UpdateRow().field(f);
return doUpdate(updateRow);
}
public PlayerPrivilegeDTO applyTemplate(PrivilegeTemplateDTO template) {
this.admin = template.getAdmin();
UpdateRow updateRow = new UpdateRow().field(new Field("admin", admin));
for (Flag f : Flag.getPrivilegeFlagsEnabled()) {
this.flags.put(f, template.getFlagValue(f));
updateRow.field(new Field(f.getFlagName(), template.getFlagValue(f)));
}
return doUpdate(updateRow);
}
private PlayerPrivilegeDTO(Integer id, UUID playerUUID, Boolean admin, Integer domID, Map<Flag, Boolean> flags) {
this.id = id;
this.playerUUID = playerUUID;
this.admin = admin;
this.domID = domID;
this.flags.putAll(flags);
}
public PlayerPrivilegeDTO(UUID playerUUID, DominionDTO dom) {
this.id = null;
this.playerUUID = playerUUID;
this.admin = false;
this.domID = dom.getId();
for (Flag f : Flag.getPrivilegeFlagsEnabled()) {
this.flags.put(f, dom.getFlagValue(f));
}
}
}

View File

@ -4,7 +4,8 @@ import cn.lunadeer.dominion.Cache;
import cn.lunadeer.dominion.Dominion;
import cn.lunadeer.dominion.dtos.DominionDTO;
import cn.lunadeer.dominion.dtos.Flag;
import cn.lunadeer.dominion.dtos.PlayerPrivilegeDTO;
import cn.lunadeer.dominion.dtos.GroupDTO;
import cn.lunadeer.dominion.dtos.MemberDTO;
import cn.lunadeer.minecraftpluginutils.Notification;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
@ -16,7 +17,7 @@ import org.bukkit.event.Cancellable;
import org.bukkit.inventory.Inventory;
public class Apis {
public static boolean canByPass(Player player, DominionDTO dom, PlayerPrivilegeDTO prev) {
public static boolean canByPass(Player player, DominionDTO dom, MemberDTO prev) {
if (player.isOp() && Dominion.config.getLimitOpBypass()) {
return true;
}
@ -47,13 +48,23 @@ public class Apis {
if (dom == null) {
return true;
}
PlayerPrivilegeDTO prev = Cache.instance.getPlayerPrivilege(player, dom);
MemberDTO prev = Cache.instance.getMember(player, dom);
if (canByPass(player, dom, prev)) {
return true;
}
if (prev != null) {
if (prev.getFlagValue(flag)) {
return true;
if (prev.getGroupId() == -1) {
if (prev.getFlagValue(flag)) {
return true;
}
} else {
GroupDTO group = Cache.instance.getGroup(prev.getGroupId());
if (group == null) {
return false;
}
if (group.getFlagValue(flag)) {
return true;
}
}
} else {
if (dom.getFlagValue(flag)) {

View File

@ -313,6 +313,20 @@ public class PlayerEvents implements Listener {
checkFlag(dom, Flag.DOOR, player, event);
}
@EventHandler(priority = EventPriority.HIGHEST) // dragon_egg
public void touchDragonEdd(PlayerInteractEvent event) {
Block block = event.getClickedBlock();
if (block == null) {
return;
}
if (block.getType() != Material.DRAGON_EGG) {
return;
}
Player player = event.getPlayer();
DominionDTO dom = Cache.instance.getDominion(block.getLocation());
checkFlag(dom, Flag.DRAGON_EGG, player, event);
}
@EventHandler(priority = EventPriority.HIGHEST) // dye
public void dyeEvent(PlayerInteractEntityEvent event) {
Player player = event.getPlayer();

View File

@ -83,6 +83,7 @@ public class ConfigManager {
_economy_only_xz = _file.getBoolean("Economy.OnlyXZ", false);
_economy_refund = (float) _file.getDouble("Economy.Refund", 0.85);
_fly_permission_nodes = _file.getStringList("FlyPermissionNodes");
_residence_migration = _file.getBoolean("ResidenceMigration", false);
saveAll(); // 回写文件 防止文件中的数据不完整
Flag.loadFromJson();
}
@ -111,6 +112,7 @@ public class ConfigManager {
_file.set("Economy.OnlyXZ", _economy_only_xz);
_file.set("Economy.Refund", _economy_refund);
_file.set("FlyPermissionNodes", _fly_permission_nodes);
_file.set("ResidenceMigration", _residence_migration);
_plugin.saveConfig();
}
@ -388,6 +390,16 @@ public class ConfigManager {
_plugin.saveConfig();
}
public Boolean getResidenceMigration() {
return _residence_migration;
}
public void setResidenceMigration(Boolean residence_migration) {
_residence_migration = residence_migration;
_file.set("ResidenceMigration", residence_migration);
_plugin.saveConfig();
}
private final Dominion _plugin;
private FileConfiguration _file;
private Boolean _debug;
@ -426,4 +438,5 @@ public class ConfigManager {
private Boolean _economy_only_xz;
private Float _economy_refund;
private List<String> _fly_permission_nodes;
private Boolean _residence_migration;
}

View File

@ -6,10 +6,13 @@ import cn.lunadeer.minecraftpluginutils.databse.DatabaseManager;
import cn.lunadeer.minecraftpluginutils.databse.Field;
import cn.lunadeer.minecraftpluginutils.databse.FieldType;
import cn.lunadeer.minecraftpluginutils.databse.TableColumn;
import cn.lunadeer.minecraftpluginutils.databse.*;
import cn.lunadeer.minecraftpluginutils.databse.syntax.AddColumn;
import cn.lunadeer.minecraftpluginutils.databse.syntax.CreateTable;
import cn.lunadeer.minecraftpluginutils.databse.syntax.InsertRow;
import java.sql.ResultSet;
public class DatabaseTables {
public static void migrate() {
// player name
@ -60,23 +63,35 @@ public class DatabaseTables {
.foreignKey(dominion_parent_dom_id_fk);
dominion.execute();
for (Flag flag : Flag.getAllDominionFlags()) {
TableColumn column = new TableColumn(flag.getFlagName(), FieldType.BOOLEAN, false, false, true, false, flag.getDefaultValue());
new AddColumn(column).table("dominion").ifNotExists().execute();
}
// player privilege
TableColumn player_privilege_id = new TableColumn("id", FieldType.INT, true, true, true, true, 0);
TableColumn player_privilege_player_uuid = new TableColumn("player_uuid", FieldType.STRING, false, false, true, false, "''");
TableColumn player_privilege_dom_id = new TableColumn("dom_id", FieldType.INT, false, false, true, false, -1);
TableColumn player_privilege_admin = new TableColumn("admin", FieldType.BOOLEAN, false, false, true, false, false);
CreateTable.ForeignKey player_privilege_player_uuid_fk = new CreateTable.ForeignKey(player_privilege_player_uuid, "player_name", player_name_uuid, true);
CreateTable.ForeignKey player_privilege_dom_id_fk = new CreateTable.ForeignKey(player_privilege_dom_id, "dominion", dominion_id, true);
CreateTable player_privilege = new CreateTable().ifNotExists();
player_privilege.table("player_privilege")
.field(player_privilege_id)
.field(player_privilege_player_uuid)
.field(player_privilege_dom_id)
.field(player_privilege_admin)
.foreignKey(player_privilege_player_uuid_fk)
.foreignKey(player_privilege_dom_id_fk)
.unique(player_privilege_player_uuid, player_privilege_dom_id);
player_privilege.execute();
if (!Common.IsTableExist("dominion_member")) {
TableColumn player_privilege_id = new TableColumn("id", FieldType.INT, true, true, true, true, 0);
TableColumn player_privilege_player_uuid = new TableColumn("player_uuid", FieldType.STRING, false, false, true, false, "''");
TableColumn player_privilege_dom_id = new TableColumn("dom_id", FieldType.INT, false, false, true, false, -1);
TableColumn player_privilege_admin = new TableColumn("admin", FieldType.BOOLEAN, false, false, true, false, false);
CreateTable.ForeignKey player_privilege_player_uuid_fk = new CreateTable.ForeignKey(player_privilege_player_uuid, "player_name", player_name_uuid, true);
CreateTable.ForeignKey player_privilege_dom_id_fk = new CreateTable.ForeignKey(player_privilege_dom_id, "dominion", dominion_id, true);
CreateTable player_privilege = new CreateTable().ifNotExists();
player_privilege.table("player_privilege")
.field(player_privilege_id)
.field(player_privilege_player_uuid)
.field(player_privilege_dom_id)
.field(player_privilege_admin)
.foreignKey(player_privilege_player_uuid_fk)
.foreignKey(player_privilege_dom_id_fk)
.unique(player_privilege_player_uuid, player_privilege_dom_id);
player_privilege.execute();
for (Flag flag : Flag.getAllPrivilegeFlags()) {
TableColumn column = new TableColumn(flag.getFlagName(), FieldType.BOOLEAN, false, false, true, false, flag.getDefaultValue());
new AddColumn(column).table("player_privilege").ifNotExists().execute();
}
}
// server root player name
Field server_player_name_id_field = new Field("id", -1);
@ -118,21 +133,11 @@ public class DatabaseTables {
.field(server_dom_leave_message_field);
insert_server_dom.execute();
for (Flag flag : Flag.getAllDominionFlags()) {
TableColumn column = new TableColumn(flag.getFlagName(), FieldType.BOOLEAN, false, false, true, false, flag.getDefaultValue());
new AddColumn(column).table("dominion").ifNotExists().execute();
}
for (Flag flag : Flag.getAllPrivilegeFlags()) {
TableColumn column = new TableColumn(flag.getFlagName(), FieldType.BOOLEAN, false, false, true, false, flag.getDefaultValue());
new AddColumn(column).table("player_privilege").ifNotExists().execute();
}
// 1.18.0
// 1.18.0 dominion add tp_location
TableColumn dominion_tp_location = new TableColumn("tp_location", FieldType.STRING, false, false, true, false, "'default'");
new AddColumn(dominion_tp_location).table("dominion").ifNotExists().execute();
// 1.31.0
// 1.31.0 add privilege_template
TableColumn privilege_template_id = new TableColumn("id", FieldType.INT, true, true, true, true, 0);
TableColumn privilege_template_creator = new TableColumn("creator", FieldType.STRING, false, false, true, false, "''");
TableColumn privilege_template_name = new TableColumn("name", FieldType.STRING, false, false, true, false, "'未命名'");
@ -154,10 +159,84 @@ public class DatabaseTables {
new AddColumn(column).table("privilege_template").ifNotExists().execute();
}
// 1.31.6
// 1.31.6 dominion add blue-map tile color
TableColumn dominion_color = new TableColumn("color", FieldType.STRING, false, false, true, false, "'#00BFFF'");
new AddColumn(dominion_color).table("dominion").ifNotExists().execute();
// 1.34.0 add dominion_group
if (!Common.IsTableExist("dominion_member")) {
TableColumn player_privilege_group_id = new TableColumn("group_id", FieldType.INT, false, false, true, false, -1);
new AddColumn(player_privilege_group_id).table("player_privilege").ifNotExists().execute();
}
TableColumn dominion_group_id = new TableColumn("id", FieldType.INT, true, true, true, true, 0);
TableColumn dominion_group_dom_id = new TableColumn("dom_id", FieldType.INT, false, false, true, false, -1);
TableColumn dominion_group_name = new TableColumn("name", FieldType.STRING, false, false, true, false, "'未命名'");
TableColumn dominion_group_admin = new TableColumn("admin", FieldType.BOOLEAN, false, false, true, false, false);
CreateTable.ForeignKey group_dom_id_fk = new CreateTable.ForeignKey(dominion_group_dom_id, "dominion", dominion_id, true);
CreateTable group = new CreateTable().ifNotExists();
group.table("dominion_group")
.field(dominion_group_id)
.field(dominion_group_dom_id)
.field(dominion_group_name)
.field(dominion_group_admin)
.foreignKey(group_dom_id_fk)
.unique(dominion_group_dom_id, dominion_group_name);
group.execute();
for (Flag flag : Flag.getAllPrivilegeFlags()) {
TableColumn column = new TableColumn(flag.getFlagName(), FieldType.BOOLEAN, false, false, true, false, flag.getDefaultValue());
new AddColumn(column).table("dominion_group").ifNotExists().execute();
}
// 1.35.0 migrate player_privilege -> dominion_member
TableColumn dominion_member_id = new TableColumn("id", FieldType.INT, true, true, true, true, 0);
TableColumn dominion_member_player_uuid = new TableColumn("player_uuid", FieldType.STRING, false, false, true, false, "''");
TableColumn dominion_member_dom_id = new TableColumn("dom_id", FieldType.INT, false, false, true, false, -1);
TableColumn dominion_member_admin = new TableColumn("admin", FieldType.BOOLEAN, false, false, true, false, false);
TableColumn dominion_member_group_id = new TableColumn("group_id", FieldType.INT, false, false, true, false, -1);
CreateTable.ForeignKey dominion_member_player_uuid_fk = new CreateTable.ForeignKey(dominion_member_player_uuid, "player_name", player_name_uuid, true);
CreateTable.ForeignKey dominion_member_dom_id_fk = new CreateTable.ForeignKey(dominion_member_dom_id, "dominion", dominion_id, true);
CreateTable dominion_member = new CreateTable().ifNotExists();
dominion_member.table("dominion_member")
.field(dominion_member_id)
.field(dominion_member_player_uuid)
.field(dominion_member_dom_id)
.field(dominion_member_admin)
.field(dominion_member_group_id)
.foreignKey(dominion_member_player_uuid_fk)
.foreignKey(dominion_member_dom_id_fk)
.unique(dominion_member_player_uuid, dominion_member_dom_id);
dominion_member.execute();
for (Flag flag : Flag.getAllPrivilegeFlags()) {
TableColumn column = new TableColumn(flag.getFlagName(), FieldType.BOOLEAN, false, false, true, false, flag.getDefaultValue());
new AddColumn(column).table("dominion_member").ifNotExists().execute();
}
if (Common.IsTableExist("player_privilege")) {
// migrate from player_privilege to dominion_member
String sql = "SELECT * FROM player_privilege;";
try (ResultSet rs = DatabaseManager.instance.query(sql)) {
while (rs.next()) {
String player_uuid = rs.getString("player_uuid");
int dom_id = rs.getInt("dom_id");
boolean admin = rs.getBoolean("admin");
int group_id = rs.getInt("group_id");
InsertRow insert = new InsertRow().table("dominion_member")
.field(new Field("player_uuid", player_uuid))
.field(new Field("dom_id", dom_id))
.field(new Field("group_id", group_id))
.field(new Field("admin", admin));
for (Flag flag : Flag.getAllPrivilegeFlags()) {
insert.field(new Field(flag.getFlagName(), rs.getBoolean(flag.getFlagName())));
}
insert.execute();
}
sql = "DROP TABLE player_privilege;";
DatabaseManager.instance.query(sql);
} catch (Exception e) {
DatabaseManager.handleDatabaseError("迁移 player_privilege 到 dominion_member 失败", e, sql);
}
}
// global teleport
TableColumn server_info_id = new TableColumn("id", FieldType.INT, true, true, true, true, 0);
TableColumn server_info_name = new TableColumn("name", FieldType.STRING, false, false, true, false, "'server'");

View File

@ -13,7 +13,7 @@ import java.util.List;
import static cn.lunadeer.dominion.commands.Apis.playerOnly;
import static cn.lunadeer.dominion.tuis.Apis.getPage;
import static cn.lunadeer.dominion.tuis.Apis.notOp;
import static cn.lunadeer.dominion.tuis.ListDominion.BuildTreeLines;
import static cn.lunadeer.dominion.tuis.dominion.DominionList.BuildTreeLines;
public class AllDominion {
@ -21,7 +21,7 @@ public class AllDominion {
Player player = playerOnly(sender);
if (player == null) return;
if (notOp(player)) return;
int page = getPage(args);
int page = getPage(args, 1);
List<DominionNode> allDominions = Cache.instance.getAllDominionTree();

View File

@ -2,7 +2,7 @@ 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.dominion.dtos.MemberDTO;
import cn.lunadeer.minecraftpluginutils.Notification;
import cn.lunadeer.minecraftpluginutils.stui.ListView;
import cn.lunadeer.minecraftpluginutils.stui.components.Button;
@ -14,11 +14,11 @@ import static cn.lunadeer.dominion.commands.Apis.playerOnly;
public class Apis {
public static int getPage(String[] args) {
public static int getPage(String[] args, int pos) {
int page = 1;
if (args.length == 2) {
if (args.length > pos) {
try {
page = Integer.parseInt(args[1]);
page = Integer.parseInt(args[pos]);
} catch (Exception e) {
return 1;
}
@ -42,26 +42,10 @@ public class Apis {
}
}
/**
* 尝试从 arg[2] 获取领地名称
* 如果没有此参数则会尝试获取玩家当前所在位置
*
* @param player 玩家
* @param args 参数
* @return 领地信息
*/
public static DominionDTO getDominionNameArg_2(Player player, String[] args) {
if (args.length >= 3) {
return DominionDTO.select(args[2]);
} else {
return Cache.instance.getPlayerCurrentDominion(player);
}
}
public static boolean noAuthToManage(Player player, DominionDTO dominion) {
if (player.isOp()) return false;
if (!dominion.getOwner().equals(player.getUniqueId())) {
PlayerPrivilegeDTO privileges = PlayerPrivilegeDTO.select(player.getUniqueId(), dominion.getId());
MemberDTO privileges = MemberDTO.select(player.getUniqueId(), dominion.getId());
if (privileges == null || !privileges.getAdmin()) {
Notification.error(player, "你不是领地 %s 的拥有者或管理员,无权访问此页面", dominion.getName());
return true;
@ -81,11 +65,11 @@ public class Apis {
public static void printHelp(CommandSender sender, String[] args) {
Player player = playerOnly(sender);
if (player == null) return;
int page = getPage(args);
int page = getPage(args, 1);
ListView view = ListView.create(10, "/dominion help");
view.title("领地插件命令帮助 <>表示必填参数 []表示可选参数")
.add(Line.create().append("打开交互菜单").append(Button.create("/dominion menu").setExecuteCommand("/dominion menu").build()))
.add(Line.create().append("查看帮助").append(Button.create("/dominion help [页码]").setExecuteCommand("/dominion help 1").build()))
.add(Line.create().append("打开交互菜单").append("/dominion menu"))
.add(Line.create().append("查看帮助").append("/dominion help [页码]"))
.add(Line.create().append("创建领地").append("/dominion create <领地名称>"))
.add(Line.create().append("自动创建领地").append("/dominion auto_create <领地名称>"))
.add(Line.create().append("创建子领地").append("/dominion create_sub <子领地名称> [父领地名称]"))
@ -104,18 +88,6 @@ public class Apis {
.add(Line.create().append("---[管理员指令]---"))
.add(Line.create().append("刷新缓存").append(Button.create("/dominion reload_cache").setExecuteCommand("/dominion reload_cache").build()))
.add(Line.create().append("重载配置").append(Button.create("/dominion reload_config").setExecuteCommand("/dominion reload_config").build()))
// 以下指令主要被用于 ui 触发
.add(Line.create().append("---[以下主要用于UI触发]---"))
.add(Line.create().append("列出所有领地").append(Button.create("/dominion list [页码]").setExecuteCommand("/dominion list").build()))
.add(Line.create().append("查看领地信息").append(Button.create("/dominion info [领地名称]").setExecuteCommand("/dominion info").build()))
.add(Line.create().append("查看领地权限信息").append(Button.create("/dominion flag_info <领地名称> [页码]").setExecuteCommand("/dominion flag_info").build()))
.add(Line.create().append("设置领地权限").append("/dominion set <权限名称> <true/false> [领地名称]"))
.add(Line.create().append("创建玩家特权").append("/dominion create_privilege <玩家名称> [领地名称]"))
.add(Line.create().append("设置玩家特权").append("/dominion set_privilege <玩家名称> <权限名称> <true/false> [领地名称]"))
.add(Line.create().append("重置玩家特权").append("/dominion clear_privilege <玩家名称> [领地名称]"))
.add(Line.create().append("查看领地玩家特权列表").append("/dominion privilege_list [领地名称] [页码]"))
.add(Line.create().append("查看玩家特权信息").append("/dominion privilege_info <玩家名称> [领地名称] [页码]"))
.add(Line.create().append("系统配置").append(Button.create("/dominion config [页码]").setExecuteCommand("/dominion config").build()))
.showOn(player, page);
}

View File

@ -1,91 +0,0 @@
package cn.lunadeer.dominion.tuis;
import cn.lunadeer.dominion.dtos.DominionDTO;
import cn.lunadeer.dominion.dtos.Flag;
import cn.lunadeer.dominion.dtos.PlayerDTO;
import cn.lunadeer.dominion.dtos.PlayerPrivilegeDTO;
import cn.lunadeer.minecraftpluginutils.Notification;
import cn.lunadeer.minecraftpluginutils.stui.ListView;
import cn.lunadeer.minecraftpluginutils.stui.components.Button;
import cn.lunadeer.minecraftpluginutils.stui.components.Line;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.format.Style;
import net.kyori.adventure.text.format.TextColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.List;
import static cn.lunadeer.dominion.commands.Apis.playerOnly;
import static cn.lunadeer.dominion.tuis.Apis.getDominionNameArg_1;
import static cn.lunadeer.dominion.tuis.Apis.noAuthToManage;
public class DominionPrivilegeList {
public static void show(CommandSender sender, String[] args) {
int page = 1;
if (args.length == 3) {
try {
page = Integer.parseInt(args[2]);
} catch (Exception ignored) {
}
}
Player player = playerOnly(sender);
if (player == null) return;
DominionDTO dominion = getDominionNameArg_1(player, args);
if (dominion == null) {
Notification.error(sender, "你不在任何领地内,请指定领地名称 /dominion privilege_list <领地名称>");
return;
}
ListView view = ListView.create(10, "/dominion privilege_list " + dominion.getName());
if (noAuthToManage(player, dominion)) return;
List<PlayerPrivilegeDTO> privileges = PlayerPrivilegeDTO.select(dominion.getId());
view.title("领地 " + dominion.getName() + " 成员列表");
view.navigator(
Line.create()
.append(Button.create("主菜单").setExecuteCommand("/dominion menu").build())
.append(Button.create("我的领地").setExecuteCommand("/dominion list").build())
.append(Button.create("管理界面").setExecuteCommand("/dominion manage " + dominion.getName()).build())
.append("成员列表")
);
view.add(Line.create().append(Button.create("添加成员").setExecuteCommand("/dominion select_player_create_privilege " + dominion.getName()).build()));
for (PlayerPrivilegeDTO privilege : privileges) {
PlayerDTO p_player = PlayerDTO.select(privilege.getPlayerUUID());
if (p_player == null) continue;
Line line = Line.create();
if (privilege.getAdmin()) {
line.append(adminTag);
} else {
if (!privilege.getFlagValue(Flag.MOVE)) {
line.append(banTag);
} else {
line.append(normalTag);
}
}
line.append(Button.createGreen("权限")
.setHoverText("配置成员权限")
.setExecuteCommand("/dominion privilege_info " + p_player.getLastKnownName() + " " + dominion.getName()).build());
if ((!player.getName().equals(p_player.getLastKnownName()) && !privilege.getAdmin()) || dominion.getOwner().equals(player.getUniqueId())) {
line.append(Button.createRed("移除")
.setHoverText("将此成员移出(变为访客)")
.setExecuteCommand("/dominion clear_privilege " + p_player.getLastKnownName() + " " + dominion.getName() + " b").build());
line.append(Button.createGreen("模板")
.setHoverText("套用权限模板")
.setExecuteCommand("/dominion select_template " + p_player.getLastKnownName() + " " + dominion.getName() + " " + page).build());
}
line.append(p_player.getLastKnownName());
view.add(line);
}
view.showOn(player, page);
}
private static final TextComponent adminTag = Component.text("[A]", Style.style(TextColor.color(97, 97, 210)))
.hoverEvent(Component.text("这是一个管理员"));
private static final TextComponent normalTag = Component.text("[N]", Style.style(TextColor.color(255, 255, 255)))
.hoverEvent(Component.text("这是一个普通成员"));
private static final TextComponent banTag = Component.text("[B]", Style.style(TextColor.color(255, 67, 0)))
.hoverEvent(Component.text("这是一个黑名单成员"));
}

View File

@ -1,5 +1,6 @@
package cn.lunadeer.dominion.tuis;
import cn.lunadeer.dominion.Dominion;
import cn.lunadeer.minecraftpluginutils.stui.ListView;
import cn.lunadeer.minecraftpluginutils.stui.ViewStyles;
import cn.lunadeer.minecraftpluginutils.stui.components.Button;
@ -30,7 +31,7 @@ public class Menu {
.append(Button.create("我的领地").setExecuteCommand("/dominion list").build())
.append("查看我的领地");
Line template = Line.create()
.append(Button.create("模板列表").setExecuteCommand("/dominion template_list").build())
.append(Button.create("模板列表").setExecuteCommand("/dominion template list").build())
.append("成员权限模板列表");
Line help = Line.create()
.append(Button.create("指令帮助").setExecuteCommand("/dominion help").build())
@ -38,6 +39,9 @@ public class Menu {
Line link = Line.create()
.append(Button.create("使用文档").setOpenURL("https://ssl.lunadeer.cn:14448/doc/23/").build())
.append("在浏览器中打开使用文档");
Line migrate = Line.create()
.append(Button.create("迁移数据").setExecuteCommand("/dominion migrate_list").build())
.append("把你的领地从Residence迁移到Dominion");
Line all = Line.create()
.append(Button.create("所有领地").setExecuteCommand("/dominion all_dominion").build())
.append("查看所有领地");
@ -58,6 +62,9 @@ public class Menu {
.add(template)
.add(help)
.add(link);
if (Dominion.config.getResidenceMigration()) {
view.add(migrate);
}
if (player.isOp()) {
view.add(Line.create().append(""));
view.add(Line.create().append(Component.text("--- 以下选项仅OP可见 ---", ViewStyles.main_color)));

View File

@ -0,0 +1,75 @@
package cn.lunadeer.dominion.tuis;
import cn.lunadeer.dominion.Cache;
import cn.lunadeer.dominion.Dominion;
import cn.lunadeer.dominion.utils.ResMigration;
import cn.lunadeer.minecraftpluginutils.Notification;
import cn.lunadeer.minecraftpluginutils.stui.ListView;
import cn.lunadeer.minecraftpluginutils.stui.components.Button;
import cn.lunadeer.minecraftpluginutils.stui.components.Line;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.format.Style;
import net.kyori.adventure.text.format.TextColor;
import net.kyori.adventure.text.format.TextDecoration;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.List;
import static cn.lunadeer.dominion.commands.Apis.playerOnly;
public class MigrateList {
public static void show(CommandSender sender, String[] args) {
Player player = playerOnly(sender);
if (player == null) return;
if (!Dominion.config.getResidenceMigration()) {
Notification.error(sender, "Residence 迁移功能没有开启");
return;
}
int page = Apis.getPage(args, 1);
ListView view = ListView.create(10, "/dominion migrate_list");
view.title("从 Residence 迁移数据");
view.navigator(Line.create().append(Button.create("主菜单").setExecuteCommand("/dominion menu").build()).append("Res数据"));
List<ResMigration.ResidenceNode> res_data = Cache.instance.getResidenceData(player.getUniqueId());
if (res_data == null) {
view.add(Line.create().append("你没有可迁移的数据"));
} else {
view.addLines(BuildTreeLines(res_data, 0, page));
}
view.showOn(player, page);
}
public static List<Line> BuildTreeLines(List<ResMigration.ResidenceNode> dominionTree, Integer depth, int page) {
List<Line> lines = new ArrayList<>();
StringBuilder prefix = new StringBuilder();
for (int i = 0; i < depth; i++) {
prefix.append(" | ");
}
for (ResMigration.ResidenceNode node : dominionTree) {
TextComponent migrate = Button.create("迁移").setExecuteCommand("/dominion migrate " + node.name + " " + page).build();
Line line = Line.create();
if (depth == 0) {
line.append(migrate);
} else {
line.append(Component.text("[迁移]",
Style.style(TextColor.color(190, 190, 190),
TextDecoration.STRIKETHROUGH))
.hoverEvent(Component.text("子领地无法手动迁移,会随父领地自动迁移")));
}
line.append(prefix + node.name);
lines.add(line);
lines.addAll(BuildTreeLines(node.children, depth + 1, page));
}
return lines;
}
}

View File

@ -15,13 +15,13 @@ import static cn.lunadeer.dominion.commands.Apis.playerOnly;
import static cn.lunadeer.dominion.tuis.Apis.getPage;
import static cn.lunadeer.dominion.tuis.Apis.notOp;
public class DominionConfig {
public class SysConfig {
public static void show(CommandSender sender, String[] args) {
Player player = playerOnly(sender);
if (player == null) return;
if (notOp(player)) return;
int page = getPage(args);
ListView view = ListView.create(10, "/dominion config");
int page = getPage(args, 1);
ListView view = ListView.create(10, "/dominion sys_config");
view.title("系统配置");
view.navigator(Line.create().append(Button.create("主菜单").setExecuteCommand("/dominion menu").build()).append("系统配置"));
@ -151,6 +151,15 @@ public class DominionConfig {
.append(NumChanger.create(Dominion.config.getEconomyRefund(), "/dominion set_config economy_refund", 0.01).setPageNumber(page).build());
view.add(refund);
}
if (Dominion.config.getResidenceMigration()) {
view.add(Line.create()
.append("是否允许从Residence迁移数据")
.append(Button.createGreen("").setExecuteCommand("/dominion set_config residence_migration false " + page).build()));
} else {
view.add(Line.create()
.append("是否允许从Residence迁移数据")
.append(Button.createRed("").setExecuteCommand("/dominion set_config residence_migration true " + page).build()));
}
view.showOn(player, page);
}
}

View File

@ -1,4 +1,4 @@
package cn.lunadeer.dominion.tuis;
package cn.lunadeer.dominion.tuis.dominion;
import cn.lunadeer.dominion.Cache;
import cn.lunadeer.dominion.DominionNode;
@ -21,11 +21,11 @@ import static cn.lunadeer.dominion.commands.Apis.playerOnly;
import static cn.lunadeer.dominion.commands.Helper.playerAdminDominions;
import static cn.lunadeer.dominion.tuis.Apis.getPage;
public class ListDominion {
public class DominionList {
public static void show(CommandSender sender, String[] args) {
Player player = playerOnly(sender);
if (player == null) return;
int page = getPage(args);
int page = getPage(args, 1);
ListView view = ListView.create(10, "/dominion list");
view.title("我的领地列表");

View File

@ -1,4 +1,4 @@
package cn.lunadeer.dominion.tuis;
package cn.lunadeer.dominion.tuis.dominion;
import cn.lunadeer.dominion.Dominion;
import cn.lunadeer.dominion.dtos.DominionDTO;
@ -12,8 +12,7 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import static cn.lunadeer.dominion.commands.Apis.playerOnly;
import static cn.lunadeer.dominion.tuis.Apis.getDominionNameArg_1;
import static cn.lunadeer.dominion.tuis.Apis.noAuthToManage;
import static cn.lunadeer.dominion.tuis.Apis.*;
public class DominionManage {
public static void show(CommandSender sender, String[] args) {
@ -25,18 +24,22 @@ public class DominionManage {
return;
}
if (noAuthToManage(player, dominion)) return;
int page = getPage(args, 2);
Line size_info = Line.create()
.append(Button.create("详细信息").setExecuteCommand("/dominion info " + dominion.getName()).build())
.append("查看领地详细信息");
Line env_info = Line.create()
.append(Button.create("环境设置").setExecuteCommand("/dominion env_info " + dominion.getName()).build())
.append(Button.create("环境设置").setExecuteCommand("/dominion env_setting " + dominion.getName()).build())
.append("设置领地内的一些非玩家相关效果");
Line flag_info = Line.create()
.append(Button.create("访客权限").setExecuteCommand("/dominion flag_info " + dominion.getName()).build())
.append(Button.create("访客权限").setExecuteCommand("/dominion guest_setting " + dominion.getName()).build())
.append("访客在此领地的权限");
Line privilege_list = Line.create()
.append(Button.create("成员权限").setExecuteCommand("/dominion privilege_list " + dominion.getName()).build())
.append(Button.create("成员管理").setExecuteCommand("/dominion member list " + dominion.getName()).build())
.append("管理此领地成员的权限");
Line group_list = Line.create()
.append(Button.create("权限组").setExecuteCommand("/dominion group list " + dominion.getName()).build())
.append("管理此领地的权限组");
Line set_tp = Line.create()
.append(Button.create("设置传送点").setExecuteCommand("/dominion set_tp_location " + dominion.getName()).build())
.append("设置当前位置为此领地传送点");
@ -64,6 +67,7 @@ public class DominionManage {
.add(env_info)
.add(flag_info)
.add(privilege_list)
.add(group_list)
.add(set_tp)
.add(rename)
.add(join_msg)
@ -71,6 +75,6 @@ public class DominionManage {
if (Dominion.config.getBlueMap()) {
view.add(map_color);
}
view.showOn(player, 1);
view.showOn(player, page);
}
}

View File

@ -1,4 +1,4 @@
package cn.lunadeer.dominion.tuis;
package cn.lunadeer.dominion.tuis.dominion.manage;
import cn.lunadeer.dominion.dtos.DominionDTO;
import cn.lunadeer.dominion.dtos.Flag;
@ -11,29 +11,24 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import static cn.lunadeer.dominion.commands.Apis.playerOnly;
import static cn.lunadeer.dominion.tuis.Apis.getPage;
public class DominionEnvInfo {
public class EnvSetting {
public static void show(CommandSender sender, String[] args) {
Player player = playerOnly(sender);
if (player == null) return;
if (args.length < 2) {
Notification.error(sender, "用法: /dominion env_info <领地名称> [页码]");
Notification.error(sender, "用法: /dominion env_setting <领地名称> [页码]");
return;
}
Player player = playerOnly(sender);
if (player == null) return;
DominionDTO dominion = DominionDTO.select(args[1]);
if (dominion == null) {
Notification.error(sender, "领地 %s 不存在", args[1]);
return;
}
int page = 1;
if (args.length == 3) {
try {
page = Integer.parseInt(args[2]);
} catch (Exception ignored) {
}
}
ListView view = ListView.create(10, "/dominion env_info " + dominion.getName());
int page = getPage(args, 2);
ListView view = ListView.create(10, "/dominion env_setting " + dominion.getName());
view.title("领地 " + dominion.getName() + " 环境设置")
.navigator(Line.create()
.append(Button.create("主菜单").setExecuteCommand("/dominion menu").build())

View File

@ -1,4 +1,4 @@
package cn.lunadeer.dominion.tuis;
package cn.lunadeer.dominion.tuis.dominion.manage;
import cn.lunadeer.dominion.dtos.DominionDTO;
import cn.lunadeer.dominion.dtos.Flag;
@ -11,29 +11,24 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import static cn.lunadeer.dominion.commands.Apis.playerOnly;
import static cn.lunadeer.dominion.tuis.Apis.getPage;
public class DominionFlagInfo {
public class GuestSetting {
public static void show(CommandSender sender, String[] args) {
Player player = playerOnly(sender);
if (player == null) return;
if (args.length < 2) {
Notification.error(sender, "用法: /dominion flag_info <领地名称> [页码]");
Notification.error(sender, "用法: /dominion guest_setting <领地名称> [页码]");
return;
}
Player player = playerOnly(sender);
if (player == null) return;
DominionDTO dominion = DominionDTO.select(args[1]);
if (dominion == null) {
Notification.error(sender, "领地 %s 不存在", args[1]);
return;
}
int page = 1;
if (args.length == 3) {
try {
page = Integer.parseInt(args[2]);
} catch (Exception ignored) {
}
}
ListView view = ListView.create(10, "/dominion flag_info " + dominion.getName());
int page = getPage(args, 2);
ListView view = ListView.create(10, "/dominion guest_setting " + dominion.getName());
view.title("领地 " + dominion.getName() + " 访客权限")
.navigator(Line.create()
.append(Button.create("主菜单").setExecuteCommand("/dominion menu").build())

View File

@ -1,4 +1,4 @@
package cn.lunadeer.dominion.tuis;
package cn.lunadeer.dominion.tuis.dominion.manage;
import cn.lunadeer.dominion.Dominion;
import cn.lunadeer.dominion.controllers.PlayerController;
@ -15,7 +15,7 @@ import org.bukkit.entity.Player;
import static cn.lunadeer.dominion.commands.Apis.playerOnly;
import static cn.lunadeer.dominion.tuis.Apis.getDominionNameArg_1;
public class DominionSizeInfo {
public class SizeInfo {
public static void show(CommandSender sender, String[] args) {
Player player = playerOnly(sender);
if (player == null) return;
@ -47,7 +47,7 @@ public class DominionSizeInfo {
))
.actionBar(Line.create()
.append(Button.create("管理界面").setExecuteCommand("/dominion manage " + dominion.getName()).build())
.append(Button.create("权限列表").setExecuteCommand("/dominion flag_info " + dominion.getName()).build()))
.append(Button.create("访客权限").setExecuteCommand("/dominion guest_setting " + dominion.getName()).build()))
.showOn(player);
ParticleRender.showBoxFace(Dominion.instance, player,
dominion.getLocation1(),

View File

@ -0,0 +1,93 @@
package cn.lunadeer.dominion.tuis.dominion.manage.group;
import cn.lunadeer.dominion.dtos.DominionDTO;
import cn.lunadeer.dominion.dtos.GroupDTO;
import cn.lunadeer.dominion.dtos.MemberDTO;
import cn.lunadeer.dominion.dtos.PlayerDTO;
import cn.lunadeer.dominion.tuis.Apis;
import cn.lunadeer.minecraftpluginutils.Notification;
import cn.lunadeer.minecraftpluginutils.XLogger;
import cn.lunadeer.minecraftpluginutils.stui.ListView;
import cn.lunadeer.minecraftpluginutils.stui.components.Button;
import cn.lunadeer.minecraftpluginutils.stui.components.Line;
import net.kyori.adventure.text.Component;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.List;
import static cn.lunadeer.dominion.commands.Apis.playerOnly;
import static cn.lunadeer.dominion.tuis.Apis.noAuthToManage;
public class GroupList {
public static void show(CommandSender sender, String dominionName) {
show(sender, new String[]{"", "", dominionName});
}
public static void show(CommandSender sender, String dominionName, int page) {
show(sender, new String[]{"", "", dominionName, String.valueOf(page)});
}
public static void show(CommandSender sender, String[] args) {
if (args.length < 3) {
Notification.error(sender, "用法: /dominion group list <领地名称> [页码]");
return;
}
Player player = playerOnly(sender);
if (player == null) return;
DominionDTO dominion = DominionDTO.select(args[2]);
if (dominion == null) {
Notification.error(sender, "领地 %s 不存在", args[2]);
return;
}
if (noAuthToManage(player, dominion)) return;
int page = Apis.getPage(args, 3);
List<GroupDTO> groups = GroupDTO.selectByDominionId(dominion.getId());
ListView view = ListView.create(10, "/dominion group list " + dominion.getName());
view.title("权限组列表");
view.navigator(
Line.create()
.append(Button.create("主菜单").setExecuteCommand("/dominion menu").build())
.append(Button.create("我的领地").setExecuteCommand("/dominion list").build())
.append(Button.create("管理界面").setExecuteCommand("/dominion manage " + dominion.getName()).build())
.append("权限组列表")
);
Button create_btn = Button.createGreen("创建权限组")
.setHoverText("创建一个新的权限组")
.setExecuteCommand("/dominion cui_create_group " + dominion.getName());
view.add(new Line().append(create_btn.build()));
for (GroupDTO group : groups) {
Line line = new Line();
Button del = Button.createRed("删除")
.setHoverText("删除权限组 " + group.getName())
.setExecuteCommand("/dominion group delete " + dominion.getName() + " " + group.getName());
Button edit = Button.create("编辑")
.setHoverText("编辑权限组 " + group.getName())
.setExecuteCommand("/dominion group setting " + dominion.getName() + " " + group.getName());
Button add = Button.createGreen("+")
.setHoverText("添加成员到权限组 " + group.getName())
.setExecuteCommand("/dominion group select_member " + dominion.getName() + " " + group.getName() + " " + page);
line.append(del.build()).append(edit.build()).append(group.getName()).append(add.build());
view.add(line);
List<MemberDTO> players = MemberDTO.selectByGroupId(group.getId());
XLogger.debug("players: " + players.size());
for (MemberDTO playerPrivilege : players) {
PlayerDTO p = PlayerDTO.select(playerPrivilege.getPlayerUUID());
if (p == null) continue;
Button remove = Button.createRed("-")
.setHoverText("" + p.getLastKnownName() + " 移出权限组 " + group.getName())
.setExecuteCommand("/dominion group remove_member " + dominion.getName() + " " + group.getName() + " " + p.getLastKnownName() + " " + page);
Line playerLine = new Line().setDivider("");
playerLine.append(Component.text(" "));
playerLine.append(remove.build()).append(" | " + p.getLastKnownName());
view.add(playerLine);
}
view.add(new Line().append(""));
}
view.showOn(player, page);
}
}

View File

@ -0,0 +1,101 @@
package cn.lunadeer.dominion.tuis.dominion.manage.group;
import cn.lunadeer.dominion.dtos.DominionDTO;
import cn.lunadeer.dominion.dtos.Flag;
import cn.lunadeer.dominion.dtos.GroupDTO;
import cn.lunadeer.dominion.tuis.Apis;
import cn.lunadeer.minecraftpluginutils.Notification;
import cn.lunadeer.minecraftpluginutils.stui.ListView;
import cn.lunadeer.minecraftpluginutils.stui.components.Button;
import cn.lunadeer.minecraftpluginutils.stui.components.Line;
import net.kyori.adventure.text.Component;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import static cn.lunadeer.dominion.commands.Apis.playerOnly;
import static cn.lunadeer.dominion.tuis.Apis.noAuthToManage;
public class GroupSetting {
public static void show(CommandSender sender, String dominionName, String groupName) {
show(sender, new String[]{"", "", dominionName, groupName});
}
public static void show(CommandSender sender, String dominionName, String groupName, Integer page) {
show(sender, new String[]{"", "", dominionName, groupName, page.toString()});
}
public static void show(CommandSender sender, String[] args) {
if (args.length < 4) {
Notification.error(sender, "用法: /dominion group setting <领地名称> <权限组名称> [页码]");
return;
}
Player player = playerOnly(sender);
if (player == null) return;
DominionDTO dominion = DominionDTO.select(args[2]);
if (dominion == null) {
Notification.error(sender, "领地 %s 不存在", args[2]);
return;
}
if (noAuthToManage(player, dominion)) return;
int page = Apis.getPage(args, 4);
GroupDTO group = GroupDTO.select(dominion.getId(), args[3]);
if (group == null) {
Notification.error(sender, "权限组 %s 不存在", args[3]);
return;
}
ListView view = ListView.create(10, "/dominion group setting " + dominion.getName() + " " + group.getName());
view.title("权限组 " + group.getName() + " 管理");
view.navigator(
Line.create()
.append(Button.create("主菜单").setExecuteCommand("/dominion menu").build())
.append(Button.create("我的领地").setExecuteCommand("/dominion list").build())
.append(Button.create("管理界面").setExecuteCommand("/dominion manage " + dominion.getName()).build())
.append(Button.create("权限组列表").setExecuteCommand("/dominion group list " + dominion.getName()).build())
.append("权限组管理")
);
Button rename_btn = Button.create("重命名此权限组")
.setHoverText("重命名权限组 " + group.getName())
.setExecuteCommand("/dominion cui_rename_group " + dominion.getName() + " " + group.getName());
view.add(Line.create().append(rename_btn.build()));
if (group.getAdmin()) {
view.add(Line.create()
.append(Button.createGreen("")
.setExecuteCommand(parseCommand(dominion.getName(), group.getName(), "admin", false, page))
.build())
.append("管理员"));
view.add(createOption(Flag.GLOW, group.getFlagValue(Flag.GLOW), dominion.getName(), group.getName(), page));
} else {
view.add(Line.create()
.append(Button.createRed("")
.setExecuteCommand(parseCommand(dominion.getName(), group.getName(), "admin", true, page))
.build())
.append("管理员"));
for (Flag flag : Flag.getPrivilegeFlagsEnabled()) {
view.add(createOption(flag, group.getFlagValue(flag), dominion.getName(), group.getName(), page));
}
}
view.showOn(player, page);
}
private static Line createOption(Flag flag, boolean value, String DominionName, String groupName, int page) {
if (value) {
return Line.create()
.append(Button.createGreen("")
.setExecuteCommand(parseCommand(DominionName, groupName, flag.getFlagName(), false, page))
.build())
.append(Component.text(flag.getDisplayName()).hoverEvent(Component.text(flag.getDescription())));
} else {
return Line.create()
.append(Button.createRed("")
.setExecuteCommand(parseCommand(DominionName, groupName, flag.getFlagName(), true, page))
.build())
.append(Component.text(flag.getDisplayName()).hoverEvent(Component.text(flag.getDescription())));
}
}
private static String parseCommand(String dominionName, String groupName, String flagName, boolean value, int page) {
return String.format("/dominion group set_flag %s %s %s %s %d", dominionName, groupName, flagName, value, page);
}
}

View File

@ -0,0 +1,57 @@
package cn.lunadeer.dominion.tuis.dominion.manage.group;
import cn.lunadeer.dominion.dtos.DominionDTO;
import cn.lunadeer.dominion.dtos.GroupDTO;
import cn.lunadeer.dominion.dtos.MemberDTO;
import cn.lunadeer.dominion.dtos.PlayerDTO;
import cn.lunadeer.minecraftpluginutils.Notification;
import cn.lunadeer.minecraftpluginutils.stui.ListView;
import cn.lunadeer.minecraftpluginutils.stui.components.Button;
import cn.lunadeer.minecraftpluginutils.stui.components.Line;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.List;
import static cn.lunadeer.dominion.commands.Apis.playerOnly;
import static cn.lunadeer.dominion.tuis.Apis.getPage;
import static cn.lunadeer.dominion.tuis.Apis.noAuthToManage;
public class SelectMember {
public static void show(CommandSender sender, String[] args) {
if (args.length < 4) {
Notification.error(sender, "用法: /dominion group select_member <领地名称> <权限组名称> [回显页码] [页码]");
return;
}
Player player = playerOnly(sender);
if (player == null) return;
DominionDTO dominion = DominionDTO.select(args[2]);
if (dominion == null) {
Notification.error(sender, "领地 %s 不存在", args[2]);
return;
}
if (noAuthToManage(player, dominion)) return;
GroupDTO group = GroupDTO.select(dominion.getId(), args[3]);
if (group == null) {
Notification.error(sender, "权限组不存在");
return;
}
int backPage = getPage(args, 4);
int page = getPage(args, 5);
ListView view = ListView.create(10, "/dominion group select_member " + dominion.getName() + " " + group.getName() + " " + backPage);
view.title("选择成员");
Line sub = Line.create().append("选择成员添加到权限组 " + group.getName())
.append(Button.create("返回").setExecuteCommand("/dominion group list " + dominion.getName() + " " + backPage).build());
view.subtitle(sub);
List<MemberDTO> members = MemberDTO.selectByDomGroupId(dominion.getId(), -1);
for (MemberDTO member : members) {
PlayerDTO p = PlayerDTO.select(member.getPlayerUUID());
if (p == null) continue;
view.add(Line.create()
.append(Button.create(p.getLastKnownName())
.setExecuteCommand("/dominion group add_member " + dominion.getName() + " " + group.getName() + " " + p.getLastKnownName() + " " + backPage)
.build()));
}
view.showOn(player, page);
}
}

View File

@ -0,0 +1,119 @@
package cn.lunadeer.dominion.tuis.dominion.manage.member;
import cn.lunadeer.dominion.Cache;
import cn.lunadeer.dominion.dtos.*;
import cn.lunadeer.minecraftpluginutils.Notification;
import cn.lunadeer.minecraftpluginutils.stui.ListView;
import cn.lunadeer.minecraftpluginutils.stui.components.Button;
import cn.lunadeer.minecraftpluginutils.stui.components.Line;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.format.Style;
import net.kyori.adventure.text.format.TextColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import java.util.List;
import static cn.lunadeer.dominion.commands.Apis.CommandParser;
import static cn.lunadeer.dominion.commands.Apis.playerOnly;
import static cn.lunadeer.dominion.tuis.Apis.getPage;
import static cn.lunadeer.dominion.tuis.Apis.noAuthToManage;
public class MemberList {
public static void show(CommandSender sender, String dominionName, Integer page) {
show(sender, new String[]{"", "", dominionName, page.toString()});
}
public static void show(CommandSender sender, String dominionName) {
show(sender, new String[]{"", "", dominionName});
}
public static void show(CommandSender sender, String[] args) {
if (args.length < 3) {
Notification.error(sender, "用法: /dominion member list <领地名称> [页码]");
return;
}
Player player = playerOnly(sender);
if (player == null) return;
DominionDTO dominion = DominionDTO.select(args[2]);
if (dominion == null) {
Notification.error(sender, "领地 %s 不存在", args[2]);
return;
}
int page = getPage(args, 3);
ListView view = ListView.create(10, "/dominion member list " + dominion.getName());
if (noAuthToManage(player, dominion)) return;
List<MemberDTO> privileges = MemberDTO.select(dominion.getId());
view.title("领地 " + dominion.getName() + " 成员列表");
view.navigator(
Line.create()
.append(Button.create("主菜单").setExecuteCommand("/dominion menu").build())
.append(Button.create("我的领地").setExecuteCommand("/dominion list").build())
.append(Button.create("管理界面").setExecuteCommand("/dominion manage " + dominion.getName()).build())
.append("成员列表")
);
view.add(Line.create().append(Button.create("添加成员")
.setExecuteCommand(CommandParser("/dominion member select_player %s", dominion.getName())).build()));
for (MemberDTO privilege : privileges) {
PlayerDTO p_player = PlayerDTO.select(privilege.getPlayerUUID());
if (p_player == null) continue;
GroupDTO group = Cache.instance.getGroup(privilege.getGroupId());
Line line = Line.create();
if (group != null) {
line.append(groupTag);
} else if (privilege.getAdmin()) {
line.append(adminTag);
} else {
if (!privilege.getFlagValue(Flag.MOVE)) {
line.append(banTag);
} else {
line.append(normalTag);
}
}
Button prev = Button.createGreen("权限")
.setHoverText("配置成员权限")
.setExecuteCommand(CommandParser("/dominion member setting %s %s", dominion.getName(), p_player.getLastKnownName()));
Button remove = Button.createRed("移除")
.setHoverText("将此成员移出(变为访客)")
.setExecuteCommand(CommandParser("/dominion member remove %s %s", dominion.getName(), p_player.getLastKnownName()));
if (!player.getUniqueId().equals(dominion.getOwner())) {
boolean disable = false;
if (group == null) {
if (privilege.getAdmin()) {
disable = true;
}
} else {
if (group.getAdmin()) {
disable = true;
}
}
if (disable) {
prev.setDisabled("你不是领地主人,无法编辑管理员权限");
remove.setDisabled("你不是领地主人,无法移除管理员");
}
}
if (group != null) {
prev.setDisabled(String.format("此成员属于权限组 %s 无法单独编辑权限", group.getName()));
}
line.append(remove.build());
line.append(prev.build());
line.append(p_player.getLastKnownName());
view.add(line);
}
view.showOn(player, page);
}
private static final TextComponent adminTag = Component.text("[A]", Style.style(TextColor.color(97, 97, 210)))
.hoverEvent(Component.text("这是一个管理员"));
private static final TextComponent normalTag = Component.text("[N]", Style.style(TextColor.color(255, 255, 255)))
.hoverEvent(Component.text("这是一个普通成员"));
private static final TextComponent banTag = Component.text("[B]", Style.style(TextColor.color(255, 67, 0)))
.hoverEvent(Component.text("这是一个黑名单成员"));
private static final TextComponent groupTag = Component.text("[G]", Style.style(TextColor.color(0, 185, 153)))
.hoverEvent(Component.text("这个成员在一个权限组里"));
}

View File

@ -1,9 +1,9 @@
package cn.lunadeer.dominion.tuis;
package cn.lunadeer.dominion.tuis.dominion.manage.member;
import cn.lunadeer.dominion.dtos.DominionDTO;
import cn.lunadeer.dominion.dtos.Flag;
import cn.lunadeer.dominion.dtos.MemberDTO;
import cn.lunadeer.dominion.dtos.PlayerDTO;
import cn.lunadeer.dominion.dtos.PlayerPrivilegeDTO;
import cn.lunadeer.minecraftpluginutils.Notification;
import cn.lunadeer.minecraftpluginutils.stui.ListView;
import cn.lunadeer.minecraftpluginutils.stui.components.Button;
@ -13,35 +13,40 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import static cn.lunadeer.dominion.commands.Apis.playerOnly;
import static cn.lunadeer.dominion.tuis.Apis.getDominionNameArg_2;
import static cn.lunadeer.dominion.tuis.Apis.getPage;
import static cn.lunadeer.dominion.tuis.Apis.noAuthToManage;
public class PrivilegeInfo {
// /dominion privilege_info <玩家名称> [领地名称] [页码]
public class MemberSetting {
public static void show(CommandSender sender, String dominionName, String playerName, Integer page) {
show(sender, new String[]{"", "", dominionName, playerName, page.toString()});
}
public static void show(CommandSender sender, String dominionName, String playerName) {
show(sender, new String[]{"", "", dominionName, playerName});
}
public static void show(CommandSender sender, String[] args) {
Player player = playerOnly(sender);
if (player == null) return;
DominionDTO dominion = getDominionNameArg_2(player, args);
int page = 1;
if (args.length == 4) {
try {
page = Integer.parseInt(args[3]);
} catch (Exception ignored) {
}
}
String playerName = args[1];
if (dominion == null) {
Notification.error(sender, "你不在任何领地内,请指定领地名称 /dominion privilege_info <玩家名称> [领地名称]");
if (args.length < 3) {
Notification.error(sender, "用法: /dominion member setting <领地名称> <玩家名称> [页码]");
return;
}
Player player = playerOnly(sender);
if (player == null) return;
DominionDTO dominion = DominionDTO.select(args[2]);
if (dominion == null) {
Notification.error(sender, "领地 %s 不存在", args[2]);
return;
}
ListView view = ListView.create(10, "/dominion privilege_info " + playerName + " " + dominion.getName());
if (noAuthToManage(player, dominion)) return;
int page = getPage(args, 4);
String playerName = args[3];
ListView view = ListView.create(10, "/dominion member setting " + dominion.getName() + " " + playerName);
PlayerDTO playerDTO = PlayerDTO.select(playerName);
if (playerDTO == null) {
Notification.error(sender, "玩家 %s 不存在", playerName);
return;
}
PlayerPrivilegeDTO privilege = PlayerPrivilegeDTO.select(playerDTO.getUuid(), dominion.getId());
MemberDTO privilege = MemberDTO.select(playerDTO.getUuid(), dominion.getId());
if (privilege == null) {
Notification.warn(sender, "玩家 %s 不是领地 %s 的成员", playerName, dominion.getName());
return;
@ -52,17 +57,24 @@ public class PrivilegeInfo {
.append(Button.create("主菜单").setExecuteCommand("/dominion menu").build())
.append(Button.create("我的领地").setExecuteCommand("/dominion list").build())
.append(Button.create("管理界面").setExecuteCommand("/dominion manage " + dominion.getName()).build())
.append(Button.create("成员列表").setExecuteCommand("/dominion privilege_list " + dominion.getName()).build())
.append(Button.create("成员列表").setExecuteCommand("/dominion member list " + dominion.getName()).build())
.append("成员权限")
);
view.add(Line.create().append(Button.createGreen("套用模板")
.setHoverText("选择一个权限模板套用")
.setExecuteCommand("/dominion member select_template " + dominion.getName() + " " + playerName).build()));
if (privilege.getAdmin()) {
view.add(Line.create()
.append(Button.createGreen("").setExecuteCommand("/dominion set_privilege " + playerName + " admin false " + dominion.getName() + " " + page).build())
.append(Button.createGreen("").setExecuteCommand(
parseCommand(dominion.getName(), playerName, "admin", false, page)
).build())
.append("管理员"));
view.add(createOption(Flag.GLOW, privilege.getFlagValue(Flag.GLOW), playerName, dominion.getName(), page));
} else {
view.add(Line.create()
.append(Button.createRed("").setExecuteCommand("/dominion set_privilege " + playerName + " admin true " + dominion.getName() + " " + page).build())
.append(Button.createRed("").setExecuteCommand(
parseCommand(dominion.getName(), playerName, "admin", true, page)
).build())
.append("管理员"));
for (Flag flag : Flag.getPrivilegeFlagsEnabled()) {
view.add(createOption(flag, privilege.getFlagValue(flag), playerName, dominion.getName(), page));
@ -74,12 +86,20 @@ public class PrivilegeInfo {
private static Line createOption(Flag flag, boolean value, String player_name, String dominion_name, int page) {
if (value) {
return Line.create()
.append(Button.createGreen("").setExecuteCommand("/dominion set_privilege " + player_name + " " + flag.getFlagName() + " false " + dominion_name + " " + page).build())
.append(Button.createGreen("").setExecuteCommand(
parseCommand(dominion_name, player_name, flag.getFlagName(), false, page)
).build())
.append(Component.text(flag.getDisplayName()).hoverEvent(Component.text(flag.getDescription())));
} else {
return Line.create()
.append(Button.createRed("").setExecuteCommand("/dominion set_privilege " + player_name + " " + flag.getFlagName() + " true " + dominion_name + " " + page).build())
.append(Button.createRed("").setExecuteCommand(
parseCommand(dominion_name, player_name, flag.getFlagName(), true, page)
).build())
.append(Component.text(flag.getDisplayName()).hoverEvent(Component.text(flag.getDescription())));
}
}
private static String parseCommand(String dominionName, String playerName, String flagName, boolean value, int page) {
return String.format("/dominion member set_flag %s %s %s %s %d", dominionName, playerName, flagName, value, page);
}
}

View File

@ -1,7 +1,8 @@
package cn.lunadeer.dominion.tuis;
package cn.lunadeer.dominion.tuis.dominion.manage.member;
import cn.lunadeer.dominion.controllers.PlayerController;
import cn.lunadeer.dominion.dtos.PlayerDTO;
import cn.lunadeer.minecraftpluginutils.Notification;
import cn.lunadeer.minecraftpluginutils.stui.ListView;
import cn.lunadeer.minecraftpluginutils.stui.components.Button;
import cn.lunadeer.minecraftpluginutils.stui.components.Line;
@ -10,26 +11,29 @@ import org.bukkit.entity.Player;
import java.util.List;
import static cn.lunadeer.dominion.commands.Apis.CommandParser;
import static cn.lunadeer.dominion.commands.Apis.playerOnly;
import static cn.lunadeer.dominion.tuis.Apis.getPage;
public class SelectPlayer {
// /dominion select_player_create_privilege <领地名称> [页码]
public static void show(CommandSender sender, String dominionName, Integer page) {
show(sender, new String[]{"", "", dominionName, page.toString()});
}
public static void show(CommandSender sender, String[] args) {
if (args.length < 3) {
Notification.error(sender, "用法: /dominion member select_player <领地名称> [页码]");
return;
}
Player player = playerOnly(sender);
if (player == null) return;
int page = 1;
if (args.length == 3) {
try {
page = Integer.parseInt(args[2]);
} catch (Exception ignored) {
}
}
String dominion_name = args[1];
ListView view = ListView.create(10, "/dominion select_player_create_privilege " + dominion_name);
int page = getPage(args, 3);
String dominion_name = args[2];
ListView view = ListView.create(10, "/dominion member select_player " + dominion_name);
Line sub = Line.create()
.append("只能选择已经登录过的玩家")
.append(Button.create("搜索").setExecuteCommand("/dominion cui_create_privilege " + dominion_name).build())
.append(Button.create("返回").setExecuteCommand("/dominion privilege_list " + dominion_name).build());
.append(Button.create("搜索").setExecuteCommand("/dominion cui_member_add " + dominion_name).build())
.append(Button.create("返回").setExecuteCommand("/dominion member list " + dominion_name).build());
view.title("选择玩家添加为成员").subtitle(sub);
List<PlayerDTO> players = PlayerController.allPlayers();
for (PlayerDTO p : players) {
@ -38,7 +42,7 @@ public class SelectPlayer {
}
view.add(Line.create().
append(Button.create(p.getLastKnownName())
.setExecuteCommand("/dominion create_privilege " + p.getLastKnownName() + " " + dominion_name + " b")
.setExecuteCommand(CommandParser("/dominion member add %s %s", dominion_name, p.getLastKnownName()))
.build()));
}
view.showOn(player, page);

View File

@ -1,6 +1,7 @@
package cn.lunadeer.dominion.tuis;
package cn.lunadeer.dominion.tuis.dominion.manage.member;
import cn.lunadeer.dominion.dtos.PrivilegeTemplateDTO;
import cn.lunadeer.minecraftpluginutils.Notification;
import cn.lunadeer.minecraftpluginutils.stui.ListView;
import cn.lunadeer.minecraftpluginutils.stui.components.Button;
import cn.lunadeer.minecraftpluginutils.stui.components.Line;
@ -10,40 +11,42 @@ import org.bukkit.entity.Player;
import java.util.List;
import static cn.lunadeer.dominion.commands.Apis.CommandParser;
import static cn.lunadeer.dominion.commands.Apis.playerOnly;
import static cn.lunadeer.dominion.tuis.Apis.getPage;
public class SelectTemplate {
public static void show(CommandSender sender, String[] args) {
if (args.length < 4) {
// /dominion member select_template <领地名称> <玩家名称> [页码]
Notification.error(sender, "用法: /dominion member select_template <领地名称> <玩家名称> [页码]");
return;
}
Player player = playerOnly(sender);
if (player == null) return;
String playerName = args[1];
String dominionName = args[2];
String backPage = args[3];
String playerName = args[3];
int page = 1;
if (args.length == 5) {
try {
page = Integer.parseInt(args[4]);
} catch (Exception ignored) {
}
}
int page = getPage(args, 4);
List<PrivilegeTemplateDTO> templates = PrivilegeTemplateDTO.selectAll(player.getUniqueId());
ListView view = ListView.create(10, "/dominion select_template " + playerName + " " + dominionName + " " + backPage);
ListView view = ListView.create(10, "/dominion member select_template " + dominionName + " " + playerName);
view.title("选择一个模板");
Line sub = Line.create()
.append("套用在领地 " + dominionName + " 的成员 " + playerName + " 身上")
.append(Button.create("返回").setExecuteCommand("/dominion privilege_list " + dominionName + " " + backPage).build());
.append(Button.create("返回").setExecuteCommand("/dominion member setting " + dominionName + " " + playerName).build());
view.subtitle(sub);
for (PrivilegeTemplateDTO template : templates) {
// /dominion apply_template <玩家名称> <领地名称> <模板名称>
// /dominion member apply_template <领地名称> <成员名称> <模板名称>
view.add(Line.create()
.append(Button.create("选择")
.setExecuteCommand("/dominion apply_template " + playerName + " " + dominionName + " " + template.getName() + " " + backPage)
.setExecuteCommand(CommandParser("/dominion member apply_template %s %s %s", dominionName, playerName, template.getName()))
.build())
.append(Component.text(template.getName())));
}

View File

@ -1,4 +1,4 @@
package cn.lunadeer.dominion.tuis;
package cn.lunadeer.dominion.tuis.template;
import cn.lunadeer.dominion.dtos.PrivilegeTemplateDTO;
import cn.lunadeer.minecraftpluginutils.stui.ListView;
@ -14,11 +14,19 @@ import static cn.lunadeer.dominion.tuis.Apis.getPage;
public class TemplateList {
public static void show(CommandSender sender) {
show(sender, 1);
}
public static void show(CommandSender sender, int page) {
show(sender, new String[]{"", "", String.valueOf(page)});
}
public static void show(CommandSender sender, String[] args) {
Player player = playerOnly(sender);
if (player == null) return;
int page = getPage(args);
ListView view = ListView.create(10, "/dominion template_list");
int page = getPage(args, 2);
ListView view = ListView.create(10, "/dominion template list");
List<PrivilegeTemplateDTO> templates = PrivilegeTemplateDTO.selectAll(player.getUniqueId());
view.title("成员权限模板列表");
@ -30,8 +38,8 @@ public class TemplateList {
view.add(Line.create().append(create.build()));
for (PrivilegeTemplateDTO template : templates) {
Button manage = Button.createGreen("配置").setExecuteCommand("/dominion template_manage " + template.getName());
Button delete = Button.createRed("删除").setExecuteCommand("/dominion template_delete " + template.getName());
Button manage = Button.createGreen("配置").setExecuteCommand("/dominion template setting " + template.getName());
Button delete = Button.createRed("删除").setExecuteCommand("/dominion template delete " + template.getName());
Line line = Line.create()
.append(delete.build())
.append(manage.build())

View File

@ -1,4 +1,4 @@
package cn.lunadeer.dominion.tuis;
package cn.lunadeer.dominion.tuis.template;
import cn.lunadeer.dominion.dtos.Flag;
import cn.lunadeer.dominion.dtos.PrivilegeTemplateDTO;
@ -11,31 +11,34 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import static cn.lunadeer.dominion.commands.Apis.playerOnly;
import static cn.lunadeer.dominion.tuis.Apis.getPage;
public class TemplateManage {
public class TemplateSetting {
// /dominion template setting <模板名称> [页码]
public static void show(CommandSender sender, String templateName, int page) {
show(sender, new String[]{"", "", templateName, String.valueOf(page)});
}
public static void show(CommandSender sender, String templateName) {
show(sender, new String[]{"", "", templateName});
}
// /dominion template_manage <模板名称> [页码]
public static void show(CommandSender sender, String[] args) {
Player player = playerOnly(sender);
if (player == null) return;
int page = 1;
if (args.length == 3) {
try {
page = Integer.parseInt(args[2]);
} catch (Exception ignored) {
}
}
PrivilegeTemplateDTO template = PrivilegeTemplateDTO.select(player.getUniqueId(), args[1]);
int page = getPage(args, 3);
PrivilegeTemplateDTO template = PrivilegeTemplateDTO.select(player.getUniqueId(), args[2]);
if (template == null) {
Notification.error(sender, "模板 %s 不存在", args[1]);
Notification.error(sender, "模板 %s 不存在", args[2]);
return;
}
ListView view = ListView.create(10, "/dominion template_manage " + template.getName());
ListView view = ListView.create(10, "/dominion template manage " + template.getName());
view.title("模板 " + args[1] + " 权限管理");
view.navigator(Line.create()
.append(Button.create("主菜单").setExecuteCommand("/dominion menu").build())
.append(Button.create("模板列表").setExecuteCommand("/dominion template_list").build())
.append(Button.create("模板列表").setExecuteCommand("/dominion template list").build())
.append("模板管理")
);
@ -43,11 +46,11 @@ public class TemplateManage {
if (template.getAdmin()) {
view.add(Line.create()
.append(Button.createGreen("").setExecuteCommand("/dominion template_set_flag " + template.getName() + " admin false " + page).build())
.append(Button.createGreen("").setExecuteCommand("/dominion template set_flag " + template.getName() + " admin false " + page).build())
.append("管理员"));
} else {
view.add(Line.create()
.append(Button.createRed("").setExecuteCommand("/dominion template_set_flag " + template.getName() + " admin true " + page).build())
.append(Button.createRed("").setExecuteCommand("/dominion template set_flag " + template.getName() + " admin true " + page).build())
.append("管理员"));
}
for (Flag flag : Flag.getPrivilegeFlagsEnabled()) {
@ -59,11 +62,11 @@ public class TemplateManage {
private static Line createOption(Flag flag, boolean value, String templateName, int page) {
if (value) {
return Line.create()
.append(Button.createGreen("").setExecuteCommand("/dominion template_set_flag " + templateName + " " + flag.getFlagName() + " false " + page).build())
.append(Button.createGreen("").setExecuteCommand("/dominion template set_flag " + templateName + " " + flag.getFlagName() + " false " + page).build())
.append(Component.text(flag.getDisplayName()).hoverEvent(Component.text(flag.getDescription())));
} else {
return Line.create()
.append(Button.createRed("").setExecuteCommand("/dominion template_set_flag " + templateName + " " + flag.getFlagName() + " true " + page).build())
.append(Button.createRed("").setExecuteCommand("/dominion template set_flag " + templateName + " " + flag.getFlagName() + " true " + page).build())
.append(Component.text(flag.getDisplayName()).hoverEvent(Component.text(flag.getDescription())));
}
}

View File

@ -0,0 +1,155 @@
package cn.lunadeer.dominion.utils;
import cn.lunadeer.dominion.Dominion;
import cn.lunadeer.dominion.dtos.PlayerDTO;
import cn.lunadeer.dominion.utils.Residence.Message;
import cn.lunadeer.dominion.utils.Residence.Permission;
import cn.lunadeer.dominion.utils.Residence.Residence;
import cn.lunadeer.dominion.utils.Residence.SaveFile;
import cn.lunadeer.minecraftpluginutils.XLogger;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
import org.bukkit.World;
import org.bukkit.plugin.java.JavaPlugin;
import org.yaml.snakeyaml.Yaml;
import java.io.File;
import java.io.InputStream;
import java.nio.file.Files;
import java.util.*;
public class ResMigration {
public static class ResidenceNode {
public UUID owner;
public World world;
public String name;
public Location loc1;
public Location loc2;
public Location tpLoc;
public String joinMessage;
public String leaveMessage;
public List<ResidenceNode> children = new ArrayList<>();
}
public static List<ResidenceNode> extractFromResidence(JavaPlugin plugin) {
List<ResidenceNode> dominions = new ArrayList<>();
File resSave = new File(plugin.getDataFolder().getParent(), "Residence");
resSave = new File(resSave, "Save");
resSave = new File(resSave, "Worlds");
if (!resSave.exists()) {
XLogger.info("Residence Save not found, skipping migration");
return dominions;
}
// list .yml files
File[] files = resSave.listFiles((dir, name) -> name.endsWith(".yml"));
if (files == null || files.length == 0) {
XLogger.info("No save files found");
return dominions;
}
for (File file : files) {
try {
dominions.addAll(processWorld(file));
} catch (Exception e) {
XLogger.err("Failed to process file: %s, %s", file.getName(), e.getMessage());
}
}
XLogger.info("Extract %d residences", dominions.size());
return dominions;
}
private static ResidenceNode parseDominion(String name, World world, Residence res, SaveFile save) {
OfflinePlayer bukkitOwner = Dominion.instance.getServer().getOfflinePlayer(UUID.fromString(res.Permissions.OwnerUUID));
PlayerDTO owner = PlayerDTO.get(bukkitOwner);
if (owner == null) {
XLogger.warn("Owner not found: " + res.Permissions.OwnerUUID);
return null;
}
String[] loc = res.Areas.values().toArray()[0].toString().split(":");
if (loc.length != 6) {
XLogger.warn("Invalid location: " + res.Areas.get("main"));
return null;
}
ResidenceNode dominionNode = new ResidenceNode();
dominionNode.owner = owner.getUuid();
dominionNode.world = world;
dominionNode.name = name;
dominionNode.joinMessage = save.Messages.get(res.Messages).EnterMessage;
dominionNode.leaveMessage = save.Messages.get(res.Messages).LeaveMessage;
dominionNode.loc1 = new Location(world, Double.parseDouble(loc[0]), Double.parseDouble(loc[1]), Double.parseDouble(loc[2]));
dominionNode.loc2 = new Location(world, Double.parseDouble(loc[3]), Double.parseDouble(loc[4]), Double.parseDouble(loc[5]));
if (res.TPLoc != null) {
String[] tpLocStr = res.TPLoc.split(":");
if (tpLocStr.length >= 3) {
dominionNode.tpLoc = new Location(world, Double.parseDouble(tpLocStr[0]), Double.parseDouble(tpLocStr[1]), Double.parseDouble(tpLocStr[2]));
}
}
if (res.Subzones != null) {
for (Map.Entry<String, Residence> entry : res.Subzones.entrySet()) {
ResidenceNode sub = parseDominion(entry.getKey(), world, entry.getValue(), save);
if (sub != null) {
dominionNode.children.add(sub);
}
}
}
return dominionNode;
}
private static Map<String, Residence> parseResYml(Map<String, Object> zones) {
Map<String, Residence> res = new HashMap<>();
for (Map.Entry<String, Object> entry : zones.entrySet()) {
Map<String, Object> zone = (Map<String, Object>) entry.getValue();
Residence residence = new Residence();
if (zone.containsKey("TPLoc")) {
residence.setTPLoc((String) zone.get("TPLoc"));
}
residence.setMessages((int) zone.get("Messages"));
Permission permission = new Permission();
permission.OwnerUUID = ((Map<String, Object>) zone.get("Permissions")).get("OwnerUUID").toString();
permission.OwnerLastKnownName = ((Map<String, Object>) zone.get("Permissions")).get("OwnerLastKnownName").toString();
residence.setPermissions(permission);
residence.setAreas((Map<String, String>) zone.get("Areas"));
if (zone.containsKey("Subzones")) {
residence.setSubzones(parseResYml((Map<String, Object>) zone.get("Subzones")));
}
res.put(entry.getKey(), residence);
}
return res;
}
private static List<ResidenceNode> processWorld(File saveFile) throws Exception {
XLogger.debug("=====================================");
XLogger.debug("Processing file: %s", saveFile.getName());
String worldName = saveFile.getName().replace("res_", "").replace(".yml", "");
World world = Dominion.instance.getServer().getWorld(worldName);
InputStream inputStream = Files.newInputStream(saveFile.toPath());
Map<String, Object> yaml = new Yaml().load(inputStream);
SaveFile save = new SaveFile();
Map<Integer, Object> Messages = (Map<Integer, Object>) yaml.get("Messages");
Map<Integer, Message> messages = new HashMap<>();
for (Map.Entry<Integer, Object> entry : Messages.entrySet()) {
Map<String, String> message = (Map<String, String>) entry.getValue();
Message msg = new Message();
msg.EnterMessage = (String) message.get("EnterMessage");
msg.LeaveMessage = (String) message.get("LeaveMessage");
messages.put(entry.getKey(), msg);
}
save.setMessages(messages);
Map<String, Object> Residences = (Map<String, Object>) yaml.get("Residences");
save.Residences = parseResYml(Residences);
inputStream.close();
List<ResidenceNode> dominions = new ArrayList<>();
for (Map.Entry<String, Residence> entry : save.Residences.entrySet()) {
String name = entry.getKey();
Residence residence = entry.getValue();
ResidenceNode dominion = parseDominion(name, world, residence, save);
dominions.add(dominion);
}
return dominions;
}
}

View File

@ -0,0 +1,24 @@
package cn.lunadeer.dominion.utils.Residence;
public class Message {
public String LeaveMessage;
public String EnterMessage;
// getters and setters
public String getLeaveMessage() {
return LeaveMessage;
}
public void setLeaveMessage(String leaveMessage) {
LeaveMessage = leaveMessage;
}
public String getEnterMessage() {
return EnterMessage;
}
public void setEnterMessage(String enterMessage) {
EnterMessage = enterMessage;
}
}

View File

@ -0,0 +1,24 @@
package cn.lunadeer.dominion.utils.Residence;
public class Permission {
public String OwnerUUID;
public String OwnerLastKnownName;
// getters and setters
public String getOwnerUUID() {
return OwnerUUID;
}
public void setOwnerUUID(String ownerUUID) {
OwnerUUID = ownerUUID;
}
public String getOwnerLastKnownName() {
return OwnerLastKnownName;
}
public void setOwnerLastKnownName(String ownerLastKnownName) {
OwnerLastKnownName = ownerLastKnownName;
}
}

View File

@ -0,0 +1,53 @@
package cn.lunadeer.dominion.utils.Residence;
import java.util.Map;
public class Residence {
public String TPLoc;
public Map<String, Residence> Subzones;
public int Messages;
public Permission Permissions;
public Map<String, String> Areas;
// getters and setters
public String getTPLoc() {
return TPLoc;
}
public void setTPLoc(String TPLoc) {
this.TPLoc = TPLoc;
}
public Map<String, Residence> getSubzones() {
return Subzones;
}
public void setSubzones(Map<String, Residence> subzones) {
Subzones = subzones;
}
public int getMessages() {
return Messages;
}
public void setMessages(int messages) {
Messages = messages;
}
public Permission getPermissions() {
return Permissions;
}
public void setPermissions(Permission permissions) {
Permissions = permissions;
}
public Map<String, String> getAreas() {
return Areas;
}
public void setAreas(Map<String, String> areas) {
Areas = areas;
}
}

View File

@ -0,0 +1,25 @@
package cn.lunadeer.dominion.utils.Residence;
import java.util.Map;
public class SaveFile {
public Map<String, Residence> Residences;
public Map<Integer, Message> Messages;
// getters and setters
public Map<String, Residence> getResidences() {
return Residences;
}
public void setResidences(Map<String, Residence> residences) {
Residences = residences;
}
public Map<Integer, Message> getMessages() {
return Messages;
}
public void setMessages(Map<Integer, Message> messages) {
Messages = messages;
}
}

View File

@ -49,6 +49,9 @@ FlyPermissionNodes:
- essentials.fly
- cmi.command.fly
# 是否允许玩家从 Residence 迁移领地数据
ResidenceMigration: false
BlueMap: true
CheckUpdate: true