forked from ChestShop-authors/ChestShop-3
-
Notifications
You must be signed in to change notification settings - Fork 2
/
ItemInfo.java
70 lines (58 loc) · 2.21 KB
/
ItemInfo.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package com.Acrobot.ChestShop.Commands;
import static com.Acrobot.ChestShop.Configuration.Messages.INCORRECT_ITEM_ID;
import static com.Acrobot.ChestShop.Configuration.Messages.ITEM_INFO;
import com.Acrobot.Breeze.Utils.MaterialUtil;
import com.Acrobot.Breeze.Utils.StringUtil;
import com.Acrobot.ChestShop.ChestShop;
import com.Acrobot.ChestShop.Configuration.Messages;
import com.Acrobot.ChestShop.Events.ItemInfoEvent;
import com.Acrobot.ChestShop.Utils.ComponentUtils;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.HumanEntity;
import org.bukkit.inventory.ItemStack;
/**
* @author Acrobot
*/
public class ItemInfo implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
ItemStack item;
if (args.length == 0) {
if (!(sender instanceof HumanEntity)) {
return false;
}
item = ((HumanEntity) sender).getInventory().getItemInMainHand();
if (MaterialUtil.isEmpty(item)) {
return false;
}
} else {
item = MaterialUtil.getItem(StringUtil.joinArray(args));
}
showItemInfo(sender, item);
return true;
}
public static void showItemInfo(CommandSender sender, ItemStack item) {
sender.sendMessage(Messages.prefix(ITEM_INFO));
if (MaterialUtil.isEmpty(item)) {
sender.sendMessage(" " + ChatColor.DARK_RED + INCORRECT_ITEM_ID);
return;
}
TextComponent tc = new TextComponent(" ");
BaseComponent tcName = ComponentUtils.getLocalizedItemName(item);
tc.addExtra(tcName);
sender.spigot().sendMessage(tc);
ItemInfoEvent event = new ItemInfoEvent(sender, item);
ChestShop.callEvent(event);
}
public static String getMetadata(ItemStack item) {
if (!item.hasItemMeta()) {
return "";
}
return ChatColor.GOLD + "#" + MaterialUtil.Metadata.getItemCode(item);
}
}