Add player respawn handling with custom logic
Introduced a new event handler for player respawn to set custom spawn locations and apply game class attributes. This ensures players rejoin the game with the correct state after death.
This commit is contained in:
@@ -1,10 +1,14 @@
|
||||
package com.alttd.ctf.events;
|
||||
|
||||
import com.alttd.ctf.game.GameManager;
|
||||
import com.alttd.ctf.team.TeamPlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.event.player.PlayerRespawnEvent;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class OnPlayerDeath implements Listener {
|
||||
|
||||
@@ -26,4 +30,16 @@ public class OnPlayerDeath implements Listener {
|
||||
player.updateInventory();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerRespawn(PlayerRespawnEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
Optional<TeamPlayer> optionalTeamPlayer = gameManager.getTeamPlayer(player.getUniqueId());
|
||||
if (optionalTeamPlayer.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
TeamPlayer teamPlayer = optionalTeamPlayer.get();
|
||||
event.setRespawnLocation(teamPlayer.getTeam().getSpawnLocation());
|
||||
teamPlayer.getGameClass().apply(teamPlayer);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user