Error on Player Join [Solved]

Discussion in 'Spigot Plugin Development' started by TheMonsterBUFF, May 21, 2015.

  1. I have this error on player join this is the class
    Code (Text):

    package tk.themonsterbuff;

    import org.bukkit.Location;
    import org.bukkit.World;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;

    public class Events implements Listener{
        private World world;
       
        @EventHandler
        public void onPlayerJoin(PlayerJoinEvent e) {
            Player p = e.getPlayer();

            Location lobby1 = new Location(world, -1160, 12, -1428);

            p.teleport(lobby1);
           
        }
    }

    And this is the console error
    Code (Text):
    [19:49:34] [Server thread/ERROR]: Could not pass event PlayerJoinEvent to AsaltoOmegaV1 v1.0
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:305) ~[spigot.jar:git-Spigot-15fa8e1-17a3db7]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot.jar:git-Spigot-15fa8e1-17a3db7]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot.jar:git-Spigot-15fa8e1-17a3db7]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot.jar:git-Spigot-15fa8e1-17a3db7]
        at net.minecraft.server.v1_8_R1.PlayerList.onPlayerJoin(PlayerList.java:272) [spigot.jar:git-Spigot-15fa8e1-17a3db7]
        at net.minecraft.server.v1_8_R1.PlayerList.a(PlayerList.java:156) [spigot.jar:git-Spigot-15fa8e1-17a3db7]
        at net.minecraft.server.v1_8_R1.LoginListener.b(LoginListener.java:109) [spigot.jar:git-Spigot-15fa8e1-17a3db7]
        at net.minecraft.server.v1_8_R1.LoginListener.c(LoginListener.java:41) [spigot.jar:git-Spigot-15fa8e1-17a3db7]
        at net.minecraft.server.v1_8_R1.NetworkManager.a(NetworkManager.java:159) [spigot.jar:git-Spigot-15fa8e1-17a3db7]
        at net.minecraft.server.v1_8_R1.ServerConnection.c(ServerConnection.java:82) [spigot.jar:git-Spigot-15fa8e1-17a3db7]
        at net.minecraft.server.v1_8_R1.MinecraftServer.z(MinecraftServer.java:800) [spigot.jar:git-Spigot-15fa8e1-17a3db7]
        at net.minecraft.server.v1_8_R1.DedicatedServer.z(DedicatedServer.java:316) [spigot.jar:git-Spigot-15fa8e1-17a3db7]
        at net.minecraft.server.v1_8_R1.MinecraftServer.y(MinecraftServer.java:634) [spigot.jar:git-Spigot-15fa8e1-17a3db7]
        at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java:537) [spigot.jar:git-Spigot-15fa8e1-17a3db7]
        at java.lang.Thread.run(Unknown Source) [?:1.7.0_13]
    Caused by: java.lang.NullPointerException
        at org.bukkit.craftbukkit.v1_8_R1.entity.CraftPlayer.teleport(CraftPlayer.java:464) ~[spigot.jar:git-Spigot-15fa8e1-17a3db7]
        at org.bukkit.craftbukkit.v1_8_R1.entity.CraftEntity.teleport(CraftEntity.java:223) ~[spigot.jar:git-Spigot-15fa8e1-17a3db7]
        at tk.themonsterbuff.Events.onPlayerJoin(Events.java:20) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_13]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_13]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_13]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_13]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:301) ~[spigot.jar:git-Spigot-15fa8e1-17a3db7]
        ... 14 more
    Help me Please!
     
  2. world is null/not set.
     
    • Winner Winner x 1
  3. Code (Text):
    package tk.themonsterbuff;

    import org.bukkit.Location;
    import org.bukkit.World;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;

    public class Events implements Listener{

       
        @EventHandler
        public void onPlayerJoin(PlayerJoinEvent e) {
            Player p = e.getPlayer();
            World world = null;

            Location lobby1 = new Location(world, -1160, 12, -1428);

            p.teleport(lobby1);
           
        }
    }
     
     
    • Funny Funny x 1
  4. konsolas

    Supporter

    You never set world in your plugin. Setting it to null won't help :p
     
    • Agree Agree x 1
    • Winner Winner x 1
  5. package tk.themonsterbuff;

    import org.bukkit.Bukkit;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.Plugin;
    import org.bukkit.plugin.java.JavaPlugin;


    public class main extends JavaPlugin implements Listener{


    private static Plugin plugin;

    public void onEnable() {
    plugin = this;
    Bukkit.getServer().getPluginManager().registerEvents(new Events(),this);
    Bukkit.getServer().getPluginManager().registerEvents(new Commands(),this);
    Bukkit.getServer().getPluginManager().registerEvents(new Teams(),this);



    }

    public void onDisable() {

    }



    public static void registerEvents(org.bukkit.plugin.Plugin plugin, Listener... listeners) {
    for (Listener listener : listeners) {
    Bukkit.getServer().getPluginManager().registerEvents(listener, plugin);
    }
    }


    public static Plugin getPlugin() {
    return plugin;
    }
    }
     
  6. JamesJ

    Supporter

    The code that I have highlighted in bold, italics and underlined, you must read.
    You've set the value 'world' to null. But never changed it to a real value.
     
  7. MAIN CLASS
    Code (Text):

    package tk.themonsterbuff;

    import org.bukkit.Bukkit;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.Plugin;
    import org.bukkit.plugin.java.JavaPlugin;


    public class main extends JavaPlugin implements Listener{
     
        private static Plugin plugin;
     
        public void onEnable() {
            plugin = this;
            Bukkit.getServer().getPluginManager().registerEvents(new Events(),this);
            Bukkit.getServer().getPluginManager().registerEvents(new Commands(),this);
            Bukkit.getServer().getPluginManager().registerEvents(new Teams(),this);
         
       

        }
     
        public void onDisable() {
         
        }
     
     

        public static void registerEvents(org.bukkit.plugin.Plugin plugin, Listener... listeners) {
            for (Listener listener : listeners) {
                Bukkit.getServer().getPluginManager().registerEvents(listener, plugin);
            }
        }
     

        public static Plugin getPlugin() {
            return plugin;
        }
    }
     
    EventClass

    Code (Text):

    package tk.themonsterbuff;

    import org.bukkit.Location;
    import org.bukkit.World;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;

    public class Events implements Listener{

       
        @EventHandler
        public void onPlayerJoin(PlayerJoinEvent e) {
            Player p = e.getPlayer();
            World world = null;

            Location lobby1 = new Location(world, -1160, 12, -1428);

            p.teleport(lobby1);
           
        }
    }
     
    ERROR ON JOIN
    Code (Text):
    [19:49:34] [Server thread/ERROR]: Could not pass event PlayerJoinEvent to AsaltoOmegaV1 v1.0
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:305) ~[spigot.jar:git-Spigot-15fa8e1-17a3db7]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot.jar:git-Spigot-15fa8e1-17a3db7]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot.jar:git-Spigot-15fa8e1-17a3db7]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot.jar:git-Spigot-15fa8e1-17a3db7]
        at net.minecraft.server.v1_8_R1.PlayerList.onPlayerJoin(PlayerList.java:272) [spigot.jar:git-Spigot-15fa8e1-17a3db7]
        at net.minecraft.server.v1_8_R1.PlayerList.a(PlayerList.java:156) [spigot.jar:git-Spigot-15fa8e1-17a3db7]
        at net.minecraft.server.v1_8_R1.LoginListener.b(LoginListener.java:109) [spigot.jar:git-Spigot-15fa8e1-17a3db7]
        at net.minecraft.server.v1_8_R1.LoginListener.c(LoginListener.java:41) [spigot.jar:git-Spigot-15fa8e1-17a3db7]
        at net.minecraft.server.v1_8_R1.NetworkManager.a(NetworkManager.java:159) [spigot.jar:git-Spigot-15fa8e1-17a3db7]
        at net.minecraft.server.v1_8_R1.ServerConnection.c(ServerConnection.java:82) [spigot.jar:git-Spigot-15fa8e1-17a3db7]
        at net.minecraft.server.v1_8_R1.MinecraftServer.z(MinecraftServer.java:800) [spigot.jar:git-Spigot-15fa8e1-17a3db7]
        at net.minecraft.server.v1_8_R1.DedicatedServer.z(DedicatedServer.java:316) [spigot.jar:git-Spigot-15fa8e1-17a3db7]
        at net.minecraft.server.v1_8_R1.MinecraftServer.y(MinecraftServer.java:634) [spigot.jar:git-Spigot-15fa8e1-17a3db7]
        at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java:537) [spigot.jar:git-Spigot-15fa8e1-17a3db7]
        at java.lang.Thread.run(Unknown Source) [?:1.7.0_13]
    Caused by: java.lang.NullPointerException
        at org.bukkit.craftbukkit.v1_8_R1.entity.CraftPlayer.teleport(CraftPlayer.java:464) ~[spigot.jar:git-Spigot-15fa8e1-17a3db7]
        at org.bukkit.craftbukkit.v1_8_R1.entity.CraftEntity.teleport(CraftEntity.java:223) ~[spigot.jar:git-Spigot-15fa8e1-17a3db7]
        at tk.themonsterbuff.Events.onPlayerJoin(Events.java:20) ~[?:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_13]
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_13]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_13]
        at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_13]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:301) ~[spigot.jar:git-Spigot-15fa8e1-17a3db7]
        ... 14 more
     
  8. Pass a World to the constructor of the Events class.
    Code (Text):
    public class Events implements Listener {
        private final World world;
        public Events(World world) {
            this.world = world;
        }
    }
     
    #8 smrkn, May 21, 2015
    Last edited: May 21, 2015
  9. konsolas

    Supporter

    Learn Java.
     
    • Agree Agree x 8
    • Funny Funny x 3
    • Winner Winner x 1
  10. JamesJ

    Supporter



    PLEASE LEARN TO READ!
    >>>> We have stated what the problem is 3 times! <<<<


    @TheMonsterBUFF
     
  11. Troll?
    Else: Please read, what everyone above already said...
     
    • Funny Funny x 1
  12. Hahahahahahhahahaha! This is a joke too, I think...
     
    • Agree Agree x 1
  13. Do you have special world names for you lobbies? For example lobby1, lobby2...
    Try this for getting the right location:
    Code (Text):

    public class Events implements Listener{


      @EventHandler
      public void onPlayerJoin(PlayerJoinEvent e) {
      Player p = e.getPlayer();

      Location lobby1 = new Location(Bukkit.getWorld(world), -1160, 12, -1428);

      p.teleport(lobby1);
     
      }
    }
     
     
  14. Set the world :D Its null atm
     
  15. You can't do that the
    Code (Text):
      World world = null;
    the world is null, please learn something basic java before the spigot/bukkit API, thanks.
    Variables: Click Here
    Start Learn Java: Click Here
    Code (Text):
    @EventHandler
    public void playerJoin(PlayerJoinEvent event){
    Player player = event.getPlayer();                         //X     //Y   //Z
    Location loc = new Location(getServer().getWorld("world"), -1160, 12, -1428);
    player.teleport(loc);
    for(String current : Players){
    getServer().getPlayer(current).teleport(loc);
       }
    }
     
    • Like Like x 1
  16. Why?