mirror of
				https://e.coding.net/circlecloud/YumCore.git
				synced 2025-11-03 23:06:02 +00:00 
			
		
		
		
	@@ -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;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -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);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user