From 111a18585d871deeda2c49d1c8731112bcd0ca8e Mon Sep 17 00:00:00 2001 From: md678685 <1917406+md678685@users.noreply.github.com> Date: Thu, 30 May 2019 15:09:31 +0100 Subject: [PATCH] Allow clearing item names + add locale messages for /itemname --- .../essentials/commands/Commanditemname.java | 18 +++++++++++------- Essentials/src/messages.properties | 3 +++ Essentials/src/plugin.yml | 2 +- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/Essentials/src/com/earth2me/essentials/commands/Commanditemname.java b/Essentials/src/com/earth2me/essentials/commands/Commanditemname.java index 52aa9f46e..d3003b33d 100644 --- a/Essentials/src/com/earth2me/essentials/commands/Commanditemname.java +++ b/Essentials/src/com/earth2me/essentials/commands/Commanditemname.java @@ -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)); - ItemMeta im = item.getItemMeta(); - im.setDisplayName(name); - item.setItemMeta(im); - user.sendMessage(tl("itemnameSuccess", name)); + if (item.getType().name().contains("AIR")) { + user.sendMessage(tl("itemnameInvalidItem", item.getType().toString().toLowerCase(Locale.ENGLISH).replace('_', ' '))); return; } - user.sendMessage(tl("itemnameInvalidItem", item.getType().toString().toLowerCase(Locale.ENGLISH).replace('_', ' '))); + + 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(name == null ? tl("itemnameClear") : tl("itemnameSuccess", name)); } } diff --git a/Essentials/src/messages.properties b/Essentials/src/messages.properties index 82e89dc10..6cf466919 100644 --- a/Essentials/src/messages.properties +++ b/Essentials/src/messages.properties @@ -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. diff --git a/Essentials/src/plugin.yml b/Essentials/src/plugin.yml index bf0529fb5..019f8e70c 100644 --- a/Essentials/src/plugin.yml +++ b/Essentials/src/plugin.yml @@ -210,7 +210,7 @@ commands: aliases: [dura,edura,durability,edurability,eitemdb,itemno,eitemno] itemname: description: Names an item. - usage: / + usage: / [name] aliases: [iname, einame, eitemname, itemrename, irename, eitemrename, eirename] jails: description: List all jails.