2016-06-21 23:39:19 +00:00
|
|
|
package com.earth2me.essentials.commands;
|
|
|
|
|
|
|
|
import com.earth2me.essentials.User;
|
|
|
|
import com.earth2me.essentials.utils.FormatUtil;
|
2020-08-11 18:09:22 +00:00
|
|
|
import org.bukkit.Material;
|
2016-06-21 23:39:19 +00:00
|
|
|
import org.bukkit.Server;
|
|
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
import org.bukkit.inventory.meta.ItemMeta;
|
|
|
|
|
|
|
|
import java.util.Locale;
|
|
|
|
|
2020-04-25 12:08:57 +00:00
|
|
|
import static com.earth2me.essentials.I18n.tl;
|
|
|
|
|
2016-06-21 23:39:19 +00:00
|
|
|
public class Commanditemname extends EssentialsCommand {
|
2020-10-03 17:46:05 +00:00
|
|
|
|
2016-06-21 23:39:19 +00:00
|
|
|
public Commanditemname() {
|
|
|
|
super("itemname");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-10-03 17:46:05 +00:00
|
|
|
protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
|
|
|
|
final ItemStack item = user.getBase().getItemInHand();
|
2020-08-11 18:09:22 +00:00
|
|
|
if (item.getType() == Material.AIR) {
|
2019-05-30 14:09:31 +00:00
|
|
|
user.sendMessage(tl("itemnameInvalidItem", item.getType().toString().toLowerCase(Locale.ENGLISH).replace('_', ' ')));
|
2016-06-21 23:39:19 +00:00
|
|
|
return;
|
|
|
|
}
|
2019-05-30 14:09:31 +00:00
|
|
|
|
|
|
|
String name = FormatUtil.formatString(user, "essentials.itemname", getFinalArg(args, 0)).trim();
|
2020-08-11 18:09:22 +00:00
|
|
|
if (name.isEmpty()) {
|
|
|
|
name = null;
|
|
|
|
}
|
2019-05-30 14:09:31 +00:00
|
|
|
|
2020-10-03 17:46:05 +00:00
|
|
|
final ItemMeta im = item.getItemMeta();
|
2019-05-30 14:09:31 +00:00
|
|
|
im.setDisplayName(name);
|
|
|
|
item.setItemMeta(im);
|
|
|
|
user.sendMessage(name == null ? tl("itemnameClear") : tl("itemnameSuccess", name));
|
2016-06-21 23:39:19 +00:00
|
|
|
}
|
|
|
|
}
|