Configuration check giving error

Discussion in 'Plugin Development' started by ItsMas_, Jan 27, 2016.

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

    ItsMas_

    When a player logs on, I am testing whether they have been registered in the config, and if they haven't, it adds some data for them.

    Code:
    Code:
    package me.mas.mageguilds.Join;
    
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import me.mas.mageguilds.MageGuilds;
    
    public class NewJoin implements Listener {
     
        private static MageGuilds Plugin;
     
        @EventHandler
        public void onJoin(PlayerJoinEvent e){
            Player p = (Player) e.getPlayer();
            if (Plugin.getConfig().contains("players." + p.getUniqueId())){
                return;
            }else{
                Plugin.getConfig().set("players." + p.getUniqueId() + ".played", true);
             
                //Class choosing stuff
            }
        }
    }
    
    Error:
    Code:
    [16:24:40 ERROR]: Could not pass event PlayerJoinEvent to MageGuilds v1.0.0
    org.bukkit.event.EventException
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:302) ~[craftbukkit.jar:git-Bukkit-18fbb24]
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[craftbukkit.jar:git-Bukkit-18fbb24]
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:501) [craftbukkit.jar:git-Bukkit-18fbb24]
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:486) [craftbukkit.jar:git-Bukkit-18fbb24]
            at net.minecraft.server.v1_8_R3.PlayerList.onPlayerJoin(PlayerList.java:282) [craftbukkit.jar:git-Bukkit-18fbb24]
            at net.minecraft.server.v1_8_R3.PlayerList.a(PlayerList.java:142) [craftbukkit.jar:git-Bukkit-18fbb24]
            at net.minecraft.server.v1_8_R3.LoginListener.b(LoginListener.java:115) [craftbukkit.jar:git-Bukkit-18fbb24]
            at net.minecraft.server.v1_8_R3.LoginListener.c(LoginListener.java:53) [craftbukkit.jar:git-Bukkit-18fbb24]
            at net.minecraft.server.v1_8_R3.NetworkManager.a(NetworkManager.java:222) [craftbukkit.jar:git-Bukkit-18fbb24]
            at net.minecraft.server.v1_8_R3.ServerConnection.c(SourceFile:168) [craftbukkit.jar:git-Bukkit-18fbb24]
            at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:745) [craftbukkit.jar:git-Bukkit-18fbb24]
            at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:335) [craftbukkit.jar:git-Bukkit-18fbb24]
            at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:629) [craftbukkit.jar:git-Bukkit-18fbb24]
            at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:537) [craftbukkit.jar:git-Bukkit-18fbb24]
            at java.lang.Thread.run(Unknown Source) [?:1.7.0_79]
    Caused by: java.lang.NullPointerException
            at me.mas.mageguilds.Join.NewJoin.onJoin(NewJoin.java:16) ~[?:?]
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_79]
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_79]
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_79]
            at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_79]
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:300) ~[craftbukkit.jar:git-Bukkit-18fbb24]
            ... 14 more
    
    Also, is there a way I can set the name of a player's enderchest? I looked at some tutorials made a while ago but none seemed to work :(


    Any help? Thanks :)
     
    Last edited: Jan 27, 2016
  2. Offline

    JoaoBM

  3. Offline

    ItsMas_

  4. Offline

    JoaoBM

    @ItsMas_ Try creating a constructor that passes the Main Plugin to this class instead of using static. Also can you post here your config?
     
  5. Offline

    WolfMage1


    your variable 'plugin' is null.

    also please follow naming conventions.
     
  6. Offline

    Zombie_Striker

    @ItsMas_
    Please don't abuse static; if you use static for move around an object instead of passing the instance through a constructor, you are being lazy.

    As has been said, plugin is null. Manually set it through a constructor.
     
  7. Offline

    ItsMas_

    Okay getting the same error

    Updated code:
    Code:
    package me.mas.mageguilds.Join;
    
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    
    import me.mas.mageguilds.MageGuilds;
    
    public class NewJoin implements Listener {
      
        private MageGuilds plugin;
      
        public NewJoin(MageGuilds plugin){
            this.plugin = plugin;
        }
      
        @EventHandler
        public void onJoin(PlayerJoinEvent e){
            Player p = (Player) e.getPlayer();
            if (plugin.getConfig().contains("players." + p.getUniqueId())){
                return;
            }else{
                plugin.getConfig().set("players." + p.getUniqueId() + ".played", true);
              
                //Class choosing stuff
            }
        }
    }
    
     
  8. Offline

    Zombie_Striker

    @ItsMas_
    {EDIT} You forgot to add "p.getUniqueID().toString()" What you are currently doing is printing out the memory space the UUID is taking up, not the actual UUID.
     
  9. Offline

    teej107

    What if I told that it doesn't make a difference? Appending Strings and other Objects together still call toString() on the Object.

    @ItsMas_ Post updated stacktrace
     
    dbaum102 and Zombie_Striker like this.
  10. Offline

    dbaum102

    try:
    Code:
    if(Plugin.getConfig.getString("players."+p.getUniqueId()!=null)return;
    if that doesnt work try what the others said:
    Code:
    if(Plugin.getConfig.getString("players."+p.getUniqueId().toString()!=null)return;
    ^Shouldnt be different then the first one though
     
  11. Offline

    ItsMas_

    Still doesn't work ;-;

    Error
    Code:
    [16:44:14 ERROR]: Could not pass event PlayerJoinEvent to MageGuilds v1.0.0
    org.bukkit.event.EventException
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:302) ~[craftbukkit.jar:git-Bukkit-18fbb24]
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[craftbukkit.jar:git-Bukkit-18fbb24]
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:501) [craftbukkit.jar:git-Bukkit-18fbb24]
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:486) [craftbukkit.jar:git-Bukkit-18fbb24]
            at net.minecraft.server.v1_8_R3.PlayerList.onPlayerJoin(PlayerList.java:282) [craftbukkit.jar:git-Bukkit-18fbb24]
            at net.minecraft.server.v1_8_R3.PlayerList.a(PlayerList.java:142) [craftbukkit.jar:git-Bukkit-18fbb24]
            at net.minecraft.server.v1_8_R3.LoginListener.b(LoginListener.java:115) [craftbukkit.jar:git-Bukkit-18fbb24]
            at net.minecraft.server.v1_8_R3.LoginListener.c(LoginListener.java:53) [craftbukkit.jar:git-Bukkit-18fbb24]
            at net.minecraft.server.v1_8_R3.NetworkManager.a(NetworkManager.java:222) [craftbukkit.jar:git-Bukkit-18fbb24]
            at net.minecraft.server.v1_8_R3.ServerConnection.c(SourceFile:168) [craftbukkit.jar:git-Bukkit-18fbb24]
            at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:745) [craftbukkit.jar:git-Bukkit-18fbb24]
            at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:335) [craftbukkit.jar:git-Bukkit-18fbb24]
            at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:629) [craftbukkit.jar:git-Bukkit-18fbb24]
            at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:537) [craftbukkit.jar:git-Bukkit-18fbb24]
            at java.lang.Thread.run(Unknown Source) [?:1.7.0_79]
    Caused by: java.lang.NullPointerException
            at me.mas.mageguilds.Join.NewJoin.onJoin(NewJoin.java:21) ~[?:?]
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_79]
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_79]
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.7.0_79]
            at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.7.0_79]
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:300) ~[craftbukkit.jar:git-Bukkit-18fbb24]
            ... 14 more
    
     
  12. Offline

    teej107

Thread Status:
Not open for further replies.

Share This Page