Solved for each player don't work

Discussion in 'Plugin Development' started by nastasescu, Sep 6, 2014.

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

    nastasescu

    So, a random player will receive everything random...
    Code:java
    1. public void kp1timer() {
    2. getServer().getScheduler().scheduleSyncRepeatingTask(this,
    3. new Runnable() {
    4. public void run() {
    5. for (Player player : Bukkit.getOnlinePlayers()) {
    6. if (joc1kitpvp.contains(player)) {
    7. if (pl1kitpvp >= 2) {
    8. kp1timerstart -= 1;
    9. if (kp1timerstart == 0) {
    10. Bukkit.broadcastMessage(ChatColor.BLUE
    11. + "Game> " + ChatColor.GRAY
    12. + "KitPVP #1 has started!");
    13. if (getKit(player) == "Warrior") {
    14. player.getInventory().clear();
    15. player.getInventory()
    16. .setHelmet(
    17. new ItemStack(
    18. Material.LEATHER_HELMET));
    19. player.getInventory()
    20. .setChestplate(
    21. new ItemStack(
    22. Material.LEATHER_CHESTPLATE));
    23. player.getInventory()
    24. .setLeggings(
    25. new ItemStack(
    26. Material.LEATHER_LEGGINGS));
    27. player.getInventory()
    28. .setBoots(
    29. new ItemStack(
    30. Material.LEATHER_BOOTS));
    31. player.getInventory()
    32. .addItem(
    33. new ItemStack(
    34. Material.IRON_SWORD));
    35. player.getInventory()
    36. .setArmorContents(null);
    37. }
    38. kp1s = 1;
    39. player.sendMessage(ChatColor.GREEN
    40. + "===================================================");
    41. player.sendMessage(ChatColor.BOLD + ""
    42. + ChatColor.UNDERLINE
    43. + "KitPVP");
    44. player.sendMessage("");
    45. player.sendMessage("All you have to do is to kill players in just 3 minutes!");
    46. player.sendMessage("");
    47. player.sendMessage(ChatColor.GREEN
    48. + "===================================================");
    49. kp1timersend = 180;
    50. player.sendMessage(ChatColor.BLUE
    51. + "Game> " + ChatColor.GRAY
    52. + kp1timersend
    53. + " seconds remaining.");
    54. }
    55. if (kp1timerstart == 59
    56. || kp1timerstart == 50
    57. || kp1timerstart == 40
    58. || kp1timerstart == 30
    59. || kp1timerstart == 25
    60. || kp1timerstart == 20
    61. || kp1timerstart == 15
    62. || (kp1timerstart <= 10 && kp1timerstart >= 1)) {
    63. player.sendMessage(ChatColor.YELLOW
    64. + "The game will start in "
    65. + ChatColor.GOLD
    66. + ChatColor.BOLD
    67. + kp1timerstart
    68. + ChatColor.RESET
    69. + ChatColor.YELLOW
    70. + " seconds.");
    71. if (kp1timerstart <= 10
    72. && kp1timerstart > 3) {
    73. player.playSound(
    74. player.getLocation(),
    75. Sound.NOTE_STICKS, 1, 1);
    76. } else if (kp1timerstart <= 3
    77. && kp1timerstart >= 1) {
    78. player.playSound(
    79. player.getLocation(),
    80. Sound.NOTE_PIANO, 1, 1);
    81. }
    82. }
    83. } else {
    84. kp1timerstart = 60;
    85. }
    86. if (kp1timerstart == 0
    87. && joc1kitpvp.contains(player)) {
    88. player.playSound(player.getLocation(),
    89. Sound.NOTE_PLING, 1, 1);
    90. }
    91. if (kp1timersend >= 1 || kp1timersend <= 180) {
    92. kp1timersend--;
    93. if (kp1timersend >= 20
    94. && kp1timersend <= 180) {
    95. if (kp1timersend % 20 == 0) {
    96. player.sendMessage(ChatColor.BLUE
    97. + "Game> " + ChatColor.GRAY
    98. + kp1timersend
    99. + " seconds remaining.");
    100. }
    101. }
    102. if (kp1timersend == 10 || kp1timersend == 5
    103. || kp1timersend == 3
    104. || kp1timersend == 2) {
    105. player.sendMessage(ChatColor.BLUE
    106. + "Game> " + ChatColor.GRAY
    107. + kp1timersend
    108. + " seconds remaining.");
    109. }
    110. if (kp1timersend == 1) {
    111. player.sendMessage(ChatColor.BLUE
    112. + "Game> " + ChatColor.GRAY
    113. + "1 second remaining.");
    114. kp1timersend = -1;
    115. player.teleport(Bukkit
    116. .getWorld("world")
    117. .getSpawnLocation());
    118. kp1s = 0;
    119. pl1kitpvp = 0;
    120. kp1timerstart = 60;
    121. removeKit(player);
    122. for (PotionEffect effect : player
    123. .getActivePotionEffects()) {
    124. player.removePotionEffect(effect
    125. .getType());
    126. }
    127. player.addPotionEffect(new PotionEffect(
    128. PotionEffectType.SPEED,
    129. 999999999, 3));
    130. player.sendMessage(ChatColor.GREEN
    131. + "===================================================");
    132. player.sendMessage(ChatColor.DARK_AQUA
    133. + "Nickname: "
    134. + ChatColor.YELLOW + ""
    135. + player.getName());
    136. player.sendMessage(ChatColor.DARK_AQUA
    137. + "You received:");
    138. player.sendMessage(ChatColor.GREEN
    139. + "- 10 Gems - Participation");
    140. economy.depositPlayer(player, 10);
    141. player.sendMessage(ChatColor.DARK_AQUA
    142. + "You have "
    143. + ChatColor.GREEN
    144. + ""
    145. + (int) economy
    146. .getBalance(player)
    147. + " Gems" + ChatColor.DARK_AQUA
    148. + "!");
    149. player.sendMessage(ChatColor.GREEN
    150. + "===================================================");
    151. player.getInventory().clear();
    152. player.getInventory().setArmorContents(
    153. null);
    154. }
    155. }
    156. }
    157. }
    158. }
    159.  
    160. }, 20L, 20L);
    161. }

    and photo for me: http://imgur.com/FPrYJNS and my friend: http://imgur.com/2BUTRqL,At9Lnvl

    I changed the craftbukkit in build path and now eclipse says the getOnlinePlayers is deprecated.

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

    Deleted user

    nastasescu
    I really suggest you learn some more Java before you make a Mineplex clone

    nastasescu
    ...
    You're an idiot. Everything you've done in your code is a copy of Mineplex
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Feb 6, 2022
  3. Offline

    teej107

    Are you using NMS? If not, build against Bukkit, not CraftBukkit. What's your problem exactly?
     
  4. Offline

    nastasescu

    Last edited by a moderator: Jun 14, 2016
  5. Offline

    Totom3

    zombiekiller753 That's kinda rude.... nastasescu I don't see the problem, but I highly suggest you start by making separate methods, one for pre-game, one for the game itself, etc... The runnable should only decrease the timer and call the appropriate methods at the appropriate time. A few tips :
    • Give your variables/methods readable names. If you don't get confused, we certainly do.
    • Compare Strings with .equals() and .equalsIgnoreCase(). Never with '=='
    • The code will not execute properly if the name of the world is not exactly "world"; you should change that.
    • You forgot to cancel the task when the game ends.
    • Don't use like 10 indents in your code; it makes it very hard to read (combined with the 2,000 if/else statements, it's very hard). Imagine if you have a silent error and you're trying to understand why.. God, good luck.
     
    nastasescu likes this.
  6. Offline

    Zarkopafilis

    Mineplex's not the first server and not everything is stolen....
    I think Bukkit.getServer().getOnlinePlayers() will work
     
    nastasescu likes this.
  7. Offline

    bennie3211

    But calling people an idiot is not nice :')
     
  8. Offline

    nastasescu

  9. Offline

    niko454

    zombiekiller753
    Yeah zombiekiller doesn't help at all. He's just a troll and tells everybody to learn java. When I asked for help with the oneat event he just told me to go learn java -.-
     
  10. Offline

    bennie3211

    nastasescu I know, but doing the same back won't help you or someone else...

    niko454 that is because the most questions on the forums are "spoon-feed" questions, like "where do i have to place it?" Or "Can you show me how to do?". But (im not sure if it is for this thread) if someone is copying and pasting someone else his code and ask a question about it, the only correct answer for it is: "first learn java" because copying pasting wont help you farther ;)
     
  11. Offline

    Zarkopafilis

    To be honest most people here think that know java if they learn half or less of the bukkit API
     
Thread Status:
Not open for further replies.

Share This Page