1
0
mirror of https://e.coding.net/circlecloud/Residence.git synced 2025-11-24 21:46:16 +00:00

add config load tip and format config file...

Signed-off-by: 502647092 <jtb1@163.com>
This commit is contained in:
502647092
2015-09-30 21:39:40 +08:00
parent a898be349c
commit d23eb1c154
4 changed files with 162 additions and 145 deletions

View File

@@ -343,8 +343,8 @@ public class ResidenceMain extends JavaPlugin {
@Override @Override
public void onDisable() { public void onDisable() {
taskmanager.cancelall();
if (this.init) { if (this.init) {
taskmanager.cancelall();
try { try {
this.saveYml(); this.saveYml();
this.backup.backup(); this.backup.backup();

View File

@@ -213,6 +213,7 @@ public class ConfigManager {
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
private void load(final FileConfiguration config) { private void load(final FileConfiguration config) {
try {
defaultGroup = config.getString("Global.DefaultGroup", "default").toLowerCase(); defaultGroup = config.getString("Global.DefaultGroup", "default").toLowerCase();
adminsOnly = config.getBoolean("Global.AdminOnlyCommands", false); adminsOnly = config.getBoolean("Global.AdminOnlyCommands", false);
useLeases = config.getBoolean("Global.UseLeaseSystem", false); useLeases = config.getBoolean("Global.UseLeaseSystem", false);
@@ -246,6 +247,9 @@ public class ConfigManager {
customContainers = config.getIntegerList("Global.CustomContainers"); customContainers = config.getIntegerList("Global.CustomContainers");
customBothClick = config.getIntegerList("Global.CustomBothClick"); customBothClick = config.getIntegerList("Global.CustomBothClick");
customRightClick = config.getIntegerList("Global.CustomRightClick"); customRightClick = config.getIntegerList("Global.CustomRightClick");
} catch (final Exception e) {
throw new RuntimeException("领地配置文件载入错误...", e);
}
final ConfigurationSection node = config.getConfigurationSection("Global.GroupDefault"); final ConfigurationSection node = config.getConfigurationSection("Global.GroupDefault");
if (!plugin.is1_8()) { if (!plugin.is1_8()) {

View File

@@ -46,11 +46,13 @@ public class WorldFlagManager {
public FlagPermissions getPerms(String world) { public FlagPermissions getPerms(String world) {
world = world.toLowerCase(); world = world.toLowerCase();
final FlagPermissions list = worldperms.get(world); final FlagPermissions list = worldperms.get(world);
if (list == null) if (list == null) {
if (globaldefaults == null) if (globaldefaults == null) {
return new FlagPermissions(); return new FlagPermissions();
else } else {
return globaldefaults; return globaldefaults;
}
}
return list; return list;
} }
@@ -58,16 +60,19 @@ public class WorldFlagManager {
world = world.toLowerCase(); world = world.toLowerCase();
group = group.toLowerCase(); group = group.toLowerCase();
final Map<String, FlagPermissions> groupworldperms = groupperms.get(group); final Map<String, FlagPermissions> groupworldperms = groupperms.get(group);
if (groupworldperms == null) if (groupworldperms == null) {
return this.getPerms(world); return this.getPerms(world);
}
FlagPermissions list = groupworldperms.get(world); FlagPermissions list = groupworldperms.get(world);
if (list == null) { if (list == null) {
list = groupworldperms.get("global." + world); list = groupworldperms.get("global." + world);
if (list == null) if (list == null) {
list = groupworldperms.get("global"); list = groupworldperms.get("global");
if (list == null) }
if (list == null) {
return this.getPerms(world); return this.getPerms(world);
} }
}
return list; return list;
} }
@@ -75,16 +80,20 @@ public class WorldFlagManager {
try { try {
Set<String> keys = config.getConfigurationSection("Global.Flags").getKeys(false); Set<String> keys = config.getConfigurationSection("Global.Flags").getKeys(false);
if (keys != null) if (keys != null) {
for (final String key : keys) for (final String key : keys) {
if (key.equalsIgnoreCase("Global")) if (key.equalsIgnoreCase("Global")) {
globaldefaults = FlagPermissions.parseFromConfigNode(key, config.getConfigurationSection("Global.Flags")); globaldefaults = FlagPermissions.parseFromConfigNode(key, config.getConfigurationSection("Global.Flags"));
else } else {
worldperms.put(key.toLowerCase(), FlagPermissions.parseFromConfigNode(key, config.getConfigurationSection("Global.Flags"))); worldperms.put(key.toLowerCase(), FlagPermissions.parseFromConfigNode(key, config.getConfigurationSection("Global.Flags")));
for (final Entry<String, FlagPermissions> entry : worldperms.entrySet()) }
}
}
for (final Entry<String, FlagPermissions> entry : worldperms.entrySet()) {
entry.getValue().setParent(globaldefaults); entry.getValue().setParent(globaldefaults);
}
keys = config.getConfigurationSection("Groups").getKeys(false); keys = config.getConfigurationSection("Groups").getKeys(false);
if (keys != null) if (keys != null) {
for (final String key : keys) { for (final String key : keys) {
final ConfigurationSection worldkeylist = config.getConfigurationSection("Groups." + key + ".Flags.World"); final ConfigurationSection worldkeylist = config.getConfigurationSection("Groups." + key + ".Flags.World");
if (worldkeylist != null) { if (worldkeylist != null) {
@@ -101,24 +110,28 @@ public class WorldFlagManager {
list.setParent(worldperm.getValue()); list.setParent(worldperm.getValue());
perms.put("global." + worldperm.getKey().toLowerCase(), list); perms.put("global." + worldperm.getKey().toLowerCase(), list);
} }
} else } else {
perms.put(wkey.toLowerCase(), list); perms.put(wkey.toLowerCase(), list);
} }
}
for (final Entry<String, FlagPermissions> entry : perms.entrySet()) { for (final Entry<String, FlagPermissions> entry : perms.entrySet()) {
final String wkey = entry.getKey(); final String wkey = entry.getKey();
final FlagPermissions list = entry.getValue(); final FlagPermissions list = entry.getValue();
if (!wkey.startsWith("global.")) { if (!wkey.startsWith("global.")) {
list.setParent(perms.get("global." + wkey)); list.setParent(perms.get("global." + wkey));
if (list.getParent() == null) if (list.getParent() == null) {
list.setParent(worldperms.get(wkey)); list.setParent(worldperms.get(wkey));
if (list.getParent() == null) }
if (list.getParent() == null) {
list.setParent(globaldefaults); list.setParent(globaldefaults);
} }
} }
}
groupperms.put(key.toLowerCase(), perms); groupperms.put(key.toLowerCase(), perms);
} }
} }
} }
}
} catch (final Exception ex) { } catch (final Exception ex) {
Logger.getLogger(WorldFlagManager.class.getName()).log(Level.SEVERE, null, ex); Logger.getLogger(WorldFlagManager.class.getName()).log(Level.SEVERE, null, ex);
} }

View File

@@ -250,7 +250,7 @@ Groups:
#玩家是否可以改变领地进出提示. #玩家是否可以改变领地进出提示.
CanChange: true CanChange: true
# 这个文本是当前用户组新建领地后的默认进入信息. # 这个文本是当前用户组新建领地后的默认进入信息.
# 消息留空将禁用. # 消息留空将禁用信息.
DefaultEnter: '欢迎 %player 来到 %owner 的领地 %residence.' DefaultEnter: '欢迎 %player 来到 %owner 的领地 %residence.'
# 这个文本是当前用户组新建领地后的默认离开信息. # 这个文本是当前用户组新建领地后的默认离开信息.
# 消息留空将禁用信息. # 消息留空将禁用信息.
@@ -301,7 +301,7 @@ Groups:
#default: #组名 #default: #组名
#build: false #build: false
# 这些Flag将应用于这个组, 当他们在领地之外时将会被使用. # 这些Flag将应用于这个组, 当他们在领地之外时将会被使用.
# 这些Flag将会覆盖上面的Flag, 均为全局选?钕? # 这些Flag将会覆盖上面的Flag, 均为全局选项.
World: World:
Global: # 这些Flag将会应用于所有世界. Global: # 这些Flag将会应用于所有世界.
#build: false #build: false