Solved Sign Colors! [Help]

Discussion in 'Plugin Development' started by ImImprobable, Jan 4, 2014.

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

    ImImprobable

    Hey Guys,
    Here is my code. the rest of it is right but this doesn't seem to work help?
    Code:java
    1. sign.setLine(0, ChatColor.GOLD + "[" + ChatColor.AQUA + "MobArena" + ChatColor.GOLD + "]");

    Also this is a custom plugin that i'm using on mm server for MobArena :p not creating rip off!

    Thx
    ImIm
     
  2. Offline

    ResultStatic

    ImImprobable you have to replace & with the color symbol.
    Code:
    @EventHandler
      public void onSignChange(SignChangeEvent sign)
      {
        if (sign.getLine(0).contains("&"));
        sign.setLine(0, sign.getLine(0).replace("&", "§"));
        if (sign.getLine(1).contains("&"));
        sign.setLine(1, sign.getLine(1).replace("&", "§"));
        if (sign.getLine(2).contains("&"));
        sign.setLine(2, sign.getLine(2).replace("&", "§"));
        if (sign.getLine(3).contains("&"));
        sign.setLine(3, sign.getLine(3).replace("&", "§"));
      }
    }
    this code with make it so anytime you do a color code it will work on a sign in game
     
  3. Offline

    ImImprobable

    ResultStatic
    Hi, Im trying to make an activate sign stage, How would i do it in this context/Code
    Code:java
    1. @EventHandler
    2. public void onPlayerInteractSign(PlayerInteractEvent e) {
    3. if(e.getAction() == Action.RIGHT_CLICK_BLOCK) {
    4. Block b = e.getClickedBlock();
    5. Player p = e.getPlayer();
    6.  
    7. if(b.getType() == Material.WALL_SIGN || b.getType() == Material.SIGN_POST) {
    8. Sign sign = (Sign) b.getState();
    9. String[] lines = sign.getLines();
    10. if(lines[0].equalsIgnoreCase("[MobArena]")) {
    11. sign.setLine(0, ChatColor.GOLD + "[" + ChatColor.AQUA + "MobArena" + ChatColor.GOLD + "]");
    12. if(lines[1].equalsIgnoreCase("Join"))
    13. {
    14. sign.setLine(1, ChatColor.GREEN + "Join");
    15. if(lines[2].equalsIgnoreCase("Cage"))
    16. {
    17. sign.setLine(2, ChatColor.AQUA + "Cage");
    18. }
    19. else
    20. {
    21. p.sendMessage(ChatColor.RED + "Sign Warp Generation Failure Contact Plugin Dev!!!");
    22. }
    23. }
    24. else
    25. {
    26. p.sendMessage(ChatColor.RED + "Second Line Brocken");
    27. }
    28. }
    29. else
    30. {
    31. p.sendMessage(ChatColor.RED + "First Line Brocken");
    32. }
    33. }
    34.  
    35. }
    36. }
     
  4. Offline

    ResultStatic

    ImImprobable no you dont have to just put a &4 &3 &2 where ever you want colors. dont use chatcolor because it litteraly is chatcolor. so you would do
    Code:
    sign.setLine(0, "&6[&3MobArena&6]");
    as long as you have the code i put before in your plugin it will create colors where ever you put &
     
  5. Offline

    ImImprobable

    ResultStatic
    Also forgot how would you check for Colour Codes on a sign and make it go on and carry out the if() part if the sign only contains that colour?
    Also thank you for the colour code fix ^^
     
  6. Offline

    ResultStatic

  7. Offline

    ImImprobable

    ResultStatic
    This
    Code:java
    1. @EventHandler
    2. public void onPlayerInteractWorkingSign(PlayerInteractEvent e)
    3. {
    4. if(e.getAction() == Action.RIGHT_CLICK_BLOCK)
    5. {
    6. Block b = e.getClickedBlock();
    7. Player p = e.getPlayer();
    8. if(b.getType() == Material.WALL_SIGN || b.getType() == Material.SIGN_POST)
    9. {
    10. Sign sign = (Sign) b.getState();
    11. String[] lines = sign.getLines();
    12. if(lines[0].equalsIgnoreCase(ChatColor.GOLD + "[" + ChatColor.AQUA + "MobArena" + ChatColor.GOLD + "]"))
    13. {
    14. p.sendMessage("Line 1 Working! Going onto line 2");
    15. if(lines[0].equalsIgnoreCase(ChatColor.GREEN + "Join"))
    16. {
    17. p.sendMessage("Line 2 Working! Going onto line 3");
    18. if(lines[0].equalsIgnoreCase(ChatColor.AQUA + "Cage"))
    19. {
    20. p.sendMessage("Plugin Works ready to be released after a few more touches!");
    21. p.chat("/ma join Cage");
    22.  
    23.  
    24.  
    25. //* //Reserved
    26.  
    27. }
    28. }
    29. }
    30. else
    31. {
    32. p.sendMessage(ChatColor.RED + "Generation Failure please try again later or contact ImImprobable on Bukkit!");
    33.  
    34. }
    35. }
    36. }
    37. }


    ResultStatic
    ok i click the sign no errors pop up but the sign doesnt change?
    Code:java
    1. EventHandler
    2. public void onPlayerInteractSign(PlayerInteractEvent e) {
    3. if(e.getAction() == Action.RIGHT_CLICK_BLOCK) {
    4. Block b = e.getClickedBlock();
    5. Player p = e.getPlayer();
    6.  
    7. if(b.getType() == Material.WALL_SIGN || b.getType() == Material.SIGN_POST) {
    8. Sign sign = (Sign) b.getState();
    9. String[] lines = sign.getLines();
    10. if(lines[0].equalsIgnoreCase("[MobArena]")) {
    11. sign.setLine(0, "&6[MobArena]");
    12. if(lines[1].equalsIgnoreCase("Join"))
    13. {
    14. sign.setLine(1, "&2Join");
    15. if(lines[2].equalsIgnoreCase("Cage"))
    16. {
    17. sign.setLine(2, "&2Cage");
    18. }
    19. else
    20. {
    21. p.sendMessage(ChatColor.RED + "Sign Warp Generation Failure Contact Plugin Dev!!!");
    22. }
    23. }
    24. else
    25. {
    26. p.sendMessage(ChatColor.RED + "Second Line Brocken");
    27. }
    28. }
    29. else
    30. {
    31. p.sendMessage(ChatColor.RED + "First Line Brocken");
    32. }
    33. }
    34.  
    35. }
    36. }


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

    ResultStatic

    @ImImprobable wait im confused why do u need to set the line to something
    just do.
    Code:
    if line.equalIgnorecase("§6[§3MobArena§6]);
    player.sendMessage...
    remeber any & will be replaced with § when you write the sign
     
  9. Offline

    CeramicTitan

    when you replace the string use: setLine(array index, ChatColor.translateAlternateColorCodes('&', "String you are trying to change"); Also what happens when you click the sign? Anything?
     
  10. Offline

    ImImprobable

    Pardon i dont understand, oh i figured out the post before my last one, the last post i had the signs doesnt change when i click it so i made the lines wrong and it gave me the error i made if the lines were wrong.

    I have a checker for the &

    CeramicTitan
    I changed it to what you said i should, just errors in NetBeans

    EDIT: Forgot Bracket O_O

    CeramicTitan
    I dont see how sign.setLine(2, ChatColor.translateAlternateColorCodes('&', "Cage"));
    Will change the colour to what i want it to there is no colour codes in there anywhere??

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

    ResultStatic

    ImImprobable dont use that (2, ChatColor.translateAlternateColorCodes('&', "Cage"));
     
  12. Offline

    ImImprobable

  13. Offline

    CeramicTitan

    You be quiet.
    Example: sign.setLine(2, ChatColor.transAlternateColorCodes('&',"&2Cage"); // This will replace the '&' and replace it with the corresponding color code. But don't check for this, only use it to set.
     
  14. Offline

    ImImprobable

    Ok will try

    Code:java
    1. @EventHandler
    2. public void onPlayerInteractSign(PlayerInteractEvent e) {
    3. if(e.getAction() == Action.RIGHT_CLICK_BLOCK) {
    4. Block b = e.getClickedBlock();
    5. Player p = e.getPlayer();
    6.  
    7. if(b.getType() == Material.WALL_SIGN || b.getType() == Material.SIGN_POST) {
    8. Sign sign = (Sign) b.getState();
    9. String[] lines = sign.getLines();
    10. if(lines[0].equalsIgnoreCase("[MobArena]")) {
    11. sign.setLine(2, ChatColor.translateAlternateColorCodes('&',"&7[&6MobArena&7]"));
    12. if(lines[1].equalsIgnoreCase("Join"))
    13. {
    14. sign.setLine(2, ChatColor.translateAlternateColorCodes('&',"&2Join"));
    15. if(lines[2].equalsIgnoreCase("Cage"))
    16. {
    17. sign.setLine(2, ChatColor.translateAlternateColorCodes('&',"&2Cage"));
    18. }
    19. else
    20. {
    21. p.sendMessage(ChatColor.RED + "Sign Warp Generation Failure Contact Plugin Dev!!!");
    22. }
    23. }
    24. else
    25. {
    26. p.sendMessage(ChatColor.RED + "Second Line Brocken");
    27. }
    28. }
    29. else
    30. {
    31. p.sendMessage(ChatColor.RED + "First Line Brocken");
    32. }
    33. }
    34.  
    35. }
    36. }

    There was an error on line 3 and the colours didn't change.
    I know there was an error cuz of the code
    the colours didn't change either

    plz help

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

    CeramicTitan

    Useless information without stacktrace
     
  16. Offline

    ImImprobable

    CeramicTitan
    there is no stack trace. not an error in NetBeans in game
    Line 21 i get that message sent to me
     
  17. You have to update the Sign after setting something on it with:
    Code:java
    1. sign.update();
     
  18. Offline

    CeramicTitan

    which line is 21? and what is the error?
     
  19. Offline

    ImImprobable

    CeramicTitan
    look at the code i sent go to line 21. its sending me the line of code i made there
    AlexMl
    Im trying that now

    AlexMl
    I tried what you said gave me the same error and the sign didnt update
    I put the sign.update(); in the test for the line Cage.
    It goes to the else of that for some reason and sends me the message
    Code:java
    1. p.sendMessage(ChatColor.RED + "Sign Warp Generation Failure Contact Plugin Dev!!!");


    Omg!!!
    Im so sorry every1!!!!!
    I set the signs 3rd line to Join then after then when it tried to check that line for cage it didnt update and it gave me the error
    So Sorry!!!
    O_O

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

    PhilipsNostrum

    Lol. You're actually always changing line 3 ;) don't forget sign.update();
     
  21. Offline

    ImImprobable

    Alright, Still unsolved.
    Yeah i know using coding format PhilipsNostrum
    CeramicTitan AlexMl
    Still the if/else statement goes to the else for no reason and i still dont know why!
     
  22. Offline

    PhilipsNostrum

    Can you post your current code?
     
  23. Offline

    ImImprobable

    here is the wholllleeeee thing
    Code:java
    1. package com.ghostrider.MobArenaSigns;
    2.  
    3.  
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.Color;
    6. import org.bukkit.Material;
    7. import org.bukkit.block.Block;
    8. import org.bukkit.block.Sign;
    9. import org.bukkit.entity.Player;
    10. import org.bukkit.event.EventHandler;
    11. import org.bukkit.event.Listener;
    12. import org.bukkit.event.block.Action;
    13. import org.bukkit.event.block.SignChangeEvent;
    14. import org.bukkit.event.player.PlayerInteractEvent;
    15. import org.bukkit.event.player.PlayerRespawnEvent;
    16. import org.bukkit.plugin.java.JavaPlugin;
    17.  
    18. public class SignsMobArena extends JavaPlugin implements Listener
    19. {
    20. @Override
    21. public void onEnable()
    22. {
    23. getLogger().info("Multiuse Enabled");
    24. getLogger().info("Version:0.3");
    25. getLogger().info("Author: X__GhostRider__X");
    26. getServer().getPluginManager().registerEvents(this, this);
    27. }
    28.  
    29. @Override
    30. public void onDisable()
    31. {
    32. getLogger().info("Multiuse Has been Disabled");
    33. }
    34.  
    35. @EventHandler
    36. public void onPlayerInteractSign(PlayerInteractEvent e) {
    37. if(e.getAction() == Action.RIGHT_CLICK_BLOCK) {
    38. Block b = e.getClickedBlock();
    39. Player p = e.getPlayer();
    40.  
    41. if(b.getType() == Material.WALL_SIGN || b.getType() == Material.SIGN_POST) {
    42. Sign sign = (Sign) b.getState();
    43. String[] lines = sign.getLines();
    44. if(lines[0].equalsIgnoreCase("[MobArena]")) {
    45. sign.setLine(2, ChatColor.translateAlternateColorCodes('&',"&7[&6MobArena&7]"));
    46. sign.update();
    47. if(lines[1].equalsIgnoreCase("Join"))
    48. {
    49. sign.setLine(1, ChatColor.translateAlternateColorCodes('&',"&2Join"));
    50. sign.update();
    51. if(lines[2].equalsIgnoreCase("Cage"))
    52. {
    53. sign.setLine(2, ChatColor.translateAlternateColorCodes('&',"&2Cage"));
    54. sign.update();
    55.  
    56. }
    57. else
    58. {
    59. p.sendMessage(ChatColor.RED + "Sign Warp Generation Failure Contact Plugin Dev!!!");
    60. }
    61. }
    62. else
    63. {
    64. p.sendMessage(ChatColor.RED + "Second Line Brocken");
    65. }
    66. }
    67. else
    68. {
    69. p.sendMessage(ChatColor.RED + "First Line Brocken");
    70. }
    71. }
    72.  
    73. }
    74. }
    75.  
    76. @EventHandler
    77. public void onSignChange(SignChangeEvent sign)
    78. {
    79. if (sign.getLine(0).contains("&")){
    80. sign.setLine(0, sign.getLine(0).replace("&", "§"));
    81. }
    82. if (sign.getLine(1).contains("&")){
    83. sign.setLine(1, sign.getLine(1).replace("&", "§"));
    84. }
    85. if (sign.getLine(2).contains("&")){
    86. sign.setLine(2, sign.getLine(2).replace("&", "§"));
    87. }
    88. if (sign.getLine(3).contains("&")){
    89. sign.setLine(3, sign.getLine(3).replace("&", "§"));
    90. }
    91. }
    92. }
    93.  


    I found the error... another line number that is wrong D:<

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

    PhilipsNostrum

    You need to sign.update() only after you're done changing the sign, otherwise it will mess up. Not sure if on purpose, but you are setting line 3 to mobarena and then a bit later setting it to cage

    Actually wait, basically when a player right clicks a sign you're changing it? That's kind of weird. You should use PlayerInteractEvent to check the text only and based on that make him join whatever you want.

    And add sign.update() to onSignChange

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

    ImImprobable

    Alright this fixed it, Thanks for your help throughout the day guys great help every one ^^

    Great Great GREAT Thx
    ~ImIm
     
  26. You don't need sign.update() in onSignChange
     
  27. Offline

    PhilipsNostrum

    Change it to Solved please and you're welcome

    He did cause he was changing the text

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
Thread Status:
Not open for further replies.

Share This Page