-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
4 changed files
with
67 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
IF/src/main/java/com/github/stefvanschie/inventoryframework/util/DispatchUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.github.stefvanschie.inventoryframework.util; | ||
|
||
import org.bukkit.Bukkit; | ||
import org.bukkit.entity.Entity; | ||
import org.bukkit.plugin.Plugin; | ||
|
||
public class DispatchUtil { | ||
private static boolean isFolia() { | ||
try { | ||
Class.forName("io.papermc.paper.threadedregions.RegionizedServer"); | ||
return true; | ||
} catch (ClassNotFoundException e) { | ||
return false; | ||
} | ||
} | ||
|
||
/* | ||
* Schedules a task to run for a given entity. | ||
* | ||
* For non-Folia servers, runs on Bukkit scheduler. | ||
* For Folia servers, runs on the entity's scheduler. | ||
*/ | ||
@SuppressWarnings("deprecation") | ||
public static void runTaskFor(Entity entity, Plugin plugin, Runnable task) { | ||
if (isFolia()) { | ||
entity.getScheduler().run(plugin, e -> task.run(), null); | ||
} else { | ||
Bukkit.getScheduler().runTask(plugin, task); | ||
} | ||
} | ||
} |