PlayerInteractEvent

Discussion in 'Plugin Development' started by micrlink, Dec 8, 2012.

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

    micrlink

    I use this and nothing happens in chat or in console.
    Code:
    @EventHandler
        public void onPlayerInteract(PlayerInteractEvent event){
            Block block = event.getClickedBlock();
            Player player = event.getPlayer();
            String playername = player.getName();
            if(block.getType().getId() == 70){
                player.sendMessage(ChatColor.DARK_GRAY + ".");
                    }
         }
    and
    Code:
    Logger log = Logger.getLogger("MineCraft");
    PluginDescriptionFile p = this.getDescription();
        public void onEnable(){
        log.info("[" + p.getName() + "] Version " + p.getVersion() + " has been enabled!");
        getServer().getPluginManager().registerEvents(this, this);
        }
     
  2. Offline

    BucketOfFun

    Is the event listener in your main class?
     
  3. Offline

    micrlink

    Yes i only have one class
     
  4. Offline

    BucketOfFun

    Does your main class implement Listener then? Also, if you aren't using the "playername" String in the event listener, you should probably delete it.
     
  5. Offline

    ZeusAllMighty11

    Try printing out debug messages to see if the event is even fired. If it isn't, you're missing part of your handler or you do not implement listener or did not register the event.
     
  6. Offline

    micrlink

  7. Offline

    krazytraynz

    The order you posted your code in makes me think you put the event listener before the onEnable() method... If you did, that's probably the reason why it isn't working.
     
  8. Offline

    micrlink

    The onEnable is before is the listener
    The class implements listener, it is register and their arent any messages in the console
    i do use the "playername"
     
  9. Offline

    Woobie

    You never checked if the player actually clicked a block.
    Code:
    if(event.getAction() == Action.POOP_CLICK_BLOCK) {
        Block block = event.getClickedBlock();
        //etc 
    Replace 'POOP' with LEFT or RIGHT
     
  10. Offline

    micrlink

    Its not a button its a pressure plate
     
  11. Offline

    chasechocolate

    Are you trying to see if they click a pressure plate, or stand on one?
     
    Woobie likes this.
  12. Offline

    micrlink

    Stand
     
  13. Offline

    krazytraynz

    If you're checking to see if they're standing on a pressure plate, using e.getClickedBlock() wouldn't work too well :p
     
Thread Status:
Not open for further replies.

Share This Page