Solved SignChangeEvent

Discussion in 'Plugin Development' started by random_username, Nov 3, 2013.

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

    random_username

    Hello, I am working with signs in my plugin, I have BlockBreakEvent, PlayerINteractEvent, and SignChangeEvent. Everything is working fine, except the SignChangeEvent; It isn't working at all. I am not getting any errors, here is the code:
    Code:java
    1. @EventHandler
    2. public void onSignCreate(SignChangeEvent event)
    3. {
    4. String prefix = replaceColors(getConfig().getString("Prefix"));
    5. Player player = event.getPlayer();
    6. Sign sign = (Sign) event.getBlock().getState();
    7. if(sign.getLine(0).equalsIgnoreCase(getConfig().getString("Signprefix")))
    8. {
    9. if(player.hasPermission("ecore.signs.admin"))
    10. {
    11. sign.setLine(0, ChatColor.AQUA + getConfig().getString("Signprefix"));
    12. if(!(sign.getLine(1).equalsIgnoreCase("Premium") || sign.getLine(1).equalsIgnoreCase("VIP") || sign.getLine(1).equalsIgnoreCase("Legend") || sign.getLine(1).equalsIgnoreCase("Store")))
    13. {
    14. player.sendMessage(prefix + ChatColor.RED + "Invalid Sign!");
    15. event.setCancelled(true);
    16. }
    17. else
    18. {
    19. player.sendMessage(prefix + ChatColor.BLUE + "Sign has been created!");
    20. }
    21. if(sign.getLine(1).equalsIgnoreCase("Premium")) sign.setLine(1, ChatColor.GREEN + "Premium");
    22. else if(sign.getLine(1).equalsIgnoreCase("VIP")) sign.setLine(1, ChatColor.GREEN + "VIP");
    23. else if(sign.getLine(1).equalsIgnoreCase("Legend")) sign.setLine(1, ChatColor.GREEN + "Legend");
    24. else if(sign.getLine(1).equalsIgnoreCase("StoreInfo")) sign.setLine(1, ChatColor.GREEN + "Store Info");
    25. }
    26. else
    27. {
    28. player.sendMessage(prefix + ChatColor.RED + "You do not have permission to do this!");
    29. event.setCancelled(true);
    30. }
    31. }
    32. }
    33.  
    34. @EventHandler
    35. public void onBlockBreak(BlockBreakEvent event)
    36. {
    37. String prefix = replaceColors(getConfig().getString("Prefix"));
    38. Player player = event.getPlayer();
    39. if(event.getBlock().getState() instanceof Sign)
    40. {
    41. Sign s = (Sign) event.getBlock().getState();
    42. if(s.getLine(0).equalsIgnoreCase(getConfig().getString("Signprefix")))
    43. {
    44. if(player.hasPermission("ecore.signs.admin"))
    45. {
    46. player.sendMessage(prefix + ChatColor.AQUA + "This Enstopia sign has been destroyed!");
    47. }
    48. else
    49. {
    50. event.setCancelled(true);
    51. player.sendMessage(prefix + ChatColor.RED + "You do not have permission to break an Enstopia Sign!");
    52. }
    53. }
    54. }
    55. }
    56.  
    57. @EventHandler
    58. public void onPlayerInteract(PlayerInteractEvent event)
    59. {
    60. String prefix = replaceColors(getConfig().getString("Prefix"));
    61. Player player = event.getPlayer();
    62. Action action = event.getAction();
    63. if(action == Action.RIGHT_CLICK_BLOCK)
    64. {
    65. if(event.getClickedBlock().getState() instanceof Sign)
    66. {
    67. Sign s = (Sign) event.getClickedBlock().getState();
    68. if(s.getLine(0).equalsIgnoreCase(getConfig().getString("Signprefix")))
    69. {
    70. if(player.hasPermission("ecore.signs.use"))
    71. {
    72. if(s.getLine(1).equalsIgnoreCase("Premium"))
    73. {
    74. for(String string : getConfig().getStringList("Premium"))
    75. {
    76. player.sendMessage(replaceColors(string));
    77. }
    78. }
    79. if(s.getLine(1).equalsIgnoreCase("VIP"))
    80. {
    81. for(String string : getConfig().getStringList("VIP"))
    82. {
    83. player.sendMessage(replaceColors(string));
    84. }
    85. }
    86. if(s.getLine(1).equalsIgnoreCase("Legend"))
    87. {
    88. for(String string : getConfig().getStringList("Legend"))
    89. {
    90. player.sendMessage(replaceColors(string));
    91. }
    92. }
    93. if(s.getLine(1).equalsIgnoreCase("Store Info"))
    94. {
    95. for(String string : getConfig().getStringList("Store"))
    96. {
    97. player.sendMessage(replaceColors(string));
    98. }
    99. }
    100. }
    101. else
    102. {
    103. player.sendMessage(prefix + ChatColor.RED + "You do not have permission to do this!");
    104. }
    105. }
    106. }
    107. }
    108. }
    109.  
    110. public String replaceColors(String s)
    111. {
    112. s = s.replaceAll("(&([a-fk-or0-9A-FK-OR]))", "\u00A7$2");
    113. return s;
    114. }
    115.  

    Is there any way to fix this? Thanks for the help :)
     
  2. Offline

    xize

    random_username
    I'm not very sure could you sent the error in a pastebin or something??
    but I think you are missing some curly braces where you check the sign lines whenever its vip or something else.
     
  3. Offline

    random_username

    There is no error in the console, but the sign wont change color, and the permissions in SignChangeEvent wont work.
     
  4. Offline

    xize

    random_username
    ah I think I see your problem does sign.getLine(0) contains colour? if it is you might want to use contains() instead of equalsIgnoreCase or do:
    Code:
    if(sign.getLine(0).equalsIgnoreCase(ChatColor.stripColor("yourtext")) {
     
    }
    
     
  5. Offline

    random_username

    no, when I create the sign it doesn't contain color, but the idea is to change the color in line 0 if line 0 = signprefix which is in the config.yml, signprefix doesn't have color.
     
  6. Offline

    xize

    random_username
    what happends if you print out the config prefix with System.out.println(getConfig().getString("signPrefix")); in the same method above the check ?, if it says null that could be the cause.
     
  7. Offline

    random_username

    I dont understand, what do I need to do? :)
     
  8. Offline

    xize

    random_username
    well before you do the name check in SignChangeEvent can you print out the Signprefix string from the config in the same event?
    if it says null your problem lays perhaps on a wrong instanced plugin variable or the config node doesn't exist.
    strings can return as null without throwing a error in the console.
     
  9. Offline

    random_username

    Added
    Code:java
    1. System.out.println(getConfig().getString("signPrefix"));

    To the SignChangeEvent, and when I created the sign, the console just said "null". What should I do now? :)
     
  10. Offline

    xize

    random_username

    okay, the best way is to know are these events triggered in the main class or outside?
    if these events are inside the main class (which I think is strange it still returns null) try replace at every
    getConfig().getString("signPrefix");

    to:
    Code:
    this.getConfig().getString("signPrefix");
    
    if it still won't work your configuration node is called invalid, note that nodes in yml are case sensitive.

    if it still won't work I probally show a other way of loading files and configuration keys since I don't use getConfig() though:p
     
  11. Offline

    OffLuffy

    Also, memory is a bit skethy on this, but I believe after a sign's text has been altered in an event, you'd need to do something along the lines of sign.update(), if I'm not mistaken. Good luck !
     
  12. Offline

    random_username

    hm... Still won't work, It will print out "null". What is that other way? :)
     
  13. Offline

    xize

    random_username

    I always use this:

    Code:
    try {
         File f = new File(this.getDataFolder() + File.Seperator + "yourfile.yml");
         if(f.exists()) {
               FileConfiguration con = YamlConfiguration.loadConfiguration(f);
                String prefix = con.getString("signPrefix");
         } else {
               //file does not exist make a new one.
              FileConfiguration con = YamlConfiguration.loadConfiguration(f);
              con.set("justAConfigKey", value);
              con.save(f);
         }
    } catch(Exception r) {
    r.printStackTrace();
    }
    
    but if you are using a other class and still want to access getDataFolder() (your plugin folder)

    I add in the main class this:
    Code:
    public class yourplugin extends JavaPlugin {
           public static yourplugin pl;
     
           public void onEnable() {
                 pl = this;
            }
     
             public void onDisable() {
     
             }
    }
    
    then I will call the path in a other class like: yourplugin.pl.getDataFolder() etc etc
     
  14. Offline

    random_username

    Wait, actually, the console is no longer sending "null". It is now sending the correct string, as the
    Code:java
    1. System.out.println(this.getConfig().getString("SignPrefix"));

    has the "p" as a capital, it was in lower case. If the console is sending me the correct string, why is the signchangeevent not working right? here is my current code:
    Code:java
    1. @EventHandler
    2. public void onSignCreate(SignChangeEvent event)
    3. {
    4. System.out.println(this.getConfig().getString("Signprefix"));
    5. String prefix = replaceColors(getConfig().getString("Prefix"));
    6. Player player = event.getPlayer();
    7. Sign sign = (Sign) event.getBlock().getState();
    8. if(sign.getLine(0).equalsIgnoreCase(this.getConfig().getString("Signprefix")))
    9. {
    10. if(player.hasPermission("ecore.signs.admin"))
    11. {
    12. sign.setLine(0, ChatColor.AQUA + getConfig().getString("Signprefix"));
    13. sign.update();
    14. if(!(sign.getLine(1).equalsIgnoreCase("Premium") || sign.getLine(1).equalsIgnoreCase("VIP") || sign.getLine(1).equalsIgnoreCase("Legend") || sign.getLine(1).equalsIgnoreCase("Store")))
    15. {
    16. player.sendMessage(prefix + ChatColor.RED + "Invalid Sign!");
    17. event.setCancelled(true);
    18. }
    19. else
    20. {
    21. player.sendMessage(prefix + ChatColor.BLUE + "Sign has been created!");
    22. }
    23. if(sign.getLine(1).equalsIgnoreCase("Premium")) sign.setLine(1, ChatColor.GREEN + "Premium");
    24. else if(sign.getLine(1).equalsIgnoreCase("VIP")) sign.setLine(1, ChatColor.GREEN + "VIP");
    25. else if(sign.getLine(1).equalsIgnoreCase("Legend")) sign.setLine(1, ChatColor.GREEN + "Legend");
    26. else if(sign.getLine(1).equalsIgnoreCase("StoreInfo")) sign.setLine(1, ChatColor.GREEN + "Store Info");
    27. sign.update();
    28. }
    29. else
    30. {
    31. player.sendMessage(prefix + ChatColor.RED + "You do not have permission to do this!");
    32. event.setCancelled(true);
    33. }
    34. }
    35. }
    36.  
    37. @EventHandler
    38. public void onBlockBreak(BlockBreakEvent event)
    39. {
    40. String prefix = replaceColors(getConfig().getString("Prefix"));
    41. Player player = event.getPlayer();
    42. if(event.getBlock().getState() instanceof Sign)
    43. {
    44. Sign s = (Sign) event.getBlock().getState();
    45. if(s.getLine(0).equalsIgnoreCase(getConfig().getString("Signprefix")))
    46. {
    47. if(player.hasPermission("ecore.signs.admin"))
    48. {
    49. player.sendMessage(prefix + ChatColor.AQUA + "This Enstopia sign has been destroyed!");
    50. }
    51. else
    52. {
    53. event.setCancelled(true);
    54. player.sendMessage(prefix + ChatColor.RED + "You do not have permission to break an Enstopia Sign!");
    55. }
    56. }
    57. }
    58. }
    59.  
    60. @EventHandler
    61. public void onPlayerInteract(PlayerInteractEvent event)
    62. {
    63. String prefix = replaceColors(getConfig().getString("Prefix"));
    64. Player player = event.getPlayer();
    65. Action action = event.getAction();
    66. if(action == Action.RIGHT_CLICK_BLOCK)
    67. {
    68. if(event.getClickedBlock().getState() instanceof Sign)
    69. {
    70. Sign s = (Sign) event.getClickedBlock().getState();
    71. if(s.getLine(0).equalsIgnoreCase(getConfig().getString("Signprefix")))
    72. {
    73. if(player.hasPermission("ecore.signs.use"))
    74. {
    75. if(s.getLine(1).equalsIgnoreCase("Premium"))
    76. {
    77. for(String string : getConfig().getStringList("Premium"))
    78. {
    79. player.sendMessage(replaceColors(string));
    80. }
    81. }
    82. if(s.getLine(1).equalsIgnoreCase("VIP"))
    83. {
    84. for(String string : getConfig().getStringList("VIP"))
    85. {
    86. player.sendMessage(replaceColors(string));
    87. }
    88. }
    89. if(s.getLine(1).equalsIgnoreCase("Legend"))
    90. {
    91. for(String string : getConfig().getStringList("Legend"))
    92. {
    93. player.sendMessage(replaceColors(string));
    94. }
    95. }
    96. if(s.getLine(1).equalsIgnoreCase("Store Info"))
    97. {
    98. for(String string : getConfig().getStringList("Store"))
    99. {
    100. player.sendMessage(replaceColors(string));
    101. }
    102. }
    103. }
    104. else
    105. {
    106. player.sendMessage(prefix + ChatColor.RED + "You do not have permission to do this!");
    107. }
    108. }
    109. }
    110. }
    111. }
    112.  
    113. public String replaceColors(String s)
    114. {
    115. s = s.replaceAll("(&([a-fk-or0-9A-FK-OR]))", "\u00A7$2");
    116. return s;
    117. }

    What can I do now? Thanks for helping btw :)
     
  15. Offline

    xize

    random_username
    well it depends where the code gets stuck if you put at each if else loop a System.out.println("here you line number");
    you could debug it where it goes wrong, my guess is that the variable prefix doesn't works right or atleast not stripping the colors.

    a small example how it works correct me If I'm wrong.

    § is the character which does the colours, ChatColor returns actually this character as this character so it makes text colorable note that this is in a int unicode.

    but when you check such prefix you need to strip these characters or it would'nt detect the text.

    you could fix it by using ChatColor.stripColor(String);, instead of the method replaceColors.

    sorry for my strange markup don't know why it happend:p
     
  16. Offline

    random_username

    okay, when I try the
    Code:java
    1. System.out.println(this.getConfig().getString("Signprefix"));

    After the if where I check line (0), as below:
    Code:java
    1. @EventHandler
    2. public void onSignCreate(SignChangeEvent event)
    3. {
    4. String prefix = replaceColors(getConfig().getString("Prefix"));
    5. Player player = event.getPlayer();
    6. Sign sign = (Sign) event.getBlock().getState();
    7. if(sign.getLine(0).equalsIgnoreCase(this.getConfig().getString("Signprefix")))
    8. {
    9. System.out.println(this.getConfig().getString("Signprefix"));
    10. if(player.hasPermission("ecore.signs.admin"))
    11. {
    12. sign.setLine(0, ChatColor.AQUA + getConfig().getString("Signprefix"));
    13. sign.update();
    14. if(!(sign.getLine(1).equalsIgnoreCase("Premium") || sign.getLine(1).equalsIgnoreCase("VIP") || sign.getLine(1).equalsIgnoreCase("Legend") || sign.getLine(1).equalsIgnoreCase("Store")))
    15. {
    16. player.sendMessage(prefix + ChatColor.RED + "Invalid Sign!");
    17. event.setCancelled(true);
    18. }
    19. else
    20. {
    21. player.sendMessage(prefix + ChatColor.BLUE + "Sign has been created!");
    22. }
    23. if(sign.getLine(1).equalsIgnoreCase("Premium")) sign.setLine(1, ChatColor.GREEN + "Premium");
    24. else if(sign.getLine(1).equalsIgnoreCase("VIP")) sign.setLine(1, ChatColor.GREEN + "VIP");
    25. else if(sign.getLine(1).equalsIgnoreCase("Legend")) sign.setLine(1, ChatColor.GREEN + "Legend");
    26. else if(sign.getLine(1).equalsIgnoreCase("StoreInfo")) sign.setLine(1, ChatColor.GREEN + "Store Info");
    27. sign.update();
    28. }
    29. else
    30. {
    31. player.sendMessage(prefix + ChatColor.RED + "You do not have permission to do this!");
    32. event.setCancelled(true);
    33. }
    34. }
    35. }

    It doesn't show up anything at all in the console, not even "null". It just won't appear. Any ideas on what Can I do? This is the entire code of all the events on signs:
    Code:java
    1. @EventHandler
    2. public void onSignCreate(SignChangeEvent event)
    3. {
    4. String prefix = replaceColors(getConfig().getString("Prefix"));
    5. Player player = event.getPlayer();
    6. Sign sign = (Sign) event.getBlock().getState();
    7. System.out.println(this.getConfig().getString("Signprefix"));
    8. if(sign.getLine(0).equalsIgnoreCase(this.getConfig().getString("Signprefix")))
    9. {
    10. if(player.hasPermission("ecore.signs.admin"))
    11. {
    12. sign.setLine(0, ChatColor.AQUA + getConfig().getString("Signprefix"));
    13. sign.update();
    14. if(!(sign.getLine(1).equalsIgnoreCase("Premium") || sign.getLine(1).equalsIgnoreCase("VIP") || sign.getLine(1).equalsIgnoreCase("Legend") || sign.getLine(1).equalsIgnoreCase("Store")))
    15. {
    16. player.sendMessage(prefix + ChatColor.RED + "Invalid Sign!");
    17. event.setCancelled(true);
    18. }
    19. else
    20. {
    21. player.sendMessage(prefix + ChatColor.BLUE + "Sign has been created!");
    22. }
    23. if(sign.getLine(1).equalsIgnoreCase("Premium")) sign.setLine(1, ChatColor.GREEN + "Premium");
    24. else if(sign.getLine(1).equalsIgnoreCase("VIP")) sign.setLine(1, ChatColor.GREEN + "VIP");
    25. else if(sign.getLine(1).equalsIgnoreCase("Legend")) sign.setLine(1, ChatColor.GREEN + "Legend");
    26. else if(sign.getLine(1).equalsIgnoreCase("StoreInfo")) sign.setLine(1, ChatColor.GREEN + "Store Info");
    27. sign.update();
    28. }
    29. else
    30. {
    31. player.sendMessage(prefix + ChatColor.RED + "You do not have permission to do this!");
    32. event.setCancelled(true);
    33. }
    34. }
    35. }
    36.  
    37. @EventHandler
    38. public void onBlockBreak(BlockBreakEvent event)
    39. {
    40. String prefix = replaceColors(getConfig().getString("Prefix"));
    41. Player player = event.getPlayer();
    42. if(event.getBlock().getState() instanceof Sign)
    43. {
    44. Sign s = (Sign) event.getBlock().getState();
    45. if(s.getLine(0).equalsIgnoreCase(getConfig().getString("Signprefix")))
    46. {
    47. if(player.hasPermission("ecore.signs.admin"))
    48. {
    49. player.sendMessage(prefix + ChatColor.AQUA + "This Enstopia sign has been destroyed!");
    50. }
    51. else
    52. {
    53. event.setCancelled(true);
    54. player.sendMessage(prefix + ChatColor.RED + "You do not have permission to break an Enstopia Sign!");
    55. }
    56. }
    57. }
    58. }
    59.  
    60. @EventHandler
    61. public void onPlayerInteract(PlayerInteractEvent event)
    62. {
    63. String prefix = replaceColors(getConfig().getString("Prefix"));
    64. Player player = event.getPlayer();
    65. Action action = event.getAction();
    66. if(action == Action.RIGHT_CLICK_BLOCK)
    67. {
    68. if(event.getClickedBlock().getState() instanceof Sign)
    69. {
    70. Sign s = (Sign) event.getClickedBlock().getState();
    71. if(s.getLine(0).equalsIgnoreCase(getConfig().getString("Signprefix")))
    72. {
    73. if(player.hasPermission("ecore.signs.use"))
    74. {
    75. if(s.getLine(1).equalsIgnoreCase("Premium"))
    76. {
    77. for(String string : getConfig().getStringList("Premium"))
    78. {
    79. player.sendMessage(replaceColors(string));
    80. }
    81. }
    82. if(s.getLine(1).equalsIgnoreCase("VIP"))
    83. {
    84. for(String string : getConfig().getStringList("VIP"))
    85. {
    86. player.sendMessage(replaceColors(string));
    87. }
    88. }
    89. if(s.getLine(1).equalsIgnoreCase("Legend"))
    90. {
    91. for(String string : getConfig().getStringList("Legend"))
    92. {
    93. player.sendMessage(replaceColors(string));
    94. }
    95. }
    96. if(s.getLine(1).equalsIgnoreCase("Store Info"))
    97. {
    98. for(String string : getConfig().getStringList("Store"))
    99. {
    100. player.sendMessage(replaceColors(string));
    101. }
    102. }
    103. }
    104. else
    105. {
    106. player.sendMessage(prefix + ChatColor.RED + "You do not have permission to do this!");
    107. }
    108. }
    109. }
    110. }
    111. }
    112.  
    113. public String replaceColors(String s)
    114. {
    115. s = s.replaceAll("(&([a-fk-or0-9A-FK-OR]))", "\u00A7$2");
    116. return s;
    117. }

    Thanks for the help :)
     
  17. Offline

    blablubbabc

  18. Offline

    random_username

    Hello, Thanks, it worked. Now I'm having another problem; The BlockBreakEvent and PlayerInteractEvent won't work. Any idea of how to solve this? This is the new code:
    Code:java
    1. @EventHandler
    2. public void onSignCreate(SignChangeEvent event)
    3. {
    4. String prefix = replaceColors(getConfig().getString("Prefix"));
    5. Player player = event.getPlayer();
    6. if(event.getLine(0).equalsIgnoreCase(this.getConfig().getString("Signprefix")))
    7. {
    8. if(player.hasPermission("ecore.signs.admin"))
    9. {
    10. event.setLine(0, ChatColor.AQUA + getConfig().getString("Signprefix"));
    11. if(!(event.getLine(1).equalsIgnoreCase("Premium") || event.getLine(1).equalsIgnoreCase("VIP") || event.getLine(1).equalsIgnoreCase("Legend") || event.getLine(1).equalsIgnoreCase("Store")))
    12. {
    13. player.sendMessage(prefix + ChatColor.RED + "Invalid Sign!");
    14. event.setCancelled(true);
    15. }
    16. else
    17. {
    18. player.sendMessage(prefix + ChatColor.BLUE + "Sign has been created!");
    19. }
    20. if(event.getLine(1).equalsIgnoreCase("Premium")) event.setLine(1, ChatColor.GREEN + "Premium");
    21. else if(event.getLine(1).equalsIgnoreCase("VIP")) event.setLine(1, ChatColor.GREEN + "VIP");
    22. else if(event.getLine(1).equalsIgnoreCase("Legend")) event.setLine(1, ChatColor.GREEN + "Legend");
    23. else if(event.getLine(1).equalsIgnoreCase("StoreInfo")) event.setLine(1, ChatColor.GREEN + "Store Info");
    24. }
    25. else
    26. {
    27. player.sendMessage(prefix + ChatColor.RED + "You do not have permission to do this!");
    28. event.setCancelled(true);
    29. }
    30. }
    31. }
    32.  
    33. @EventHandler
    34. public void onBlockBreak(BlockBreakEvent event)
    35. {
    36. String prefix = replaceColors(getConfig().getString("Prefix"));
    37. Player player = event.getPlayer();
    38. if(event.getBlock().getState() instanceof Sign)
    39. {
    40. Sign s = (Sign) event.getBlock().getState();
    41. if(s.getLine(0).equalsIgnoreCase(getConfig().getString("Signprefix")))
    42. {
    43. if(player.hasPermission("ecore.signs.admin"))
    44. {
    45. player.sendMessage(prefix + ChatColor.AQUA + "This Enstopia sign has been destroyed!");
    46. }
    47. else
    48. {
    49. event.setCancelled(true);
    50. player.sendMessage(prefix + ChatColor.RED + "You do not have permission to break an Enstopia Sign!");
    51. }
    52. }
    53. }
    54. }
    55.  
    56. @EventHandler
    57. public void onPlayerInteract(PlayerInteractEvent event)
    58. {
    59. String prefix = replaceColors(getConfig().getString("Prefix"));
    60. Player player = event.getPlayer();
    61. Action action = event.getAction();
    62. if(action == Action.RIGHT_CLICK_BLOCK)
    63. {
    64. if(event.getClickedBlock().getState() instanceof Sign)
    65. {
    66. Sign s = (Sign) event.getClickedBlock().getState();
    67. if(s.getLine(0).equalsIgnoreCase(getConfig().getString("Signprefix")))
    68. {
    69. if(player.hasPermission("ecore.signs.use"))
    70. {
    71. if(s.getLine(1).equalsIgnoreCase("Premium"))
    72. {
    73. for(String string : getConfig().getStringList("Premium"))
    74. {
    75. player.sendMessage(replaceColors(string));
    76. }
    77. }
    78. if(s.getLine(1).equalsIgnoreCase("VIP"))
    79. {
    80. for(String string : getConfig().getStringList("VIP"))
    81. {
    82. player.sendMessage(replaceColors(string));
    83. }
    84. }
    85. if(s.getLine(1).equalsIgnoreCase("Legend"))
    86. {
    87. for(String string : getConfig().getStringList("Legend"))
    88. {
    89. player.sendMessage(replaceColors(string));
    90. }
    91. }
    92. if(s.getLine(1).equalsIgnoreCase("Store Info"))
    93. {
    94. for(String string : getConfig().getStringList("Store"))
    95. {
    96. player.sendMessage(replaceColors(string));
    97. }
    98. }
    99. }
    100. else
    101. {
    102. player.sendMessage(prefix + ChatColor.RED + "You do not have permission to do this!");
    103. }
    104. }
    105. }
    106. }
    107. }

    Thanks for the help :)
     
  19. Offline

    blablubbabc

    random_username

    You are coloring the line 0 in the sign change event:
    event.setLine(0, ChatColor.AQUA + getConfig().getString("Signprefix"));

    So you have to compare the line 0 in the interact and block break event with the colored version of your "Signprefix".
    Same goes for the other checks for the other lines.

    As an alternative you could check if your line(s) "contain" the string by doing for example: getSomeLineOfTheSign.toLowerCase().contains(theStringFromYourConfig().toLowerCase());
    or use regex (which are a bit costy though).
     
  20. Offline

    random_username

    And how would I do that? Can you please make an example? :)
     
  21. Offline

    blablubbabc

    See my edit above, or do:
    if(s.getLine(0).equalsIgnoreCase(ChatColor.AQUA + getConfig().getString("Signprefix")))
    instead of
    if(s.getLine(0).equalsIgnoreCase(getConfig().getString("Signprefix")))
     
  22. Offline

    random_username

    It worked! Thanks so much :D
     
Thread Status:
Not open for further replies.

Share This Page