Could not pass event X to plugin

Discussion in 'Plugin Development' started by Zillo7, Feb 9, 2011.

  1. Offline

    Zillo7

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    I've nearly finished making my first plugin, but when I run it, I get
    Code:
    SEVERE: Could not pass event PLAYER_MOVE to Tiberium
    java.lang.NoSuchMethodError: org.bukkit.World.getLoadedChunks()[Lorg/bukkit/Chun
    k;
            at com.bukkit.Zillo7.Tiberium.Tiberium.GrowStuff(Tiberium.java:66)
            at com.bukkit.Zillo7.Tiberium.TiberiumPlayerListener.onPlayerMove(Tiberi
    umPlayerListener.java:41)
            at org.bukkit.plugin.java.JavaPluginLoader.callEvent(JavaPluginLoader.ja
    va:141)
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.j
    ava:201)...

    Here's the code I wrote(not all of it), what am I missing? I'm not sure! [IMG]

    Tiberium.java
    Code:
    public void onEnable() {
            PluginManager pm = getServer().getPluginManager();
            pm.registerEvent(Event.Type.PLAYER_MOVE, this.playerListener, Priority.Normal, this);
    }
    
    public void GrowStuff(org.bukkit.World word) {
            if (grow == false) {
                return;
            }
            org.bukkit.Chunk[] loaded = word.getLoadedChunks();
    
            for (int C = 0; C < loaded.length; C++) {
    
                for (int X = 0; X <= 15; X++) {
                    for (int Y = 0; Y <= 127; Y++) {
                        for (int Z = 0; Z <= 15; Z++) {
                            org.bukkit.block.Block blc = loaded[C].getBlock(X, Y, Z);
                            if (blc != null) {
                                GrowBlock(blc);
                            }
                        }
                    }
                }
            }
    
        }
    
        private void GrowBlock(org.bukkit.block.Block bl) {
            if (bl.getType() != org.bukkit.Material.DIAMOND_ORE) {
                return;
            }
    
            for (int X = -1; X <= 1; X++) {
                for (int Y = -1; Y <= 1; Y++) {
                    for (int Z = -1; Z <= 1; Z++) {
    
                        if (X == Y && Y == Z && X == 0) {
                            continue;
                        }
                        org.bukkit.block.Block nblc = bl.getRelative(X, Y, Z);
                        org.bukkit.Material m =nblc.getType();
                        if (m == org.bukkit.Material.DIAMOND_ORE
                                || m == org.bukkit.Material.AIR
                                || m == org.bukkit.Material.BEDROCK
                                || m == org.bukkit.Material.GLASS) {
                            continue;
                        }
                        nblc.setType(org.bukkit.Material.DIAMOND_ORE);
                    }
                }
            }
        }
    
    TiberiumPlayerListener.java
    Code:
    private final Tiberium plugin;
        private int ticksdone = 0;
        public org.bukkit.World worldref = null;
    
        public void onPlayerMove(PlayerMoveEvent event) {
            ticksdone++;
            if (ticksdone < 100) {
                return;
            }
            ticksdone = 0;
            Player play = event.getPlayer();
            if (play == null) {
                return;
            }
            if (worldref == null) {
                worldref = play.getWorld();
            }
            plugin.GrowStuff(worldref);
        }
  2. Offline

    Dinnerbone Bukkit Team Member Administrator

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    You're testing on a version different than you're compiling with. Update both bukkit and craftbukkit.
  3. Offline

    Tuna

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Hm well in the error it says that it cannot pass the Player_Move Event to Tiberium. in your onEnable function you have
    Code:
    pm.registerEvent(Event.Type.PLAYER_MOVE, this.playerListener, Priority.Normal, this);
    
    
    in which you are telling it to send the PLAYER_MOVE event to this.playerListener, but there is no variable named playerListener! Your TiberiumPlayerListener class also needs to extend PlayerListener. Once you do that your code for OnEnable() should be:
    Code:
    PluginManager pm = getServer().getPluginManager();
    
    
    Your TiberiumPlayerListener class should also have a default constructor that takes an instance of Tiberium as an argument.
  4. Offline

    Dinnerbone Bukkit Team Member Administrator

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Tuna, the constructor of a listener does not matter in the slightest, it's just easier to get the plugin back from that. It's clear that he/she missed out a lot of code such as the surrounding class, accounting for the missing variable. If it were that problem, it wouldn't register at all. Or even compile.
  5. Offline

    Tuna

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Sorry, formatting messed me up. Your OnEnable() should be

    PluginManager pm = getServer().getPluginManager();
    TiberiumPlayerListener playerListener = new TiberiumPlayerListener(this);
    pm.registerEvent(Event.Type.PLAYER_MOVE, this.playerListener, Priority.Normal, this);

    Then your TiberiumPlayerListener needs a default constructor that takes an instance object of Tiberium.
    --- merged: Feb 9, 2011 6:53 PM ---
    Ah i see... well disregard that then :p
  6. Offline

    Zillo7

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    I updated both. Now I'm getting
    Code:
    SEVERE: Could not pass event PLAYER_MOVE to Tiberium
    java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Lnet.minecr
    aft.server.Chunk;
            at org.bukkit.craftbukkit.CraftWorld.getLoadedChunks(CraftWorld.java:76)
    
            at com.bukkit.Zillo7.Tiberium.Tiberium.GrowStuff(Tiberium.java:66)
            at com.bukkit.Zillo7.Tiberium.TiberiumPlayerListener.onPlayerMove(Tiberi
    umPlayerListener.java:41)
            at org.bukkit.plugin.java.JavaPluginLoader$7.execute(JavaPluginLoader.ja
    va:154)
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.jav
    a:60)
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.j
    ava:214)
    The update also broke another plugin, essentials. I updated that too, and only some commands work.
    --- merged: Feb 9, 2011 7:05 PM ---
    I've only posted some of the code, as to not make a huge post. The playerlistener is created when the variable is initialized, and it does have the constructor take the plugin class as a parameter.
  7. Offline

    Dinnerbone Bukkit Team Member Administrator

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Okay, internal bug, will fix it shortly.
    --- merged: Feb 9, 2011 8:07 PM ---
    Please update craftbukkit and try it now.
  8. Offline

    Zillo7

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Still doesn't work

    Code:
    SEVERE: Could not pass event PLAYER_MOVE to Tiberium
    java.lang.ClassCastException: net.minecraft.server.LongHashtable$Entry cannot be
     cast to net.minecraft.server.Chunk
            at org.bukkit.craftbukkit.CraftWorld.getLoadedChunks(CraftWorld.java:80)
    
            at com.bukkit.Zillo7.Tiberium.Tiberium.GrowStuff(Tiberium.java:63)
            at com.bukkit.Zillo7.Tiberium.TiberiumPlayerListener.onPlayerMove(Tiberi
    umPlayerListener.java:40)
            at org.bukkit.plugin.java.JavaPluginLoader$7.execute(JavaPluginLoader.ja
    va:154)
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.jav
    a:60)
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.j
    ava:214)
    It's gotta be something with my code, most of the other plugins I'm using still work. I've attached all the code, in case it helps.
  9. Offline

    Dinnerbone Bukkit Team Member Administrator

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    ... Fixed again! Try it now. Sorry about that!
  10. Offline

    Zillo7

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    No more errors! [IMG]
    Now I just need to work on my code some more. Thanks!
  11. Offline

    GarretSidzaka

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    UM this isnt fixed by a long shot boss
  12. Offline

    Dinnerbone Bukkit Team Member Administrator

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Totally was dude, 4 months ago.
    Banana937 likes this.

Share This Page