Folia icon indicating copy to clipboard operation
Folia copied to clipboard

now working API, show me analog

Open Alienn-Know opened this issue 2 years ago • 7 comments

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

Alienn-Know avatar Jun 27 '23 13:06 Alienn-Know

Did you register the events?

RaphaelWoude avatar Jun 27 '23 14:06 RaphaelWoude

yes, I have other events, and they are in the 1st class, they work, but these do not

Alienn-Know avatar Jun 27 '23 18:06 Alienn-Know

Those events aren't called by Folia, the API will be completed someday

sofianedjerbi avatar Jun 27 '23 18:06 sofianedjerbi

Thank you

Alienn-Know avatar Jun 27 '23 18:06 Alienn-Know

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.

Spottedleaf avatar Jun 28 '23 00:06 Spottedleaf

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

nyancat-hu avatar Mar 28 '24 10:03 nyancat-hu

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.

kerudion avatar Aug 06 '24 08:08 kerudion