Solved Help with rename plugin

Discussion in 'Plugin Development' started by vhbob, Apr 6, 2015.

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

    vhbob

    Hey guys, i made this rename plugin and when i use my command /rename it says internal error, please help with this heres the code:
    Code:
    package me.vhbob.Rename;
    
    import java.util.logging.Logger;
    
    import org.bukkit.ChatColor;
    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;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class Rename extends JavaPlugin {
    public final Logger logger = Logger.getLogger("Minecraft");
    
        public void onEnable()
        {
            PluginDescriptionFile pdffile = this.getDescription();
            this.logger.info(pdffile.getName() + "Has Been Enabled!");
        }
           
        public void onDisable()
        {
            PluginDescriptionFile pdffile = this.getDescription();
            this.logger.info(pdffile.getName() + "Has Been Diabled");
    
        }
    
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
            if(label.equalsIgnoreCase("rename"));{
            Player p = (Player) sender;
            ItemStack items = p.getItemInHand();
            ItemMeta itemsMeta = items.getItemMeta();
            itemsMeta.setDisplayName(ChatColor.translateAlternateColorCodes('&', args[0]));
           
            
               
         
        }
           
            return true;
        }
    
    
    }
    
     
  2. @vhbob
    1. Don't log, Bukkit already does that for you.
    2. Don't steal Minecraft's logger.
    3. Are you putting your command in your plugin.yml
    4. You aren't setting the item meta.
    5. Don't use commandLabel, use cmd.getName().
    6. Check before casting (see code).
    7. You aren't checking for the length of the arguments (args.lenght == int).
    8. You have a semicolon after your first 'if' statement...
    9. Your code isn't formatted properly. If you have Eclipse it's CTRL + Shift + F.
    10. If you have a stack trace, please post it.
    11. If I solved your problem, please set this to solved by going to Thread Tools (at the top) > Edit Title > Prefix > Solved. (And maybe leave a like? Just kidding! :p)
    Code:
    // CHECK BEFORE CASTING!
    if(sender instanceof Player) {
    Player player = (Player) sender;
    } else {
    sender.sendMessage("You're not a player!");
    }
    The ones in bold are the ones you need to pay the most attention to.

    If you haven't already, LEARN JAVA! You can't write a plugin in a language you don't know.
     
    Last edited: Apr 6, 2015
  3. Offline

    uksspy

    1. Post the error!
    2. if(label.equalsIgnoreCase("rename"));{ Really...
    3. Learn Java before Bukkit.
    4. Seriously, learn Java before Bukkit!
     
  4. Offline

    Orange Tabby

    this isn't the answer for your post but you might want to put items.setItemMeta(itemsMeta);
     
  5. Offline

    vhbob

Thread Status:
Not open for further replies.

Share This Page