Solved /game command error

Discussion in 'Plugin Development' started by nastasescu, Sep 12, 2014.

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

    nastasescu

    Today i've created a command named /game, and when the syntax is not:
    /game stop
    /game start
    /game gm message
    the console sends me error, there's my code:
    Code:java
    1. if (label.equalsIgnoreCase("game")) {
    2. if (p.hasPermission("kitpvp.game")) {
    3. if (args[0].equalsIgnoreCase("start")) {
    4. if (joc1kitpvp.contains(p) && kp1s == 0) {
    5. kp1timerstart = 11;
    6. for (Player playerz : Bukkit.getOnlinePlayers()) {
    7. if (joc1kitpvp.contains(playerz)) {
    8. playerz.sendMessage(ChatColor.YELLOW + ""
    9. + ChatColor.BOLD
    10. + "The game was force-started by "
    11. + ChatColor.GOLD + ChatColor.BOLD
    12. + p.getName() + ChatColor.BOLD
    13. + ChatColor.YELLOW + "!");
    14. }
    15. }
    16. }
    17. } else if (args[0].equalsIgnoreCase("stop")) {
    18. if (joc1kitpvp.contains(p) && kp1s == 1) {
    19. kp1timersend = 11;
    20. for (Player playerz : Bukkit.getOnlinePlayers()) {
    21. if (joc1kitpvp.contains(playerz)) {
    22. playerz.sendMessage(ChatColor.YELLOW + ""
    23. + ChatColor.BOLD
    24. + "The game was force-stopped by "
    25. + ChatColor.GOLD + ChatColor.BOLD
    26. + p.getName() + ChatColor.BOLD
    27. + ChatColor.YELLOW + "!");
    28. }
    29. }
    30. }
    31. } else if (args[0].equalsIgnoreCase("gm")) {
    32. if (args[1].equalsIgnoreCase(null)) {
    33. p.sendMessage("Syntax: /game gm <message>");
    34. } else {
    35. Bukkit.broadcastMessage(ChatColor.WHITE + ""
    36. + ChatColor.BOLD + p.getName() + ChatColor.AQUA
    37. + " " + ChatColor.BOLD + buildMessage(args, 1));
    38. }
    39. } else {
    40. p.sendMessage(ChatColor.AQUA + "" + ChatColor.BOLD
    41. + "Syntax: /game <command>");
    42. p.sendMessage(ChatColor.GREEN + "Commands: start, end, gm");
    43. }
    44. } else {
    45. p.sendMessage(ChatColor.RED
    46. + "You haven't enough permissions to run that command!");
    47. }
    48. }
     
  2. Offline

    4thegame3

    please post the console error

    anyways should be String cmd = command.getName();
    then if cmd.equals...("game")

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

    nastasescu

    Code:
    [19:31:30 INFO]: nastasescu issued server command: /game gm
    [19:31:30 ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'game
    ' in plugin Lobby v1.0
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[cra
    ftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:18
    0) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
            at org.bukkit.craftbukkit.v1_7_R4.CraftServer.dispatchCommand(CraftServe
    r.java:740) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
            at net.minecraft.server.v1_7_R4.PlayerConnection.handleCommand(PlayerCon
    nection.java:957) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
            at net.minecraft.server.v1_7_R4.PlayerConnection.a(PlayerConnection.java
    :818) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
            at net.minecraft.server.v1_7_R4.PacketPlayInChat.a(PacketPlayInChat.java
    :28) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
            at net.minecraft.server.v1_7_R4.PacketPlayInChat.handle(PacketPlayInChat
    .java:47) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
            at net.minecraft.server.v1_7_R4.NetworkManager.a(NetworkManager.java:157
    ) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
            at net.minecraft.server.v1_7_R4.ServerConnection.c(SourceFile:134) [craf
    tbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
            at net.minecraft.server.v1_7_R4.MinecraftServer.v(MinecraftServer.java:6
    67) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
            at net.minecraft.server.v1_7_R4.DedicatedServer.v(DedicatedServer.java:2
    58) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
            at net.minecraft.server.v1_7_R4.MinecraftServer.u(MinecraftServer.java:5
    58) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
            at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java
    :469) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
            at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:6
    28) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
    Caused by: java.lang.ArrayIndexOutOfBoundsException: 1
            at me.nastasescu.lobby.Main.onCommand(Main.java:931) ~[?:?]
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[cra
    ftbukkit.jar:git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks]
            ... 13 more
    4thegame3
     
  4. Offline

    mrCookieSlime

    nastasescu
    Always check for the size of the args array before accessing a value from it.
    Just insert if (args.length >= 2)

    indyetoile
    Ehhhm, it does not... Read the error. Its an ArrayOutOfBoundsException. He tries to access a value from an array which doesnt contain that much values.

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

    indyetoile

  6. Offline

    nastasescu

  7. Offline

    mrCookieSlime

    indyetoile
    returning null does NOT mean its a NullPointerException!
    A NullPointerException is when the System tries to use something that doesnt exist. If something returns null it just means that the Value null was returned.

    nastasescu No problem.
     
  8. Offline

    indyetoile

    mrCookieSlime
    I corrected myself in my next post, don't need to tell me.
     
  9. Offline

    mrCookieSlime

    indyetoile
    I felt like I had to tell you.
    It kinda sounded like you have no idea what a NPE or null means...
     
  10. Offline

    indyetoile

    mrCookieSlime
    Because isn't misreading something human? You're quite obdurate. I definitely know the difference, and I don't need you to tell me.
    I'm sorry if I sound rude and if I'm decrying you, but you don't have to tell me the difference between a NPE and null when I had already corrected myself in my next post.
     
  11. Offline

    mrCookieSlime

    indyetoile
    I didnt say you dont know the difference.
    I didnt say misreading isnt normal either.
    I probably misread things as often as you do, but as I said... it "sounded" like you dont know the difference.

    The "still it returns null" part sounds like you treat a null as a NPE.
    And if you know the difference, wheres the problem then? I am just trying to help and if you already know it, then its fine. If your teacher teaches you something you already know, you dont get mad at him either. You smile and think "Ahhhh, already knew that :) ".

    And as you can see I can make mistakes too...
    There is no need to argue with me now, just because I said something you already know...
     
Thread Status:
Not open for further replies.

Share This Page