SignChangeEvent.getLine(0) doesn't work

Discussion in 'Resources' started by homerbond005, May 30, 2011.

Thread Status:
Not open for further replies.
  1. Hey guys!
    I really need your help:
    Code:
    public void onSignChange(SignChangeEvent event){
            Player player = event.getPlayer();
            BlockState state = event.getBlock().getState();
            if(state instanceof Sign) {
                Sign sign = (Sign) state;
                if(sign.getLine(0).toLowerCase().contains("something")){
                    player.sendMessage("It works");
                }
            }
        }
    doesn't works. Are there any failures? I copied some parts from a tutorial.
    This is part of a BlockListener class.
    Thanks for helping.
     
  2. Offline

    Ancetras

    Did you register the event?
    It's SIGN_CHANGE.
    You have to register it in your main class.
     
  3. Yes I did. If I place a sign, it starts the class. The only failure is that sign.getLine(0) doesn't return anything.

    Code:
    pm.registerEvent(Event.Type.SIGN_CHANGE, blocklistener,
                    Event.Priority.Normal, this);
    This is written in my Main-Class, do I have to change the "this" to my blcklistener class?
    Main-Class: com.bukkit.HomerBond005.RSC.RSC
    Blocklistener-Class: com.bukkit.HomerBond005.RSC.RSCL

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 16, 2016
  4. Offline

    Ancetras

    The line 0 is the first line. Are you sure you are writing on the first line and not the second? o,o
    However, try to do this:

    Code:
    public void onSignChange(SignChangeEvent event){
            Player player = event.getPlayer();
            if ((event.getLine(0).equalsIgnoreCase("something"))){
                    player.sendMessage("It works.");
            }else if ((event.getLine(0).equalsIgnoreCase(""))){
                    player.sendMessage("Your sign is empty.");
            }
       
    }
     
  5. It doesn't print out anything. I added
    Code:
    else{
    player.sendmessage("None of them");
    }
    and I got "None of them".

    I got it: after "something" was a space: "something "
    I'm sorry having distrubed you. :)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 16, 2016
Thread Status:
Not open for further replies.

Share This Page