Solved Sign#getLine returns with formatting/color

Discussion in 'Plugin Development' started by Dubehh, Aug 29, 2014.

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

    Dubehh

    Is there a way to get the content of a sign without the actual color? Somehow getLine(#) returns the actual format on the sign (including color formatting).

    Example:

    ------------------------------ (sign)
    AwesomeGameName (first line)
    TheArena (second line)

    -------------------------------

    'TheArena' is an existing String inside my config file.
    So I check
    Code:java
    1. String arenaName = s.getLine(1);

    However, when I try to search for 'arenaName' in the config it returns null, because there are formatting options inside arenaName.
    I need to get the blank text from arenaName, which is 'TheArena' (as written on the sign). Not with the blue color, so I can look for it in the config.
     
  2. Offline

    teej107

  3. Offline

    FerusGrim

    I don't believe there's a built-in way to do this.

    What is the output of Sign#getLine with the formatting? We could probably create a method of getting just the text. :)
     
  4. Offline

    Dubehh

    teej107
    Does not work ;)
    I used
    Code:java
    1. ChatColor.stripColor(e.getLine(1));
    .

    Code:java
    1. @EventHandler
    2. public void onInteract(PlayerInteractEvent e){
    3. Player p =e.getPlayer();
    4.  
    5. if(e.getAction() == Action.RIGHT_CLICK_BLOCK){
    6. Material block = e.getClickedBlock().getType();
    7. if(block == Material.SIGN || block==Material.WALL_SIGN || block==Material.SIGN_POST){
    8. Sign s = (Sign) e.getClickedBlock().getState();
    9. if(s.getLine(0).equals(DARK_GRAY+""+BOLD+"StrikerZ") && !(s.getLine(1).equals(""))){
    10. String arenaName = ChatColor.stripColor(s.getLine(1));
    11. m.ingame.addToGame(arenaName, p);
    12. p.teleport(m.spawnloc.getLobbySpawn(arenaName));
    13. }
    14. }
    15. }
    16. }


    SignChange
    Code:java
    1. e.setLine(0, DARK_GRAY+""+BOLD+"StrikerZ");
    2. e.setLine(1, DARK_BLUE+e.getLine(1));
    3. e.setLine(2, BLACK+""+BOLD + ArenaTime.getStatus(e.getLine(1)));
     
  5. Offline

    FerusGrim

    Dubehh
    Take a gander at my post? :)
     
  6. Offline

    teej107

    Dubehh What does not work about it?
     
  7. Offline

    Necrodoom

    Dubehh well, then, what is the output of stripcolor?
    Also, why wouldn't getLine return color codes? Its part of the string after all.
     
  8. Offline

    Dubehh

    FerusGrim Necrodoom teej107
    Excuse me sirs ;)
    I went full retard and use the wrong string inside the config.
    ChatColor.stripColor did the job like it was supposed to.
    Solved
     
    FerusGrim likes this.
  9. Offline

    FerusGrim

    Don't forget to mark this as solved.
    Dubehh
     
Thread Status:
Not open for further replies.

Share This Page