1
0
mirror of https://e.coding.net/circlecloud/Soulbound.git synced 2024-11-25 02:19:11 +00:00

使用PluginHelper处理配置文件...

Signed-off-by: 502647092 <jtb1@163.com>
This commit is contained in:
502647092 2015-11-24 13:41:56 +08:00
parent 5b62b023a7
commit ad79ccdfc9
13 changed files with 229 additions and 447 deletions

13
pom.xml
View File

@ -5,6 +5,7 @@
<artifactId>Soulbound</artifactId> <artifactId>Soulbound</artifactId>
<version>1.1.12</version> <version>1.1.12</version>
<name>Soulbound</name> <name>Soulbound</name>
<description>Soulbound items for your RPG servers!</description>
<url>https://github.com/TfT-02/Soulbound</url> <url>https://github.com/TfT-02/Soulbound</url>
<issueManagement> <issueManagement>
<system>GitHub</system> <system>GitHub</system>
@ -37,14 +38,9 @@
<artifactSet> <artifactSet>
<includes> <includes>
<include>cn.citycraft:PluginHelper</include> <include>cn.citycraft:PluginHelper</include>
<include>org.mcstats.*:*</include>
</includes> </includes>
</artifactSet> </artifactSet>
<relocations> <relocations>
<relocation>
<pattern>org.mcstats</pattern>
<shadedPattern>${project.groupId}.${project.artifactId}.mcstats</shadedPattern>
</relocation>
<relocation> <relocation>
<pattern>cn.citycraft.PluginHelper</pattern> <pattern>cn.citycraft.PluginHelper</pattern>
<shadedPattern>${project.groupId}.${project.artifactId}</shadedPattern> <shadedPattern>${project.groupId}.${project.artifactId}</shadedPattern>
@ -89,15 +85,8 @@
<type>jar</type> <type>jar</type>
<version>1.0</version> <version>1.0</version>
</dependency> </dependency>
<dependency>
<groupId>org.mcstats.bukkit</groupId>
<artifactId>metrics</artifactId>
<version>R8-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies> </dependencies>
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties> </properties>
<description>Soulbound items for your RPG servers!</description>
</project> </project>

View File

@ -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.commands.UnbindCommand;
import com.me.tft_02.soulbound.config.Config; import com.me.tft_02.soulbound.config.Config;
import com.me.tft_02.soulbound.config.ItemsConfig; 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.BlockListener;
import com.me.tft_02.soulbound.listeners.EntityListener; import com.me.tft_02.soulbound.listeners.EntityListener;
import com.me.tft_02.soulbound.listeners.InventoryListener; import com.me.tft_02.soulbound.listeners.InventoryListener;
@ -25,20 +24,22 @@ import cn.citycraft.PluginHelper.config.FileConfig;
import cn.citycraft.PluginHelper.utils.VersionChecker; import cn.citycraft.PluginHelper.utils.VersionChecker;
public class Soulbound extends JavaPlugin { public class Soulbound extends JavaPlugin {
/* File Paths */ // Checks for hooking into other plugins
private static String mainDirectory; public static boolean epicBossRecodedEnabled = false;
public static boolean loreLocksEnabled = false;
public static Soulbound p; public static Soulbound p;
// Jar Stuff // Jar Stuff
public static File soulbound; public static File soulbound;
// Checks for hooking into other plugins /* File Paths */
public static boolean epicBossRecodedEnabled = false; private static String mainDirectory;
private FileConfig config;
private FileConfig itemcfg;
private FileConfig msgcfg;
public static boolean loreLocksEnabled = false;
FileConfig msgcfg;
FileConfig config;
// Update Check // Update Check
private boolean updateAvailable; private boolean updateAvailable;
@ -80,22 +81,16 @@ public class Soulbound extends JavaPlugin {
loadConfigFiles(); loadConfigFiles();
setupEpicBossRecoded();
registerEvents(); registerEvents();
getCommand("soulbound").setExecutor(new SoulboundCommand()); registerCommands();
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());
new VersionChecker(this); new VersionChecker(this);
} }
@Override @Override
public void onLoad() { public void onLoad() {
itemcfg = new FileConfig(this, "item.yml");
msgcfg = new FileConfig(this, "message.yml"); msgcfg = new FileConfig(this, "message.yml");
config = new FileConfig(this); config = new FileConfig(this);
} }
@ -107,8 +102,17 @@ public class Soulbound extends JavaPlugin {
} }
private void loadConfigFiles() { private void loadConfigFiles() {
Config.getInstance(); Config.load(config);
ItemsConfig.getInstance(); 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() { private void registerEvents() {
@ -119,17 +123,6 @@ public class Soulbound extends JavaPlugin {
pm.registerEvents(new BlockListener(), this); 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() { private void setupFilePaths() {
soulbound = getFile(); soulbound = getFile();
mainDirectory = getDataFolder().getPath() + File.separator; mainDirectory = getDataFolder().getPath() + File.separator;

View File

@ -68,7 +68,7 @@ public class BindCommand implements CommandExecutor {
ItemUtils.soulbindItem(target, itemInHand); 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())); sender.sendMessage(Soulbound.p.getlang("BINDED").replace("%target%", target.getName()));
} }
return true; 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") player.sendMessage(Soulbound.p.getlang("BIND_FULL_INEVNTORY")
.replace("%player%", player.getName()).replace("%target%", target.getName())); .replace("%player%", player.getName()).replace("%target%", target.getName()));
} }

