Platform: WorldAccessor - Dani-error/velar GitHub Wiki
🌍 WorldAccessor
PlatformWorldAccessor
?
📘 What is PlatformWorldAccessor
is a cross-platform interface that provides a way to map world instances to a string identifier (e.g. name or namespaced key), and vice versa.
This is useful for handling worlds across multiple platforms like Bukkit, Folia, or custom server implementations.
🧩 Interface Methods
Method | Description |
---|---|
extractWorldIdentifier(world: W): String |
Returns a string identifier for the given world instance. |
resolveWorldFromIdentifier(identifier: String): W? |
Resolves a world instance from its string identifier. Returns null if not found. |
🎮 Bukkit Support
BukkitWorldAccessor.kt
provides two built-in implementations depending on server version:
-
BukkitWorldAccessor.nameBasedAccessor()
Uses the world name as the identifier (legacy-compatible). -
BukkitWorldAccessor.keyBasedAccessor()
Uses the namespaced key (e.g.minecraft:world
) introduced in Paper 1.16.5+.
The best choice is selected automatically based on runtime environment via:
val accessor = BukkitWorldAccessor.worldAccessor()
🧠 Implementing Your Own
You can easily implement your own PlatformWorldAccessor
:
class CustomWorldAccessor : PlatformWorldAccessor<MyWorldType> {
override fun extractWorldIdentifier(world: MyWorldType): String {
// Your logic to generate an ID
}
override fun resolveWorldFromIdentifier(identifier: String): MyWorldType? {
// Your logic to look up world by ID
}
}