Timer Repeats When i don't Want

Discussion in 'Plugin Development' started by Wazup93, Sep 9, 2013.

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

    Wazup93

    Hi All Again ..
    I Got Another Problem In My Plugin ...
    My Timer is a repeating Timer So If its 60 Seconds left .. It Gives u a Warn That Remains A Min
    But It Just repeats Something Wrong As Well ...
    First Of All Before The Timing It Give you A Warn That Someone Came And His Number Of Players In Game .. Like Here Its [ 2 / 100 ] Whatever was it ..
    It Gives you The Warn Of The Min But it Freaky Repeats The [ 2 / 100 ] !!!!
    I Want It To Repeat When Its 10 Seconds So Player Know Its Working And Time Remaining But Even When Its On The [ 2 / 100 ] It Doesn't Stop Even When Its 0 And It Continues To - In The Code Of [ 2 / 100 ]
    And For Some Reason I Made It Correct And it made what I wanted Before of it with a day .. After It I Added Some Codes And Now Its Not Working ..
    I Want It As Following
    Warning 1 : 60 Seconds Left ( 1 Min )
    Warning 2 : 30 Seconds Left
    Warning 3 : A Couple Of Warns From 10 To 0 Then My Commands I Made Go All On ..
    As Well The Code Is :
    Code:java
    1. if(enabledPlayers.size() == 1) {
    2. this.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
    3. int Seconds = 61;
    4.  
    5. public void run() {
    6. //code that you want to run in 30 seconds
    7. Seconds--;
    8. for(String p : enabledPlayers) {
    9. Bukkit.getPlayerExact(p).sendMessage(ChatColor.BLACK + "[" + ChatColor.AQUA + "TNTWarZ" + ChatColor.BLACK + "] " + ChatColor.GRAY + "[ 2 / 100 ]");
    10. if(Seconds == 60) {
    11. if(Bukkit.getOfflinePlayer(p).isOnline()){
    12. Bukkit.getPlayerExact(p).sendMessage(ChatColor.BLACK + "[" + ChatColor.AQUA + "TNTWarZ" + ChatColor.BLACK + "] " + ChatColor.GRAY + "Game Will Start After A Min !");
    13. }
    14. if(Seconds == 30) {
    15. if(Bukkit.getOfflinePlayer(p).isOnline()){
    16. Bukkit.getPlayerExact(p).sendMessage(ChatColor.BLACK + "[" + ChatColor.AQUA + "TNTWarZ" + ChatColor.BLACK + "] " + ChatColor.GRAY + "Game Will Start After 30 Sec !");
    17. }
    18. }
    19. if(Seconds == 10) {
    20. if(Bukkit.getOfflinePlayer(p).isOnline()){
    21. Bukkit.getPlayerExact(p).sendMessage(ChatColor.BLACK + "[" + ChatColor.AQUA + "TNTWarZ" + ChatColor.BLACK + "] " + ChatColor.GRAY + "Game Will Start In " + Seconds);
    22. }
    23. }
    24.  
    25. if(Seconds == 0) {
    26. if(Bukkit.getOfflinePlayer(p).isOnline()){
    27. int xx = getConfig().getInt("Lobby2" + ".x"), yy = getConfig().getInt("Lobby2" + ".y"), zz = getConfig().getInt("Lobby2" + ".z");
    28. player.teleport(new Location(player.getWorld(), xx, yy, zz));
    29. Bukkit.getPlayerExact(p).sendMessage(ChatColor.BLACK + "[" + ChatColor.AQUA + "TNTWarZ" + ChatColor.BLACK + "] " + ChatColor.GRAY + "Welcome To Lobby2 !");
    30. Bukkit.getScheduler().cancelAllTasks();
    31. Gaming.add(playerName);
    32. }
    33. }
    34. if(enabledPlayers.size() == 4) {
    35. Bukkit.getScheduler().cancelAllTasks();
    36. if(Bukkit.getOfflinePlayer(p).isOnline()){
    37. Bukkit.getPlayerExact(p).sendMessage(ChatColor.BLACK + "[" + ChatColor.AQUA + "TNTWarZ" + ChatColor.BLACK + "] " + ChatColor.GRAY + "[ 4 / 100 ]");
    38. Bukkit.getPlayerExact(p).sendMessage(ChatColor.BLACK + "[" + ChatColor.AQUA + "TNTWarZ" + ChatColor.BLACK + "] " + ChatColor.GRAY + "CountDown Has Been Cancelled For Losing Players !");
    39. if(enabledPlayers.size() == 5) {
    40. Bukkit.getPlayerExact(p).sendMessage(ChatColor.BLACK + "[" + ChatColor.AQUA + "TNTWarZ" + ChatColor.BLACK + "] " + ChatColor.GRAY + "CountDown Has Started Over Again .. Cause Of Getting More Players !");
    41. }
    42. }
    43. }
    44. }
    45. }
    46. }
    47. }, 20L, 20L); // 60 L == 3 sec, 20 ticks == 1 sec
    48.  
    49. }

    Any Help I'll Be ThankFul ..
    Wazup91
     
  2. Offline

    sharp237

    Why did you put everything in italics?


    you have put all the ifs under the if(seconds == 60). So it will never reach them.

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

    Wazup93

    Is This A Wrong Habit ? ....
    Wazup91

    How Exactly ?
    Wazup91

    If I made it with Else if Will it work ?? :/
    Wazup91
     
  4. Offline

    sharp237


    1. if(Seconds == 60) {
    2. if(Bukkit.getOfflinePlayer(p).isOnline()){
    3. Bukkit.getPlayerExact(p).sendMessage(ChatColor.BLACK + "[" + ChatColor.AQUA + "TNTWarZ" + ChatColor.BLACK + "] " + ChatColor.GRAY + "Game Will Start After A Min !");
    4. }
    5. if(Seconds == 30) {
    Here it will only continue if Seconds ==60 (top line). Only if Seconds == 60 will it do the last line if(Seconds == 30).

    Essentially your { } are messed up.
     
  5. Offline

    Wazup93

    Sorry But For Real I Didn't Get it Bro .. This is What I did .. Maybe ..
    Wazup91
     
  6. Offline

    sharp237


    Okay i'll make it real simple.

    In your class, on the 10th line it has:

    if(Seconds == 60) {

    And on the 44th line it has (the end of the above if statement):

    }

    This means that the code between the 10th line and 44th line will only be executed if Seconds equals 60.
     
  7. Offline

    Wazup93

    Just Worked .. Thx :)
    Wazup91

    But Still a Small Problem
    I want it to repeat when its 10 Seconds
    Wazup91

    Plz try To Help At
    Wazup91
     
  8. Offline

    sharp237


    In your class you have a:

    if(Seconds == 10)
    {

    }

    ????
     
  9. Offline

    Wazup93

    Yeah xD
    Wazup91
     
  10. Offline

    sharp237


    What do you mean you want it to repeat?
     
  11. Offline

    Wazup93

    Ummm .. I mean When its in seconds == 10 then It Repeats on It Cause It
    Gets The Remaining Seconds So Its Goes Like 10 , 9 , 8 , ....
    I wish u got It D:
    Wazup91
     
  12. Offline

    sharp237


    I don't understand. How did you make that whole class and yet not know how to send a message countdown from 10.
     
  13. Offline

    Wazup93

    Bro I Know How To Send Single
    But Not as Repeat
    Wazup91

    Please at all if u got a fix .. Write It ..
    Time To Sleeeep ZzZzZzZzzzzz.....
    Wazup91
    Thanks A lot For Helping Me :)
     
  14. Offline

    sharp237


    Why don't you just do...

    if(Seconds == 9)
    {
    ///Do stuff
    }
    else if(Seconds == 8)
    {
    ///Do stuff
    }
    else if(Seconds == 7)
    {
    ///Do stuff
    }

    etc...
     
  15. Offline

    Jade

    Merged multiple triple and double posts. Please use the edit function in the future.
     
  16. Code:text
    1.  
    2. if(Seconds < 10){
    3. Bukkit.getPlayerExact(p).sendMessage(ChatColor.BLACK + "[" + ChatColor.AQUA + "TNTWarZ" + ChatColor.BLACK + "] " + ChatColor.GRAY + "Game Will Start In " + Seconds);
    4. }
    5.  
     
  17. Offline

    xTNBx__DNinja



    I see the problem

    Code:
    }, 20L, 20L);
    you have 20L and 20L

    You should have this:

    Code:
    }, 0L, 20L);
     
  18. Offline

    Loogeh

    Wazup93 Off topic - It would be better if you didn't use Italics and Capitals At The Start Of Every Word because they both make it hard to read.
     
Thread Status:
Not open for further replies.

Share This Page