How to get this so it doesn't spam the message.

Discussion in 'Plugin Development' started by KmanCrazy, May 12, 2014.

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

    KmanCrazy

    http://pastebin.com/wUXvFQh0
    I have an issue where it spams it and it multiplies every time it repeats. Can I have some help?

    boomp?

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

    Mayoz

    I'd be nice if you were more descriptive and could tell us what's wrong. I don't want to read the that whole thing just to find what you could have told us is wrong.
     
  3. Offline

    KmanCrazy

    Sorry your right I should be more descriptive, I dontknow if I can paste the whole code. But all I know is that it spams the message that goes to all players in the game. I think it is because of the loop but I want another persons opinion and how I could fix it.
    Code:java
    1. public void onJoin(PlayerJoinEvent e){
    2. Player p = e.getPlayer();
    3. e.setJoinMessage(prefix + ChatColor.BLUE + " Welcome " + e.getPlayer().getDisplayName() + ", to Random Minigames!");
    4. playersingame.add(e.getPlayer().getName());
    5. p.teleport(new Location(Bukkit.getWorld("McUltraGames"), 3, 98, 0));
    6. //if (playersingame.size() == 1){
    7. //}
    8. }
    9. @EventHandler
    10. public void onJoinSort(PlayerJoinEvent e) {
    11. Player p = e.getPlayer();
    12. if (lobby == true) {
    13. p.sendMessage(ChatColor.BLUE + "The game will be starting shortly!!! If you get enough players!");
    14. if (playersingame.size() >= 2) {
    15. for (String s : playersingame) {
    16. Bukkit.getPlayer(s).sendMessage(prefix + ChatColor.BLUE + " The game is starting in 10 seconds! Vote now donators!");
    17.  
    18. new BukkitRunnable() {
    19. @Override
    20. public void run() {
    21. pickGame();
    22.  
    23. }
    24. }.runTaskLater(this, 100);
    25. }
    26. }
    27. }
    28. }
    29. @EventHandler
    30. public void onJoinGo(PlayerJoinEvent e){
    31. if (lobby == false){
    32. //if player is not in lobby!
    33. e.getPlayer().sendMessage(ChatColor.RED + "You have joined while a game is in process. Please wait until the next games starts! :)");
    34.  
    35. }
    36. }
    37.  
    38. @EventHandler
    39. public void onLeave(PlayerQuitEvent e) {
    40. e.setQuitMessage(prefix + ChatColor.BLUE + e.getPlayer().getDisplayName() + " has left Random Minigames!");
    41. playersingame.remove(e.getPlayer().getName());
    42. }
    43. public void lobby() {
    44. for (String s : playersingame) {
    45. Player ig = Bukkit.getPlayer(s);
    46. ig.sendMessage(ChatColor.LIGHT_PURPLE + "The game will be chosen in 10 seconds! Vote now donators!");
    47.  
    48. new BukkitRunnable() {
    49. @Override
    50. public void run() {
    51.  
    52. }
    53. }.runTaskLater(this, 200);
    54. pickGame();
    55. }
    56. }
    57.  
    58. public void pickGame() {
    59. if (g1 > g2 && (g1 > g3)) {
    60. game1();
    61. } else if (g2 > g1 && (g2 > g3)) {
    62. game2();
    63. } else if (g3 > g1 && (g3 > g2)) {
    64. game3();
    65. } else {
    66. Random rand = new Random();
    67. int n = rand.nextInt(3);
    68. switch (n){
    69. case 1:
    70. game1();
    71. break;
    72. case 2:
    73. game2();
    74. break;
    75. case 3:
    76. game3();
    77. break;
    78. default:
    79. game1();
    80. break;
    81. }
    82. }
    83. }
    84. public void timer1() {
    85. if (playersingame.size() >= 2) {
    86. if (game_here == true) {//This is where you would put how long each game is and how long it will take to play blahahahahahahahah. You can also do announcements and a bunch of other stuff!
    87. new BukkitRunnable() {
    88. @Override
    89. public void run() {
    90. for (String s : playersingame) {
    91. game_here = false;
    92.  
    93.  
    94. Player ig = Bukkit.getPlayer(s);
    95. ig.sendMessage(ChatColor.RED + "KmanCrazy won the game == game 1");
    96. lobby = true;
    97. ig.teleport(lobbyspawn);
    98. lobby();
    99.  
    100. }
    101.  
    102. }
    103. }.runTaskLater(this, 100);
    104. }
    105. }
    106. }
    107. public void timer2() {
    108. if (game_here2 == true) {
    109. new BukkitRunnable() {
    110. @Override
    111. public void run() {
    112. for (String s : playersingame) {
    113. game_here2 = false;
    114. Player ig = Bukkit.getPlayer(s);
    115. ig.sendMessage(ChatColor.RED + "Aaron won the game == game 2");
    116. lobby();
    117. }
    118. }
    119. }.runTaskLater(this, 100);
    120. }
    121. }
    122. public void timer3 () {
    123. if (game_here3 == true) {
    124. new BukkitRunnable() {
    125. @Override
    126. public void run() {
    127. for (String s : playersingame) {
    128. game_here3 = false;
    129. Player ig = Bukkit.getPlayer(s);
    130. ig.sendMessage(ChatColor.RED + "Hunter won the game == game 2");
    131. lobby();
    132. }
    133. }
    134. }.runTaskLater(this, 100);
    135. }
    136. }
     
  4. Offline

    tryy3

    KmanCrazy
    what message?
    and is the message being sent constantly or just on a specific event?
     
  5. Offline

    KmanCrazy

    tryy3
    It is all the events and methods being constantly reused and tried again. It is weird. It just spams the
    1. ig.sendMessage(ChatColor.RED + "KmanCrazy won the game == game 1");
     
  6. Offline

    tryy3

    Events are supposed to be runned when they are fired (example PlayerJoinEvent will always be called if someone joins)

    and you got a bit loop going on here... lobby() runs pickGame() on line 85, pickGame() runs Game(), Game() runs timer() , timer() runs lobby()
     
  7. Offline

    KmanCrazy

    tryy3
    Yes I realize that it is a loop that is what it is made to do. But what I really want it to do is not spam the message constantly. When the timer runs off (The end of the game) i want it to say the winner only once.
    Same with all the other messages. I think the bukkitrunnable is activated every time one person joins. Is this true and how would i fix it?

    Xyplo
    ... Do you understand what I am talking about? I am saying I don't want it to spam. When the bukkit runnable happens, I don't want it to activate the pick game multiple times. Did you even read what you just quoted?

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

    Lolmewn

    Dat backdoor though, lol.
     
    TheSpherret likes this.
  9. Offline

    KmanCrazy

  10. Offline

    Lolmewn

    KmanCrazy If you're banned, unban? Silly backdoor ;) Never gonna get accepted on DBO anyway.
     
  11. Offline

    Xyplo

    I quoted the wrong thing. Messags didn't show when I replied to the thread. Sorry :)
     
  12. Offline

    KmanCrazy

    Oh that backdoor is supposed to be there. Sorry if that seems scary, the owner of the server said it was ok. I have a "killswitch" because he says that he will pay me. It is completely fine with the owner and if i ever programmed for someone i would tell them if i was putting a backdoor on. And also this isn't for public... So don't go being a jerk about it Lolmewn it is a plugin that I am custom creating. He knows and everything. I though bukkit dev staff were supposed to help. Obviously Im wrong...

    Xyplo No prob just though you were talking about that :p

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

Share This Page