@EventHandler
void onPlayerMove(PlayerMoveEvent event) {
Location to = event.getTo();
Location from = event.getFrom();
if (from.getBlockX() == to.getBlockX() &&
from.getBlockY() == to.getBlockY() &&
from.getBlockZ() == to.getBlockZ()) {
return;
}
Material toType = to.getBlock().getType();
if (!Tag.PORTALS.isTagged(toType) || toType == Material.END_GATEWAY) {
return;
}
World originWorld = to.getWorld();
World targetWorld = switch (originWorld.getName()) {
case "world" -> {
if (toType == Material.END_PORTAL) {
yield Bukkit.getWorld("world_the_end");
}
yield Bukkit.getWorld("world_nether");
}
default -> Bukkit.getWorld("world");
};
Bukkit.getScheduler().runTask(this, () -> {
event.getPlayer().teleport(new Location(targetWorld, to.getBlockX(), to.getBlockX(), to.getBlockZ()));
});
}