PlayerInteractEvent only if allowed (WG, LWC)

Discussion in 'Plugin Development' started by Baba43, Apr 17, 2013.

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

    Baba43

    Hello,

    is it possible to find out if the PlayerInteractEvent was allowed by LWC and WorldGuard?

    I need to know if the player is interaction a block he would be able to destroy.. also I don't want to hook into WG or LWC.

    Any ideas?
     
  2. Offline

    Morthis

    Throw a BlockBreakEvent on the block for that player and see if it comes back as cancelled.
     
    Baba43 likes this.
  3. Offline

    Baba43

    Sounds interesting, but how can I do that?

    /edit
    Found it. Thanks very much, thats working fine!

    Code:
    Block b = event.getClickedBlock();
    BlockBreakEvent bbe = new BlockBreakEvent(b, event.getPlayer());
    Bukkit.getServer().getPluginManager().callEvent(bbe);
     
  4. Offline

    Morthis

    Code:
            BlockBreakEvent event = new BlockBreakEvent(block, player);
            Bukkit.getPluginManager().callEvent(event);
            if (event.isCancelled()) {
                // LWC/WG blocked
            }
     
  5. Offline

    macguy8

    That method might screw up block logging plugins, I'd just use the API
     
  6. Offline

    afistofirony

    macguy8 It shouldn't. I assume all logging plugins use the ignoreCancelled = true parameter for EventHandler (wouldn't make sense not to do so); and BlockBreakEvents are fired regardless of whether they're cancelled. So calling it would cause WorldGuard / LWC to cancel it (thus not affecting loggers). This is simply firing it and seeing if it gets cancelled.
     
  7. Offline

    macguy8

    afistofirony
    Yes, it would work fine if it was cancelled, but if it isn't the logging plugins will not see it as cancelled, and therefor log it
     
  8. Offline

    afistofirony

    Hmm, true, you have a point. So there really isn't a way to do this unless you try this:

    Code:
            if (event.isCancelled()) {
                // stuff
          } else event.setCancelled(true);
    
     
Thread Status:
Not open for further replies.

Share This Page