Error joinevent

Discussion in 'Plugin Development' started by kingsofbart, Sep 7, 2015.

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

    kingsofbart

    Hello,

    I got a error about joinevent:
    Error (open)

    org.bukkit.event.EventException
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:310) ~[spigot_server.jar:git-Spigot-fdc1440-53fac9f]
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot_server.jar:git-Spigot-fdc1440-53fac9f]
    at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot_server.jar:git-Spigot-fdc1440-53fac9f]
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot_server.jar:git-Spigot-fdc1440-53fac9f]
    at net.minecraft.server.v1_8_R3.PlayerList.onPlayerJoin(PlayerList.java:298) [spigot_server.jar:git-Spigot-fdc1440-53fac9f]
    at net.minecraft.server.v1_8_R3.PlayerList.a(PlayerList.java:157) [spigot_server.jar:git-Spigot-fdc1440-53fac9f]
    at net.minecraft.server.v1_8_R3.LoginListener.b(LoginListener.java:144) [spigot_server.jar:git-Spigot-fdc1440-53fac9f]
    at net.minecraft.server.v1_8_R3.LoginListener.c(LoginListener.java:54) [spigot_server.jar:git-Spigot-fdc1440-53fac9f]
    at net.minecraft.server.v1_8_R3.NetworkManager.a(NetworkManager.java:231) [spigot_server.jar:git-Spigot-fdc1440-53fac9f]
    at net.minecraft.server.v1_8_R3.ServerConnection.c(ServerConnection.java:148) [spigot_server.jar:git-Spigot-fdc1440-53fac9f]
    at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:813) [spigot_server.jar:git-Spigot-fdc1440-53fac9f]
    at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:374) [spigot_server.jar:git-Spigot-fdc1440-53fac9f]
    at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:653) [spigot_server.jar:git-Spigot-fdc1440-53fac9f]
    at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:556) [spigot_server.jar:git-Spigot-fdc1440-53fac9f]
    at java.lang.Thread.run(Unknown Source) [?:1.8.0_60]
    Caused by: java.lang.NullPointerException
    at main.Level.onPlayerJoin(Level.java:14) ~[?:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_60]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_60]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_60]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_60]
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[spigot_server.jar:git-Spigot-fdc1440-53fac9f]
    ... 14 more

    Code main (open)

    package main;

    import org.bukkit.Bukkit;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;

    public class Main extends JavaPlugin{
    public void onEnable() {
    PluginManager pm = Bukkit.getServer().getPluginManager();
    pm.registerEvents(new Level(), this);
    }
    public Main() {

    }
    }


    Code Level (open)

    package main;

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

    public class Level implements Listener {
    Main m;
    @EventHandler
    public void onPlayerJoin(PlayerJoinEvent event) {
    Player p = event.getPlayer();
    String l = m.getConfig().getString(p + ".level");
    if(l == "1"){
    p.setDisplayName(ChatColor.GRAY+ "[" + ChatColor.GOLD + "L1" + ChatColor.GRAY + "]" + p.getPlayerListName());
    }if(l == "2"){
    p.setDisplayName(ChatColor.GRAY+ "[" + ChatColor.GOLD + "L2" + ChatColor.GRAY + "]" + p.getPlayerListName());
    }if(l == "3"){
    p.setDisplayName(ChatColor.GRAY+ "[" + ChatColor.GOLD + "L3" + ChatColor.GRAY + "]" + p.getPlayerListName());
    }if(l == "4"){
    p.setDisplayName(ChatColor.GRAY+ "[" + ChatColor.GOLD + "L4" + ChatColor.GRAY + "]" + p.getPlayerListName());
    }if(l == "5"){
    p.setDisplayName(ChatColor.GRAY+ "[" + ChatColor.GOLD + "L5" + ChatColor.GRAY + "]" + p.getPlayerListName());
    }if(l == "6"){
    p.setDisplayName(ChatColor.GRAY+ "[" + ChatColor.GOLD + "L6" + ChatColor.GRAY + "]" + p.getPlayerListName());
    }if(l == "7"){
    p.setDisplayName(ChatColor.GRAY+ "[" + ChatColor.GOLD + "L7" + ChatColor.GRAY + "]" + p.getPlayerListName());
    }if(l == "8"){
    p.setDisplayName(ChatColor.GRAY+ "[" + ChatColor.GOLD + "L8" + ChatColor.GRAY + "]" + p.getPlayerListName());
    }if(l == "9"){
    p.setDisplayName(ChatColor.GRAY+ "[" + ChatColor.GOLD + "L9" + ChatColor.GRAY + "]" + p.getPlayerListName());
    }else{
    m.getConfig().addDefault(p + ".level", "1");
    p.setDisplayName(ChatColor.GRAY+ "[" + ChatColor.GOLD + "L1" + ChatColor.GRAY + "]" + p.getPlayerListName());
    }

    }


    }

     
  2. You didn't initialize Main m; in your Level class
     
  3. Offline

    SuperSniper

    @kingsofbart
    Code:
    Caused by: java.lang.NullPointerException
    at main.Level.onPlayerJoin(Level.java:14) ~[?:?]
    
    Im guessing line #14 inside the "Level" class is :
    Code:
    String l = m.getConfig().getString(p + ".level");
    
    Is the string that you're searching for even inside the config? If not, that's most likely what's causing the problem.
    Also, if you're searching for a number inside a config, use getInt, not getString.
    Use .equals, not ==
     
  4. Offline

    kingsofbart

  5. Offline

    Zombie_Striker

    @kingsofbart
    1. You should not create a constructor for you Main class because you should only have one instance of your class.
    2. JAVA NAMING CONVENTIONS: Why do people love naming their main classes MAIN
    3. You are only using pm once, you can remove the PluginManager field.
    4. The level class: That is terrible. That's roughly 30 lines that can be reduced to 2 lines.
    Seems like I've been ninja'd.
     
  6. Offline

    kingsofbart

    thanks for your reaction but it still dont work
    error (open)

    org.bukkit.event.EventException
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:310) ~[spigot_server.jar:git-Spigot-fdc1440-53fac9f]
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot_server.jar:git-Spigot-fdc1440-53fac9f]
    at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot_server.jar:git-Spigot-fdc1440-53fac9f]
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot_server.jar:git-Spigot-fdc1440-53fac9f]
    at net.minecraft.server.v1_8_R3.PlayerList.onPlayerJoin(PlayerList.java:298) [spigot_server.jar:git-Spigot-fdc1440-53fac9f]
    at net.minecraft.server.v1_8_R3.PlayerList.a(PlayerList.java:157) [spigot_server.jar:git-Spigot-fdc1440-53fac9f]
    at net.minecraft.server.v1_8_R3.LoginListener.b(LoginListener.java:144) [spigot_server.jar:git-Spigot-fdc1440-53fac9f]
    at net.minecraft.server.v1_8_R3.LoginListener.c(LoginListener.java:54) [spigot_server.jar:git-Spigot-fdc1440-53fac9f]
    at net.minecraft.server.v1_8_R3.NetworkManager.a(NetworkManager.java:231) [spigot_server.jar:git-Spigot-fdc1440-53fac9f]
    at net.minecraft.server.v1_8_R3.ServerConnection.c(ServerConnection.java:148) [spigot_server.jar:git-Spigot-fdc1440-53fac9f]
    at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:813) [spigot_server.jar:git-Spigot-fdc1440-53fac9f]
    at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:374) [spigot_server.jar:git-Spigot-fdc1440-53fac9f]
    at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:653) [spigot_server.jar:git-Spigot-fdc1440-53fac9f]
    at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:556) [spigot_server.jar:git-Spigot-fdc1440-53fac9f]
    at java.lang.Thread.run(Unknown Source) [?:1.8.0_60]
    Caused by: java.lang.NullPointerException
    at main.Level.onPlayerJoin(Level.java:15) ~[?:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_60]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_60]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_60]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_60]
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[spigot_server.jar:git-Spigot-fdc1440-53fac9f]
    ... 14 more

    is comming now
     
  7. Offline

    SuperSniper

  8. Offline

    kingsofbart

    Object l = m.getConfig().getInt(p + ".level");
    (if i try Int l = m.getConfig().getInt(p + ".level"); it doesnt work too)
     
  9. Offline

    Zombie_Striker

    @SuperSniper
    Line 15 is this:

    String l = m.getConfig().getString(p + ".level");

    Make sure l is not equal to null, the m is not null,

    @kingsofbart
    That is because P is the PLAYERS instance, not their NAME

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

    SuperSniper

    @kingsofbart Can we see your config? Im guessing your config is the problem as I said in my first post.
     
  11. Offline

    Zombie_Striker

    @SuperSniper
    Even is we see his config, we know that he's trying to use the PLAYER'S INSTANCE, not their name as the path.

    @kingsofbart Also, your package is called main, and your main class is called Main. Who taught you these bad practices?
     
  12. Offline

    SuperSniper

    @Zombie_Striker Good point, and that's probably a reason why. I want to see it to see if he has anything about the p + ".level
     
  13. Offline

    kingsofbart

    I got it! thanks.
     
Thread Status:
Not open for further replies.

Share This Page