1
0
mirror of https://e.coding.net/circlecloud/ItemMamager.git synced 2024-11-22 01:58:54 +00:00

complete some class and add GuiUtil...

Signed-off-by: 502647092 <jtb1@163.com>
This commit is contained in:
502647092 2015-09-23 20:58:24 +08:00
parent f385164196
commit 98bd87f908
5 changed files with 87 additions and 24 deletions

View File

@ -7,7 +7,7 @@ import org.bukkit.plugin.java.JavaPlugin;
import cn.citycraft.ItemMamager.commands.BindCommand; import cn.citycraft.ItemMamager.commands.BindCommand;
import cn.citycraft.ItemMamager.listen.PlayerListen; import cn.citycraft.ItemMamager.listen.PlayerListen;
import cn.citycraft.PluginHelper.commands.HandlerCommand; import cn.citycraft.PluginHelper.commands.HandlerSubCommand;
/** /**
* 物品管理器主类 * 物品管理器主类
@ -20,7 +20,7 @@ public class ItemMamager extends JavaPlugin {
@Override @Override
public void onEnable() { public void onEnable() {
this.getServer().getPluginManager().registerEvents(new PlayerListen(this), this); this.getServer().getPluginManager().registerEvents(new PlayerListen(this), this);
HandlerCommand cmdhandler = new HandlerCommand(this); HandlerSubCommand cmdhandler = new HandlerSubCommand(this);
cmdhandler.registerCommand(new BindCommand()); cmdhandler.registerCommand(new BindCommand());
this.getCommand("im").setExecutor(cmdhandler); this.getCommand("im").setExecutor(cmdhandler);
this.getCommand("im").setTabCompleter(cmdhandler); this.getCommand("im").setTabCompleter(cmdhandler);

View File

@ -1,5 +1,6 @@
package cn.citycraft.ItemMamager.commands; package cn.citycraft.ItemMamager.commands;
import org.bukkit.command.Command;
import org.bukkit.command.CommandException; import org.bukkit.command.CommandException;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -12,7 +13,7 @@ public class BindCommand extends BaseCommand {
} }
@Override @Override
public void execute(CommandSender sender, String label, String[] args) throws CommandException { public void execute(CommandSender sender, Command command, String label, String[] args) throws CommandException {
// TODO 自动生成的方法存根 // TODO 自动生成的方法存根
} }

View File

@ -7,6 +7,7 @@ import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.inventory.meta.ItemMeta;
import cn.citycraft.ItemMamager.utils.ItemUtil.MARK;
import cn.citycraft.ItemMamager.utils.ItemUtil.TAG; import cn.citycraft.ItemMamager.utils.ItemUtil.TAG;
/** /**
@ -31,6 +32,22 @@ public class ItemHandler {
return false; return false;
} }
public String getBindName(ItemStack itemStack) {
if (isBound(itemStack, TAG.TIME) || isBound(itemStack, TAG.TIMEBIND)) {
String mark = getMarkString(itemStack, MARK.BIND);
return MARK.BIND.clearMark(mark);
}
return null;
}
public String getBindTime(ItemStack itemStack) {
if (isBound(itemStack, TAG.BIND) || isBound(itemStack, TAG.TIMEBIND)) {
String mark = getMarkString(itemStack, MARK.TIME);
return MARK.TIME.clearMark(mark);
}
return null;
}
public int getIndex(ItemStack itemStack, TAG tag) { public int getIndex(ItemStack itemStack, TAG tag) {
if (!itemStack.hasItemMeta()) if (!itemStack.hasItemMeta())
return -1; return -1;
@ -38,16 +55,33 @@ public class ItemHandler {
if (!itemMeta.hasLore()) if (!itemMeta.hasLore())
return -1; return -1;
List<String> lores = itemMeta.getLore(); List<String> lores = itemMeta.getLore();
return lores.lastIndexOf(tag.getTag()); return tag.getIndex(lores);
}
public String getMarkString(ItemStack itemStack, MARK mark) {
if (!itemStack.hasItemMeta())
return null;
ItemMeta itemMeta = itemStack.getItemMeta();
if (!itemMeta.hasLore())
return null;
List<String> lores = itemMeta.getLore();
for (int i = 0; i < lores.size(); i++)
if (mark.hasMark(lores.get(i)))
return lores.get(i);
return null;
} }
public boolean isBound(ItemStack itemStack) { public boolean isBound(ItemStack itemStack) {
for (TAG tag : TAG.values()) for (TAG tag : TAG.values())
if (getIndex(itemStack, tag) != -1) if (isBound(itemStack, tag))
return true; return true;
return false; return false;
} }
public boolean isBound(ItemStack itemStack, TAG tag) {
return getIndex(itemStack, tag) != -1;
}
public boolean unbind(ItemStack itemStack) { public boolean unbind(ItemStack itemStack) {
return false; return false;
} }

View File

@ -0,0 +1,5 @@
package cn.citycraft.ItemMamager.utils;
public class GuiUtil {
}

View File

@ -17,28 +17,47 @@ public class ItemUtil {
public enum BIND { public enum BIND {
PICKUP(ChatColor.DARK_RED + "拾取后绑定"), PICKUP(ChatColor.DARK_RED + "拾取后绑定"),
USE(ChatColor.DARK_RED + "使用后绑定"), USE(ChatColor.DARK_RED + "使用后绑定"),
EQUIP(ChatColor.DARK_RED + "装备后绑定"); EQUIP(ChatColor.DARK_RED + "装备后绑定"),
String tag; TIME(ChatColor.DARK_RED + "有效期: ");
BIND(String tag) { String bind;
this.tag = tag;
BIND(String bind) {
this.bind = bind;
}
public int getIndex(List<String> lores) {
return lores.lastIndexOf(bind);
}
public boolean isBind(List<String> lores) {
return lores.lastIndexOf(bind) != -1;
} }
} }
public enum MARK { public enum MARK {
BIND("§b§m"), BIND(ChatColor.GOLD + "绑定玩家: "),
TIME("§t§m"); TIME(ChatColor.GOLD + "到期时间: ");
String tag; String mark;
MARK(String tag) { MARK(String mark) {
this.tag = tag; this.mark = mark;
} }
public boolean isMark(String lore) { public String addMark(String lore) {
return lore.startsWith(tag); return mark + lore;
} }
public String clearMark(String lore) {
return lore.replaceAll(mark, "");
}
public boolean hasMark(String lore) {
return lore.startsWith(mark);
}
} }
public enum STONE { public enum STONE {
@ -46,18 +65,18 @@ public class ItemUtil {
TIMEBIND(ChatColor.DARK_RED + "限时绑定石"), TIMEBIND(ChatColor.DARK_RED + "限时绑定石"),
UNBIND(ChatColor.DARK_RED + "解绑石"); UNBIND(ChatColor.DARK_RED + "解绑石");
String tag; String stone;
STONE(String tag) { STONE(String stone) {
this.tag = tag; this.stone = stone;
} }
public int getIndex(List<String> lores) { public int getIndex(List<String> lores) {
return lores.lastIndexOf(tag); return lores.lastIndexOf(stone);
} }
public boolean is(List<String> lores) { public boolean isStone(List<String> lores) {
return lores.lastIndexOf(tag) != -1; return lores.lastIndexOf(stone) != -1;
} }
} }
@ -73,8 +92,12 @@ public class ItemUtil {
this.tag = tag; this.tag = tag;
} }
public String getTag() { public int getIndex(List<String> lores) {
return tag; return lores.lastIndexOf(tag);
}
public boolean hasTag(List<String> lores) {
return lores.lastIndexOf(tag) != -1;
} }
} }