mirror of
https://github.com/ColdeZhang/Dominion.git
synced 2025-02-04 22:49:41 +08:00
实现了单独配置世界圈地规则的功能
This commit is contained in:
parent
1f3fb77b49
commit
40d4ede3fc
@ -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))
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
@ -103,6 +103,14 @@ public class DominionController {
|
||||
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()));
|
||||
|
@ -5,6 +5,7 @@ import cn.lunadeer.dominion.dtos.Flag;
|
||||
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 class ConfigManager {
|
||||
_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 class ConfigManager {
|
||||
_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));
|
||||
ConfigurationSection worldSettings = _file.getConfigurationSection("Limit.WorldSettings");
|
||||
if (worldSettings != null) {
|
||||
defaultGroup.addWorldLimits(WorldSetting.load("config.yml", worldSettings));
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
groupLimits.putAll(GroupLimit.loadGroups(_plugin));
|
||||
|
||||
checkRules();
|
||||
saveAll(); // 回写文件 防止文件中的数据不完整
|
||||
Flag.loadFromFile(); // 加载 Flag 配置
|
||||
}
|
||||
@ -165,24 +114,25 @@ public class ConfigManager {
|
||||
_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 class ConfigManager {
|
||||
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 class ConfigManager {
|
||||
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 class ConfigManager {
|
||||
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 class ConfigManager {
|
||||
}
|
||||
|
||||
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 class ConfigManager {
|
||||
public void setAutoCreateRadius(Integer radius) {
|
||||
_auto_create_radius = radius;
|
||||
_file.set("AutoCreateRadius", radius);
|
||||
_plugin.saveConfig();
|
||||
}
|
||||
|
||||
public Boolean getBlueMap() {
|
||||
@ -346,75 +269,36 @@ public class ConfigManager {
|
||||
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<String> 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 class ConfigManager {
|
||||
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 class ConfigManager {
|
||||
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 class ConfigManager {
|
||||
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 class ConfigManager {
|
||||
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<String> getFlyPermissionNodes() {
|
||||
return _fly_permission_nodes;
|
||||
}
|
||||
|
||||
public void setFlyPermissionNodes(List<String> 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 class ConfigManager {
|
||||
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;
|
||||
|
@ -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<String, WorldSetting> 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);
|
||||
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_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);
|
||||
}
|
||||
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 class GroupLimit {
|
||||
}
|
||||
|
||||
|
||||
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<String, WorldSetting> limits) {
|
||||
world_limits.putAll(limits);
|
||||
}
|
||||
|
||||
|
||||
public static Map<String, GroupLimit> loadGroups(JavaPlugin plugin) {
|
||||
Map<String, GroupLimit> groups = new HashMap<>();
|
||||
File root = plugin.getDataFolder();
|
||||
@ -233,7 +236,7 @@ public class GroupLimit {
|
||||
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 @@ public class GroupLimit {
|
||||
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 @@ public class GroupLimit {
|
||||
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<String, WorldSetting> 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<String> getWorldBlackList() {
|
||||
List<String> list = new ArrayList<>();
|
||||
for (Map.Entry<String, WorldSetting> entry : world_limits.entrySet()) {
|
||||
if (!entry.getValue().allow) {
|
||||
list.add(entry.getKey());
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
@ -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<String, WorldSetting> load(String sourceName, ConfigurationSection worldSettings) {
|
||||
Map<String, WorldSetting> 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;
|
||||
}
|
||||
}
|
||||
}
|
@ -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
|
||||
|
@ -8,4 +8,15 @@ Depth: 3
|
||||
Vert: false
|
||||
Price: 10.0
|
||||
OnlyXZ: false
|
||||
Refund: 0.85
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user