now working API, show me analog #105

Open
opened 2023-06-27 15:55:07 +02:00 by Alienn-Know · 7 comments
Alienn-Know commented 2023-06-27 15:55:07 +02:00 (Migrated from github.com)
@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

### 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_
RaphaelWoude commented 2023-06-27 16:12:22 +02:00 (Migrated from github.com)

Did you register the events?

Did you register the events?
Alienn-Know commented 2023-06-27 20:05:52 +02:00 (Migrated from github.com)

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

yes, I have other events, and they are in the 1st class, they work, but these do not
sofianedjerbi commented 2023-06-27 20:23:46 +02:00 (Migrated from github.com)

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

Those events aren't called by Folia, the API will be completed someday
Alienn-Know commented 2023-06-27 20:28:08 +02:00 (Migrated from github.com)

Thank you

Thank you
Spottedleaf commented 2023-06-28 02:52:18 +02:00 (Migrated from github.com)

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.
nyancat-hu commented 2024-03-28 11:28:29 +01:00 (Migrated from github.com)

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

> 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
kerudion commented 2024-08-06 10:33:22 +02:00 (Migrated from github.com)

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.

For anyone who really needs PlayerRespawnEvent, here is the alternative (tested on Folia 1.21): ```java @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](https://jd.papermc.io/paper/1.21/org/bukkit/event/entity/EntityPortalEnterEvent.html) can be used.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Minecraft/Folia#105
No description provided.