Solved Anyone can give me a example countdown?

Discussion in 'Plugin Development' started by Guinomus, Mar 22, 2014.

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

    Guinomus

    A example of countdown with scheduler? please ?
     
  2. Offline

    Konkz

    Code:java
    1. cooldownc.add(clicker.getName());
    2.  
    3. Darkness.getInstance()
    4. .getServer()
    5. .getScheduler()
    6. .scheduleSyncDelayedTask(this,
    7. new Runnable() {
    8. public void run() {
    9. cooldownc.remove(clicker.getName());
    10. }
    11. }, 100);


    After 5 seconds they are removed from cooldown.
     
  3. Offline

    FirecatHD

    I prefer BukkitRunnables, but idk whats best ._. I think BukkitRunnables are more compact :3
     
    Konkz likes this.
  4. Offline

    Konkz

    Same here, I find them more compact and nicer to look at.
     
    FirecatHD likes this.
  5. Offline

    MRPS

    BukkitRunnables/BukkitTasks are subclasses of Runnable. You should study up on Runnable and understand the superclasses of BukkitRunnable before using BukkitRunnable.
     
  6. Offline

    Guinomus

    I need 1 for a mini game to count when it start ex:
    Time 30..29...28...

    I found this tutorial
    but doesnt work
     
  7. Offline

    Konkz

    PHP:
    public void startCountdown() {
          new 
    BukkitRunnable() {
                
    int time 30// time in seconds
     
                
    public void run() {
                    if (
    time 0) {
                        if (
    time 10 == || time 11) {
                            
    Bukkit.broadcastMessage("");
                            
    Bukkit.broadcastMessage("Game is starting in " ChatColor.GOLD
                                    
    time ChatColor.GREEN " seconds!");
                            
    Bukkit.broadcastMessage("");
     
                        }
                        
    time--;
                    } else {
                        
    startGame();
                        
    this.cancel();
                    }
                }
            }.
    runTaskTimer(this2020);
        }
    This will broadcast a message every 10 seconds, when it gets to 0 you have to make a method which determines what happens in the game.

    Eg:

    PHP:
    public void startGame() {
      for(
    Player pBukkit.getOnlinePlayers()) {
      
    p.teleport(LOCATION);
      }
    }
    Something like that :p

    Also, when you want the countdown to start you simply do startCountDown();

    You'd have to add boolean checks so it does not start multiple times, but I will leave that one to you.
     
  8. Offline

    Guinomus

    Konkz THX i love you!
    but what is this?
    Syntax error on token "void", @ expected
     
  9. Offline

    AoH_Ruthless

    Guinomus
    #LearnJava

    this and void are java terminology.
    'this' is an instance of the current class.
    'void' is referring to the return type of the method.
     
    Konkz likes this.
  10. Offline

    Guinomus

    I know. I can't put a method inside another method... I'm trying to put inside a command.
    Please help :D
     
  11. Offline

    GameplayJDK

    Guinomus
    Just add "@Override" above the "public void run() {" and it should work fine.
     
  12. Offline

    AoH_Ruthless

    Guinomus
    What?

    I'm saying that you should put down Bukkit for the time being and learn the basics of Java. It will make yours and our lives easier.

    GameplayJDK
    Lol the @Override annotation is useless. It doesn't magically fix anything.

    Edit: Useless was poor word choice. What I mean to say is that the purpose of @Override is to print a message if you used the wrong method. i.e if you used public void ru() {} with the @Override, it would tell you that you spelled run wrong. Without @Override, you are left with a weird stacktrace and it might be more difficult to fix. The @Override doesn't fix the mistakes, it just notifies you when you are missing a parameter or you misspelled something.

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

    GameplayJDK

  14. Offline

    Konkz


    Works fine for me without it :p
     
  15. Offline

    Wizehh

    You cannot put a method inside another block. Put the method outside, and then reference it like so:
    PHP:
    startCountdown();
     
    Guinomus likes this.
  16. Offline

    AoH_Ruthless

    GameplayJDK
    Either way you don't need the @Override..
     
  17. Offline

    GameplayJDK

  18. Offline

    Guinomus

    Thx this work... Love u :* haha
     
  19. Offline

    Wizehh

    Don't love me, love this.
     
    Guinomus and Konkz like this.
  20. Offline

    AoH_Ruthless

    GameplayJDK
    I think it actually makes it look uglier but Beauty is in the eye of the beholder.
     
    Konkz likes this.
  21. Offline

    Guinomus

    I'll tell you what we don't need...
    We do not need people who do not want to help this community.
     
  22. Offline

    AoH_Ruthless

  23. Offline

    GameplayJDK

    Guinomus
    If I wouldn't want to help the Community I wouldn't be here.
    Here is something you should know about @Override before telling me, that I wouldn't want to help.
     
  24. Offline

    AoH_Ruthless

    GameplayJDK
    He was speaking to me because I didn't just hand him the answer.
     
  25. Offline

    GameplayJDK

Thread Status:
Not open for further replies.

Share This Page