diff --git a/src/main/java/cn/citycraft/ItemMamager/manager/ItemHandler.java b/src/main/java/cn/citycraft/ItemMamager/manager/ItemHandler.java index 2199aa4..da7372d 100644 --- a/src/main/java/cn/citycraft/ItemMamager/manager/ItemHandler.java +++ b/src/main/java/cn/citycraft/ItemMamager/manager/ItemHandler.java @@ -1,9 +1,11 @@ package cn.citycraft.ItemMamager.manager; import java.util.Date; +import java.util.List; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.ItemMeta; import cn.citycraft.ItemMamager.utils.ItemUtil.TAG; @@ -15,19 +17,38 @@ import cn.citycraft.ItemMamager.utils.ItemUtil.TAG; */ public class ItemHandler { - public static ItemStack bind(Player player, ItemStack itemStack) { - return TAG.BIND.bind(player, itemStack); + public ItemStack bind(Player player, ItemStack itemStack) { + if (isBound(itemStack)) + return itemStack; + return itemStack; } - public static boolean bingtime(ItemStack item) { + public boolean bingtime(ItemStack item) { return bingtime(item, new Date()); } - public static boolean bingtime(ItemStack item, Date time) { + public boolean bingtime(ItemStack item, Date time) { return false; } - public static boolean unbind(ItemStack itemStack) { + public int getIndex(ItemStack itemStack, TAG tag) { + if (!itemStack.hasItemMeta()) + return -1; + ItemMeta itemMeta = itemStack.getItemMeta(); + if (!itemMeta.hasLore()) + return -1; + List lores = itemMeta.getLore(); + return lores.lastIndexOf(tag.getTag()); + } + + public boolean isBound(ItemStack itemStack) { + for (TAG tag : TAG.values()) + if (getIndex(itemStack, tag) != -1) + return true; + return false; + } + + public boolean unbind(ItemStack itemStack) { return false; } } diff --git a/src/main/java/cn/citycraft/ItemMamager/runnable/ArmorHandlerTask.java b/src/main/java/cn/citycraft/ItemMamager/runnable/ArmorHandlerTask.java index c0fc860..564dec2 100644 --- a/src/main/java/cn/citycraft/ItemMamager/runnable/ArmorHandlerTask.java +++ b/src/main/java/cn/citycraft/ItemMamager/runnable/ArmorHandlerTask.java @@ -1,5 +1,11 @@ package cn.citycraft.ItemMamager.runnable; -public class ArmorHandlerTask { +public class ArmorHandlerTask implements Runnable { + + @Override + public void run() { + // TODO 自动生成的方法存根 + + } } diff --git a/src/main/java/cn/citycraft/ItemMamager/runnable/InventoryHandlerTask.java b/src/main/java/cn/citycraft/ItemMamager/runnable/InventoryHandlerTask.java index ff830cb..f65232f 100644 --- a/src/main/java/cn/citycraft/ItemMamager/runnable/InventoryHandlerTask.java +++ b/src/main/java/cn/citycraft/ItemMamager/runnable/InventoryHandlerTask.java @@ -1,5 +1,11 @@ package cn.citycraft.ItemMamager.runnable; -public class InventoryHandlerTask { +public class InventoryHandlerTask implements Runnable { + + @Override + public void run() { + // TODO 自动生成的方法存根 + + } } diff --git a/src/main/java/cn/citycraft/ItemMamager/runnable/ItemHandlerTask.java b/src/main/java/cn/citycraft/ItemMamager/runnable/ItemHandlerTask.java index a1598e5..61856d0 100644 --- a/src/main/java/cn/citycraft/ItemMamager/runnable/ItemHandlerTask.java +++ b/src/main/java/cn/citycraft/ItemMamager/runnable/ItemHandlerTask.java @@ -1,5 +1,11 @@ package cn.citycraft.ItemMamager.runnable; -public class ItemHandlerTask { +public class ItemHandlerTask implements Runnable { + + @Override + public void run() { + // TODO 自动生成的方法存根 + + } } diff --git a/src/main/java/cn/citycraft/ItemMamager/runnable/TaskManager.java b/src/main/java/cn/citycraft/ItemMamager/runnable/TaskManager.java new file mode 100644 index 0000000..a5a10a3 --- /dev/null +++ b/src/main/java/cn/citycraft/ItemMamager/runnable/TaskManager.java @@ -0,0 +1,30 @@ +package cn.citycraft.ItemMamager.runnable; + +import java.util.HashMap; + +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; +import org.bukkit.scheduler.BukkitTask; + +public class TaskManager { + static HashMap tasklist; + static Plugin plugin; + static int tasktime; + + public static void add(Player p, Runnable run) { + tasklist.put(p.getName(), Bukkit.getScheduler().runTaskTimer(plugin, run, tasktime, tasktime)); + } + + public static void init(Plugin plugin) { + TaskManager.plugin = plugin; + tasktime = plugin.getConfig().getInt("CheckTime") * 20; + tasklist = new HashMap(); + } + + public static void remove(Player p) { + if (tasklist.containsKey(p.getName())) + tasklist.remove(p.getName()).cancel(); + } + +} diff --git a/src/main/java/cn/citycraft/ItemMamager/utils/ItemUtil.java b/src/main/java/cn/citycraft/ItemMamager/utils/ItemUtil.java index 8a42b4a..1b64d19 100644 --- a/src/main/java/cn/citycraft/ItemMamager/utils/ItemUtil.java +++ b/src/main/java/cn/citycraft/ItemMamager/utils/ItemUtil.java @@ -6,13 +6,10 @@ package cn.citycraft.ItemMamager.utils; import java.util.List; import org.bukkit.ChatColor; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; /** * 物品绑定类 - * + * * @author 蒋天蓓 * */ @@ -76,28 +73,10 @@ public class ItemUtil { this.tag = tag; } - public ItemStack bind(Player player, ItemStack itemStack) { - if (isBound(itemStack)) - return itemStack; - return itemStack; + public String getTag() { + return tag; } - public int getIndex(ItemStack itemStack) { - if (!itemStack.hasItemMeta()) - return -1; - ItemMeta itemMeta = itemStack.getItemMeta(); - if (!itemMeta.hasLore()) - return -1; - List lores = itemMeta.getLore(); - return lores.lastIndexOf(tag); - } - - public boolean isBound(ItemStack itemStack) { - for (TAG tag : TAG.values()) - if (tag.getIndex(itemStack) != -1) - return true; - return false; - } } }