1.14.4 Wait time between broadcasts?

Discussion in 'Spigot Plugin Development' started by ManishBH, Mar 20, 2020.

  1. How can I add delay between two broadcast messages?

    Code (Text):
        @EventHandler
        public void onPlayerDeath(PlayerDeathEvent e) {
            String msg = e.getDeathMessage();
            e.setDeathMessage("");
            Bukkit.broadcastMessage(msg);
            // wait one second
            Bukkit.broadcastMessage(ChatColor.YELLOW + "F");
        }
     
  2. Use BukkitScheduler (Bukkit#getScheduler)

    Example:
    Code (Java):
    Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, () -> {
        // Your code
    }, 20); // duration in ticks (20 ticks = 1 second)
     
     
  3. Use a bukkitrunnable
    https://bukkit.gamepedia.com/Scheduler_Programming

    Snipped from the link
    Code (Text):
     new BukkitRunnable() {
           
                @Override
                public void run() {
                    // What you want to schedule goes here
                    plugin.getServer().broadcastMessage(
                        "Welcome to Bukkit! Remember to read the documentation!");
                }
               
            }.runTaskLater(this.plugin, 20);
     
  4. with the bukkit scheduler https://bukkit.gamepedia.com/Scheduler_Programming