Create /itemname command that names held items.

This contains changes from #672 minus messages, squashed into one commit.

Closes #672.
This commit is contained in:
Ali Moghnieh 2016-06-22 00:39:19 +01:00 committed by md678685
parent 0e3f48ee54
commit 8bafacbd51
2 changed files with 40 additions and 0 deletions

View File

@ -0,0 +1,36 @@
package com.earth2me.essentials.commands;
import static com.earth2me.essentials.I18n.tl;
import com.earth2me.essentials.CommandSource;
import com.earth2me.essentials.I18n;
import com.earth2me.essentials.User;
import com.earth2me.essentials.utils.FormatUtil;
import org.bukkit.Material;
import org.bukkit.Server;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.Locale;
public class Commanditemname extends EssentialsCommand {
public Commanditemname() {
super("itemname");
}
@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));
return;
}
user.sendMessage(tl("itemnameInvalidItem", item.getType().toString().toLowerCase(Locale.ENGLISH).replace('_', ' ')));
}
}

View File

@ -208,6 +208,10 @@ commands:
description: Searches for an item.
usage: /<command> <item>
aliases: [dura,edura,durability,edurability,eitemdb,itemno,eitemno]
itemname:
description: Names an item.
usage: /<command> <name...>
aliases: [iname, einame, eitemname]
jails:
description: List all jails.
usage: /<command>