A little I can't squash

Discussion in 'Plugin Development' started by TheChinski, Mar 19, 2013.

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

    TheChinski

    As the title says, but what really gets me is this plugin was working fine up until this evening. I've updated a few plugins, and Bukkit to a newer Dev build, and now no matter what I do I get a nullpointerexception error on line 47. I have downgraded, tried on clean server, everything!

    Error
    Code:
    2013-03-19 20:03:22 [SEVERE] Could not pass event PlayerMoveEvent to WorldExplorer v0.1 Alpha
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:427)
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62)
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:477)
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:462)
        at net.minecraft.server.v1_5_R1.PlayerConnection.a(PlayerConnection.java:220)
        at com.bergerkiller.bukkit.common.internal.CommonPacketListener.a(CommonPacketListener.java:166)
        at net.minecraft.server.v1_5_R1.Packet10Flying.handle(SourceFile:136)
        at net.minecraft.server.v1_5_R1.NetworkManager.b(NetworkManager.java:292)
        at net.minecraft.server.v1_5_R1.PlayerConnection.d(PlayerConnection.java:113)
        at net.minecraft.server.v1_5_R1.ServerConnection.b(SourceFile:35)
        at net.minecraft.server.v1_5_R1.DedicatedServerConnection.b(SourceFile:30)
        at net.minecraft.server.v1_5_R1.MinecraftServer.r(MinecraftServer.java:580)
        at net.minecraft.server.v1_5_R1.DedicatedServer.r(DedicatedServer.java:225)
        at net.minecraft.server.v1_5_R1.MinecraftServer.q(MinecraftServer.java:476)
        at net.minecraft.server.v1_5_R1.MinecraftServer.run(MinecraftServer.java:409)
        at net.minecraft.server.v1_5_R1.ThreadServerApplication.run(SourceFile:573)
    Caused by: java.lang.NullPointerException
        at com.SludgeCraft.WorldExplorer.PlayerMove.randomLoc(PlayerMove.java:47)
        at com.SludgeCraft.WorldExplorer.PlayerMove.onPlayerMove(PlayerMove.java:30)
        at sun.reflect.GeneratedMethodAccessor17.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:425)
        ... 15 more
    My Code

    Code:
    package com.SludgeCraft.WorldExplorer;
     
    import java.util.Random;
    import java.util.logging.Logger;
     
    import net.minecraft.server.v1_5_R1.Material;
     
    import org.bukkit.Bukkit;
    import org.bukkit.Location;
    import org.bukkit.block.Biome;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.EventPriority;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerMoveEvent;
     
    public class PlayerMove implements Listener{
    static String colorize(String string) { return string.replaceAll("(?i)&([a-l0-9])", "\u00A7$1"); }
    public static Main plugin;
    public final Logger logger = Logger.getLogger("Minecraft");
    public PlayerMove(Main plugin) {
    this.plugin = plugin;
    }
     
    //Nice new empty location
    static Location randomLoc = new Location(null, 0, 0, 0);
     
    @EventHandler(priority=EventPriority.MONITOR)
    public void onPlayerMove(PlayerMoveEvent event) {
    //Reducing the load just that bit
    if(event.getFrom() != event.getTo()) {
    //Checking if the player is in the portal
    if(event.getTo().getBlockX() == 1018 && 130 <= event.getTo().getBlockY() && 166 >= event.getTo().getBlockY() && -2898 >= event.getTo().getBlockZ() && -2929 <= event.getTo().getBlockZ()) {
    //Generate a new random location
    randomLoc();
    //Making sure the new location is OK
    while(!randomLoc.getBlock().getType().equals(Material.AIR) || randomLoc.getBlock().getBiome().equals(Biome.OCEAN) || randomLoc.getBlock().getBiome().equals(Biome.BEACH) || randomLoc.getBlock().getBiome().equals(Biome.FROZEN_OCEAN) || randomLoc.getBlock().getBiome().equals(Biome.FROZEN_RIVER) || randomLoc.getBlock().getBiome().equals(Biome.RIVER)) {
    randomLoc();
    }
    //Whisk them off
    event.getPlayer().teleport(randomLoc);
    event.getPlayer().sendMessage(colorize("&eYou have been teleported to &4" + Main.SelectedWorld + "&e!"));
    }
    }
    }
     
    //Come up with random location to tp player
    public void randomLoc() {
    int ranX = new Random().nextInt(100000);
    int ranZ = new Random().nextInt(100000);
    randomLoc.setX(ranX);
    randomLoc.setY(256);
    randomLoc.setZ(ranZ);
    randomLoc.setWorld(Bukkit.getWorld(Main.SelectedWorld));
    //THIS LINE
    int highY = Bukkit.getWorld(Main.SelectedWorld).getHighestBlockYAt(randomLoc);
    randomLoc.setY(highY);
    }
     
    }
    This is only my third or fourth plugin, and I am learning Java as a first programming language, so noob mistake expected! :p

    Thanks in advance!
     
  2. Offline

    skipperguy12

    http://forums.bukkit.org/threads/ho...ubleshoot-your-own-plugins-by-yourself.32457/

    Don't send entire code unless absolutely necessary.

    In your case, it's not necessary, look:
    Code:
    Caused by: java.lang.NullPointerException
        at com.SludgeCraft.WorldExplorer.PlayerMove.randomLoc(PlayerMove.java:47)
        at com.SludgeCraft.WorldExplorer.PlayerMove.onPlayerMove(PlayerMove.java:30)
    What does this mean? In class PlayerMove, @ line 47, you are trying to do something null.
    Also at 30.

    EDIT: There's no way to help unless you only send us the NPE part of the code or use syntax java tags.
     
  3. Offline

    TheChinski

    5 lines up from the bottom is line 47. randomLoc is a Location which is first made just before the onPlayerMove. Although it is null at first, before it gets to line 47, the four lines above it are meant to fill in randomLoc with all the details it needs. I can't see how line 47 can be null if it isn't... :eek:
     
  4. Offline

    Lolmewn

    TheChinski Try adding some debug lines. Those can be live-savers in times of, eh, debugging.
     
  5. So you say that:
    Code:
    int highY = Bukkit.getWorld(Main.SelectedWorld).getHighestBlockYAt(randomLoc);
    is the line from the stacktrace ?
    That would make sense since Bukkit.getWorld() can return null if the world does not exist/not loaded.

    Your "Main.SelectedWorld" might not be a valid loaded world, getWorld() doesn't load worlds, it finds a loaded world.
     
  6. Offline

    skipperguy12

    To add onto what Lolmewn had said, here's how:
    Bukkit.getLogger().info("DEBUG TEST 1 RAN!");

    Try adding these after if statements, and parts of code that don't work.
     
  7. skipperguy12
    You'd usually want debug messages before conditions and printing the actual values used in the conditions, otherwise you're still guessing.
     
  8. Offline

    skipperguy12

    Digi
    Kind of what I meant lol.

    Basically, place a crap ton of them everywhere, make them print numbers, and see what number it gets up to before it dies.
     
  9. Offline

    Lolmewn

    Orrrr use Eclipse/Netbeans' built-in debugger, giving you the opportunity to real-time test code and see variables in real-time :)
     
  10. Offline

    TheChinski

    It seems removing this line made it work again:

    while(!randomLoc.getBlock().getType().equals(Material.AIR)) {
    randomLoc;
    }

    which infinitely looped. I can't guess why though. I added that line because i'd often find myself or other players would get teleported underground, irrelevant to the .getHighestBlockYAt
     
  11. Lolmewn
    I'm curious how that can be set up... I've searched and found a thread about it (http://forums.bukkit.org/threads/debugging-plugins-in-eclipse.4043/) but it doesn't work properly and instead of bumping that I'll ask you :p
    It fails at step 2 with this console log:
    Code:
    229 recipes
    27 achievements
    java.lang.NoClassDefFoundError: Could not initialize class org.fusesource.jansi.internal.Kernel32
    	at org.fusesource.jansi.internal.WindowsSupport.getConsoleMode(WindowsSupport.java:50)
    	at org.bukkit.craftbukkit.libs.jline.WindowsTerminal.getConsoleMode(WindowsTerminal.java:176)
    	at org.bukkit.craftbukkit.libs.jline.WindowsTerminal.init(WindowsTerminal.java:80)
    	at org.bukkit.craftbukkit.libs.jline.TerminalFactory.create(TerminalFactory.java:93)
    	at org.bukkit.craftbukkit.libs.jline.TerminalFactory.get(TerminalFactory.java:151)
    	at org.bukkit.craftbukkit.libs.jline.console.ConsoleReader.<init>(ConsoleReader.java:140)
    	at org.bukkit.craftbukkit.libs.jline.console.ConsoleReader.<init>(ConsoleReader.java:126)
    	at net.minecraft.server.v1_5_R1.MinecraftServer.<init>(MinecraftServer.java:99)
    	at net.minecraft.server.v1_5_R1.DedicatedServer.<init>(DedicatedServer.java:34)
    	at net.minecraft.server.v1_5_R1.MinecraftServer.main(MinecraftServer.java:652)
    	at org.bukkit.craftbukkit.Main.main(Main.java:152)
    
    TheChinski
    The getHighestBlockYAt() doesn't really do what it says it does, it's mostly used by lighting and stuff, you should calculate that yourself, much more reliable.
    It's just a matter of starting at Y = world.getMaxHeight() and checking for block type while going downwards and break when you find one.
     
  12. Offline

    Lolmewn

    Digi That's actually something else, try adding --no-jline after the bit where you specified craftbukkit.jar
     
  13. Offline

    raGan.

    Digi
    One user solved it by adding -Djline.terminal=jline.UnsupportedTerminal into VM arguments. It does work, but different error shows up afterwards.
    Code:
    229 recipes
    27 achievements
    12:59:44 [INFO] Starting minecraft server version 1.5
    12:59:44 [WARNING] To start the server with more ram, launch it as "java -Xmx1024M -Xms1024M -jar minecraft_server.jar"
    12:59:44 [INFO] Loading properties
    12:59:44 [INFO] Default game type: SURVIVAL
    12:59:44 [INFO] Generating keypair
    12:59:45 [INFO] Starting Minecraft server on *:25565
    12:59:45 [SEVERE] java.lang.NullPointerException
    12:59:45 [SEVERE]at org.bukkit.craftbukkit.v1_5_R1.util.Versioning.getBukkitVersion(Versioning.java:14)
    12:59:45 [SEVERE]at org.bukkit.craftbukkit.v1_5_R1.CraftServer.<init>(CraftServer.java:139)
    12:59:45 [SEVERE]at net.minecraft.server.v1_5_R1.PlayerList.<init>(PlayerList.java:55)
    12:59:45 [SEVERE]at net.minecraft.server.v1_5_R1.DedicatedPlayerList.<init>(SourceFile:11)
    12:59:45 [SEVERE]at net.minecraft.server.v1_5_R1.DedicatedServer.init(DedicatedServer.java:105)
    12:59:45 [SEVERE]at net.minecraft.server.v1_5_R1.MinecraftServer.run(MinecraftServer.java:381)
    12:59:45 [SEVERE]at net.minecraft.server.v1_5_R1.ThreadServerApplication.run(SourceFile:573)
    12:59:45 [SEVERE] Encountered an unexpected exception NullPointerException
    java.lang.NullPointerException
    at org.bukkit.craftbukkit.v1_5_R1.util.Versioning.getBukkitVersion(Versioning.java:14)
    at org.bukkit.craftbukkit.v1_5_R1.CraftServer.<init>(CraftServer.java:139)
    at net.minecraft.server.v1_5_R1.PlayerList.<init>(PlayerList.java:55)
    at net.minecraft.server.v1_5_R1.DedicatedPlayerList.<init>(SourceFile:11)
    at net.minecraft.server.v1_5_R1.DedicatedServer.init(DedicatedServer.java:105)
    at net.minecraft.server.v1_5_R1.MinecraftServer.run(MinecraftServer.java:381)
    at net.minecraft.server.v1_5_R1.ThreadServerApplication.run(SourceFile:573)
     
  14. Lolmewn
    I get the same error as raGan. posted with --nojline (the --no-jline arg does not exist).

    Yeah anyway, I guess it would be easier to just print messages :p
     
  15. Offline

    Lolmewn

    raGan. Just somewhat looks like a faulty version of CraftBukkit, actually.
    Digi Try adding -Djline.terminal=jline.UnsupportedTerminal into VM arguments. (as raGan. said)
     
  16. Lolmewn
    I did, I get the same error.
    Code:
    229 recipes
    27 achievements
    16:17:54 [INFO] Starting minecraft server version 1.5
    16:17:54 [WARNING] To start the server with more ram, launch it as "java -Xmx1024M -Xms1024M -jar minecraft_server.jar"
    16:17:54 [INFO] Loading properties
    16:17:54 [INFO] Default game type: CREATIVE
    16:17:54 [INFO] Generating keypair
    16:17:54 [INFO] Starting Minecraft server on *:25555
    16:17:55 [SEVERE] java.lang.NullPointerException
    16:17:55 [SEVERE] 	at org.bukkit.craftbukkit.v1_5_R1.util.Versioning.getBukkitVersion(Versioning.java:14)
    16:17:55 [SEVERE] 	at org.bukkit.craftbukkit.v1_5_R1.CraftServer.<init>(CraftServer.java:139)
    16:17:55 [SEVERE] 	at net.minecraft.server.v1_5_R1.PlayerList.<init>(PlayerList.java:56)
    16:17:55 [SEVERE] 	at net.minecraft.server.v1_5_R1.DedicatedPlayerList.<init>(SourceFile:11)
    16:17:55 [SEVERE] 	at net.minecraft.server.v1_5_R1.DedicatedServer.init(DedicatedServer.java:105)
    16:17:55 [SEVERE] 	at net.minecraft.server.v1_5_R1.MinecraftServer.run(MinecraftServer.java:381)
    16:17:55 [SEVERE] 	at net.minecraft.server.v1_5_R1.ThreadServerApplication.run(SourceFile:573)
    16:17:55 [SEVERE] Encountered an unexpected exception NullPointerException
    java.lang.NullPointerException
    	at org.bukkit.craftbukkit.v1_5_R1.util.Versioning.getBukkitVersion(Versioning.java:14)
    	at org.bukkit.craftbukkit.v1_5_R1.CraftServer.<init>(CraftServer.java:139)
    	at net.minecraft.server.v1_5_R1.PlayerList.<init>(PlayerList.java:56)
    	at net.minecraft.server.v1_5_R1.DedicatedPlayerList.<init>(SourceFile:11)
    	at net.minecraft.server.v1_5_R1.DedicatedServer.init(DedicatedServer.java:105)
    	at net.minecraft.server.v1_5_R1.MinecraftServer.run(MinecraftServer.java:381)
    	at net.minecraft.server.v1_5_R1.ThreadServerApplication.run(SourceFile:573)
    16:17:55 [SEVERE] This crash report has been saved to: D:\Dev\Minecraft\Server\.\crash-reports\crash-2013-03-20_16.17.55-server.txt
    
    Using CB #2681.

    It's too much hassle and becomes a waste of time instead of saving time :p
     
  17. Offline

    Lolmewn

    Digi I guess so. Works fine on my machine, no clue what's wrong!
     
Thread Status:
Not open for further replies.

Share This Page