我正在创建一个 bukkit 插件,但每隔几分钟就无法发送消息。它曾经可以工作,但我现在使用的是 bukkit 1.4.6 beta,但现在不行了。以前的方法已被弃用,但它给了我同样的错误,所以我决定切换到它的替代品,但没有运气。
这是我的代码:
Bukkit.getServer().getScheduler().runTaskTimerAsynchronously((Plugin) this, new Runnable() {
public void run() {
Bukkit.broadcastMessage(ChatColor.DARK_PURPLE + "" + ChatColor.MAGIC + "aaaaaa" + ChatColor.RESET + " Important " + ChatColor.DARK_PURPLE + "" + ChatColor.MAGIC + "aaaaaa" + ChatColor.RESET + ":");
Bukkit.broadcastMessage("");
Bukkit.broadcastMessage(" Hacks are stricly prohibited. A list of approved mods is available on our website. Use of mods not approved by the arenacraft team may lead to a permanent ban.");
}}, 60L, 36000L);
}
我正在使用 this
控制台给了我以下信息:
me.silvershad0wz.arenacraft.Notices (the class this code is from) Cannot be cast to org.bukkit.plugin.Plugin.
随后出现许多错误。源于此
Bukkit.getServer().getScheduler().runTaskTimerAsynchronously((Plugin) this, new Runnable() {
行。
感谢任何帮助,因为我不知道“无法转换为”错误是什么意思。
最佳答案
您是从扩展 JavaPlugin 的主类调用调度程序吗?如果你不是,那么你将不得不通过将 (Plugin) this
更改为 Bukkit.getServer().getPluginManager().getPlugin("YOUR_PLUGIN_NAME")
关于java - Bukkit - 无法启动 runTaskTimerAsynchronously();,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14082660/