Editing Signs on Left Click

Discussion in 'Plugin Development' started by BurnerDiamond, Mar 21, 2015.

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

    BurnerDiamond

    Code:
     if (e.getAction() == Action.LEFT_CLICK_BLOCK) {
                if(check.get(p) == null) {
                    return;
                }
                if(check.get(p) == false) {
                    p.sendMessage("It's false");
                }
                if (check.get(p) == true) {
                    p.sendMessage("It's true");
                    Material clicked = e.getItem().getType();
                    if (clicked == Material.PAPER) {
                        Block block = e.getClickedBlock();
                        if (block.getType() == Material.SIGN_POST || block.getType() == Material.WALL_SIGN) {
                            if (e.getItem().getItemMeta().getDisplayName() != null) {
                                if (e.getItem().getItemMeta().getDisplayName().equals(main.getConfig().get("books.players." + p.getName() + ".title"))) {
                                    if (block.getState() instanceof Sign) {
                                        ((Sign) block.getState()).setLine(2, p.getName());
                                        ((Sign) block.getState()).setLine(3, e.getItem().getItemMeta().getDisplayName());
                                        p.sendMessage("It has been set");
    
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    I currently have the code above but it doesn't seem to be working. It sends the message "It's true" but it doesn't do anything else. The sign doesn't change at all. Any help?
     
  2. update the sign.
    ((Sign) block.getState()).update();
     
  3. Offline

    BurnerDiamond

    Found a secondary problem. It doesn't send the message it has been set. I've tried debugging but no use.

    @FisheyLP
     
    Last edited: Mar 21, 2015
  4. Offline

    mine-care

    @BurnerDiamond don't compare Boolean values as you did above,
    Prefer to do it as folows: if(Boolean) to check for true and if(!Boolean) to check for false.
    Also getitemmeta can return null, so be careful.
    Now that you're not even getting messages, is the event working;
     
  5. Try sending a message after each block and see where it stops, then you can see where it goes wrong.
     
Thread Status:
Not open for further replies.

Share This Page