|
| 1 | +# FoliaLib |
| 2 | +This project is not directly affiliated with Paper team or the Folia project. |
| 3 | + |
| 4 | +## Description |
| 5 | +This is a wrapper library for aiding in supporting the Folia Paper Fork. This library adds multiple scheduler options to use instead of the Bukkit or Folia native schedulers. Developers are expected to depend on this library and relocate the package to their own to prevent conflicts with other plugins. |
| 6 | + |
| 7 | +Note: This project is still in its early stages and may make frequent breaking changes to the API. Additionally, I won't claim that this library is perfect; If you find any issues, please report them on the [issues page](https://github.com/TechnicallyCoded/FoliaLib/issues) |
| 8 | + |
| 9 | +## As a dependency |
| 10 | +### Maven |
| 11 | +```xml |
| 12 | +<repositories> |
| 13 | + <repository> |
| 14 | + <id>devmart-other</id> |
| 15 | + <url>https://nexuslite.gcnt.net/repos/other/</url> |
| 16 | + </repository> |
| 17 | +</repositories> |
| 18 | + |
| 19 | +<dependencies> |
| 20 | + <dependency> |
| 21 | + <groupId>com.tcoded</groupId> |
| 22 | + <artifactId>FoliaLib</artifactId> |
| 23 | + <version>[VERSION]</version> |
| 24 | + <scope>compile</scope> |
| 25 | + </dependency> |
| 26 | +</dependencies> |
| 27 | +``` |
| 28 | +**!! You are expected to relocate the package "com.tcoded.folialib" to your own (ex: "me.steve.lib.folialib") to prevent conflicts with other plugins !!** |
| 29 | + |
| 30 | +*** |
| 31 | + |
| 32 | +### Gradle |
| 33 | +```groovy |
| 34 | +repositories { |
| 35 | + maven { |
| 36 | + name = "devmart-other" |
| 37 | + url = "https://nexuslite.gcnt.net/repos/other/" |
| 38 | + } |
| 39 | +} |
| 40 | +
|
| 41 | +dependencies { |
| 42 | + compileOnly "com.tcoded:FoliaLib:[VERSION]" |
| 43 | +} |
| 44 | +``` |
| 45 | +**!! You are expected to relocate the package "com.tcoded.folialib" to your own (ex: "me.steve.lib.folialib") to prevent conflicts with other plugins !!** |
| 46 | + |
| 47 | +## How to use |
| 48 | +Create a new instance of the FoliaLib class: |
| 49 | +```java |
| 50 | +FoliaLib foliaLib = new FoliaLib(this); |
| 51 | +``` |
| 52 | +Then you can use the scheduler options: |
| 53 | +```java |
| 54 | +// Remember that 20 ticks = 1000 milliseconds, and 20 * 50L = 1000L |
| 55 | + |
| 56 | +// On a spigot server, runTimer() will run on the main thread |
| 57 | +// On a folia server, runTimer() will run using the AsyncScheduler |
| 58 | +foliaLib.getImpl().runTimer(() -> {/* Code */}, 0L, 20 * 50L, TimeUnit.MILLISECONDS); |
| 59 | + |
| 60 | +// You can also specify the thread that you want it to run on |
| 61 | +// On a Folia server, the SYNC option will run using the GlobalRegionScheduler |
| 62 | +// !! This does not make it safe to use for players or block changes !! |
| 63 | +// Use other methods below for handling those |
| 64 | +// This should only be used for updating the following (see GlobalRegionScheduler.java for more info) |
| 65 | +// - world day time, world game time, weather cycle, sleep night skipping, executing commands for console, and other misc |
| 66 | +// On a spigot server, the SYNC option will run on the main thread |
| 67 | +// In both cases, the ASYNC option will run asynchronously |
| 68 | +foliaLib.getImpl().runTimer(ThreadScope.ASYNC, () -> {/* Code */}, 0L, 20 * 50L, TimeUnit.MILLISECONDS); |
| 69 | + |
| 70 | +// On a folia server, this will run the code using the RegionScheduler that is appropriate for the location |
| 71 | +// On a spigot server, this will run the code on the main thread |
| 72 | +foliaLib.getImpl().runInRegion(location, () -> {/* Code */}); |
| 73 | + |
| 74 | +// On a folia server, you need to run code that affects a player or the world in a region. |
| 75 | +// On a spigot server, this will just run the code on the main thread |
| 76 | +foliaLib.getImpl().runInPlayerRegion(player, () -> {/* Code */}); |
| 77 | +``` |
| 78 | + |
| 79 | +## License |
| 80 | +This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details |
0 commit comments