Countdown

Discussion in 'Plugin Development' started by Gmack9872, Aug 19, 2013.

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

    Gmack9872

    Can someone help me,
    In my plugin I am trying to add a countdown feature. So basically you do a command like /countdown, then in chat it broadcasts, 5,4,3,2,1. In seconds.

    Thanks for your help!
     
  2. Offline

    Gmack9872

    Could you explain it a bit for me, I'm having trouble understanding.
     
  3. You can create a class like CountdownTask, and you make it extend BukkitRunnable.
    Than you have to create a run method in which you can do Bukkit.broadcast() i think. After that when the command /countdown is done you do Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, countdowntask, 0L, 20);
     
  4. Offline

    Gmack9872

    Could you show me some code, sorry I'm a slow learner.
     
  5. Offline

    Sicka_gp

    Code:java
    1. public void CountDown(){
    2. mytaskid2 = ConfigurableMessages.getPlugin().getServer().getScheduler().runTaskTimer(ConfigurableMessages.getPlugin(), new Runnable() {
    3. int number = 5;
    4. public void run() {
    5. if(number != -1) {
    6. if(number !=0) {
    7. Bukkit.broadcastMessage(ChatColor.GOLD + "" + number);
    8. number--;
    9. for(Player player: Bukkit.getOnlinePlayers()){
    10. player.playSound(player.getLocation(), Sound.NOTE_PLING, 4.0F, player.getLocation().getPitch());
    11. }
    12. }else{
    13. Bukkit.broadcastMessage(ChatColor.DARK_RED + "Start!");
    14. number--;
    15. mytaskid2.cancel();
    16. for(Player player: Bukkit.getOnlinePlayers()){
    17. player.playSound(player.getLocation(), Sound.EXPLODE, 4.0F, player.getLocation().getPitch());
    18. }
    19.  
    20. }
    21. }
    22. }
    23. }, 0L, 20L);
    24. }


    Simple countdown, which I use in my project.
     
  6. Offline

    Gmack9872

    How can I make a command perform that?

    Bump

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

    Sicka_gp

    Code:java
    1. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    2. if(cmd.getName().equalsIgnoreCase("countdown")){
    3. CountDown();
    4. return true;
    5. }
    6. return false;
    7. }
     
  8. Offline

    Gmack9872

    Sicka_gp In
    publicvoid CountDown(){
    it highlights void and the {

    Also, how can I make it do 1 minute until start, then 30 seconds until start, then have 10,9,8,7,6,5,4,3,2,1.

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

    DrTURTLE2

    There whould be a space between public and void.
     
  10. Offline

    Gmack9872

    There is a space thats a typo
     
  11. Offline

    DrTURTLE2

    Try doing this.
    Code:java
    1. public void CountDown() {
     
  12. Offline

    Gmack9872

    That doesn't help...
     
  13. Offline

    DrTURTLE2

    In his code, It doesnt have a space With this CountDown(){ In mine it does.

    Just trying to help you even though Im not the most knowledgable at bukkit

    WAIT, DO YOU HAVE @EVENTHANDLER OVER THE TOP?!

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

    Gmack9872

    DrTURTLE2
    I tried it and It didn't do anything that's what I mean't.
     
  15. Offline

    Quantix

    I suggest you go look at some java tutorials online to get a better grip of the language. I could tell you how to code the countdown the way you want but I have a feeling that a lot of users use the plugin development section to simply learn java or have other people punch out code for them, which as I understand it is not this section's purpose. Your problem is not rooted in a specific Bukkit or Minecraft related issue you can't figure out but in your lack of java knowledge.
     
  16. Offline

    Gmack9872

    Where do I put @EventHandler
     
  17. Offline

    DrTURTLE2

    Gmack9872

    #Facepalm

    Above the public void.
     
Thread Status:
Not open for further replies.

Share This Page