[UNSQUASHABLE] Null Pointer Teleport on Join

Discussion in 'Plugin Development' started by ccrama, Nov 16, 2013.

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

    ccrama

    Hello Bukkit
    I have an unsquashable bug, and have no idea why it is occuring. When a player joins, I want them to teleport to their respective spawns, but every time a player joins, I get this error:
    PHP:
    2013-11-16 15:35:40 [SEVERECould not pass event PlayerTeleportEvent to Multiverse-Core v2.5-b675
    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 org.bukkit.craftbukkit.v1_6_R3.entity.CraftPlayer.teleport(CraftPlayer.java:382)
        
    at org.bukkit.craftbukkit.v1_6_R3.entity.CraftEntity.teleport(CraftEntity.java:199)
        
    at me.ccrama.MineFortress2.Badlands$1.run(Badlands.java:43)
        
    at org.bukkit.craftbukkit.v1_6_R3.scheduler.CraftTask.run(CraftTask.java:53)
        
    at org.bukkit.craftbukkit.v1_6_R3.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:345)
        
    at net.minecraft.server.v1_6_R3.MinecraftServer.t(MinecraftServer.java:524)
        
    at net.minecraft.server.v1_6_R3.DedicatedServer.t(DedicatedServer.java:227)
        
    at net.minecraft.server.v1_6_R3.MinecraftServer.s(MinecraftServer.java:488)
        
    at net.minecraft.server.v1_6_R3.MinecraftServer.run(MinecraftServer.java:421)
        
    at net.minecraft.server.v1_6_R3.ThreadServerApplication.run(SourceFile:583)
    Caused byjava.lang.NullPointerException
        at com
    .onarandombox.MultiverseCore.listeners.MVPlayerListener.playerTeleport(MVPlayerListener.java:178)
        
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        
    at java.lang.reflect.Method.invoke(Method.java:606)
        
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:425)
        ... 
    13 more
    2013
    -11-16 15:35:40 [WARNING] [MineFortress2Task #21 for MineFortress2 v2.0 generated an exception
    java.lang.NullPointerException
        at org
    .bukkit.craftbukkit.v1_6_R3.entity.CraftPlayer.teleport(CraftPlayer.java:395)
        
    at org.bukkit.craftbukkit.v1_6_R3.entity.CraftEntity.teleport(CraftEntity.java:199)
        
    at me.ccrama.MineFortress2.Badlands$1.run(Badlands.java:43)
        
    at org.bukkit.craftbukkit.v1_6_R3.scheduler.CraftTask.run(CraftTask.java:53)
        
    at org.bukkit.craftbukkit.v1_6_R3.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:345)
        
    at net.minecraft.server.v1_6_R3.MinecraftServer.t(MinecraftServer.java:524)
        
    at net.minecraft.server.v1_6_R3.DedicatedServer.t(DedicatedServer.java:227)
        
    at net.minecraft.server.v1_6_R3.MinecraftServer.s(MinecraftServer.java:488)
        
    at net.minecraft.server.v1_6_R3.MinecraftServer.run(MinecraftServer.java:421)
        
    at net.minecraft.server.v1_6_R3.ThreadServerApplication.run(SourceFile:583)
    This is the "badlands.java" mentioned in the stacktrace:

    Code:java
    1. package me.ccrama.MineFortress2;
    2.  
    3.  
    4. import org.bukkit.Bukkit;
    5. import org.bukkit.ChatColor;
    6. import org.bukkit.Location;
    7. import org.bukkit.entity.Player;
    8. import org.bukkit.event.EventHandler;
    9. import org.bukkit.event.Listener;
    10. import org.bukkit.event.entity.PlayerDeathEvent;
    11. import org.bukkit.event.player.PlayerJoinEvent;
    12. import org.bukkit.event.player.PlayerRespawnEvent;
    13. import org.bukkit.plugin.Plugin;
    14.  
    15. import com.shampaggon.crackshot.events.WeaponDamageEntityEvent;
    16.  
    17. public class Badlands implements Listener {
    18. Location a = new Location(Bukkit.getWorld("arena_badlands"), -336, 81, -182);
    19. Location b = new Location(Bukkit.getWorld("arena_badlands"), -190, 81, -144);
    20. Location c = new Location(Bukkit.getWorld("arena_badlands"), -263, 82, -163);
    21. public void pregameBadlands(){
    22. if(Lists.getLists().Game.contains("Badlands")){
    23.  
    24. new Arenahandler().pregame("arena_badlands", a, b, c, "Badlands");
    25. }
    26. }
    27. final Plugin plugin = Bukkit.getPluginManager().getPlugin("MineFortress2");
    28.  
    29. @EventHandler
    30. public void Join(PlayerJoinEvent e){
    31.  
    32. if(Lists.getLists().Game.contains("Badlands")){
    33.  
    34. if(Bukkit.getOnlinePlayers().length == 2){
    35. new Arenahandler().startGame(a, b, c);
    36. }
    37. final Player player = e.getPlayer();
    38. Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable(){
    39. public void run(){
    40. if (Lists.getLists().Blue.contains(player.getName())){
    41.  
    42.  
    43. player.teleport(a);
    44. Lists.getLists().Blueplayers.add(player.getName());
    45.  
    46.  
    47.  
    48.  
    49.  
    50. } else{
    51.  
    52. player.teleport(b);
    53. Lists.getLists().Redplayers.add(player.getName());
    54.  
    55. }
    56. }
    57. }, 3);
    58. }
    59.  
    60. }
    61.  
    62. @EventHandler
    63. public void onDeath(PlayerDeathEvent e){
    64. if(Lists.getLists().Game.contains("Badlands")){
    65.  
    66. Player player = (Player) e.getEntity();
    67. String name = player.getName();
    68. if(Lists.getLists().Blue.contains(name)){
    69. Lists.getLists().Blueplayers.remove(name);
    70. }
    71. if(Lists.getLists().Red.contains(name)){
    72. Lists.getLists().Redplayers.remove(name);
    73. }
    74. if(Lists.getLists().Redplayers.size() - Lists.getLists().Blueplayers.size() == 0 ){
    75. Bukkit.broadcastMessage(ChatColor.RED + "RED TEAM HAS WON!");
    76. new End();
    77. }
    78. if(Lists.getLists().Blueplayers.size() - Lists.getLists().Redplayers.size() == 0 ){
    79. Bukkit.broadcastMessage(ChatColor.BLUE + "BLUE TEAM HAS WON!");
    80. new End();
    81. }
    82. }
    83. }
    84. @EventHandler
    85. public void respawn(PlayerRespawnEvent e){
    86. if(Lists.getLists().Game.contains("Badlands")){
    87.  
    88. Player p = e.getPlayer();
    89. for (Player players : Bukkit.getOnlinePlayers())
    90. {
    91. players.hidePlayer
    92. (p);
    93.  
    94. }
    95. }
    96. }
    97. @EventHandler
    98. public void shot(WeaponDamageEntityEvent e){
    99. if(Lists.getLists().Game.contains("Badlands")){
    100.  
    101. if(Lists.getLists().Blueplayers.contains(e.getPlayer().getName() ) || Lists.getLists().Redplayers.contains(e.getPlayer().getName())){
    102. e.setCancelled(false);
    103. } else {
    104. e.setCancelled(true);
    105. }
    106. }
    107. }
    108. }
    109.  


    Although it mentions multiverse, I don't believe that is the culprit. Any help is appriciated!

    Cheers,
    ccrama
     
  2. Offline

    xTrollxDudex

    ccrama
    Multiverse handles the multiworld teleports, so I do believe that is the problem.
     
  3. Offline

    ccrama

    xTrollxDudex, it occurs with other multiworld plugins too though...
     
  4. Offline

    xTrollxDudex

    ccrama
    Try using Bukkit.getServer().getWorld(...) instead of just Bukkit.getWorld(...)
     
  5. Offline

    ccrama

  6. Offline

    tommykins20

    Presumably you are initializing the listener in the onEnable method of your plugin. I think that Bukkit loads worlds after plugins have loaded (not sure about this) so you need to re-initialize the Location variables (a, b, c) after the worlds have loaded.
     
  7. Offline

    ccrama



    The variables are initiated in the class, which is initiated on join event for the first player. I created the runnable to delay the action, letting the locations load and presumably fix the error. The problem is it works perfectly for my twofort (world) world, but the error occurs on Badlands (arena_badlands) and Doublecross (doublecross) (they implement the same methods, basically the same) They run on non-default worlds, which is probably causing the teleportation errors for my multiworld plugins.
     
  8. Offline

    tommykins20

    Are you able to teleport to the worlds normally through your current multi-world method?
     
  9. Offline

    Garris0n

    Put the initializations of those variables in a constructor and see what happens.
     
  10. Offline

    ccrama

    Holy crap, thanks so much Garris0n. Is there any particular reason that would have caused the error?

    Thanks!
     
  11. Offline

    Garris0n

    After doing a bit of research I'm not sure why that would work at all, they should actually do the same thing. Also, when are you initiating the class, exactly? You said it's in the join event for the first player but an instance of it should be made when you register the event in the first place.
     
  12. Offline

    maxben34

    ccrama Garris0n
    BTW i've had this same problem before, i found that if you reload the server it actually fixes it. (But that would mean reloading the server everytime it starts up which is a pain in the butt)
     
  13. Offline

    drtshock

  14. Offline

    ccrama

    Garris0n,when a player joins, it randomly chooses 1 of 4 classes to initiate. Each of these clasess handel one world's game using a handler class for each gametype (some games have different versions in other worlds). Then when each ends, a new number is chosen and makes a new game. This is a horrible method to use, with lots of problems. Im going to do some research drtshock 's link!

    Well the main point I have is that the bug is fixed, but can anyone scour my code to see WHY that fixed it? I am very confused as to why this is happening. Just ask and I'll post some more of my classes!

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

    Garris0n

    Feel free, I'm kinda curious.
     

  16. I suspect that the variables were being initialized before the worlds were actually loaded, causing the error. Waiting to initialize variables until the object is actually instantiated is generally considered to be good practice, I believe.
     
Thread Status:
Not open for further replies.

Share This Page