diff --git a/src/main/java/pw/yumc/YumCore/bungee/Log.java b/src/main/java/pw/yumc/YumCore/bungee/Log.java new file mode 100644 index 0000000..53febe2 --- /dev/null +++ b/src/main/java/pw/yumc/YumCore/bungee/Log.java @@ -0,0 +1,49 @@ +package pw.yumc.YumCore.bungee; + +import java.util.logging.Logger; + +import net.md_5.bungee.api.plugin.Plugin; + +/** + * 插件日志输出类 + * + * @author 喵♂呜 + * @since 2016年7月23日 上午9:11:01 + */ +public class Log { + private static boolean debug = false; + public static Plugin plugin; + public static Logger logger; + + public static void init(Plugin plugin) { + Log.plugin = plugin; + Log.logger = plugin.getLogger(); + } + + public static void d(String s, Exception e) { + if (debug) { + logger.info(s); + e.printStackTrace(); + } + } + + public static void i(String s, Object... objects) { + logger.info(String.format(s, objects)); + } + + public static void d(String s) { + if (debug) { + logger.info(s); + } + } + + public static void d(Exception e) { + if (debug) { + e.printStackTrace(); + } + } + + public static void w(String s, Object... objects) { + logger.warning(String.format(s, objects)); + } +} diff --git a/src/main/java/pw/yumc/YumCore/bungee/config/FileConfig.java b/src/main/java/pw/yumc/YumCore/bungee/config/FileConfig.java new file mode 100644 index 0000000..bef54c9 --- /dev/null +++ b/src/main/java/pw/yumc/YumCore/bungee/config/FileConfig.java @@ -0,0 +1,209 @@ +package pw.yumc.YumCore.bungee.config; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.util.Collection; +import java.util.List; + +import net.md_5.bungee.api.plugin.Plugin; +import net.md_5.bungee.config.Configuration; +import net.md_5.bungee.config.ConfigurationProvider; +import net.md_5.bungee.config.YamlConfiguration; +import pw.yumc.YumCore.bungee.Log; + +/** + * + * Created by 蒋天蓓 on 2016/11/7 0007. + */ +public class FileConfig { + private File file; + private Configuration config; + + public FileConfig(Plugin plugin) { + this(plugin, "config.yml"); + } + + public T get(String path, T def) { + return config.get(path, def); + } + + public boolean contains(String path) { + return config.contains(path); + } + + public Object get(String path) { + return config.get(path); + } + + public Object getDefault(String path) { + return config.getDefault(path); + } + + public void set(String path, Object value) { + config.set(path, value); + } + + public Configuration getSection(String path) { + return config.getSection(path); + } + + public Collection getKeys() { + return config.getKeys(); + } + + public byte getByte(String path) { + return config.getByte(path); + } + + public byte getByte(String path, byte def) { + return config.getByte(path, def); + } + + public List getByteList(String path) { + return config.getByteList(path); + } + + public short getShort(String path) { + return config.getShort(path); + } + + public short getShort(String path, short def) { + return config.getShort(path, def); + } + + public List getShortList(String path) { + return config.getShortList(path); + } + + public int getInt(String path) { + return config.getInt(path); + } + + public int getInt(String path, int def) { + return config.getInt(path, def); + } + + public List getIntList(String path) { + return config.getIntList(path); + } + + public long getLong(String path) { + return config.getLong(path); + } + + public long getLong(String path, long def) { + return config.getLong(path, def); + } + + public List getLongList(String path) { + return config.getLongList(path); + } + + public float getFloat(String path) { + return config.getFloat(path); + } + + public float getFloat(String path, float def) { + return config.getFloat(path, def); + } + + public List getFloatList(String path) { + return config.getFloatList(path); + } + + public double getDouble(String path) { + return config.getDouble(path); + } + + public double getDouble(String path, double def) { + return config.getDouble(path, def); + } + + public List getDoubleList(String path) { + return config.getDoubleList(path); + } + + public boolean getBoolean(String path) { + return config.getBoolean(path); + } + + public boolean getBoolean(String path, boolean def) { + return config.getBoolean(path, def); + } + + public List getBooleanList(String path) { + return config.getBooleanList(path); + } + + public char getChar(String path) { + return config.getChar(path); + } + + public char getChar(String path, char def) { + return config.getChar(path, def); + } + + public List getCharList(String path) { + return config.getCharList(path); + } + + public String getString(String path) { + return config.getString(path); + } + + public String getString(String path, String def) { + return config.getString(path, def); + } + + public List getStringList(String path) { + return config.getStringList(path); + } + + public List getList(String path) { + return config.getList(path); + } + + public List getList(String path, List def) { + return config.getList(path, def); + } + + public FileConfig(Plugin plugin, String name) { + this.file = new File(plugin.getDataFolder(), name); + try { + if (!file.exists()) { + if (!file.getParentFile().exists()) { + file.getParentFile().mkdirs(); + } + Files.copy(plugin.getResourceAsStream(name), file.toPath()); + } + this.config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(file); + } catch (IOException e) { + Log.w("配置文件读取失败!"); + e.printStackTrace(); + } + } + + public Configuration getConfig() { + return config; + } + + public void save() { + try { + ConfigurationProvider.getProvider(YamlConfiguration.class).save(config, file); + } catch (IOException e) { + Log.w("配置文件保存失败!"); + e.printStackTrace(); + } + } + + public void reload() { + try { + this.config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(file); + } catch (IOException e) { + Log.w("配置文件读取失败!"); + e.printStackTrace(); + } + } + +}