From 83a2daaaed3873982c6bae96276a085b42a080e6 Mon Sep 17 00:00:00 2001 From: zhangyuheng Date: Fri, 6 Sep 2024 11:11:31 +0800 Subject: [PATCH 1/7] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BA=86=20group=20limit?= =?UTF-8?q?=20=E4=BB=A5=E6=94=AF=E6=8C=81=20i18n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dominion/managers/ConfigManager.java | 84 ++++++++++--------- .../dominion/managers/GroupLimit.java | 82 ++++++++++++------ .../dominion/managers/Translation.java | 21 +++-- core/src/main/resources/config.yml | 1 - core/src/main/resources/groups/sponsor.yml | 31 +++---- core/src/main/resources/languages/zh-cn.yml | 11 ++- 6 files changed, 136 insertions(+), 94 deletions(-) diff --git a/core/src/main/java/cn/lunadeer/dominion/managers/ConfigManager.java b/core/src/main/java/cn/lunadeer/dominion/managers/ConfigManager.java index 13738fcb..6a22cd01 100644 --- a/core/src/main/java/cn/lunadeer/dominion/managers/ConfigManager.java +++ b/core/src/main/java/cn/lunadeer/dominion/managers/ConfigManager.java @@ -16,7 +16,10 @@ import java.util.Map; public class ConfigManager { + public static ConfigManager instance; + public ConfigManager(Dominion plugin) { + instance = this; new Translation(plugin); _plugin = plugin; _plugin.saveDefaultConfig(); @@ -87,11 +90,10 @@ public void reload() { defaultGroup.setLimitAmount(_file.getInt("Limit.Amount", 10)); defaultGroup.setLimitDepth(_file.getInt("Limit.Depth", 3)); defaultGroup.setLimitVert(_file.getBoolean("Limit.Vert", false)); - defaultGroup.setWorldBlackList(_file.getStringList("Limit.WorldBlackList")); defaultGroup.setPrice(_file.getDouble("Economy.Price", 10.0)); defaultGroup.setPriceOnlyXZ(_file.getBoolean("Economy.OnlyXZ", false)); defaultGroup.setRefundRatio(_file.getDouble("Economy.Refund", 0.85)); - limits.put("default", defaultGroup); + groupLimits.put("default", defaultGroup); if (defaultGroup.getLimitSizeX() <= 4 && defaultGroup.getLimitSizeX() != -1) { XLogger.err(Translation.Config_Check_LimitSizeXError); @@ -131,7 +133,7 @@ public void reload() { setLimitDepth(3); } - limits.putAll(GroupLimit.loadGroups(_plugin)); + groupLimits.putAll(GroupLimit.loadGroups(_plugin)); saveAll(); // 回写文件 防止文件中的数据不完整 Flag.loadFromFile(); // 加载 Flag 配置 @@ -163,24 +165,22 @@ public void saveAll() { _file.setComments("Limit", List.of(Translation.Config_Comment_DefaultLimit.trans())); _file.set("Limit.SpawnProtection", _spawn_protection); _file.setInlineComments("Limit.SpawnProtection", List.of(Translation.Config_Comment_SpawnProtectRadius.trans() + Translation.Config_Comment_NegativeOneDisabled.trans())); - _file.set("Limit.MinY", limits.get("default").getLimitMinY()); + _file.set("Limit.MinY", groupLimits.get("default").getLimitMinY()); _file.setInlineComments("Limit.MinY", List.of(Translation.Config_Comment_MinY.trans())); - _file.set("Limit.MaxY", limits.get("default").getLimitMaxY()); + _file.set("Limit.MaxY", groupLimits.get("default").getLimitMaxY()); _file.setInlineComments("Limit.MaxY", List.of(Translation.Config_Comment_MaxY.trans())); - _file.set("Limit.SizeX", limits.get("default").getLimitSizeX()); + _file.set("Limit.SizeX", groupLimits.get("default").getLimitSizeX()); _file.setInlineComments("Limit.SizeX", List.of(Translation.Config_Comment_SizeX.trans() + Translation.Config_Comment_NegativeOneUnlimited.trans())); - _file.set("Limit.SizeY", limits.get("default").getLimitSizeY()); + _file.set("Limit.SizeY", groupLimits.get("default").getLimitSizeY()); _file.setInlineComments("Limit.SizeY", List.of(Translation.Config_Comment_SizeY.trans() + Translation.Config_Comment_NegativeOneUnlimited.trans())); - _file.set("Limit.SizeZ", limits.get("default").getLimitSizeZ()); + _file.set("Limit.SizeZ", groupLimits.get("default").getLimitSizeZ()); _file.setInlineComments("Limit.SizeZ", List.of(Translation.Config_Comment_SizeZ.trans() + Translation.Config_Comment_NegativeOneUnlimited.trans())); - _file.set("Limit.Amount", limits.get("default").getLimitAmount()); + _file.set("Limit.Amount", groupLimits.get("default").getLimitAmount()); _file.setInlineComments("Limit.Amount", List.of(Translation.Config_Comment_Amount.trans() + Translation.Config_Comment_NegativeOneUnlimited.trans())); - _file.set("Limit.Depth", limits.get("default").getLimitDepth()); + _file.set("Limit.Depth", groupLimits.get("default").getLimitDepth()); _file.setInlineComments("Limit.Depth", List.of(Translation.Config_Comment_Depth.trans() + Translation.Config_Comment_ZeroDisabled.trans() + Translation.Config_Comment_NegativeOneUnlimited.trans())); - _file.set("Limit.Vert", limits.get("default").getLimitVert()); + _file.set("Limit.Vert", groupLimits.get("default").getLimitVert()); _file.setInlineComments("Limit.Vert", List.of(Translation.Config_Comment_Vert.trans())); - _file.set("Limit.WorldBlackList", limits.get("default").getWorldBlackList()); - _file.setInlineComments("Limit.WorldBlackList", List.of(Translation.Config_Comment_DisabledWorlds.trans())); _file.set("Limit.OpByPass", _limit_op_bypass); _file.setInlineComments("Limit.OpByPass", List.of(Translation.Config_Comment_OpBypass.trans())); @@ -198,11 +198,11 @@ public void saveAll() { _file.setComments("Economy", Arrays.asList(Translation.Config_Comment_Economy.trans(), Translation.Config_Comment_VaultRequired.trans())); _file.set("Economy.Enable", _economy_enable); - _file.set("Economy.Price", limits.get("default").getPrice()); + _file.set("Economy.Price", groupLimits.get("default").getPrice()); _file.setInlineComments("Economy.Price", List.of(Translation.Config_Comment_Price.trans())); - _file.set("Economy.OnlyXZ", limits.get("default").getPriceOnlyXZ()); + _file.set("Economy.OnlyXZ", groupLimits.get("default").getPriceOnlyXZ()); _file.setInlineComments("Economy.OnlyXZ", List.of(Translation.Config_Comment_OnlyXZ.trans())); - _file.set("Economy.Refund", limits.get("default").getRefundRatio()); + _file.set("Economy.Refund", groupLimits.get("default").getRefundRatio()); _file.setInlineComments("Economy.Refund", List.of(Translation.Config_Comment_Refund.trans())); _file.set("FlyPermissionNodes", _fly_permission_nodes); @@ -292,31 +292,31 @@ public String getDbPass() { } public Integer getLimitSizeX(Player player) { - return limits.get(getPlayerGroup(player)).getLimitSizeX(); + return groupLimits.get(getPlayerGroup(player)).getLimitSizeX(); } public void setLimitSizeX(Integer max_x) { - limits.get("default").setLimitSizeX(max_x); + groupLimits.get("default").setLimitSizeX(max_x); _file.set("Limit.SizeX", max_x); _plugin.saveConfig(); } public Integer getLimitSizeY(Player player) { - return limits.get(getPlayerGroup(player)).getLimitSizeY(); + return groupLimits.get(getPlayerGroup(player)).getLimitSizeY(); } public void setLimitSizeY(Integer max_y) { - limits.get("default").setLimitSizeY(max_y); + groupLimits.get("default").setLimitSizeY(max_y); _file.set("Limit.SizeY", max_y); _plugin.saveConfig(); } public Integer getLimitSizeZ(Player player) { - return limits.get(getPlayerGroup(player)).getLimitSizeZ(); + return groupLimits.get(getPlayerGroup(player)).getLimitSizeZ(); } public void setLimitSizeZ(Integer max_z) { - limits.get("default").setLimitSizeZ(max_z); + groupLimits.get("default").setLimitSizeZ(max_z); _file.set("Limit.SizeZ", max_z); _plugin.saveConfig(); } @@ -350,57 +350,59 @@ public void setAutoCleanAfterDays(Integer auto_clean_after_days) { } public Integer getLimitMinY(Player player) { - return limits.get(getPlayerGroup(player)).getLimitMinY(); + return groupLimits.get(getPlayerGroup(player)).getLimitMinY(); } public void setLimitMinY(Integer limit_bottom) { - limits.get("default").setLimitMinY(limit_bottom); + groupLimits.get("default").setLimitMinY(limit_bottom); _file.set("Limit.MinY", limit_bottom); _plugin.saveConfig(); } public Integer getLimitMaxY(Player player) { - return limits.get(getPlayerGroup(player)).getLimitMaxY(); + return groupLimits.get(getPlayerGroup(player)).getLimitMaxY(); } public void setLimitMaxY(Integer limit_top) { - limits.get("default").setLimitMaxY(limit_top); + groupLimits.get("default").setLimitMaxY(limit_top); _file.set("Limit.MaxY", limit_top); _plugin.saveConfig(); } public Integer getLimitAmount(Player player) { - return limits.get(getPlayerGroup(player)).getLimitAmount(); + return groupLimits.get(getPlayerGroup(player)).getLimitAmount(); } public void setLimitAmount(Integer limit_amount) { - limits.get("default").setLimitAmount(limit_amount); + groupLimits.get("default").setLimitAmount(limit_amount); _file.set("Limit.Amount", limit_amount); _plugin.saveConfig(); } public Integer getLimitDepth(Player player) { - return limits.get(getPlayerGroup(player)).getLimitDepth(); + return groupLimits.get(getPlayerGroup(player)).getLimitDepth(); } public void setLimitDepth(Integer limit_depth) { - limits.get("default").setLimitDepth(limit_depth); + groupLimits.get("default").setLimitDepth(limit_depth); _file.set("Limit.Depth", limit_depth); _plugin.saveConfig(); } public Boolean getLimitVert(Player player) { - return limits.get(getPlayerGroup(player)).getLimitVert(); + return groupLimits.get(getPlayerGroup(player)).getLimitVert(); } public void setLimitVert(Boolean limit_vert) { - limits.get("default").setLimitVert(limit_vert); + groupLimits.get("default").setLimitVert(limit_vert); _file.set("Limit.Vert", limit_vert); _plugin.saveConfig(); } public List getWorldBlackList(Player player) { - return limits.get(getPlayerGroup(player)).getWorldBlackList(); + // todo + // return groupLimits.get(getPlayerGroup(player)).getWorldBlackList(); + return null; } public Boolean getLimitOpBypass() { @@ -468,31 +470,31 @@ public void setEconomyEnable(Boolean economy_enable) { } public Float getEconomyPrice(Player player) { - return limits.get(getPlayerGroup(player)).getPrice().floatValue(); + return groupLimits.get(getPlayerGroup(player)).getPrice().floatValue(); } public void setEconomyPrice(Float economy_price) { - limits.get("default").setPrice((double) economy_price); + groupLimits.get("default").setPrice((double) economy_price); _file.set("Economy.Price", economy_price); _plugin.saveConfig(); } public Boolean getEconomyOnlyXZ(Player player) { - return limits.get(getPlayerGroup(player)).getPriceOnlyXZ(); + return groupLimits.get(getPlayerGroup(player)).getPriceOnlyXZ(); } public void setEconomyOnlyXZ(Boolean economy_only_xz) { - limits.get("default").setPriceOnlyXZ(economy_only_xz); + groupLimits.get("default").setPriceOnlyXZ(economy_only_xz); _file.set("Economy.OnlyXZ", economy_only_xz); _plugin.saveConfig(); } public Float getEconomyRefund(Player player) { - return limits.get(getPlayerGroup(player)).getRefundRatio().floatValue(); + return groupLimits.get(getPlayerGroup(player)).getRefundRatio().floatValue(); } public void setEconomyRefund(Float economy_refund) { - limits.get("default").setRefundRatio((double) economy_refund); + groupLimits.get("default").setRefundRatio((double) economy_refund); _file.set("Economy.Refund", economy_refund); _plugin.saveConfig(); } @@ -607,13 +609,13 @@ public void setLanguage(String language) { private String _group_title_prefix; private String _group_title_suffix; - private final Map limits = new HashMap<>(); + private final Map groupLimits = new HashMap<>(); private String getPlayerGroup(@Nullable Player player) { if (player == null) { return "default"; } - for (String group : limits.keySet()) { + for (String group : groupLimits.keySet()) { if (group.equals("default")) { continue; } diff --git a/core/src/main/java/cn/lunadeer/dominion/managers/GroupLimit.java b/core/src/main/java/cn/lunadeer/dominion/managers/GroupLimit.java index e030c3d4..a84f8881 100644 --- a/core/src/main/java/cn/lunadeer/dominion/managers/GroupLimit.java +++ b/core/src/main/java/cn/lunadeer/dominion/managers/GroupLimit.java @@ -1,16 +1,18 @@ package cn.lunadeer.dominion.managers; +import cn.lunadeer.dominion.Dominion; import cn.lunadeer.minecraftpluginutils.XLogger; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.plugin.java.JavaPlugin; import java.io.File; +import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; public class GroupLimit { - private final YamlConfiguration config; + private YamlConfiguration config; private final File file_path; private Integer min_y; private Integer max_y; @@ -20,7 +22,6 @@ public class GroupLimit { private Integer amount; private Integer depth; private Boolean vert; - private List world_black_list; private Double price; private Boolean only_xz; private Double refund; @@ -33,52 +34,52 @@ public GroupLimit() { public GroupLimit(File filePath) { this.file_path = filePath; config = YamlConfiguration.loadConfiguration(this.file_path); - setLimitMinY(config.getInt("MinY", -64)); - setLimitMaxY(config.getInt("MaxY", 320)); + min_y = config.getInt("MinY", -64); + max_y = config.getInt("MaxY", 320); if (getLimitMinY() >= getLimitMaxY()) { XLogger.err(Translation.Config_Check_GroupMinYError, this.file_path.getName()); setLimitMinY(-64); setLimitMaxY(320); } - setLimitSizeX(config.getInt("SizeX", 128)); + size_x = config.getInt("SizeX", 128); if (getLimitSizeX() <= 4 && getLimitSizeX() != -1) { XLogger.err(Translation.Config_Check_GroupSizeXError, this.file_path.getName()); setLimitSizeX(128); } - setLimitSizeY(config.getInt("SizeY", 64)); + size_y = config.getInt("SizeY", 64); if (getLimitSizeY() <= 4 && getLimitSizeY() != -1) { XLogger.err(Translation.Config_Check_GroupSizeYError, this.file_path.getName()); setLimitSizeY(64); } - setLimitSizeZ(config.getInt("SizeZ", 128)); + size_z = config.getInt("SizeZ", 128); if (getLimitSizeZ() <= 4 && getLimitSizeZ() != -1) { XLogger.err(Translation.Config_Check_GroupSizeZError, this.file_path.getName()); setLimitSizeZ(128); } - setLimitAmount(config.getInt("Amount", 10)); + amount = config.getInt("Amount", 10); if (getLimitAmount() <= 0 && getLimitAmount() != -1) { XLogger.err(Translation.Config_Check_GroupAmountError, this.file_path.getName()); setLimitAmount(10); } - setLimitDepth(config.getInt("Depth", 3)); + depth = config.getInt("Depth", 3); if (getLimitDepth() <= 0 && getLimitDepth() != -1) { XLogger.err(Translation.Config_Check_GroupDepthError, this.file_path.getName()); setLimitDepth(3); } - setLimitVert(config.getBoolean("Vert", false)); - setWorldBlackList(config.getStringList("WorldBlackList")); - setPrice(config.getDouble("Price", 10.0)); + vert = config.getBoolean("Vert", false); + price = config.getDouble("Price", 10.0); if (getPrice() < 0.0) { XLogger.err(Translation.Config_Check_GroupPriceError, this.file_path.getName()); setPrice(10.0); } - setPriceOnlyXZ(config.getBoolean("OnlyXZ", false)); - setRefundRatio(config.getDouble("Refund", 0.85)); + only_xz = config.getBoolean("OnlyXZ", false); + refund = config.getDouble("Refund", 0.85); if (getRefundRatio() < 0.0 || getRefundRatio() > 1.0) { XLogger.err(Translation.Config_Check_GroupRefundError, this.file_path.getName()); setRefundRatio(0.85); } save(); // 保存一次,确保文件中的数据是合法的 + saveAll(); } public Integer getLimitMinY() { @@ -113,10 +114,6 @@ public Boolean getLimitVert() { return vert; } - public List getWorldBlackList() { - return world_black_list; - } - public Double getPrice() { return price; } @@ -178,12 +175,6 @@ public void setLimitVert(Boolean vert) { this.save(); } - public void setWorldBlackList(List world_black_list) { - this.world_black_list = world_black_list; - this.config.set("WorldBlackList", world_black_list); - this.save(); - } - public void setPrice(Double price) { this.price = price; this.config.set("Price", price); @@ -238,4 +229,47 @@ public static Map loadGroups(JavaPlugin plugin) { XLogger.info(Translation.Messages_LoadedGroupAmount, groups.size()); return groups; } + + private void saveAll() { + this.file_path.delete(); + this.config = new YamlConfiguration(); + this.config.set("MinY", min_y); + this.config.setComments("MinY", Arrays.asList( + Translation.Config_Comment_GroupLine1.trans(), + Translation.Config_Comment_GroupLine2.trans(), + Translation.Config_Comment_GroupLine3.trans(), + Translation.Config_Comment_GroupLine4.trans(), + Translation.Config_Comment_GroupLine5.trans(), + Translation.Config_Comment_GroupLine6.trans(), + Translation.Config_Comment_GroupLine7.trans(), + String.format(Translation.Config_Comment_GroupLine8DocumentAddress.trans(), ConfigManager.instance.getLanguage()) + )); + this.config.setInlineComments("MinY", List.of(Translation.Config_Comment_MinY.trans())); + this.config.set("MaxY", max_y); + this.config.setInlineComments("MaxY", List.of(Translation.Config_Comment_MaxY.trans())); + this.config.set("SizeX", size_x); + this.config.setInlineComments("SizeX", List.of(Translation.Config_Comment_SizeX.trans() + Translation.Config_Comment_NegativeOneUnlimited.trans())); + this.config.set("SizeY", size_y); + this.config.setInlineComments("SizeY", List.of(Translation.Config_Comment_SizeY.trans() + Translation.Config_Comment_NegativeOneUnlimited.trans())); + this.config.set("SizeZ", size_z); + this.config.setInlineComments("SizeZ", List.of(Translation.Config_Comment_SizeZ.trans() + Translation.Config_Comment_NegativeOneUnlimited.trans())); + this.config.set("Amount", amount); + this.config.setInlineComments("Amount", List.of(Translation.Config_Comment_Amount.trans() + Translation.Config_Comment_NegativeOneUnlimited.trans())); + this.config.set("Depth", depth); + this.config.setInlineComments("Depth", List.of(Translation.Config_Comment_Depth.trans() + Translation.Config_Comment_ZeroDisabled.trans() + Translation.Config_Comment_NegativeOneUnlimited.trans())); + this.config.set("Vert", vert); + this.config.setInlineComments("Vert", List.of(Translation.Config_Comment_Vert.trans())); + this.config.set("Price", price); + this.config.setInlineComments("Price", List.of(Translation.Config_Comment_Price.trans())); + this.config.set("OnlyXZ", only_xz); + this.config.setInlineComments("OnlyXZ", List.of(Translation.Config_Comment_OnlyXZ.trans())); + this.config.set("Refund", refund); + this.config.setInlineComments("Refund", List.of(Translation.Config_Comment_Refund.trans())); + + try { + this.config.save(this.file_path); + } catch (Exception e) { + XLogger.err("Failed to save group limit file: " + this.file_path.getName()); + } + } } diff --git a/core/src/main/java/cn/lunadeer/dominion/managers/Translation.java b/core/src/main/java/cn/lunadeer/dominion/managers/Translation.java index 69a79968..b5464ae3 100644 --- a/core/src/main/java/cn/lunadeer/dominion/managers/Translation.java +++ b/core/src/main/java/cn/lunadeer/dominion/managers/Translation.java @@ -808,9 +808,6 @@ public class Translation extends Localization { @i18nField(defaultValue = "来自领地:") public static i18n TUI_TitleList_FromDominion; - @i18nField(defaultValue = "Dominion 系统配置") - public static i18n TUI_Config_Title; - @i18nField(defaultValue = "输入要创建的领地名称") public static i18n CUI_Input_CreateDominion; @i18nField(defaultValue = "输入要创建的权限组名称") @@ -907,8 +904,6 @@ public class Translation extends Localization { public static i18n Config_Comment_ZeroDisabled; @i18nField(defaultValue = "是否自动延伸到 MaxY 和 MinY") public static i18n Config_Comment_Vert; - @i18nField(defaultValue = "不允许圈地的世界列表") - public static i18n Config_Comment_DisabledWorlds; @i18nField(defaultValue = "是否允许OP无视领地限制") public static i18n Config_Comment_OpBypass; @i18nField(defaultValue = "传送延迟 秒") @@ -941,6 +936,22 @@ public class Translation extends Localization { public static i18n Config_Comment_GroupTitleColor; @i18nField(defaultValue = "性能测试计时器") public static i18n Config_Comment_PerformanceTimer; + @i18nField(defaultValue = ">---------------------------------<") + public static i18n Config_Comment_GroupLine1; + @i18nField(defaultValue = "| 圈地限制特殊权限组配置 |") + public static i18n Config_Comment_GroupLine2; + @i18nField(defaultValue = ">---------------------------------<") + public static i18n Config_Comment_GroupLine3; + @i18nField(defaultValue = "此文件可以作为模板,你可以将此文件复制后重命名为你想要的") + public static i18n Config_Comment_GroupLine4; + @i18nField(defaultValue = "权限组名,然后修改里面的配置如果你想给赞助玩家(或者VIP)") + public static i18n Config_Comment_GroupLine5; + @i18nField(defaultValue = "一些特殊优惠,例如更少的圈地价格、更大的领地等,你可以在") + public static i18n Config_Comment_GroupLine6; + @i18nField(defaultValue = "这里配置。详细说明参阅以下链接:") + public static i18n Config_Comment_GroupLine7; + @i18nField(defaultValue = "> https://dominion.lunadeer.cn/%s/operator/privilege.html") + public static i18n Config_Comment_GroupLine8DocumentAddress; @i18nField(defaultValue = "管理员") public static i18n Flags_admin_DisplayName; diff --git a/core/src/main/resources/config.yml b/core/src/main/resources/config.yml index 752e62d1..81d3c3e0 100644 --- a/core/src/main/resources/config.yml +++ b/core/src/main/resources/config.yml @@ -20,7 +20,6 @@ Limit: Amount: 10 Depth: 3 Vert: false - WorldBlackList: ['some_world'] OpByPass: true Teleport: diff --git a/core/src/main/resources/groups/sponsor.yml b/core/src/main/resources/groups/sponsor.yml index e5f4aa5a..2e2dc45f 100644 --- a/core/src/main/resources/groups/sponsor.yml +++ b/core/src/main/resources/groups/sponsor.yml @@ -1,20 +1,11 @@ -# >---------------------------------< -# | 圈地限制特殊权限组配置 | -# >---------------------------------< -# 此文件可以作为模板,你可以将此文件复制后重命名为你想要的权限组名,然后修改里面的配置 -# 如果你想给赞助玩家(或者VIP)一些特殊优惠,例如更少的圈地价格、更大的领地等,你可以在这里配置 -# 详细说明参阅 > https://ssl.lunadeer.cn:14448/doc/82/ - - -MinY: -64 # 最小Y坐标 -MaxY: 320 # 最大Y坐标 -SizeX: 128 # X方向最大长度 -1:表示不限制 -SizeY: 64 # Y方向最大长度 -1:表示不限制 -SizeZ: 128 # Z方向最大长度 -1:表示不限制 -Amount: 10 # 最大领地数量 -1:表示不限制 -Depth: 3 # 子领地深度 0:不允许子领地 -1:不限制 -Vert: false # 是否自动延伸到 MaxY 和 MinY -WorldBlackList: [ ] # 不允许领地的世界 -Price: 10.0 # 方块单价 -OnlyXZ: false # 是否只计算xz平面积 -Refund: 0.85 # 删除领地退还比例 \ No newline at end of file +MinY: -64 +MaxY: 320 +SizeX: 128 +SizeY: 64 +SizeZ: 128 +Amount: 10 +Depth: 3 +Vert: false +Price: 10.0 +OnlyXZ: false +Refund: 0.85 \ No newline at end of file diff --git a/core/src/main/resources/languages/zh-cn.yml b/core/src/main/resources/languages/zh-cn.yml index 76df7f83..01f50ccf 100644 --- a/core/src/main/resources/languages/zh-cn.yml +++ b/core/src/main/resources/languages/zh-cn.yml @@ -410,8 +410,6 @@ TUI: RemoveButton: 卸下 ApplyButton: 使用 FromDominion: 来自领地: - Config: - Title: Dominion 系统配置 CUI: Input: CreateDominion: 输入要创建的领地名称 @@ -465,7 +463,6 @@ Config: Depth: 子领地深度 ZeroDisabled: 0表示不开启 Vert: 是否自动延伸到 MaxY 和 MinY - DisabledWorlds: 不允许圈地的世界列表 OpBypass: 是否允许OP无视领地限制 TpDelay: 传送延迟 秒 TpCoolDown: 传送冷却 秒 @@ -482,6 +479,14 @@ Config: GroupTitleVariable: '变量: %dominion_group_title%' GroupTitleColor: 前后缀如需要加颜色请使用这种格式 &#ffffff PerformanceTimer: 性能测试计时器 + GroupLine1: '>---------------------------------<' + GroupLine2: '| 圈地限制特殊权限组配置 |' + GroupLine3: '>---------------------------------<' + GroupLine4: 此文件可以作为模板,你可以将此文件复制后重命名为你想要的 + GroupLine5: 权限组名,然后修改里面的配置如果你想给赞助玩家(或者VIP) + GroupLine6: 一些特殊优惠,例如更少的圈地价格、更大的领地等,你可以在 + GroupLine7: 这里配置。详细说明参阅以下链接: + GroupLine8DocumentAddress: '> https://dominion.lunadeer.cn/%s/operator/privilege.html' Flags: admin: DisplayName: 管理员 From 1f3fb77b49fd4df899a9692a534b034adb6b497e Mon Sep 17 00:00:00 2001 From: zhangyuheng Date: Fri, 6 Sep 2024 11:17:20 +0800 Subject: [PATCH 2/7] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20readme=20=E6=96=87?= =?UTF-8?q?=E6=A1=A3=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c3735a7e..0847d1fe 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ [![bStats](https://img.shields.io/badge/bStats-Statistics-eacd76?logo=google-analytics)](https://bstats.org/plugin/bukkit/Dominion/21445) [![Hangar](https://img.shields.io/badge/Hangar-Project-bacac6?logo=paper)](https://hangar.papermc.io/zhangyuheng/Dominion) -[![Documentation](https://img.shields.io/badge/在线文档-点击跳转-70f3ff?logo=readthedocs)](https://ssl.lunadeer.cn:14448/doc/23/) +[![Documentation](https://img.shields.io/badge/在线文档-点击跳转-70f3ff?logo=readthedocs)](https://dominion.lunadeer.cn/) [![Latest Build](https://img.shields.io/github/v/release/ColdeZhang/Dominion?label=%E6%9C%80%E6%96%B0%E6%9E%84%E5%BB%BA%E4%B8%8B%E8%BD%BD&logo=github&color=0aa344)](https://github.com/ColdeZhang/Dominion/releases/latest) [![Latest Build](https://img.shields.io/github/v/release/ColdeZhang/Dominion?label=%E5%A4%87%E7%94%A8%E4%B8%8B%E8%BD%BD%E5%9C%B0%E5%9D%80&logo=gitea&color=0aa344)](https://ssl.lunadeer.cn:14446/mirror/Dominion/releases) From 40d4ede3fce13202ae9a5621a07270e70d8a05e5 Mon Sep 17 00:00:00 2001 From: zhangyuheng Date: Fri, 6 Sep 2024 16:42:43 +0800 Subject: [PATCH 3/7] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E4=BA=86=E5=8D=95?= =?UTF-8?q?=E7=8B=AC=E9=85=8D=E7=BD=AE=E4=B8=96=E7=95=8C=E5=9C=88=E5=9C=B0?= =?UTF-8?q?=E8=A7=84=E5=88=99=E7=9A=84=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle.kts | 2 +- .../lunadeer/dominion/commands/SetConfig.java | 280 ----------------- .../controllers/DominionController.java | 8 + .../dominion/managers/ConfigManager.java | 276 ++++------------ .../dominion/managers/GroupLimit.java | 297 ++++++++++-------- .../dominion/managers/WorldSetting.java | 103 ++++++ core/src/main/resources/config.yml | 11 + core/src/main/resources/groups/sponsor.yml | 13 +- 8 files changed, 363 insertions(+), 627 deletions(-) delete mode 100644 core/src/main/java/cn/lunadeer/dominion/commands/SetConfig.java create mode 100644 core/src/main/java/cn/lunadeer/dominion/managers/WorldSetting.java diff --git a/build.gradle.kts b/build.gradle.kts index edad4168..e2bb0327 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -4,7 +4,7 @@ plugins { } group = "cn.lunadeer" -version = "2.5.7-beta" +version = "2.6.0-beta" java { toolchain.languageVersion.set(JavaLanguageVersion.of(21)) diff --git a/core/src/main/java/cn/lunadeer/dominion/commands/SetConfig.java b/core/src/main/java/cn/lunadeer/dominion/commands/SetConfig.java deleted file mode 100644 index cc7bf06d..00000000 --- a/core/src/main/java/cn/lunadeer/dominion/commands/SetConfig.java +++ /dev/null @@ -1,280 +0,0 @@ -package cn.lunadeer.dominion.commands; - -import cn.lunadeer.dominion.Dominion; -import cn.lunadeer.dominion.managers.Translation; -import cn.lunadeer.minecraftpluginutils.Notification; -import org.bukkit.command.CommandSender; - -import static cn.lunadeer.dominion.utils.CommandUtils.hasPermission; - -public class SetConfig { - - @Deprecated - public static void handler(CommandSender sender, String[] args) { - if (!hasPermission(sender, "dominion.admin")) { - return; - } - if (args.length < 2) { - Notification.error(sender, Translation.Commands_ArgumentsNotEnough); - return; - } - switch (args[1]) { - case "auto_create_radius": - setAutoCreateRadius(sender, args); - break; - case "limit_max_y": - setLimitMaxY(sender, args); - break; - case "limit_min_y": - setLimitMinY(sender, args); - break; - case "limit_size_x": - setLimitSizeX(sender, args); - break; - case "limit_size_z": - setLimitSizeZ(sender, args); - break; - case "limit_size_y": - setLimitSizeY(sender, args); - break; - case "limit_amount": - setLimitAmount(sender, args); - break; - case "limit_depth": - setLimitDepth(sender, args); - break; - case "limit_vert": - setLimitVert(sender, args); - break; - case "limit_op_bypass": - setLimitOpBypass(sender, args); - break; - case "tp_enable": - setTpEnable(sender, args); - break; - case "tp_delay": - setTpDelay(sender, args); - break; - case "tp_cool_down": - setTpCoolDown(sender, args); - break; - case "economy_enable": - setEconomyEnable(sender, args); - break; - case "economy_price": - setEconomyPrice(sender, args); - break; - case "economy_only_xz": - setEconomyOnlyXZ(sender, args); - break; - case "economy_refund": - setEconomyRefund(sender, args); - break; - case "residence_migration": - setResidenceMigration(sender, args); - break; - case "spawn_protection": - setSpawnProtection(sender, args); - break; - default: - Notification.error(sender, Translation.Commands_UnknownArgument); - } - } - - public static void refreshPageOrNot(CommandSender sender, String[] args) { - if (args.length == 4) { - int page = Integer.parseInt(args[3]); - String[] newArgs = new String[2]; - newArgs[0] = "config"; - newArgs[1] = String.valueOf(page); - // SysConfig.show(sender, newArgs); - } - } - - private static void setAutoCreateRadius(CommandSender sender, String[] args) { - int size = Integer.parseInt(args[2]); - if (size <= 0) { - Dominion.config.setAutoCreateRadius(1); - Notification.error(sender, Translation.Config_Check_AutoCreateRadiusError); - } else { - Dominion.config.setAutoCreateRadius(size); - } - refreshPageOrNot(sender, args); - } - - private static void adjustSizeY() { - if (Dominion.config.getLimitVert(null)) { - Dominion.config.setLimitSizeY(Dominion.config.getLimitMaxY(null) - Dominion.config.getLimitMinY(null) + 1); - } - } - - private static void setLimitMaxY(CommandSender sender, String[] args) { - int maxY = Integer.parseInt(args[2]); - if (maxY <= Dominion.config.getLimitMinY(null)) { - Notification.error(sender, Translation.Commands_SetConfig_MinYShouldBeLessThanMaxY); - return; - } - Dominion.config.setLimitMaxY(maxY); - adjustSizeY(); - refreshPageOrNot(sender, args); - } - - private static void setLimitMinY(CommandSender sender, String[] args) { - int minY = Integer.parseInt(args[2]); - if (minY >= Dominion.config.getLimitMaxY(null)) { - Notification.error(sender, Translation.Commands_SetConfig_MaxYShouldBeGreaterThanMinY); - return; - } - Dominion.config.setLimitMinY(minY); - adjustSizeY(); - refreshPageOrNot(sender, args); - } - - private static void setLimitSizeX(CommandSender sender, String[] args) { - int sizeX = Integer.parseInt(args[2]); - if (sizeX != -1 && sizeX < 4) { - Dominion.config.setLimitSizeX(4); - Notification.error(sender, Translation.Commands_SetConfig_SizeXShouldBeGreaterThan4); - } else { - Dominion.config.setLimitSizeX(sizeX); - } - refreshPageOrNot(sender, args); - } - - private static void setLimitSizeZ(CommandSender sender, String[] args) { - int sizeZ = Integer.parseInt(args[2]); - if (sizeZ != -1 && sizeZ < 4) { - Dominion.config.setLimitSizeZ(4); - Notification.error(sender, Translation.Commands_SetConfig_SizeZShouldBeGreaterThan4); - return; - } else { - Dominion.config.setLimitSizeZ(sizeZ); - } - refreshPageOrNot(sender, args); - } - - private static void setLimitSizeY(CommandSender sender, String[] args) { - int sizeY = Integer.parseInt(args[2]); - if (sizeY != -1 && sizeY < 4) { - Dominion.config.setLimitSizeY(4); - Notification.error(sender, Translation.Commands_SetConfig_SizeYShouldBeGreaterThan4); - } else { - Dominion.config.setLimitSizeY(sizeY); - } - refreshPageOrNot(sender, args); - } - - private static void setLimitAmount(CommandSender sender, String[] args) { - int amount = Integer.parseInt(args[2]); - if (amount != -1 && amount < 0) { - Dominion.config.setLimitAmount(0); - Notification.error(sender, Translation.Commands_SetConfig_AmountShouldBeGreaterThan0); - } else { - Dominion.config.setLimitAmount(amount); - } - refreshPageOrNot(sender, args); - } - - private static void setLimitDepth(CommandSender sender, String[] args) { - int depth = Integer.parseInt(args[2]); - if (depth != -1 && depth < 0) { - Dominion.config.setLimitDepth(0); - Notification.error(sender, Translation.Commands_SetConfig_DepthShouldBeGreaterThan0); - } else { - Dominion.config.setLimitDepth(depth); - } - refreshPageOrNot(sender, args); - } - - private static void setLimitVert(CommandSender sender, String[] args) { - boolean limitVert = Boolean.parseBoolean(args[2]); - Dominion.config.setLimitVert(limitVert); - adjustSizeY(); - refreshPageOrNot(sender, args); - } - - private static void setLimitOpBypass(CommandSender sender, String[] args) { - boolean limitOpBypass = Boolean.parseBoolean(args[2]); - Dominion.config.setLimitOpBypass(limitOpBypass); - refreshPageOrNot(sender, args); - } - - private static void setTpEnable(CommandSender sender, String[] args) { - boolean tpEnable = Boolean.parseBoolean(args[2]); - Dominion.config.setTpEnable(tpEnable); - refreshPageOrNot(sender, args); - } - - private static void setTpDelay(CommandSender sender, String[] args) { - int tpDelay = Integer.parseInt(args[2]); - if (tpDelay < 0) { - Dominion.config.setTpDelay(0); - Notification.error(sender, Translation.Commands_SetConfig_TpDelayShouldBeGreaterThan0); - } else { - Dominion.config.setTpDelay(tpDelay); - } - refreshPageOrNot(sender, args); - } - - private static void setTpCoolDown(CommandSender sender, String[] args) { - int tpCoolDown = Integer.parseInt(args[2]); - if (tpCoolDown < 0) { - Dominion.config.setTpCoolDown(0); - Notification.error(sender, Translation.Commands_SetConfig_TpCoolDownShouldBeGreaterThan0); - } else { - Dominion.config.setTpCoolDown(tpCoolDown); - } - refreshPageOrNot(sender, args); - } - - private static void setEconomyEnable(CommandSender sender, String[] args) { - boolean economyEnable = Boolean.parseBoolean(args[2]); - Dominion.config.setEconomyEnable(economyEnable); - refreshPageOrNot(sender, args); - } - - private static void setEconomyPrice(CommandSender sender, String[] args) { - float economyPrice = Float.parseFloat(args[2]); - if (economyPrice < 0) { - Dominion.config.setEconomyPrice(0.0f); - Notification.error(sender, Translation.Commands_SetConfig_PriceShouldBeGreaterThan0); - } else { - Dominion.config.setEconomyPrice(economyPrice); - } - refreshPageOrNot(sender, args); - } - - private static void setEconomyOnlyXZ(CommandSender sender, String[] args) { - boolean economyOnlyXZ = Boolean.parseBoolean(args[2]); - Dominion.config.setEconomyOnlyXZ(economyOnlyXZ); - refreshPageOrNot(sender, args); - } - - private static void setEconomyRefund(CommandSender sender, String[] args) { - float economyRefund = Float.parseFloat(args[2]); - if (economyRefund < 0) { - Dominion.config.setEconomyRefund(0.0f); - Notification.error(sender, Translation.Commands_SetConfig_RefundShouldBeGreaterThan0); - } else { - Dominion.config.setEconomyRefund(economyRefund); - } - refreshPageOrNot(sender, args); - } - - private static void setResidenceMigration(CommandSender sender, String[] args) { - boolean residenceMigration = Boolean.parseBoolean(args[2]); - Dominion.config.setResidenceMigration(residenceMigration); - refreshPageOrNot(sender, args); - } - - private static void setSpawnProtection(CommandSender sender, String[] args) { - int spawnProtection = Integer.parseInt(args[2]); - if (spawnProtection != -1 && spawnProtection <= 0) { - Dominion.config.setSpawnProtection(1); - Notification.error(sender, Translation.Commands_SetConfig_SpawnProtectRadiusShouldBeGreaterThan0); - } else { - Dominion.config.setSpawnProtection(spawnProtection); - } - refreshPageOrNot(sender, args); - } -} diff --git a/core/src/main/java/cn/lunadeer/dominion/controllers/DominionController.java b/core/src/main/java/cn/lunadeer/dominion/controllers/DominionController.java index c7848d99..5ebfc764 100644 --- a/core/src/main/java/cn/lunadeer/dominion/controllers/DominionController.java +++ b/core/src/main/java/cn/lunadeer/dominion/controllers/DominionController.java @@ -103,6 +103,14 @@ public static void create(AbstractOperator operator, String name, operator.setResponse(FAIL.addMessage(Translation.Messages_SelectPointsWorldNotSame)); return; } + if (operator.getLocation() == null) { + operator.setResponse(FAIL.addMessage(Translation.Messages_CommandPlayerOnly)); + return; + } + if (!loc1.getWorld().getUID().equals(operator.getLocation().getWorld().getUID())) { + operator.setResponse(FAIL.addMessage(Translation.Messages_CrossWorldOperationDisallowed)); + return; + } // 检查世界是否可以创建 if (worldNotValid(operator, loc1.getWorld().getName())) { operator.setResponse(FAIL.addMessage(Translation.Messages_CreateDominionDisabledWorld, loc1.getWorld().getName())); diff --git a/core/src/main/java/cn/lunadeer/dominion/managers/ConfigManager.java b/core/src/main/java/cn/lunadeer/dominion/managers/ConfigManager.java index 6a22cd01..2f967023 100644 --- a/core/src/main/java/cn/lunadeer/dominion/managers/ConfigManager.java +++ b/core/src/main/java/cn/lunadeer/dominion/managers/ConfigManager.java @@ -5,6 +5,7 @@ import cn.lunadeer.minecraftpluginutils.VaultConnect.VaultConnect; import cn.lunadeer.minecraftpluginutils.XLogger; import org.bukkit.Material; +import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.Player; @@ -41,36 +42,17 @@ public void reload() { _db_user = _file.getString("Database.User", "postgres"); _db_pass = _file.getString("Database.Pass", "postgres"); _auto_create_radius = _file.getInt("AutoCreateRadius", 10); - if (_auto_create_radius == 0) { - XLogger.err(Translation.Config_Check_AutoCreateRadiusError); - setAutoCreateRadius(10); - } _spawn_protection = _file.getInt("Limit.SpawnProtection", 10); _blue_map = _file.getBoolean("BlueMap", false); _dynmap = _file.getBoolean("Dynmap", false); _auto_clean_after_days = _file.getInt("AutoCleanAfterDays", 180); - if (_auto_clean_after_days == 0) { - XLogger.err(Translation.Config_Check_AutoCleanAfterDaysError); - setAutoCleanAfterDays(180); - } _limit_op_bypass = _file.getBoolean("Limit.OpByPass", true); _check_update = _file.getBoolean("CheckUpdate", true); _tp_enable = _file.getBoolean("Teleport.Enable", false); _tp_delay = _file.getInt("Teleport.Delay", 0); - if (_tp_delay < 0) { - XLogger.err(Translation.Config_Check_TpDelayError); - setTpDelay(0); - } _tp_cool_down = _file.getInt("Teleport.CoolDown", 0); - if (_tp_cool_down < 0) { - XLogger.err(Translation.Config_Check_TpCoolDownError); - setTpCoolDown(0); - } _tool = _file.getString("Tool", "ARROW"); - if (Material.getMaterial(_tool) == null) { - XLogger.err(Translation.Config_Check_ToolNameError); - setTool("ARROW"); - } + _economy_enable = _file.getBoolean("Economy.Enable", false); if (getEconomyEnable()) { new VaultConnect(this._plugin); @@ -82,59 +64,26 @@ public void reload() { _group_title_suffix = _file.getString("GroupTitle.Suffix", "&#ffffff]"); GroupLimit defaultGroup = new GroupLimit(); - defaultGroup.setLimitSizeX(_file.getInt("Limit.SizeX", 128)); - defaultGroup.setLimitSizeY(_file.getInt("Limit.SizeY", 64)); - defaultGroup.setLimitSizeZ(_file.getInt("Limit.SizeZ", 128)); - defaultGroup.setLimitMinY(_file.getInt("Limit.MinY", -64)); - defaultGroup.setLimitMaxY(_file.getInt("Limit.MaxY", 320)); - defaultGroup.setLimitAmount(_file.getInt("Limit.Amount", 10)); - defaultGroup.setLimitDepth(_file.getInt("Limit.Depth", 3)); - defaultGroup.setLimitVert(_file.getBoolean("Limit.Vert", false)); + defaultGroup.setLimitSizeX(_file.getInt("Limit.SizeX", 128), null); + defaultGroup.setLimitSizeY(_file.getInt("Limit.SizeY", 64), null); + defaultGroup.setLimitSizeZ(_file.getInt("Limit.SizeZ", 128), null); + defaultGroup.setLimitMinY(_file.getInt("Limit.MinY", -64), null); + defaultGroup.setLimitMaxY(_file.getInt("Limit.MaxY", 320), null); + defaultGroup.setLimitAmount(_file.getInt("Limit.Amount", 10), null); + defaultGroup.setLimitDepth(_file.getInt("Limit.Depth", 3), null); + defaultGroup.setLimitVert(_file.getBoolean("Limit.Vert", false), null); defaultGroup.setPrice(_file.getDouble("Economy.Price", 10.0)); defaultGroup.setPriceOnlyXZ(_file.getBoolean("Economy.OnlyXZ", false)); defaultGroup.setRefundRatio(_file.getDouble("Economy.Refund", 0.85)); - groupLimits.put("default", defaultGroup); - - if (defaultGroup.getLimitSizeX() <= 4 && defaultGroup.getLimitSizeX() != -1) { - XLogger.err(Translation.Config_Check_LimitSizeXError); - setLimitSizeX(128); - } - if (defaultGroup.getLimitSizeY() <= 4 && defaultGroup.getLimitSizeY() != -1) { - XLogger.err(Translation.Config_Check_LimitSizeYError); - setLimitSizeY(64); - } - if (defaultGroup.getLimitSizeZ() <= 4 && defaultGroup.getLimitSizeZ() != -1) { - XLogger.err(Translation.Config_Check_LimitSizeZError); - setLimitSizeZ(128); - } - if (defaultGroup.getLimitMinY() >= defaultGroup.getLimitMaxY()) { - XLogger.err(Translation.Config_Check_LimitMinYError); - setLimitMinY(-64); - setLimitMaxY(320); - } - if (defaultGroup.getRefundRatio() < 0.0 || defaultGroup.getRefundRatio() > 1.0) { - XLogger.err(Translation.Config_Check_RefundError); - setEconomyRefund(0.85f); - } - if (defaultGroup.getPrice() < 0.0) { - XLogger.err(Translation.Config_Check_PriceError); - setEconomyPrice(10.0f); - } - if (defaultGroup.getLimitVert() && defaultGroup.getLimitSizeY() <= defaultGroup.getLimitMaxY() - defaultGroup.getLimitMinY()) { - XLogger.warn(Translation.Config_Check_LimitSizeYAutoAdjust, (defaultGroup.getLimitMaxY() - defaultGroup.getLimitMinY() + 1)); - setLimitSizeY(defaultGroup.getLimitMaxY() - defaultGroup.getLimitMinY() + 1); - } - if (defaultGroup.getLimitAmount() < 0 && defaultGroup.getLimitAmount() != -1) { - XLogger.err(Translation.Config_Check_AmountError); - setLimitAmount(10); - } - if (defaultGroup.getLimitDepth() < 0 && defaultGroup.getLimitDepth() != -1) { - XLogger.err(Translation.Config_Check_DepthError); - setLimitDepth(3); + ConfigurationSection worldSettings = _file.getConfigurationSection("Limit.WorldSettings"); + if (worldSettings != null) { + defaultGroup.addWorldLimits(WorldSetting.load("config.yml", worldSettings)); } + groupLimits.put("default", defaultGroup); groupLimits.putAll(GroupLimit.loadGroups(_plugin)); + checkRules(); saveAll(); // 回写文件 防止文件中的数据不完整 Flag.loadFromFile(); // 加载 Flag 配置 } @@ -165,24 +114,25 @@ public void saveAll() { _file.setComments("Limit", List.of(Translation.Config_Comment_DefaultLimit.trans())); _file.set("Limit.SpawnProtection", _spawn_protection); _file.setInlineComments("Limit.SpawnProtection", List.of(Translation.Config_Comment_SpawnProtectRadius.trans() + Translation.Config_Comment_NegativeOneDisabled.trans())); - _file.set("Limit.MinY", groupLimits.get("default").getLimitMinY()); + _file.set("Limit.MinY", groupLimits.get("default").getLimitMinY(null)); _file.setInlineComments("Limit.MinY", List.of(Translation.Config_Comment_MinY.trans())); - _file.set("Limit.MaxY", groupLimits.get("default").getLimitMaxY()); + _file.set("Limit.MaxY", groupLimits.get("default").getLimitMaxY(null)); _file.setInlineComments("Limit.MaxY", List.of(Translation.Config_Comment_MaxY.trans())); - _file.set("Limit.SizeX", groupLimits.get("default").getLimitSizeX()); + _file.set("Limit.SizeX", groupLimits.get("default").getLimitSizeX(null)); _file.setInlineComments("Limit.SizeX", List.of(Translation.Config_Comment_SizeX.trans() + Translation.Config_Comment_NegativeOneUnlimited.trans())); - _file.set("Limit.SizeY", groupLimits.get("default").getLimitSizeY()); + _file.set("Limit.SizeY", groupLimits.get("default").getLimitSizeY(null)); _file.setInlineComments("Limit.SizeY", List.of(Translation.Config_Comment_SizeY.trans() + Translation.Config_Comment_NegativeOneUnlimited.trans())); - _file.set("Limit.SizeZ", groupLimits.get("default").getLimitSizeZ()); + _file.set("Limit.SizeZ", groupLimits.get("default").getLimitSizeZ(null)); _file.setInlineComments("Limit.SizeZ", List.of(Translation.Config_Comment_SizeZ.trans() + Translation.Config_Comment_NegativeOneUnlimited.trans())); - _file.set("Limit.Amount", groupLimits.get("default").getLimitAmount()); + _file.set("Limit.Amount", groupLimits.get("default").getLimitAmount(null)); _file.setInlineComments("Limit.Amount", List.of(Translation.Config_Comment_Amount.trans() + Translation.Config_Comment_NegativeOneUnlimited.trans())); - _file.set("Limit.Depth", groupLimits.get("default").getLimitDepth()); + _file.set("Limit.Depth", groupLimits.get("default").getLimitDepth(null)); _file.setInlineComments("Limit.Depth", List.of(Translation.Config_Comment_Depth.trans() + Translation.Config_Comment_ZeroDisabled.trans() + Translation.Config_Comment_NegativeOneUnlimited.trans())); - _file.set("Limit.Vert", groupLimits.get("default").getLimitVert()); + _file.set("Limit.Vert", groupLimits.get("default").getLimitVert(null)); _file.setInlineComments("Limit.Vert", List.of(Translation.Config_Comment_Vert.trans())); _file.set("Limit.OpByPass", _limit_op_bypass); _file.setInlineComments("Limit.OpByPass", List.of(Translation.Config_Comment_OpBypass.trans())); + _file.set("Limit.WorldSettings", groupLimits.get("default").getWorldSettings()); _file.set("Teleport.Enable", _tp_enable); _file.set("Teleport.Delay", _tp_delay); @@ -250,12 +200,6 @@ public String getDbType() { return _db_type; } - public void setDbType(String db_type) { - _db_type = db_type; - _file.set("Database.Type", db_type); - _plugin.saveConfig(); - } - public String getDbHost() { return _db_host; } @@ -271,7 +215,6 @@ public String getDbName() { public void setDbUser(String db_user) { _db_user = db_user; _file.set("Database.User", db_user); - _plugin.saveConfig(); } public String getDbUser() { @@ -284,7 +227,6 @@ public String getDbUser() { public void setDbPass(String db_pass) { _db_pass = db_pass; _file.set("Database.Pass", db_pass); - _plugin.saveConfig(); } public String getDbPass() { @@ -292,33 +234,15 @@ public String getDbPass() { } public Integer getLimitSizeX(Player player) { - return groupLimits.get(getPlayerGroup(player)).getLimitSizeX(); - } - - public void setLimitSizeX(Integer max_x) { - groupLimits.get("default").setLimitSizeX(max_x); - _file.set("Limit.SizeX", max_x); - _plugin.saveConfig(); + return groupLimits.get(getPlayerGroup(player)).getLimitSizeX(player.getWorld()); } public Integer getLimitSizeY(Player player) { - return groupLimits.get(getPlayerGroup(player)).getLimitSizeY(); - } - - public void setLimitSizeY(Integer max_y) { - groupLimits.get("default").setLimitSizeY(max_y); - _file.set("Limit.SizeY", max_y); - _plugin.saveConfig(); + return groupLimits.get(getPlayerGroup(player)).getLimitSizeY(player.getWorld()); } public Integer getLimitSizeZ(Player player) { - return groupLimits.get(getPlayerGroup(player)).getLimitSizeZ(); - } - - public void setLimitSizeZ(Integer max_z) { - groupLimits.get("default").setLimitSizeZ(max_z); - _file.set("Limit.SizeZ", max_z); - _plugin.saveConfig(); + return groupLimits.get(getPlayerGroup(player)).getLimitSizeZ(player.getWorld()); } public Integer getAutoCreateRadius() { @@ -328,7 +252,6 @@ public Integer getAutoCreateRadius() { public void setAutoCreateRadius(Integer radius) { _auto_create_radius = radius; _file.set("AutoCreateRadius", radius); - _plugin.saveConfig(); } public Boolean getBlueMap() { @@ -346,75 +269,36 @@ public Integer getAutoCleanAfterDays() { public void setAutoCleanAfterDays(Integer auto_clean_after_days) { _auto_clean_after_days = auto_clean_after_days; _file.set("AutoCleanAfterDays", auto_clean_after_days); - _plugin.saveConfig(); } public Integer getLimitMinY(Player player) { - return groupLimits.get(getPlayerGroup(player)).getLimitMinY(); - } - - public void setLimitMinY(Integer limit_bottom) { - groupLimits.get("default").setLimitMinY(limit_bottom); - _file.set("Limit.MinY", limit_bottom); - _plugin.saveConfig(); + return groupLimits.get(getPlayerGroup(player)).getLimitMinY(player.getWorld()); } public Integer getLimitMaxY(Player player) { - return groupLimits.get(getPlayerGroup(player)).getLimitMaxY(); - } - - public void setLimitMaxY(Integer limit_top) { - groupLimits.get("default").setLimitMaxY(limit_top); - _file.set("Limit.MaxY", limit_top); - _plugin.saveConfig(); + return groupLimits.get(getPlayerGroup(player)).getLimitMaxY(player.getWorld()); } public Integer getLimitAmount(Player player) { - return groupLimits.get(getPlayerGroup(player)).getLimitAmount(); - } - - public void setLimitAmount(Integer limit_amount) { - groupLimits.get("default").setLimitAmount(limit_amount); - _file.set("Limit.Amount", limit_amount); - _plugin.saveConfig(); + return groupLimits.get(getPlayerGroup(player)).getLimitAmount(player.getWorld()); } public Integer getLimitDepth(Player player) { - return groupLimits.get(getPlayerGroup(player)).getLimitDepth(); - } - - public void setLimitDepth(Integer limit_depth) { - groupLimits.get("default").setLimitDepth(limit_depth); - _file.set("Limit.Depth", limit_depth); - _plugin.saveConfig(); + return groupLimits.get(getPlayerGroup(player)).getLimitDepth(player.getWorld()); } public Boolean getLimitVert(Player player) { - return groupLimits.get(getPlayerGroup(player)).getLimitVert(); - } - - public void setLimitVert(Boolean limit_vert) { - groupLimits.get("default").setLimitVert(limit_vert); - _file.set("Limit.Vert", limit_vert); - _plugin.saveConfig(); + return groupLimits.get(getPlayerGroup(player)).getLimitVert(player.getWorld()); } public List getWorldBlackList(Player player) { - // todo - // return groupLimits.get(getPlayerGroup(player)).getWorldBlackList(); - return null; + return groupLimits.get(getPlayerGroup(player)).getWorldBlackList(); } public Boolean getLimitOpBypass() { return _limit_op_bypass; } - public void setLimitOpBypass(Boolean limit_op_bypass) { - _limit_op_bypass = limit_op_bypass; - _file.set("Limit.OpByPass", limit_op_bypass); - _plugin.saveConfig(); - } - public Boolean getCheckUpdate() { return _check_update; } @@ -423,12 +307,6 @@ public Boolean getTpEnable() { return _tp_enable; } - public void setTpEnable(Boolean tp_enable) { - _tp_enable = tp_enable; - _file.set("Teleport.Enable", tp_enable); - _plugin.saveConfig(); - } - public Integer getTpDelay() { return _tp_delay; } @@ -436,7 +314,6 @@ public Integer getTpDelay() { public void setTpDelay(Integer tp_delay) { _tp_delay = tp_delay; _file.set("Teleport.Delay", tp_delay); - _plugin.saveConfig(); } public Integer getTpCoolDown() { @@ -446,7 +323,6 @@ public Integer getTpCoolDown() { public void setTpCoolDown(Integer tp_cool_down) { _tp_cool_down = tp_cool_down; _file.set("Teleport.CoolDown", tp_cool_down); - _plugin.saveConfig(); } public Material getTool() { @@ -456,79 +332,36 @@ public Material getTool() { public void setTool(String tool) { _tool = tool; _file.set("Tool", tool); - _plugin.saveConfig(); } public Boolean getEconomyEnable() { return _economy_enable; } - public void setEconomyEnable(Boolean economy_enable) { - _economy_enable = economy_enable; - _file.set("Economy.Enable", economy_enable); - _plugin.saveConfig(); - } - public Float getEconomyPrice(Player player) { return groupLimits.get(getPlayerGroup(player)).getPrice().floatValue(); } - public void setEconomyPrice(Float economy_price) { - groupLimits.get("default").setPrice((double) economy_price); - _file.set("Economy.Price", economy_price); - _plugin.saveConfig(); - } - public Boolean getEconomyOnlyXZ(Player player) { return groupLimits.get(getPlayerGroup(player)).getPriceOnlyXZ(); } - public void setEconomyOnlyXZ(Boolean economy_only_xz) { - groupLimits.get("default").setPriceOnlyXZ(economy_only_xz); - _file.set("Economy.OnlyXZ", economy_only_xz); - _plugin.saveConfig(); - } - public Float getEconomyRefund(Player player) { return groupLimits.get(getPlayerGroup(player)).getRefundRatio().floatValue(); } - public void setEconomyRefund(Float economy_refund) { - groupLimits.get("default").setRefundRatio((double) economy_refund); - _file.set("Economy.Refund", economy_refund); - _plugin.saveConfig(); - } - public List getFlyPermissionNodes() { return _fly_permission_nodes; } - public void setFlyPermissionNodes(List fly_permission_nodes) { - _fly_permission_nodes = fly_permission_nodes; - _file.set("FlyPermissionNodes", fly_permission_nodes); - _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(); - } - public Integer getSpawnProtection() { return _spawn_protection; } - public void setSpawnProtection(Integer spawn_protection) { - _spawn_protection = spawn_protection; - _file.set("Limit.SpawnProtection", spawn_protection); - _plugin.saveConfig(); - } - public Boolean getGroupTitleEnable() { return _group_title_enable; } @@ -536,38 +369,45 @@ public Boolean getGroupTitleEnable() { public void setGroupTitleEnable(Boolean group_title_enable) { _group_title_enable = group_title_enable; _file.set("GroupTitle.Enable", group_title_enable); - _plugin.saveConfig(); } public String getGroupTitlePrefix() { return _group_title_prefix; } - public void setGroupTitlePrefix(String group_title_prefix) { - _group_title_prefix = group_title_prefix; - _file.set("GroupTitle.Prefix", group_title_prefix); - _plugin.saveConfig(); - } - public String getGroupTitleSuffix() { return _group_title_suffix; } - public void setGroupTitleSuffix(String group_title_suffix) { - _group_title_suffix = group_title_suffix; - _file.set("GroupTitle.Suffix", group_title_suffix); - _plugin.saveConfig(); - } - public String getLanguage() { return _language; } - public void setLanguage(String language) { - _language = language; - _file.set("Language", language); - _plugin.saveConfig(); - Translation.instance.loadLocale(language); + public void checkRules() { + if (Material.getMaterial(_tool) == null) { + XLogger.err(Translation.Config_Check_ToolNameError); + setTool("ARROW"); + } + if (getAutoCreateRadius() == 0) { + XLogger.err(Translation.Config_Check_AutoCreateRadiusError); + setAutoCreateRadius(10); + } + if (getAutoCleanAfterDays() == 0) { + XLogger.err(Translation.Config_Check_AutoCleanAfterDaysError); + setAutoCleanAfterDays(180); + } + if (getTpDelay() < 0) { + XLogger.err(Translation.Config_Check_TpDelayError); + setTpDelay(0); + } + if (getTpCoolDown() < 0) { + XLogger.err(Translation.Config_Check_TpCoolDownError); + setTpCoolDown(0); + } + + for (GroupLimit limit : groupLimits.values()) { + limit.checkRules(); + } } private final Dominion _plugin; diff --git a/core/src/main/java/cn/lunadeer/dominion/managers/GroupLimit.java b/core/src/main/java/cn/lunadeer/dominion/managers/GroupLimit.java index a84f8881..6b9199af 100644 --- a/core/src/main/java/cn/lunadeer/dominion/managers/GroupLimit.java +++ b/core/src/main/java/cn/lunadeer/dominion/managers/GroupLimit.java @@ -1,27 +1,21 @@ package cn.lunadeer.dominion.managers; -import cn.lunadeer.dominion.Dominion; import cn.lunadeer.minecraftpluginutils.XLogger; +import org.bukkit.World; +import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.plugin.java.JavaPlugin; +import org.jetbrains.annotations.Nullable; import java.io.File; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; public class GroupLimit { + + private YamlConfiguration config; private final File file_path; - private Integer min_y; - private Integer max_y; - private Integer size_x; - private Integer size_y; - private Integer size_z; - private Integer amount; - private Integer depth; - private Boolean vert; + private final Map world_limits = new HashMap<>(); private Double price; private Boolean only_xz; private Double refund; @@ -29,89 +23,96 @@ public class GroupLimit { public GroupLimit() { this.file_path = null; this.config = new YamlConfiguration(); + WorldSetting defaultSetting = new WorldSetting("config.yml"); + world_limits.put("default", defaultSetting); } - public GroupLimit(File filePath) { + private GroupLimit(File filePath) { this.file_path = filePath; config = YamlConfiguration.loadConfiguration(this.file_path); - min_y = config.getInt("MinY", -64); - max_y = config.getInt("MaxY", 320); - if (getLimitMinY() >= getLimitMaxY()) { - XLogger.err(Translation.Config_Check_GroupMinYError, this.file_path.getName()); - setLimitMinY(-64); - setLimitMaxY(320); - } - size_x = config.getInt("SizeX", 128); - if (getLimitSizeX() <= 4 && getLimitSizeX() != -1) { - XLogger.err(Translation.Config_Check_GroupSizeXError, this.file_path.getName()); - setLimitSizeX(128); - } - size_y = config.getInt("SizeY", 64); - if (getLimitSizeY() <= 4 && getLimitSizeY() != -1) { - XLogger.err(Translation.Config_Check_GroupSizeYError, this.file_path.getName()); - setLimitSizeY(64); + WorldSetting defaultSetting = new WorldSetting(filePath.getName()); + defaultSetting.min_y = config.getInt("MinY", -64); + defaultSetting.max_y = config.getInt("MaxY", 320); + defaultSetting.size_x = config.getInt("SizeX", 128); + defaultSetting.size_y = config.getInt("SizeY", 64); + defaultSetting.size_z = config.getInt("SizeZ", 128); + defaultSetting.amount = config.getInt("Amount", 10); + defaultSetting.depth = config.getInt("Depth", 3); + defaultSetting.vert = config.getBoolean("Vert", false); + world_limits.put("default", defaultSetting); + ConfigurationSection worldSettings = config.getConfigurationSection("WorldSettings"); + if (worldSettings != null) { + addWorldLimits(WorldSetting.load(filePath.getName() + ":WorldSettings", worldSettings)); } - size_z = config.getInt("SizeZ", 128); - if (getLimitSizeZ() <= 4 && getLimitSizeZ() != -1) { - XLogger.err(Translation.Config_Check_GroupSizeZError, this.file_path.getName()); - setLimitSizeZ(128); - } - amount = config.getInt("Amount", 10); - if (getLimitAmount() <= 0 && getLimitAmount() != -1) { - XLogger.err(Translation.Config_Check_GroupAmountError, this.file_path.getName()); - setLimitAmount(10); - } - depth = config.getInt("Depth", 3); - if (getLimitDepth() <= 0 && getLimitDepth() != -1) { - XLogger.err(Translation.Config_Check_GroupDepthError, this.file_path.getName()); - setLimitDepth(3); - } - vert = config.getBoolean("Vert", false); price = config.getDouble("Price", 10.0); - if (getPrice() < 0.0) { - XLogger.err(Translation.Config_Check_GroupPriceError, this.file_path.getName()); - setPrice(10.0); - } only_xz = config.getBoolean("OnlyXZ", false); refund = config.getDouble("Refund", 0.85); - if (getRefundRatio() < 0.0 || getRefundRatio() > 1.0) { - XLogger.err(Translation.Config_Check_GroupRefundError, this.file_path.getName()); - setRefundRatio(0.85); - } - save(); // 保存一次,确保文件中的数据是合法的 + checkRules(); saveAll(); } - public Integer getLimitMinY() { - return min_y; + public Integer getLimitMinY(@Nullable World world) { + if (world == null || !world_limits.containsKey(world.getName())) { + return world_limits.get("default").min_y; + } else { + return world_limits.get(world.getName()).min_y; + } } - public Integer getLimitMaxY() { - return max_y; + public Integer getLimitMaxY(@Nullable World world) { + if (world == null || !world_limits.containsKey(world.getName())) { + return world_limits.get("default").max_y; + } else { + return world_limits.get(world.getName()).max_y; + } } - public Integer getLimitSizeX() { - return size_x; + public Integer getLimitSizeX(@Nullable World world) { + if (world == null || !world_limits.containsKey(world.getName())) { + return world_limits.get("default").size_x; + } else { + return world_limits.get(world.getName()).size_x; + } } - public Integer getLimitSizeY() { - return size_y; + public Integer getLimitSizeY(@Nullable World world) { + if (world == null || !world_limits.containsKey(world.getName())) { + return world_limits.get("default").size_y; + } else { + return world_limits.get(world.getName()).size_y; + } } - public Integer getLimitSizeZ() { - return size_z; + public Integer getLimitSizeZ(@Nullable World world) { + if (world == null || !world_limits.containsKey(world.getName())) { + return world_limits.get("default").size_z; + } else { + return world_limits.get(world.getName()).size_z; + } } - public Integer getLimitAmount() { - return amount; + public Integer getLimitAmount(@Nullable World world) { + if (world == null || !world_limits.containsKey(world.getName())) { + return world_limits.get("default").amount; + } else { + return world_limits.get(world.getName()).amount; + } } - public Integer getLimitDepth() { - return depth; + public Integer getLimitDepth(@Nullable World world) { + if (world == null || !world_limits.containsKey(world.getName())) { + return world_limits.get("default").depth; + } else { + return world_limits.get(world.getName()).depth; + } } - public Boolean getLimitVert() { - return vert; + public Boolean getLimitVert(@Nullable World world) { + if (world == null || !world_limits.containsKey(world.getName())) { + return world_limits.get("default").vert; + } else { + return world_limits.get(world.getName()).vert; + } } public Double getPrice() { @@ -127,84 +128,86 @@ public Double getRefundRatio() { } - public void setLimitMinY(Integer min_y) { - this.min_y = min_y; - this.config.set("MinY", min_y); - this.save(); + public void setLimitMinY(Integer min_y, @Nullable World world) { + if (world == null || !world_limits.containsKey(world.getName())) { + world_limits.get("default").min_y = min_y; + } else { + world_limits.get(world.getName()).min_y = min_y; + } } - public void setLimitMaxY(Integer max_y) { - this.max_y = max_y; - this.config.set("MaxY", max_y); - this.save(); + public void setLimitMaxY(Integer max_y, @Nullable World world) { + if (world == null || !world_limits.containsKey(world.getName())) { + world_limits.get("default").max_y = max_y; + } else { + world_limits.get(world.getName()).max_y = max_y; + } } - public void setLimitSizeX(Integer size_x) { - this.size_x = size_x; - this.config.set("SizeX", size_x); - this.save(); + public void setLimitSizeX(Integer size_x, @Nullable World world) { + if (world == null || !world_limits.containsKey(world.getName())) { + world_limits.get("default").size_x = size_x; + } else { + world_limits.get(world.getName()).size_x = size_x; + } } - public void setLimitSizeY(Integer size_y) { - this.size_y = size_y; - this.config.set("SizeY", size_y); - this.save(); + public void setLimitSizeY(Integer size_y, @Nullable World world) { + if (world == null || !world_limits.containsKey(world.getName())) { + world_limits.get("default").size_y = size_y; + } else { + world_limits.get(world.getName()).size_y = size_y; + } } - public void setLimitSizeZ(Integer size_z) { - this.size_z = size_z; - this.config.set("SizeZ", size_z); - this.save(); + public void setLimitSizeZ(Integer size_z, @Nullable World world) { + if (world == null || !world_limits.containsKey(world.getName())) { + world_limits.get("default").size_z = size_z; + } else { + world_limits.get(world.getName()).size_z = size_z; + } } - public void setLimitAmount(Integer amount) { - this.amount = amount; - this.config.set("Amount", amount); - this.save(); + public void setLimitAmount(Integer amount, @Nullable World world) { + if (world == null || !world_limits.containsKey(world.getName())) { + world_limits.get("default").amount = amount; + } else { + world_limits.get(world.getName()).amount = amount; + } } - public void setLimitDepth(Integer depth) { - this.depth = depth; - this.config.set("Depth", depth); - this.save(); + public void setLimitDepth(Integer depth, @Nullable World world) { + if (world == null || !world_limits.containsKey(world.getName())) { + world_limits.get("default").depth = depth; + } else { + world_limits.get(world.getName()).depth = depth; + } } - public void setLimitVert(Boolean vert) { - this.vert = vert; - this.config.set("Vert", vert); - this.save(); + public void setLimitVert(Boolean vert, @Nullable World world) { + if (world == null || !world_limits.containsKey(world.getName())) { + world_limits.get("default").vert = vert; + } else { + world_limits.get(world.getName()).vert = vert; + } } public void setPrice(Double price) { this.price = price; - this.config.set("Price", price); - this.save(); } public void setPriceOnlyXZ(Boolean only_xz) { this.only_xz = only_xz; - this.config.set("OnlyXZ", only_xz); - this.save(); } public void setRefundRatio(Double refund) { this.refund = refund; - this.config.set("Refund", refund); - this.save(); } - private void save() { - if (file_path == null) { - return; - } - try { - config.save(file_path); - } catch (Exception e) { - XLogger.err("Failed to save group limit file: " + file_path.getName()); - } + public void addWorldLimits(Map limits) { + world_limits.putAll(limits); } - public static Map loadGroups(JavaPlugin plugin) { Map groups = new HashMap<>(); File root = plugin.getDataFolder(); @@ -233,7 +236,7 @@ public static Map loadGroups(JavaPlugin plugin) { private void saveAll() { this.file_path.delete(); this.config = new YamlConfiguration(); - this.config.set("MinY", min_y); + this.config.set("MinY", world_limits.get("default").min_y); this.config.setComments("MinY", Arrays.asList( Translation.Config_Comment_GroupLine1.trans(), Translation.Config_Comment_GroupLine2.trans(), @@ -245,19 +248,19 @@ private void saveAll() { String.format(Translation.Config_Comment_GroupLine8DocumentAddress.trans(), ConfigManager.instance.getLanguage()) )); this.config.setInlineComments("MinY", List.of(Translation.Config_Comment_MinY.trans())); - this.config.set("MaxY", max_y); + this.config.set("MaxY", world_limits.get("default").max_y); this.config.setInlineComments("MaxY", List.of(Translation.Config_Comment_MaxY.trans())); - this.config.set("SizeX", size_x); + this.config.set("SizeX", world_limits.get("default").size_x); this.config.setInlineComments("SizeX", List.of(Translation.Config_Comment_SizeX.trans() + Translation.Config_Comment_NegativeOneUnlimited.trans())); - this.config.set("SizeY", size_y); + this.config.set("SizeY", world_limits.get("default").size_y); this.config.setInlineComments("SizeY", List.of(Translation.Config_Comment_SizeY.trans() + Translation.Config_Comment_NegativeOneUnlimited.trans())); - this.config.set("SizeZ", size_z); + this.config.set("SizeZ", world_limits.get("default").size_z); this.config.setInlineComments("SizeZ", List.of(Translation.Config_Comment_SizeZ.trans() + Translation.Config_Comment_NegativeOneUnlimited.trans())); - this.config.set("Amount", amount); + this.config.set("Amount", world_limits.get("default").amount); this.config.setInlineComments("Amount", List.of(Translation.Config_Comment_Amount.trans() + Translation.Config_Comment_NegativeOneUnlimited.trans())); - this.config.set("Depth", depth); + this.config.set("Depth", world_limits.get("default").depth); this.config.setInlineComments("Depth", List.of(Translation.Config_Comment_Depth.trans() + Translation.Config_Comment_ZeroDisabled.trans() + Translation.Config_Comment_NegativeOneUnlimited.trans())); - this.config.set("Vert", vert); + this.config.set("Vert", world_limits.get("default").vert); this.config.setInlineComments("Vert", List.of(Translation.Config_Comment_Vert.trans())); this.config.set("Price", price); this.config.setInlineComments("Price", List.of(Translation.Config_Comment_Price.trans())); @@ -266,10 +269,50 @@ private void saveAll() { this.config.set("Refund", refund); this.config.setInlineComments("Refund", List.of(Translation.Config_Comment_Refund.trans())); + this.config.set("WorldSettings", getWorldSettings()); + try { this.config.save(this.file_path); } catch (Exception e) { XLogger.err("Failed to save group limit file: " + this.file_path.getName()); } } + + public YamlConfiguration getWorldSettings() { + YamlConfiguration section = new YamlConfiguration(); + if (world_limits.size() <= 1) { + return WorldSetting.getDefaultList(); + } + for (Map.Entry entry : world_limits.entrySet()) { + if (entry.getKey().equals("default")) { + continue; + } + section.set(entry.getKey(), entry.getValue().getYaml()); + } + return section; + } + + public void checkRules() { + if (getPrice() < 0.0) { + XLogger.err(Translation.Config_Check_GroupPriceError, this.file_path.getName()); + setPrice(10.0); + } + if (getRefundRatio() < 0.0 || getRefundRatio() > 1.0) { + XLogger.err(Translation.Config_Check_GroupRefundError, this.file_path.getName()); + setRefundRatio(0.85); + } + for (WorldSetting w : world_limits.values()) { + w.checkRules(); + } + } + + public List getWorldBlackList() { + List list = new ArrayList<>(); + for (Map.Entry entry : world_limits.entrySet()) { + if (!entry.getValue().allow) { + list.add(entry.getKey()); + } + } + return list; + } } diff --git a/core/src/main/java/cn/lunadeer/dominion/managers/WorldSetting.java b/core/src/main/java/cn/lunadeer/dominion/managers/WorldSetting.java new file mode 100644 index 00000000..0c06dcc2 --- /dev/null +++ b/core/src/main/java/cn/lunadeer/dominion/managers/WorldSetting.java @@ -0,0 +1,103 @@ +package cn.lunadeer.dominion.managers; + +import cn.lunadeer.minecraftpluginutils.XLogger; +import org.bukkit.configuration.ConfigurationSection; +import org.bukkit.configuration.file.YamlConfiguration; + +import java.util.Map; + +public class WorldSetting { + public Integer min_y; + public Integer max_y; + public Integer size_x; + public Integer size_y; + public Integer size_z; + public Integer amount; + public Integer depth; + public Boolean vert; + public Boolean allow = true; + private final String sourceName; + + /** + * 生成默认设置 + * + * @return 设置内容 + */ + public static YamlConfiguration getDefaultList() { + YamlConfiguration section = new YamlConfiguration(); + section.set("some_world_name.MinY", -64); + section.set("some_world_name.MaxY", 320); + section.set("some_world_name.SizeX", 128); + section.set("some_world_name.SizeY", 64); + section.set("some_world_name.SizeZ", 128); + section.set("some_world_name.Amount", 10); + section.set("some_world_name.Depth", 3); + section.set("some_world_name.Vert", false); + section.set("some_world_name.Allow", false); + return section; + } + + public WorldSetting(String sourceName) { + this.sourceName = sourceName; + } + + public static Map load(String sourceName, ConfigurationSection worldSettings) { + Map world_limits = new java.util.HashMap<>(); + for (String worldName : worldSettings.getKeys(false)) { + WorldSetting setting = new WorldSetting(sourceName); + setting.min_y = worldSettings.getInt(worldName + ".MinY", -64); + setting.max_y = worldSettings.getInt(worldName + ".MaxY", 320); + setting.size_x = worldSettings.getInt(worldName + ".SizeX", 128); + setting.size_y = worldSettings.getInt(worldName + ".SizeY", 64); + setting.size_z = worldSettings.getInt(worldName + ".SizeZ", 128); + setting.amount = worldSettings.getInt(worldName + ".Amount", 10); + setting.depth = worldSettings.getInt(worldName + ".Depth", 3); + setting.vert = worldSettings.getBoolean(worldName + ".Vert", false); + setting.allow = worldSettings.getBoolean(worldName + ".Allow", false); + world_limits.put(worldName, setting); + } + return world_limits; + } + + public YamlConfiguration getYaml() { + YamlConfiguration section = new YamlConfiguration(); + section.set("MinY", min_y); + section.set("MaxY", max_y); + section.set("SizeX", size_x); + section.set("SizeY", size_y); + section.set("SizeZ", size_z); + section.set("Amount", amount); + section.set("Depth", depth); + section.set("Vert", vert); + section.set("Allow", allow); + return section; + } + + public void checkRules() { + if (min_y > max_y) { + XLogger.err(Translation.Config_Check_GroupMinYError, sourceName); + min_y = -64; + max_y = 320; + } + if (size_x <= 4 && size_x != -1) { + XLogger.err(Translation.Config_Check_GroupSizeXError, sourceName); + size_x = 128; + } + if (size_y <= 4 && size_y != -1) { + XLogger.err(Translation.Config_Check_GroupSizeYError, sourceName); + size_y = 64; + } + if (size_z <= 4 && size_z != -1) { + XLogger.err(Translation.Config_Check_GroupSizeZError, sourceName); + size_z = 128; + } + if (amount <= 0 && amount != -1) { + XLogger.err(Translation.Config_Check_GroupAmountError, sourceName); + amount = 10; + } + if (depth < 0 && depth != -1) { + XLogger.err(Translation.Config_Check_GroupDepthError, sourceName); + depth = 3; + } + } +} diff --git a/core/src/main/resources/config.yml b/core/src/main/resources/config.yml index 81d3c3e0..7ba57c0b 100644 --- a/core/src/main/resources/config.yml +++ b/core/src/main/resources/config.yml @@ -21,6 +21,17 @@ Limit: Depth: 3 Vert: false OpByPass: true + WorldSettings: + some_world_name: + MinY: -64 + MaxY: 320 + SizeX: 128 + SizeY: 64 + SizeZ: 128 + Amount: 10 + Depth: 3 + Vert: false + Allow: false Teleport: Enable: true diff --git a/core/src/main/resources/groups/sponsor.yml b/core/src/main/resources/groups/sponsor.yml index 2e2dc45f..b98c09d1 100644 --- a/core/src/main/resources/groups/sponsor.yml +++ b/core/src/main/resources/groups/sponsor.yml @@ -8,4 +8,15 @@ Depth: 3 Vert: false Price: 10.0 OnlyXZ: false -Refund: 0.85 \ No newline at end of file +Refund: 0.85 +WorldSettings: + some_world_name: + MinY: -64 + MaxY: 320 + SizeX: 128 + SizeY: 64 + SizeZ: 128 + Amount: 10 + Depth: 3 + Vert: false + Allow: false From 989cad0dd8931254a0431e8528a95359d601572d Mon Sep 17 00:00:00 2001 From: zhangyuheng Date: Fri, 6 Sep 2024 17:08:53 +0800 Subject: [PATCH 4/7] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E4=BA=86=E5=8D=95?= =?UTF-8?q?=E7=8B=AC=E5=AF=B9=E4=B8=96=E7=95=8C=E8=AE=BE=E7=BD=AE=E5=9C=88?= =?UTF-8?q?=E5=9C=B0=E8=A7=84=E5=88=99=E5=8A=9F=E8=83=BD=20#10?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dominion/managers/ConfigManager.java | 1 + .../dominion/managers/GroupLimit.java | 1 + .../dominion/managers/Translation.java | 36 ++++++------------- docs/zh-cn/operator/config.md | 26 ++++++++++---- docs/zh-cn/operator/privilege.md | 9 ++++- 5 files changed, 39 insertions(+), 34 deletions(-) diff --git a/core/src/main/java/cn/lunadeer/dominion/managers/ConfigManager.java b/core/src/main/java/cn/lunadeer/dominion/managers/ConfigManager.java index 2f967023..2fdff7a8 100644 --- a/core/src/main/java/cn/lunadeer/dominion/managers/ConfigManager.java +++ b/core/src/main/java/cn/lunadeer/dominion/managers/ConfigManager.java @@ -133,6 +133,7 @@ public void saveAll() { _file.set("Limit.OpByPass", _limit_op_bypass); _file.setInlineComments("Limit.OpByPass", List.of(Translation.Config_Comment_OpBypass.trans())); _file.set("Limit.WorldSettings", groupLimits.get("default").getWorldSettings()); + _file.setInlineComments("Limit.WorldSettings", List.of(Translation.Config_Comment_WorldSettings.trans())); _file.set("Teleport.Enable", _tp_enable); _file.set("Teleport.Delay", _tp_delay); diff --git a/core/src/main/java/cn/lunadeer/dominion/managers/GroupLimit.java b/core/src/main/java/cn/lunadeer/dominion/managers/GroupLimit.java index 6b9199af..9049450e 100644 --- a/core/src/main/java/cn/lunadeer/dominion/managers/GroupLimit.java +++ b/core/src/main/java/cn/lunadeer/dominion/managers/GroupLimit.java @@ -270,6 +270,7 @@ private void saveAll() { this.config.setInlineComments("Refund", List.of(Translation.Config_Comment_Refund.trans())); this.config.set("WorldSettings", getWorldSettings()); + this.config.setInlineComments("WorldSettings", List.of(Translation.Config_Comment_WorldSettings.trans())); try { this.config.save(this.file_path); diff --git a/core/src/main/java/cn/lunadeer/dominion/managers/Translation.java b/core/src/main/java/cn/lunadeer/dominion/managers/Translation.java index b5464ae3..7812a8b8 100644 --- a/core/src/main/java/cn/lunadeer/dominion/managers/Translation.java +++ b/core/src/main/java/cn/lunadeer/dominion/managers/Translation.java @@ -833,39 +833,21 @@ public class Translation extends Localization { public static i18n Config_Check_AutoCleanAfterDaysError; @i18nField(defaultValue = "工具名称设置错误,已重置为 ARROW") public static i18n Config_Check_ToolNameError; - @i18nField(defaultValue = "Limit.SizeX 尺寸不能小于 4,已重置为 128") - public static i18n Config_Check_LimitSizeXError; - @i18nField(defaultValue = "Limit.SizeY 尺寸不能小于 4,已重置为 64") - public static i18n Config_Check_LimitSizeYError; - @i18nField(defaultValue = "Limit.SizeZ 尺寸不能小于 4,已重置为 128") - public static i18n Config_Check_LimitSizeZError; - @i18nField(defaultValue = "Limit.MinY 不能大于或等于 Limit.MaxY,已重置为 -64 320") - public static i18n Config_Check_LimitMinYError; - @i18nField(defaultValue = "Economy.Refund 设置不合法,已重置为 0.85") - public static i18n Config_Check_RefundError; - @i18nField(defaultValue = "Economy.Price 设置不合法,已重置为 10.0") - public static i18n Config_Check_PriceError; - @i18nField(defaultValue = "启用 Limit.Vert 时 Limit.SizeY 不能小于 Limit.MaxY - Limit.MinY,已自动调整为 %d") - public static i18n Config_Check_LimitSizeYAutoAdjust; - @i18nField(defaultValue = "Limit.Amount 设置不合法,已重置为 10") - public static i18n Config_Check_AmountError; - @i18nField(defaultValue = "Limit.Depth 设置不合法,已重置为 3") - public static i18n Config_Check_DepthError; - @i18nField(defaultValue = "权限组 %s 的 MinY 不能大于等于 MaxY,已重置为 -64 和 320") + @i18nField(defaultValue = "%s 的 MinY 不能大于等于 MaxY,已重置为 -64 和 320") public static i18n Config_Check_GroupMinYError; - @i18nField(defaultValue = "权限组 %s 的 SizeX 设置过小,已重置为 128") + @i18nField(defaultValue = "%s 的 SizeX 设置过小,已重置为 128") public static i18n Config_Check_GroupSizeXError; - @i18nField(defaultValue = "权限组 %s 的 SizeY 设置过小,已重置为 64") + @i18nField(defaultValue = "%s 的 SizeY 设置过小,已重置为 64") public static i18n Config_Check_GroupSizeYError; - @i18nField(defaultValue = "权限组 %s 的 SizeZ 设置过小,已重置为 128") + @i18nField(defaultValue = "%s 的 SizeZ 设置过小,已重置为 128") public static i18n Config_Check_GroupSizeZError; - @i18nField(defaultValue = "权限组 %s 的 Amount 设置不合法,已重置为 10") + @i18nField(defaultValue = "%s 的 Amount 设置不合法,已重置为 10") public static i18n Config_Check_GroupAmountError; - @i18nField(defaultValue = "权限组 %s 的 Depth 设置不合法,已重置为 3") + @i18nField(defaultValue = "%s 的 Depth 设置不合法,已重置为 3") public static i18n Config_Check_GroupDepthError; - @i18nField(defaultValue = "权限组 %s 的 Price 设置不合法,已重置为 10.0") + @i18nField(defaultValue = "%s 的 Price 设置不合法,已重置为 10.0") public static i18n Config_Check_GroupPriceError; - @i18nField(defaultValue = "权限组 %s 的 Refund 设置不合法,已重置为 0.85") + @i18nField(defaultValue = "%s 的 Refund 设置不合法,已重置为 0.85") public static i18n Config_Check_GroupRefundError; @i18nField(defaultValue = "读取权限配置失败:%s") public static i18n Config_Check_LoadFlagError; @@ -906,6 +888,8 @@ public class Translation extends Localization { public static i18n Config_Comment_Vert; @i18nField(defaultValue = "是否允许OP无视领地限制") public static i18n Config_Comment_OpBypass; + @i18nField(defaultValue = "单独设置某个世界的圈地规则(如不设置则使用以上规则)") + public static i18n Config_Comment_WorldSettings; @i18nField(defaultValue = "传送延迟 秒") public static i18n Config_Comment_TpDelay; @i18nField(defaultValue = "传送冷却 秒") diff --git a/docs/zh-cn/operator/config.md b/docs/zh-cn/operator/config.md index 244ecae0..7a35d528 100644 --- a/docs/zh-cn/operator/config.md +++ b/docs/zh-cn/operator/config.md @@ -27,9 +27,18 @@ Limit: Amount: 10 # 最大领地数量-1表示不限制 Depth: 3 # 子领地深度0表示不开启-1表示不限制 Vert: false # 是否自动延伸到 MaxY 和 MinY - WorldBlackList: # 不允许圈地的世界列表 - - some_world OpByPass: true # 是否允许OP无视领地限制 + WorldSettings: + some_world_name: + MinY: -64 + MaxY: 320 + SizeX: 128 + SizeY: 64 + SizeZ: 128 + Amount: 10 + Depth: 3 + Vert: false + Allow: false Teleport: Enable: true @@ -102,13 +111,16 @@ Timer: false # 性能测试计时器 - SpawnProtection:出生点半径保护,此半径范围内普通玩家无法创建领地 - MinY:领地的最小Y坐标 - MaxY:领地的最大Y坐标 -- SizeX:X方向最大长度 -- SizeY:Y方向最大长度 -- SizeZ:Z方向最大长度 -- Amount:每个玩家拥有的最大领地数量 +- SizeX:X方向最大长度 1表示不限制 +- SizeY:Y方向最大长度 1表示不限制 +- SizeZ:Z方向最大长度 1表示不限制 +- Amount:每个玩家拥有的最大领地数量 1表示不限制 - Depth:子领地深度、0表示不允许子领地、 -1表示不限制 -- WorldBlackList:不允许创建领地的世界 - Vert:当设置为 `true` 时,玩家选择区域创建或者自动创建领地,会自动将Y向下向上延伸到MinY和MaxY。**同时也会根据 MinY 和 MaxY 的设置自动调整 SizeY 的配置保证数值逻辑一致。** +- WorldSettings:单独设置某个世界的圈地规则(如不设置则使用上述默认规则) + - Allow:是否允许在此世界圈地 + +> 您服务器世界的名称应该避免使用 `default` 这样的特殊单词,否则会导致不可预料的意外错误。 ### Teleport diff --git a/docs/zh-cn/operator/privilege.md b/docs/zh-cn/operator/privilege.md index 3f8567de..41de3e1d 100644 --- a/docs/zh-cn/operator/privilege.md +++ b/docs/zh-cn/operator/privilege.md @@ -11,7 +11,8 @@ 假设你现在想为赞助玩家提供优惠,打开 `plugins/Dominion/groups/sponsor.yml` 文件。修改里面的设置为你期望的数值,保存文件。 -假如你想再为 VIP 玩家提供更丰厚的优惠,你可以复制一份 `sponsor.yml` 重命名为 `vip.yml` ,然后编辑里面的数值。(这个文件的名称你可以自定义,但是请不要使用中文、特殊字符、空格等) +假如你想再为 VIP 玩家提供更丰厚的优惠,你可以复制一份 `sponsor.yml` 重命名为 `vip.yml` +,然后编辑里面的数值。(这个文件的名称你可以自定义,但是请不要使用中文、特殊字符、空格等) ## 加载配置 @@ -27,3 +28,9 @@ 最后保存 LuckPerms 配置,即可生效。 +## 注意事项 + +`groups` 中的 `WorldSettings` 与 `config.yml` 中的是独立的。 +例如:你不希望任何玩家在下届顶层圈地(包括 `sponsor`),你已经在 `config.yml` 中设置了下届的 `MinY` 和 `MaxY`。 +如果你不在 `sponsor.yml` 中进行同样的设置的话,那么 `sponsor` 玩家就不会收到这个限制。 + From 04c3036f2cd7eb4f34fd128cda3dc680e4ef94e6 Mon Sep 17 00:00:00 2001 From: zhangyuheng Date: Fri, 6 Sep 2024 17:12:12 +0800 Subject: [PATCH 5/7] =?UTF-8?q?=E8=A1=A5=E5=85=85=20zh-cn=20=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E7=BF=BB=E8=AF=91=E5=AD=97=E6=AE=B5=20#10?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle.kts | 2 +- core/src/main/resources/languages/zh-cn.yml | 10 ++++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index e2bb0327..98c566c9 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -4,7 +4,7 @@ plugins { } group = "cn.lunadeer" -version = "2.6.0-beta" +version = "2.6.1-beta" java { toolchain.languageVersion.set(JavaLanguageVersion.of(21)) diff --git a/core/src/main/resources/languages/zh-cn.yml b/core/src/main/resources/languages/zh-cn.yml index 01f50ccf..719f92f5 100644 --- a/core/src/main/resources/languages/zh-cn.yml +++ b/core/src/main/resources/languages/zh-cn.yml @@ -4,8 +4,7 @@ Commands: CreateDominionUsage: '用法: /dominion create <领地名称>' CreateSelectPointsFirst: 请先使用工具选择领地的对角线两点,或使用 /dominion auto_create <领地名称> 创建自动领地 CreateSubDominionUsage: '用法: /dominion create_sub <子领地名称> [父领地名称]' - CreateSubSelectPointsFirst: 请先使用工具选择子领地的对角线两点,或使用 /dominion auto_create_sub <子领地名称> - [父领地名称] 创建自动子领地 + CreateSubSelectPointsFirst: 请先使用工具选择子领地的对角线两点,或使用 /dominion auto_create_sub <子领地名称> [父领地名称] 创建自动子领地 AutoCreateDominionUsage: '用法: /dominion auto_create <领地名称>' AutoCreateSubDominionUsage: '用法: /dominion auto_create_sub <子领地名称> [父领地名称]' AutoCreateDominionDisabled: 自动创建领地功能已关闭 @@ -35,8 +34,7 @@ Commands: DominionAddMemberUsage: '用法: /dominion member add <领地名称> <玩家名称>' DominionSetFlagUsage: '用法: /dominion member set_flag <领地名称> <玩家名称> <权限名称> ' DominionRemoveMemberUsage: '用法: /dominion member remove <领地名称> <玩家名称>' - DominionApplyTemplateUsage: '用法: /dominion member apply_template <领地名称> <玩家名称> - <模板名称>' + DominionApplyTemplateUsage: '用法: /dominion member apply_template <领地名称> <玩家名称> <模板名称>' MemberUsage: '用法: /dominion member ' PageOptional: 页码(可选) ArgumentsNotEnough: 参数不足 @@ -432,8 +430,7 @@ Config: LimitMinYError: Limit.MinY 不能大于或等于 Limit.MaxY,已重置为 -64 320 RefundError: Economy.Refund 设置不合法,已重置为 0.85 PriceError: Economy.Price 设置不合法,已重置为 10.0 - LimitSizeYAutoAdjust: 启用 Limit.Vert 时 Limit.SizeY 不能小于 Limit.MaxY - Limit.MinY,已自动调整为 - %d + LimitSizeYAutoAdjust: 启用 Limit.Vert 时 Limit.SizeY 不能小于 Limit.MaxY - Limit.MinY,已自动调整为 %d AmountError: Limit.Amount 设置不合法,已重置为 10 DepthError: Limit.Depth 设置不合法,已重置为 3 GroupMinYError: 权限组 %s 的 MinY 不能大于等于 MaxY,已重置为 -64 和 320 @@ -487,6 +484,7 @@ Config: GroupLine6: 一些特殊优惠,例如更少的圈地价格、更大的领地等,你可以在 GroupLine7: 这里配置。详细说明参阅以下链接: GroupLine8DocumentAddress: '> https://dominion.lunadeer.cn/%s/operator/privilege.html' + WorldSettings: 单独设置某个世界的圈地规则(如不设置则使用以上规则) Flags: admin: DisplayName: 管理员 From 18632f90945fe615495463c41b0043ef094dd7a7 Mon Sep 17 00:00:00 2001 From: zhangyuheng Date: Fri, 6 Sep 2024 17:25:49 +0800 Subject: [PATCH 6/7] =?UTF-8?q?=E5=8D=AB=E6=98=9F=E5=9C=B0=E5=9B=BE?= =?UTF-8?q?=E5=B1=95=E7=A4=BA=E6=96=B0=E5=A2=9E=E6=89=80=E6=9C=89=E4=BA=BA?= =?UTF-8?q?=E5=90=8D=E7=A7=B0=20#12?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle.kts | 2 +- .../java/cn/lunadeer/dominion/managers/Translation.java | 2 ++ .../cn/lunadeer/dominion/utils/map/BlueMapConnect.java | 7 +++++++ .../java/cn/lunadeer/dominion/utils/map/DynmapConnect.java | 7 ++++++- core/src/main/resources/languages/zh-cn.yml | 1 + 5 files changed, 17 insertions(+), 2 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 98c566c9..1bf59a33 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -4,7 +4,7 @@ plugins { } group = "cn.lunadeer" -version = "2.6.1-beta" +version = "2.6.2-beta" java { toolchain.languageVersion.set(JavaLanguageVersion.of(21)) diff --git a/core/src/main/java/cn/lunadeer/dominion/managers/Translation.java b/core/src/main/java/cn/lunadeer/dominion/managers/Translation.java index 7812a8b8..2e872de7 100644 --- a/core/src/main/java/cn/lunadeer/dominion/managers/Translation.java +++ b/core/src/main/java/cn/lunadeer/dominion/managers/Translation.java @@ -504,6 +504,8 @@ public class Translation extends Localization { public static i18n Messages_PlaceholderAPIRegisterSuccess; @i18nField(defaultValue = "共加载了 %d 个领地组") public static i18n Messages_LoadedGroupAmount; + @i18nField(defaultValue = "
%s
所有人:%s
") + public static i18n Messages_MapInfoDetail; @i18nField(defaultValue = "开始自动清理长时间未登录玩家领地数据") public static i18n Messages_AutoCleanStart; diff --git a/core/src/main/java/cn/lunadeer/dominion/utils/map/BlueMapConnect.java b/core/src/main/java/cn/lunadeer/dominion/utils/map/BlueMapConnect.java index 8ea16c69..d10c6afe 100644 --- a/core/src/main/java/cn/lunadeer/dominion/utils/map/BlueMapConnect.java +++ b/core/src/main/java/cn/lunadeer/dominion/utils/map/BlueMapConnect.java @@ -2,6 +2,7 @@ import cn.lunadeer.dominion.Cache; import cn.lunadeer.dominion.dtos.DominionDTO; +import cn.lunadeer.dominion.dtos.PlayerDTO; import cn.lunadeer.dominion.managers.Translation; import cn.lunadeer.minecraftpluginutils.Scheduler; import cn.lunadeer.minecraftpluginutils.XLogger; @@ -37,6 +38,11 @@ public static void render() { .build(); for (DominionDTO dominion : d.getValue()) { + PlayerDTO p = PlayerDTO.select(dominion.getOwner()); + if (p == null) { + continue; + } + Collection vectors = new ArrayList<>(); vectors.add(new Vector2d(dominion.getX1() + 0.001, dominion.getZ1() + 0.001)); vectors.add(new Vector2d(dominion.getX2() - 0.001, dominion.getZ1() + 0.001)); @@ -55,6 +61,7 @@ public static void render() { Color fill = new Color(r, g, b, 0.2F); ExtrudeMarker marker = ExtrudeMarker.builder() .label(dominion.getName()) + .detail(String.format(Translation.Messages_MapInfoDetail.trans(), dominion.getName(), p.getLastKnownName())) .position(x, y, z) .shape(shape, dominion.getY1() + 0.001f, dominion.getY2() - 0.001f) .lineColor(line) diff --git a/core/src/main/java/cn/lunadeer/dominion/utils/map/DynmapConnect.java b/core/src/main/java/cn/lunadeer/dominion/utils/map/DynmapConnect.java index c3b0e576..da0512e2 100644 --- a/core/src/main/java/cn/lunadeer/dominion/utils/map/DynmapConnect.java +++ b/core/src/main/java/cn/lunadeer/dominion/utils/map/DynmapConnect.java @@ -1,6 +1,7 @@ package cn.lunadeer.dominion.utils.map; import cn.lunadeer.dominion.dtos.DominionDTO; +import cn.lunadeer.dominion.dtos.PlayerDTO; import cn.lunadeer.dominion.managers.Translation; import cn.lunadeer.minecraftpluginutils.Scheduler; import cn.lunadeer.minecraftpluginutils.XLogger; @@ -40,7 +41,11 @@ public void apiEnabled(DynmapCommonAPI dynmapCommonAPI) { } private void setDominionMarker(DominionDTO dominion) { - String nameLabel = "
" + dominion.getName() + "
"; + PlayerDTO p = PlayerDTO.select(dominion.getOwner()); + if (p == null) { + return; + } + String nameLabel = String.format(Translation.Messages_MapInfoDetail.trans(), dominion.getName(), p.getLastKnownName()); double[] xx = {dominion.getX1(), dominion.getX2()}; double[] zz = {dominion.getZ1(), dominion.getZ2()}; if (dominion.getWorld() == null) { diff --git a/core/src/main/resources/languages/zh-cn.yml b/core/src/main/resources/languages/zh-cn.yml index 719f92f5..19ba4367 100644 --- a/core/src/main/resources/languages/zh-cn.yml +++ b/core/src/main/resources/languages/zh-cn.yml @@ -250,6 +250,7 @@ Messages: AutoCleanStart: 开始自动清理长时间未登录玩家领地数据 AutoCleanPlayer: 已清理玩家 %s 的领地数据 AutoCleanEnd: 自动清理完成 + MapInfoDetail:
%s
所有人:%s
TUI: NotDominionOwnerOrAdminForPage: 你不是领地 %s 的拥有者或管理员,无权访问此页面 CommandHelp: From e158066d8865d3cf6da57fecde85df8361af19e6 Mon Sep 17 00:00:00 2001 From: zhangyuheng Date: Fri, 6 Sep 2024 17:31:04 +0800 Subject: [PATCH 7/7] =?UTF-8?q?=E8=A1=A5=E5=85=85=E4=BA=86=E5=85=B3?= =?UTF-8?q?=E4=BA=8E=20Residence=20=E9=A2=86=E5=9C=B0=E8=BF=81=E7=A7=BB?= =?UTF-8?q?=E7=9A=84=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/zh-cn/migration-residence.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/docs/zh-cn/migration-residence.md b/docs/zh-cn/migration-residence.md index e69de29b..bf0ba0eb 100644 --- a/docs/zh-cn/migration-residence.md +++ b/docs/zh-cn/migration-residence.md @@ -0,0 +1,20 @@ +# 将领地从 Residence 迁移到 Dominion + +## 注意事项 + +1. 迁移采取的“玩家自助”方案,即由玩家自行决定要迁移自己的哪些领地; +2. 目前支持迁移:领地、tp点、欢迎/离开提示消息、子领地; +3. 由于对权限的存储、索引方式不同,目前**不支持**对权限进行迁移; +4. 迁移领地**不会产生二次消费**; + +## 服主要做的事 + +1. 删除 Residence 插件,保留其数据文件 `plugins/Residence`; +2. 在 Dominion 配置中将 `ResidenceMigration` 打开(设置为true); + +## 玩家要做的事 + +1. 上线,打开 Dominion 菜单 `/dom`,点击`【迁移数据】`: +2. 选择要迁移的 Residence 领地,点击前面的`【迁移】`; +3. 完成后即可前往领地列表进一步配置领地的权限等信息: +