Solved Wait time

Discussion in 'Spigot Plugin Development' started by Steven627, May 15, 2016.

  1. Hello, I am making a cool new plugin with a count down for some thing to happen but I am not sure how to do the the wait time I would like it to be 5 (wait 1 second) 4 and so on dose anyone know how to do this?
  2. Yep, it's using a cooldown system. Basically the way a cooldown works (well.. is supposed to), is you put a player into a Map with their UUID as the key, and the current time + the time in milliseconds you want them to be on cooldown as the value. Some people use BukkitRunnables for this, however it's not recommended in this case as

    1. Minecraft doesn't guarantee you 20 ticks per second.
    2. The cooldowns will be reset when the server is reloaded.
    3. It's not always efficient, especially when looping through all of the players, getting their cooldown.
    4. etc.
    The way I would recommend it is the way I mentioned above. There are some good tutorials on various forums, however the one I have found to be one of the better ones can be found here. There are still some flaws with this, however the basis of the cooldown is correct.
    • Agree Agree x 1
  3. I am not sure on where the code would go here is my code -
    package mc.steven.ships;

    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;

    public class ships extends JavaPlugin {

    public void onEnable() {
    getLogger().info("Ships is working");


    public void onDisable() {


    public boolean OnCommand(CommandSender sender, Command cmd, String lable, String[] args) {

    if (cmd.getName().equalsIgnoreCase("ship start")) {

    Player player = (Player) sender;

    player.sendMessage("§9Starting the ship....");
    //This is where I need it to wait for 1 second



  4. What? I sent you a link to how you do it? All you do is send a player 2 messages at the same time. What is that even supposed to do? If you want a cooldown system, click the link that I sent earlier. What you're doing now won't do anything.

    • Instead of checking if the command name is equal to two words, check if the command name is equal to "ship", and the first argument is equal to "start".
    • Don't blindly cast the player to the sender. Check if the sender is actually a player first. If you execute the command from the console, it will throw an error, as the console isn't a player.
  5. Yes i saw the link but where do I put that in my code?
  6. Where it applies? I don't know why you need a cooldown system, so I can't really answer that question.
  7. I dont need a cool down system I need it so it tells the player 5 then it "waits" 1 second then tells them 4 and so on...
  8. Didn't answer my question, but alright. Well, wherever you need it, add them to the Map, and follow the tutorial. I am not going to give you all of the code and where to put it, I already linked you to a pretty good tutorial that you can follow.
  9. I'd tip you with Threads and Methods.
    A new thread. Run a check once a sec.
    Loop through. If time is right, invoke the method with specified arguments.