View File

@ -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<String> configKeys = config.getKeys(true);
Set<String> internalConfigKeys = internalConfig.getKeys(true);
boolean needSave = false;
Set<String> oldKeys = new HashSet<String>(configKeys);
oldKeys.removeAll(internalConfigKeys);
Set<String> newKeys = new HashSet<String>(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<String, String> comments = new HashMap<String, String>();
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();
}
}
}
}

View File

@ -3,87 +3,124 @@ package com.me.tft_02.soulbound.config;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
public class Config extends AutoUpdateConfigLoader { import cn.citycraft.PluginHelper.config.FileConfig;
private static Config instance;
private Config() { public class Config {
super("config.yml"); private static FileConfig config;
public static boolean getAllowItemStoring() {
return config.getBoolean("Soulbound.Allow_Item_Storing", true);
} }
public static Config getInstance() { public static List<String> getBindCommands() {
if (instance == null) { return config.getStringList("Soulbound.Commands_Bind_When_Used");
instance = new Config();
} }
return instance; public static List<String> getBlockedCommands() {
return config.getStringList("Soulbound.Blocked_Commands");
} }
@Override public static boolean getConfigOverwriteEnabled() {
protected void loadKeys() {} return config.getBoolean("General.Config_Update_Overwrite", true);
}
/* @formatter:off */ public static boolean getDeleteOnDrop() {
return config.getBoolean("Soulbound.Delete_On_Drop", false);
}
/* GENERAL SETTINGS */ public static List<String> getDiabloDropsBindOnEquipTiers() {
// public String getLocale() { return config.getString("General.Locale", "en_us"); } return getDiabloDropsItemTiers("BindOnEquip");
// 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); }
/* @formatter:on */ public static List<String> getDiabloDropsBindOnPickupTiers() {
return getDiabloDropsItemTiers("BindOnPickup");
}
/* SOULBOUND SETTINGS */ public static List<String> getDiabloDropsBindOnUseTiers() {
public boolean getShowNameInLore() { return config.getBoolean("Soulbound.Show_Name_In_Lore", true); } return getDiabloDropsItemTiers("BindOnUse");
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 List<String> getBlockedCommands() { return config.getStringList("Soulbound.Blocked_Commands"); } public static List<String> getDiabloDropsItemTiers(final String bindType) {
public List<String> getBindCommands() { return config.getStringList("Soulbound.Commands_Bind_When_Used"); } final String[] tiersString = config.getString("Dependency_Plugins.DiabloDrops." + bindType).replaceAll(" ", "").split("[,]");
final List<String> tiers = new ArrayList<String>();
// EpicBossRecoded config settings for (final String tier : tiersString) {
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");}
// DiabloDrops config settings
public List<String> getDiabloDropsBindOnPickupTiers() { return getDiabloDropsItemTiers("BindOnPickup");}
public List<String> getDiabloDropsBindOnUseTiers() { return getDiabloDropsItemTiers("BindOnUse");}
public List<String> getDiabloDropsBindOnEquipTiers() { return getDiabloDropsItemTiers("BindOnEquip"); }
public List<String> getDiabloDropsItemTiers(String bindType) {
String[] tiersString = config.getString("Dependency_Plugins.DiabloDrops." + bindType).replaceAll(" ", "").split("[,]");
List<String> tiers = new ArrayList<String>();
for (String tier : tiersString) {
tiers.add(tier); tiers.add(tier);
} }
return tiers; return tiers;
} }
// LoreLocks config settings public static boolean getEBRBindOnEquip() {
return config.getBoolean("Dependency_Plugins.EpicBossRecoded.BindOnEquip");
}
public boolean getLoreLocksBindKeys() { return config.getBoolean("Dependency_Plugins.LoreLocks.Bind_Keys"); } public static boolean getEBRBindOnPickup() {
return config.getBoolean("Dependency_Plugins.EpicBossRecoded.BindOnPickup");
}
// MythicDrops config settings public static boolean getEBRBindOnUse() {
return config.getBoolean("Dependency_Plugins.EpicBossRecoded.BindOnUse");
}
public List<String> getMythicDropsBindOnPickupTiers() { return getMythicDropsItemTiers("BindOnPickup"); } public static boolean getFeedbackEnabled() {
public List<String> getMythicDropsBindOnUseTiers() { return getMythicDropsItemTiers("BindOnUse"); } return config.getBoolean("Soulbound.Feedback_Messages_Enabled", true);
public List<String> getMythicDropsBindOnEquipTiers() { return getMythicDropsItemTiers("BindOnEquip"); } }
public List<String> getMythicDropsItemTiers(String bindType) { public static boolean getInfiniteDurability() {
String[] tiersString = config.getString("Dependency_Plugins.MythicDrops." + bindType).replaceAll(" ", "").split("[,]"); return config.getBoolean("Soulbound.Infinite_Durability", false);
List<String> tiers = new ArrayList<String>(); }
for (String tier : tiersString) { public static boolean getLoreLocksBindKeys() {
return config.getBoolean("Dependency_Plugins.LoreLocks.Bind_Keys");
}
public static List<String> getMythicDropsBindOnEquipTiers() {
return getMythicDropsItemTiers("BindOnEquip");
}
public static List<String> getMythicDropsBindOnPickupTiers() {
return getMythicDropsItemTiers("BindOnPickup");
}
public static List<String> getMythicDropsBindOnUseTiers() {
return getMythicDropsItemTiers("BindOnUse");
}
public static List<String> getMythicDropsItemTiers(final String bindType) {
final String[] tiersString = config.getString("Dependency_Plugins.MythicDrops." + bindType).replaceAll(" ", "").split("[,]");
final List<String> tiers = new ArrayList<String>();
for (final String tier : tiersString) {
tiers.add(tier); tiers.add(tier);
} }
return tiers; 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;
}
} }

