From ad79ccdfc99a4f333b41b466868408d2eff98249 Mon Sep 17 00:00:00 2001 From: 502647092 Date: Tue, 24 Nov 2015 13:41:56 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8PluginHelper=E5=A4=84?= =?UTF-8?q?=E7=90=86=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6...?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 502647092 --- pom.xml | 13 +- .../com/me/tft_02/soulbound/Soulbound.java | 51 +++-- .../soulbound/commands/BindCommand.java | 4 +- .../config/AutoUpdateConfigLoader.java | 119 ----------- .../me/tft_02/soulbound/config/Config.java | 161 +++++++++------ .../tft_02/soulbound/config/ConfigLoader.java | 93 --------- .../tft_02/soulbound/config/ItemsConfig.java | 187 +++++++++--------- .../hooks/EpicBossRecodedListener.java | 22 --- .../listeners/InventoryListener.java | 6 +- .../soulbound/listeners/PlayerListener.java | 12 +- .../runnables/SoulbindInventoryTask.java | 4 +- .../soulbound/util/DurabilityUtils.java | 2 +- .../me/tft_02/soulbound/util/ItemUtils.java | 2 +- 13 files changed, 229 insertions(+), 447 deletions(-) delete mode 100644 src/main/java/com/me/tft_02/soulbound/config/AutoUpdateConfigLoader.java delete mode 100644 src/main/java/com/me/tft_02/soulbound/config/ConfigLoader.java delete mode 100644 src/main/java/com/me/tft_02/soulbound/hooks/EpicBossRecodedListener.java diff --git a/pom.xml b/pom.xml index dbbd685..0a758d2 100644 --- a/pom.xml +++ b/pom.xml @@ -5,6 +5,7 @@ Soulbound 1.1.12 Soulbound + Soulbound items for your RPG servers! https://github.com/TfT-02/Soulbound GitHub @@ -37,14 +38,9 @@ cn.citycraft:PluginHelper - org.mcstats.*:* - - org.mcstats - ${project.groupId}.${project.artifactId}.mcstats - cn.citycraft.PluginHelper ${project.groupId}.${project.artifactId} @@ -89,15 +85,8 @@ jar 1.0 - - org.mcstats.bukkit - metrics - R8-SNAPSHOT - compile - UTF-8 - Soulbound items for your RPG servers! diff --git a/src/main/java/com/me/tft_02/soulbound/Soulbound.java b/src/main/java/com/me/tft_02/soulbound/Soulbound.java index c588151..bc459f7 100644 --- a/src/main/java/com/me/tft_02/soulbound/Soulbound.java +++ b/src/main/java/com/me/tft_02/soulbound/Soulbound.java @@ -14,7 +14,6 @@ import com.me.tft_02.soulbound.commands.SoulboundCommand; import com.me.tft_02.soulbound.commands.UnbindCommand; import com.me.tft_02.soulbound.config.Config; import com.me.tft_02.soulbound.config.ItemsConfig; -import com.me.tft_02.soulbound.hooks.EpicBossRecodedListener; import com.me.tft_02.soulbound.listeners.BlockListener; import com.me.tft_02.soulbound.listeners.EntityListener; import com.me.tft_02.soulbound.listeners.InventoryListener; @@ -25,20 +24,22 @@ import cn.citycraft.PluginHelper.config.FileConfig; import cn.citycraft.PluginHelper.utils.VersionChecker; public class Soulbound extends JavaPlugin { - /* File Paths */ - private static String mainDirectory; + // Checks for hooking into other plugins + public static boolean epicBossRecodedEnabled = false; + + public static boolean loreLocksEnabled = false; public static Soulbound p; // Jar Stuff public static File soulbound; - // Checks for hooking into other plugins - public static boolean epicBossRecodedEnabled = false; + /* File Paths */ + private static String mainDirectory; + private FileConfig config; + private FileConfig itemcfg; + private FileConfig msgcfg; - public static boolean loreLocksEnabled = false; - FileConfig msgcfg; - FileConfig config; // Update Check private boolean updateAvailable; @@ -80,22 +81,16 @@ public class Soulbound extends JavaPlugin { loadConfigFiles(); - setupEpicBossRecoded(); - registerEvents(); - getCommand("soulbound").setExecutor(new SoulboundCommand()); - getCommand("bind").setExecutor(new BindCommand()); - getCommand("bindonpickup").setExecutor(new BindOnPickupCommand()); - getCommand("bindonuse").setExecutor(new BindOnUseCommand()); - getCommand("bindonequip").setExecutor(new BindOnEquipCommand()); - getCommand("unbind").setExecutor(new UnbindCommand()); + registerCommands(); new VersionChecker(this); } @Override public void onLoad() { + itemcfg = new FileConfig(this, "item.yml"); msgcfg = new FileConfig(this, "message.yml"); config = new FileConfig(this); } @@ -107,8 +102,17 @@ public class Soulbound extends JavaPlugin { } private void loadConfigFiles() { - Config.getInstance(); - ItemsConfig.getInstance(); + Config.load(config); + ItemsConfig.load(itemcfg); + } + + private void registerCommands() { + getCommand("soulbound").setExecutor(new SoulboundCommand()); + getCommand("bind").setExecutor(new BindCommand()); + getCommand("bindonpickup").setExecutor(new BindOnPickupCommand()); + getCommand("bindonuse").setExecutor(new BindOnUseCommand()); + getCommand("bindonequip").setExecutor(new BindOnEquipCommand()); + getCommand("unbind").setExecutor(new UnbindCommand()); } private void registerEvents() { @@ -119,17 +123,6 @@ public class Soulbound extends JavaPlugin { pm.registerEvents(new BlockListener(), this); } - private void setupEpicBossRecoded() { - if (getServer().getPluginManager().isPluginEnabled("EpicBossRecoded")) { - epicBossRecodedEnabled = true; - debug("EpicBossRecoded found!"); - getServer().getPluginManager().registerEvents(new EpicBossRecodedListener(), this); - } - } - - /** - * Setup the various storage file paths - */ private void setupFilePaths() { soulbound = getFile(); mainDirectory = getDataFolder().getPath() + File.separator; diff --git a/src/main/java/com/me/tft_02/soulbound/commands/BindCommand.java b/src/main/java/com/me/tft_02/soulbound/commands/BindCommand.java index 363d9df..3386309 100644 --- a/src/main/java/com/me/tft_02/soulbound/commands/BindCommand.java +++ b/src/main/java/com/me/tft_02/soulbound/commands/BindCommand.java @@ -68,7 +68,7 @@ public class BindCommand implements CommandExecutor { ItemUtils.soulbindItem(target, itemInHand); - if (ItemUtils.isSoulbound(itemInHand) && Config.getInstance().getFeedbackEnabled()) { + if (ItemUtils.isSoulbound(itemInHand) && Config.getFeedbackEnabled()) { sender.sendMessage(Soulbound.p.getlang("BINDED").replace("%target%", target.getName())); } return true; @@ -81,7 +81,7 @@ public class BindCommand implements CommandExecutor { } } - if (Config.getInstance().getFeedbackEnabled()) { + if (Config.getFeedbackEnabled()) { player.sendMessage(Soulbound.p.getlang("BIND_FULL_INEVNTORY") .replace("%player%", player.getName()).replace("%target%", target.getName())); } diff --git a/src/main/java/com/me/tft_02/soulbound/config/AutoUpdateConfigLoader.java b/src/main/java/com/me/tft_02/soulbound/config/AutoUpdateConfigLoader.java deleted file mode 100644 index 0774904..0000000 --- a/src/main/java/com/me/tft_02/soulbound/config/AutoUpdateConfigLoader.java +++ /dev/null @@ -1,119 +0,0 @@ -package com.me.tft_02.soulbound.config; - -import java.io.BufferedReader; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileWriter; -import java.io.InputStreamReader; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Set; - -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.configuration.file.YamlConfiguration; - -public abstract class AutoUpdateConfigLoader extends ConfigLoader { - public AutoUpdateConfigLoader(String relativePath, String fileName) { - super(relativePath, fileName); - } - - public AutoUpdateConfigLoader(String fileName) { - super(fileName); - } - - @SuppressWarnings("deprecation") - @Override - protected void loadFile() { - super.loadFile(); - FileConfiguration internalConfig = YamlConfiguration.loadConfiguration(plugin.getResource(fileName)); - - Set configKeys = config.getKeys(true); - Set internalConfigKeys = internalConfig.getKeys(true); - - boolean needSave = false; - - Set oldKeys = new HashSet(configKeys); - oldKeys.removeAll(internalConfigKeys); - - Set newKeys = new HashSet(internalConfigKeys); - newKeys.removeAll(configKeys); - - // Don't need a re-save if we have old keys sticking around? - // Would be less saving, but less... correct? - if (!newKeys.isEmpty() || !oldKeys.isEmpty()) { - needSave = true; - } - - for (String key : oldKeys) { - plugin.debug("Removing unused key: " + key); - config.set(key, null); - } - - for (String key : newKeys) { - plugin.debug("Adding new key: " + key + " = " + internalConfig.get(key)); - config.set(key, internalConfig.get(key)); - } - - if (needSave) { - // Get Bukkit's version of an acceptable config with new keys, and no old keys - String output = config.saveToString(); - - // Convert to the superior 4 space indentation - output = output.replace(" ", " "); - - // Rip out Bukkit's attempt to save comments at the top of the file - while (output.indexOf('#') != -1) { - output = output.substring(output.indexOf('\n', output.indexOf('#')) + 1); - } - - // Read the internal config to get comments, then put them in the new one - try { - // Read internal - BufferedReader reader = new BufferedReader(new InputStreamReader(plugin.getResource(fileName))); - HashMap comments = new HashMap(); - String temp = ""; - - String line; - while ((line = reader.readLine()) != null) { - if (line.contains("#")) { - temp += line + "\n"; - } - else if (line.contains(":")) { - line = line.substring(0, line.indexOf(":") + 1); - if (!temp.isEmpty()) { - comments.put(line, temp); - temp = ""; - } - } - } - - // Dump to the new one - for (String key : comments.keySet()) { - if (output.indexOf(key) != -1) { - output = output.substring(0, output.indexOf(key)) + comments.get(key) + output.substring(output.indexOf(key)); - } - } - } - catch (Exception e) { - e.printStackTrace(); - } - - // Save it - try { - String saveName = fileName; - // At this stage we cannot guarantee that Config has been loaded, so we do the check directly here - if (!plugin.getConfig().getBoolean("General.Config_Update_Overwrite", true)) { - saveName += ".new"; - } - - BufferedWriter writer = new BufferedWriter(new FileWriter(new File(plugin.getDataFolder(), saveName))); - writer.write(output); - writer.flush(); - writer.close(); - } - catch (Exception e) { - e.printStackTrace(); - } - } - } -} diff --git a/src/main/java/com/me/tft_02/soulbound/config/Config.java b/src/main/java/com/me/tft_02/soulbound/config/Config.java index 89700f2..8190a4c 100644 --- a/src/main/java/com/me/tft_02/soulbound/config/Config.java +++ b/src/main/java/com/me/tft_02/soulbound/config/Config.java @@ -3,87 +3,124 @@ package com.me.tft_02.soulbound.config; import java.util.ArrayList; import java.util.List; -public class Config extends AutoUpdateConfigLoader { - private static Config instance; +import cn.citycraft.PluginHelper.config.FileConfig; - private Config() { - super("config.yml"); - } +public class Config { + private static FileConfig config; - public static Config getInstance() { - if (instance == null) { - instance = new Config(); - } + public static boolean getAllowItemStoring() { + return config.getBoolean("Soulbound.Allow_Item_Storing", true); + } - return instance; - } + public static List getBindCommands() { + return config.getStringList("Soulbound.Commands_Bind_When_Used"); + } - @Override - protected void loadKeys() {} + public static List getBlockedCommands() { + return config.getStringList("Soulbound.Blocked_Commands"); + } - /* @formatter:off */ + public static boolean getConfigOverwriteEnabled() { + return config.getBoolean("General.Config_Update_Overwrite", true); + } - /* GENERAL SETTINGS */ -// public String getLocale() { return config.getString("General.Locale", "en_us"); } -// public int getSaveInterval() { return config.getInt("General.Save_Interval", 10); } - public boolean getStatsTrackingEnabled() { return config.getBoolean("General.Stats_Tracking", true); } - public boolean getUpdateCheckEnabled() { return config.getBoolean("General.Update_Check", true); } - public boolean getPreferBeta() { return config.getBoolean("General.Prefer_Beta", false); } - public boolean getVerboseLoggingEnabled() { return config.getBoolean("General.Verbose_Logging", false); } - public boolean getConfigOverwriteEnabled() { return config.getBoolean("General.Config_Update_Overwrite", true); } + public static boolean getDeleteOnDrop() { + return config.getBoolean("Soulbound.Delete_On_Drop", false); + } - /* @formatter:on */ + public static List getDiabloDropsBindOnEquipTiers() { + return getDiabloDropsItemTiers("BindOnEquip"); + } - /* SOULBOUND SETTINGS */ - public boolean getShowNameInLore() { return config.getBoolean("Soulbound.Show_Name_In_Lore", true); } - public boolean getFeedbackEnabled() { return config.getBoolean("Soulbound.Feedback_Messages_Enabled", true); } - public boolean getPreventItemDrop() { return config.getBoolean("Soulbound.Prevent_Item_Drop", false); } - public boolean getDeleteOnDrop() { return config.getBoolean("Soulbound.Delete_On_Drop", false); } - public boolean getAllowItemStoring() { return config.getBoolean("Soulbound.Allow_Item_Storing", true); } - public boolean getInfiniteDurability() { return config.getBoolean("Soulbound.Infinite_Durability", false); } + public static List getDiabloDropsBindOnPickupTiers() { + return getDiabloDropsItemTiers("BindOnPickup"); + } - public List getBlockedCommands() { return config.getStringList("Soulbound.Blocked_Commands"); } - public List getBindCommands() { return config.getStringList("Soulbound.Commands_Bind_When_Used"); } + public static List getDiabloDropsBindOnUseTiers() { + return getDiabloDropsItemTiers("BindOnUse"); + } - // EpicBossRecoded config settings + public static List getDiabloDropsItemTiers(final String bindType) { + final String[] tiersString = config.getString("Dependency_Plugins.DiabloDrops." + bindType).replaceAll(" ", "").split("[,]"); + final List tiers = new ArrayList(); - public boolean getEBRBindOnPickup() { return config.getBoolean("Dependency_Plugins.EpicBossRecoded.BindOnPickup"); } - public boolean getEBRBindOnEquip() { return config.getBoolean("Dependency_Plugins.EpicBossRecoded.BindOnEquip"); } - public boolean getEBRBindOnUse() { return config.getBoolean("Dependency_Plugins.EpicBossRecoded.BindOnUse");} + for (final String tier : tiersString) { + tiers.add(tier); + } + return tiers; + } - // DiabloDrops config settings + public static boolean getEBRBindOnEquip() { + return config.getBoolean("Dependency_Plugins.EpicBossRecoded.BindOnEquip"); + } - public List getDiabloDropsBindOnPickupTiers() { return getDiabloDropsItemTiers("BindOnPickup");} - public List getDiabloDropsBindOnUseTiers() { return getDiabloDropsItemTiers("BindOnUse");} - public List getDiabloDropsBindOnEquipTiers() { return getDiabloDropsItemTiers("BindOnEquip"); } + public static boolean getEBRBindOnPickup() { + return config.getBoolean("Dependency_Plugins.EpicBossRecoded.BindOnPickup"); + } - public List getDiabloDropsItemTiers(String bindType) { - String[] tiersString = config.getString("Dependency_Plugins.DiabloDrops." + bindType).replaceAll(" ", "").split("[,]"); - List tiers = new ArrayList(); + public static boolean getEBRBindOnUse() { + return config.getBoolean("Dependency_Plugins.EpicBossRecoded.BindOnUse"); + } - for (String tier : tiersString) { - tiers.add(tier); - } - return tiers; - } + public static boolean getFeedbackEnabled() { + return config.getBoolean("Soulbound.Feedback_Messages_Enabled", true); + } - // LoreLocks config settings + public static boolean getInfiniteDurability() { + return config.getBoolean("Soulbound.Infinite_Durability", false); + } - public boolean getLoreLocksBindKeys() { return config.getBoolean("Dependency_Plugins.LoreLocks.Bind_Keys"); } + public static boolean getLoreLocksBindKeys() { + return config.getBoolean("Dependency_Plugins.LoreLocks.Bind_Keys"); + } - // MythicDrops config settings + public static List getMythicDropsBindOnEquipTiers() { + return getMythicDropsItemTiers("BindOnEquip"); + } - public List getMythicDropsBindOnPickupTiers() { return getMythicDropsItemTiers("BindOnPickup"); } - public List getMythicDropsBindOnUseTiers() { return getMythicDropsItemTiers("BindOnUse"); } - public List getMythicDropsBindOnEquipTiers() { return getMythicDropsItemTiers("BindOnEquip"); } + public static List getMythicDropsBindOnPickupTiers() { + return getMythicDropsItemTiers("BindOnPickup"); + } - public List getMythicDropsItemTiers(String bindType) { - String[] tiersString = config.getString("Dependency_Plugins.MythicDrops." + bindType).replaceAll(" ", "").split("[,]"); - List tiers = new ArrayList(); + public static List getMythicDropsBindOnUseTiers() { + return getMythicDropsItemTiers("BindOnUse"); + } - for (String tier : tiersString) { - tiers.add(tier); - } - return tiers; - } + public static List getMythicDropsItemTiers(final String bindType) { + final String[] tiersString = config.getString("Dependency_Plugins.MythicDrops." + bindType).replaceAll(" ", "").split("[,]"); + final List tiers = new ArrayList(); + + for (final String tier : tiersString) { + tiers.add(tier); + } + return tiers; + } + + public static boolean getPreferBeta() { + return config.getBoolean("General.Prefer_Beta", false); + } + + public static boolean getPreventItemDrop() { + return config.getBoolean("Soulbound.Prevent_Item_Drop", false); + } + + public static boolean getShowNameInLore() { + return config.getBoolean("Soulbound.Show_Name_In_Lore", true); + } + + public static boolean getStatsTrackingEnabled() { + return config.getBoolean("General.Stats_Tracking", true); + } + + public static boolean getUpdateCheckEnabled() { + return config.getBoolean("General.Update_Check", true); + } + + public static boolean getVerboseLoggingEnabled() { + return config.getBoolean("General.Verbose_Logging", false); + } + + public static void load(final FileConfig config) { + Config.config = config; + } } diff --git a/src/main/java/com/me/tft_02/soulbound/config/ConfigLoader.java b/src/main/java/com/me/tft_02/soulbound/config/ConfigLoader.java deleted file mode 100644 index 03b24dc..0000000 --- a/src/main/java/com/me/tft_02/soulbound/config/ConfigLoader.java +++ /dev/null @@ -1,93 +0,0 @@ -package com.me.tft_02.soulbound.config; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; - -import org.bukkit.configuration.file.FileConfiguration; -import org.bukkit.configuration.file.YamlConfiguration; - -import com.me.tft_02.soulbound.Soulbound; - -public abstract class ConfigLoader { - protected static final Soulbound plugin = Soulbound.p; - protected String fileName; - protected File configFile; - protected FileConfiguration config; - - public ConfigLoader(String relativePath, String fileName) { - this.fileName = fileName; - configFile = new File(plugin.getDataFolder(), relativePath + File.separator + fileName); - loadFile(); - } - - public ConfigLoader(String fileName) { - this.fileName = fileName; - configFile = new File(plugin.getDataFolder(), fileName); - loadFile(); - } - - protected void loadFile() { - if (!configFile.exists()) { - plugin.debug("Creating Soulbound " + fileName + " File..."); - createFile(); - } - else { - plugin.debug("Loading Soulbound " + fileName + " File..."); - } - - config = YamlConfiguration.loadConfiguration(configFile); - } - - protected abstract void loadKeys(); - - protected void createFile() { - configFile.getParentFile().mkdirs(); - - InputStream inputStream = plugin.getResource(fileName); - - if (inputStream == null) { - plugin.getLogger().severe("Missing resource file: '" + fileName + "' please notify the plugin authors"); - return; - } - - OutputStream outputStream = null; - - try { - outputStream = new FileOutputStream(configFile); - - int read; - byte[] bytes = new byte[1024]; - - while ((read = inputStream.read(bytes)) != -1) { - outputStream.write(bytes, 0, read); - } - } - catch (FileNotFoundException e) { - e.printStackTrace(); - } - catch (IOException e) { - e.printStackTrace(); - } - finally { - if (outputStream != null) { - try { - outputStream.close(); - } - catch (IOException e) { - e.printStackTrace(); - } - } - - try { - inputStream.close(); - } - catch (IOException e) { - e.printStackTrace(); - } - } - } -} diff --git a/src/main/java/com/me/tft_02/soulbound/config/ItemsConfig.java b/src/main/java/com/me/tft_02/soulbound/config/ItemsConfig.java index 34e304f..c79e04c 100644 --- a/src/main/java/com/me/tft_02/soulbound/config/ItemsConfig.java +++ b/src/main/java/com/me/tft_02/soulbound/config/ItemsConfig.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Set; +import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; @@ -14,81 +15,67 @@ import org.bukkit.material.MaterialData; import com.me.tft_02.soulbound.datatypes.ActionType; import com.me.tft_02.soulbound.datatypes.SoulbindItem; -public class ItemsConfig extends ConfigLoader { - private static ItemsConfig instance; +import cn.citycraft.PluginHelper.config.FileConfig; - private List soulbindOnCraft = new ArrayList(); - private List soulbindOnOpenChest = new ArrayList(); - private List soulbindOnPickupItem = new ArrayList(); - private List soulbindOnDrop = new ArrayList(); - private List soulbindOnRespawn = new ArrayList(); - private List soulbindOnKit = new ArrayList(); +public class ItemsConfig { + private static FileConfig item; + private final static List soulbindOnCraft = new ArrayList(); + private final static List soulbindOnDrop = new ArrayList(); + private final static List soulbindOnKit = new ArrayList(); + private final static List soulbindOnOpenChest = new ArrayList(); + private final static List soulbindOnPickupItem = new ArrayList(); + private final static List soulbindOnRespawn = new ArrayList(); public ItemsConfig() { - super("items.yml"); loadKeys(); } - public static ItemsConfig getInstance() { - if (instance == null) { - instance = new ItemsConfig(); - } - - return instance; - } - - @SuppressWarnings("deprecation") - @Override - protected void loadKeys() { - ConfigurationSection configurationSection = config.getConfigurationSection("Items"); - - if (configurationSection == null) { - return; - } - - Set itemConfigSet = configurationSection.getKeys(false); - - for (String itemName : itemConfigSet) { - String[] itemInfo = itemName.split("[|]"); - - Material itemMaterial = Material.matchMaterial(itemInfo[0]); - - if (itemMaterial == null) { - plugin.getLogger().warning( - "Invalid material name. This item will be skipped. - " + itemInfo[0]); - continue; - } - - byte itemData = (itemInfo.length == 2) ? Byte.valueOf(itemInfo[1]) : 0; - MaterialData itemMaterialData = new MaterialData(itemMaterial, itemData); - - List lore = new ArrayList(); - if (config.contains("Items." + itemName + ".Lore")) { - - for (String loreEntry : config.getStringList("Items." + itemName + ".Lore")) { - lore.add(ChatColor.translateAlternateColorCodes('&', loreEntry)); - } - } - - String name = null; - if (config.contains("Items." + itemName + ".Name")) { - name = ChatColor.translateAlternateColorCodes('&', - config.getString("Items." + itemName + ".Name")); - } - - SoulbindItem soulbindItem = new SoulbindItem(itemMaterialData, name, lore); - - List actions = config.getStringList("Items." + itemName + ".Actions"); - - for (ActionType actionType : ActionType.values()) { - if (actions.contains(actionType.toString())) { - addSoulbindItem(actionType, soulbindItem); - } - } + public static List getSoulbindItems(final ActionType actionType) { + switch (actionType) { + case CRAFT: + return soulbindOnCraft; + case OPEN_CHEST: + return soulbindOnOpenChest; + case PICKUP_ITEM: + return soulbindOnPickupItem; + case DROP_ITEM: + return soulbindOnDrop; + case RESPAWN: + return soulbindOnRespawn; + case KIT: + return soulbindOnKit; + default: + return null; } } - private void addSoulbindItem(ActionType actionType, SoulbindItem soulbindItem) { + public static boolean isActionItem(final ItemStack itemStack, final ActionType actionType) { + for (final SoulbindItem soulbindItem : getSoulbindItems(actionType)) { + + if (itemStack.getData().equals(soulbindItem.getMaterialData())) { + if (itemStack.hasItemMeta()) { + final ItemMeta itemMeta = itemStack.getItemMeta(); + if (soulbindItem.getName() != null) { + if (itemMeta.getDisplayName().contains(soulbindItem.getName())) { + if (soulbindItem.getLore() != null && !soulbindItem.getLore().isEmpty()) { + if (itemMeta.hasLore() && itemMeta.getLore().containsAll(soulbindItem.getLore())) { + return true; + } + } + } + } + + } + } + } + return false; + } + + public static void load(final FileConfig config) { + item = config; + } + + private void addSoulbindItem(final ActionType actionType, final SoulbindItem soulbindItem) { switch (actionType) { case CRAFT: soulbindOnCraft.add(soulbindItem); @@ -111,41 +98,51 @@ public class ItemsConfig extends ConfigLoader { } } - public List getSoulbindItems(ActionType actionType) { - switch (actionType) { - case CRAFT: - return soulbindOnCraft; - case OPEN_CHEST: - return soulbindOnOpenChest; - case PICKUP_ITEM: - return soulbindOnPickupItem; - case DROP_ITEM: - return soulbindOnDrop; - case RESPAWN: - return soulbindOnRespawn; - case KIT: - return soulbindOnKit; - default: - return null; + @SuppressWarnings("deprecation") + protected void loadKeys() { + final ConfigurationSection configurationSection = item.getConfigurationSection("Items"); + + if (configurationSection == null) { + return; } - } - public boolean isActionItem(ItemStack itemStack, ActionType actionType) { - for (SoulbindItem soulbindItem : getSoulbindItems(actionType)) { + final Set itemConfigSet = configurationSection.getKeys(false); - if (itemStack.getData().equals(soulbindItem.getMaterialData())) { - if (itemStack.hasItemMeta()) { - ItemMeta itemMeta = itemStack.getItemMeta(); - if (soulbindItem.getName() != null) - if (itemMeta.getDisplayName().contains(soulbindItem.getName())) - if (soulbindItem.getLore() != null && !soulbindItem.getLore().isEmpty()) - if (itemMeta.hasLore() - && itemMeta.getLore().containsAll(soulbindItem.getLore())) - return true; + for (final String itemName : itemConfigSet) { + final String[] itemInfo = itemName.split("[|]"); + final Material itemMaterial = Material.matchMaterial(itemInfo[0]); + + if (itemMaterial == null) { + Bukkit.getLogger().warning("[SoulBound] Invalid material name. This item will be skipped. - " + itemInfo[0]); + continue; + } + + final byte itemData = (itemInfo.length == 2) ? Byte.valueOf(itemInfo[1]) : 0; + final MaterialData itemMaterialData = new MaterialData(itemMaterial, itemData); + + final List lore = new ArrayList(); + if (item.contains("Items." + itemName + ".Lore")) { + + for (final String loreEntry : item.getStringList("Items." + itemName + ".Lore")) { + lore.add(ChatColor.translateAlternateColorCodes('&', loreEntry)); + } + } + + String name = null; + if (item.contains("Items." + itemName + ".Name")) { + name = ChatColor.translateAlternateColorCodes('&', item.getString("Items." + itemName + ".Name")); + } + + final SoulbindItem soulbindItem = new SoulbindItem(itemMaterialData, name, lore); + + final List actions = item.getStringList("Items." + itemName + ".Actions"); + + for (final ActionType actionType : ActionType.values()) { + if (actions.contains(actionType.toString())) { + addSoulbindItem(actionType, soulbindItem); } } } - return false; } } diff --git a/src/main/java/com/me/tft_02/soulbound/hooks/EpicBossRecodedListener.java b/src/main/java/com/me/tft_02/soulbound/hooks/EpicBossRecodedListener.java deleted file mode 100644 index 12f4526..0000000 --- a/src/main/java/com/me/tft_02/soulbound/hooks/EpicBossRecodedListener.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.me.tft_02.soulbound.hooks; - -// import me.ThaH3lper.com.Api.BossDeathEvent; - -import org.bukkit.event.Listener; -import org.bukkit.inventory.ItemStack; - -import com.me.tft_02.soulbound.config.Config; -import com.me.tft_02.soulbound.util.ItemUtils; - -public class EpicBossRecodedListener implements Listener { - - public void handleEpicBossItems(final ItemStack itemStack) { - if (Config.getInstance().getEBRBindOnEquip() && ItemUtils.isEquipable(itemStack)) { - ItemUtils.boeItem(itemStack); - } else if (Config.getInstance().getEBRBindOnPickup()) { - ItemUtils.bopItem(itemStack); - } else if (Config.getInstance().getEBRBindOnUse()) { - ItemUtils.bouItem(itemStack); - } - } -} diff --git a/src/main/java/com/me/tft_02/soulbound/listeners/InventoryListener.java b/src/main/java/com/me/tft_02/soulbound/listeners/InventoryListener.java index 366fca6..bed4135 100644 --- a/src/main/java/com/me/tft_02/soulbound/listeners/InventoryListener.java +++ b/src/main/java/com/me/tft_02/soulbound/listeners/InventoryListener.java @@ -43,7 +43,7 @@ public class InventoryListener implements Listener { if (itemType != ItemType.SOULBOUND) { return; } - if (!Config.getInstance().getAllowItemStoring() && !(inventoryType == InventoryType.CRAFTING)) { + if (!Config.getAllowItemStoring() && !(inventoryType == InventoryType.CRAFTING)) { event.setCancelled(true); } if (ItemUtils.isBindedPlayer(player, itemStack) || Permissions.pickupBypass(player)) { @@ -70,7 +70,7 @@ public class InventoryListener implements Listener { } final Player player = (Player) humanEntity; for (final ItemStack itemStack : inventory.getContents()) { - if (itemStack != null && ItemsConfig.getInstance().isActionItem(itemStack, ActionType.OPEN_CHEST)) { + if (itemStack != null && ItemsConfig.isActionItem(itemStack, ActionType.OPEN_CHEST)) { ItemUtils.soulbindItem(player, itemStack); } } @@ -99,7 +99,7 @@ public class InventoryListener implements Listener { } final Player player = (Player) humanEntity; final ItemStack itemStack = event.getRecipe().getResult(); - if (ItemsConfig.getInstance().isActionItem(itemStack, ActionType.CRAFT)) { + if (ItemsConfig.isActionItem(itemStack, ActionType.CRAFT)) { event.getInventory().setResult(ItemUtils.soulbindItem(player, itemStack)); } } diff --git a/src/main/java/com/me/tft_02/soulbound/listeners/PlayerListener.java b/src/main/java/com/me/tft_02/soulbound/listeners/PlayerListener.java index 4f4060f..1cb74e2 100644 --- a/src/main/java/com/me/tft_02/soulbound/listeners/PlayerListener.java +++ b/src/main/java/com/me/tft_02/soulbound/listeners/PlayerListener.java @@ -49,7 +49,7 @@ public class PlayerListener implements Listener { final ItemStack itemStack = player.getItemInHand(); final String command = event.getMessage(); - if (ItemUtils.isSoulbound(itemStack) && Config.getInstance().getBlockedCommands().contains(command)) { + if (ItemUtils.isSoulbound(itemStack) && Config.getBlockedCommands().contains(command)) { player.sendMessage(ChatColor.RED + "You're not allowed to use " + ChatColor.GOLD + command + ChatColor.RED + " command while holding a Soulbound item."); event.setCancelled(true); } @@ -67,7 +67,7 @@ public class PlayerListener implements Listener { final ItemStack inHand = player.getItemInHand(); final String command = event.getMessage(); final String[] args = CommandUtils.extractArgs(command); - if (!ItemUtils.isSoulbound(inHand) && Config.getInstance().getBindCommands().contains(command)) { + if (!ItemUtils.isSoulbound(inHand) && Config.getBindCommands().contains(command)) { ItemUtils.soulbindItem(player, inHand); return; } @@ -136,7 +136,7 @@ public class PlayerListener implements Listener { final Player player = event.getPlayer(); final Item item = event.getItemDrop(); final ItemStack itemStack = item.getItemStack(); - if (Config.getInstance().getPreventItemDrop()) { + if (Config.getPreventItemDrop()) { if (ItemUtils.isSoulbound(itemStack) && ItemUtils.isBindedPlayer(player, itemStack)) { item.setPickupDelay(2 * 20); event.setCancelled(true); @@ -144,12 +144,12 @@ public class PlayerListener implements Listener { } return; } - if (Config.getInstance().getDeleteOnDrop()) { + if (Config.getDeleteOnDrop()) { player.playSound(player.getLocation(), Sound.ITEM_BREAK, 1.0F, 1.0F); event.getItemDrop().remove(); return; } - if (ItemsConfig.getInstance().isActionItem(itemStack, ActionType.DROP_ITEM)) { + if (ItemsConfig.isActionItem(itemStack, ActionType.DROP_ITEM)) { ItemUtils.soulbindItem(player, itemStack); return; } @@ -171,7 +171,7 @@ public class PlayerListener implements Listener { ItemUtils.soulbindItem(player, itemStack); return; } - if (ItemsConfig.getInstance().isActionItem(itemStack, ActionType.PICKUP_ITEM)) { + if (ItemsConfig.isActionItem(itemStack, ActionType.PICKUP_ITEM)) { ItemUtils.soulbindItem(player, itemStack); return; } diff --git a/src/main/java/com/me/tft_02/soulbound/runnables/SoulbindInventoryTask.java b/src/main/java/com/me/tft_02/soulbound/runnables/SoulbindInventoryTask.java index 53ecb9e..1c70023 100644 --- a/src/main/java/com/me/tft_02/soulbound/runnables/SoulbindInventoryTask.java +++ b/src/main/java/com/me/tft_02/soulbound/runnables/SoulbindInventoryTask.java @@ -20,13 +20,13 @@ public class SoulbindInventoryTask extends BukkitRunnable { @Override public void run() { for (ItemStack itemStack : player.getInventory().getContents()) { - if (itemStack != null && ItemsConfig.getInstance().isActionItem(itemStack, actionType)) { + if (itemStack != null && ItemsConfig.isActionItem(itemStack, actionType)) { ItemUtils.soulbindItem(player, itemStack); } } for (ItemStack itemStack : player.getInventory().getArmorContents()) { - if (itemStack != null && ItemsConfig.getInstance().isActionItem(itemStack, actionType)) { + if (itemStack != null && ItemsConfig.isActionItem(itemStack, actionType)) { ItemUtils.soulbindItem(player, itemStack); } } diff --git a/src/main/java/com/me/tft_02/soulbound/util/DurabilityUtils.java b/src/main/java/com/me/tft_02/soulbound/util/DurabilityUtils.java index 1193382..13d6fd0 100644 --- a/src/main/java/com/me/tft_02/soulbound/util/DurabilityUtils.java +++ b/src/main/java/com/me/tft_02/soulbound/util/DurabilityUtils.java @@ -7,7 +7,7 @@ import com.me.tft_02.soulbound.config.Config; public class DurabilityUtils { public static void handleInfiniteDurability(ItemStack itemStack) { - if (Config.getInstance().getInfiniteDurability() && ItemUtils.isSoulbound(itemStack)) { + if (Config.getInfiniteDurability() && ItemUtils.isSoulbound(itemStack)) { itemStack.setDurability((short) 0); return; } diff --git a/src/main/java/com/me/tft_02/soulbound/util/ItemUtils.java b/src/main/java/com/me/tft_02/soulbound/util/ItemUtils.java index ccc9fbe..23b2a31 100644 --- a/src/main/java/com/me/tft_02/soulbound/util/ItemUtils.java +++ b/src/main/java/com/me/tft_02/soulbound/util/ItemUtils.java @@ -51,7 +51,7 @@ public class ItemUtils { itemLore.add(Misc.SOULBOUND_TAG); - if (Config.getInstance().getShowNameInLore()) { + if (Config.getShowNameInLore()) { itemLore.add(player.getName()); }