[Solved] Help me with new event system

Discussion in 'Plugin Development' started by darker9999, May 21, 2012.

Thread Status:
Not open for further replies.
  1. Hello, i'm still here. Dunno how to work with new event system.

    Main class:
    Code:java
    1. package me.darker9999.DarkLight;
    2.  
    3. import org.bukkit.plugin.PluginManager;
    4. import org.bukkit.plugin.java.JavaPlugin;
    5.  
    6. public class Main extends JavaPlugin{
    7.  
    8. public final BL Listener = new BL();
    9.  
    10. @Override
    11. public void onDisable(){
    12. System.out.println(" DarkLight is Disabled!");
    13. }
    14.  
    15. @Override
    16. public void onEnable(){
    17. PluginManager pm = getServer().getPluginManager();
    18. pm.registerEvents(this.Listener, this);
    19. System.out.println(" DarkLight is Enabled!");
    20. }
    21.  
    22. }


    BL (block listener) class:
    Code:java
    1.  
    2. package me.darker9999.DarkLight;
    3.  
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.event.EventHandler;
    6. import org.bukkit.event.Listener;
    7. import org.bukkit.event.block.BlockBreakEvent;
    8.  
    9. public class BL implements Listener{
    10.  
    11. @EventHandler
    12. public void StopBreakBlock(BlockBreakEvent event){
    13. event.setCancelled(true);
    14. event.getPlayer().sendMessage(ChatColor.RED + "This server is protected from breaking blocks!");
    15. }
    16. }
    17.  


    I want to make that no one could destroy blocks. Tried many ways, maybe someone can show me an example of a simple plugin like that ?
     
  2. Offline

    Njol

    I can't see any problems with your code. Does the plugin actually get loaded?
     
  3. Yeah, console shows that its loaded. But i can break anything in server.
     
  4. Offline

    Njol

    Do you get the message "This server is protected from breaking blocks!" or does simply nothing happen at all?
     
  5. It simply does nothing.
     
  6. Offline

    Njol

    Are you sure this is the code you're running on the server (i.e. did you export it as jar before testing)? Export and test it again, maybe it'll solve itself ;).
     
  7. Everything is ok there.
    Its not working with what are you talking about.
     
  8. Offline

    nisovin

    What in the world are you talking about? The class is BL and the variable name is Listener, it should work fine as is.
     
  9. Offline

    jtjj222

    ok, my guess is gone then... :D
    I didn't see the variable declaration.
     
  10. Any more help ?

    Bummmp

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 25, 2016
  11. Offline

    heisan213

    Well... You could print a debug line in the constructor for BL.

    Code:java/
    1.  
    2. public BL(){
    3. System.out.println("Heisan was wrong.");
    4. }
    5.  

    If the message shows up in console, I don't know what's wrong.

    Randomness from my brain:
    Try adding (ignoreCancelled = false) to @EventHandler?

    Is it nessercairy to have the Listener variable final?

    Make the Listener variable static and initialize it in onEnable()?
     
  12. Offline

    jtjj222

    It has been solved by directly referencing the class in the event registration :D
     
Thread Status:
Not open for further replies.

Share This Page