1
0
mirror of https://e.coding.net/circlecloud/Soulbound.git synced 2024-11-22 01:49:09 +00:00

补全部分汉化 移除无用代码...

Signed-off-by: 502647092 <jtb1@163.com>
This commit is contained in:
502647092 2015-11-24 20:50:45 +08:00
parent 220ca9e339
commit 6195f57d62
15 changed files with 410 additions and 559 deletions

View File

@ -18,7 +18,6 @@ import com.me.tft_02.soulbound.listeners.BlockListener;
import com.me.tft_02.soulbound.listeners.EntityListener; import com.me.tft_02.soulbound.listeners.EntityListener;
import com.me.tft_02.soulbound.listeners.InventoryListener; import com.me.tft_02.soulbound.listeners.InventoryListener;
import com.me.tft_02.soulbound.listeners.PlayerListener; import com.me.tft_02.soulbound.listeners.PlayerListener;
import com.me.tft_02.soulbound.util.LogFilter;
import cn.citycraft.PluginHelper.config.FileConfig; import cn.citycraft.PluginHelper.config.FileConfig;
import cn.citycraft.PluginHelper.utils.VersionChecker; import cn.citycraft.PluginHelper.utils.VersionChecker;
@ -75,7 +74,6 @@ public class Soulbound extends JavaPlugin {
@Override @Override
public void onEnable() { public void onEnable() {
p = this; p = this;
getLogger().setFilter(new LogFilter(this));
setupFilePaths(); setupFilePaths();

View File

@ -1,6 +1,5 @@
package com.me.tft_02.soulbound.config; package com.me.tft_02.soulbound.config;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import cn.citycraft.PluginHelper.config.FileConfig; import cn.citycraft.PluginHelper.config.FileConfig;
@ -20,48 +19,10 @@ public class Config {
return config.getStringList("Soulbound.Blocked_Commands"); return config.getStringList("Soulbound.Blocked_Commands");
} }
public static boolean getConfigOverwriteEnabled() {
return config.getBoolean("General.Config_Update_Overwrite", true);
}
public static boolean getDeleteOnDrop() { public static boolean getDeleteOnDrop() {
return config.getBoolean("Soulbound.Delete_On_Drop", false); return config.getBoolean("Soulbound.Delete_On_Drop", false);
} }
public static List<String> getDiabloDropsBindOnEquipTiers() {
return getDiabloDropsItemTiers("BindOnEquip");
}
public static List<String> getDiabloDropsBindOnPickupTiers() {
return getDiabloDropsItemTiers("BindOnPickup");
}
public static List<String> getDiabloDropsBindOnUseTiers() {
return getDiabloDropsItemTiers("BindOnUse");
}
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>();
for (final String tier : tiersString) {
tiers.add(tier);
}
return tiers;
}
public static boolean getEBRBindOnEquip() {
return config.getBoolean("Dependency_Plugins.EpicBossRecoded.BindOnEquip");
}
public static boolean getEBRBindOnPickup() {
return config.getBoolean("Dependency_Plugins.EpicBossRecoded.BindOnPickup");
}
public static boolean getEBRBindOnUse() {
return config.getBoolean("Dependency_Plugins.EpicBossRecoded.BindOnUse");
}
public static boolean getFeedbackEnabled() { public static boolean getFeedbackEnabled() {
return config.getBoolean("Soulbound.Feedback_Messages_Enabled", true); return config.getBoolean("Soulbound.Feedback_Messages_Enabled", true);
} }
@ -70,36 +31,6 @@ public class Config {
return config.getBoolean("Soulbound.Infinite_Durability", false); return config.getBoolean("Soulbound.Infinite_Durability", false);
} }
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() { public static boolean getPreventItemDrop() {
return config.getBoolean("Soulbound.Prevent_Item_Drop", false); return config.getBoolean("Soulbound.Prevent_Item_Drop", false);
} }
@ -108,18 +39,6 @@ public class Config {
return config.getBoolean("Soulbound.Show_Name_In_Lore", true); 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) { public static void load(final FileConfig config) {
Config.config = config; Config.config = config;
} }