View File

@ -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();
}
}
}
}

View File

@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection; 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.ActionType;
import com.me.tft_02.soulbound.datatypes.SoulbindItem; import com.me.tft_02.soulbound.datatypes.SoulbindItem;
public class ItemsConfig extends ConfigLoader { import cn.citycraft.PluginHelper.config.FileConfig;
private static ItemsConfig instance;
private List<SoulbindItem> soulbindOnCraft = new ArrayList<SoulbindItem>(); public class ItemsConfig {
private List<SoulbindItem> soulbindOnOpenChest = new ArrayList<SoulbindItem>(); private static FileConfig item;
private List<SoulbindItem> soulbindOnPickupItem = new ArrayList<SoulbindItem>(); private final static List<SoulbindItem> soulbindOnCraft = new ArrayList<SoulbindItem>();
private List<SoulbindItem> soulbindOnDrop = new ArrayList<SoulbindItem>(); private final static List<SoulbindItem> soulbindOnDrop = new ArrayList<SoulbindItem>();
private List<SoulbindItem> soulbindOnRespawn = new ArrayList<SoulbindItem>(); private final static List<SoulbindItem> soulbindOnKit = new ArrayList<SoulbindItem>();
private List<SoulbindItem> soulbindOnKit = new ArrayList<SoulbindItem>(); private final static List<SoulbindItem> soulbindOnOpenChest = new ArrayList<SoulbindItem>();
private final static List<SoulbindItem> soulbindOnPickupItem = new ArrayList<SoulbindItem>();
private final static List<SoulbindItem> soulbindOnRespawn = new ArrayList<SoulbindItem>();
public ItemsConfig() { public ItemsConfig() {
super("items.yml");
loadKeys(); loadKeys();
} }
public static ItemsConfig getInstance() { public static List<SoulbindItem> getSoulbindItems(final ActionType actionType) {
if (instance == null) { switch (actionType) {
instance = new ItemsConfig(); case CRAFT:
} return soulbindOnCraft;
case OPEN_CHEST:
return instance; return soulbindOnOpenChest;
} case PICKUP_ITEM:
return soulbindOnPickupItem;
@SuppressWarnings("deprecation") case DROP_ITEM:
@Override return soulbindOnDrop;
protected void loadKeys() { case RESPAWN:
ConfigurationSection configurationSection = config.getConfigurationSection("Items"); return soulbindOnRespawn;
case KIT:
if (configurationSection == null) { return soulbindOnKit;
return; default:
} return null;
Set<String> 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<String> lore = new ArrayList<String>();
if (config.contains("Items." + itemName + ".Lore")) {
for (String loreEntry : config.getStringList("Items." + itemName + ".Lore")) {
lore.add(ChatColor.translateAlternateColorCodes('&', loreEntry));
} }
} }
String name = null; public static boolean isActionItem(final ItemStack itemStack, final ActionType actionType) {
if (config.contains("Items." + itemName + ".Name")) { for (final SoulbindItem soulbindItem : getSoulbindItems(actionType)) {
name = ChatColor.translateAlternateColorCodes('&',
config.getString("Items." + itemName + ".Name"));
}
SoulbindItem soulbindItem = new SoulbindItem(itemMaterialData, name, lore); if (itemStack.getData().equals(soulbindItem.getMaterialData())) {
if (itemStack.hasItemMeta()) {
List<String> actions = config.getStringList("Items." + itemName + ".Actions"); final ItemMeta itemMeta = itemStack.getItemMeta();
if (soulbindItem.getName() != null) {
for (ActionType actionType : ActionType.values()) { if (itemMeta.getDisplayName().contains(soulbindItem.getName())) {
if (actions.contains(actionType.toString())) { if (soulbindItem.getLore() != null && !soulbindItem.getLore().isEmpty()) {
addSoulbindItem(actionType, soulbindItem); if (itemMeta.hasLore() && itemMeta.getLore().containsAll(soulbindItem.getLore())) {
return true;
} }
} }
} }
} }
private void addSoulbindItem(ActionType actionType, SoulbindItem soulbindItem) { }
}
}
return false;
}
public static void load(final FileConfig config) {
item = config;
}
private void addSoulbindItem(final ActionType actionType, final SoulbindItem soulbindItem) {
switch (actionType) { switch (actionType) {
case CRAFT: case CRAFT:
soulbindOnCraft.add(soulbindItem); soulbindOnCraft.add(soulbindItem);
@ -111,41 +98,51 @@ public class ItemsConfig extends ConfigLoader {
} }
} }
public List<SoulbindItem> getSoulbindItems(ActionType actionType) { @SuppressWarnings("deprecation")
switch (actionType) { protected void loadKeys() {
case CRAFT: final ConfigurationSection configurationSection = item.getConfigurationSection("Items");
return soulbindOnCraft;
case OPEN_CHEST: if (configurationSection == null) {
return soulbindOnOpenChest; return;
case PICKUP_ITEM: }
return soulbindOnPickupItem;
case DROP_ITEM: final Set<String> itemConfigSet = configurationSection.getKeys(false);
return soulbindOnDrop;
case RESPAWN: for (final String itemName : itemConfigSet) {
return soulbindOnRespawn; final String[] itemInfo = itemName.split("[|]");
case KIT:
return soulbindOnKit; final Material itemMaterial = Material.matchMaterial(itemInfo[0]);
default:
return null; 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<String> lore = new ArrayList<String>();
if (item.contains("Items." + itemName + ".Lore")) {
for (final String loreEntry : item.getStringList("Items." + itemName + ".Lore")) {
lore.add(ChatColor.translateAlternateColorCodes('&', loreEntry));
} }
} }
public boolean isActionItem(ItemStack itemStack, ActionType actionType) { String name = null;
for (SoulbindItem soulbindItem : getSoulbindItems(actionType)) { if (item.contains("Items." + itemName + ".Name")) {
name = ChatColor.translateAlternateColorCodes('&', item.getString("Items." + itemName + ".Name"));
}
if (itemStack.getData().equals(soulbindItem.getMaterialData())) { final SoulbindItem soulbindItem = new SoulbindItem(itemMaterialData, name, lore);
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;
final List<String> actions = item.getStringList("Items." + itemName + ".Actions");
for (final ActionType actionType : ActionType.values()) {
if (actions.contains(actionType.toString())) {
addSoulbindItem(actionType, soulbindItem);
} }
} }
} }
return false;
} }
} }

