Detect Sign Near Door and Whats written on it

Discussion in 'Plugin Development' started by D4RKKNIGH7, Jun 8, 2012.

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


    Hey guys,

    I'm having a bit of trouble,

    When you open a door i want it to detect if there's a sign near the door (1 block).
    If it doesn't have your name on it Cancel the event.

    Code i have so far
    public void onPlayerInteract(PlayerInteractEvent event) {
       Player player = event.getPlayer();
       Block block = event.getClickedBlock();
       if(block.getTypeId() == 64) {
       Location l1 = block.getLocation().add(1, 1, 0);
       Block b1 = l1.getBlock();
                if(b1.getType().equals(Material.WALL_SIGN)) {
               Sign sign = (Sign) b1.getState();
               //If the signs text isnt username then
           if(!sign.getLine(1).contains(player.getDisplayName())) {
               player.sendMessage("You shall not pass");
           } else {
    NOTE: I also have L2, L3, L4 and B2,B3,B4 in else if tags thats why tehre is a return after event cancel. This is to check if there is a sign near it. This part seems to be working (ONLY IF YOU RIGHT CLICK THE TOP PART OF THE DOOR) and the sigh.getline isnt working either.

    I was wondering if someone could help me out and maybe show/tell me and easier way of detecting the surrounding area of the door (where the signs would go) maybe an array or something.



    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: May 26, 2016
  2. you can check whit the blockface al sides so you have only code, and not 20 the same of it
Thread Status:
Not open for further replies.

Share This Page