Folia - ShaneBeee/SkBee GitHub Wiki
This page contains information regarding running Skript/SkBee on a Folia server.
[!IMPORTANT] As of Skript's current state (Skript 2.10.2), Skript does not run on Folia.
SkBee is prepared for when Skript actually does work on Folia. (I had to modify Skript myself just to get it to run on Folia, so I was able to update/test SkBee to work with Folia)
NOTES:
- I have done a moderate amount of testing, things work but can easily break.
- Due to Folia spreading things out between different threads, you need to be extra careful how you're handling world changes.
You can easily get thread errors if you’re doing things in the wrong region.
DISABLED:
Some elements are disabled due to Folia not currently supporting them:
- World Creator
- Chunk Generator
- Vanilla Scoreboard/Teams
CHANGED:
- Runnable Task/While loop sections have support for global/regional/entity schedulers
- You will need to use the appropriate scheduler to prevent async errors
REGIONS:
This section will talk about how Skript differs on a Folia server.
[!CAUTION] This section is written assuming you understand Folia's ticking regions.
If you don't... maybe you shouldn't be using Folia, or at least shouldn't be writing code for it.
Region Types:
There are 2 types of regions to be concerned with.
-
Global Region = The global region is responsible for maintaining world day time, world game time, weather cycle, sleep night skipping, executing commands for console, and other misc. tasks that do not belong to any specific region.
Blocks/Entities should NOT be manipulated in this region. -
Local Regions = The world is broken up into regions based on where the player is.
Any code execute that manipulates blocks/entities should be done in these regions.
Current Region:
When executing Skript code, you need to ensure your code is executed in the correct region.
Some elements will require special attention, mostly Blocks and Entities.
You will NOT be able to modify an entity/block outside of its owning region.
If you do, your console will get spammed with region threading errors.
Determining Current Region:
There are a few ways regions can be determined:
Events:
Depending on the event you are listening to, the region will most likely be determined for you.
For example, entity based events, the current region will be the region at the entity involved in the event.
For block based events, the current region will be the region at the block in the event.
Some events (such as the periodical event) will be run on the global region.
Commands:
If the command is run by a player, the current region will be the region at the player.
If the command is run by console, the current region will be the global region.
Checking Current Region:
You can check if an entity/block/location is owned by a current region using Owned by Current Region condition.
If this returns false, you will have to pass off to the correct region or your code will fail.
Changing Regions:
Depending how your code is execute, you may need to pass off to a different region.
You can do this in the following ways:
Run Tasks:
SkBee's run tasks now have an option to explicitly run at the region of an entity/block/location.
If not specified, the task will run on the global region.
Entity based tasks will auto-cancel themselves if the entity is no longer valid (ie: death, unloading, logout).
Repeating While Loops:
Same as run tasks, you can chose to pass off to the region of an entity/block/location.
Just like run tasks, if using an entity, the while loop will auto cancel itself if the entity is no longer valid.
Things That Can Go Wrong:
Let's look at some ways your code can cause issues:
-
Let's pretend you are listening to a break event... if you were to set a block 1000s of blocks away from this (for whatever reason), you're going to get a thread error in console (meaning you are attempting to set a block outside of the current region).
You are going to want to pass this off to another region, this can be done with run tasks (Hopefully Skript will also implement something for this). -
Let's say you listen to some event or even use a command... if you were to teleport a player far far away and then set the block below the player, you will get a thread error, because the current region is at the location the player teleported from, you haven't moved the region yet. In this scenario you'd have to pass off to the new region using a run task.