mirror of
https://e.coding.net/circlecloud/ItemMamager.git
synced 2024-11-21 01:48:53 +00:00
complete some class and add GuiUtil...
Signed-off-by: 502647092 <jtb1@163.com>
This commit is contained in:
parent
f385164196
commit
98bd87f908
@ -7,7 +7,7 @@ import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import cn.citycraft.ItemMamager.commands.BindCommand;
|
||||
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
|
||||
public void onEnable() {
|
||||
this.getServer().getPluginManager().registerEvents(new PlayerListen(this), this);
|
||||
HandlerCommand cmdhandler = new HandlerCommand(this);
|
||||
HandlerSubCommand cmdhandler = new HandlerSubCommand(this);
|
||||
cmdhandler.registerCommand(new BindCommand());
|
||||
this.getCommand("im").setExecutor(cmdhandler);
|
||||
this.getCommand("im").setTabCompleter(cmdhandler);
|
||||
|
@ -1,5 +1,6 @@
|
||||
package cn.citycraft.ItemMamager.commands;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandException;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
@ -12,7 +13,7 @@ public class BindCommand extends BaseCommand {
|
||||
}
|
||||
|
||||
@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 自动生成的方法存根
|
||||
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import cn.citycraft.ItemMamager.utils.ItemUtil.MARK;
|
||||
import cn.citycraft.ItemMamager.utils.ItemUtil.TAG;
|
||||
|
||||
/**
|
||||
@ -31,6 +32,22 @@ public class ItemHandler {
|
||||
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) {
|
||||
if (!itemStack.hasItemMeta())
|
||||
return -1;
|
||||
@ -38,16 +55,33 @@ public class ItemHandler {
|
||||
if (!itemMeta.hasLore())
|
||||
return -1;
|
||||
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) {
|
||||
for (TAG tag : TAG.values())
|
||||
if (getIndex(itemStack, tag) != -1)
|
||||
if (isBound(itemStack, tag))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isBound(ItemStack itemStack, TAG tag) {
|
||||
return getIndex(itemStack, tag) != -1;
|
||||
}
|
||||
|
||||
public boolean unbind(ItemStack itemStack) {
|
||||
return false;
|
||||
}
|
||||
|
@ -0,0 +1,5 @@
|
||||
package cn.citycraft.ItemMamager.utils;
|
||||
|
||||
public class GuiUtil {
|
||||
|
||||
}
|
@ -17,28 +17,47 @@ public class ItemUtil {
|
||||
public enum BIND {
|
||||
PICKUP(ChatColor.DARK_RED + "拾取后绑定"),
|
||||
USE(ChatColor.DARK_RED + "使用后绑定"),
|
||||
EQUIP(ChatColor.DARK_RED + "装备后绑定");
|
||||
EQUIP(ChatColor.DARK_RED + "装备后绑定"),
|
||||
|
||||
String tag;
|
||||
TIME(ChatColor.DARK_RED + "有效期: ");
|
||||
|
||||
BIND(String tag) {
|
||||
this.tag = tag;
|
||||
String bind;
|
||||
|
||||
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 {
|
||||
BIND("§b§m"),
|
||||
TIME("§t§m");
|
||||
BIND(ChatColor.GOLD + "绑定玩家: "),
|
||||
TIME(ChatColor.GOLD + "到期时间: ");
|
||||
|
||||
String tag;
|
||||
String mark;
|
||||
|
||||
MARK(String tag) {
|
||||
this.tag = tag;
|
||||
MARK(String mark) {
|
||||
this.mark = mark;
|
||||
}
|
||||
|
||||
public boolean isMark(String lore) {
|
||||
return lore.startsWith(tag);
|
||||
public String addMark(String lore) {
|
||||
return mark + lore;
|
||||
}
|
||||
|
||||
public String clearMark(String lore) {
|
||||
return lore.replaceAll(mark, "");
|
||||
}
|
||||
|
||||
public boolean hasMark(String lore) {
|
||||
return lore.startsWith(mark);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public enum STONE {
|
||||
@ -46,18 +65,18 @@ public class ItemUtil {
|
||||
TIMEBIND(ChatColor.DARK_RED + "限时绑定石"),
|
||||
UNBIND(ChatColor.DARK_RED + "解绑石");
|
||||
|
||||
String tag;
|
||||
String stone;
|
||||
|
||||
STONE(String tag) {
|
||||
this.tag = tag;
|
||||
STONE(String stone) {
|
||||
this.stone = stone;
|
||||
}
|
||||
|
||||
public int getIndex(List<String> lores) {
|
||||
return lores.lastIndexOf(tag);
|
||||
return lores.lastIndexOf(stone);
|
||||
}
|
||||
|
||||
public boolean is(List<String> lores) {
|
||||
return lores.lastIndexOf(tag) != -1;
|
||||
public boolean isStone(List<String> lores) {
|
||||
return lores.lastIndexOf(stone) != -1;
|
||||
}
|
||||
}
|
||||
|
||||
@ -73,8 +92,12 @@ public class ItemUtil {
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
public String getTag() {
|
||||
return tag;
|
||||
public int getIndex(List<String> lores) {
|
||||
return lores.lastIndexOf(tag);
|
||||
}
|
||||
|
||||
public boolean hasTag(List<String> lores) {
|
||||
return lores.lastIndexOf(tag) != -1;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user