Code:
Error:
Game: Minecraft 1.16.5
You can read it here.
CommandExecutor.CMD_Stop can't be cast to org.bukkit.plugin.Plugin
at CommandExecutor.CMD_Stop.onCommand (CMD_Stop.java:22)
(Plugin) this
Line 33:
} .runTaskTimer ((plugin) this, 0, 20);
You cast your command class to the plugin. That will not do. You need to pass in your class instead, which inherits from JavaPlugin.
It works strangely in the main class… How do I make it work there?
Like you don't even try. You can create a maximum of one variable that has the type of your main class and set the value via the constructor.
E.g.:
TestPlugin plugin;
public MyClass () {
this.plugin = TestPlugin.getPlugin (TestPlugin.class)
}
Public class CMD_Stop implements CommandExecutor {
CMD_Stop plugin;
public CMD_Stop () {
this.plugin = CMD_Stop.getPlugin (CMD_Stop.class);
}
new BukkitRunnable () {
public void run () {
} .runTaskTimer (plugin, 0, 20);
}
I feel stupid.
You should use your main class, i.e. The class that inherits from JavaPlugin, i.e. Main class plugin; not CMD_stop