Cancel rightclick event

Discussion in 'Plugin Development' started by xZise, Feb 9, 2011.

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

    xZise

    Hello,
    is it possible to cancel the right click event? For example if somebody right clicks on a sign and I warp the player, I want to prevent that the player is building a block there :p

    Fabian
     
  2. Offline

    Acru

    You could watch for a BLOCK_CANBUILD event and cancel it if the getBlock for the event returns one of your signs?
     
  3. Offline

    retsrif

    I don't think right clicking a sign would place a block... Though if it does, wherever you detect the player right clicking a sign, use
    Code:
    event.setCancelled(true);
    
     
  4. Offline

    xZise

    The “BlockRightClickEvent” don't support the method “setCancelled” or something like this. And “BlockCanBuildEvent” don't tell me the person who right clicked. Also it seems that it works not like the right click command:
    Code:
        public void onBlockCanBuild(BlockCanBuildEvent event) {
            Block block = event.getBlock();
            if(block.getState() instanceof Sign /*&& MyWarp.permissions.permission(event.getPlayer(), PermissionTypes.SIGN_WARP)*/) {
                SignWarp signWarp = new SignWarp((Sign) block.getState());
                if (signWarp.getType() != SignWarpType.NONE) {
                    XLogger.info("cb");
                    event.setBuildable(false);
                }
                XLogger.info("cb pre");
            } else {
                XLogger.info("cb !sign");
            }
        }
    If I click on a sign it will log a “cb !sign”, so how I could know it was a click on a sign? Or maybe make “BlockRightClickEvent” cancelable.

    Fabian
     
  5. Offline

    retsrif

    If you want the person who right clicked, use this:
    Code:
    event.getPlayer();
     
  6. Offline

    xZise

    Jep this works for “BlockRightClickEvent” but not for “BlockCanBuildEvent” and I'm using the latest version from github. And in BlockCanBuildEvent I don't know how I know that somebody rightclicked a sign before.

    Fabian
     
  7. Offline

    Acru

    I looked into this further and seems that the setBuildable of a BLOCK_CANBUILD event is ignored at the moment.

    In the event BLOCK_PLACED however, you can either setCancelled(true) or setBuild(false) to stop the block from being made. I tested this and they both work. I'm not sure which is more proper, but probably the cancel one.

    You'll need to confirm that getBlockAgainst() returns a sign owned by your plugin first, however.

    The event BLOCK_RIGHTCLICKED is triggered as well, just before the place event, so should be handled separately.
     
  8. Offline

    xZise

    Moin,
    okay that is a possibility but it looks like a work around... So if possible please make it cancelable (or tell my, why it won't implemented).

    Fabian
     
  9. Offline

    ursa_arcadius

    I would like to "lock" a chest so if someone is currently using it noone else can open it until they are done. That being said, what work around can I use for there being no setCancelled ?
     
  10. Offline

    lololmaker

    xZise
    You can also use PlayerInteractEvent, than get state of block, compare to sign and cancel the event.


    Code:
    if(!e.getAction().equals(Action.RIGHT_CLICK_BLOCK)) return;
    State s = event.getClickedBlock().getState();
    if(!(s instanceof Sign)) return;
    event.setCanceled(true);
     
Thread Status:
Not open for further replies.

Share This Page