1
0
mirror of https://e.coding.net/circlecloud/Soulbound.git synced 2025-11-25 21:46:20 +00:00

初始化项目...

Signed-off-by: j502647092 <jtb1@163.com>
This commit is contained in:
j502647092
2015-04-29 10:04:46 +08:00
commit 70d7d7f6a0
41 changed files with 3566 additions and 0 deletions

View File

@@ -0,0 +1,136 @@
package com.me.tft_02.soulbound;
import java.io.File;
import net.gravitydevelopment.updater.soulbound.Updater;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import com.me.tft_02.soulbound.commands.BindCommand;
import com.me.tft_02.soulbound.commands.BindOnEquipCommand;
import com.me.tft_02.soulbound.commands.BindOnPickupCommand;
import com.me.tft_02.soulbound.commands.BindOnUseCommand;
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;
import com.me.tft_02.soulbound.listeners.PlayerListener;
import com.me.tft_02.soulbound.util.LogFilter;
public class Soulbound extends JavaPlugin {
/* File Paths */
private static String mainDirectory;
public static Soulbound p;
// Jar Stuff
public static File soulbound;
// Checks for hooking into other plugins
public static boolean epicBossRecodedEnabled = false;
public static boolean loreLocksEnabled = false;
public static boolean mythicDropsEnabled = false;
// Update Check
private boolean updateAvailable;
/**
* Run things on enable.
*/
@Override
public void onEnable() {
p = this;
getLogger().setFilter(new LogFilter(this));
setupFilePaths();
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());
checkForUpdates();
}
private void registerEvents() {
PluginManager pm = getServer().getPluginManager();
pm.registerEvents(new PlayerListener(), this);
pm.registerEvents(new InventoryListener(), this);
pm.registerEvents(new EntityListener(), 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);
}
}
/**
* Run things on disable.
*/
@Override
public void onDisable() {}
public static String getMainDirectory() {
return mainDirectory;
}
public boolean isUpdateAvailable() {
return updateAvailable;
}
public void debug(String message) {
getLogger().info("[Debug] " + message);
}
/**
* Setup the various storage file paths
*/
private void setupFilePaths() {
soulbound = getFile();
mainDirectory = getDataFolder().getPath() + File.separator;
}
private void loadConfigFiles() {
Config.getInstance();
ItemsConfig.getInstance();
}
private void checkForUpdates() {
if (!Config.getInstance().getUpdateCheckEnabled()) {
return;
}
Updater updater = new Updater(this, 53483, soulbound, Updater.UpdateType.NO_DOWNLOAD, false);
if (updater.getResult() != Updater.UpdateResult.UPDATE_AVAILABLE) {
this.updateAvailable = false;
return;
}
if (updater.getLatestType().equals("beta") && !Config.getInstance().getPreferBeta()) {
this.updateAvailable = false;
return;
}
this.updateAvailable = true;
getLogger().info("Soulbound is outdated!");
getLogger().info("http://dev.bukkit.org/server-mods/soulbound/");
}
}

View File

@@ -0,0 +1,116 @@
package com.me.tft_02.soulbound.api;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import com.me.tft_02.soulbound.util.ItemUtils;
public final class ItemAPI {
private ItemAPI() {}
/**
* Check if a Player is binded to an ItemStack.
* </br>
* This function is designed for API usage.
*
* @param player The Player to check
* @param itemStack The ItemStack to check
*
* @return true or false
*/
public static boolean isSoulbindedPlayer(Player player, ItemStack itemStack) {
return ItemUtils.isBindedPlayer(player, itemStack);
}
/**
* Soulbind an ItemStack to a Player.
* </br>
* This function is designed for API usage.
*
* @param player The Player to bind the item to
* @param itemStack The ItemStack to bind
*
* @return the soulbound ItemStack
*/
public static ItemStack soulbindItem(Player player, ItemStack itemStack) {
return ItemUtils.soulbindItem(player, itemStack);
}
/**
* Check if an itemstack is Soulbound.
* </br>
* This function is designed for API usage.
*
* @param itemStack The itemstack to check
*
* @return true or false
*/
public static boolean isSoulbound(ItemStack itemStack) {
return ItemUtils.isSoulbound(itemStack);
}
/**
* Mark an itemstack as Bind on Pickup
* </br>
* This function is designed for API usage.
*
* @param itemStack The itemstack to mark as Bind on Pickup
*
* @return the marked itemstack
*/
public static ItemStack bindOnPickupItem(ItemStack itemStack) {
return ItemUtils.bopItem(itemStack);
}
/**
* Check if an itemstack is Bind on Pickup.
* </br>
* This function is designed for API usage.
*
* @param itemStack The itemstack to check
*
* @return true or false
*/
public static boolean isBindOnPickup(ItemStack itemStack) {
return ItemUtils.isBindOnPickup(itemStack);
}
/**
* Mark an itemstack as Bind on Use
* </br>
* This function is designed for API usage.
*
* @param itemStack The itemstack to mark as Bind on Use
*
* @return the marked itemstack
*/
public static ItemStack bindOnUseItem(ItemStack itemStack) {
return ItemUtils.bouItem(itemStack);
}
/**
* Mark an itemstack as Bind on Equip
* </br>
* This function is designed for API usage.
*
* @param itemStack The itemstack to mark as Bind on Equip
*
* @return the marked itemstack
*/
public static ItemStack bindOnEquipItem(ItemStack itemStack) {
return ItemUtils.boeItem(itemStack);
}
/**
* Get the Soulbound type of an itemstack.
* </br>
* This function is designed for API usage.
*
* @param itemStack The itemstack to check
*
* @return the Bind type
*/
public static String getItemType(ItemStack itemStack) {
return ItemUtils.getItemType(itemStack).toString();
}
}

View File

@@ -0,0 +1,92 @@
package com.me.tft_02.soulbound.commands;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import com.me.tft_02.soulbound.Soulbound;
import com.me.tft_02.soulbound.config.Config;
import com.me.tft_02.soulbound.util.CommandUtils;
import com.me.tft_02.soulbound.util.ItemUtils;
public class BindCommand implements CommandExecutor {
String soulbound = ChatColor.GOLD + "Soulbound ";
@SuppressWarnings("deprecation")
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (CommandUtils.noConsoleUsage(sender)) {
return true;
}
if (!sender.hasPermission("soulbound.commands.bind")) {
return false;
}
boolean bindFullInventory = false;
Player player = (Player) sender;
Player target;
switch (args.length) {
case 1:
target = Soulbound.p.getServer().getPlayerExact(args[0]);
if (CommandUtils.isOffline(sender, target)) {
return true;
}
break;
case 2:
if (!args[1].equalsIgnoreCase("inventory")) {
sender.sendMessage(ChatColor.RED + "Proper usage: " + ChatColor.GREEN + "/bind <player> inventory");
return true;
}
bindFullInventory = true;
target = Soulbound.p.getServer().getPlayerExact(args[0]);
if (CommandUtils.isOffline(sender, target)) {
return true;
}
break;
default:
target = player;
}
if (bindFullInventory) {
return handleBindFullInventory(player, target);
}
ItemStack itemInHand = player.getItemInHand();
if ((itemInHand.getType() == Material.AIR) || ItemUtils.isSoulbound(itemInHand)) {
sender.sendMessage(ChatColor.GRAY + "You can't " + soulbound + ChatColor.GRAY + "this item.");
return false;
}
ItemUtils.soulbindItem(target, itemInHand);
if (ItemUtils.isSoulbound(itemInHand) && Config.getInstance().getFeedbackEnabled()) {
sender.sendMessage(ChatColor.GRAY + "Item is now " + soulbound + ChatColor.GRAY + "to " + ChatColor.DARK_AQUA + target.getName());
}
return true;
}
private boolean handleBindFullInventory(Player player, Player target) {
for (ItemStack itemStack : player.getInventory().getContents()) {
if (itemStack != null && itemStack.getType() != Material.AIR) {
ItemUtils.soulbindItem(target, itemStack);
}
}
if (Config.getInstance().getFeedbackEnabled()) {
player.sendMessage(ChatColor.GRAY + "All items in " + ChatColor.DARK_AQUA + target.getName() + ChatColor.GRAY + "'s inventory are now " + soulbound + ChatColor.GRAY + "to " + ChatColor.DARK_AQUA + target.getName());
}
return true;
}
}

