同时适配Folia和bukkit核心
首先: Folia要求 在plugin.yml 中添加配置 folia-supported: true
-
maven引入
<dependency> <groupId>cn.handyplus.lib.adapter</groupId> <artifactId>FoliaLib</artifactId> <version>最新版本</version> </dependency>
-
初始化;
public class MyPlugin extends JavaPlugin { @Override public void onEnable() { // 初始化 HandySchedulerUtil.init(this); } }
// 同步方法
public void test1(Player player) {
HandySchedulerUtil.runTask(player::closeInventory);
}
// 异步方法
public void test2() {
HandySchedulerUtil.runTaskAsynchronously(() -> {
// 执行方法
});
}
// TP方法
public void test3(Player player, Location location) {
PlayerTeleportEvent.teleport(player, location);
}
// 执行命令
public void test4(Player player, String command) {
PlayerTeleportEvent.performCommand(player, command);
}
// 定时方法
public void test5() {
HandyRunnable handyRunnable = new HandyRunnable() {
@Override
public void run() {
try {
// 执行逻辑
} catch (Exception ignored) {
this.cancel();
}
}
};
HandySchedulerUtil.runTaskTimerAsynchronously(handyRunnable, 20 * 2, 20 * 60);
}
可以在issues提出