Development Assistance Listeners dont work

Discussion in 'Plugin Help/Development/Requests' started by thomashomsy, Oct 6, 2014.

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

    thomashomsy

    Hi Guys,

    Because im such a noob and dont know how to code that well im trying to make a basic KitPvP Plugin but atm im trying to get some listeners to work, heres the code, can anyone please help? and tell me what i will need to add to my Main/ an other class

    Code:
    package me.thomashomsy.Listeners;
     
    import org.bukkit.GameMode;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.BlockBreakEvent;
    import org.bukkit.event.block.BlockPlaceEvent;
    import org.bukkit.event.entity.FoodLevelChangeEvent;
     
     
    public class Listeners implements Listener {
     
       
     
            @EventHandler
            public void onFoodChange(FoodLevelChangeEvent e) {
                    e.setCancelled(true);
            }
       
        @EventHandler
        public void onBreak(BlockBreakEvent e) {
            if (e.getPlayer().getGameMode() == GameMode.CREATIVE && e.getPlayer().hasPermission("kitpvp.build")) {
                e.setCancelled(false);
            }
            else {
                e.setCancelled(true);
            }
        }
        @EventHandler
        public void onPlace(BlockPlaceEvent e) {
            if (e.getPlayer().getGameMode() == GameMode.CREATIVE && e.getPlayer().hasPermission("kitpvp.build")) {
                e.setCancelled(false);
            }
            else {
                e.setCancelled(true);
            }
        }
    }
    
    Thank You

    -Thomas
     
  2. Offline

    Lolmewn Retired Staff

    Did you... register them?
     
  3. Offline

    acer5999

    Assuming you have multiple classes seeing as you didn't extend JavaPlugin, here is a good tutorial on how to register listeners from other classes: https://forums.bukkit.org/threads/tutorial-using-multiple-classes.179833/
    If, for some crazy reason this is your only class, change
    Code:java
    1. public class Listeners implements Listener

    to
    Code:java
    1. public class Listeners extends JavaPlugin implements Listener

    and add an onEnable that goes something like this:
    Code:java
    1. public void onEnable() {
    2. PluginManager pm = getServer().getPluginManager();
    3. pm.registerEvents(this, this);
    4. }

    Cheers :)
     
Thread Status:
Not open for further replies.

Share This Page