Solved Countdown Not Working

Discussion in 'Plugin Development' started by FabeGabeMC, Mar 1, 2014.

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

    FabeGabeMC

    Hello. I have been experiencing a bug while coding a Countdown.

    Apparently, whenever I run the command to start the countdown, it will only read the first if() statement in the entire class.

    Ex:
    Code:java
    1. public int exampleinteger = 5;
    2. public void run() {
    3. if(exampleinteger != 0){
    4. p.sendMessage("This is an example text."); //Does work
    5. }else if(exampleinteger == 2){
    6. p.sendMessage("This is an example text."); //Doesn't work
    7. }
    8. }


    Proof it doesn't work:
    [​IMG]

    (I was testing another plugin I made don't mind the other chat.)

    Here's my Countdown class:
    Code:java
    1. import java.util.ArrayList;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.entity.Player;
    6. import org.bukkit.potion.PotionEffect;
    7. import org.bukkit.potion.PotionEffectType;
    8.  
    9. public class Countdown implements Runnable {
    10.  
    11. public int number = 1225;
    12. public int numberInTicksSpeed = 100;
    13. public int numberInTicks = 24000;
    14.  
    15. ArrayList<String> alive = new ArrayList<String>();
    16. ArrayList<String> queue = new ArrayList<String>();
    17. ArrayList<String> dead = new ArrayList<String>();
    18. ArrayList<String> spectator = new ArrayList<String>();
    19. ArrayList<String> frozen = new ArrayList<String>();
    20. ArrayList<String> alivepvp = new ArrayList<String>();
    21.  
    22. public void run() {
    23. if(number != -1){
    24. if(number != 0){
    25. number--;
    26. if(number == 1225){
    27. frozen.addAll(queue);
    28. queue.clear();
    29. Bukkit.broadcastMessage(ChatColor.YELLOW + "UHC starts in " + ChatColor.RED + "25" + ChatColor.YELLOW + " seconds!");
    30. number --;
    31. }
    32. }else if(number == 1210){
    33. Bukkit.broadcastMessage(ChatColor.YELLOW + "UHC starts in " + ChatColor.RED + "10" + ChatColor.YELLOW + " seconds!");
    34. }else if(number >= 1199 && number <= 1206){
    35. Bukkit.broadcastMessage(ChatColor.YELLOW + "UHC starts in " + ChatColor.RED + number + ChatColor.YELLOW + " seconds!");
    36. }else if(number == 1200) {
    37. Bukkit.broadcastMessage(ChatColor.DARK_AQUA + "UHC has started! You have 20 minutes of grace period!");
    38. Bukkit.broadcastMessage(ChatColor.GREEN + "Once grace period ends, PVP will be turned on and regeneration will be turned off!");
    39. for(Player allP : Bukkit.getServer().getOnlinePlayers()) {
    40. if(alive.contains(allP)){
    41. allP.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, numberInTicksSpeed, 3));
    42. allP.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, numberInTicks, 3));
    43. }
    44. }
    45. }else if(number == 0){
    46. alivepvp.addAll(alive);
    47. alive.clear();
    48. PlayerListener.Regen(false);
    49. for(Player allP : Bukkit.getServer().getOnlinePlayers()){
    50. if(alive.contains(allP) || alivepvp.contains(allP)){
    51. allP.removePotionEffect(PotionEffectType.REGENERATION);
    52. }
    53. Bukkit.broadcastMessage(ChatColor.RED + "Grace period is over! PVP has been turned on and regeneration has been turned off!");
    54. }
    55. }
    56. }
    57. }
    58. }


    And here is the code to start the actual timer:

    Code:java
    1. if(args[0].equalsIgnoreCase("start")) {
    2. if(p.hasPermission("uhc.start")){
    3. Bukkit.broadcastMessage(ChatColor.RED + "UHC countdown started!");
    4. this.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Countdown(), 0L, 20L);
    5. }
    6. }


    If this would be fixed, I would thank you guys for the support.

    Thanks,

    FabeGabe
     
  2. Offline

    Gater12

    FabeGabeMC
    I will walk you through the first code.
    You are basically saying 'if variable exampleinteger doesn't equal to 0 else if the exampleinetger is equalled to 2' It will never trigger the second if, if the exampleinteger is greater than 0. And if the if returns false and triggers the second if condition, it will never return true, because in order to trigger that if condition you need to have the first to be false and exampleinetger would be 0 or less.
     
  3. Offline

    FabeGabeMC

    Gater12 So what would be the code for it?
     
  4. Offline

    Gater12

  5. Offline

    FabeGabeMC

    Gater12
    All of them or just 1 in specific?

    Gater12 Okay. Thanks for the countdown but like the effects like potion effects and such don't trigger on the countdown end.

    Code:java
    1. if(alive.contains(allP)){
    2. allP.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, numberInTicksSpeed, 3));
    3. allP.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, numberInTicks, 3));
    4.  
    5. //Doesn't work


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

Share This Page