View File

@@ -0,0 +1,51 @@
package com.me.tft_02.soulbound.commands;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import com.me.tft_02.soulbound.util.CommandUtils;
import com.me.tft_02.soulbound.util.ItemUtils;
public class BindOnEquipCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (CommandUtils.noConsoleUsage(sender)) {
return true;
}
switch (args.length) {
case 0:
Player player = (Player) sender;
if (!player.hasPermission("soulbound.commands.bindonequip")) {
return false;
}
ItemStack itemInHand = player.getItemInHand();
if ((itemInHand.getType() == Material.AIR) || ItemUtils.isSoulbound(itemInHand)) {
player.sendMessage(ChatColor.GRAY + "You can't " + ChatColor.GOLD + "Soulbound " + ChatColor.GRAY + "this item.");
return false;
}
ItemUtils.unbindItem(itemInHand);
ItemUtils.boeItem(itemInHand);
if (ItemUtils.isBindOnEquip(itemInHand)) {
player.sendMessage(ChatColor.GRAY + "Item is now " + ChatColor.DARK_RED + "Bind on Equip");
}
else {
player.sendMessage(ChatColor.RED + "Cannot mark this item as " + ChatColor.DARK_RED + "Bind on Equip");
}
return true;
default:
return false;
}
}
}

View File

@@ -0,0 +1,45 @@
package com.me.tft_02.soulbound.commands;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import com.me.tft_02.soulbound.util.CommandUtils;
import com.me.tft_02.soulbound.util.ItemUtils;
public class BindOnPickupCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (CommandUtils.noConsoleUsage(sender)) {
return true;
}
switch (args.length) {
case 0:
Player player = (Player) sender;
if (!player.hasPermission("soulbound.commands.bindonpickup")) {
return false;
}
ItemStack itemInHand = player.getItemInHand();
if ((itemInHand.getType() == Material.AIR) || ItemUtils.isSoulbound(itemInHand)) {
player.sendMessage(ChatColor.GRAY + "You can't " + ChatColor.GOLD + "Soulbound " + ChatColor.GRAY + "this item.");
return false;
}
ItemUtils.unbindItem(itemInHand);
ItemUtils.bopItem(itemInHand);
player.sendMessage(ChatColor.GRAY + "Item is now " + ChatColor.DARK_RED + "Bind on pickup");
return true;
default:
return false;
}
}
}

View File

@@ -0,0 +1,45 @@
package com.me.tft_02.soulbound.commands;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import com.me.tft_02.soulbound.util.CommandUtils;
import com.me.tft_02.soulbound.util.ItemUtils;
public class BindOnUseCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (CommandUtils.noConsoleUsage(sender)) {
return true;
}
switch (args.length) {
case 0:
Player player = (Player) sender;
if (!player.hasPermission("soulbound.commands.bindonuse")) {
return false;
}
ItemStack itemInHand = player.getItemInHand();
if ((itemInHand.getType() == Material.AIR) || ItemUtils.isSoulbound(itemInHand)) {
player.sendMessage(ChatColor.GRAY + "You can't " + ChatColor.GOLD + "Soulbound " + ChatColor.GRAY + "this item.");
return false;
}
ItemUtils.unbindItem(itemInHand);
ItemUtils.bouItem(itemInHand);
player.sendMessage(ChatColor.GRAY + "Item is now " + ChatColor.DARK_RED + "Bind on Use");
return true;
default:
return false;
}
}
}

View File

@@ -0,0 +1,134 @@
package com.me.tft_02.soulbound.commands;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import com.me.tft_02.soulbound.Soulbound;
public class SoulboundCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command,
String label, String[] args) {
switch (args.length) {
case 0:
sender.sendMessage("Soulbound version "
+ Soulbound.p.getDescription().getVersion());
return printUsage(sender);
case 1:
if (args[0].equalsIgnoreCase("reload")) {
return reloadConfiguration(sender);
}
default:
if (args[0].equalsIgnoreCase("help")
|| args[0].equalsIgnoreCase("?")) {
return helpPages(sender, args);
}
return false;
}
}
private boolean reloadConfiguration(CommandSender sender) {
if (sender instanceof Player
&& !sender.hasPermission("soulbound.commands.reload")) {
return false;
}
Soulbound.p.reloadConfig();
sender.sendMessage(ChatColor.GREEN + "Configuration reloaded.");
return false;
}
private boolean helpPages(CommandSender sender, String[] args) {
if (!(sender instanceof Player)) {
sender.sendMessage("Can't use this from the console, sorry!");
return false;
}
if (args.length >= 2 && Integer.parseInt(args[1]) > 0) {
getHelpPage(Integer.parseInt(args[1]), sender);
return true;
}
return false;
}
private void getHelpPage(int page, CommandSender sender) {
int maxPages = 2;
int nextPage = page + 1;
if (page > maxPages) {
sender.sendMessage(ChatColor.RED + "This page does not exist."
+ ChatColor.GOLD + " /help [0-" + maxPages + "]");
return;
}
String dot = ChatColor.DARK_RED + "* ";
sender.sendMessage(ChatColor.GRAY + "-----[ " + ChatColor.GOLD
+ "Soulbound Help" + ChatColor.GRAY + " ]----- Page " + page
+ "/" + maxPages);
if (page == 1) {
sender.sendMessage(ChatColor.GOLD + "How does it work?");
sender.sendMessage(dot
+ ChatColor.GRAY
+ "Soulbound items are special items which are bound to a sender.");
sender.sendMessage(dot
+ ChatColor.GRAY
+ "Players are prevented from doing certain actions with Soulbound items, such as:");
sender.sendMessage(dot
+ ChatColor.GRAY
+ "dropping them on the ground, storing them in chests or giving them to other players.");
sender.sendMessage(dot
+ ChatColor.GRAY
+ "Items marked as 'Bind on Pickup' will get Soulbound as soon as they get picked up.");
sender.sendMessage(dot
+ ChatColor.GRAY
+ "Items marked as 'Bind on Use' will get Soulbound as soon as they get used.");
sender.sendMessage(dot
+ ChatColor.GRAY
+ "Items marked as 'Bind on Equip' will get Soulbound as soon as they get equipped.");
}
if (page == 2) {
sender.sendMessage(ChatColor.GOLD + "Commands:");
if (sender.hasPermission("soulbound.commands.bindonpickup")) {
sender.sendMessage(dot + ChatColor.GREEN + "/soulbound"
+ ChatColor.GRAY + " Check the status of the plugin.");
}
if (sender.hasPermission("soulbound.commands.bind")) {
sender.sendMessage(dot + ChatColor.GREEN + "/bind <sender>"
+ ChatColor.GRAY
+ " Soulbound the item currently in hand.");
sender.sendMessage(dot + ChatColor.GREEN
+ "/bind <sender> inventory" + ChatColor.GRAY
+ " Soulbound an entire inventory.");
}
if (sender.hasPermission("soulbound.commands.bindonpickup")) {
sender.sendMessage(dot + ChatColor.GREEN + "/bindonpickup"
+ ChatColor.GRAY
+ " Mark the item in hand as 'Bind on Pickup'");
}
if (sender.hasPermission("soulbound.commands.bindonuse")) {
sender.sendMessage(dot + ChatColor.GREEN + "/bindonuse"
+ ChatColor.GRAY
+ " Mark the item in hand as 'Bind on Use'");
}
if (sender.hasPermission("soulbound.commands.bindonequip")) {
sender.sendMessage(dot + ChatColor.GREEN + "/bindonequip"
+ ChatColor.GRAY
+ " Mark the item in hand as 'Bind on Equip'");
}
if (sender.hasPermission("soulbound.commands.unbind")) {
sender.sendMessage(dot + ChatColor.GREEN + "/unbind"
+ ChatColor.GRAY + " Unbind the item in hand.");
}
}
if (nextPage <= maxPages) {
sender.sendMessage(ChatColor.GOLD + "Type /soulbound help "
+ nextPage + " for more");
}
}
private boolean printUsage(CommandSender sender) {
sender.sendMessage("Usage: /soulbound [reload | help]");
return false;
}
}

