diff --git a/src/cn/citycraft/plugins/RealBackpacks.java b/src/cn/citycraft/plugins/RealBackpacks.java index 1a9e1fc..6f0168c 100644 --- a/src/cn/citycraft/plugins/RealBackpacks.java +++ b/src/cn/citycraft/plugins/RealBackpacks.java @@ -11,7 +11,6 @@ import net.milkbowl.vault.economy.Economy; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.event.HandlerList; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ShapedRecipe; import org.bukkit.inventory.meta.ItemMeta; @@ -19,6 +18,7 @@ import org.bukkit.material.MaterialData; import org.bukkit.plugin.RegisteredServiceProvider; import org.bukkit.plugin.java.JavaPlugin; +import cn.citycraft.plugins.config.Config; import cn.citycraft.plugins.listeners.CraftListener; import cn.citycraft.plugins.listeners.EntityListener; import cn.citycraft.plugins.listeners.InventoryListener; @@ -28,12 +28,6 @@ import cn.citycraft.plugins.util.RBUtil; public class RealBackpacks extends JavaPlugin { - @Override - public FileConfiguration getConfig() { - // TODO 自动生成的方法存根 - return super.getConfig(); - } - public static RBInterface NMS; public static Economy econ = null; @@ -87,7 +81,6 @@ public class RealBackpacks extends JavaPlugin { @Override public void onEnable() { - final String p = getServer().getClass().getPackage().getName(); final String version = p.substring(p.lastIndexOf('.') + 1); String classname = getClass().getPackage().getName() + ".versions." @@ -105,7 +98,6 @@ public class RealBackpacks extends JavaPlugin { } if (isEnabled()) { - saveDefaultConfig(); MysqlFunctions.setMysqlFunc(this); RBUtil.setRBUtil(this); if (!setupEconomy()) { @@ -114,7 +106,6 @@ public class RealBackpacks extends JavaPlugin { } else { getLogger().info("Vault found, economy features enabled."); } - reloadConfig(); setupLists(); final File userdata = new File(getDataFolder() + File.separator + "userdata"); @@ -134,17 +125,33 @@ public class RealBackpacks extends JavaPlugin { getCommand("rb").setExecutor(new MainCommand(this)); getServer().getScheduler().runTaskTimer(this, new WalkSpeedRunnable(this), 20, 20); - getLogger().info("Realistic Backpacks has been enabled."); + getLogger().info("真实背包已加载 By: 喵♂呜."); } } } @Override - public void onDisable() { - econ = null; - HandlerList.unregisterAll(this); - getServer().getPluginManager().disablePlugin(this); - getLogger().info("Realistic Backpacks has been disabled."); + public FileConfiguration getConfig() { + if(Config.getInstance()==null){ + Config.load(this); + } + return Config.getInstance(); + } + + /* (非 Javadoc) + * @see org.bukkit.plugin.java.JavaPlugin#saveConfig() + */ + @Override + public void saveConfig() { + Config.save(); + } + + /* (非 Javadoc) + * @see org.bukkit.plugin.java.JavaPlugin#reloadConfig() + */ + @Override + public void reloadConfig() { + Config.load(this); } private boolean setupEconomy() { diff --git a/src/cn/citycraft/plugins/config/Config.java b/src/cn/citycraft/plugins/config/Config.java new file mode 100644 index 0000000..5b65631 --- /dev/null +++ b/src/cn/citycraft/plugins/config/Config.java @@ -0,0 +1,47 @@ +package cn.citycraft.plugins.config; + +import java.io.File; +import java.io.IOException; + +import org.bukkit.plugin.Plugin; + +import cn.citycraft.Utils.config.ConfigLoader; +import cn.citycraft.Utils.config.FileConfig; + +public class Config extends ConfigLoader { + private static String CONFIG_NAME = "config.yml"; + private static FileConfig instance; + private static File file; + + public Config(Plugin p) { + super(p, CONFIG_NAME); + file = new File(p.getDataFolder(), CONFIG_NAME); + instance = super.getInstance(); + } + + public static void load(Plugin p) { + new Config(p); + } + + public static FileConfig getInstance() { + return instance; + } + + public static String getMessage(String path) { + String message = instance.getString(path).replaceAll("&", "§"); + return message; + } + + public static String[] getStringArray(String path) { + return instance.getStringList(path).toArray(new String[0]); + } + + public static void save(){ + try { + instance.save(file); + } catch (IOException e) { + saveError(file); + e.printStackTrace(); + } + } +} diff --git a/src/config.yml b/src/config.yml index c441313..8b06672 100644 --- a/src/config.yml +++ b/src/config.yml @@ -26,13 +26,13 @@ Backpacks: - 334,334,334 BackpackItem: id: 334 - name: "&a-18" + name: "&a背包-18" lore: - - "&5һЯı." - - "&b&d18&bӵƷɴ." - - "&3ƶٶ½5%." - - "&6ʧٴι򼴿ɣƷʧ." - - "&cÿֱ蹺һΣ." + - "&5一个随身携带的背包." + - "&b有&d18&b个格子的物品可存放." + - "&3移动速度下降5%." + - "&6背包掉落或丢失,再次购买即可,物品不丢失." + - "&c每种背包仅需购买一次,多个不叠加." UseWhitelist: false ItemWhitelist: [] ItemBlacklist: @@ -68,13 +68,13 @@ Backpacks: - 334,334,334 BackpackItem: id: 334 - name: "&a-27" + name: "&a背包-27" lore: - - "&5һЯı." - - "&b&d27&bӵƷɴ." - - "&3ƶٶ½10%." - - "&6ʧٴι򼴿ɣƷʧ." - - "&cÿֱ蹺һΣ." + - "&5一个随身携带的背包." + - "&b有&d27&b个格子的物品可存放." + - "&3移动速度下降10%." + - "&6背包掉落或丢失,再次购买即可,物品不丢失." + - "&c每种背包仅需购买一次,多个不叠加." UseWhitelist: false ItemWhitelist: [] ItemBlacklist: @@ -110,13 +110,13 @@ Backpacks: - 334,334,334 BackpackItem: id: 334 - name: "&a-36" + name: "&a背包-36" lore: - - "&5һЯı." - - "&b&d36&bӵƷɴ." - - "&3ƶٶ½15%." - - "&6ʧٴι򼴿ɣƷʧ." - - "&cÿֱ蹺һΣ." + - "&5一个随身携带的背包." + - "&b有&d36&b个格子的物品可存放." + - "&3移动速度下降15%." + - "&6背包掉落或丢失,再次购买即可,物品不丢失." + - "&c每种背包仅需购买一次,多个不叠加." UseWhitelist: false ItemWhitelist: [] ItemBlacklist: @@ -152,13 +152,13 @@ Backpacks: - 334,334,334 BackpackItem: id: 334 - name: "&a-45" + name: "&a背包-45" lore: - - "&5һЯı." - - "&b&d45&bӵƷɴ." - - "&3ƶٶ½20%." - - "&6ʧٴι򼴿ɣƷʧ." - - "&cÿֱ蹺һΣ." + - "&5一个随身携带的背包." + - "&b有&d45&b个格子的物品可存放." + - "&3移动速度下降20%." + - "&6背包掉落或丢失,再次购买即可,物品不丢失." + - "&c每种背包仅需购买一次,多个不叠加." UseWhitelist: false ItemWhitelist: [] ItemBlacklist: @@ -194,12 +194,12 @@ Backpacks: - 334,334,334 BackpackItem: id: 334 - name: "&a-54" + name: "&a背包-54" lore: - - "&5һЯı." - - "&b&d54&bӵƷɴ." - - "&6ʧٴι򼴿ɣƷʧ." - - "&cÿֱ蹺һΣ." + - "&5一个随身携带的背包." + - "&b有&d54&b个格子的物品可存放." + - "&6背包掉落或丢失,再次购买即可,物品不丢失." + - "&c每种背包仅需购买一次,多个不叠加." UseWhitelist: false ItemWhitelist: [] ItemBlacklist: