Get text on sign?! (PlayerInteractEvent)

Discussion in 'Spigot Plugin Development' started by redstonebiten, May 18, 2016.

Thread Status:
Not open for further replies.
  1. Why can't i get the text on a sign?!

    Here is code:
    Code (Text):
        @EventHandler
        public void SignClick(PlayerInteractEvent event){
            Player player = (Player) event.getPlayer();
            Block block = event.getClickedBlock();
            Sign sign = (Sign) block.getState();
            if(event.getPlayer() instanceof Player){
                if(event.getAction() == Action.RIGHT_CLICK_BLOCK){
                    if(block.getType() == Material.SIGN||block.getType() == Material.WALL_SIGN){
                        if(sign.getLine()){
                           
                        }
                    }
                }
            }
        }
    }
    It tells me to create a method for: getLine(int)

    WHY!!??
     
  2. Choco

    Moderator

    No, it's probably telling you to USE getLine(int). You have to specify which line you would like to get.

    Also, you're getting the sign BEFORE you're checking if it's a sign (ClassCastException), checking if a Player is an instanceof Player (And casting a Player to a player), again... before you need to even though it's unnecessary. The method is literally .getPlayer(), and what if the block is null? Again.. before you even checked

    TL;DR:
    - You're getting things before checking them. Check first
    - You're not using the method properly. Sign#getLine(int lineNumber);
    - You clearly have the slightest clue how to program in Java
     
  3. Nope :/ It does not even give me stuff to pick.. or how you say it.. idk.. Like. i can pick: equals, clone, and more but not bukkit stuff?...
     
  4. Choco

    Moderator

    Assume this is your sign:
    This is the best
    sign that has
    ever been
    created

    sign.getLine(0), Returns: "This is the best"
    sign.getLine(1), Returns: "sign that has"
    sign.getLine(2), Returns: "ever been"
    sign.getLine(3), Returns: "created"

    .getLine(int linNum) returns a String, which would be a Java thing. You may use String methods, such as .equalsIgnoreCase()
     
    • Agree Agree x 1
  5. I feel like there are a dozen threads where this is answered, try Googling it.
     
    • Agree Agree x 1
    • Winner Winner x 1
  6. It shows this...
    https://gyazo.com/5ca62f720b5821089a88a90f157be5f7
     
  7. No... No one has the problem i have?
     
  8. @EventHandler
    public void onPlayerInteract(PlayerInteractEvent e) {
    if (e.getAction() == Action.RIGHT_CLICK_BLOCK) {
    Block block = e.getClickedBlock();
    if (block.getType() == Material.SIGN || block.getType() == Material.SIGN_POST
    || block.getType() == Material.WALL_SIGN) {
    Sign sign = (Sign) e.getClickedBlock().getState();
    if (sign.getLine(0).contains("...")) {
     
    • Funny Funny x 2
  9. BUT GETLINE DOES NOT REGISTER!
     
  10. https://gyazo.com/1b766f10b1c38f095a1496fabf9276b3
     
  11. You're either really, really stupid, or you have no experience with Bukkit at all.
     
  12. Choco

    Moderator

  13. oh..wait.... fuck me... i named the fucking class Sign..
     
    • Funny Funny x 3
    • Winner Winner x 1
    • Optimistic Optimistic x 1
Thread Status:
Not open for further replies.