Punish v1.0 (by me) not working (internal error) (I pasted the source now)

Discussion in 'Plugin Development' started by mighty2361, Jul 24, 2012.

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

    mighty2361

    Now I fixed, and I got another internal error when using command /punish without arguments. It should say something about missing arguments, but it says something about internal error. Stuff from console:

    org.bukkit.command.CommandException: Unhandled exception executing command 'puni
    sh' in plugin Punish v1
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:42)
    at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:16
    6)
    at org.bukkit.craftbukkit.CraftServer.dispatchCommand(CraftServer.java:4
    79)
    at net.minecraft.server.NetServerHandler.handleCommand(NetServerHandler.
    java:821)
    at net.minecraft.server.NetServerHandler.chat(NetServerHandler.java:781)

    at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:764)
    at net.minecraft.server.Packet3Chat.handle(Packet3Chat.java:34)
    at net.minecraft.server.NetworkManager.b(NetworkManager.java:229)
    at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:113)
    at net.minecraft.server.NetworkListenThread.a(NetworkListenThread.java:7
    8)
    at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:567)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:459)
    at net.minecraft.server.ThreadServerApplication.run(SourceFile:492)
    Caused by: java.lang.ArrayIndexOutOfBoundsException: 0
    at tk.mighty2361.Myplugin.onCommand(Myplugin.java:31)
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:40)
    ... 12 more






    HERE IS THE SOURCE: http://pastie.org/4318826
     
  2. Offline

    nisovin

    You're doing something like args[0] without first checking if there are any args in the first place. You should do something like if (args.length == 0) then send your error message.
     
  3. Offline

    mighty2361

    ok thank you

    org.bukkit.command.CommandException: Unhandled exception executing command 'puni
    sh' in plugin Punish v1
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:42)
    at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:16
    6)
    at org.bukkit.craftbukkit.CraftServer.dispatchCommand(CraftServer.java:4
    79)
    at net.minecraft.server.NetServerHandler.handleCommand(NetServerHandler.
    java:821)
    at net.minecraft.server.NetServerHandler.chat(NetServerHandler.java:781)

    at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:764)
    at net.minecraft.server.Packet3Chat.handle(Packet3Chat.java:34)
    at net.minecraft.server.NetworkManager.b(NetworkManager.java:229)
    at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:113)
    at net.minecraft.server.NetworkListenThread.a(NetworkListenThread.java:7
    8)

    at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:567)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:459)
    at net.minecraft.server.ThreadServerApplication.run(SourceFile:492)
    Caused by: java.lang.ArrayIndexOutOfBoundsException: 0
    at tk.mighty2361.Myplugin.onCommand(Myplugin.java:31)
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:40)
    ... 12 more


    I fixed but now I got this stuff and when I do just /punish I get a internal error

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

    ZeusAllMighty11

    Post some code? I can fix it for you
     
  5. Offline

    evilmidget38

    No one can help you debug your program without seeing source code. If you've truly fixed it like what nisovin said, then we need to see your source code. http://pastie.org/ is a good place to put your source so we can see it.
     
  6. Offline

    sayaad

    Caused by: java.lang.ArrayIndexOutOfBoundsException: 0

    at tk.mighty2361.Myplugin.onCommand(Myplugin.java:31)

    Here is a link that can be of use for you.

    ArrayIndexOutOfBoundsException means that you called a value from the array when the array does not contain that value

    example :

    Code:java
    1. String[] array;
    2. array[0] = "a";
    3. array[1] = "b";
    4. array[2] = "c";
    5. //array.length == 3 therefore this will return a ArrayIndexOutOfBoundsException
    6. if(array[3]/*<-- value does not exist*/.equals("")){
    7. }
    8. //however you can do this
    9. if(array[2]/*value exists*/.equals("c")){
    10. }
     
  7. Offline

    mighty2361

    Sorry but I just started with plugin and I don't understand most of that stuff you sent. Can you fix it for me?
     
  8. Offline

    sayaad

    Sure, send me ur code for the "Myplugin" class in a pm. Ill explain how to fix it.

    *Hint* *Hint*
     
  9. Offline

    mighty2361

  10. Offline

    ZeusAllMighty11

    If you don't understand the code he just COPYPASTA'd, perhaps you should look at the API a little more closely, or learn some java? xD
     
  11. Offline

    sayaad

    mighty2361

    Your error is this

    Code:java
    1. Player other = (Bukkit.getServer().getPlayer(args[0]));


    Commands are divided into a string array. ( the message after the command is split by " " ) , in this case, you named the array "args".

    So if I enter "/punish Jeb"

    the command = "punish"
    and args[0] = "Jeb"

    but if i enter "/punish"

    args[0] does not exists and you get that error.

    To fix this, we check if the user enters the command correctly "/punish <Player>" and not "/punish". This is done in a simple if statement to check the lenght of the array

    Code:java
    1. if(cmd.getName().equalsIgnoreCase("punish")){
    2.  
    3. if (!args.length == 0) {
    4.  
    5. Player other = (Bukkit.getServer().getPlayer(args[0]));
    6.  
    7. if(other.isOnline()){
    8.  
    9. other.getWorld().createExplosion(other.getLocation(), 0);
    10. sender.sendMessage(ChatColor.GREEN + other.getName() + ChatColor.RED + "Went BOOM");
    11. return true;
    12.  
    13. }else{
    14.  
    15. ender.sendMessage(ChatColor.RED + args[0] + " is not online!");
    16. return true;
    17. }
    18.  
    19. }else{
    20.  
    21. sender.sendMessage(ChatColor.RED + "Wrong usage! You have to do /punish [Player]");
    22. return true;
    23.  
    24. }
    25. }
    26. return false;
     
  12. Offline

    mighty2361

    I fixed but now I get error when trying to punish player which doesnt exist.





    org.bukkit.command.CommandException: Unhandled exception executing command 'puni
    sh' in plugin Punish v1
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:42)
    at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:16
    6)
    at org.bukkit.craftbukkit.CraftServer.dispatchCommand(CraftServer.java:4
    79)
    at net.minecraft.server.NetServerHandler.handleCommand(NetServerHandler.
    java:821)
    at net.minecraft.server.NetServerHandler.chat(NetServerHandler.java:781)

    at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:764)
    at net.minecraft.server.Packet3Chat.handle(Packet3Chat.java:34)
    at net.minecraft.server.NetworkManager.b(NetworkManager.java:229)
    at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:113)
    at net.minecraft.server.NetworkListenThread.a(NetworkListenThread.java:7
    8)
    at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:567)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:459)
    at net.minecraft.server.ThreadServerApplication.run(SourceFile:492)
    Caused by: java.lang.NullPointerException
    at tk.mighty2361.Myplugin.onCommand(Myplugin.java:37)
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:40)
    ... 12 more
     
  13. Offline

    sayaad

    Caused by: java.lang.NullPointerException

    From looking at your code, you already know how to fix this >.>

    My goal is not to fix your error... its to try to make you understand java better.
     
  14. Offline

    mighty2361



    Yes I know I can fix that. I even tried but I get this:


    org.bukkit.command.CommandException: Unhandled exception executing command 'puni
    sh' in plugin Punish v1
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:42)
    at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:16
    6)
    at org.bukkit.craftbukkit.CraftServer.dispatchCommand(CraftServer.java:4
    79)
    at net.minecraft.server.NetServerHandler.handleCommand(NetServerHandler.
    java:821)
    at net.minecraft.server.NetServerHandler.chat(NetServerHandler.java:781)

    at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:764)
    at net.minecraft.server.Packet3Chat.handle(Packet3Chat.java:34)
    at net.minecraft.server.NetworkManager.b(NetworkManager.java:229)
    at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:113)
    at net.minecraft.server.NetworkListenThread.a(NetworkListenThread.java:7
    8)
    at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:567)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:459)
    at net.minecraft.server.ThreadServerApplication.run(SourceFile:492)
    Caused by: java.lang.NullPointerException
    at tk.mighty2361.Myplugin.onCommand(Myplugin.java:37)
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:40)
     
  15. Offline

    Lolmewn

    Hey I think I heard that before :p This time, probably true xD
     
  16. Offline

    sayaad

    Then do it. Simplest problem you will ever encounter in java.
     
  17. Offline

    mighty2361

    How? What could be wrong with this?:

    if (other == null)
    sender.sendMessage(ChatColor.RED + args[0] + " is not online!");
    return false;
     
  18. Offline

    sayaad

    Well what I think you don't know is this :

    A computer's CPU's ( mah grammar is so proper ) CU executes tasks in a particular order, that order is from line 1 of your code to the last line.

    if you put other == null AFTER the line the with the error ( Please read this ), then it processes the error causing code first before the fix, causing the error.
     
  19. Offline

    mighty2361

    I dont understand and I got to go. See you tomorrow
     
  20. Offline

    sayaad

    010110010110111101110101001000000111001101101000011011110111010101101100011001000010000001101100011001010110000101110010011011100010000001101010011000010111011001100001001000000110000100100000011000100110100101110100001000000110001001100101011101000111010001100101011100100010000001100010011001010110011001101111011100100110010100100000011000010111010001110100011001010110110101110000011101000110100101101110011001110010000001110100011011110010000001100011011011110110010001100101001000000111000001101100011101010110011101101001011011100111001100101100001000000110111001101111001000000110111101100110011001100110010101101110011000110110010100101110
     
  21. Offline

    mighty2361

    Im still here! why is that shit good? I know what it is but i dont know why u posted it

    Some binary $#!T

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

    sayaad

    I'm sure almost every developer will agree to what I said.
     
  23. Offline

    mighty2361

    I could agree if I would inderstand that binary stuff

    I will learn it. I don't have time right now. tommorow. Can you please tell me what's wrong with my code?
    I beg you

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 27, 2016
Thread Status:
Not open for further replies.

Share This Page