Solved Problem Registering Event Listener

Discussion in 'Plugin Development' started by Trtld, Jun 8, 2015.

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

    Trtld

    Hi, I'm new to the Bukkit API and have been having some problems while making a plugin that listens to player events. I apologize if I did something wrong while posting this thread, this is my first time posting on these forums.


    Here is my main class:
    Code:
    package com.trtld.FireBlocker;
    
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class FireBlocker extends JavaPlugin{
    public void onEnable(){
      
        getServer().getPluginManager().registerEvents(new Eventinator(), this);
      
        //this.getCommand("WW").setExecutor(new FBCommandExec(this));
        getLogger().info("Are YOU ready to be on \"fake fire?\"");
      
    }
    
    
    public void onDisable(){
        getLogger().info("No more \"fake fire\" today, folks!");
    }
    
    
    }
    
    The stack trace states that the error is at line 7 of the class, in the onEnable method where I use "getServer().getPluginManager().registerEvents(new Eventinator(), this);," as the Bukkit wiki tutorials says to.

    Stack trace details:
    "org.bukkit.plugin.IllegalPluginAccessException: Unable to find handler list for event org.Bukkit.event.player.PlayerEvent"
    "at com.trtld.FireBlocker.onEnable(FireBlocker.java:7) ~[? : ?]"

    Here is my Listener class:
    Listener (open)

    Code:
    package com.trtld.FireBlocker;
    
    import org.bukkit.ChatColor;
    import org.bukkit.Effect;
    import org.bukkit.Location;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerEvent;
    
    public class Eventinator implements Listener {
        @SuppressWarnings("deprecation")
        @EventHandler
        public void playerBlocking(PlayerEvent p){
            Player player = p.getPlayer();
          
          
            if(player.isBlocking()){
                Location loc = player.getLocation();
                player.sendMessage(ChatColor.RED + "" + ChatColor.BOLD + "This message never appears.");
                 player.playEffect(loc, Effect.MOBSPAWNER_FLAMES, null);
            }
        }
        



    What is wrong with the statement "getServer().getPluginManager().registerEvents(new Eventinator(), this);?"

    Also, I know that I am using a deprecated method for showing a particle effect on the player while he/she is blocking with a sword, but I couldn't get any alternatives to work.

    Thank you!
     
  2. Offline

    I Al Istannen

    Konato_K likes this.
  3. Offline

    Trtld

    @I Al Istannen Thanks.
    I used PlayerItemHeldEvent instead and I don't get that error in console anymore but nothing really happens in-game.
    It never reaches the point of playEffect(). (The message "ChatColor.RED + "" + ChatColor.BOLD + "This message never appears."" does not appear.)

    Was I right to use PlayerItemHeldEvent?
     
  4. Offline

    justin_393

    Use PlayerInteractEvent, check if the player is holding a sword, and check if it's a right click.
     
    Konato_K likes this.
  5. Offline

    Konato_K

    @Trtld I don't think there is "toggle block" event or related, so the best may be a PlayerInteractEvent I guess, but I don't think the player is block when the event is called (yet) since the event can be cancelled
     
  6. Offline

    Freelix2000

    @Trtld
    PlayerItemHeldEvent is used to detect when the player changes the item they're holding, so it wouldn't work for this event. I'm not sure how to do this best, but you may want to have a look at all the Player events to find another one for this.
     
  7. Offline

    Trtld

    @justin_393 How would I check if the player is clicking on, for example, Material.DIAMOND_SWORD? Or more specifically, how would I check if the player is holding right click on a diamond sword without using isBlocking()?

    After a bit more foolin' around on my test server I found that isBlocking() only works if you are right-clicking AND left-clicking with a sword ON a block (?!?!?).

    Thanks everyone!!!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 12, 2016
Thread Status:
Not open for further replies.

Share This Page