OH MY GOD MASSIVE ERROR! (NEW PROBLEM!)

Discussion in 'Plugin Development' started by Jnorr44, Jun 22, 2012.

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

    Jnorr44

    But it had something to do with calling the event BFTE I think, because I kept seeing .callevent
    Any ideas? I have my main class and my event class below

    Main:
    Code:
    //-----------------------------
    //FLOW MAIN CLASS
    //FOR: BUKKIT PLUGIN - "FLOW"
    //CREATOR: JAMESNORRIS
    //-----------------------------
     
    package com.github.JamesNorris.Flow;
     
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.plugin.java.JavaPlugin;
     
    import java.io.File;
    import java.util.logging.Logger;
     
    public class Flow extends JavaPlugin implements CommandExecutor {
        private FixCommand flowFixExecutor;
        private FlowCommand flowExecutor;
        private ConfigCommands configExecutor;
        private File config;
        private static Logger log = Logger.getLogger("Minecraft");
        int configVersion = 0;
        int configVersionNumber = 3; //TODO add 1 every time there's an update to the config!
        String version = "v1.1.2"; //TODO set this every time there's an update! ex. vX.X.X
        @Override
        public void onEnable(){
            getServer().getPluginManager().registerEvents(new StreamPreventer(), this);
            this.getConfig().set("configVersion", configVersionNumber);
            if(config == null || configVersion != configVersionNumber){
                config = new File(getDataFolder(), "config.yml");
                log.info("Loading config.yml...");
                this.getConfig().set("version", version);
                getConfig().options().copyDefaults(true);
                this.getConfig().addDefault("enabled", true);
                this.getConfig().addDefault("enableLava", true);
                this.getConfig().addDefault("enableWater", true);
                this.getConfig().addDefault("fixBelow", true);
            } 
            if(getConfig().getBoolean("enabled") == false){
                log.warning("Flow has been disabled in the config! Check the config.yml to change this!");
                this.setEnabled(false);
            }
            flowFixExecutor = new FixCommand(this);
            getCommand("flowfix").setExecutor(flowFixExecutor);
            flowExecutor = new FlowCommand(this);
            getCommand("flow").setExecutor(flowExecutor);
            configExecutor = new ConfigCommands(this);
            getCommand("flowset").setExecutor(configExecutor);
        }
        public void onDisable(){
            log.info("Flow has been disabled.");
            this.saveConfig();
        }
    }
    Event:
    Code:
    package com.github.JamesNorris.Flow;
     
    import org.bukkit.Bukkit;
    import org.bukkit.Material;
    import org.bukkit.World;
    import org.bukkit.block.Block;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.EventPriority;
    import org.bukkit.event.HandlerList;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.BlockFromToEvent;
     
    public class StreamPreventer implements Listener {
        private static final HandlerList handlers = new HandlerList();
     
        private Flow plugin;
        @EventHandler(priority = EventPriority.HIGHEST)
        public void BFTE(BlockFromToEvent event){
            Bukkit.getServer().getPluginManager().callEvent(event);
            plugin.getServer().getPluginManager().registerEvents(this, plugin);
            final World world = ((Block) event).getWorld();
            for (int x = -1; x < 2; x++) {
                for (int y = -1; y < 2; y++) {
                    for (int z = -1; z < 2; z++) {
                        Block stream = world.getBlockAt(x,y,z);
                        if (stream.getRelative(x, y, z).getTypeId() == 9 || stream.getRelative(x, y, z).getTypeId() == 11) {
                            if(plugin.getConfig().getBoolean("enableWater")) {
                                if (stream.getTypeId() == 9) {
                                    stream.setType(Material.STATIONARY_WATER);
                                }
                            }
                            if(plugin.getConfig().getBoolean("enableLava")) {
                                if (stream.getTypeId() == 11) {
                                    stream.setType(Material.STATIONARY_LAVA);
                                }
                            }
                        }
                    }
                }
            }
        }
        public HandlerList getHandlers() {
            return handlers;
        }
     
        public static HandlerList getHandlerList() {
            return handlers;
        }
    }
     
  2. Offline

    Firefly

    We'd really need the stack trace to help you with anything. Check server.log and see if you can post it.
     
  3. read the stacktrace by yourself?
     
    Firefly likes this.
  4. Offline

    Jnorr44

    Im trying to open it, but its 49,000KB, so its taking a while

    ferrybig
    Firefly
    Ok, so Its a looping error, and the stacktrace that keeps appearing is this:
    Code:
    2012-06-22 12:43:10 [SEVERE] Could not pass event BlockFromToEvent to Flow
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:304)
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62)
        at org.bukkit.plugin.TimedRegisteredListener.callEvent(TimedRegisteredListener.java:30)
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:460)
        at net.minecraft.server.BlockFlowing.a(BlockFlowing.java:144)
        at net.minecraft.server.World.l(World.java:2040)
        at net.minecraft.server.World.doTick(World.java:1757)
        at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:554)
        at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:459)
        at net.minecraft.server.ThreadServerApplication.run(SourceFile:492)
    Caused by: java.lang.NullPointerException
        at com.github.JamesNorris.Flow.StreamPreventer.BFTE(StreamPreventer.java:16)
        at sun.reflect.GeneratedMethodAccessor55.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:302)
        ... 9 more
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 26, 2016
  5. Offline

    Firefly

    What's on line 16 of your BTFE method?
     
  6. Offline

    Jnorr44

    private Flow plugin;
     
  7. Offline

    Firefly

    Are you sure? The Stack Trace points to the BTFE method in the StreamPreventer class.
     
  8. Offline

    Jnorr44

    yeah, im looking at it now. that variable shouldnt make an error, thats what I don't understand

    I posted the entire class... its the event class at the first post
     
  9. Offline

    Firefly

    As I said, the Stack Trace points to the BTFE method. You gave me the line outside of that. So either you are looking at updated code from when you got this Stack Trace or you aren't looking at the right line 16 in Eclipse.
     
  10. Offline

    Jnorr44

    Code:
    package com.github.JamesNorris.Flow;
     
    import org.bukkit.Bukkit;
    import org.bukkit.Material;
    import org.bukkit.World;
    import org.bukkit.block.Block;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.EventPriority;
    import org.bukkit.event.HandlerList;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.BlockFromToEvent;
     
    public class StreamPreventer implements Listener {
        private static final HandlerList handlers = new HandlerList();
     
        private Flow plugin;//line 16 --------------------------------------------------------------------------------------
        @EventHandler(priority = EventPriority.HIGHEST)
        public void BFTE(BlockFromToEvent event){
            Bukkit.getServer().getPluginManager().callEvent(event);
            plugin.getServer().getPluginManager().registerEvents(this, plugin);
            final World world = ((Block) event).getWorld();
            for (int x = -1; x < 2; x++) {
                for (int y = -1; y < 2; y++) {
                    for (int z = -1; z < 2; z++) {
                        Block stream = world.getBlockAt(x,y,z);
                        if (stream.getRelative(x, y, z).getTypeId() == 9 || stream.getRelative(x, y, z).getTypeId() == 11) {
                            if(plugin.getConfig().getBoolean("enableWater")) {
                                if (stream.getTypeId() == 9) {
                                    stream.setType(Material.STATIONARY_WATER);
                                }
                            }
                            if(plugin.getConfig().getBoolean("enableLava")) {
                                if (stream.getTypeId() == 11) {
                                    stream.setType(Material.STATIONARY_LAVA);
                                }
                            }
                        }
                    }
                }
            }
        }
        public HandlerList getHandlers() {
            return handlers;
        }
     
        public static HandlerList getHandlerList() {
            return handlers;
        }
    }
    I am pretty sure its calling the event though, because I had no errors before.

    EDIT: It only happens when the source should generate a stream

    EX: I placed lava, and it didn't form a stream, insted it started that error loop
     
  11. Offline

    Firefly

    Jnorr44

    Have you added any code to this class since your first saw the Stack Trace? If so post the latest Stack Trace that appears with this code you have posted.
     
  12. Offline

    Jnorr44

    No, I didn't add any code, and I just tried it again with the same code your seeing, it still gets a stacktrace. Before that I just called the event, and tried it, that was what got this error, so it has to be in BFTE
     
  13. Offline

    nisovin

    Your 'plugin' variable is null. This is a problem.
     
  14. Offline

    Jnorr44

    Should I delete that variable, or add a getter and setter?
     
  15. Offline

    Firefly

    If I'm not mistaken, you need to initialize the variable.

    Code:
     plugin = ... 
     
  16. Offline

    Jnorr44

    yeah i started it up and got this:
    Code:
    [SEVERE] Could not pass event BlockFromToEvent to Flow
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306)
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62)
        at org.bukkit.plugin.TimedRegisteredListener.callEvent(TimedRegisteredListener.java:30)
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:460)
        at com.github.JamesNorris.Flow.StreamPreventer.BFTE(StreamPreventer.java:30)
        at sun.reflect.GeneratedMethodAccessor5.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
    after putting this into the same class as BFTE:
    Code:
        private Flow plugin;
        public StreamPreventer(Flow instance) {
            plugin = instance;
            this.setPlugin(plugin);
        }
        public Flow getPlugin() {
            return plugin;
        }
        public void setPlugin(Flow plugin) {
            this.plugin = plugin;
        }
    LINE 30 = Bukkit.getServer().getPluginManager().callEvent(event);
     
  17. Offline

    Firefly

    What's on line 30 of your StreamPreventer class?
     
  18. Offline

    Jnorr44

  19. Offline

    Firefly

    Why are you calling the event?

    [EDIT]

    Oh, I see the problem. You need to register events when you enable the plugin.

    Code:
    plugin.getServer().getPluginManager().registerEvents(this, plugin);
    That should go in your onEnable, not in your Event method.
     
  20. Offline

    Jnorr44

    The event wouldnt work?
     
  21. Offline

    Firefly

    See my edit above.
     
  22. Offline

    Jnorr44

    Tried that and got an error under registerEvents()
    EDIT: wait nevermind, just had to implement listener
     
  23. Offline

    Firefly

    Error in Eclipse or Stack Trace?

    [EDIT]

    getServer().getPluginManager().registerEvents(new StreamPreventer(), this);
     
  24. Offline

    Jnorr44

    ^ Fixed it, running the server

    Ok, its no longer looping, but line 28 of flow is the exact line you just gave me, its getting this stacktrace, and the event isn't working.

    Code:
    [SEVERE] Error occurred while enabling Flow v1.1.2 (Is it up to date?)
    java.lang.NullPointerException
        at com.github.JamesNorris.Flow.Flow.onEnable(Flow.java:28)
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:215)
        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:337)
        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:381)
        at org.bukkit.craftbukkit.CraftServer.loadPlugin(CraftServer.java:256)
        at org.bukkit.craftbukkit.CraftServer.enablePlugins(CraftServer.java:238)
        at net.minecraft.server.MinecraftServer.t(MinecraftServer.java:381)
        at net.minecraft.server.MinecraftServer.a(MinecraftServer.java:368)
        at net.minecraft.server.MinecraftServer.init(MinecraftServer.java:197)
        at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:432)
        at net.minecraft.server.ThreadServerApplication.run(SourceFile:492)
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Sep 6, 2018
  25. Offline

    Firefly

    Sweet, nevermind my edit then :p

    Try this on your onEnable instead.

    Code:
    getServer().getPluginManager().registerEvents(new StreamPreventer(), this);
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Sep 6, 2018
  26. Offline

    Jnorr44

    New stacktrace.. HAHA sorry about this, ill be sure to put a thanks to: firefly on my plugin page.

    Code:
    2012-06-22 13:50:33 [SEVERE] Could not pass event BlockFromToEvent to Flow
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:304)
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62)
        at org.bukkit.plugin.TimedRegisteredListener.callEvent(TimedRegisteredListener.java:30)
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:460)
        at net.minecraft.server.BlockFlowing.a(BlockFlowing.java:144)
        at net.minecraft.server.World.a(World.java:2407)
        at net.minecraft.server.World.doTick(World.java:1755)
        at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:554)
        at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:459)
        at net.minecraft.server.ThreadServerApplication.run(SourceFile:492)
    Caused by: java.lang.NullPointerException
        at com.github.JamesNorris.Flow.StreamPreventer.BFTE(StreamPreventer.java:29)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:302)
        ... 9 more
     
  27. Offline

    Firefly

    Line 29?
     
  28. Offline

    Jnorr44

    I figured out it was the same line you gave me earlier, I removed it, but them got ANOTHER stacktrace, this one only occurs during the event.


    Code:
    2012-06-22 13:55:35 [SEVERE] Could not pass event BlockFromToEvent to Flow
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:304)
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62)
        at org.bukkit.plugin.TimedRegisteredListener.callEvent(TimedRegisteredListener.java:30)
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:460)
        at net.minecraft.server.BlockFlowing.a(BlockFlowing.java:144)
        at net.minecraft.server.World.a(World.java:2407)
        at net.minecraft.server.World.doTick(World.java:1755)
        at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:554)
        at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:459)
        at net.minecraft.server.ThreadServerApplication.run(SourceFile:492)
    Caused by: java.lang.ClassCastException: org.bukkit.event.block.BlockFromToEvent cannot be cast to org.bukkit.block.Block
        at com.github.JamesNorris.Flow.StreamPreventer.BFTE(StreamPreventer.java:29)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:302)
        ... 9 more
    Heres 29:

    final World world = ((Block) event).getWorld();
     
  29. Offline

    Firefly

    Wait. Why are you casting the event to a block?
     
  30. Offline

    Jnorr44

    I had to get the world in which the block is. Im trying to change stream blocks into source blocks, if they have 2 sources next to them.
     
Thread Status:
Not open for further replies.

Share This Page