diff --git a/src/cn/citycraft/plugins/RealBackpacks.java b/src/cn/citycraft/plugins/RealBackpacks.java index d2adc15..5b3cf99 100644 --- a/src/cn/citycraft/plugins/RealBackpacks.java +++ b/src/cn/citycraft/plugins/RealBackpacks.java @@ -1,6 +1,5 @@ package cn.citycraft.plugins; -import java.io.File; import java.lang.reflect.Constructor; import java.util.ArrayList; import java.util.HashMap; @@ -107,12 +106,7 @@ public class RealBackpacks extends JavaPlugin { getLogger().info("Vault found, economy features enabled."); } setupLists(); - final File userdata = new File(getDataFolder() + File.separator - + "userdata"); setup(); - if (!userdata.exists()) { - userdata.mkdirs(); - } if (isEnabled()) { getServer().getPluginManager().registerEvents( new PlayerListener(this), this); diff --git a/src/cn/citycraft/plugins/listeners/EntityListener.java b/src/cn/citycraft/plugins/listeners/EntityListener.java index fb48039..c586694 100644 --- a/src/cn/citycraft/plugins/listeners/EntityListener.java +++ b/src/cn/citycraft/plugins/listeners/EntityListener.java @@ -57,7 +57,6 @@ public class EntityListener implements Listener { setlevel = pLevel; } } - e.setCancelled(true); p.setFoodLevel(setlevel); } diff --git a/src/cn/citycraft/plugins/listeners/InventoryListener.java b/src/cn/citycraft/plugins/listeners/InventoryListener.java index 5854fad..f5a917b 100644 --- a/src/cn/citycraft/plugins/listeners/InventoryListener.java +++ b/src/cn/citycraft/plugins/listeners/InventoryListener.java @@ -1,13 +1,9 @@ package cn.citycraft.plugins.listeners; -import java.io.File; -import java.io.IOException; import java.sql.SQLException; import java.util.List; import org.bukkit.ChatColor; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -18,6 +14,7 @@ import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; +import cn.citycraft.Utils.config.PlayerConfig; import cn.citycraft.plugins.RealBackpacks; import cn.citycraft.plugins.util.MysqlFunctions; import cn.citycraft.plugins.util.RBUtil; @@ -53,21 +50,8 @@ public class InventoryListener implements Listener { e.printStackTrace(); } } else { - final File file = new File(plugin - .getDataFolder() - + File.separator - + "userdata" - + File.separator - + name - + ".yml"); - final FileConfiguration config = YamlConfiguration - .loadConfiguration(file); - config.set(backpack + ".Inventory", invString); - try { - config.save(file); - } catch (final IOException e) { - e.printStackTrace(); - } + PlayerConfig.getInstance(plugin, name).set(backpack + ".Inventory", invString); + PlayerConfig.save(); } } }); @@ -85,22 +69,9 @@ public class InventoryListener implements Listener { e.printStackTrace(); } } else { - final List invString = Serialization - .toString(inv); - final File file = new File(plugin - .getDataFolder() - + File.separator - + "userdata" - + File.separator - + split[1] + ".yml"); - final FileConfiguration config = YamlConfiguration - .loadConfiguration(file); - config.set(split[0] + ".Inventory", invString); - try { - config.save(file); - } catch (final IOException e) { - e.printStackTrace(); - } + PlayerConfig.getInstance(plugin, split[1]). + set(split[0] + ".Inventory", invString); + PlayerConfig.save(); } } }); diff --git a/src/cn/citycraft/plugins/listeners/PlayerListener.java b/src/cn/citycraft/plugins/listeners/PlayerListener.java index 997a1c2..c09cf2d 100644 --- a/src/cn/citycraft/plugins/listeners/PlayerListener.java +++ b/src/cn/citycraft/plugins/listeners/PlayerListener.java @@ -1,15 +1,11 @@ package cn.citycraft.plugins.listeners; -import java.io.File; -import java.io.IOException; import java.sql.SQLException; import java.util.HashMap; import java.util.List; import org.bukkit.ChatColor; import org.bukkit.Location; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -23,6 +19,8 @@ import org.bukkit.event.player.PlayerRespawnEvent; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; +import cn.citycraft.Utils.config.FileConfig; +import cn.citycraft.Utils.config.PlayerConfig; import cn.citycraft.plugins.RealBackpacks; import cn.citycraft.plugins.util.MysqlFunctions; import cn.citycraft.plugins.util.RBUtil; @@ -96,15 +94,7 @@ public class PlayerListener implements Listener { inv = plugin.getServer().createInventory(p, Integer.parseInt(key.get(0)), ChatColor.translateAlternateColorCodes('&', key.get(3))); } } else { - final File file = new File(plugin.getDataFolder() + File.separator + "userdata" + File.separator + name + ".yml"); - if (!file.exists()) { - try { - file.createNewFile(); - } catch (final IOException e1) { - e1.printStackTrace(); - } - } - final FileConfiguration config = YamlConfiguration.loadConfiguration(file); + FileConfig config = PlayerConfig.getInstance(plugin, name); if (!config.isSet(backpack + ".Inventory")) { inv = plugin.getServer().createInventory(p, Integer.parseInt(key.get(0)), ChatColor.translateAlternateColorCodes('&', key.get(3))); } else { @@ -210,11 +200,7 @@ public class PlayerListener implements Listener { e1.printStackTrace(); } } else { - final File file = new File(plugin.getDataFolder() + File.separator + "userdata" + File.separator + name + ".yml"); - if (!file.exists()) { - continue; - } - final FileConfiguration config = YamlConfiguration.loadConfiguration(file); + FileConfig config = PlayerConfig.getInstance(plugin, name); if (config.getStringList(backpack + ".Inventory") == null) { continue; } diff --git a/src/cn/citycraft/plugins/util/MysqlFunctions.java b/src/cn/citycraft/plugins/util/MysqlFunctions.java index 9a74ba4..3c66e19 100644 --- a/src/cn/citycraft/plugins/util/MysqlFunctions.java +++ b/src/cn/citycraft/plugins/util/MysqlFunctions.java @@ -24,7 +24,6 @@ public class MysqlFunctions { public static boolean checkIfTableExists(final String table) { try { - //final Connection conn = DriverManager.getConnection(plugin.getUrl(), plugin.getUser(), plugin.getPass()); String url = plugin.getUrl()+"?" + "user=" + plugin.getUser() + "&password=" + plugin.getPass() + "&useUnicode=true&characterEncoding=utf-8"; final Connection conn = DriverManager.getConnection(url); diff --git a/src/cn/citycraft/plugins/util/RBUtil.java b/src/cn/citycraft/plugins/util/RBUtil.java index 17d3fd8..5e63110 100644 --- a/src/cn/citycraft/plugins/util/RBUtil.java +++ b/src/cn/citycraft/plugins/util/RBUtil.java @@ -1,16 +1,13 @@ package cn.citycraft.plugins.util; -import java.io.File; -import java.io.IOException; import java.util.ArrayList; import java.util.Collections; import java.util.List; import org.bukkit.Material; -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.inventory.ItemStack; +import cn.citycraft.Utils.config.PlayerConfig; import cn.citycraft.plugins.RealBackpacks; public class RBUtil { @@ -28,14 +25,8 @@ public class RBUtil { if (plugin.isUsingMysql()) { MysqlFunctions.delete(name, backpack); } else { - final File file = new File(plugin.getDataFolder() + File.separator + "userdata" + File.separator + name + ".yml"); - final FileConfiguration config = YamlConfiguration.loadConfiguration(file); - config.set(backpack + ".Inventory", null); - try { - config.save(file); - } catch (final IOException e1) { - e1.printStackTrace(); - } + PlayerConfig.getInstance(plugin, name).set(backpack + ".Inventory", null); + PlayerConfig.save(); } } });