View File

@ -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);
}
}
}

View File

@ -43,7 +43,7 @@ public class InventoryListener implements Listener {
if (itemType != ItemType.SOULBOUND) { if (itemType != ItemType.SOULBOUND) {
return; return;
} }
if (!Config.getInstance().getAllowItemStoring() && !(inventoryType == InventoryType.CRAFTING)) { if (!Config.getAllowItemStoring() && !(inventoryType == InventoryType.CRAFTING)) {
event.setCancelled(true); event.setCancelled(true);
} }
if (ItemUtils.isBindedPlayer(player, itemStack) || Permissions.pickupBypass(player)) { if (ItemUtils.isBindedPlayer(player, itemStack) || Permissions.pickupBypass(player)) {
@ -70,7 +70,7 @@ public class InventoryListener implements Listener {
} }
final Player player = (Player) humanEntity; final Player player = (Player) humanEntity;
for (final ItemStack itemStack : inventory.getContents()) { 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); ItemUtils.soulbindItem(player, itemStack);
} }
} }
@ -99,7 +99,7 @@ public class InventoryListener implements Listener {
} }
final Player player = (Player) humanEntity; final Player player = (Player) humanEntity;
final ItemStack itemStack = event.getRecipe().getResult(); 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)); event.getInventory().setResult(ItemUtils.soulbindItem(player, itemStack));
} }
} }

