Solved [Help me] Thank you!

Discussion in 'Plugin Development' started by Cheesepro, Aug 14, 2014.

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

    Cheesepro

    So what I am struggled at is that when I typed a name of a player that is not online(Command: /spamit aslfdaf <level> <msg>) console will out put this:
    Code:
    [09:38:46] [Server thread/INFO]: XxxCheeseproxxX issued server command: /spamit broadt level1 hi
    [09:38:46] [Server thread/ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'spamit' in plugin Spamit v1
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:180) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
        at org.bukkit.craftbukkit.v1_7_R3.CraftServer.dispatchCommand(CraftServer.java:701) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
        at net.minecraft.server.v1_7_R3.PlayerConnection.handleCommand(PlayerConnection.java:956) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
        at net.minecraft.server.v1_7_R3.PlayerConnection.a(PlayerConnection.java:817) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
        at net.minecraft.server.v1_7_R3.PacketPlayInChat.a(PacketPlayInChat.java:28) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
        at net.minecraft.server.v1_7_R3.PacketPlayInChat.handle(PacketPlayInChat.java:47) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
        at net.minecraft.server.v1_7_R3.NetworkManager.a(NetworkManager.java:157) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
        at net.minecraft.server.v1_7_R3.ServerConnection.c(SourceFile:134) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
        at net.minecraft.server.v1_7_R3.MinecraftServer.v(MinecraftServer.java:667) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
        at net.minecraft.server.v1_7_R3.DedicatedServer.v(DedicatedServer.java:260) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
        at net.minecraft.server.v1_7_R3.MinecraftServer.u(MinecraftServer.java:558) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
        at net.minecraft.server.v1_7_R3.MinecraftServer.run(MinecraftServer.java:469) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
        at net.minecraft.server.v1_7_R3.ThreadServerApplication.run(SourceFile:628) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    Caused by: java.lang.NullPointerException
        at me.cheesepro.spamit.Main.onCommand(Main.java:55) ~[?:?]
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
        ... 13 more
    

    and it said the problem is from Class main and line 55,

    Code from Main Class and lines around line "55"
    Code:java
    1. }else if(name!=null && !name.equalsIgnoreCase("broadcast") && targetPlayer.isOnline()){
    2. if (level.equalsIgnoreCase("level1")){
    3. loop = 50;
    4. }else if (level.equalsIgnoreCase("level2")){
    5. loop = 100;
    6. }else if (level.equalsIgnoreCase("level3")){
    7. loop = 200;
    8. }else if (level.equalsIgnoreCase("level4")){
    9. loop = 400;
    10. }else if (level.equalsIgnoreCase("level5")){
    11. loop = 800;
    12. }else if (level.equalsIgnoreCase("super")){
    13. loop = 1600;
    14. }else{
    15. player.sendMessage(ChatColor.RED + "Unknown level input [" + level + "]");
    16. }
    17.  
    18. int i = 0;
    19. while(i<loop){
    20. targetPlayer.sendMessage(ChatColor.DARK_RED + ">Spam< " + ChatColor.WHITE + "(" + ChatColor.YELLOW + player.getName() + ChatColor.WHITE + ")" + ChatColor.AQUA + " >> " + ChatColor.RESET + msg);
    21. i++;
    22. }
    23. }else{
    24. player.sendMessage("error");
    25. }


    Line 55: else if(name!=null && !name.equalsIgnoreCase("broadcast") && targetPlayer.isOnline())

    and if its because the player is not online, then the program should go to the else statement at the bottom


    IF you can please help me! Thank you so much! :D
     
  2. Offline

    xTigerRebornx

    Cheesepro As I have told you before, Bukkit#getPlayer() will return null if the Player is not online, so you would be invoking isOnline() on null, throwing the NullPointerException. Use a != null check rather then an isOnline() check
     
  3. Offline

    Cheesepro

    xTigerRebornx
    Even I change the line to this:
    Code:java
    1. else if(name!=null && !name.equalsIgnoreCase("broadcast") && targetPlayer.getPlayer()!=null)

    it will throw the same error
     
  4. Offline

    daavko

    Cheesepro He meant change it to this:
    Code:java
    1. else if(name!=null && !name.equalsIgnoreCase("broadcast") && targetPlayer!=null)
     
  5. Offline

    Cheesepro

    Ohhhh... Thank you guys SOO MUCH!! :DD
     
Thread Status:
Not open for further replies.

Share This Page