1
0
mirror of https://e.coding.net/circlecloud/YumCore.git synced 2024-11-22 01:48:50 +00:00

fix: 修复玩家配置构造错误 添加Location保存

Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
502647092 2016-08-25 03:57:44 +08:00
parent f2dbac8454
commit 27a81f7e84
2 changed files with 37 additions and 37 deletions

View File

@ -15,6 +15,7 @@ import java.util.logging.Logger;
import org.apache.commons.lang.Validate; import org.apache.commons.lang.Validate;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
@ -57,7 +58,6 @@ public class FileConfig extends AbstractConfig {
public FileConfig(final File file) { public FileConfig(final File file) {
Validate.notNull(file, "文件不能为 null"); Validate.notNull(file, "文件不能为 null");
this.file = file; this.file = file;
check(file);
init(file); init(file);
} }
@ -70,7 +70,9 @@ public class FileConfig extends AbstractConfig {
* 配置文件名称 * 配置文件名称
*/ */
public FileConfig(final String filename) { 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(); 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 颜色转码后的文本 * @return 颜色转码后的文本
*/ */
public String getMessage(final String path) { public String getMessage(final String path) {
String message = this.getString(path); return getMessage(path, null);
if (message != null) {
message = ChatColor.translateAlternateColorCodes('&', message);
}
return message;
} }
/** /**
@ -205,15 +228,14 @@ public class FileConfig extends AbstractConfig {
* @return 颜色转码后的文本 * @return 颜色转码后的文本
*/ */
public List<String> getMessageList(final String path) { public List<String> getMessageList(final String path) {
final List<String> message = new ArrayList<String>();
final List<String> cfgmsg = this.getStringList(path); final List<String> cfgmsg = this.getStringList(path);
if (cfgmsg == null) { if (cfgmsg == null) {
return null; return null;
} }
for (final String msg : cfgmsg) { for (int i = 0; i < cfgmsg.size(); i++) {
message.add(ChatColor.translateAlternateColorCodes('&', msg)); cfgmsg.set(i, ChatColor.translateAlternateColorCodes('&', cfgmsg.get(i)));
} }
return message; return cfgmsg;
} }
/** /**

View File

@ -3,7 +3,6 @@ package pw.yumc.YumCore.config;
import java.io.File; import java.io.File;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
/** /**
* 玩家配置管理类 * 玩家配置管理类
@ -14,16 +13,6 @@ import org.bukkit.plugin.Plugin;
public class PlayerConfig extends FileConfig { public class PlayerConfig extends FileConfig {
private static String CONFIG_FOLDER = "userdata"; private static String CONFIG_FOLDER = "userdata";
/**
* 获得玩家配置(保存在 PLUGINHELPER 文件夹)
*
* @param playername
* 玩家名称
*/
public PlayerConfig(final Player playername) {
super(playername.getName());
}
/** /**
* 获得玩家配置(保存在 CONFIG_FOLDER 文件夹) * 获得玩家配置(保存在 CONFIG_FOLDER 文件夹)
* *
@ -32,8 +21,8 @@ public class PlayerConfig extends FileConfig {
* @param playername * @param playername
* 玩家名称 * 玩家名称
*/ */
public PlayerConfig(final Plugin plugin, final Player playername) { public PlayerConfig(final Player player) {
super(new File(plugin.getDataFolder(), CONFIG_FOLDER + File.separatorChar + playername.getName())); this(player.getName());
} }
/** /**
@ -44,18 +33,7 @@ public class PlayerConfig extends FileConfig {
* @param player * @param player
* 玩家 * 玩家
*/ */
public PlayerConfig(final Plugin plugin, final String player) { public PlayerConfig(final String playername) {
super(new File(plugin.getDataFolder(), CONFIG_FOLDER + File.separatorChar + player)); super(new File(plugin.getDataFolder(), CONFIG_FOLDER + File.separatorChar + playername + ".yml"));
} }
/**
* 获得玩家配置(保存在 PLUGINHELPER 文件夹)
*
* @param player
* 玩家
*/
public PlayerConfig(final String player) {
super(player);
}
} }