View File

@ -49,7 +49,7 @@ public class PlayerListener implements Listener {
final ItemStack itemStack = player.getItemInHand(); final ItemStack itemStack = player.getItemInHand();
final String command = event.getMessage(); 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."); player.sendMessage(ChatColor.RED + "You're not allowed to use " + ChatColor.GOLD + command + ChatColor.RED + " command while holding a Soulbound item.");
event.setCancelled(true); event.setCancelled(true);
} }
@ -67,7 +67,7 @@ public class PlayerListener implements Listener {
final ItemStack inHand = player.getItemInHand(); final ItemStack inHand = player.getItemInHand();
final String command = event.getMessage(); final String command = event.getMessage();
final String[] args = CommandUtils.extractArgs(command); 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); ItemUtils.soulbindItem(player, inHand);
return; return;
} }
@ -136,7 +136,7 @@ public class PlayerListener implements Listener {
final Player player = event.getPlayer(); final Player player = event.getPlayer();
final Item item = event.getItemDrop(); final Item item = event.getItemDrop();
final ItemStack itemStack = item.getItemStack(); final ItemStack itemStack = item.getItemStack();
if (Config.getInstance().getPreventItemDrop()) { if (Config.getPreventItemDrop()) {
if (ItemUtils.isSoulbound(itemStack) && ItemUtils.isBindedPlayer(player, itemStack)) { if (ItemUtils.isSoulbound(itemStack) && ItemUtils.isBindedPlayer(player, itemStack)) {
item.setPickupDelay(2 * 20); item.setPickupDelay(2 * 20);
event.setCancelled(true); event.setCancelled(true);
@ -144,12 +144,12 @@ public class PlayerListener implements Listener {
} }
return; return;
} }
if (Config.getInstance().getDeleteOnDrop()) { if (Config.getDeleteOnDrop()) {
player.playSound(player.getLocation(), Sound.ITEM_BREAK, 1.0F, 1.0F); player.playSound(player.getLocation(), Sound.ITEM_BREAK, 1.0F, 1.0F);
event.getItemDrop().remove(); event.getItemDrop().remove();
return; return;
} }
if (ItemsConfig.getInstance().isActionItem(itemStack, ActionType.DROP_ITEM)) { if (ItemsConfig.isActionItem(itemStack, ActionType.DROP_ITEM)) {
ItemUtils.soulbindItem(player, itemStack); ItemUtils.soulbindItem(player, itemStack);
return; return;
} }
@ -171,7 +171,7 @@ public class PlayerListener implements Listener {
ItemUtils.soulbindItem(player, itemStack); ItemUtils.soulbindItem(player, itemStack);
return; return;
} }
if (ItemsConfig.getInstance().isActionItem(itemStack, ActionType.PICKUP_ITEM)) { if (ItemsConfig.isActionItem(itemStack, ActionType.PICKUP_ITEM)) {
ItemUtils.soulbindItem(player, itemStack); ItemUtils.soulbindItem(player, itemStack);
return; return;
} }

View File

@ -20,13 +20,13 @@ public class SoulbindInventoryTask extends BukkitRunnable {
@Override @Override
public void run() { public void run() {
for (ItemStack itemStack : player.getInventory().getContents()) { 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); ItemUtils.soulbindItem(player, itemStack);
} }
} }
for (ItemStack itemStack : player.getInventory().getArmorContents()) { 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); ItemUtils.soulbindItem(player, itemStack);
} }
} }

View File

@ -7,7 +7,7 @@ import com.me.tft_02.soulbound.config.Config;
public class DurabilityUtils { public class DurabilityUtils {
public static void handleInfiniteDurability(ItemStack itemStack) { public static void handleInfiniteDurability(ItemStack itemStack) {
if (Config.getInstance().getInfiniteDurability() && ItemUtils.isSoulbound(itemStack)) { if (Config.getInfiniteDurability() && ItemUtils.isSoulbound(itemStack)) {
itemStack.setDurability((short) 0); itemStack.setDurability((short) 0);
return; return;
} }

View File

@ -51,7 +51,7 @@ public class ItemUtils {
itemLore.add(Misc.SOULBOUND_TAG); itemLore.add(Misc.SOULBOUND_TAG);
if (Config.getInstance().getShowNameInLore()) { if (Config.getShowNameInLore()) {
itemLore.add(player.getName()); itemLore.add(player.getName());
} }