Help with command arguements

Discussion in 'Plugin Development' started by malachipclover, Jun 2, 2012.

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

    malachipclover

    I am trying to write a plugin that will allow me to play sound effects to players to scare them in the night. Imagine being completly alone, in your house at nighttime, brewing potions in the basement when all of a sudden you hear your door open... but its not actually open. This is my first plugin so I'm not very sure of what I'm doing. I programmed all the help pages first, then compiled and checked if it worked before I did the actual commands. I did /plugman load ParanoiaPlugin, and whenever I try to use the command, it gives errors.

    Code:
    2012-06-02 08:57:56 [WARNING] Unexpected exception while parsing console command
    org.bukkit.command.CommandException: Unhandled exception executing command 'pps' in plugin ParanoiaPlugin v1
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:42)
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:166)
        at org.bukkit.craftbukkit.CraftServer.dispatchCommand(CraftServer.java:479)
        at org.bukkit.craftbukkit.CraftServer.dispatchServerCommand(CraftServer.java:475)
        at net.minecraft.server.MinecraftServer.b(MinecraftServer.java:612)
        at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:581)
        at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:459)
        at net.minecraft.server.ThreadServerApplication.run(SourceFile:492)
    Caused by: java.lang.ArrayIndexOutOfBoundsException: 0
        at malachipclover.paranoia.src.ParanoiaPlugin.onCommand(ParanoiaPlugin.java:42)
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:40)
        ... 7 more
    Then I did a reload of the server, and conditions improved slightly. Now, all I can get it to say is /pps {player} {sound} [repeat], which is what I have under usage in plugin.yml. The only other thing that works is typing in too few or too many arguements.

    Pastebin of both ParanoiaPlugin.java and plugin.yml:
    http://pastebin.com/QQaytMKV
     
  2. I only read the error: "Caused by: java.lang.ArrayIndexOutOfBoundsException: 0" which means you're getting an index from an array that doesn't have that index... 0, and if it doesn't even have the 0 index it means it's totally empty.

    Most likely here:
    Code:
    if(args[0] == "?" || args[0] == "help")
    Just check if args is above 0 first and then check that.

    I don't know what line is there because you altered the code with extra comments and the line from the error doesn't point correctly anymore :)
     
  3. Offline

    malachipclover

    Oh, I am so dumb! Of course I spent 3 days trying to find the issue then half an hour after I finally post it I find the issue myself. I was doing if(args[0] == "<arguement>") when it should have been if(args[0].equalsIgnoreCase("<arguement>")

    Now I just realized I forgot to hit the post button, typed this in a long time ago...
     
  4. Oh, that too... but no, I was mainly telling you that the index 0 doesn't exist :) which is what the error implies.
    So do it like this:
    Code:
    if(args.length > 0 && (args[0].charAt(0) == '?' || args[0].equalsIgnoreCase("help")))
     
  5. Offline

    malachipclover

    But the IndexOutOfBoundException was only happening with reloading between compiles using Plugman. When I do a full reload it doesn't do that.
     
  6. Weird... well, you shouldn't use the "reload" command anyway... and neither Plugman. If you want your plugin to reload its settings you should make a specific command for your plugin that does that.

    Oh and I didn't see the return in the previous condition :confused: so nvm about my above post xD
     
  7. Offline

    malachipclover

    The thing with reload is it causes a lot of problems. It also takes really long on my server because a few plugins will just hang, so it is easier to selectively reload only the plugins I need reloading. About making a command for reloading the settings, that would be useless to me because my plugin has no settings. When I fix bugs or add features or whatever, I tell Eclipse to output the .jar directly to my plugins directory, then I do a /plugman reload ParanoiaPlugin so that it will see the new file. No settings are ever being created, loaded, or reload. Only the actual plugin.
     
Thread Status:
Not open for further replies.

Share This Page