Yea I Know Im Bad

Discussion in 'Spigot Plugin Development' started by TheShermanTanker, Apr 13, 2017.

  1. I literally googled for hours and it drove me mad, trying to learn how to use a scheduler to make a 30 second countdown timer. Im trying to make it so this happens:
    Plugins checks for number of Players in world named Dragonkeep
    If number of Players in that world is 100
    Start a 30 second timer

    Send a Message to all players in the world Dragonkeep:

    At 30 seconds: The game starts in 30 seconds!
    At 10 seconds: The game starts in 10 seconds!
    At 5/4/3/2/1 seconds: The game starts in 5/4/3/2/1 second(s)!

    So far I have:
    Code (Java):
    package me.TheShermanTanker.MegaWalls;

    import org.bukkit.Bukkit;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerChangedWorldEvent;
    import org.bukkit.scheduler.BukkitRunnable;
    import org.bukkit.ChatColor;

    public class GameStart implements Listener{
     
        boolean GameStarted = false; //Ignore this, this lets the game know when to make the map breakable
     
        @EventHandler
        public void onJoin(PlayerChangedWorldEvent event){
           //I know my method  to check isnt the most effecient method, but i was rushed, so if anyone could improve the part that checks 100 players I would appreciate it a lot
            if(Bukkit.getWorld("Dragonkeep").getPlayers().size() == 100){
             
                //Trying to code timer here...
             
            }
         
        }

    }
    Yea, guess I need to rewrite this entire class, coding hypixel Mega Walls is hard ;-;
     
    1. Add a BukkitTask field to the class.
    2. When the player count reaches 100, schedule the task and assign the field.
    3. When the player count goes below 100 again, check if the field is not null. If it's not, cancel it and set the field to null
     
  2. Nah i dont want a game to stop when 1 player leaves then people will rage
     
  3. What you've altready tried? Also you shall follow naming conventions
     
  4. Then put the border a little lower.
     
  5. Then leave that part out.
     
  6. I tried Bukkit Schedulers and well...
     
  7. I wouldn't call this beginner code, I'd call it something like written by a beginner. This is extremely ugly.
     
    • Agree Agree x 2
    • Funny Funny x 1
  8. Choco

    Moderator

    Works != Good
     
    • Agree Agree x 7
  9. Yes thanks. Dont really bother about ugly or not ;-; im desperate

    EDIT: I have an idea on how to shrink and neaten that, will try and see if my idea works
     
    #10 TheShermanTanker, Apr 13, 2017
    Last edited: Apr 13, 2017
  10. Of course its an ugly code. But its a beginning, of course you should make it better/smaller.
     
  11. FrostedSnowman

    Resource Staff

    no need for a scheduler. use system time
     
    • Agree Agree x 1
    • Funny Funny x 1
  12. Thats inconvenient for such a small thing, also you would need to check the system time if it even is the time he needs.
     
    • Agree Agree x 1
  13. FrostedSnowman

    Resource Staff

    what..?

    you compare system times for the 'countdown' it uses way less resources.
     
    • Agree Agree x 1
  14. for such a small countdown its no difference
     
  15. FrostedSnowman

    Resource Staff

    a small countdown? a countdown.. is a countdown.
     
    • Agree Agree x 1
  16. You would still have to use a scheduler to constantly check the system time against itself to see where the timer is at.
     
  17. Thats what i also was thinking about, I mean it may makes a diffrence if there are more tasks to do, but for 1 countdow? Thats not a problem with a shedular
     
  18. Try
    Code (Text):
    e.Wait(20.00);
    code 20 seconds
     
     
  19. It still stops the main thread