mirror of
https://github.com/TotalFreedomMC/TF-EssentialsX.git
synced 2025-08-05 12:02:53 +00:00
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:
parent
0e3f48ee54
commit
8bafacbd51
2 changed files with 40 additions and 0 deletions
|
@ -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('_', ' ')));
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue