Solved Colored Signs

Discussion in 'Plugin Development' started by Lactem, May 19, 2013.

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

    Lactem

    I'm trying to make signs have color from a plugin.
    Code:
    line0.replace("test", ChatColor.translateAlternateColorCodes((char) '&', "&btest"));
    That's what I have, but coloring signs won't work at all, not even from in-game. If I make a sign and type &btest, it won't change the color. How can I make it change the color without having to use a different plugin?

    Thanks,
    Lactem
     
  2. Offline

    GodzOfMadness

    Lactem use event.setLine(line, ChatColor.translateAlternateColorCodes('&', "textHere"));
     
  3. Offline

    Lactem

    That's what I'm doing. I just didn't show you
    Code:
    String line0 = event.getLine(0);
    because it wasn't really relevant.
     
  4. Offline

    Craftiii4

    When setting colour I tend to use the symbol "§"

    Here is part of some code in one of my plugins, it should explain it :p

    Code:java
    1. String newfailmessage = failmessage.replace("&p", player.getName()).replace("&0", "§0").replace("&1", "§1").replace("&2", "§2").replace("&3", "§3").replace("&4", "§4").replace("&5", "§5").replace("&6", "§6").replace("&7", "§7").replace("&8", "§8").replace("&9", "§9").replace("&a", "§a").replace("&b", "§b").replace("&c", "§c").replace("&d", "§d").replace("&e", "§e").replace("&f", "§f").replace("&k", "§k").replace("&l", "§l").replace("&m", "§m").replace("&n", "§n").replace("&o", "§o");


    Once you have done that, set the line to the new string.
     
  5. Offline

    GodzOfMadness

    Lactem Then are you setting the line on the sign to the line of text you edited?
     
  6. Offline

    Lactem

    Yes. Setting what the sign says is not the problem. That part is easy. My problem is color. For example, if I replaced the first line with ChatColor.GREEN + "test", then all it would say is test, but not in green.
     
  7. Offline

    Craftiii4

    Here is an example

    Code:java
    1. @EventHandler
    2. public void onSignChange(SignChangeEvent event) {
    3.  
    4. if (event.getLine(0).equalsIgnoreCase("[###]") || event.getLine(0).equalsIgnoreCase("§a[###]")) {
    5.  
    6. ItemStack sign = new ItemStack(Material.SIGN,1);
    7.  
    8. Player player = event.getPlayer();
    9.  
    10. if (player.hasPermission("####.pick.createsign")) {
    11.  
    12. boolean nationcorrect = false;
    13.  
    14. if (event.getLine(1).equalsIgnoreCase("Text")) {
    15. nationcorrect = true;
    16. player.sendMessage("§eCreated ### pick point for the ## §cText");
    17. event.setLine(1, "§c§lText");
    18.  
    19. }
     
  8. Offline

    Lactem

    Thanks. I'll try it. I think it's because I have to use the § symbol instead of &.

    Nope. I think the problem is using color on signs. I can't do it at all. As I said earlier, if I try to make a sign that says &btest, it will say "&btest" instead of being blue and saying test.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
  9. Offline

    Craftiii4

     
  10. Offline

    Lactem

    What is this failmessage?
     
  11. Offline

    Craftiii4

    That's just a variable name, when creating colours, you need to replace the &c with §c or ChatColor.Red, do this by creating a new string of the old string (the sign line). Once done that use event.setLine(#, thenewstringwithreplacedcolours)
     
  12. Offline

    Lactem

    Now it works. I was actually doing event.getLine(0).replace instead of event.setLine(0).
     
Thread Status:
Not open for further replies.

Share This Page