Hi,
I’m trying to create my first sponge plugin. I’ve encountered a problem that I can’t fully understand. I want to make async task, doing it just like in scheduler docs, but plugin refuses to work.
Here is my part of code I use to create task:
private final Task.Builder taskBuilder = Sponge.getScheduler().createTaskBuilder();
private Task makeTask() {
return taskBuilder
.execute(new ScheduledWeatherStateUpdateHandler(this))
.async()
.intervalTicks(interval)
.name("RealWeatherChecker")
.submit((Plugin)this);
}
My IDE tells me that Casting ‘this’ to ‘Plugin’ is redundant, but when I try to run plugin event with that cast, it fails with stacktrace
[14:32:21 ERROR] [Sponge]: Could not pass GameStartedServerEvent$Impl to Plugin{id=realweather, name=RH-RealWeather, version=1.1, authors=[Micha▒ "Bopke" Kubik], source=mods\RealWeather-1.1.jar}
java.lang.ClassCastException: ovh.rehost.realWeatherSponge.RealWeather cannot be cast to org.spongepowered.api.plugin.Plugin
at ovh.rehost.realWeatherSponge.RealWeather.makeTask(RealWeather.java:79) ~[RealWeather.class:?]
at ovh.rehost.realWeatherSponge.RealWeather.onServerStart(RealWeather.java:71) ~[RealWeather.class:?]
at org.spongepowered.common.event.listener.GameStartedServerEventListener_RealWeather_onServerStart3.handle(Unknown Source) ~[?:?]
When I run the plugin without that cast, it crashes with stacktrace:
[14:50:14 ERROR] [Sponge]: The Scheduler tried to run the task RealWeatherChecker owned by Plugin{id=realweather, name=RH-RealWeather, version=1.1, authors=[Micha▒ "Bopke" Kubik], source=mods\RealWeather-1.1.jar}, but an error occured.
java.lang.IllegalArgumentException: Provided object is not a plugin instance
at com.google.common.base.Preconditions.checkArgument(Preconditions.java:122) ~[minecraft_server.1.12.2.jar:?]
at org.spongepowered.common.scheduler.SpongeScheduler.checkPluginInstance(SpongeScheduler.java:155) ~[SpongeScheduler.class:1.12.2-7.1.0-BETA-59]
What should I do to make it work properly? I’ve tried to take a look at working plugins code and tasks were created the same way…
If you want to take a look, here is full code of my plugin main class package ovh.rehost.realWeatherSponge;import com.google.common.reflect.TypeTo - Pastebin.com