Plugin Help Bukkit Listener doesn't work

Discussion in 'Plugin Help/Development/Requests' started by haussik, Oct 25, 2014.

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


    package me.chargon.test;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.event.player.PlayerLoginEvent;
    import org.bukkit.inventory.ItemStack;
    public class test extends JavaPlugin implements Listener{
        public void onEnable(){
        public void onDisable(){
    -------> READ HERE
        public void onRightClick(PlayerInteractEvent event){
            Player player = event.getPlayer();
            Action a = event.getAction();
            if (a == Action.RIGHT_CLICK_AIR){
                System.out.println("Right click");
                if(player.getItemInHand().getType() == Material.COBBLESTONE){
                    System.out.println("Click w/ cobble");
                    player.getInventory().addItem(new ItemStack(Material.DIAMOND, 64));
    -------> TO HERE
        public boolean onCommand(CommandSender sender ,Command cmd, String CommandLabel, String[] args){
            if (cmd.getName().equalsIgnoreCase("test")){
                sender.sendMessage("Plugin is working");
            return true;   
    As You See, I have placed a System.out.println... under the if statement to see if everything working fine.
    There is no error in the console but it seems that the event is not taking place because I do not receives the text "Right click" from the System.out.println.

    Sorry for my poor english :p
  2. Offline

    timtower Administrator Administrator Moderator

  3. Offline


    You have to register the listener class, so Bukkit knows where to send events to.
    You register Listener classes in your onEnable by using:
    1. getServer().getPluginManager().registerEvents(this, this);
    2. // arguments 'this, this' is Listener class, and plugin instance. Which are the same for you now.
  4. Offline


    ok thanks Flamedek ! It's working now :3
Thread Status:
Not open for further replies.

Share This Page