Use Fluent Interface Design Pattern to provide uniform and fast scheduling tools for Spigot/Folia.
Irs is compatible with Folia, but this is not a reason to abuse the scheduler.
There are three schedulers in Folia: GlobalRegionScheduler
, AsyncScheduler
, and EntityScheduler
.
Both Bukkit.getScheduler()
and new BukkitRunnable().run()
that were available in Spigot and
Paper are no longer available.
To learn more, see the Folia project description.
Irs are published to a central repository and can be imported without adding additional repositories.
maven
<dependency>
<groupId>one.tranic</groupId>
<artifactId>irs</artifactId>
<version>1.3.3.2</version>
</dependency>
Gradle (Groovy)
repositories {
mavenCentral()
}
dependencies {
implementation 'one.tranic:irs:1.3.3.2'
}
Gradle (Kotlin DSL)
repositories {
mavenCentral()
}
dependencies {
implementation("one.tranic:irs:1.3.3.2")
}
When using the Irs library in a plugin, it is essential to relocate its dependencies to prevent conflicts with other plugins that might also include the same library. Here is a guide to set up relocation.
Add the Shadow plugin to your build.gradle
file.
Gradle (Groovy)
:
plugins {
id 'com.gradleup.shadow' version '8.3.5'
}
Gradle (Kotlin DSL)
:
plugins {
id("com.gradleup.shadow") version "8.3.5"
}
Configure the Shadow plugin to relocate the one.tranic.irs
package.
This ensures that the Irs library’s classes do not conflict with other plugins.
Gradle (Groovy)
:
shadowJar {
relocate 'one.tranic.irs', 'your.plugin.shadow.irs'
}
Gradle (Kotlin DSL)
:
tasks.shadowJar {
relocate("one.tranic.irs", "your.plugin.shadow.irs")
}
Run the Shadow task to build your plugin with the relocated dependencies:
gradle shadowJar
The resulting jar file in the build/libs
directory will include the relocated Irs library,
avoiding classloader conflicts.
To ensure that relocation works as intended, decompile the built jar and verify that the
one.tranic.irs
package has been renamed to your.plugin.shadow.irs
or your specified relocation path.
For Maven users, you can use the Maven Shade Plugin to achieve relocation.
Include the Maven Shade Plugin in your pom.xml
:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.4.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<relocations>
<relocation>
<pattern>one.tranic.irs</pattern>
<shadedPattern>your.plugin.shadow.irs</shadedPattern>
</relocation>
</relocations>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Run the Maven package command:
mvn clean install
The resulting jar file in the target
directory will include the relocated Irs library.
As with Gradle, decompile the jar and confirm that the one.tranic.irs
package has been
relocated to your.plugin.shadow.irs
or the specified path.
By following this guide, you can safely include the Irs library in your project without worrying about conflicts with other plugins.
IRS tries to allow developers to use a set of codes to adapt to spigot and folia, but in fact, developers also need to dispatch tasks to the correct scheduling instead of blind selection. IRS is not so intelligent.
I need to modify the data near an entity: RegionScheduler
or EntityScheduler
I need to modify the weather: GlobalRegionScheduler
I need to get updates for my plugin, or other tasks that do not operate in the world: AsyncScheduler
or CustomThread
PluginSchedulerBuilder.builder(this)
.sync() // Starting at 1.3, Sync is the default behavior.
.task(task)
.run();
// In Spigot/Paper
Bukkit.getScheduler().runTask(this, task);
// In Folia
Bukkit.getGlobalRegionScheduler().run(this, (e)-> task.run());
PluginSchedulerBuilder.builder(this)
.sync(entity)
.sync(player) // Yes, players can also use.
.task(task)
.run();
// In Spigot/Paper
Bukkit.getScheduler().runTask(this, task);
// In Folia
entity.getScheduler().run(this, (e) -> task.run(), null);
PluginSchedulerBuilder.builder(this)
.sync(entity.getLocation())
.sync(location) // or
.task(task)
.run();
// In Spigot/Paper
Bukkit.getScheduler().runTask(this, task);
// In Folia
Bukkit.getRegionScheduler().run(this, location, (e) -> task.run());
PluginSchedulerBuilder.builder(this)
.async()
.task(task)
.run();
// In Spigot/Paper
Bukkit.getScheduler().runTaskAsynchronously(this, task);
// In Folia
Bukkit.getAsyncScheduler().runNow(this, (e) -> task.run());