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:
parent
5b62b023a7
commit
ad79ccdfc9
13
pom.xml
13
pom.xml
@ -5,6 +5,7 @@
|
||||
<artifactId>Soulbound</artifactId>
|
||||
<version>1.1.12</version>
|
||||
<name>Soulbound</name>
|
||||
<description>Soulbound items for your RPG servers!</description>
|
||||
<url>https://github.com/TfT-02/Soulbound</url>
|
||||
<issueManagement>
|
||||
<system>GitHub</system>
|
||||
@ -37,14 +38,9 @@
|
||||
<artifactSet>
|
||||
<includes>
|
||||
<include>cn.citycraft:PluginHelper</include>
|
||||
<include>org.mcstats.*:*</include>
|
||||
</includes>
|
||||
</artifactSet>
|
||||
<relocations>
|
||||
<relocation>
|
||||
<pattern>org.mcstats</pattern>
|
||||
<shadedPattern>${project.groupId}.${project.artifactId}.mcstats</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>cn.citycraft.PluginHelper</pattern>
|
||||
<shadedPattern>${project.groupId}.${project.artifactId}</shadedPattern>
|
||||
@ -89,15 +85,8 @@
|
||||
<type>jar</type>
|
||||
<version>1.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mcstats.bukkit</groupId>
|
||||
<artifactId>metrics</artifactId>
|
||||
<version>R8-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<description>Soulbound items for your RPG servers!</description>
|
||||
</project>
|
||||
|
@ -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;
|
||||
|
@ -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()));
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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 boolean getAllowItemStoring() {
|
||||
return config.getBoolean("Soulbound.Allow_Item_Storing", true);
|
||||
}
|
||||
|
||||
public static Config getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new Config();
|
||||
public static List<String> getBindCommands() {
|
||||
return config.getStringList("Soulbound.Commands_Bind_When_Used");
|
||||
}
|
||||
|
||||
return instance;
|
||||
public static List<String> getBlockedCommands() {
|
||||
return config.getStringList("Soulbound.Blocked_Commands");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadKeys() {}
|
||||
public static boolean getConfigOverwriteEnabled() {
|
||||
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 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 List<String> getDiabloDropsBindOnEquipTiers() {
|
||||
return getDiabloDropsItemTiers("BindOnEquip");
|
||||
}
|
||||
|
||||
/* @formatter:on */
|
||||
public static List<String> getDiabloDropsBindOnPickupTiers() {
|
||||
return getDiabloDropsItemTiers("BindOnPickup");
|
||||
}
|
||||
|
||||
/* 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<String> getDiabloDropsBindOnUseTiers() {
|
||||
return getDiabloDropsItemTiers("BindOnUse");
|
||||
}
|
||||
|
||||
public List<String> getBlockedCommands() { return config.getStringList("Soulbound.Blocked_Commands"); }
|
||||
public List<String> getBindCommands() { return config.getStringList("Soulbound.Commands_Bind_When_Used"); }
|
||||
public static List<String> getDiabloDropsItemTiers(final String bindType) {
|
||||
final String[] tiersString = config.getString("Dependency_Plugins.DiabloDrops." + bindType).replaceAll(" ", "").split("[,]");
|
||||
final List<String> tiers = new ArrayList<String>();
|
||||
|
||||
// EpicBossRecoded config settings
|
||||
|
||||
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) {
|
||||
for (final String tier : tiersString) {
|
||||
tiers.add(tier);
|
||||
}
|
||||
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 List<String> getMythicDropsBindOnUseTiers() { return getMythicDropsItemTiers("BindOnUse"); }
|
||||
public List<String> getMythicDropsBindOnEquipTiers() { return getMythicDropsItemTiers("BindOnEquip"); }
|
||||
public static boolean getFeedbackEnabled() {
|
||||
return config.getBoolean("Soulbound.Feedback_Messages_Enabled", true);
|
||||
}
|
||||
|
||||
public List<String> getMythicDropsItemTiers(String bindType) {
|
||||
String[] tiersString = config.getString("Dependency_Plugins.MythicDrops." + bindType).replaceAll(" ", "").split("[,]");
|
||||
List<String> tiers = new ArrayList<String>();
|
||||
public static boolean getInfiniteDurability() {
|
||||
return config.getBoolean("Soulbound.Infinite_Durability", false);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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<SoulbindItem> soulbindOnCraft = new ArrayList<SoulbindItem>();
|
||||
private List<SoulbindItem> soulbindOnOpenChest = new ArrayList<SoulbindItem>();
|
||||
private List<SoulbindItem> soulbindOnPickupItem = new ArrayList<SoulbindItem>();
|
||||
private List<SoulbindItem> soulbindOnDrop = new ArrayList<SoulbindItem>();
|
||||
private List<SoulbindItem> soulbindOnRespawn = new ArrayList<SoulbindItem>();
|
||||
private List<SoulbindItem> soulbindOnKit = new ArrayList<SoulbindItem>();
|
||||
public class ItemsConfig {
|
||||
private static FileConfig item;
|
||||
private final static List<SoulbindItem> soulbindOnCraft = new ArrayList<SoulbindItem>();
|
||||
private final static List<SoulbindItem> soulbindOnDrop = new ArrayList<SoulbindItem>();
|
||||
private final static 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() {
|
||||
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<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));
|
||||
public static List<SoulbindItem> 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;
|
||||
}
|
||||
}
|
||||
|
||||
String name = null;
|
||||
if (config.contains("Items." + itemName + ".Name")) {
|
||||
name = ChatColor.translateAlternateColorCodes('&',
|
||||
config.getString("Items." + itemName + ".Name"));
|
||||
}
|
||||
public static boolean isActionItem(final ItemStack itemStack, final ActionType actionType) {
|
||||
for (final SoulbindItem soulbindItem : getSoulbindItems(actionType)) {
|
||||
|
||||
SoulbindItem soulbindItem = new SoulbindItem(itemMaterialData, name, lore);
|
||||
|
||||
List<String> actions = config.getStringList("Items." + itemName + ".Actions");
|
||||
|
||||
for (ActionType actionType : ActionType.values()) {
|
||||
if (actions.contains(actionType.toString())) {
|
||||
addSoulbindItem(actionType, soulbindItem);
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
case CRAFT:
|
||||
soulbindOnCraft.add(soulbindItem);
|
||||
@ -111,41 +98,51 @@ public class ItemsConfig extends ConfigLoader {
|
||||
}
|
||||
}
|
||||
|
||||
public List<SoulbindItem> 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;
|
||||
}
|
||||
|
||||
final Set<String> itemConfigSet = configurationSection.getKeys(false);
|
||||
|
||||
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<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) {
|
||||
for (SoulbindItem soulbindItem : getSoulbindItems(actionType)) {
|
||||
String name = null;
|
||||
if (item.contains("Items." + itemName + ".Name")) {
|
||||
name = ChatColor.translateAlternateColorCodes('&', item.getString("Items." + itemName + ".Name"));
|
||||
}
|
||||
|
||||
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;
|
||||
final SoulbindItem soulbindItem = new SoulbindItem(itemMaterialData, name, lore);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ public class ItemUtils {
|
||||
|
||||
itemLore.add(Misc.SOULBOUND_TAG);
|
||||
|
||||
if (Config.getInstance().getShowNameInLore()) {
|
||||
if (Config.getShowNameInLore()) {
|
||||
itemLore.add(player.getName());
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user