Solved {Help} Command Internal Error

Discussion in 'Plugin Development' started by The Fancy Whale, Oct 22, 2013.

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

    The Fancy Whale

    I have been recoding a plugin of mine because I wanted to start from scratch and now the commands aren't working for some reason so here is everything that would be helpful.
    Well so here is the part of my code that has my commands:
    Code:java
    1. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    2. if(cmd.getName().equalsIgnoreCase("mc"))
    3. {
    4. if(sender instanceof Player){
    5. Player player = (Player) sender;
    6. if(args.length > 0){
    7. if (args[1].equalsIgnoreCase("help")){
    8. sender.sendMessage(ChatColor.AQUA + "/mc info" + ChatColor.WHITE + " Get Info about the plugin");
    9. sender.sendMessage(ChatColor.AQUA + "/mc version" + ChatColor.WHITE + " Find out the version of the plugin you are running");
    10. sender.sendMessage(ChatColor.AQUA + "/mc spawn (1-4)" + ChatColor.WHITE + " Set the spawn of the Tooads");
    11. sender.sendMessage(ChatColor.AQUA + "/mc spawn maario" + ChatColor.WHITE + " Set the spawn for Maario");
    12. sender.sendMessage(ChatColor.AQUA + "/mc lobbyspawn" + ChatColor.WHITE + " Set the lobby spawn");
    13. sender.sendMessage(ChatColor.AQUA + "/mc create (arena name)" + ChatColor.WHITE + " Creates an arena");
    14. sender.sendMessage(ChatColor.AQUA + "/mc join (arena name)" + ChatColor.WHITE + " Join an arena");
    15. return true;
    16. }
    17. else if (args[1].equalsIgnoreCase("setspawn") && player.hasPermission("MaarioChase.admin")){
    18. if(args.length > 1){
    19. if (args[2].equalsIgnoreCase("1")){
    20. sender.sendMessage(ChatColor.AQUA + "Spawn 1 Set");
    21. player.setMetadata("s1", (MetadataValue) new FixedMetadataValue(this, LocationUtility.LocationToString(player.getLocation())));}
    22. else if (args[2].equalsIgnoreCase("2")){
    23. sender.sendMessage(ChatColor.AQUA + "Spawn 2 Set");
    24. player.setMetadata("s2", (MetadataValue) new FixedMetadataValue(this, LocationUtility.LocationToString(player.getLocation())));}
    25. else if (args[2].equalsIgnoreCase("3")){
    26. sender.sendMessage(ChatColor.AQUA + "Spawn 3 Set");
    27. player.setMetadata("s3", (MetadataValue) new FixedMetadataValue(this, LocationUtility.LocationToString(player.getLocation())));}
    28. else if (args[2].equalsIgnoreCase("4")){
    29. sender.sendMessage(ChatColor.AQUA + "Spawn 4 Set");
    30. player.setMetadata("s4", (MetadataValue) new FixedMetadataValue(this, LocationUtility.LocationToString(player.getLocation())));}
    31. }
    32.  
    33. }
    34. }
    35.  
    36. }
    37. }
    38. return false;
    39. }


    Here is the error I got from my server:
    Code:
    22.10 21:50:27 [Server] INFO at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44)
    22.10 21:50:27 [Server] INFO at tfw.MaarioChaseV2.Main.onCommand(Main.java:33)
    22.10 21:50:27 [Server] INFO Caused by: java.lang.ArrayIndexOutOfBoundsException: 1
    22.10 21:50:27 [Server] INFO at net.minecraft.server.v1_6_R3.ThreadServerApplication.run(SourceFile:583)
    22.10 21:50:27 [Server] INFO at net.minecraft.server.v1_6_R3.MinecraftServer.run(MinecraftServer.java:421)
    22.10 21:50:27 [Server] INFO at net.minecraft.server.v1_6_R3.MinecraftServer.s(MinecraftServer.java:488)
    22.10 21:50:27 [Server] INFO at net.minecraft.server.v1_6_R3.DedicatedServer.t(DedicatedServer.java:227)
    22.10 21:50:27 [Server] INFO at net.minecraft.server.v1_6_R3.MinecraftServer.t(MinecraftServer.java:592)
    22.10 21:50:27 [Server] INFO at net.minecraft.server.v1_6_R3.DedicatedServerConnection.b(SourceFile:30)
    22.10 21:50:27 [Server] INFO at net.minecraft.server.v1_6_R3.ServerConnection.b(SourceFile:37)
    22.10 21:50:27 [Server] INFO at net.minecraft.server.v1_6_R3.PlayerConnection.e(PlayerConnection.java:116)
    22.10 21:50:27 [Server] INFO at net.minecraft.server.v1_6_R3.NetworkManager.b(NetworkManager.java:296)
    22.10 21:50:27 [Server] INFO at net.minecraft.server.v1_6_R3.Packet3Chat.handle(SourceFile:49)
    22.10 21:50:27 [Server] INFO at net.minecraft.server.v1_6_R3.PlayerConnection.a(PlayerConnection.java:834)
    22.10 21:50:27 [Server] INFO at net.minecraft.server.v1_6_R3.PlayerConnection.chat(PlayerConnection.java:877)
    22.10 21:50:27 [Server] INFO at net.minecraft.server.v1_6_R3.PlayerConnection.handleCommand(PlayerConnection.java:959)
    22.10 21:50:27 [Server] INFO at org.bukkit.craftbukkit.v1_6_R3.CraftServer.dispatchCommand(CraftServer.java:523)
    22.10 21:50:27 [Server] INFO at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:192)
    22.10 21:50:27 [Server] INFO at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46)
    22.10 21:50:27 [Server] INFO org.bukkit.command.CommandException: Unhandled exception executing command 'mc' in plugin MaarioChase v1.1
    22.10 21:50:27 [Server] SEVERE null
    Also here is my plugin.yml
    Code:
    name: MaarioChase
    version: 1.1
    main: tfw.MaarioChaseV2.Main
    commands:
      mc:
          description: DO MC HELP FOR A LONG LIST
     
    permissions:
      MaarioChase.admin:
        description: Access to all commands
        default: op
    
    Thanks in advance
    BTW You do not need to tag me since this is my post thanks!
     
    JPG2000 likes this.
  2. Offline

    JPG2000

    The Fancy Whale Dont use args[1] use args[0] because args dont count thr base command, only the arguments.

    The Fancy Whale So pretty much lower all args by 1. They mean extra arguments not including base commands

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
    The Fancy Whale likes this.
  3. Offline

    adam753

    You forget that the args array (well, arrays in general) are indexed from 0 rather than 1. So when the user types "/mc help", "help" is args[0], not args[1].

    Edit: beaten by JPG2000
     
  4. Offline

    JPG2000

    adam753 Winner ;)

    adam753 You explained it wrong, I belive. Args only count the arguments not the base command. So only of the basecommand is typed its length is 0 and args[0] wold be null.

    Edit: basicly what adam753 said but you ddint explain why

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
  5. Offline

    The Fancy Whale

    adam753 JPG2000 Thanks guys! I had that in my old plugin but on the rewrite I raised them for some reason lol. Thanks anyway!
     
    adam753 likes this.
  6. Offline

    adam753

    JPG2000 That's what I said. mc is the command and help is the first arg (which is 0 and not 1).
     
    JPG2000 likes this.
  7. Offline

    The Fancy Whale

    JPG2000 adam753 What do I do for my args.length statements? I think they stay the same right?
     
  8. Offline

    adam753

    The Fancy Whale Yes, keep them the same. args.length is the actual number of args.
     
Thread Status:
Not open for further replies.

Share This Page