Skip to content

Commit

Permalink
Allow clearing item names + add locale messages for /itemname
Browse files Browse the repository at this point in the history
  • Loading branch information
mdcfe committed May 30, 2019
1 parent 155d3ec commit 111a185
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
Expand Up @@ -7,6 +7,7 @@
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;
Expand All @@ -23,14 +24,17 @@ public Commanditemname() {
@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));
}
}
3 changes: 3 additions & 0 deletions Essentials/src/messages.properties
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion Essentials/src/plugin.yml
Expand Up @@ -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.
Expand Down

0 comments on commit 111a185

Please sign in to comment.