Events
Overview
Folia never calls PlayerTeleportEvent or PlayerChangedWorldEvent for teleportAsync. Prism adds two events in their place, in io.prismmc.prism.event.player, both called on the thread that owns the player.
AsyncPlayerTeleportEvent
Called before a player is teleported with teleportAsync: change where the player goes, or cancel it.
@EventHandler
public void onTeleport(AsyncPlayerTeleportEvent event) {
if (event.getTo().getWorld().getName().equals("event_world") && !event.getPlayer().hasPermission("event.join")) {
event.setCancelled(true);
}
}
getFrom(), getTo(), setTo(Location), getCause() and changesWorld() say where from, where to and why.
AsyncPlayerWorldChangeEvent
Called once the player is in another world, after a teleport across worlds.
@EventHandler
public void onWorldChange(AsyncPlayerWorldChangeEvent event) {
event.getPlayer().sendMessage("Welcome to " + event.getPlayer().getWorld().getName());
}
getFrom() is the world left, getFromLocation() where the player stood, getCause() why.
Depending on Prism
Compile against Prism's API (compileOnly): buyers build it from Prism's source code (ask for it on Discord) with ./gradlew :prism-api:jar. Check at runtime that the classes exist before registering the listeners, so the plugin still runs on Folia.