Allow clearing item names + add locale messages for /itemname

This commit is contained in:
md678685 2019-05-30 15:09:31 +01:00
parent 155d3ec938
commit 111a18585d
3 changed files with 15 additions and 8 deletions

View File

@ -7,6 +7,7 @@ import com.earth2me.essentials.I18n;
import com.earth2me.essentials.User;
import com.earth2me.essentials.utils.FormatUtil;
import com.earth2me.essentials.utils.MaterialUtil;
import org.bukkit.Material;
import org.bukkit.Server;
import org.bukkit.inventory.ItemStack;
@ -23,14 +24,17 @@ public class Commanditemname extends EssentialsCommand {
@Override
protected void run(Server server, User user, String commandLabel, String[] args) throws Exception {
ItemStack item = user.getBase().getItemInHand();
if (item.getType() != Material.AIR) {
String name = FormatUtil.formatString(user, "essentials.itemname", getFinalArg(args, 0));
if (item.getType().name().contains("AIR")) {
user.sendMessage(tl("itemnameInvalidItem", item.getType().toString().toLowerCase(Locale.ENGLISH).replace('_', ' ')));
return;
}
String name = FormatUtil.formatString(user, "essentials.itemname", getFinalArg(args, 0)).trim();
if (name.isEmpty()) name = null;
ItemMeta im = item.getItemMeta();
im.setDisplayName(name);
item.setItemMeta(im);
user.sendMessage(tl("itemnameSuccess", name));
return;
}
user.sendMessage(tl("itemnameInvalidItem", item.getType().toString().toLowerCase(Locale.ENGLISH).replace('_', ' ')));
user.sendMessage(name == null ? tl("itemnameClear") : tl("itemnameSuccess", name));
}
}

View File

@ -211,6 +211,9 @@ itemCannotBeSold=\u00a74That item cannot be sold to the server.
itemId=\u00a76ID\:\u00a7c {0}
itemMustBeStacked=\u00a74Item must be traded in stacks. A quantity of 2s would be two stacks, etc.
itemNames=\u00a76Item short names\:\u00a7r {0}
itemnameClear=\u00a76You have cleared this item''s name.
itemnameInvalidItem=\u00a7cYou need to hold an item to rename it.
itemnameSuccess=\u00a76You have renamed your held item to "\u00a7c{0}\u00a76".
itemNotEnough1=\u00a74You do not have enough of that item to sell.
itemNotEnough2=\u00a76If you meant to sell all of your items of that type, use\u00a7c /sell itemname\u00a76.
itemNotEnough3=\u00a7c/sell itemname -1\u00a76 will sell all but one item, etc.

View File

@ -210,7 +210,7 @@ commands:
aliases: [dura,edura,durability,edurability,eitemdb,itemno,eitemno]
itemname:
description: Names an item.
usage: /<command> <name>
usage: /<command> [name]
aliases: [iname, einame, eitemname, itemrename, irename, eitemrename, eirename]
jails:
description: List all jails.