An internal error occurred while attempting this command Help!

Discussion in 'Plugin Development' started by TheArabianCoder, Jan 23, 2015.

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

    TheArabianCoder

    I have developed this one plugin a week ago, cause I was bored... I've run into the error "An internal error occurred while attempting this command" when I do /hearts, but I when I do /hearts <player>, everything is fine. Here's my code;
    Code:
    package me.thearabiangamer.test;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    
    public class Hearts implements CommandExecutor {
    
        public void onEnable() {
                Bukkit.getServer().getLogger().info(null);
        }
      
        public void onDisable() {
                Bukkit.getServer().getLogger().info(null);
        }
      
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
              
                if (!(sender instanceof Player)) {
                        sender.sendMessage(ChatColor.RED + "The Console is Invinsible!");
                }
              
                Player p = (Player) sender;
                if (cmd.getName().equalsIgnoreCase("hearts")){
                    if (args.length == 0){
                p.sendMessage(ChatColor.GREEN + "You Have " + p.getHealth() / 2 + " Hearts!");
    
                    }
               
        Player target = Bukkit.getServer().getPlayer(args[0]);
        if (target == null) {
            p.sendMessage(ChatColor.RED + "Could not find player!");
            return true;
        }
            
            p.sendMessage(ChatColor.GREEN + target.getName() + " Has " + target.getHealth() / 2 + " Hearts!");
    }
                return true;
        }
    }
    So does anyone see a error?
     
  2. Offline

    Larry Newman

  3. Offline

    Ambamore2000

    Don't get it. Why does it not extend JavaPlugin?
     
  4. Offline

    mrCookieSlime

    Moved to Plugin Developement.

    @Larry Newman
    Also next time, report it.
     
  5. Offline

    teej107

    CommandExecutors don't need to extend JavaPlugin

    @TheArabianCoder It really helps to post the stacktrace but I bet the error is a ArrayIndexOutOfBoundsException. You aren't doing anything to stop if the array length is 0 before you attempt to get the 0 index of the array.
     
  6. Offline

    Seadragon91

    Add a
    Code:
    return true;
    at line 30.
     
  7. Offline

    TheArabianCoder

    Using Multiple Classes

    Sorry, new to the bukkit forums. Ill be sure to move to Plugin Development next time I have an error.

    Thanks! It worked!
     
    Last edited by a moderator: Jan 24, 2015
Thread Status:
Not open for further replies.

Share This Page