My plugin commands return an error! help! [FIXED! Takedown please!]

Discussion in 'Spigot Plugin Help' started by JOEYSARMY, Jun 2, 2015.

  1. I have been learning lately about plugins and making them! Unfortunately I've run into a bit of a problem, but luckily I save my previous versions so I can post the versions and the changes I made to the code. The error I get is an Internal error (Thats what it said) and I can't figure it out.

    Code (Text):
    package me.joeysarmy;

    import org.bukkit.Bukkit;
    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.PlayerInventory;
    import org.bukkit.plugin.java.JavaPlugin;

    public class EventHandle extends JavaPlugin {
       
        @Override
        public void onEnable()
        {
            new PlayerListener(this);
        }
       
        @Override
        public void onDisable()
        {
       
        }
       
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args)
        {
            @SuppressWarnings("deprecation")
            Player target = Bukkit.getServer().getPlayer(args[0]);
            Player player = (Player) sender;
           
            if (!(sender instanceof Player))
            {
                sender.sendMessage(ChatColor.RED + "The console cannot use this command!");
                return true;
            }
           
           
           
           
            if (cmd.getName().equalsIgnoreCase("heal"))
            {
                if (!sender.hasPermission("cmd.heal"))
                {
                    player.sendMessage(ChatColor.RED + "You do not have the required permissions!");
                    return true;
                }
                if (args.length == 0)
                {
                    player.setHealth(20);
                    player.sendMessage(ChatColor.GREEN + "You have been healed!");
                    return true;
                }
               
               
                if (target == null)
                {
                    player.sendMessage(ChatColor.RED + ("Could not find player!"));
                    return true;
                }
                target.setHealth(20);
                target.sendMessage(ChatColor.BLUE + "You have been healed by " + player.getPlayer() + "!");
                player.sendMessage(ChatColor.BLUE + "You have healed " + target.getName() + "!");
            }
           
           
                if (!(sender instanceof Player))
                {
                    sender.sendMessage(ChatColor.RED + "The console cannot use this command!");
                    return true;
                }
               
               
                if (cmd.getName().equalsIgnoreCase("feed"))
                {
                    if (!sender.hasPermission("cmd.feed"))
                    {
                        player.sendMessage(ChatColor.RED + "You do not have the required permissions!");
                        return true;
                    }
                   
                   
                    if (args.length == 0)
                    {
                        player.setFoodLevel(20);
                        player.sendMessage(ChatColor.GREEN + "You have been fed!");
                        return true;
                    }
                   
                   
                    if (target == null)
                    {
                        player.sendMessage(ChatColor.RED + ("Could not find player!"));
                        return true;
                    }
                   
                   
                    target.setFoodLevel(20);
                    target.sendMessage(ChatColor.BLUE + "You have been fed by " + player.getPlayer() + "!");
                    player.sendMessage(ChatColor.BLUE + "You have fed " + target.getName() + "!");
                }
               
                if (cmd.getName().equalsIgnoreCase("sk"))
                {
                    PlayerInventory pinv = player.getInventory();
                    if (!sender.hasPermission("cmd.sk"))
                    {
                        player.sendMessage(ChatColor.RED + "You do not have the required permissions!");
                        return true;
                    }
                    pinv.addItem(new ItemStack(Material.STONE_PICKAXE, 1));
                    pinv.addItem(new ItemStack(Material.STONE_SPADE, 1));
                    pinv.addItem(new ItemStack(Material.STONE_SWORD, 1));
                    pinv.addItem(new ItemStack(Material.BREAD, 5));
                    player.sendMessage(ChatColor.AQUA + "You have been given the Starter Kit!");
                }
               
                if (cmd.getName().equalsIgnoreCase("cinv"))
                {
                    PlayerInventory pinv = player.getInventory();
                    if (!sender.hasPermission("cmd.cinv"))
                    {
                        player.sendMessage(ChatColor.RED + "You do not have the required permissions!");
                        return true;
                    }
                    pinv.clear();
                    player.sendMessage(ChatColor.BLUE + "Inventory Cleared!");
                }
               
                return true;
               
        }
    }
     
    Here is the plugin.yml
    Code (Text):

    name: GameMechanics
    main: me.joeysarmy.EventHandle
    version: 1.0
    commands:
       heal:
          description: Heals you or the specified player.
          usage: /heal <Blank or player name>
       feed:
          description: Feeds you or a player.
          usage: /feed <Blank or player name>
       sk:
          description: Gives you a starter kit.
          usage: /sk
       cinv:
          description: Clears your inventory.
          usage: /cinv


    permissions:
       cmd.heal:
          description: Use the heal command.
          default: op
       cmd.feed:
          description: Use the feed command.
          default: op
       cmd.sk:
          description: Use the sk command.
          default: op
       cmd.cinv:
          description: Use the cinv command.
          default: op
    I will start up the server and paste the log after I do a command.
    Here is the log.
    Code (Text):

    [20:41:42] [Server thread/INFO]: Starting minecraft server version 1.8.6
    [20:41:42] [Server thread/INFO]: Loading properties
    [20:41:42] [Server thread/INFO]: Default game type: SURVIVAL
    [20:41:42] [Server thread/INFO]: Generating keypair
    [20:41:42] [Server thread/INFO]: Starting Minecraft server on *:25565
    [20:41:42] [Server thread/INFO]: Using default channel type
    [20:41:43] [Server thread/INFO]: This server is running CraftBukkit version git-Bukkit-e8c6403 (MC: 1.8.6) (Implementing API version 1.8.6-R0.1-SNAPSHOT)
    [20:41:43] [Server thread/INFO]: [WorldEdit] Loading WorldEdit v6.0;3342-78f975b9
    [20:41:43] [Server thread/INFO]: [GameMechanics] Loading GameMechanics v1.0
    [20:41:43] [Server thread/INFO]: Preparing level "world"
    [20:41:43] [Server thread/INFO]: Preparing start region for level 0 (Seed: 3804617226223605313)
    [20:41:44] [Server thread/INFO]: Preparing start region for level 1 (Seed: 3338017905050404025)
    [20:41:45] [Server thread/INFO]: Preparing spawn area: 70%
    [20:41:45] [Server thread/INFO]: Preparing start region for level 2 (Seed: 3338017905050404025)
    [20:41:46] [Server thread/INFO]: [WorldEdit] Enabling WorldEdit v6.0;3342-78f975b9
    [20:41:46] [Server thread/INFO]: WEPIF: Using the Bukkit Permissions API.
    [20:41:46] [Server thread/WARN]: [WorldEdit]
    **********************************************
    ** This WorldEdit version does not fully support your version of Bukkit.
    **
    ** When working with blocks or undoing, chests will be empty, signs
    ** will be blank, and so on. There will be no support for entity
    ** and biome-related functions.
    **
    ** Please see http://wiki.sk89q.com/wiki/WorldEdit/Bukkit_adapters
    **********************************************

    [20:41:46] [Server thread/INFO]: [GameMechanics] Enabling GameMechanics v1.0
    [20:41:46] [Server thread/INFO]: Server permissions file permissions.yml is empty, ignoring it
    [20:41:46] [Server thread/INFO]: Done (3.100s)! For help, type "help" or "?"
    [20:42:09] [User Authenticator #1/INFO]: UUID of player JOEYSARMY is 9ae306c2-ee17-4deb-a1b8-7fada897988e
    [20:42:09] [Server thread/INFO]: JOEYSARMY[/10.0.0.21:46960] logged in with entity id 145 at ([world]-892.7638323680851, 56.0, 659.8975110230195)
    [20:42:17] [Server thread/INFO]: JOEYSARMY issued server command: /heal
    [20:42:17] [Server thread/ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'heal' in plugin GameMechanics v1.0
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[mcserver.jar:git-Bukkit-e8c6403]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:140) ~[mcserver.jar:git-Bukkit-e8c6403]
        at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchCommand(CraftServer.java:621) ~[mcserver.jar:git-Bukkit-e8c6403]
        at net.minecraft.server.v1_8_R3.PlayerConnection.handleCommand(PlayerConnection.java:1079) [mcserver.jar:git-Bukkit-e8c6403]
        at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java:939) [mcserver.jar:git-Bukkit-e8c6403]
        at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(SourceFile:37) [mcserver.jar:git-Bukkit-e8c6403]
        at net.minecraft.server.v1_8_R3.PacketPlayInChat.a(SourceFile:9) [mcserver.jar:git-Bukkit-e8c6403]
        at net.minecraft.server.v1_8_R3.PlayerConnectionUtils$1.run(SourceFile:13) [mcserver.jar:git-Bukkit-e8c6403]
        at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_45]
        at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_45]
        at net.minecraft.server.v1_8_R3.SystemUtils.a(SystemUtils.java:19) [mcserver.jar:git-Bukkit-e8c6403]
        at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:676) [mcserver.jar:git-Bukkit-e8c6403]
        at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:335) [mcserver.jar:git-Bukkit-e8c6403]
        at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:632) [mcserver.jar:git-Bukkit-e8c6403]
        at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:540) [mcserver.jar:git-Bukkit-e8c6403]
        at java.lang.Thread.run(Unknown Source) [?:1.8.0_45]
    Caused by: java.lang.ArrayIndexOutOfBoundsException: 0
        at me.joeysarmy.EventHandle.onCommand(EventHandle.java:30) ~[?:?]
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[mcserver.jar:git-Bukkit-e8c6403]
        ... 15 more
    [20:42:21] [Server thread/INFO]: JOEYSARMY issued server command: /stop
    [20:42:21] [Server thread/INFO]: [JOEYSARMY: Stopping the server]
    [20:42:21] [Server thread/INFO]: Stopping server
    [20:42:21] [Server thread/INFO]: [GameMechanics] Disabling GameMechanics v1.0
    [20:42:21] [Server thread/INFO]: [WorldEdit] Disabling WorldEdit v6.0;3342-78f975b9
    [20:42:21] [Server thread/INFO]: Saving players
    [20:42:21] [Server thread/INFO]: JOEYSARMY lost connection: Server closed
    [20:42:21] [Server thread/INFO]: JOEYSARMY left the game.
    [20:42:21] [Server thread/INFO]: Saving worlds
    [20:42:21] [Server thread/INFO]: Saving chunks for level 'world'/Overworld
    [20:42:21] [Server thread/INFO]: Saving chunks for level 'world_nether'/Nether
    [20:42:21] [Server thread/INFO]: Saving chunks for level 'world_the_end'/The End
    And thats about it I guess...

    Thank you for your time!