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