deadmanwalking
deadmanwalking

Reputation: 1

How would I make a message wait in onEnable?

So I am creating a 'chatbot' plugin, where the plugin automatically messages the chat with a donation link and other helpful messages, I know I would need to put in probably in public void onEnable void, however I wouldn't know how to make it wait for about 45 seconds before it posts another message, I know thread.sleep will crash the server, but that was my only thought.

Upvotes: 0

Views: 135

Answers (1)

CraftCoderr
CraftCoderr

Reputation: 46

For any delayed/repeated actions you can use Bukkit Schedule API (https://bukkit.gamepedia.com/Scheduler_Programming).

For sending message after delay you can use this code:

public void onEnable() {
    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, 20);  // means delay of 20 ticks = 1 sec
}

Upvotes: 2

Related Questions