Could not pass event X to plugin

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

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

    Zillo7

    I've nearly finished making my first plugin, but when I run it, I get
    Code (Text):
    1. SEVERE: Could not pass event PLAYER_MOVE to Tiberium
    2. java.lang.NoSuchMethodError: org.bukkit.World.getLoadedChunks()[Lorg/bukkit/Chun
    3. k;
    4.         at com.bukkit.Zillo7.Tiberium.Tiberium.GrowStuff(Tiberium.java:66)
    5.         at com.bukkit.Zillo7.Tiberium.TiberiumPlayerListener.onPlayerMove(Tiberi
    6. umPlayerListener.java:41)
    7.         at org.bukkit.plugin.java.JavaPluginLoader.callEvent(JavaPluginLoader.ja
    8. va:141)
    9.         at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.j
    10. ava:201)...

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

    Tiberium.java
    Code (Text):
    1. public void onEnable() {
    2.         PluginManager pm = getServer().getPluginManager();
    3.         pm.registerEvent(Event.Type.PLAYER_MOVE, this.playerListener, Priority.Normal, this);
    4. }
    5.  
    6. public void GrowStuff(org.bukkit.World word) {
    7.         if (grow == false) {
    8.             return;
    9.         }
    10.         org.bukkit.Chunk[] loaded = word.getLoadedChunks();
    11.  
    12.         for (int C = 0; C < loaded.length; C++) {
    13.  
    14.             for (int X = 0; X <= 15; X++) {
    15.                 for (int Y = 0; Y <= 127; Y++) {
    16.                     for (int Z = 0; Z <= 15; Z++) {
    17.                         org.bukkit.block.Block blc = loaded[C].getBlock(X, Y, Z);
    18.                         if (blc != null) {
    19.                             GrowBlock(blc);
    20.                         }
    21.                     }
    22.                 }
    23.             }
    24.         }
    25.  
    26.     }
    27.  
    28.     private void GrowBlock(org.bukkit.block.Block bl) {
    29.         if (bl.getType() != org.bukkit.Material.DIAMOND_ORE) {
    30.             return;
    31.         }
    32.  
    33.         for (int X = -1; X <= 1; X++) {
    34.             for (int Y = -1; Y <= 1; Y++) {
    35.                 for (int Z = -1; Z <= 1; Z++) {
    36.  
    37.                     if (X == Y && Y == Z && X == 0) {
    38.                         continue;
    39.                     }
    40.                     org.bukkit.block.Block nblc = bl.getRelative(X, Y, Z);
    41.                     org.bukkit.Material m =nblc.getType();
    42.                     if (m == org.bukkit.Material.DIAMOND_ORE
    43.                             || m == org.bukkit.Material.AIR
    44.                             || m == org.bukkit.Material.BEDROCK
    45.                             || m == org.bukkit.Material.GLASS) {
    46.                         continue;
    47.                     }
    48.                     nblc.setType(org.bukkit.Material.DIAMOND_ORE);
    49.                 }
    50.             }
    51.         }
    52.     }
    53.  
    TiberiumPlayerListener.java
    Code (Text):
    1. private final Tiberium plugin;
    2.     private int ticksdone = 0;
    3.     public org.bukkit.World worldref = null;
    4.  
    5.     public void onPlayerMove(PlayerMoveEvent event) {
    6.         ticksdone++;
    7.         if (ticksdone < 100) {
    8.             return;
    9.         }
    10.         ticksdone = 0;
    11.         Player play = event.getPlayer();
    12.         if (play == null) {
    13.             return;
    14.         }
    15.         if (worldref == null) {
    16.             worldref = play.getWorld();
    17.         }
    18.         plugin.GrowStuff(worldref);
    19.     }
     
  2. Offline

    Dinnerbone Bukkit Team Member Administrator

    You're testing on a version different than you're compiling with. Update both bukkit and craftbukkit.
     
  3. Offline

    Tuna

    Hm well in the error it says that it cannot pass the Player_Move Event to Tiberium. in your onEnable function you have
    Code (Text):
    1. pm.registerEvent(Event.Type.PLAYER_MOVE, this.playerListener, Priority.Normal, this);
    2.  
    3.  
    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 (Text):
    1. PluginManager pm = getServer().getPluginManager();
    2.  
    3.  
    4. 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

    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

    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

    I updated both. Now I'm getting
    Code (Text):
    1. SEVERE: Could not pass event PLAYER_MOVE to Tiberium
    2. java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Lnet.minecr
    3. aft.server.Chunk;
    4.         at org.bukkit.craftbukkit.CraftWorld.getLoadedChunks(CraftWorld.java:76)
    5.  
    6.         at com.bukkit.Zillo7.Tiberium.Tiberium.GrowStuff(Tiberium.java:66)
    7.         at com.bukkit.Zillo7.Tiberium.TiberiumPlayerListener.onPlayerMove(Tiberi
    8. umPlayerListener.java:41)
    9.         at org.bukkit.plugin.java.JavaPluginLoader$7.execute(JavaPluginLoader.ja
    10. va:154)
    11.         at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.jav
    12. a:60)
    13.         at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.j
    14. 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

    Okay, internal bug, will fix it shortly.
    --- merged: Feb 9, 2011 8:07 PM ---
    Please update craftbukkit and try it now.
     
  8. Offline

    Zillo7

    Still doesn't work

    Code (Text):
    1. SEVERE: Could not pass event PLAYER_MOVE to Tiberium
    2. java.lang.ClassCastException: net.minecraft.server.LongHashtable$Entry cannot be
    3.  cast to net.minecraft.server.Chunk
    4.         at org.bukkit.craftbukkit.CraftWorld.getLoadedChunks(CraftWorld.java:80)
    5.  
    6.         at com.bukkit.Zillo7.Tiberium.Tiberium.GrowStuff(Tiberium.java:63)
    7.         at com.bukkit.Zillo7.Tiberium.TiberiumPlayerListener.onPlayerMove(Tiberi
    8. umPlayerListener.java:40)
    9.         at org.bukkit.plugin.java.JavaPluginLoader$7.execute(JavaPluginLoader.ja
    10. va:154)
    11.         at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.jav
    12. a:60)
    13.         at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.j
    14. 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.
     

    Attached Files:

  9. Offline

    Dinnerbone Bukkit Team Member Administrator

    ... Fixed again! Try it now. Sorry about that!
     
  10. Offline

    Zillo7

    No more errors! [​IMG]
    Now I just need to work on my code some more. Thanks!
     
  11. Offline

    GarretSidzaka

    UM this isnt fixed by a long shot boss
     
  12. Offline

    Dinnerbone Bukkit Team Member Administrator

    Totally was dude, 4 months ago.
     
    Banana937 likes this.
Thread Status:
Not open for further replies.

Share This Page