Folia
Folia copied to clipboard
now working API, show me analog
Is your feature request related to a problem?
@EventHandler
public void onPlayerRespawn(PlayerRespawnEvent event) {
event.getPlayer().sendMessage(ChatColor.GREEN + "PlayerRespawnEvent executed");
}
@EventHandler
public void onPlayerTeleport(PlayerTeleportEvent event) {
event.getPlayer().sendMessage(ChatColor.GREEN + "PlayerTeleportEvent executed");
}
Describe the solution you'd like.
I figured out how to get around this (PlayerRespawnEvent event)
Map<String, ScheduledTask> playerTasks = new HashMap<>();
@EventHandler
public void onEntityDeath(EntityDeathEvent event) {
if (event.getEntity().getType() == EntityType.PLAYER) {
Player player = (Player) event.getEntity();
String playerName = player.getName();
ScheduledTask task = new FoliaTaskScheduler(plugin).runRepeating(player, () -> {
if (player.getHealth() != 0) {
//////////////////////////////////// Example ////////////////////////////////////////
event.getPlayer().sendMessage(ChatColor.GREEN + "PlayerRespawnEvent executed");
/////////////////////////////////////////////////////////////////////////////////////////////
ScheduledTask playerTask = playerTasks.remove(player);
if (playerTask != null) {
playerTask.cancel();
}
}
}, 1, 10 * 1);
playerTasks.put(playerName, task);
}
}
Describe alternatives you've considered.
I did not receive any message in the chat, following these steps, show me an analogue of this
Other
No response
Did you register the events?
yes, I have other events, and they are in the 1st class, they work, but these do not
Those events aren't called by Folia, the API will be completed someday
Thank you
The respawn and teleport APIs are very awkward since the target region for the respawn position or teleport location are not actually owned during the event invocation, which may make modifying the event outcome or even reading from it very challenging. It requires a different event system to properly facilitate this, which is not a priority currently.
The respawn and teleport APIs are very awkward since the target region for the respawn position or teleport location are not actually owned during the event invocation, which may make modifying the event outcome or even reading from it very challenging. It requires a different event system to properly facilitate this, which is not a priority currently.
EntityPortalEvent doesn't work either
For anyone who really needs PlayerRespawnEvent, here is the alternative (tested on Folia 1.21):
@EventHandler
public void onRespawn(InventoryCloseEvent event) {
Player player = (Player) event.getPlayer();
if (event.getInventory().getType() != InventoryType.CRAFTING || !player.isDead() || !player.isConnected() || player.getHealth() > 0)
return;
// do stuff
}
To listen and/or cancel entity entering a portal, looks like only EntityPortalEnterEvent can be used.