Help with Renamer plugin & Materials

Discussion in 'Plugin Development' started by Lewishjames, Dec 15, 2014.

Thread Status:
Not open for further replies.
  1. Offline


    package me.elemental;
    import java.util.Arrays;
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    public class Main extends JavaPlugin {
        public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args){
            Player p = (Player) sender;
            ItemStack item = new ItemStack(p.getInventory().getItemInHand());
            ItemMeta itemMeta = item.getItemMeta();
            StringBuilder str = new StringBuilder();
            for (int i = 1; i < args.length; i++){
                str.append(args[i] + " ");
            String dname = str.toString();
            //String lname = str.toString();
            if (!(item.getType() == Material.AIR)){
                itemMeta.setDisplayName(ChatColor.translateAlternateColorCodes('&', dname));
                //itemMeta.setLore(Arrays.asList(ChatColor.translateAlternateColorCodes('&', lname)));
            if (sender instanceof Player){
                if (commandLabel.equalsIgnoreCase("er")) {
                    if (p.hasPermission("renamer.rename")){
                        if (args.length > 1){
                            if (args[0].equalsIgnoreCase("rename")){
                                if (!(item.getType() == Material.AIR)){
                                      p.sendMessage(ChatColor.AQUA + "You renamed your " + ChatColor.RED +
                                              item.getType() + ChatColor.AQUA + " to " + ChatColor.WHITE +
                                              ChatColor.translateAlternateColorCodes('&', dname));
                                    p.sendMessage("§f[§bEM-Rename§f] §bYou must have an item in your hand to rename");
                            sender.sendMessage("§f[§bEM-Rename§f] §bWrong Arguments: /er rename <name>");
                        sender.sendMessage("§f[§bEM-Rename§f] §bNo Permission... Renamer.rename");
                sender.sendMessage("§f[§bEM-Rename§f] §eyou need to be a player to perform this command");
            return true;

    This is thee code so far. Basically my friend wants it so only tools can be used and not anything so I would need to change the "f (!(item.getType() == Material.AIR)){" to something else which will make it so the plugin will refuse to operate with items other than armor and picks...
  2. Offline


    Havent learnd so much about stringbuilders so this isn't really my thread but at the end you return true;
    last time I checked you should always return false after a command.
  3. Offline


    Yes I have noticed that otherwise it will repeat the usage back eg /rename every time I perform the command..
    Thanks for the help anyhow.
  4. Offline


    Please fix the player casting.. (Read my signature)
    A Easter solution is to keep a list of the Materials that can be used, and then check if the type of the held item is contained within the list/array, if it is do stuff else do whatever =] hope I helped.

    EDIT: I THINK (correct me if I'm wrong) that iteminhand can turn to null as well.
Thread Status:
Not open for further replies.

Share This Page