diff --git a/src/main/java/pw/yumc/YumCore/config/FileConfig.java b/src/main/java/pw/yumc/YumCore/config/FileConfig.java index fd575c7..b21b85f 100644 --- a/src/main/java/pw/yumc/YumCore/config/FileConfig.java +++ b/src/main/java/pw/yumc/YumCore/config/FileConfig.java @@ -15,6 +15,7 @@ import java.util.logging.Logger; import org.apache.commons.lang.Validate; import org.bukkit.ChatColor; +import org.bukkit.Location; import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.plugin.Plugin; @@ -57,7 +58,6 @@ public class FileConfig extends AbstractConfig { public FileConfig(final File file) { Validate.notNull(file, "文件不能为 null"); this.file = file; - check(file); init(file); } @@ -70,7 +70,9 @@ public class FileConfig extends AbstractConfig { * 配置文件名称 */ public FileConfig(final String filename) { - this(new File(plugin.getDataFolder(), filename)); + this.file = new File(plugin.getDataFolder(), filename); + check(file); + init(file); } /** @@ -165,6 +167,31 @@ public class FileConfig extends AbstractConfig { return file.getName(); } + /** + * 获得Location + * + * @param key + * 键 + * @return {@link Location} + */ + public Location getLocation(final String key) { + return getLocation(key, null); + } + + /** + * 获得Location + * + * @param key + * 键 + * @param def + * 默认地点 + * @return {@link Location} + */ + public Location getLocation(final String path, final Location def) { + final Object val = get(path, def); + return val instanceof Location ? (Location) val : def; + } + /** * 获得已颜色转码的文本 * @@ -173,11 +200,7 @@ public class FileConfig extends AbstractConfig { * @return 颜色转码后的文本 */ public String getMessage(final String path) { - String message = this.getString(path); - if (message != null) { - message = ChatColor.translateAlternateColorCodes('&', message); - } - return message; + return getMessage(path, null); } /** @@ -205,15 +228,14 @@ public class FileConfig extends AbstractConfig { * @return 颜色转码后的文本 */ public List getMessageList(final String path) { - final List message = new ArrayList(); final List cfgmsg = this.getStringList(path); if (cfgmsg == null) { return null; } - for (final String msg : cfgmsg) { - message.add(ChatColor.translateAlternateColorCodes('&', msg)); + for (int i = 0; i < cfgmsg.size(); i++) { + cfgmsg.set(i, ChatColor.translateAlternateColorCodes('&', cfgmsg.get(i))); } - return message; + return cfgmsg; } /** diff --git a/src/main/java/pw/yumc/YumCore/config/PlayerConfig.java b/src/main/java/pw/yumc/YumCore/config/PlayerConfig.java index 3697ccd..173d4ba 100644 --- a/src/main/java/pw/yumc/YumCore/config/PlayerConfig.java +++ b/src/main/java/pw/yumc/YumCore/config/PlayerConfig.java @@ -3,7 +3,6 @@ package pw.yumc.YumCore.config; import java.io.File; import org.bukkit.entity.Player; -import org.bukkit.plugin.Plugin; /** * 玩家配置管理类 @@ -14,16 +13,6 @@ import org.bukkit.plugin.Plugin; public class PlayerConfig extends FileConfig { private static String CONFIG_FOLDER = "userdata"; - /** - * 获得玩家配置(保存在 PLUGINHELPER 文件夹) - * - * @param playername - * 玩家名称 - */ - public PlayerConfig(final Player playername) { - super(playername.getName()); - } - /** * 获得玩家配置(保存在 CONFIG_FOLDER 文件夹) * @@ -32,8 +21,8 @@ public class PlayerConfig extends FileConfig { * @param playername * 玩家名称 */ - public PlayerConfig(final Plugin plugin, final Player playername) { - super(new File(plugin.getDataFolder(), CONFIG_FOLDER + File.separatorChar + playername.getName())); + public PlayerConfig(final Player player) { + this(player.getName()); } /** @@ -44,18 +33,7 @@ public class PlayerConfig extends FileConfig { * @param player * 玩家 */ - public PlayerConfig(final Plugin plugin, final String player) { - super(new File(plugin.getDataFolder(), CONFIG_FOLDER + File.separatorChar + player)); + public PlayerConfig(final String playername) { + super(new File(plugin.getDataFolder(), CONFIG_FOLDER + File.separatorChar + playername + ".yml")); } - - /** - * 获得玩家配置(保存在 PLUGINHELPER 文件夹) - * - * @param player - * 玩家 - */ - public PlayerConfig(final String player) { - super(player); - } - }