Leavesdecayevent not working?

Discussion in 'Plugin Development' started by OneBillionAndOne, Dec 7, 2013.

Thread Status:
Not open for further replies.
  1. So, im making a plugin to control various aspects of your server, and ive run into a slight problem. Leavesdecayevent doesn't seem to be working. I don't know if im using an event that is to old to work, or what, but every time its called, its supposed to broadcast a test message (for developmental purposes obviously) but planting a tree, and ridding it of the logs, the leaves decay at the normal rate, even though its supposed to broadcast a message and then cancel it. (The event is registered in the main classes onEnable)
     
  2. Offline

    sgavster

    OneBillionAndOne Do you have @EventHandler on top of public void blahblahblah(eventname ect)..?
     
  3. Yes
     
  4. Offline

    SeniorQuack

    sgavster likes this.
  5. SeniorQuack
    Code:java
    1. package com.gmail.firework4lj.block;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.Material;
    5. import org.bukkit.block.Block;
    6. import org.bukkit.event.EventHandler;
    7. import org.bukkit.event.Listener;
    8. import org.bukkit.event.block.LeavesDecayEvent;
    9.  
    10. import com.gmail.firework4lj.Main;
    11.  
    12. public class Leavesdecay implements Listener{
    13.  
    14. private Main main;
    15.  
    16. public Leavesdecay(Main main) {
    17. this.main = main;
    18. }
    19.  
    20. @EventHandler
    21. public void onLeafDecay(LeavesDecayEvent e){
    22. Bukkit.broadcastMessage("Decayed!");
    23. final Block block = e.getBlock();
    24. e.setCancelled(true);
    25. int seconds = main.getConfig().getInt("leafdecayrate");
    26. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(main, new Runnable() {
    27. public void run() {
    28. block.setType(Material.AIR);
    29. }
    30. }, (seconds * 20));
    31. }
    32.  
    33. }
    34.  

    Theres the code for the event class. And you can take my word for it that its registered in onenable :p
     
  6. Offline

    sgavster

    OneBillionAndOne Try to change private Main main; to private final Main main;. :)
     
  7. Nope, didnt do it :(
    Heres the onenable method
    Code:java
    1. @Override
    2. public void onEnable(){
    3. File config = new File(getDataFolder()+File.separator+"config.yml");
    4. if (!config.exists()){
    5. this.getLogger().info("Generating config.yml...");
    6. this.getConfig().options().copyDefaults(true);
    7. this.saveDefaultConfig();
    8. }
    9. PluginManager pm = getServer().getPluginManager();
    10. pm.registerEvents(new Leavesdecay(this), this);
    11. enable();
    12. getLogger().info("======================");
    13. getLogger().info("ServerManager v0.1");
    14. getLogger().info("");
    15. getLogger().info("By: firework4lj");
    16. getLogger().info("");
    17. getLogger().info("Has been enabled");
    18. getLogger().info("======================");
    19. }
     
Thread Status:
Not open for further replies.

Share This Page