我如何让消息在onEnable中等待?

问题描述 投票:0回答:1

因此,我正在创建一个'chatbot'插件,该插件会通过捐赠链接和其他有用的消息自动向聊天室发送消息,我知道可能需要将public void onEnable设为空白,但是我不知道如何为了让它等待大约45秒钟,然后再发布另一条消息,我知道thread.sleep将使服务器崩溃,但这是我唯一的想法。

java minecraft bukkit
1个回答
0
投票

对于任何延迟/重复的操作,您可以使用Bukkit Schedule API(https://bukkit.gamepedia.com/Scheduler_Programming)。

对于延迟后发送消息,您可以使用此代码:

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);
}
© www.soinside.com 2019 - 2024. All rights reserved.