-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add Folia support (highly experimental)
Folia support may break at times, and currently they do not implement required events to handle nether portals properly, so please stick to non portal materials such as AIR, WATER or LAVA
- Loading branch information
Showing
7 changed files
with
91 additions
and
24 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
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
44 changes: 40 additions & 4 deletions
44
src/main/java/com/sekwah/advancedportals/bukkit/util/FoliaHandler.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 |
---|---|---|
@@ -1,17 +1,53 @@ | ||
package com.sekwah.advancedportals.bukkit.util; | ||
|
||
import com.sekwah.advancedportals.bukkit.AdvancedPortalsPlugin; | ||
import com.sekwah.advancedportals.bukkit.listeners.Listeners; | ||
import org.bukkit.entity.Entity; | ||
import org.bukkit.plugin.Plugin; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
/** | ||
* This is to stop jars such as spigot complaining about folia imports | ||
*/ | ||
public class FoliaHandler { | ||
public static void repeatingTask(AdvancedPortalsPlugin plugin, Runnable runnable, int seconds) { | ||
plugin.getServer().getAsyncScheduler().runAtFixedRate(plugin, (task) -> { | ||
public static void repeatingTask(AdvancedPortalsPlugin plugin, Runnable runnable, int ticks) { | ||
plugin.getServer().getGlobalRegionScheduler().runAtFixedRate(plugin, (task) -> { | ||
runnable.run(); | ||
}, seconds, seconds, TimeUnit.SECONDS); | ||
}, ticks, ticks); | ||
} | ||
|
||
public static void scheduleTask(AdvancedPortalsPlugin plugin, Runnable runnable, int ticks) { | ||
plugin.getServer().getGlobalRegionScheduler().runDelayed(plugin, (task) -> { | ||
runnable.run(); | ||
}, ticks); | ||
} | ||
|
||
public static void scheduleAsyncTask(Plugin plugin, Runnable runnable, int ticks) { | ||
plugin.getServer().getAsyncScheduler().runDelayed(plugin, (task) -> { | ||
runnable.run(); | ||
}, ticks * 1000L / 20L, TimeUnit.MILLISECONDS); | ||
} | ||
|
||
public static void runAsyncTask(Plugin plugin, Runnable runnable) { | ||
plugin.getServer().getAsyncScheduler().runNow(plugin, (task) -> { | ||
runnable.run(); | ||
}); | ||
} | ||
|
||
|
||
/** | ||
* Will run if the entity isn't destroyed, if you want to run something different in that case also supply a retired runnable. | ||
* @param plugin | ||
* @param entity | ||
* @param runnable | ||
* @param ticks | ||
*/ | ||
public static void scheduleEntityTask(Plugin plugin, Entity entity, Runnable runnable, int ticks) { | ||
scheduleEntityTask(plugin, entity, runnable, null, ticks); | ||
} | ||
public static void scheduleEntityTask(Plugin plugin, Entity entity, Runnable runnable, Runnable retired, int ticks) { | ||
entity.getScheduler().runDelayed(plugin, (task) -> { | ||
runnable.run(); | ||
}, retired, ticks); | ||
} | ||
} |