Invisible text on sign

Discussion in 'Plugin Development' started by torpkev, Dec 21, 2018.

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

    torpkev

    Hi,

    I'm trying to store a hidden value on a sign when I create it. I have two reasons for this.
    1) My top line is [Rent] - I'd like to have something like D[Rent] so I'm not as likely to clash with anything else that might set the same thing
    2) More importantly, I have a value PlacedID which I'd like to store on the bottom line.

    I was googling and saw someone claim that ChatColor.COLOR_CHAR will make the next character invisible. If I don't make them hidden with ChatColor.COLOR_CHAR, they are visible, so I know the values are being placed without it.

    So I have the following which I pulled from that old example from someone on a forum:

    Code:
        public static String convertToInvisibleString(String s) {
            String hidden = "";
            for (char c : s.toCharArray()) hidden += ChatColor.COLOR_CHAR+""+c;
            return hidden;
        }
    
    and

    Code:
    evt.setLine(0, Convert.convertToInvisibleString("D") + ChatColor.BLACK + "[" + ChatColor.DARK_RED + "Rent" + ChatColor.BLACK + "]");
    evt.setLine(1, ChatColor.BLACK + "Cost: $" + Integer.toString(pb.getRentCost()));
    evt.setLine(2, ChatColor.BLACK + "Days: " + Integer.toString(pb.getRentDays()));
    evt.setLine(3, Convert.convertToInvisibleString(Integer.toString(pb.getPlacedID())));
    
    And it seems to work.. [Rent] shows and not D[Rent]

    When i right click the line picking it up in PlayerInteract) - the "hidden" values just flat out aren't there

    So going back to where I'm placing them - I setLine(0) and then immediately getLine(0) and I get

    [Rent]

    No sign of the D at all.

    Any thoughts?
     
  2. Offline

    The_Spaceman

    Code:java
    1. private String[] lines;
    2. public String getLine(int index) throws IndexOutOfBoundsException {
    3. return this.lines[index];
    4. }
    5.  
    6. public void setLine(int index, String line) throws IndexOutOfBoundsException {
    7. this.lines[index] = line;
    8. }

    this is the code of CraftSign (used with the sign). I have no idea why the given 'color' is removed
     
  3. Offline

    torpkev

    yeah.. me too.

    Is there some other method to apply an invisible value to a sign?
     
  4. Offline

    The_Spaceman

    try this:
    Code:
    public static String toInvisible(char c) {
      return "§" + String.valueOf(c);
    }
    
    but isn't §D a valid color? or is it case sensitive...
     
  5. Offline

    torpkev

    I think the valid color part might be what is messing me up.

    Ok.. plan B i guess.. the (hopefully) less hacky way of doing things.. setting the block metadata on the sign when placing it and putting it back on the signs after each restart!

    Code:
    evt.getBlock().setMetadata("pid", new FixedMetadataValue(Main.getInstance(), Integer.toString(pb.getPlacedID())));
    
    Code:
    if (evt.getClickedBlock().hasMetadata("pid") && !evt.getClickedBlock().getMetadata("pid").isEmpty()) {
                                    String pid = evt.getClickedBlock().getMetadata("pid").get(0).asString();
                                }
    
    any thoughts on that approach?
     
  6. Offline

    The_Spaceman

    I
    have never used this, so I don't know
     
Thread Status:
Not open for further replies.

Share This Page