Implement /itemname command (#2573)

Implement /itemname command, across three PRs. Originally implemented by SupaHam, and updated by zsturgess and myself.
This commit is contained in:
md678685 2019-05-30 19:16:43 +01:00 committed by GitHub
commit a08832cfc8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 47 additions and 0 deletions

View File

@ -0,0 +1,40 @@
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 com.earth2me.essentials.utils.MaterialUtil;
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().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(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

@ -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, itemrename, irename, eitemrename, eirename]
jails:
description: List all jails.
usage: /<command>