Bukkit - 无法启动runTaskTimerAsynchronously();

时间:2012-12-29 14:37:46

标签: java plugins timer minecraft bukkit

我正在创建一个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() {

线。

任何帮助都表示赞赏,因为我不知道"不能被投射到"错误意味着。

2 个答案:

答案 0 :(得分:4)

您是否从扩展JavaPlugin的主类调用Scheduler?如果您不是,则必须通过更改(Plugin) thisBukkit.getServer().getPluginManager().getPlugin("YOUR_PLUGIN_NAME")的位置来获取插件的实例

答案 1 :(得分:0)

插件的主要类扩展了JavaPlugin,而不是插件。 :)

我认为只是改变

.runTaskTimerAsynchronously((Plugin) this, new Runnable()

.runTaskTimerAsynchronously((JavaPlugin) this, new Runnable()

会起作用,甚至

.runTaskTimerAsynchronously(this, new Runnable()

if 在您的主要课程中调用。

来源:http://wiki.bukkit.org/Plugin_Tutorial#Creating_the_Plugin.27s_Class