How to make delay around use the command?

Discussion in 'Plugin Development' started by makcoh2018, Aug 5, 2021.

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

    makcoh2018

    Hey, i have a command and i need to make delay around use the command. How am i can do this?
     
  2. Offline

    pixelrider2000

    In english please.
     
  3. Offline

    c7dev

    A way to do this is with a simple array list and a runnable
    When a player runs the command, they can only run it if their uuid is not on the list. If it is not, then the command is run but their uuid is added to the list (disabling them from using the command). You then make a bukkit runnable to run after the set delay to remove the player from the list.

    Code:
    new BukkitRunnable() {
    public void run() {
            list.remove(player.getUniqueId());
        }
    }.runTaskLaterAsynchronously(plugin, 20l); //delay, in ticks
     
  4. Online

    KarimAKL

    @c7dev A BukkitRunnable would not work very well if the server TPS is not perfect at all times. I believe a preferable solution would be to save the time when the command is run, then check against that time inside of a repeating BukkitRunnable.
     
Thread Status:
Not open for further replies.

Share This Page