Strange Error config

Discussion in 'Spigot Plugin Development' started by Froyzz, May 27, 2016.

  1. Hi guys,
    I'm trying to take a number in the config with:
    Code (Text):
                long aa = this.pl.getConfig().getLong("Time");
                Bukkit.broadcastMessage(""+ aa +"");
    it's a test, but it didn't works, it makes me error :
    Code (Text):
    Could not pass event EntityDeathEvent to HerobrineAddon v1.0
    org.bukkit.event.EventException
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:310) ~[spigot-1.9.2.jar:git-Spigot-944aa20-420b983]
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot-1.9.2.jar:git-Spigot-944aa20-420b983]
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:502) [spigot-1.9.2.jar:git-Spigot-944aa20-420b983]
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:487) [spigot-1.9.2.jar:git-Spigot-944aa20-420b983]
            at org.bukkit.craftbukkit.v1_9_R1.event.CraftEventFactory.callEntityDeathEvent(CraftEventFactory.java:391) [spigot-1.9.2.jar:git-Spigot-944aa20-420b983]
            at net.minecraft.server.v1_9_R1.EntityLiving.die(EntityLiving.java:983) [spigot-1.9.2.jar:git-Spigot-944aa20-420b983]
            at net.minecraft.server.v1_9_R1.EntityZombie.die(EntityZombie.java:549) [spigot-1.9.2.jar:git-Spigot-944aa20-420b983]
            at net.minecraft.server.v1_9_R1.EntityLiving.damageEntity(EntityLiving.java:900) [spigot-1.9.2.jar:git-Spigot-944aa20-420b983]
            at net.minecraft.server.v1_9_R1.EntityMonster.damageEntity(EntityMonster.java:44) [spigot-1.9.2.jar:git-Spigot-944aa20-420b983]
            at net.minecraft.server.v1_9_R1.EntityZombie.damageEntity(EntityZombie.java:179) [spigot-1.9.2.jar:git-Spigot-944aa20-420b983]
            at net.minecraft.server.v1_9_R1.EntityPigZombie.damageEntity(SourceFile:148) [spigot-1.9.2.jar:git-Spigot-944aa20-420b983]
            at net.minecraft.server.v1_9_R1.EntityHuman.attack(EntityHuman.java:999) [spigot-1.9.2.jar:git-Spigot-944aa20-420b983]
            at net.minecraft.server.v1_9_R1.EntityPlayer.attack(EntityPlayer.java:1129) [spigot-1.9.2.jar:git-Spigot-944aa20-420b983]
            at net.minecraft.server.v1_9_R1.PlayerConnection.a(PlayerConnection.java:1577) [spigot-1.9.2.jar:git-Spigot-944aa20-420b983]
            at net.minecraft.server.v1_9_R1.PacketPlayInUseEntity.a(SourceFile:68) [spigot-1.9.2.jar:git-Spigot-944aa20-420b983]
            at net.minecraft.server.v1_9_R1.PacketPlayInUseEntity.a(SourceFile:12) [spigot-1.9.2.jar:git-Spigot-944aa20-420b983]
            at net.minecraft.server.v1_9_R1.PlayerConnectionUtils$1.run(SourceFile:13) [spigot-1.9.2.jar:git-Spigot-944aa20-420b983]
            at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_66]
            at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_66]
            at net.minecraft.server.v1_9_R1.SystemUtils.a(SourceFile:45) [spigot-1.9.2.jar:git-Spigot-944aa20-420b983]
            at net.minecraft.server.v1_9_R1.MinecraftServer.D(MinecraftServer.java:721) [spigot-1.9.2.jar:git-Spigot-944aa20-420b983]
            at net.minecraft.server.v1_9_R1.DedicatedServer.D(DedicatedServer.java:400) [spigot-1.9.2.jar:git-Spigot-944aa20-420b983]
            at net.minecraft.server.v1_9_R1.MinecraftServer.C(MinecraftServer.java:660) [spigot-1.9.2.jar:git-Spigot-944aa20-420b983]
            at net.minecraft.server.v1_9_R1.MinecraftServer.run(MinecraftServer.java:559) [spigot-1.9.2.jar:git-Spigot-944aa20-420b983]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_66]
    Caused by: java.lang.NullPointerException
            at fr.froyz.NpcHeroInfo.Main.onMort(Main.java:54) ~[?:?]
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_66]
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_66]
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_66]
            at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_66]
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[spigot-1.9.2.jar:git-Spigot-944aa20-420b983]
            ... 24 more
    Can you explain me please
    My config file:
    Code (Text):
    Valeur: false
    Time: 0
    TempsHero: 1464386295175
    My config code:
    Code (Text):
    public class Config {
       
        public static File Configfile = new File("plugins/NpcHeroInfo","Config.yml");
        public static FileConfiguration Config = YamlConfiguration.loadConfiguration(Configfile);
       
        public static void save() throws IOException{
            Config.save(Configfile);
        }

        public static void setValeur(Boolean valeur) throws IOException{
            Config.set("Valeur", valeur);
            save();
        }
       
        public static void setTime(long nombre) throws IOException{
            Config.set("Time", nombre);
            save();
        }
       
        public static void setTimeHero(long nombre) throws IOException{
            Config.set("TempsHero", nombre);
            save();
        }

        public static boolean getValeur() {
            return Config.getBoolean("Valeur");
     
  2. Inkzzz

    Resource Staff

    What's on line Main, 54?
     
  3. 54:
    Code (Text):
    long number = this.pl.getConfig().getLong("Time");
     
  4. Inkzzz

    Resource Staff

    Check if variable, 'pl' is actually set to a value as I presume it is currently null.
     
  5. Code (Text):
        public Main pl;
    it's wrong ?
     
  6. Inkzzz

    Resource Staff

    Do you initiate / set the value of it?
     
  7. Code (Text):
    package fr.froyz.NpcHeroInfo;

    import java.io.IOException;
    import java.util.Random;
    import java.util.logging.Logger;

    import org.bukkit.Bukkit;
    import org.bukkit.entity.Entity;
    import org.bukkit.entity.EntityType;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.EntityDeathEvent;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;

    public class Main extends JavaPlugin implements Listener {
       
        public Main pl;
        public final Logger logger = Logger.getLogger("Minecraft");
           
        public void onEnable(){
                   
        Bukkit.getPluginManager().registerEvents(this, this);
        PluginManager pm = getServer().getPluginManager();
        pm.registerEvents(new Events(this), this);
        try {
            Config.save();
    } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
    }
    }
        public void onDisable(){
            System.out.println("Test ondisable");
            if(Bukkit.getServer().getScheduler().isCurrentlyRunning(task)){
                System.out.println("Success (nextdisable)");
                long i = System.currentTimeMillis();
                try {
                    Config.setTime(i);
                    Config.save();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
        }
            }  

            }
        public int task;
        long number = 0;
        @EventHandler
        public void onMort(final EntityDeathEvent event) throws IOException{
            Entity p = event.getEntity();
            if (p.getType() == EntityType.PIG_ZOMBIE){
                long number = pl.getConfig().getLong("Time");
                Bukkit.broadcastMessage(""+ number +"");
     
  8. It's very strange, i don't understand why..
     
  9. In the onEnable add:
    pl = this;
     
  10. You pl is null since you haven't pass anything into it yet
     
  11. thank you so much, that works !