View File

@@ -0,0 +1,47 @@
package com.me.tft_02.soulbound.commands;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import com.me.tft_02.soulbound.util.CommandUtils;
import com.me.tft_02.soulbound.util.ItemUtils;
public class UnbindCommand implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (CommandUtils.noConsoleUsage(sender)) {
return true;
}
switch (args.length) {
case 0:
Player player = (Player) sender;
if (!player.hasPermission("soulbound.commands.unbind")) {
return false;
}
ItemStack itemInHand = player.getItemInHand();
if ((itemInHand.getType() == Material.AIR) || !ItemUtils.isSoulbound(itemInHand)) {
player.sendMessage(ChatColor.GRAY + "You can't " + ChatColor.GOLD + "Unbind " + ChatColor.GRAY + "this item.");
return false;
}
if (ItemUtils.unbindItem(itemInHand)==null ){
player.sendMessage(ChatColor.GRAY + "You can't " + ChatColor.GOLD + "Unbind " + ChatColor.GRAY + "this item.");
return false;
}
player.sendMessage(ChatColor.GRAY + "Item no longer Soulbound.");
return true;
default:
return false;
}
}
}

View File

@@ -0,0 +1,119 @@
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

@@ -0,0 +1,89 @@
package com.me.tft_02.soulbound.config;
import java.util.ArrayList;
import java.util.List;
public class Config extends AutoUpdateConfigLoader {
private static Config instance;
private Config() {
super("config.yml");
}
public static Config getInstance() {
if (instance == null) {
instance = new Config();
}
return instance;
}
@Override
protected void loadKeys() {}
/* @formatter:off */
/* 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); }
/* @formatter:on */
/* 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 List<String> getBlockedCommands() { return config.getStringList("Soulbound.Blocked_Commands"); }
public List<String> getBindCommands() { return config.getStringList("Soulbound.Commands_Bind_When_Used"); }
// 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) {
tiers.add(tier);
}
return tiers;
}
// LoreLocks config settings
public boolean getLoreLocksBindKeys() { return config.getBoolean("Dependency_Plugins.LoreLocks.Bind_Keys"); }
// MythicDrops config settings
public List<String> getMythicDropsBindOnPickupTiers() { return getMythicDropsItemTiers("BindOnPickup"); }
public List<String> getMythicDropsBindOnUseTiers() { return getMythicDropsItemTiers("BindOnUse"); }
public List<String> getMythicDropsBindOnEquipTiers() { return getMythicDropsItemTiers("BindOnEquip"); }
public List<String> getMythicDropsItemTiers(String bindType) {
String[] tiersString = config.getString("Dependency_Plugins.MythicDrops." + bindType).replaceAll(" ", "").split("[,]");
List<String> tiers = new ArrayList<String>();
for (String tier : tiersString) {
tiers.add(tier);
}
return tiers;
}
}

View File

@@ -0,0 +1,93 @@
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

@@ -0,0 +1,155 @@
package com.me.tft_02.soulbound.config;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
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;
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 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));
}
}
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<String> actions = config.getStringList("Items." + itemName + ".Actions");
for (ActionType actionType : ActionType.values()) {
if (actions.contains(actionType.toString())) {
addSoulbindItem(actionType, soulbindItem);
}
}
}
}
private void addSoulbindItem(ActionType actionType, SoulbindItem soulbindItem) {
switch (actionType) {
case CRAFT:
soulbindOnCraft.add(soulbindItem);
return;
case OPEN_CHEST:
soulbindOnOpenChest.add(soulbindItem);
return;
case PICKUP_ITEM:
soulbindOnPickupItem.add(soulbindItem);
return;
case DROP_ITEM:
soulbindOnDrop.add(soulbindItem);
return;
case RESPAWN:
soulbindOnRespawn.add(soulbindItem);
return;
case KIT:
soulbindOnKit.add(soulbindItem);
return;
}
}
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;
}
}
public boolean isActionItem(ItemStack itemStack, ActionType actionType) {
for (SoulbindItem soulbindItem : getSoulbindItems(actionType)) {
if (itemStack.getData().equals(soulbindItem.getMaterialData())) {
if (itemStack.hasItemMeta()) {
ItemMeta itemMeta = itemStack.getItemMeta();
if (soulbindItem.getName() != null) {
if (!itemMeta.getDisplayName().contains(soulbindItem.getName())) {
return false;
}
}
if (soulbindItem.getLore() != null && !soulbindItem.getLore().isEmpty()) {
if (itemMeta.hasLore() || !itemMeta.getLore().containsAll(soulbindItem.getLore())) {
return false;
}
}
}
return true;
}
}
return false;
}
}

View File

@@ -0,0 +1,10 @@
package com.me.tft_02.soulbound.datatypes;
public enum ActionType {
CRAFT,
OPEN_CHEST,
PICKUP_ITEM,
DROP_ITEM,
RESPAWN,
KIT;
};

View File

@@ -0,0 +1,34 @@
package com.me.tft_02.soulbound.datatypes;
import java.util.List;
import org.bukkit.material.MaterialData;
public class SoulbindItem {
private MaterialData materialData;
private String name;
private List<String> lore;
public SoulbindItem(MaterialData materialData, String name, List<String> lore) {
this.materialData = materialData;
this.name = name;
this.lore = lore;
}
public MaterialData getMaterialData() {
return materialData;
}
public List<String> getLore() {
return lore;
}
public String getName() {
return name;
}
@Override
public String toString() {
return materialData.toString() + " " + name.toString() + " " + lore.toString();
}
}

View File

@@ -0,0 +1,54 @@
package com.me.tft_02.soulbound.events;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.bukkit.event.player.PlayerEvent;
import org.bukkit.inventory.ItemStack;
public class SoulbindItemEvent extends PlayerEvent implements Cancellable {
private ItemStack itemStack;
private boolean cancelled;
public SoulbindItemEvent(Player player, ItemStack itemStack) {
super(player);
this.setItemStack(itemStack);
this.cancelled = false;
}
/**
* @return The itemStack being soulbound
*/
public ItemStack getItemStack() {
return itemStack;
}
/**
* @return Set the itemStack being soulbound
*/
public void setItemStack(ItemStack itemStack) {
this.itemStack = itemStack;
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}
private static final HandlerList handlers = new HandlerList();
@Override
public HandlerList getHandlers() {
return handlers;
}
public static HandlerList getHandlerList() {
return handlers;
}
}

