How can I read a text from a sign?

Discussion in 'Plugin Development' started by GamerTyp080, Dec 6, 2019.

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

    GamerTyp080

    This is the code I used so far:
    Code:
    @EventHandler
    public void clickSign(PlayerInteractEvent event) {
            if(event.getClickedBlock() instanceof sign) {
                    Sign sign =  (Sign) event.getClickedBlock().getState;
                
                     event.getPlayer().sendMessage(sign.getLine(0));
            }
    }
    
    But it doesn´t work!
    Can somebody help me?
     
  2. Offline

    KarimAKL

    @GamerTyp080 Java is case sensitive.

    "sign" should be "Sign"

    "event.getClickedBlock()" should be "event.getClickedBlock().getState()", remember to check if the block is null first.

    You need parenthesis after "getState"
     
  3. Offline

    GamerTyp080

    Code:
    @EventHandler
    public void handlePlayerJoin(PlayerInteractEvent event) {
             if(event.getClickedBlock().getState() instanceof Sign) {
                     Sign sign = (Sign) event.getClickedBlock().getState();
                              
                     event.getPlayer().sendMessage(sign.getLine(1));
            }
    }
    This is the problem:
    Code:
    event.getPlayer().sendMessage(sign.getLine(0));
     
    Last edited: Dec 7, 2019
  4. Online

    timtower Moderator Moderator

    @GamerTyp080 What is the problem then? Does it throw an error? Does it give a red line?
     
  5. Offline

    GamerTyp080

    I have registered the event in the Main class
    Code:
    PluginManager plm = Bukkit.getPluginManager();
    plm.registerEvents(new SignListener(), this);
    and there is no red line, but when I click on the sign in Minecraft nothing happens.
     
    Last edited: Dec 7, 2019
  6. Online

    timtower Moderator Moderator

    @GamerTyp080 Do you get a message if you put a sendMessage before the if statement?
     
  7. Offline

    GamerTyp080

    No, not even if I hide all if statement.
     
  8. Online

    timtower Moderator Moderator

    Then your event does not fire.
    Please post your full class and your full server log.
    Both using https://pastebin.com
     
  9. Offline

    GamerTyp080

    I got it! The init() method in the Main class was private.
    Now it works.
     
Thread Status:
Not open for further replies.

Share This Page