2011-12-05 22:25:54 +00:00
|
|
|
package com.earth2me.essentials.commands;
|
|
|
|
|
2013-10-16 19:59:39 +00:00
|
|
|
import com.earth2me.essentials.CommandSource;
|
2018-12-31 11:57:15 +00:00
|
|
|
import com.earth2me.essentials.utils.VersionUtil;
|
2012-06-10 17:31:28 +00:00
|
|
|
import org.bukkit.Material;
|
2011-12-05 22:25:54 +00:00
|
|
|
import org.bukkit.Server;
|
|
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
|
2017-06-11 00:17:43 +00:00
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.List;
|
|
|
|
|
2015-04-15 04:06:16 +00:00
|
|
|
import static com.earth2me.essentials.I18n.tl;
|
|
|
|
|
2011-12-05 22:25:54 +00:00
|
|
|
|
2015-04-15 04:06:16 +00:00
|
|
|
public class Commanditemdb extends EssentialsCommand {
|
|
|
|
public Commanditemdb() {
|
|
|
|
super("itemdb");
|
|
|
|
}
|
2011-12-05 22:25:54 +00:00
|
|
|
|
2015-04-15 04:06:16 +00:00
|
|
|
@Override
|
|
|
|
protected void run(Server server, CommandSource sender, String commandLabel, String[] args) throws Exception {
|
|
|
|
ItemStack itemStack = null;
|
|
|
|
boolean itemHeld = false;
|
|
|
|
if (args.length < 1) {
|
2017-12-13 06:06:25 +00:00
|
|
|
if (sender.isPlayer() && sender.getPlayer() != null) {
|
2015-04-15 04:06:16 +00:00
|
|
|
itemHeld = true;
|
2019-01-03 20:32:35 +00:00
|
|
|
itemStack = ess.getUser(sender.getPlayer()).getItemInHand();
|
2015-04-15 04:06:16 +00:00
|
|
|
}
|
|
|
|
if (itemStack == null) {
|
|
|
|
throw new NotEnoughArgumentsException();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
itemStack = ess.getItemDb().get(args[0]);
|
|
|
|
}
|
2017-12-13 06:06:25 +00:00
|
|
|
|
2019-01-05 16:28:53 +00:00
|
|
|
String itemId = "none";
|
2012-09-08 17:41:21 +00:00
|
|
|
|
2018-12-31 11:57:15 +00:00
|
|
|
if (VersionUtil.getServerBukkitVersion().isLowerThan(VersionUtil.v1_13_0_R01)) {
|
2019-01-05 16:28:53 +00:00
|
|
|
itemId = itemStack.getType().getId() + ":" + itemStack.getDurability();
|
|
|
|
}
|
|
|
|
|
|
|
|
sender.sendMessage(tl("itemType", itemStack.getType().toString(), itemId));
|
|
|
|
|
|
|
|
// Don't send IDs twice
|
|
|
|
if (!tl("itemType").contains("{1}") && !itemId.equals("none")) {
|
2018-12-31 11:57:15 +00:00
|
|
|
sender.sendMessage(tl("itemId", itemId));
|
|
|
|
}
|
|
|
|
|
2015-04-15 04:06:16 +00:00
|
|
|
if (itemHeld && itemStack.getType() != Material.AIR) {
|
|
|
|
int maxuses = itemStack.getType().getMaxDurability();
|
|
|
|
int durability = ((maxuses + 1) - itemStack.getDurability());
|
|
|
|
if (maxuses != 0) {
|
|
|
|
sender.sendMessage(tl("durability", Integer.toString(durability)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
final String itemNameList = ess.getItemDb().names(itemStack);
|
|
|
|
if (itemNameList != null) {
|
|
|
|
sender.sendMessage(tl("itemNames", ess.getItemDb().names(itemStack)));
|
|
|
|
}
|
|
|
|
}
|
2017-06-11 00:17:43 +00:00
|
|
|
|
|
|
|
@Override
|
|
|
|
protected List<String> getTabCompleteOptions(Server server, CommandSource sender, String commandLabel, String[] args) {
|
|
|
|
if (args.length == 1) {
|
|
|
|
return getItems();
|
|
|
|
} else {
|
|
|
|
return Collections.emptyList();
|
|
|
|
}
|
|
|
|
}
|
2011-12-05 22:25:54 +00:00
|
|
|
}
|