View File

@@ -0,0 +1,40 @@
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 {
/**
* Check BossDeathEvent events.
*
* @param event The event to check
*/
/* @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onBossDeath(BossDeathEvent event) {
if (event.getDrops().isEmpty()) {
return;
}
for (ItemStack itemStack : event.getDrops()) {
handleEpicBossItems(itemStack);
}
}
*/
public void handleEpicBossItems(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

@@ -0,0 +1,19 @@
package com.me.tft_02.soulbound.listeners;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.inventory.ItemStack;
import com.me.tft_02.soulbound.util.DurabilityUtils;
public class BlockListener implements Listener {
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onBlockBreak(BlockBreakEvent event) {
ItemStack itemStack = event.getPlayer().getItemInHand();
DurabilityUtils.handleInfiniteDurability(itemStack);
}
}

View File

@@ -0,0 +1,80 @@
package com.me.tft_02.soulbound.listeners;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityShootBowEvent;
import org.bukkit.inventory.ItemStack;
import com.me.tft_02.soulbound.util.DurabilityUtils;
public class EntityListener implements Listener {
/**
* Check EntityDamageByEntityEvent events.
*
* @param event The event to check
*/
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onEntityDeath(EntityDamageByEntityEvent event) {
if (event.getDamage() == 0 || event.getEntity().isDead()) {
return;
}
if (event.getEntity() instanceof LivingEntity) {
combatChecks(event);
}
}
/**
* Apply combat modifiers
*
* @param event The event to run the combat checks on.
*/
void combatChecks(EntityDamageByEntityEvent event) {
Entity damager = event.getDamager();
EntityType damagerType = damager.getType();
switch (damagerType) {
case PLAYER:
Player attacker = (Player) event.getDamager();
ItemStack itemInHand = attacker.getItemInHand();
DurabilityUtils.handleInfiniteDurability(itemInHand);
default:
return;
}
}
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
private void onEntityShootBow(EntityShootBowEvent event) {
Entity entity = event.getEntity();
if (entity instanceof Player) {
DurabilityUtils.handleInfiniteDurability(((Player) entity).getItemInHand());
}
}
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
private void onEntityDamage(EntityDamageEvent event) {
if (event.getDamage() == 0 || event.getEntity().isDead()) {
return;
}
Entity entity = event.getEntity();
if (entity instanceof Player) {
Player player = (Player) entity;
for (ItemStack itemStack : player.getInventory().getArmorContents()) {
DurabilityUtils.handleInfiniteDurability(itemStack);
}
}
}
}

View File

@@ -0,0 +1,179 @@
package com.me.tft_02.soulbound.listeners;
import org.bukkit.entity.HumanEntity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.enchantment.EnchantItemEvent;
import org.bukkit.event.inventory.CraftItemEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryMoveItemEvent;
import org.bukkit.event.inventory.InventoryOpenEvent;
import org.bukkit.event.inventory.InventoryPickupItemEvent;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.event.inventory.InventoryType.SlotType;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import com.me.tft_02.soulbound.Soulbound;
import com.me.tft_02.soulbound.config.Config;
import com.me.tft_02.soulbound.config.ItemsConfig;
import com.me.tft_02.soulbound.datatypes.ActionType;
import com.me.tft_02.soulbound.runnables.UpdateArmorTask;
import com.me.tft_02.soulbound.util.ItemUtils;
import com.me.tft_02.soulbound.util.ItemUtils.ItemType;
import com.me.tft_02.soulbound.util.Permissions;
public class InventoryListener implements Listener {
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
void onInventoryClick(InventoryClickEvent event) {
HumanEntity entity = event.getWhoClicked();
ItemStack itemStack = event.getCurrentItem();
SlotType slotType = event.getSlotType();
InventoryType inventoryType = event.getInventory().getType();
if (inventoryType == null) {
return;
}
if (itemStack == null) {
return;
}
if (entity instanceof Player) {
Player player = (Player) entity;
switch (slotType) {
case ARMOR:
new UpdateArmorTask(player).runTaskLater(Soulbound.p, 2);
return;
case CONTAINER:
ItemType itemType = ItemUtils.getItemType(itemStack);
switch (itemType) {
case BIND_ON_PICKUP:
ItemUtils.soulbindItem(player, itemStack);
return;
default:
return;
}
default:
if (ItemUtils.isEquipable(itemStack) && event.isShiftClick()) {
new UpdateArmorTask(player).runTaskLater(Soulbound.p, 2);
return;
}
break;
}
}
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onInventoryClickEvent(InventoryClickEvent event) {
HumanEntity entity = event.getWhoClicked();
if (!(entity instanceof Player)) {
return;
}
Player player = (Player) entity;
ItemStack itemStack = event.getCurrentItem();
InventoryType inventoryType = event.getInventory().getType();
if (inventoryType == null) {
return;
}
ItemType itemType = ItemUtils.getItemType(itemStack);
if (itemType != ItemType.SOULBOUND) {
return;
}
if (!Config.getInstance().getAllowItemStoring() && !(inventoryType == InventoryType.CRAFTING)) {
event.setCancelled(true);
}
if (ItemUtils.isBindedPlayer(player, itemStack) || Permissions.pickupBypass(player)) {
return;
}
event.setCancelled(true);
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onInventoryMoveEvent(InventoryMoveItemEvent event) {
ItemStack itemStack = event.getItem();
ItemType itemType = ItemUtils.getItemType(itemStack);
if (itemType == ItemType.SOULBOUND) {
event.setCancelled(true);
}
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onInventoryPickupItemEvent(InventoryPickupItemEvent event) {
ItemStack itemStack = event.getItem().getItemStack();
ItemType itemType = ItemUtils.getItemType(itemStack);
if (itemType == ItemType.SOULBOUND) {
event.setCancelled(true);
}
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onInventoryOpen(InventoryOpenEvent event) {
HumanEntity humanEntity = event.getPlayer();
Inventory inventory = event.getInventory();
if (!(humanEntity instanceof Player)) {
return;
}
Player player = (Player) humanEntity;
for (ItemStack itemStack : inventory.getContents()) {
if (itemStack != null && ItemsConfig.getInstance().isActionItem(itemStack, ActionType.OPEN_CHEST)) {
ItemUtils.soulbindItem(player, itemStack);
}
}
}
/**
* Check CraftItemEvent events.
*
* @param event The event to check
*/
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
private void onCraftItem(CraftItemEvent event) {
HumanEntity humanEntity = event.getWhoClicked();
if (!(humanEntity instanceof Player)) {
return;
}
Player player = (Player) humanEntity;
ItemStack itemStack = event.getRecipe().getResult();
if (ItemsConfig.getInstance().isActionItem(itemStack, ActionType.CRAFT)) {
event.getInventory().setResult(ItemUtils.soulbindItem(player, itemStack));
}
}
/**
* Check EnchantItemEvent events.
*
* @param event The event to check
*/
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
private void onEnchantItem(EnchantItemEvent event) {
Player player = event.getEnchanter();
ItemStack itemStack = event.getItem();
if (ItemUtils.isBindOnUse(itemStack)) {
ItemUtils.soulbindItem(player, itemStack);
return;
}
}
}

View File

@@ -0,0 +1,284 @@
package com.me.tft_02.soulbound.listeners;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.Sound;
import org.bukkit.entity.Item;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerFishEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerPickupItemEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.event.player.PlayerShearEntityEvent;
import org.bukkit.event.server.ServerCommandEvent;
import org.bukkit.inventory.ItemStack;
import com.me.tft_02.soulbound.Soulbound;
import com.me.tft_02.soulbound.config.Config;
import com.me.tft_02.soulbound.config.ItemsConfig;
import com.me.tft_02.soulbound.datatypes.ActionType;
import com.me.tft_02.soulbound.runnables.SoulbindInventoryTask;
import com.me.tft_02.soulbound.runnables.UpdateArmorTask;
import com.me.tft_02.soulbound.runnables.UpdateInventoryTask;
import com.me.tft_02.soulbound.util.CommandUtils;
import com.me.tft_02.soulbound.util.DurabilityUtils;
import com.me.tft_02.soulbound.util.ItemUtils;
import com.me.tft_02.soulbound.util.Permissions;
import com.me.tft_02.soulbound.util.PlayerData;
public class PlayerListener implements Listener {
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
private void onPlayerJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
if (Soulbound.p.isUpdateAvailable() && Permissions.updateCheck(player)) {
player.sendMessage(ChatColor.GOLD + "Soulbound is outdated!");
player.sendMessage(ChatColor.AQUA + "http://dev.bukkit.org/server-mods/Soulbound/");
}
}
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
private void onItemPickup(PlayerPickupItemEvent event) {
Player player = event.getPlayer();
Item item = event.getItem();
ItemStack itemStack = item.getItemStack();
if (ItemUtils.isSoulbound(itemStack) && !ItemUtils.isBindedPlayer(player, itemStack)) {
if (Permissions.pickupBypass(player)) {
return;
}
event.setCancelled(true);
return;
}
if (ItemUtils.isBindOnPickup(itemStack)) {
ItemUtils.soulbindItem(player, itemStack);
return;
}
if (ItemsConfig.getInstance().isActionItem(itemStack, ActionType.PICKUP_ITEM)) {
ItemUtils.soulbindItem(player, itemStack);
return;
}
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
private void onItemDrop(PlayerDropItemEvent event) {
Player player = event.getPlayer();
Item item = event.getItemDrop();
ItemStack itemStack = item.getItemStack();
if (Config.getInstance().getPreventItemDrop()) {
if (ItemUtils.isSoulbound(itemStack) && ItemUtils.isBindedPlayer(player, itemStack)) {
item.setPickupDelay(2 * 20);
event.setCancelled(true);
new UpdateInventoryTask(player).runTask(Soulbound.p);
}
return;
}
if (Config.getInstance().getDeleteOnDrop()) {
player.playSound(player.getLocation(), Sound.ITEM_BREAK, 1.0F, 1.0F);
event.getItemDrop().remove();
return;
}
if (ItemsConfig.getInstance().isActionItem(itemStack, ActionType.DROP_ITEM)) {
ItemUtils.soulbindItem(player, itemStack);
return;
}
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
private void onPlayerDeath(PlayerDeathEvent event) {
Player player = event.getEntity();
boolean deleteOnDeath = Permissions.deleteOnDeath(player);
boolean keepOnDeath = Permissions.keepOnDeath(player);
List<ItemStack> items = new ArrayList<ItemStack>();
if (!keepOnDeath && !deleteOnDeath) {
return;
}
for (ItemStack item : new ArrayList<ItemStack>(event.getDrops())) {
if (ItemUtils.isSoulbound(item) && ItemUtils.isBindedPlayer(player, item)) {
if (keepOnDeath) {
items.add(item);
event.getDrops().remove(item);
}
else if (deleteOnDeath) {
event.getDrops().remove(item);
}
}
}
PlayerData.storeItemsDeath(player, items);
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
private void onPlayerRespawn(PlayerRespawnEvent event) {
new SoulbindInventoryTask(event.getPlayer(), ActionType.RESPAWN).runTask(Soulbound.p);
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
private void onPlayerRespawnHighest(PlayerRespawnEvent event) {
Player player = event.getPlayer();
boolean keepOnDeath = Permissions.keepOnDeath(player);
if (!keepOnDeath) {
return;
}
List<ItemStack> items = new ArrayList<ItemStack>();
items = PlayerData.retrieveItemsDeath(player);
if (items != null) {
for (ItemStack item : items) {
player.getInventory().addItem(item);
}
}
new UpdateInventoryTask(player).runTask(Soulbound.p);
}
/**
* Watch PlayerInteract events.
*
* @param event The event to watch
*/
@EventHandler(priority = EventPriority.LOW)
public void onPlayerInteract(PlayerInteractEvent event) {
Player player = event.getPlayer();
Action action = event.getAction();
ItemStack inHand = player.getItemInHand();
switch (action) {
case RIGHT_CLICK_BLOCK:
case RIGHT_CLICK_AIR:
case LEFT_CLICK_AIR:
case LEFT_CLICK_BLOCK:
if (ItemUtils.isEquipable(inHand)) {
new UpdateArmorTask(player).runTaskLater(Soulbound.p, 2);
}
else if (ItemUtils.isBindOnUse(inHand)) {
ItemUtils.soulbindItem(player, inHand);
}
default:
break;
}
}
/**
* Monitor PlayerFishEvent events.
*
* @param event The event to monitor
*/
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
private void onPlayerFish(PlayerFishEvent event) {
ItemStack itemInHand = event.getPlayer().getItemInHand();
DurabilityUtils.handleInfiniteDurability(itemInHand);
}
/**
* Monitor PlayerShearEntityEvent events.
*
* @param event The event to monitor
*/
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
private void onPlayerShearEntity(PlayerShearEntityEvent event) {
ItemStack itemInHand = event.getPlayer().getItemInHand();
DurabilityUtils.handleInfiniteDurability(itemInHand);
}
/**
* Watch PlayerCommandPreprocessEvent events.
*
* @param event The event to watch
*/
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onPlayerCommand(PlayerCommandPreprocessEvent event) {
Player player = event.getPlayer();
ItemStack itemStack = player.getItemInHand();
String command = event.getMessage();
if (ItemUtils.isSoulbound(itemStack) && Config.getInstance().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);
}
}
/**
* Monitor PlayerCommandPreprocessEvent events.
*
* @param event The event to monitor
*/
@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerCommandMonitor(PlayerCommandPreprocessEvent event) {
Player player = event.getPlayer();
ItemStack inHand = player.getItemInHand();
String command = event.getMessage();
String[] args = CommandUtils.extractArgs(command);
if (!ItemUtils.isSoulbound(inHand) && Config.getInstance().getBindCommands().contains(command)) {
ItemUtils.soulbindItem(player, inHand);
return;
}
if (command.contains("kit")) {
Player target;
if (args.length >= 2) {
target = Soulbound.p.getServer().getPlayer(args[1]);
}
else {
target = player;
}
if (target == null) {
return;
}
new SoulbindInventoryTask(target, ActionType.KIT).runTask(Soulbound.p);
}
}
/**
* Monitor ServerCommandEvent events.
*
* @param event The event to monitor
*/
@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onServerCommand(ServerCommandEvent event) {
String command = event.getCommand();
String[] args = CommandUtils.extractArgs(command);
if (!command.contains("kit")) {
return;
}
if (args.length < 2) {
return;
}
Player target = Soulbound.p.getServer().getPlayer(args[1]);
new SoulbindInventoryTask(target, ActionType.KIT).runTask(Soulbound.p);
}
}

View File

@@ -0,0 +1,38 @@
package com.me.tft_02.soulbound.listeners;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import com.me.tft_02.soulbound.events.SoulbindItemEvent;
import com.me.tft_02.soulbound.util.ItemUtils;
import com.me.tft_02.soulbound.util.Permissions;
public class SelfListener implements Listener {
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
private void onItemSoulbound(SoulbindItemEvent event) {
Player player = event.getPlayer();
Inventory inventory = player.getInventory();
int maxAmount = Permissions.getSoulbindMaximum(player);
if (maxAmount < 0) {
return;
}
int count = 0;
for (ItemStack itemStack : inventory.getContents()) {
if (itemStack != null && ItemUtils.isSoulbound(itemStack)) {
count++;
}
}
if (count >= maxAmount) {
player.sendMessage(ChatColor.RED + "Cannot Soulbind any more items, maximum amount reached! " + ChatColor.GOLD + "(" + maxAmount + ")");
event.setCancelled(true);
}
}
}

View File

@@ -0,0 +1,34 @@
package com.me.tft_02.soulbound.runnables;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitRunnable;
import com.me.tft_02.soulbound.config.ItemsConfig;
import com.me.tft_02.soulbound.datatypes.ActionType;
import com.me.tft_02.soulbound.util.ItemUtils;
public class SoulbindInventoryTask extends BukkitRunnable {
private Player player;
private ActionType actionType;
public SoulbindInventoryTask(Player player, ActionType actionType) {
this.player = player;
this.actionType = actionType;
}
@Override
public void run() {
for (ItemStack itemStack : player.getInventory().getContents()) {
if (itemStack != null && ItemsConfig.getInstance().isActionItem(itemStack, actionType)) {
ItemUtils.soulbindItem(player, itemStack);
}
}
for (ItemStack itemStack : player.getInventory().getArmorContents()) {
if (itemStack != null && ItemsConfig.getInstance().isActionItem(itemStack, actionType)) {
ItemUtils.soulbindItem(player, itemStack);
}
}
}
}

View File

@@ -0,0 +1,31 @@
package com.me.tft_02.soulbound.runnables;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.scheduler.BukkitRunnable;
import com.me.tft_02.soulbound.util.ItemUtils;
import com.me.tft_02.soulbound.util.ItemUtils.ItemType;
public class UpdateArmorTask extends BukkitRunnable {
private Player player;
public UpdateArmorTask(Player player) {
this.player = player;
}
@Override
public void run() {
handleBindOnEquip(player);
}
public void handleBindOnEquip(Player player) {
for (ItemStack armor : player.getInventory().getArmorContents()) {
if (armor != null && ItemUtils.getItemType(armor) == ItemType.BIND_ON_EQUIP) {
ItemUtils.soulbindItem(player, armor);
}
}
player.getInventory().setArmorContents(player.getInventory().getArmorContents());
}
}

View File

@@ -0,0 +1,20 @@
package com.me.tft_02.soulbound.runnables;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
public class UpdateInventoryTask extends BukkitRunnable {
private Player player;
public UpdateInventoryTask(Player player) {
this.player = player;
}
@SuppressWarnings("deprecation")
@Override
public void run() {
if (player.isValid()) {
player.updateInventory();
}
}
}

View File

@@ -0,0 +1,38 @@
package com.me.tft_02.soulbound.util;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public final class CommandUtils {
public static String[] extractArgs(String command) {
String[] args = {""};
String[] split = command.split(" ", 2);
if (split.length > 1) {
args = split[1].split(" ");
}
return args;
}
public static boolean noConsoleUsage(CommandSender sender) {
if (sender instanceof Player) {
return false;
}
sender.sendMessage("This command does not support console usage.");
return true;
}
public static boolean isOffline(CommandSender sender, OfflinePlayer player) {
if (player != null && player.isOnline()) {
return false;
}
sender.sendMessage(ChatColor.RED + "This command does not work for offline players.");
return true;
}
}

View File

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

View File

@@ -0,0 +1,435 @@
package com.me.tft_02.soulbound.util;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import com.me.tft_02.soulbound.Soulbound;
import com.me.tft_02.soulbound.config.Config;
import com.me.tft_02.soulbound.events.SoulbindItemEvent;
public class ItemUtils {
public enum ItemType {
NORMAL,
SOULBOUND,
BIND_ON_PICKUP,
BIND_ON_USE,
BIND_ON_EQUIP;
}
public static ItemStack soulbindItem(Player player, ItemStack itemStack) {
if (itemStack == null) {
return itemStack;
}
if (isSoulbound(itemStack)) {
return itemStack;
}
SoulbindItemEvent soulbindItemEvent = new SoulbindItemEvent(player, itemStack);
Soulbound.p.getServer().getPluginManager().callEvent(soulbindItemEvent);
itemStack = soulbindItemEvent.getItemStack();
if (soulbindItemEvent.isCancelled()) {
return itemStack;
}
ItemMeta itemMeta = itemStack.getItemMeta();
List<String> itemLore = new ArrayList<String>();
if (itemMeta.hasLore()) {
List<String> oldLore = itemMeta.getLore();
oldLore.remove(ChatColor.DARK_RED + "Bind on Pickup");
oldLore.remove(ChatColor.DARK_RED + "Bind on Equip");
oldLore.remove(ChatColor.DARK_RED + "Bind on Use");
itemLore.addAll(oldLore);
}
itemLore.add(Misc.SOULBOUND_TAG + StringUtils.hideUUID(player.getUniqueId()));
if (Config.getInstance().getShowNameInLore()) {
itemLore.add(player.getName());
}
itemMeta.setLore(itemLore);
itemStack.setItemMeta(itemMeta);
return itemStack;
}
public static ItemStack bopItem(ItemStack itemStack) {
if (itemStack == null) {
return itemStack;
}
if (isBindOnPickup(itemStack)) {
return itemStack;
}
ItemMeta itemMeta = itemStack.getItemMeta();
List<String> itemLore = new ArrayList<String>();
if (itemMeta.hasLore()) {
itemLore.addAll(itemMeta.getLore());
}
itemLore.add(ChatColor.DARK_RED + "Bind on Pickup");
itemMeta.setLore(itemLore);
itemStack.setItemMeta(itemMeta);
return itemStack;
}
public static ItemStack boeItem(ItemStack itemStack) {
if (itemStack == null) {
return itemStack;
}
if (isBindOnEquip(itemStack)) {
return itemStack;
}
ItemMeta itemMeta = itemStack.getItemMeta();
List<String> itemLore = new ArrayList<String>();
if (itemMeta.hasLore()) {
itemLore.addAll(itemMeta.getLore());
}
itemLore.add(ChatColor.DARK_RED + "Bind on Equip");
itemMeta.setLore(itemLore);
itemStack.setItemMeta(itemMeta);
return itemStack;
}
public static ItemStack bouItem(ItemStack itemStack) {
if (itemStack == null) {
return itemStack;
}
if (isBindOnUse(itemStack)) {
return itemStack;
}
ItemMeta itemMeta = itemStack.getItemMeta();
List<String> itemLore = new ArrayList<String>();
if (itemMeta.hasLore()) {
itemLore.addAll(itemMeta.getLore());
}
itemLore.add(ChatColor.DARK_RED + "Bind on Use");
itemMeta.setLore(itemLore);
itemStack.setItemMeta(itemMeta);
return itemStack;
}
public static ItemStack unbindItem(ItemStack itemStack) {
if (itemStack == null) {
return null;
}
ItemMeta itemMeta = itemStack.getItemMeta();
if (itemMeta.hasLore() && isSoulbound(itemStack)) {
List<String> oldLore = itemMeta.getLore();
int loreSize = oldLore.size();
if (loreSize <= 2) {
itemMeta.setLore(null);
itemStack.setItemMeta(itemMeta);
return itemStack;
}
List<String> itemLore = new ArrayList<String>();
itemLore.addAll(oldLore);
int index = StringUtils.getIndexOfSoulbound(itemLore);
if (index == -1){
return null;
}
itemLore.remove(index);
if (index<itemLore.size())
itemLore.remove(index);
itemMeta.setLore(itemLore);
}
itemStack.setItemMeta(itemMeta);
return itemStack;
}
public static boolean isSoulbound(ItemStack itemStack) {
if (!itemStack.hasItemMeta()) {
return false;
}
ItemMeta itemMeta = itemStack.getItemMeta();
if (itemMeta.hasLore()) {
List<String> itemLore = itemMeta.getLore();
for (String lore : itemLore) {
if (lore.equalsIgnoreCase(Misc.SOULBOUND_TAG)) {
return true;
}
}
}
return false;
}
public static boolean isBindOnPickup(ItemStack itemStack) {
if (!itemStack.hasItemMeta()) {
return false;
}
ItemMeta itemMeta = itemStack.getItemMeta();
if (itemMeta.hasLore()) {
List<String> itemLore = itemMeta.getLore();
if (itemLore.contains(ChatColor.DARK_RED + "Bind on Pickup")) {
return true;
}
}
return false;
}
public static boolean isBindOnUse(ItemStack itemStack) {
if (!itemStack.hasItemMeta()) {
return false;
}
ItemMeta itemMeta = itemStack.getItemMeta();
if (itemMeta.hasLore()) {
List<String> itemLore = itemMeta.getLore();
if (itemLore.contains(ChatColor.DARK_RED + "Bind on Use")) {
return true;
}
}
return false;
}
public static boolean isBindOnEquip(ItemStack itemStack) {
if (!itemStack.hasItemMeta()) {
return false;
}
ItemMeta itemMeta = itemStack.getItemMeta();
if (itemMeta.hasLore()) {
List<String> itemLore = itemMeta.getLore();
if (itemLore.contains(ChatColor.DARK_RED + "Bind on Equip")) {
return true;
}
}
return false;
}
public static boolean isBindedPlayer(Player player, ItemStack itemStack) {
updateOldLore(player, itemStack);
checkNameChange(player, itemStack);
List<String> itemLore = itemStack.getItemMeta().getLore();
Soulbound.p.debug("UUID MATCH? " + player.getUniqueId().equals(StringUtils.readUUIDFromLore(itemLore)));
Soulbound.p.debug("NAME MATCH? " + itemLore.contains(player.getName()));
return player.getUniqueId().equals(StringUtils.readUUIDFromLore(itemLore)) || itemLore.contains(player.getName());
}
private static ItemStack updateOldLore(Player player, ItemStack itemStack) {
ItemMeta itemMeta = itemStack.getItemMeta();
if (itemMeta != null) {
if (!itemMeta.hasLore()) {
return itemStack;
}
}
List<String> itemLore = itemMeta.getLore();
if (itemLore.size() - 1 < StringUtils.getIndexOfSoulbound(itemLore) + 2) {
return itemStack;
}
int indexOfSoulbound = StringUtils.getIndexOfSoulbound(itemLore);
int indexOfUniqueId = indexOfSoulbound + 2;
UUID uuid = null;
if (itemLore.get(indexOfUniqueId).contains(player.getUniqueId().toString())) {
uuid = UUID.fromString(ChatColor.stripColor(itemLore.get(indexOfUniqueId)));
itemLore.remove(indexOfUniqueId);
}
if (StringUtils.readUUIDFromLore(itemLore) == null && uuid != null) {
itemLore.set(indexOfSoulbound, Misc.SOULBOUND_TAG + StringUtils.hideUUID(uuid));
}
itemMeta.setLore(itemLore);
itemStack.setItemMeta(itemMeta);
return itemStack;
}
private static ItemStack checkNameChange(Player player, ItemStack itemStack) {
ItemMeta itemMeta = itemStack.getItemMeta();
List<String> itemLore = itemMeta.getLore();
int indexName = StringUtils.getIndexOfSoulbound(itemLore) + 1;
if (itemLore.size() >= 2 && itemLore.contains(player.getName()) && !Config.getInstance().getShowNameInLore()) {
Soulbound.p.debug("Item lore has a player name but that's disabled in config");
Soulbound.p.debug("Going to remove what is at indexName " + indexName + " which is: " + itemLore.get(indexName));
itemLore.remove(indexName);
itemMeta.setLore(itemLore);
itemStack.setItemMeta(itemMeta);
return itemStack;
}
if (Config.getInstance().getShowNameInLore() && !itemLore.contains(player.getName()) && player.getUniqueId().equals(StringUtils.readUUIDFromLore(itemLore))) {
Soulbound.p.debug("Item lore doesn't have (correct) player name but it should and the UUIDs match");
itemLore.add(indexName, player.getName());
}
itemMeta.setLore(itemLore);
itemStack.setItemMeta(itemMeta);
return itemStack;
}
public static boolean isNormalItem(ItemStack itemStack) {
return !itemStack.hasItemMeta() && !itemStack.getItemMeta().hasLore() || ItemUtils.getItemType(itemStack) == ItemType.NORMAL;
}
public static ItemType getItemType(ItemStack itemStack) {
if (itemStack == null) {
return ItemType.NORMAL;
}
else if (isSoulbound(itemStack)) {
return ItemType.SOULBOUND;
}
else if (isBindOnPickup(itemStack)) {
return ItemType.BIND_ON_PICKUP;
}
else if (isBindOnUse(itemStack)) {
return ItemType.BIND_ON_USE;
}
else if (isBindOnEquip(itemStack)) {
return ItemType.BIND_ON_EQUIP;
}
else {
return ItemType.NORMAL;
}
}
/**
* Checks to see if an item is an equipable item.
*
* @param is Item to check
*
* @return true if the item is equipable, false otherwise
*/
public static boolean isEquipable(ItemStack is) {
return isMinecraftArmor(is) || is.getType() == Material.SKULL_ITEM || is.getType() == Material.JACK_O_LANTERN;
}
/**
* Checks to see if an item is a wearable armor piece.
*
* @param is Item to check
*
* @return true if the item is armor, false otherwise
*/
public static boolean isMinecraftArmor(ItemStack is) {
return isLeatherArmor(is) || isGoldArmor(is) || isIronArmor(is) || isDiamondArmor(is) || isChainmailArmor(is);
}
/**
* Checks to see if an item is a leather armor piece.
*
* @param is Item to check
*
* @return true if the item is leather armor, false otherwise
*/
public static boolean isLeatherArmor(ItemStack is) {
switch (is.getType()) {
case LEATHER_BOOTS:
case LEATHER_CHESTPLATE:
case LEATHER_HELMET:
case LEATHER_LEGGINGS:
return true;
default:
return false;
}
}
/**
* Checks to see if an item is a gold armor piece.
*
* @param is Item to check
*
* @return true if the item is gold armor, false otherwise
*/
public static boolean isGoldArmor(ItemStack is) {
switch (is.getType()) {
case GOLD_BOOTS:
case GOLD_CHESTPLATE:
case GOLD_HELMET:
case GOLD_LEGGINGS:
return true;
default:
return false;
}
}
/**
* Checks to see if an item is an iron armor piece.
*
* @param is Item to check
*
* @return true if the item is iron armor, false otherwise
*/
public static boolean isIronArmor(ItemStack is) {
switch (is.getType()) {
case IRON_BOOTS:
case IRON_CHESTPLATE:
case IRON_HELMET:
case IRON_LEGGINGS:
return true;
default:
return false;
}
}
/**
* Checks to see if an item is a diamond armor piece.
*
* @param is Item to check
*
* @return true if the item is diamond armor, false otherwise
*/
public static boolean isDiamondArmor(ItemStack is) {
switch (is.getType()) {
case DIAMOND_BOOTS:
case DIAMOND_CHESTPLATE:
case DIAMOND_HELMET:
case DIAMOND_LEGGINGS:
return true;
default:
return false;
}
}
/**
* Checks to see if an item is a chainmail armor piece.
*
* @param is Item to check
*
* @return true if the item is chainmail armor, false otherwise
*/
public static boolean isChainmailArmor(ItemStack is) {
switch (is.getType()) {
case CHAINMAIL_BOOTS:
case CHAINMAIL_CHESTPLATE:
case CHAINMAIL_HELMET:
case CHAINMAIL_LEGGINGS:
return true;
default:
return false;
}
}
}

View File

@@ -0,0 +1,24 @@
package com.me.tft_02.soulbound.util;
import java.util.logging.Filter;
import java.util.logging.LogRecord;
import com.me.tft_02.soulbound.Soulbound;
public class LogFilter implements Filter {
private boolean debug;
public LogFilter(Soulbound plugin) {
// Doing a config loading lite here, because we can't depend on the config loader to have loaded before any debug messages are sent
debug = plugin.getConfig().getBoolean("General.Verbose_Logging");
}
@Override
public boolean isLoggable(LogRecord record) {
if (record.getMessage().contains("[Debug]") && !debug) {
return false;
}
return true;
}
}

View File

@@ -0,0 +1,7 @@
package com.me.tft_02.soulbound.util;
import org.bukkit.ChatColor;
public class Misc {
public static String SOULBOUND_TAG = ChatColor.GOLD + "Soulbound";
}

View File

@@ -0,0 +1,40 @@
package com.me.tft_02.soulbound.util;
import org.bukkit.entity.Player;
import org.bukkit.permissions.Permissible;
import org.bukkit.permissions.PermissionAttachmentInfo;
public class Permissions {
public static boolean keepOnDeath(Permissible permissible) {
return permissible.hasPermission("soulbound.items.keep_on_death");
}
public static boolean deleteOnDeath(Permissible permissible) {
return permissible.hasPermission("soulbound.items.delete_on_death");
}
public static boolean pickupBypass(Permissible permissible) {
return permissible.hasPermission("soulbound.pickup.bypass");
}
public static boolean updateCheck(Permissible permissible) {
return permissible.hasPermission("soulbound.updatecheck");
}
public static int getSoulbindMaximum(Player player) {
String match = "soulbound.maximum_allowed.";
int amount = -1;
for (PermissionAttachmentInfo permission : player
.getEffectivePermissions()) {
if (permission.getPermission().startsWith(match)
&& permission.getValue()) {
amount = Integer.parseInt(permission.getPermission().split(
"[.]")[2]);
}
}
return amount;
}
}

View File

@@ -0,0 +1,40 @@
package com.me.tft_02.soulbound.util;
import java.util.HashMap;
import java.util.List;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import com.me.tft_02.soulbound.Soulbound;
public class PlayerData {
Soulbound plugin;
public PlayerData(Soulbound instance) {
plugin = instance;
}
public static HashMap<String, List<ItemStack>> playerSoulboundItems = new HashMap<String, List<ItemStack>>();
public static void storeItemsDeath(Player player, List<ItemStack> items) {
String playerName = player.getName();
if (playerSoulboundItems.containsKey(playerName)) {
playerSoulboundItems.put(playerName, null);
}
playerSoulboundItems.put(playerName, items);
}
public static List<ItemStack> retrieveItemsDeath(Player player) {
String playerName = player.getName();
if (playerSoulboundItems.containsKey(playerName)) {
return playerSoulboundItems.get(playerName);
}
else {
return null;
}
}
}

View File

@@ -0,0 +1,49 @@
package com.me.tft_02.soulbound.util;
import java.util.List;
import java.util.UUID;
import org.bukkit.ChatColor;
public class StringUtils {
public static int getIndexOfSoulbound(List<String> itemLore) {
int index = -1;
for (String line : itemLore) {
if (line.contains(Misc.SOULBOUND_TAG)) {
return itemLore.indexOf(line);
}
}
return index;
}
public static UUID readUUIDFromLore(List<String> itemLore) {
int index = getIndexOfSoulbound(itemLore);
if (index == -1) {
return null;
}
String line = itemLore.get(index);
line = line.substring(11);
return readUUID(line);
}
public static String hideUUID(UUID uuid) {
String string = uuid.toString();
string = string.replaceAll("-", ChatColor.MAGIC.toString());
StringBuilder formattedString = new StringBuilder();
for (int i = 0; i < string.length(); i++) {
formattedString.append(ChatColor.COLOR_CHAR).append(string.charAt(i));
}
return formattedString.toString();
}
public static UUID readUUID(String string) {
return UUID.fromString(string.replaceAll(ChatColor.MAGIC.toString(), "-").replaceAll("§", ""));
}
}