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 d0e811f..385c8e0 100644 --- a/core/src/main/java/cn/lunadeer/dominion/managers/ConfigManager.java +++ b/core/src/main/java/cn/lunadeer/dominion/managers/ConfigManager.java @@ -9,6 +9,7 @@ import org.bukkit.configuration.file.FileConfiguration; import java.io.File; import java.util.List; +import java.util.Map; public class ConfigManager { public ConfigManager(Dominion plugin) { @@ -502,20 +503,12 @@ public class ConfigManager { private Integer _auto_create_radius; - private Integer _limit_size_x; - private Integer _limit_size_y; - private Integer _limit_size_z; private Boolean _limit_op_bypass; private Boolean _blue_map; private Boolean _dynmap; private Integer _auto_clean_after_days; - private Integer _limit_min_y; - private Integer _limit_max_y; - private Integer _limit_amount; - private Integer _limit_depth; - private Boolean _limit_vert; - private List _world_black_list; + private Boolean _check_update; private Boolean _tp_enable; @@ -524,9 +517,7 @@ public class ConfigManager { private String _tool; private Boolean _economy_enable; - private Float _economy_price; - private Boolean _economy_only_xz; - private Float _economy_refund; + private List _fly_permission_nodes; private Boolean _residence_migration; private Integer _spawn_protection; @@ -534,4 +525,6 @@ public class ConfigManager { private Boolean _group_title_enable; private String _group_title_prefix; private String _group_title_suffix; + + private Map limits; } diff --git a/core/src/main/java/cn/lunadeer/dominion/managers/GroupLimit.java b/core/src/main/java/cn/lunadeer/dominion/managers/GroupLimit.java new file mode 100644 index 0000000..ece4f8d --- /dev/null +++ b/core/src/main/java/cn/lunadeer/dominion/managers/GroupLimit.java @@ -0,0 +1,214 @@ +package cn.lunadeer.dominion.managers; + +import cn.lunadeer.minecraftpluginutils.XLogger; +import org.bukkit.configuration.file.YamlConfiguration; +import org.bukkit.plugin.java.JavaPlugin; + +import java.io.File; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class GroupLimit { + private final JavaPlugin plugin; + 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 List world_black_list; + private Double price; + private Boolean only_xz; + private Double refund; + + public GroupLimit(JavaPlugin plugin, File filePath) { + this.plugin = plugin; + this.file_path = filePath; + } + + public Integer getLimitMinY() { + return min_y; + } + + public Integer getLimitMaxY() { + return max_y; + } + + public Integer getLimitSizeX() { + return size_x; + } + + public Integer getLimitSizeY() { + return size_y; + } + + public Integer getLimitSizeZ() { + return size_z; + } + + public Integer getLimitAmount() { + return amount; + } + + public Integer getLimitDepth() { + return depth; + } + + public Boolean getLimitVert() { + return vert; + } + + public List getWorldBlackList() { + return world_black_list; + } + + public Double getPrice() { + return price; + } + + public Boolean getPriceOnlyXZ() { + return only_xz; + } + + public Double getRefundRatio() { + return refund; + } + + public void setLimitMinY(Integer min_y) { + this.min_y = min_y; + } + + public void setLimitMaxY(Integer max_y) { + this.max_y = max_y; + } + + public void setLimitSizeX(Integer size_x) { + this.size_x = size_x; + } + + public void setLimitSizeY(Integer size_y) { + this.size_y = size_y; + } + + public void setLimitSizeZ(Integer size_z) { + this.size_z = size_z; + } + + public void setLimitAmount(Integer amount) { + this.amount = amount; + } + + public void setLimitDepth(Integer depth) { + this.depth = depth; + } + + public void setLimitVert(Boolean vert) { + this.vert = vert; + } + + public void setWorldBlackList(List world_black_list) { + this.world_black_list = world_black_list; + } + + public void setPrice(Double price) { + this.price = price; + } + + public void setPriceOnlyXZ(Boolean only_xz) { + this.only_xz = only_xz; + } + + public void setRefundRatio(Double refund) { + this.refund = refund; + } + + private static GroupLimit loadGroup(JavaPlugin plugin, File file) { + GroupLimit group = new GroupLimit(plugin, file); + YamlConfiguration config = YamlConfiguration.loadConfiguration(file); + group.setLimitMinY(config.getInt("MinY", -64)); + group.setLimitMaxY(config.getInt("MaxY", 320)); + if (group.getLimitMinY() >= group.getLimitMaxY()) { + XLogger.err("权限组 " + file.getName() + " 的 MinY 不能大于等于 MaxY,已重置为 -64 和 320"); + group.setLimitMinY(-64); + group.setLimitMaxY(320); + } + group.setLimitSizeX(config.getInt("SizeX", 128)); + if (group.getLimitSizeX() <= 4 && group.getLimitSizeX() != -1) { + XLogger.err("权限组 " + file.getName() + " 的 SizeX 设置过小,已重置为 128"); + group.setLimitSizeX(128); + } + group.setLimitSizeY(config.getInt("SizeY", 64)); + if (group.getLimitSizeY() <= 4 && group.getLimitSizeY() != -1) { + XLogger.err("权限组 " + file.getName() + " 的 SizeY 设置过小,已重置为 64"); + group.setLimitSizeY(64); + } + group.setLimitSizeZ(config.getInt("SizeZ", 128)); + if (group.getLimitSizeZ() <= 4 && group.getLimitSizeZ() != -1) { + XLogger.err("权限组 " + file.getName() + " 的 SizeZ 设置过小,已重置为 128"); + group.setLimitSizeZ(128); + } + group.setLimitAmount(config.getInt("Amount", 10)); + group.setLimitDepth(config.getInt("Depth", 3)); + group.setLimitVert(config.getBoolean("Vert", false)); + group.setWorldBlackList(config.getStringList("WorldBlackList")); + group.setPrice(config.getDouble("Price", 10.0)); + group.setPriceOnlyXZ(config.getBoolean("OnlyXZ", false)); + group.setRefundRatio(config.getDouble("Refund", 0.85)); + if (group.getRefundRatio() < 0.0 || group.getRefundRatio() > 1.0) { + XLogger.err("权限组 " + file.getName() + " 的 Refund 设置不合法,已重置为 0.85"); + group.setRefundRatio(0.85); + } + group.save(); + return group; + } + + private void save() { + YamlConfiguration config = new YamlConfiguration(); + config.set("MinY", min_y); + config.set("MaxY", max_y); + config.set("SizeX", size_x); + config.set("SizeY", size_y); + config.set("SizeZ", size_z); + config.set("Amount", amount); + config.set("Depth", depth); + config.set("Vert", vert); + config.set("WorldBlackList", world_black_list); + config.set("Price", price); + config.set("OnlyXZ", only_xz); + config.set("Refund", refund); + try { + config.save(file_path); + } catch (Exception e) { + XLogger.err("Failed to save group limit file: " + file_path.getName()); + } + } + + + public static Map loadGroups(JavaPlugin plugin) { + Map groups = new HashMap<>(); + File root = plugin.getDataFolder(); + File groupsDir = new File(root, "groups"); + if (!groupsDir.exists()) { + // 创建文件夹 并且从jar中复制文件 + plugin.saveResource("groups/sponsor.yml", true); + } + File[] files = groupsDir.listFiles(); + if (files == null) { + return groups; + } + for (File file : files) { + String name = file.getName(); + if (!name.endsWith(".yml")) { + continue; + } + String groupName = name.substring(0, name.length() - 4); + GroupLimit group = GroupLimit.loadGroup(plugin, file); + groups.put(groupName, group); + } + return groups; + } +} diff --git a/core/src/main/resources/groups/sponsor.yml b/core/src/main/resources/groups/sponsor.yml new file mode 100644 index 0000000..2a2af69 --- /dev/null +++ b/core/src/main/resources/groups/sponsor.yml @@ -0,0 +1,23 @@ +# >---------------------------------< +# | 圈地限制特殊权限组配置 | +# >---------------------------------< +# 此文件可以作为模板,你可以将此文件复制后重命名为你想要的权限组名,然后修改里面的配置 +# +# 如果你想给赞助玩家(或者VIP)一些特殊优惠,例如更少的圈地价格、更大的领地等,你可以在 groups 文件夹 +# 下创建一个新的文件,文件名为你想要的权限组名(例如:sponsor.yml)然后使用权限插件(例如:LuckPerms) +# 将玩家添加到此文件名对应的权限组中(如果文件名为 sponsor.yml,则权限组名为 sponsor,如果权限插件里 +# 面没有这个权限组那么需要你创建一个,然后将玩家添加进去) + + +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