View File

@ -43,7 +43,7 @@ public class InventoryListener implements Listener {
if (itemType != ItemType.SOULBOUND) { if (itemType != ItemType.SOULBOUND) {
return; return;
} }
if (!Config.getAllowItemStoring() && !(inventoryType == InventoryType.CRAFTING)) { if (!Config.getAllowItemStoring() && inventoryType != InventoryType.CRAFTING) {
event.setCancelled(true); event.setCancelled(true);
} }
if (ItemUtils.isBindedPlayer(player, itemStack) || Permissions.pickupBypass(player)) { if (ItemUtils.isBindedPlayer(player, itemStack) || Permissions.pickupBypass(player)) {

View File

@ -50,7 +50,7 @@ public class PlayerListener implements Listener {
final String command = event.getMessage(); final String command = event.getMessage();
if (ItemUtils.isSoulbound(itemStack) && Config.getBlockedCommands().contains(command)) { if (ItemUtils.isSoulbound(itemStack) && Config.getBlockedCommands().contains(command)) {
player.sendMessage(ChatColor.RED + "You're not allowed to use " + ChatColor.GOLD + command + ChatColor.RED + " command while holding a Soulbound item."); player.sendMessage(ChatColor.RED + "不允许使用命令 " + ChatColor.GOLD + command + ChatColor.RED + " 当拿着绑定物品的时候.");
event.setCancelled(true); event.setCancelled(true);
} }
} }

View File

@ -29,7 +29,7 @@ public class SelfListener implements Listener {
} }
} }
if (count >= maxAmount) { if (count >= maxAmount) {
player.sendMessage(ChatColor.RED + "Cannot Soulbind any more items, maximum amount reached! " + ChatColor.GOLD + "(" + maxAmount + ")"); player.sendMessage(ChatColor.RED + "无法绑定更多的物品, 已到达最大上限! " + ChatColor.GOLD + "(" + maxAmount + ")");
event.setCancelled(true); event.setCancelled(true);
} }
} }

View File

