2011-12-06 06:25:54 +08:00
|
|
|
package com.earth2me.essentials.commands;
|
|
|
|
|
2013-10-16 20:59:39 +01:00
|
|
|
import com.earth2me.essentials.CommandSource;
|
2021-02-05 15:27:33 -05:00
|
|
|
import com.earth2me.essentials.utils.StringUtil;
|
2018-12-31 11:57:15 +00:00
|
|
|
import com.earth2me.essentials.utils.VersionUtil;
|
2012-06-10 18:31:28 +01:00
|
|
|
import org.bukkit.Material;
|
2011-12-06 06:25:54 +08:00
|
|
|
import org.bukkit.Server;
|
|
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
|
2021-07-06 14:29:24 +10:00
|
|
|
import java.util.ArrayList;
|
2017-06-11 01:17:43 +01:00
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.List;
|
|
|
|
|
2015-04-14 23:06:16 -05:00
|
|
|
import static com.earth2me.essentials.I18n.tl;
|
|
|
|
|
|
|
|
public class Commanditemdb extends EssentialsCommand {
|
|
|
|
public Commanditemdb() {
|
|
|
|
super("itemdb");
|
|
|
|
}
|
2011-12-06 06:25:54 +08:00
|
|
|
|
2015-04-14 23:06:16 -05:00
|
|
|
@Override
|
2020-10-03 18:46:05 +01:00
|
|
|
protected void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception {
|
2015-04-14 23:06:16 -05:00
|
|
|
ItemStack itemStack = null;
|
|
|
|
boolean itemHeld = false;
|
2020-08-11 14:09:22 -04:00
|
|
|
if (args.length == 0) {
|
2017-12-12 22:06:25 -08:00
|
|
|
if (sender.isPlayer() && sender.getPlayer() != null) {
|
2015-04-14 23:06:16 -05:00
|
|
|
itemHeld = true;
|
2019-01-03 20:32:35 +00:00
|
|
|
itemStack = ess.getUser(sender.getPlayer()).getItemInHand();
|
2015-04-14 23:06:16 -05:00
|
|
|
}
|
|
|
|
if (itemStack == null) {
|
|
|
|
throw new NotEnoughArgumentsException();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
itemStack = ess.getItemDb().get(args[0]);
|
|
|
|
}
|
2017-12-12 22:06:25 -08:00
|
|
|
|
2019-01-05 16:28:53 +00:00
|
|
|
String itemId = "none";
|
2012-09-08 18:41:21 +01: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-14 23:06:16 -05:00
|
|
|
if (itemHeld && itemStack.getType() != Material.AIR) {
|
2020-10-03 18:46:05 +01:00
|
|
|
final int maxuses = itemStack.getType().getMaxDurability();
|
|
|
|
final int durability = (maxuses + 1) - itemStack.getDurability();
|
2015-04-14 23:06:16 -05:00
|
|
|
if (maxuses != 0) {
|
|
|
|
sender.sendMessage(tl("durability", Integer.toString(durability)));
|
|
|
|
}
|
|
|
|
}
|
2021-02-05 15:27:33 -05:00
|
|
|
|
|
|
|
List<String> nameList = ess.getItemDb().nameList(itemStack);
|
2021-07-06 14:29:24 +10:00
|
|
|
nameList = nameList != null ? new ArrayList<>(nameList) : new ArrayList<>();
|
2021-02-05 15:27:33 -05:00
|
|
|
nameList.addAll(ess.getCustomItemResolver().getAliasesFor(ess.getItemDb().name(itemStack)));
|
2021-07-06 14:29:24 +10:00
|
|
|
if (nameList.isEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
2021-02-05 15:27:33 -05:00
|
|
|
|
2021-07-06 14:29:24 +10:00
|
|
|
Collections.sort(nameList);
|
2021-02-05 15:27:33 -05:00
|
|
|
if (nameList.size() > 15) {
|
|
|
|
nameList = nameList.subList(0, 14);
|
2015-04-14 23:06:16 -05:00
|
|
|
}
|
2021-02-05 15:27:33 -05:00
|
|
|
final String itemNameList = StringUtil.joinList(", ", nameList);
|
|
|
|
sender.sendMessage(tl("itemNames", itemNameList));
|
2015-04-14 23:06:16 -05:00
|
|
|
}
|
2017-06-11 01:17:43 +01:00
|
|
|
|
|
|
|
@Override
|
2020-10-03 18:46:05 +01:00
|
|
|
protected List<String> getTabCompleteOptions(final Server server, final CommandSource sender, final String commandLabel, final String[] args) {
|
2017-06-11 01:17:43 +01:00
|
|
|
if (args.length == 1) {
|
|
|
|
return getItems();
|
|
|
|
} else {
|
|
|
|
return Collections.emptyList();
|
|
|
|
}
|
|
|
|
}
|
2011-12-06 06:25:54 +08:00
|
|
|
}
|