Timer help

Discussion in 'Plugin Development' started by SeanyJo, Oct 12, 2013.

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

    WauloK

    Okay. For starters, remove WorldEdit.jar and Minecraft.jar from your external JARs. Unless you are going to create regions with WorldEdit or something, you don't need it. Since you have Craftbukkit you also don't need Minecraft.jar which is basically the same thing without the hookability.

    Take off the public static declarations for your ints at the start. They only need to be public if they are to be accessed outside the class.. which from what I can work out, they aren't. They also don't need to be static.

    I compiled and loaded up the plugin with these changes and it does not generate exceptions.

    Code:java
    1. int MinutesToCountdown=plugin.getconfigfile().getInt("Countdown_Config.Lobby.Time-In-Minutes");
    2. int SecondsToCountdown=plugin.getconfigfile().getInt("Countdown_Config.Lobby.Time-In-Seconds");
     
  2. Offline

    SeanyJo

    I'll take off the minecraft.jar, but I'm planning to use worldedit to create arena from selections.
    It works on startup, but when I do /hg join, it doesn't start anything with the countdown.
     
  3. Offline

    WauloK

    Well.. it's not perfect, but it definitely does SOMETHING :)
    I also noted you don't check for perms or isop()

    [​IMG]
     
  4. Offline

    SeanyJo

    WauloK
    With my code, I have it broadcasting it at 1 to 10 seconds, 15 seconds, 30 seconds, and 45 seconds. The 2 minutes also doesn't start right away when the required amount of players have joined. I fixed the chat colors with the countdown, I forgot to include the messageColor code. I'm gonna add the perms and stuff like that in later, once I have the base plugin done.
     
  5. Offline

    WauloK

    Don't forget the first countdown repeatable task will occur AFTER the first minute.
    So when they join and you want to notify people, immediately broadcast "Game starting in 2 minutes!". The first message cannot be in the repeatable task because the first task will happen AFTER your 20*60L = 1 minute.
     
  6. Offline

    SeanyJo

    OH, now I see. Just like a regular countdown. How will I broadcast the 1-10, 15, 30, and 45 second marks? Also, it starts at 4 or 3 minutes after the game is starting, even though in the config it's 120 seconds, so it should be 2 minutes.
     
  7. Offline

    WauloK

    You may want to move your
    Code:java
    1. int MinutesToCountdown=plugin.getconfigfile().getInt("Countdown_Config.Lobby.Time-In-Minutes");
    2. int SecondsToCountdown=plugin.getconfigfile().getInt("Countdown_Config.Lobby.Time-In-Seconds");

    into the methods or the next time they will run they will not be reset.

    Try some testing. Send the player or broadcast a message for every second to make sure it counts down properly.
     
  8. Offline

    SeanyJo

    I tried moving the ints into the methods, but that gave me a lot of errors and tried to make me turn it into a final variable. The updated code is here.
     
  9. Offline

    thecrystalflame

    chuck it on Github or something.
     
  10. Offline

    SeanyJo

    Maybe if I post it on Bukkit then I'll post it on github.
     
  11. Offline

    SeanyJo

  12. Offline

    thecrystalflame

    make a class extend runnable, have an int in that class for the amount of seconds that the countdown will last. inside the run method that should be already implemented thanks to the Runnable interface have a switch, or if you dont know how to use that, if statements for all of the important times. Chuck whatever you want to happen at these times inside those statements and register a scheduledsyncrepeatingtask with the runnable you have just made.
     
  13. Offline

    SeanyJo

    I've done all of that, if you've downloaded/read my code...
    Also, did I do this right, to broadcast x seconds left, from 10 to 1?
    Code:java
    1. if(SecondsToCountdown>1 && SecondsToCountdown<11) {
    2. tellPlayersInMap(GlobalChatColor.messageColor("Messages.Prefix") + GlobalChatColor.messageColor("Messages.LobbyCount.Seconds").replace("%s", Integer.toString(SecondsToCountdown)));
    3. }
     
  14. Offline

    thecrystalflame

    that looks correct to me
     
  15. Offline

    SeanyJo

    Heres my code for the entire class:
    http://pastie.org/8412131
    Heres a screenshot of what happens. The 3 minute and 2 minutes happen at the same time, as well as the 2 and 1 minutes, and the 1 and 4 seconds.
    2013-10-18_10.28.20.png

    I added the code to stop the seconds countdown :p idk why I forgot that.. Also, heres the config:
    Code:
    # TigreGames Configuration File #
    players-required-to-start-lobby-countdown: 1
    players-required-to-start-game: 20
    Countdown_Config:
      Lobby:
        Time-In-Seconds: 120
      Invincibility:
        Enabled: true
        Time-In-Seconds: 120
      Game:
        Enabled: true
        Time-In-Seconds: 3600
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
Thread Status:
Not open for further replies.

Share This Page