Solved signs...

Discussion in 'Plugin Development' started by Juancomaster1998, Dec 4, 2014.

Thread Status:
Not open for further replies.
  1. Hello!
    I`m just trying to make signs for join arenas, but I`m having problems with refreshing the players playing the arena.
    This is what I have:
    Code:java
    1. @EventHandler
    2. public void onSignChange(SignChangeEvent e) {
    3. if (e.getLine(0).equals("[BomberCraft]") && e.getLine(1).equals("Join") && e.getLine(2).contains((CharSequence) settings.getArenas().getList("arenas")) && e.getLine(3) != null) {
    4. String arena = e.getLine(2);
    5. String l1 = getConfig().getString("Signs.Join.Line1");
    6. l1 = l1.replaceAll("&", "§");
    7. String l2 = getConfig().getString("Signs.Join.Line2");
    8. l2 = l2.replaceAll("&", "§");
    9. String l3 = getConfig().getString("Signs.Join.Line3");
    10. l3 = l3.replaceAll("&", "§");
    11. String l4 = getConfig().getString("Signs.Join.Line4");
    12. l4 = l4.replaceAll("&", "§");
    13. l1 = l1.replaceAll("%arena%", arena);
    14. l2 = l2.replaceAll("%arena%", arena);
    15. l3 = l3.replaceAll("%arena%", arena);
    16. l4 = l4.replaceAll("%arena%", arena);
    17. l1 = l1.replaceAll("%players%", Integer.toString(settings.getArenas().getStringList("arenas." + arena + ".playing").size()));
    18. l2 = l2.replaceAll("%players%", Integer.toString(settings.getArenas().getStringList("arenas." + arena + ".playing").size()));
    19. l3 = l3.replaceAll("%players%", Integer.toString(settings.getArenas().getStringList("arenas." + arena + ".playing").size()));
    20. l4 = l4.replaceAll("%players%", Integer.toString(settings.getArenas().getStringList("arenas." + arena + ".playing").size()));
    21. l1 = l1.replaceAll("%max%", settings.getArenas().getString("arenas." + arena + ".maxplayers"));
    22. l2 = l2.replaceAll("%max%", settings.getArenas().getString("arenas." + arena + ".maxplayers"));
    23. l3 = l3.replaceAll("%max%", settings.getArenas().getString("arenas." + arena + ".maxplayers"));
    24. l4 = l4.replaceAll("%max%", settings.getArenas().getString("arenas." + arena + ".maxplayers"));
    25. e.setLine(0, l1);
    26. e.setLine(1, l2);
    27. e.setLine(2, l3);
    28. e.setLine(3, l4);
    29. }
    30. }
    31.  
    32. public void onScheduler() {
    33. Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
    34. public void run() {
    35. Iterator<?> arena = settings.getArenas().getList("arenas").iterator();
    36. l1 = l1.replaceAll("%players%", Integer.toString(settings.getArenas().getStringList("arenas." + arena + ".playing").size()));
    37. l2 = l2.replaceAll("%players%", Integer.toString(settings.getArenas().getStringList("arenas." + arena + ".playing").size()));
    38. l3 = l3.replaceAll("%players%", Integer.toString(settings.getArenas().getStringList("arenas." + arena + ".playing").size()));
    39. l4 = l4.replaceAll("%players%", Integer.toString(settings.getArenas().getStringList("arenas." + arena + ".playing").size()));
    40. }
    41.  
    42. }, 10, 10);
    43. }


    The scheduler probably doesn`t make sense, I tried to make a scheduleSyncRepeatingTask, but I realised I dont know how to obtain the name of the arena (on really not even obtaining the sign)

    Here`s the config if u want see it:
    Code:
    Signs:
        Join:
            Line1: "&3&o[&c&oBomberCraft&3&o]"
            Line2: "&bJoin &a%arena%"
            Line3: "&5%players%&4/%max%"s
            Line4:
    Thanks! :D
     
  2. Offline

    kreashenz

    In the onSignChange method, at the bottom put ((Sign) e.getBlock()).update(); and that should start working.
     
    Experminator likes this.
  3. Offline

    Experminator

  4. Thanks a lot!

    Code:java
    1. public void onSignChange(SignChangeEvent e) {
    2. if (e.getLine(0).equals("[BomberCraft]") && e.getLine(1).equals("Join") && e.getLine(2).contains((CharSequence) settings.getArenas().getList("arenas")) && e.getLine(3) != null) {
    3. String arena = e.getLine(2);
    4. String l1 = getConfig().getString("Signs.Join.Line1");
    5. l1 = l1.replaceAll("&", "§");
    6. String l2 = getConfig().getString("Signs.Join.Line2");
    7. l2 = l2.replaceAll("&", "§");
    8. String l3 = getConfig().getString("Signs.Join.Line3");
    9. l3 = l3.replaceAll("&", "§");
    10. String l4 = getConfig().getString("Signs.Join.Line4");
    11. l4 = l4.replaceAll("&", "§");
    12. l1 = l1.replaceAll("%arena%", arena);
    13. l2 = l2.replaceAll("%arena%", arena);
    14. l3 = l3.replaceAll("%arena%", arena);
    15. l4 = l4.replaceAll("%arena%", arena);
    16. l1 = l1.replaceAll("%players%", Integer.toString(settings.getArenas().getStringList("arenas." + arena + ".playing").size()));
    17. l2 = l2.replaceAll("%players%", Integer.toString(settings.getArenas().getStringList("arenas." + arena + ".playing").size()));
    18. l3 = l3.replaceAll("%players%", Integer.toString(settings.getArenas().getStringList("arenas." + arena + ".playing").size()));
    19. l4 = l4.replaceAll("%players%", Integer.toString(settings.getArenas().getStringList("arenas." + arena + ".playing").size()));
    20. l1 = l1.replaceAll("%max%", settings.getArenas().getString("arenas." + arena + ".maxplayers"));
    21. l2 = l2.replaceAll("%max%", settings.getArenas().getString("arenas." + arena + ".maxplayers"));
    22. l3 = l3.replaceAll("%max%", settings.getArenas().getString("arenas." + arena + ".maxplayers"));
    23. l4 = l4.replaceAll("%max%", settings.getArenas().getString("arenas." + arena + ".maxplayers"));
    24. e.setLine(0, l1);
    25. e.setLine(1, l2);
    26. e.setLine(2, l3);
    27. e.setLine(3, l4);
    28. }
    29. ((Sign) e.getBlock()).update();
    30. }

    I`m getting a crash on "((Sign) e.getBlock()).update();", why?

    **Edit:**

    Ohh, and too on
    Code:
    if (e.getLine(0).equals("[BomberCraft]") && e.getLine(1).equals("Join") && e.getLine(2).contains((CharSequence) settings.getArenas().getList("arenas")) && e.getLine(3) != null) {
    <Edit by mrCookieSlime: Merged posts. Please don't double post. There is an Edit Button right next to the Date.>
     
  5. Offline

    SuperOriginal

    Maybe use e.getBlock().getState()
     
  6. thanks, but what to do on the edited one?
     
  7. Offline

    SuperOriginal

    Juancomaster1998 Well it's hard to tell without the stacktrace *hint hint wink wink*

    What exactly are you checking in line(2)?
     
  8. I`m checking if the arena exists, and if it does, putting the name of the arena
     
  9. Offline

    SuperOriginal

    You're not doing that correctly. You're checking if a string contains a list of strings.

    Loop through all your arenas and check if line2 equals one of them
     
  10. how?

    **Edited**
    How to get an specific key from a list?
    for example. I have on my config:
    Code:
    arenas:
        hello:
     
        test:
     
        Ilikepizza:
    So I want to obtain "hello" when a n = 1, "test" when n = 2, "Ilikepizza" when n = 3 and so.

    Please, cant any1 help me? I`m deeply stuck! D:

    PD: Skionz 2hs 20 mins.

    Please!
    I don`t know how to loop through configuration section arenas and get the keys. And I didn`t found help anywhere D:!
    I need to solve this, please, any1 help me, thanks a lot!

    <Edit by mrCookieSlime: Merged posts. Please don't double post. There is an Edit Button right next to the Date.>

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

    teej107

    Juancomaster1998 Patience. Wait while somebody finds your answer. In the mean time while you wait, you can continue to find the answer for yourself.
     
    SuperOriginal likes this.
  12. Offline

    SuperOriginal

    ConfigurationSection#getKeys(false) + enhanced for loop = profit
     
  13. What do you mean by profit?

    teej107 Thanks for adviceing, but I was the whole day with the same crash on the same line, I think I modified it like 40 or 50 times and still not finding the solution.
     
  14. Offline

    SuperOriginal

    Juancomaster1998 it doesn't mean anything important. Just a slang term for "success" in this context. Just implement the for loop and use the method I showed you.
     
  15. Offline

    Skionz

  16. Last two questions:
    - Where to say the path? (on this case: "arenas.")
    - How to get only 1 of the keys? It`s getKeys a List?

    Okey, I`ll read them

    <Edit by mrCookieSlime: Merged posts. Please don't double post. There is an Edit Button right next to the Date.>
     
  17. Offline

    Skionz

    Juancomaster1998 If you only need one key why not use FileConfiguration#getString(key, value)?
     
  18. Because I dont know the key`s name and I need to check if the key exists, and if it exists, return the key.

    Well, thanks anyway ^^
    I think I can solve this with that
    Thanks for help! :D

    <Edit by mrCookieSlime: Merged posts. Please don't double post. There is an Edit Button right next to the Date.>
     
  19. Offline

    SuperOriginal

    Juancomaster1998
    - State the path when getting the configurationsection
    - If you want to check if the key exists, then you need a list of ALL existing keys to compare it to... right?
     
  20. Solved!
    If any1 needs something like that, there`s the code:
    Code:java
    1. @EventHandler
    2. public void onSignChange(SignChangeEvent e) {
    3. String ll1 = null;
    4. String ll2 = null;
    5. String ll3 = null;
    6. String ll4 = null;
    7. if (!(e.getLine(0).isEmpty())) {
    8. ll1 = e.getLine(0);
    9. }
    10.  
    11. if (!(e.getLine(1).isEmpty())) {
    12. ll2 = e.getLine(1);
    13. }
    14.  
    15. if (!(e.getLine(2).isEmpty())) {
    16. ll3 = e.getLine(2);
    17. }
    18.  
    19. if (!(e.getLine(3).isEmpty())) {
    20. ll4 = e.getLine(3);
    21. }
    22.  
    23. if (e.getLine(0).equals("[BomberCraft]") && e.getLine(1).equals("Join")) {
    24. if (e.getLine(3).isEmpty()) {
    25. e.getPlayer().sendMessage(ChatColor.RED + "Debes especificar un id para el cartel!");
    26. return;
    27. }
    28. if (!(e.getLine(2).isEmpty())) {
    29. boolean a = false;
    30. boolean b = false;
    31. boolean c = false;
    32. boolean d = false;
    33. boolean f = false;
    34. int size = settings.getArenas().getConfigurationSection("arenas").getKeys(false).size();
    35. for (int n = 1; n < size-1; n++) {
    36. Set<String> ar = settings.getArenas().getConfigurationSection("arenas").getKeys(false);
    37. if (ar.contains(ll1)) {
    38. f = true;
    39. a = true;
    40. }
    41.  
    42. if (ar.contains(ll2)) {
    43. f= true;
    44. b = true;
    45. }
    46.  
    47. if (ar.contains(ll3)) {
    48. f = true;
    49. c = true;
    50. }
    51.  
    52. if (ar.contains(ll4)) {
    53. f = true;
    54. d = true;
    55. }
    56. }
    57. String arena = null;
    58. String sign = e.getLine(3);
    59. if (a == true) {
    60. arena = e.getLine(0);
    61. }
    62. if (b == true) {
    63. arena = e.getLine(1);
    64. }
    65. if (c == true) {
    66. arena = e.getLine(2);
    67. }
    68. if (d == true) {
    69. arena = e.getLine(3);
    70. }
    71.  
    72. if (f == true) {
    73. if (!(getConfig().get("Signs.Join.Line1").equals(null))) {
    74. String l1 = getConfig().get("Signs.Join.Line1").toString();
    75. if (l1.contains("&")) {
    76. l1 = l1.replaceAll("&", "§");
    77. }
    78.  
    79. if (l1.contains("%arena%")) {
    80. l1 = l1.replaceAll("%arena%", arena);
    81. }
    82.  
    83. if (l1.contains("%players%")) {
    84. l1 = l1.replaceAll("%players%", Integer.toString(settings.getArenas().getStringList("arenas." + arena + ".playing").size()));
    85. }
    86.  
    87. if (l1.contains("%max%")) {
    88. l1 = l1.replaceAll("%max%", settings.getArenas().getString("arenas." + arena + ".maxplayers"));
    89. }
    90.  
    91. e.setLine(0, l1);
    92. } else { }
    93.  
    94. if (!(getConfig().get("Signs.Join.Line2").equals(null))) {
    95. String l2 = getConfig().get("Signs.Join.Line2").toString();
    96. if (l2.contains("&")) {
    97. l2 = l2.replaceAll("&", "§");
    98. }
    99.  
    100. if (l2.contains("%arena%")) {
    101. l2 = l2.replaceAll("%arena%", arena);
    102. }
    103.  
    104. if (l2.contains("%players%")) {
    105. l2 = l2.replaceAll("%players%", Integer.toString(settings.getArenas().getStringList("arenas." + arena + ".playing").size()));
    106. }
    107.  
    108. if (l2.contains("%max%")) {
    109. l2 = l2.replaceAll("%max%", settings.getArenas().getString("arenas." + arena + ".maxplayers"));
    110. }
    111.  
    112. e.setLine(1, l2);
    113. } else { }
    114.  
    115. if (!(getConfig().get("Signs.Join.Line3").equals(null))) {
    116. String l3 = getConfig().get("Signs.Join.Line3").toString();
    117. if (l3.contains("&")) {
    118. l3 = l3.replaceAll("&", "§");
    119. }
    120.  
    121. if (l3.contains("%arena%")) {
    122. l3 = l3.replaceAll("%arena%", arena);
    123. }
    124.  
    125. if (l3.contains("%players%")) {
    126. l3 = l3.replaceAll("%players%", Integer.toString(settings.getArenas().getStringList("arenas." + arena + ".playing").size()));
    127. }
    128.  
    129. if (l3.contains("%max%")) {
    130. l3 = l3.replaceAll("%max%", settings.getArenas().getString("arenas." + arena + ".maxplayers"));
    131. }
    132.  
    133. e.setLine(2, l3);
    134. } else { }
    135.  
    136. if (!(getConfig().get("Signs.Join.Line4").equals(null))) {
    137. String l4 = getConfig().get("Signs.Join.Line4").toString();
    138. if (l4.contains("&")) {
    139. l4 = l4.replaceAll("&", "§");
    140. }
    141.  
    142. if (l4.contains("%arena%")) {
    143. l4 = l4.replaceAll("%arena%", arena);
    144. }
    145.  
    146. if (l4.contains("%players%")) {
    147. l4 = l4.replaceAll("%players%", Integer.toString(settings.getArenas().getStringList("arenas." + arena + ".playing").size()));
    148. }
    149.  
    150. if (l4.contains("%max%")) {
    151. l4 = l4.replaceAll("%max%", settings.getArenas().getString("arenas." + arena + ".maxplayers"));
    152. }
    153.  
    154. e.setLine(3, l4);
    155. } else { }
    156. ((Sign) e.getBlock().getState()).update();
    157. settings.create(this, sign);
    158. settings.getSign().set("id", sign);
    159. settings.getSign().set("position.x", e.getBlock().getX());
    160. settings.getSign().set("position.y", e.getBlock().getY());
    161. settings.getSign().set("position.z", e.getBlock().getZ());
    162. settings.saveSign();
    163. }
    164. else {
    165. e.getPlayer().sendMessage(ChatColor.RED + "Arena Inexistente!");
    166. return;
    167. }
    168. }
    169. else {
    170. e.getPlayer().sendMessage(ChatColor.RED + "Cartel incorrecto!");
    171. return;
    172. }
    173. }
    174. }


    The problem was that I`ve never created the file config.yml :geniuz:
    Thanks all!
     
    ProMCKingz likes this.
  21. Offline

    Experminator

    Juancomaster1998 likes this.
  22. Offline

    ProMCKingz

    Juancomaster1998 likes this.
Thread Status:
Not open for further replies.

Share This Page