Right Click Sign & Change Sign Text?

Discussion in 'Plugin Development' started by Kyle FYI, Sep 23, 2013.

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

    Kyle FYI

    Hello, I want to make it so when you right click a sign it does something, I'm unsure how to though. I was wondering as well how I could change the text of a sign?
     
  2. Offline

    CakeProgrammer

    yea use
    sign.setLine(1,"YOURTEXT");
    just a example
     
  3. Offline

    Kyle FYI

    I know that, but how do I do the right click thing? I tried player interact but it didn't work.
     
  4. Offline

    Henzz

    Kyle FYI
    Use the PlayerInteractEvent and check the action if its right click block.
     
  5. Offline

    CakeProgrammer

    next time reply my message then I'll see it faster
    and here's a code might help you a little bit:
    Code:java
    1. @EventHandler
    2. public void onPlayerClickSign(PlayerInteractEvent event){
    3. Player player = event.getPlayer();
    4. if(event.getClickedBlock().getType() == Material.SIGN ||event.getClickedBlock().getType() == Material.SIGN_POST ||event.getClickedBlock().getType() == Material.WALL_SIGN){
    5. if(event.getAction() == Action.RIGHT_CLICK_BLOCK){
    6. //^^ choose actions ^^
    7. Sign sign = (Sign) event.getClickedBlock().getState();
    8. //^^ .getState(); really important
    9. if(sign.getLine(1).equalsIgnoreCase( "YOURTEXT")){
    10. }
    11. }
    12. }
    13. }
     
  6. Offline

    kreashenz

    CakeProgrammer I think using
    String[] lines = sign.getLines();
    works better than
    sign.getLine(0-3).equalsIgnoreCase("string")
     
  7. Offline

    zakkinu2

    did you try updating the sign after using the setting the line by doing sign.update()
     
Thread Status:
Not open for further replies.

Share This Page