could not pass event PlayerJoingEvent?

Discussion in 'Plugin Development' started by xXMaTTHDXx, Mar 9, 2013.

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

    xXMaTTHDXx

    my plugin works until some one joins and it gives me this error

    SEVERE] Could not pass event PlayerJoinEvent to SweetLogin v1.0
    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_4_R1.PlayerList.c(PlayerList.java:159)
    at net.minecraft.server.v1_4_R1.PlayerList.a(PlayerList.java:98)
    at net.minecraft.server.v1_4_R1.PendingConnection.d(PendingConnection.java:130)
    at net.minecraft.server.v1_4_R1.PendingConnection.c(PendingConnection.java:45)
    at net.minecraft.server.v1_4_R1.DedicatedServerConnectionThread.a(DedicatedServerConnectionThread.java:44)
    at net.minecraft.server.v1_4_R1.DedicatedServerConnection.b(SourceFile:29)
    at net.minecraft.server.v1_4_R1.MinecraftServer.r(MinecraftServer.java:598)
    at net.minecraft.server.v1_4_R1.DedicatedServer.r(DedicatedServer.java:224)
    at net.minecraft.server.v1_4_R1.MinecraftServer.q(MinecraftServer.java:494)
    at net.minecraft.server.v1_4_R1.MinecraftServer.run(MinecraftServer.java:427)
    at net.minecraft.server.v1_4_R1.ThreadServerApplication.run(SourceFile:849)
    Caused by: java.lang.NullPointerException
    at me.mrc1.SweetLogin.SweetLogin.onJoin(SweetLogin.java:44)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:425)
    ... 14 more
     
  2. Offline

    RainoBoy97

    Ok!






    Anything more you need to show us maybe?
     
  3. Offline

    ZeusAllMighty11

    You have a NullPointerException on SweetLogin line 44
     
  4. Offline

    xXMaTTHDXx

    String loginMessage = config.getString("Messages");
     
  5. Offline

    RainoBoy97

    Show us the config variable
     
  6. Offline

    xXMaTTHDXx

    Code:
    package me.mrc1.SweetLogin;
     
    import java.util.logging.Logger;
     
    import org.bukkit.ChatColor;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class SweetLogin extends JavaPlugin implements Listener{
        public static SweetLogin plugin;
        public    final Logger logger = Logger.getLogger("Minecraft");
        public FileConfiguration config;
       
        @Override
        public void onDisable(){
            PluginDescriptionFile pdfFile = this.getDescription();
            this.logger.info(pdfFile.getName() +"version" + pdfFile.getVersion() + "is now disabled");
                }
           
       
       
        @Override
        public void onEnable(){
            PluginDescriptionFile pdfFile = this.getDescription();
            this.logger.info(pdfFile.getName() +"version" + pdfFile.getVersion() + "is now enabled");
            getServer().getPluginManager().registerEvents(this, this);
            FileConfiguration config = this.getConfig();
            config.get("Messages.path");
            config.addDefault("Messages", "%p has 360ed into the game.");
            config.addDefault("Color", "&");
            getConfig().options().copyDefaults(true);
            saveDefaultConfig();
           
           
        }
       
        @EventHandler
        public void onJoin(PlayerJoinEvent event)
        {
            String loginMessage = config.getString("Messages");
            colorPicker(loginMessage);
            loginMessage.replace("%p",event.getPlayer().getName());
        event.setJoinMessage(loginMessage);
        }
        private String colorPicker(String Message) {
            String loginColor = config.getString("Color");
            if(Message.contains("&0")){
                Message.equals(ChatColor.BLACK);
            }
            if(Message.contains("&1")){
                Message.equals(ChatColor.DARK_BLUE);
            }
            if(Message.contains("&2")){
                Message.equals(ChatColor.DARK_GREEN);
            }
            if(Message.contains("&3")){
                Message.equals(ChatColor.DARK_AQUA);
            }
            if(Message.contains("&4")){
                Message.equals(ChatColor.DARK_RED);
            }
            if(Message.contains("&5")){
                Message.equals(ChatColor.DARK_PURPLE);
            }
            if(Message.contains("&6")){
                Message.equals(ChatColor.GOLD);
            }
            if(Message.contains("&7")){
                Message.equals(ChatColor.GRAY);
            }
            if(Message.contains("&8")){
                Message.equals(ChatColor.DARK_GRAY);
            }
            if(Message.contains("&9")){
                Message.equals(ChatColor.BLUE);
            }
            if(Message.contains("&a")){
                Message.equals(ChatColor.GREEN);
            }
            if(Message.contains("&b")){
                Message.equals(ChatColor.AQUA);
            }
            if(Message.contains("&c")){
                Message.equals(ChatColor.RED);
            }
            if(Message.contains("&d")){
                Message.equals(ChatColor.LIGHT_PURPLE);
            }
            if(Message.contains("&e")){
                Message.equals(ChatColor.YELLOW);
            }
            if(Message.contains("&f")){
                Message.equals(ChatColor.WHITE);
            }
           
                   
           
            return Message;
           
           
            }
           
           
        }
    


    this is the whole code
     
  7. Offline

    ZeusAllMighty11

    You've ignored my past posts; please go back and read them.
     
  8. Offline

    xXMaTTHDXx

    i am aware ZeusAllMighty11 but when i try its not working i am not ignoring you
     
  9. Offline

    GodzOfMadness

    xXMaTTHDXx you are creating a new variable

    EDIT:
    try this

    Code:
    package me.mrc1.SweetLogin;
     
    import java.util.logging.Logger;
     
    import org.bukkit.ChatColor;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class SweetLogin extends JavaPlugin implements Listener{
        public static SweetLogin plugin;
        public    final Logger logger = Logger.getLogger("Minecraft");
        public FileConfiguration config;
     
        @Override
        public void onDisable(){
            PluginDescriptionFile pdfFile = this.getDescription();
            this.logger.info(pdfFile.getName() +"version" + pdfFile.getVersion() + "is now disabled");
                }
         
     
     
        @Override
        public void onEnable(){
            PluginDescriptionFile pdfFile = this.getDescription();
            this.logger.info(pdfFile.getName() +"version" + pdfFile.getVersion() + "is now enabled");
            getServer().getPluginManager().registerEvents(this, this);
            config = this.getConfig();
            config.get("Messages.path");
            config.addDefault("Messages", "%p has 360ed into the game.");
            config.addDefault("Color", "&");
            getConfig().options().copyDefaults(true);
            saveDefaultConfig();
         
         
        }
     
        @EventHandler
        public void onJoin(PlayerJoinEvent event)
        {
            String loginMessage = config.getString("Messages");
            colorPicker(loginMessage);
        event.setJoinMessage(loginMessage.replace("%p",event.getPlayer().getName()));
        }
        private String colorPicker(String Message) {
            String loginColor = config.getString("Color");
            if(Message.contains("&0")){
                Message.equals(ChatColor.BLACK);
            }
            if(Message.contains("&1")){
                Message.equals(ChatColor.DARK_BLUE);
            }
            if(Message.contains("&2")){
                Message.equals(ChatColor.DARK_GREEN);
            }
            if(Message.contains("&3")){
                Message.equals(ChatColor.DARK_AQUA);
            }
            if(Message.contains("&4")){
                Message.equals(ChatColor.DARK_RED);
            }
            if(Message.contains("&5")){
                Message.equals(ChatColor.DARK_PURPLE);
            }
            if(Message.contains("&6")){
                Message.equals(ChatColor.GOLD);
            }
            if(Message.contains("&7")){
                Message.equals(ChatColor.GRAY);
            }
            if(Message.contains("&8")){
                Message.equals(ChatColor.DARK_GRAY);
            }
            if(Message.contains("&9")){
                Message.equals(ChatColor.BLUE);
            }
            if(Message.contains("&a")){
                Message.equals(ChatColor.GREEN);
            }
            if(Message.contains("&b")){
                Message.equals(ChatColor.AQUA);
            }
            if(Message.contains("&c")){
                Message.equals(ChatColor.RED);
            }
            if(Message.contains("&d")){
                Message.equals(ChatColor.LIGHT_PURPLE);
            }
            if(Message.contains("&e")){
                Message.equals(ChatColor.YELLOW);
            }
            if(Message.contains("&f")){
                Message.equals(ChatColor.WHITE);
            }
         
                 
         
            return Message;
         
         
            }
         
         
        }
     
  10. xXMaTTHDXx
    You tried what exacly ?

    "config" is obviously null since you didn't asign it to anything.

    You don't even need that by the way, just use getConfig() directly, it won't re-read the config every time you call it, it's optimized nicely.

    Also, you might want to use ChatColor.translate....() to convert color codes.
     
  11. Offline

    XDemonic25

    show us you Config.yml File... you need this to call config.getstring()
     
  12. XDemonic25
    The config.yml file has nothing to do with that error on that line, the only thing that can trigger NPE at that exact line is the "config" pointer.
    If you get null back from the getString() it will asign the variable to null, why would that give a NPE ?
     
  13. Offline

    GodzOfMadness

    Digi XDemonic25 it's because he never actually asigned the variable "config" he did FileConfiguration config = this.getConfig() he was supposed to do config = this.getConfig()
     
  14. Offline

    XDemonic25

    Ah my bad. I normally dont run into problems like that.. cause its the first thing i do.. and i dont use the built in "GetConfig" thing..
     
  15. Offline

    GodzOfMadness

    XDemonic25 just personal preference nothing to feel ashamed of :p
     
  16. Offline

    xXMaTTHDXx

    ok but it all works but when someone logins in that error pops up
     
  17. Offline

    xXMaTTHDXx

    i have been looking at that but i am unable to see what is going wrong
     
  18. Offline

    GodzOfMadness

    xXMaTTHDXx we explained on what is wrong with your code it is
    because you never set your "config" variable you have to remove the FileConfiguration part from your onEnable method
     
  19. Offline

    xXMaTTHDXx

    i did

    it says the error is is line 44

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  20. Offline

    GodzOfMadness

    xXMaTTHDXx then what is the error now? (please show the line where the error is, the code, and the console error)
     
  21. Offline

    xXMaTTHDXx

    line 44: String loginMessage = config.getString("Messages");
     
  22. Offline

    GodzOfMadness

    xXMaTTHDXx just for the sake of getting this fixed replace that message with
    String loginMessage = getConfig().getString("Messages");
     
  23. Offline

    xXMaTTHDXx

    thats where it says the error is

    console:SEVERE] Could not pass event PlayerJoinEvent to SweetLogin v1.0
    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_4_R1.PlayerList.c(PlayerList.java:159)
    at net.minecraft.server.v1_4_R1.PlayerList.a(PlayerList.java:98)
    at net.minecraft.server.v1_4_R1.PendingConnection.d(PendingConnection.java:130)
    at net.minecraft.server.v1_4_R1.PendingConnection.c(PendingConnection.java:45)
    at net.minecraft.server.v1_4_R1.DedicatedServerConnectionThread.a(DedicatedServerConnectionThread.java:44)
    at net.minecraft.server.v1_4_R1.DedicatedServerConnection.b(SourceFile:29)
    at net.minecraft.server.v1_4_R1.MinecraftServer.r(MinecraftServer.java:598)
    at net.minecraft.server.v1_4_R1.DedicatedServer.r(DedicatedServer.java:224)
    at net.minecraft.server.v1_4_R1.MinecraftServer.q(MinecraftServer.java:494)
    at net.minecraft.server.v1_4_R1.MinecraftServer.run(MinecraftServer.java:427)
    at net.minecraft.server.v1_4_R1.ThreadServerApplication.run(SourceFile:849)
    Caused by: java.lang.NullPointerException
    at me.mrc1.SweetLogin.SweetLogin.colorPicker(SweetLogin.java:51)
    at me.mrc1.SweetLogin.SweetLogin.onJoin(SweetLogin.java:45)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:425)
    Code:
    package me.mrc1.SweetLogin;
     
    import java.util.logging.Logger;
     
    import org.bukkit.ChatColor;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class SweetLogin extends JavaPlugin implements Listener{
        public static SweetLogin plugin;
        public    final Logger logger = Logger.getLogger("Minecraft");
        public FileConfiguration config;
       
        @Override
        public void onDisable(){
            PluginDescriptionFile pdfFile = this.getDescription();
            this.logger.info(pdfFile.getName() +"version" + pdfFile.getVersion() + "is now disabled");
                }
           
       
       
        @Override
        public void onEnable(){
            PluginDescriptionFile pdfFile = this.getDescription();
            this.logger.info(pdfFile.getName() +"version" + pdfFile.getVersion() + "is now enabled");
            getServer().getPluginManager().registerEvents(this, this);
            config = this.getConfig();
            config.get("Messages.path");
            config.addDefault("Messages", "%p has 360ed into the game.");
            config.addDefault("Color", "&");
            getConfig().options().copyDefaults(true);
            saveDefaultConfig();
           
           
        }
       
        @EventHandler
        public void onJoin(PlayerJoinEvent event)
        {
            String loginMessage = config.getString("Messages");
            colorPicker(loginMessage);
            loginMessage.replace("%p",event.getPlayer().getName());
        event.setJoinMessage(loginMessage);
        }
        private String colorPicker(String Message) {
            String loginColor = config.getString("Color");
            if(Message.contains("&0")){
                Message.equals(ChatColor.BLACK);
            }
            if(Message.contains("&1")){
                Message.equals(ChatColor.DARK_BLUE);
            }
            if(Message.contains("&2")){
                Message.equals(ChatColor.DARK_GREEN);
            }
            if(Message.contains("&3")){
                Message.equals(ChatColor.DARK_AQUA);
            }
            if(Message.contains("&4")){
                Message.equals(ChatColor.DARK_RED);
            }
            if(Message.contains("&5")){
                Message.equals(ChatColor.DARK_PURPLE);
            }
            if(Message.contains("&6")){
                Message.equals(ChatColor.GOLD);
            }
            if(Message.contains("&7")){
                Message.equals(ChatColor.GRAY);
            }
            if(Message.contains("&8")){
                Message.equals(ChatColor.DARK_GRAY);
            }
            if(Message.contains("&9")){
                Message.equals(ChatColor.BLUE);
            }
            if(Message.contains("&a")){
                Message.equals(ChatColor.GREEN);
            }
            if(Message.contains("&b")){
                Message.equals(ChatColor.AQUA);
            }
            if(Message.contains("&c")){
                Message.equals(ChatColor.RED);
            }
            if(Message.contains("&d")){
                Message.equals(ChatColor.LIGHT_PURPLE);
            }
            if(Message.contains("&e")){
                Message.equals(ChatColor.YELLOW);
            }
            if(Message.contains("&f")){
                Message.equals(ChatColor.WHITE);
            }
           
                   
           
            return Message;
           
           
            }
           
           
        }
    
     
  24. Offline

    ZeusAllMighty11

  25. Offline

    GodzOfMadness

    xXMaTTHDXx look in the config and see if you see the path "Messages" and "Color" in there
     
  26. Offline

    xXMaTTHDXx

    its all fixed thank you!!!
     
  27. Offline

    xXMaTTHDXx

    can someone tell me how to get the color to work cause it isnt i messed around with it and now it doesnt work
     
  28. Offline

    ZeusAllMighty11

    Post your code
     
  29. Offline

    xXMaTTHDXx

    ok here it is and one quick thing when i log in it has the color code like this &1bmcc1234 has backflipped into the game so i need to fix that so its a color.

    Code:
    package me.mrc1.SweetLogin;
     
    import java.util.logging.Logger;
     
    import org.bukkit.ChatColor;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class SweetLogin extends JavaPlugin implements Listener{
        public static SweetLogin plugin;
        public    final Logger logger = Logger.getLogger("Minecraft");
        public FileConfiguration config;
       
        @Override
        public void onDisable(){
            PluginDescriptionFile pdfFile = this.getDescription();
            this.logger.info(pdfFile.getName() +"version" + pdfFile.getVersion() + "is now disabled");
                }
           
       
       
        @Override
        public void onEnable(){
            PluginDescriptionFile pdfFile = this.getDescription();
            this.logger.info(pdfFile.getName() +"version" + pdfFile.getVersion() + "is now enabled");
            getServer().getPluginManager().registerEvents(this, this);
            config = this.getConfig();
            config.get("Messages.path");
            config.addDefault(" Messages", " Your Message Here.");
            config.get("Color.path");
            config.addDefault("Color", "&");
            getConfig().options().copyDefaults(true);
            saveDefaultConfig();
           
           
        }
       
        @EventHandler
        public void onJoin(PlayerJoinEvent event)
        {
            String loginColor = getConfig().getString("Color.path");
            String loginMessage = getConfig().getString("Messages.path");
            event.setJoinMessage(loginColor + event.getPlayer().getName() + loginMessage);
            if(loginColor.contains("&0")){
                loginColor.equals(ChatColor.BLACK);
            }
            if(loginColor.contains("&1")){
                loginColor.equals(ChatColor.DARK_BLUE);
            }
            if(loginColor.contains("&2")){
                loginColor.equals(ChatColor.DARK_GREEN);
            }
            if(loginColor.contains("&3")){
                loginColor.equals(ChatColor.DARK_AQUA);
            }
            if(loginColor.contains("&4")){
                loginColor.equals(ChatColor.DARK_RED);
            }
            if(loginColor.contains("&5")){
                loginColor.equals(ChatColor.DARK_PURPLE);
            }
            if(loginColor.contains("&6")){
                loginColor.equals(ChatColor.GOLD);
            }
            if(loginColor.contains("&7")){
                loginColor.equals(ChatColor.GRAY);
            }
            if(loginColor.contains("&8")){
                loginColor.equals(ChatColor.DARK_GRAY);
            }
            if(loginColor.contains("&9")){
                loginColor.equals(ChatColor.BLUE);
            }
            if(loginColor.contains("&a")){
                loginColor.equals(ChatColor.GREEN);
            }
            if(loginColor.contains("&b")){
                loginColor.equals(ChatColor.AQUA);
            }
            if(loginColor.contains("&c")){
                loginColor.equals(ChatColor.RED);
            }
            if(loginColor.contains("&d")){
                loginColor.equals(ChatColor.LIGHT_PURPLE);
            }
            if(loginColor.contains("&e")){
                loginColor.equals(ChatColor.YELLOW);
            }
            if(loginColor.contains("&f")){
                loginColor.equals(ChatColor.WHITE);
            }
           
        }
        }
    
     
Thread Status:
Not open for further replies.

Share This Page