@ -9,23 +9,22 @@ import com.me.tft_02.soulbound.datatypes.ActionType;
import com.me.tft_02.soulbound.util.ItemUtils; import com.me.tft_02.soulbound.util.ItemUtils;
public class SoulbindInventoryTask extends BukkitRunnable { public class SoulbindInventoryTask extends BukkitRunnable {
private Player player; private final ActionType actionType;
private ActionType actionType; private final Player player;
public SoulbindInventoryTask(Player player, ActionType actionType) { public SoulbindInventoryTask(final Player player, final ActionType actionType) {
this.player = player; this.player = player;
this.actionType = actionType; this.actionType = actionType;
} }
@Override @Override
public void run() { public void run() {
for (ItemStack itemStack : player.getInventory().getContents()) { for (final ItemStack itemStack : player.getInventory().getContents()) {
if (itemStack != null && ItemsConfig.isActionItem(itemStack, actionType)) { if (itemStack != null && ItemsConfig.isActionItem(itemStack, actionType)) {
ItemUtils.soulbindItem(player, itemStack); ItemUtils.soulbindItem(player, itemStack);
} }
} }
for (final ItemStack itemStack : player.getInventory().getArmorContents()) {
for (ItemStack itemStack : player.getInventory().getArmorContents()) {
if (itemStack != null && ItemsConfig.isActionItem(itemStack, actionType)) { if (itemStack != null && ItemsConfig.isActionItem(itemStack, actionType)) {
ItemUtils.soulbindItem(player, itemStack); ItemUtils.soulbindItem(player, itemStack);
} }

View File

@ -8,24 +8,23 @@ import com.me.tft_02.soulbound.util.ItemUtils;
import com.me.tft_02.soulbound.util.ItemUtils.ItemType; import com.me.tft_02.soulbound.util.ItemUtils.ItemType;
public class UpdateArmorTask extends BukkitRunnable { public class UpdateArmorTask extends BukkitRunnable {
private Player player; private final Player player;
public UpdateArmorTask(Player player) { public UpdateArmorTask(final Player player) {
this.player = player; this.player = player;
} }
public void handleBindOnEquip(final Player player) {
for (final 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());
}
@Override @Override
public void run() { public void run() {
handleBindOnEquip(player); 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

@ -4,9 +4,9 @@ import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
public class UpdateInventoryTask extends BukkitRunnable { public class UpdateInventoryTask extends BukkitRunnable {
private Player player; private final Player player;
public UpdateInventoryTask(Player player) { public UpdateInventoryTask(final Player player) {
this.player = player; this.player = player;
} }

View File

@ -7,32 +7,30 @@ import org.bukkit.entity.Player;
public final class CommandUtils { public final class CommandUtils {
public static String[] extractArgs(String command) { public static String[] extractArgs(final String command) {
String[] args = { "" }; String[] args = { "" };
String[] split = command.split(" ", 2); final String[] split = command.split(" ", 2);
if (split.length > 1) { if (split.length > 1) {
args = split[1].split(" "); args = split[1].split(" ");
} }
return args; return args;
} }
public static boolean noConsoleUsage(CommandSender sender) { public static boolean isOffline(final CommandSender sender, final OfflinePlayer player) {
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()) { if (player != null && player.isOnline()) {
return false; return false;
} }
sender.sendMessage(ChatColor.RED + "This command does not work for offline players."); sender.sendMessage(ChatColor.RED + "当前命令不能作用于离线的玩家.");
return true;
}
public static boolean noConsoleUsage(final CommandSender sender) {
if (sender instanceof Player) {
return false;
}
sender.sendMessage("当前命令不能再控制台执行!");
return true; return true;
} }
} }

View File

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

View File

@ -13,15 +13,282 @@ import com.me.tft_02.soulbound.config.Config;
import com.me.tft_02.soulbound.events.SoulbindItemEvent; import com.me.tft_02.soulbound.events.SoulbindItemEvent;
public class ItemUtils { public class ItemUtils {
public enum ItemType { public static ItemStack boeItem(final ItemStack itemStack) {
NORMAL, if (itemStack == null) {
SOULBOUND, return itemStack;
BIND_ON_PICKUP,
BIND_ON_USE,
BIND_ON_EQUIP;
} }
public static ItemStack soulbindItem(Player player, ItemStack itemStack) { if (isBindOnEquip(itemStack)) {
return itemStack;
}
final ItemMeta itemMeta = itemStack.getItemMeta();
final List<String> itemLore = new ArrayList<String>();
if (itemMeta.hasLore()) {
itemLore.addAll(itemMeta.getLore());
}
itemLore.add(Misc.EQUIPBIND_TAG);
itemMeta.setLore(itemLore);
itemStack.setItemMeta(itemMeta);
return itemStack;
}
public static ItemStack bopItem(final ItemStack itemStack) {
if (itemStack == null) {
return itemStack;
}
if (isBindOnPickup(itemStack)) {
return itemStack;
}
final ItemMeta itemMeta = itemStack.getItemMeta();
final List<String> itemLore = new ArrayList<String>();
if (itemMeta.hasLore()) {
itemLore.addAll(itemMeta.getLore());
}
itemLore.add(Misc.PICKUPBIND_TAG);
itemMeta.setLore(itemLore);
itemStack.setItemMeta(itemMeta);
return itemStack;
}
public static ItemStack bouItem(final ItemStack itemStack) {
if (itemStack == null) {
return itemStack;
}
if (isBindOnUse(itemStack)) {
return itemStack;
}
final ItemMeta itemMeta = itemStack.getItemMeta();
final List<String> itemLore = new ArrayList<String>();
if (itemMeta.hasLore()) {
itemLore.addAll(itemMeta.getLore());
}
itemLore.add(Misc.USEBIND_TAG);
itemMeta.setLore(itemLore);
itemStack.setItemMeta(itemMeta);
return itemStack;
}
public static ItemType getItemType(final 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;
}
}
public static boolean isBindedPlayer(final Player player, final ItemStack itemStack) {
final List<String> itemLore = itemStack.getItemMeta().getLore();
return itemLore.contains(player.getName());
}
public static boolean isBindOnEquip(final ItemStack itemStack) {
if (!itemStack.hasItemMeta()) {
return false;
}
final ItemMeta itemMeta = itemStack.getItemMeta();
if (itemMeta.hasLore()) {
final List<String> itemLore = itemMeta.getLore();
if (itemLore.contains(Misc.EQUIPBIND_TAG)) {
return true;
}
}
return false;
}
public static boolean isBindOnPickup(final ItemStack itemStack) {
if (!itemStack.hasItemMeta()) {
return false;
}
final ItemMeta itemMeta = itemStack.getItemMeta();
if (itemMeta.hasLore()) {
final List<String> itemLore = itemMeta.getLore();
if (itemLore.contains(Misc.PICKUPBIND_TAG)) {
return true;
}
}
return false;
}
public static boolean isBindOnUse(final ItemStack itemStack) {
if (!itemStack.hasItemMeta()) {
return false;
}
final ItemMeta itemMeta = itemStack.getItemMeta();
if (itemMeta.hasLore()) {
final List<String> itemLore = itemMeta.getLore();
if (itemLore.contains(Misc.USEBIND_TAG)) {
return true;
}
}
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(final ItemStack is) {
switch (is.getType()) {
case CHAINMAIL_BOOTS:
case CHAINMAIL_CHESTPLATE:
case CHAINMAIL_HELMET:
case CHAINMAIL_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(final 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 an equipable item.
*
* @param is
* Item to check
*
* @return true if the item is equipable, false otherwise
*/
public static boolean isEquipable(final ItemStack is) {
return isMinecraftArmor(is) || is.getType() == Material.SKULL_ITEM || is.getType() == Material.JACK_O_LANTERN;
}
/**
* 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(final 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(final 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 leather armor piece.
*
* @param is
* Item to check
*
* @return true if the item is leather armor, false otherwise
*/
public static boolean isLeatherArmor(final 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 wearable armor piece.
*
* @param is
* Item to check
*
* @return true if the item is armor, false otherwise
*/
public static boolean isMinecraftArmor(final ItemStack is) {
return isLeatherArmor(is) || isGoldArmor(is) || isIronArmor(is) || isDiamondArmor(is) || isChainmailArmor(is);
}
public static boolean isNormalItem(final ItemStack itemStack) {
return !itemStack.hasItemMeta() && !itemStack.getItemMeta().hasLore() || ItemUtils.getItemType(itemStack) == ItemType.NORMAL;
}
public static boolean isSoulbound(final ItemStack itemStack) {
if (!itemStack.hasItemMeta()) {
return false;
}
final ItemMeta itemMeta = itemStack.getItemMeta();
if (itemMeta.hasLore()) {
final List<String> itemLore = itemMeta.getLore();
for (final String lore : itemLore) {
if (lore.contains(Misc.SOULBOUND_TAG)) {
return true;
}
}
}
return false;
}
public static ItemStack soulbindItem(final Player player, ItemStack itemStack) {
if (itemStack == null) { if (itemStack == null) {
return itemStack; return itemStack;
} }
@ -30,7 +297,7 @@ public class ItemUtils {
return itemStack; return itemStack;
} }
SoulbindItemEvent soulbindItemEvent = new SoulbindItemEvent(player, itemStack); final SoulbindItemEvent soulbindItemEvent = new SoulbindItemEvent(player, itemStack);
Soulbound.p.getServer().getPluginManager().callEvent(soulbindItemEvent); Soulbound.p.getServer().getPluginManager().callEvent(soulbindItemEvent);
itemStack = soulbindItemEvent.getItemStack(); itemStack = soulbindItemEvent.getItemStack();
@ -38,11 +305,11 @@ public class ItemUtils {
return itemStack; return itemStack;
} }
ItemMeta itemMeta = itemStack.getItemMeta(); final ItemMeta itemMeta = itemStack.getItemMeta();
List<String> itemLore = new ArrayList<String>(); final List<String> itemLore = new ArrayList<String>();
if (itemMeta.hasLore()) { if (itemMeta.hasLore()) {
List<String> oldLore = itemMeta.getLore(); final List<String> oldLore = itemMeta.getLore();
oldLore.remove(Misc.EQUIPBIND_TAG); oldLore.remove(Misc.EQUIPBIND_TAG);
oldLore.remove(Misc.PICKUPBIND_TAG); oldLore.remove(Misc.PICKUPBIND_TAG);
oldLore.remove(Misc.USEBIND_TAG); oldLore.remove(Misc.USEBIND_TAG);
@ -60,78 +327,15 @@ public class ItemUtils {
return itemStack; return itemStack;
} }
public static ItemStack bopItem(ItemStack itemStack) { public static ItemStack unbindItem(final 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(Misc.PICKUPBIND_TAG);
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(Misc.EQUIPBIND_TAG);
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(Misc.USEBIND_TAG);
itemMeta.setLore(itemLore);
itemStack.setItemMeta(itemMeta);
return itemStack;
}
public static ItemStack unbindItem(ItemStack itemStack) {
if (itemStack == null) { if (itemStack == null) {
return null; return null;
} }
ItemMeta itemMeta = itemStack.getItemMeta(); final ItemMeta itemMeta = itemStack.getItemMeta();
if (itemMeta.hasLore() && isSoulbound(itemStack)) { if (itemMeta.hasLore() && isSoulbound(itemStack)) {
List<String> oldLore = itemMeta.getLore(); final List<String> oldLore = itemMeta.getLore();
int loreSize = oldLore.size(); final int loreSize = oldLore.size();
if (loreSize <= 2) { if (loreSize <= 2) {
itemMeta.setLore(null); itemMeta.setLore(null);
@ -139,17 +343,18 @@ public class ItemUtils {
return itemStack; return itemStack;
} }
List<String> itemLore = new ArrayList<String>(); final List<String> itemLore = new ArrayList<String>();
itemLore.addAll(oldLore); itemLore.addAll(oldLore);
int index = StringUtils.getIndexOfSoulbound(itemLore); final int index = StringUtils.getIndexOfSoulbound(itemLore);
if (index == -1) { if (index == -1) {
return null; return null;
} }
itemLore.remove(index); itemLore.remove(index);
if (index<itemLore.size()) if (index < itemLore.size()) {
itemLore.remove(index); itemLore.remove(index);
}
itemMeta.setLore(itemLore); itemMeta.setLore(itemLore);
} }
@ -158,218 +363,11 @@ public class ItemUtils {
return itemStack; return itemStack;
} }
public static boolean isSoulbound(ItemStack itemStack) { public enum ItemType {
if (!itemStack.hasItemMeta()) { BIND_ON_EQUIP,
return false; BIND_ON_PICKUP,
} BIND_ON_USE,
NORMAL,
ItemMeta itemMeta = itemStack.getItemMeta(); SOULBOUND;
if (itemMeta.hasLore()) {
List<String> itemLore = itemMeta.getLore();
for (String lore : itemLore) {
if (lore.contains(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(Misc.PICKUPBIND_TAG)) {
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(Misc.USEBIND_TAG)) {
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(Misc.EQUIPBIND_TAG)) {
return true;
}
}
return false;
}
public static boolean isBindedPlayer(Player player, ItemStack itemStack) {
List<String> itemLore = itemStack.getItemMeta().getLore();
return itemLore.contains(player.getName());
}
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

@ -1,23 +0,0 @@
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 final boolean debug;
public LogFilter(final 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(final LogRecord record) {
if (record.getMessage().contains("[Debug]") && !debug) {
return false;
}
return true;
}
}

View File

@ -6,35 +6,26 @@ import org.bukkit.permissions.PermissionAttachmentInfo;
public class Permissions { public class Permissions {
public static boolean keepOnDeath(Permissible permissible) { public static boolean deleteOnDeath(final Permissible permissible) {
return permissible.hasPermission("soulbound.items.keep_on_death");
}
public static boolean deleteOnDeath(Permissible permissible) {
return permissible.hasPermission("soulbound.items.delete_on_death"); return permissible.hasPermission("soulbound.items.delete_on_death");
} }
public static boolean pickupBypass(Permissible permissible) { public static int getSoulbindMaximum(final Player player) {
return permissible.hasPermission("soulbound.pickup.bypass"); final String match = "soulbound.maximum_allowed.";
}
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; int amount = -1;
for (final PermissionAttachmentInfo permission : player.getEffectivePermissions()) {
for (PermissionAttachmentInfo permission : player if (permission.getPermission().startsWith(match) && permission.getValue()) {
.getEffectivePermissions()) { amount = Integer.parseInt(permission.getPermission().split("[.]")[2]);
if (permission.getPermission().startsWith(match)
&& permission.getValue()) {
amount = Integer.parseInt(permission.getPermission().split(
"[.]")[2]);
} }
} }
return amount; return amount;
} }
public static boolean keepOnDeath(final Permissible permissible) {
return permissible.hasPermission("soulbound.items.keep_on_death");
}
public static boolean pickupBypass(final Permissible permissible) {
return permissible.hasPermission("soulbound.pickup.bypass");
}
} }

View File

@ -4,10 +4,10 @@ import java.util.List;
public class StringUtils { public class StringUtils {
public static int getIndexOfSoulbound(List<String> itemLore) { public static int getIndexOfSoulbound(final List<String> itemLore) {
int index = -1; final int index = -1;
for (String line : itemLore) { for (final String line : itemLore) {
if (line.contains(Misc.SOULBOUND_TAG)) { if (line.contains(Misc.SOULBOUND_TAG)) {
return itemLore.indexOf(line); return itemLore.indexOf(line);
} }

View File

@ -1,26 +1,6 @@
#
# Soulbound configuration
# Last updated on ${project.version}-b${BUILD_NUMBER}
#
#####
#
# Settings for Soulbound in general
###
General: General:
# Allow Soulbound to report on basic anonymous usage
Stats_Tracking: true Stats_Tracking: true
# Allow Soulbound to check if a new version is available
Update_Check: true
Prefer_Beta: false
# Should Soulbound print out debug messages?
Verbose_Logging: false
# Should Soulbound over-write configs to update, or make new ones ending in .new?
Config_Update_Overwrite: true Config_Update_Overwrite: true
Soulbound: Soulbound:
Show_Name_In_Lore: true Show_Name_In_Lore: true
Feedback_Messages_Enabled: true Feedback_Messages_Enabled: true
@ -28,13 +8,5 @@ Soulbound:
Delete_On_Drop: false Delete_On_Drop: false
Allow_Item_Storing: true Allow_Item_Storing: true
Infinite_Durability: false Infinite_Durability: false
Blocked_Commands: Blocked_Commands: /blockedcommand
/blockedcommand Commands_Bind_When_Used: /enchant
Commands_Bind_When_Used:
/enchant
Dependency_Plugins:
EpicBossRecoded:
BindOnPickup: true
BindOnUse: false
BindOnEquip: false