Search in sources :

Example 1 with SpawnLocationMarker

use of com.ebicep.warlords.game.option.marker.SpawnLocationMarker in project Warlords by ebicep.

the class WarlordsPlayer method respawn.

public void respawn() {
    List<Location> candidates = new ArrayList<>();
    double priority = Double.NEGATIVE_INFINITY;
    for (SpawnLocationMarker marker : getGame().getMarkers(SpawnLocationMarker.class)) {
        if (candidates.isEmpty()) {
            candidates.add(marker.getLocation());
            priority = marker.getPriority(this);
        } else {
            double newPriority = marker.getPriority(this);
            if (newPriority >= priority) {
                if (newPriority > priority) {
                    candidates.clear();
                    priority = newPriority;
                }
                candidates.add(marker.getLocation());
            }
        }
    }
    Location respawnPoint = !candidates.isEmpty() ? candidates.get((int) (Math.random() * candidates.size())) : deathLocation != null ? deathLocation : getLocation();
    WarlordsRespawnEvent event = new WarlordsRespawnEvent(this, respawnPoint);
    Bukkit.getPluginManager().callEvent(event);
    if (event.isCancelled()) {
        return;
    }
    if (entity instanceof Player) {
        PacketUtils.sendTitle((Player) entity, "", "", 0, 0, 0);
    }
    setRespawnTimer(-1);
    setEnergy(getMaxEnergy() / 2);
    dead = false;
    teleport(respawnPoint);
    this.health = this.maxHealth;
    if (entity instanceof Player) {
        updatePlayer((Player) entity);
    } else {
        this.entity = spawnJimmy(respawnPoint, this.entity.getEquipment());
    }
}
Also used : Player(org.bukkit.entity.Player) DatabasePlayer(com.ebicep.warlords.database.repositories.player.pojos.general.DatabasePlayer) CraftPlayer(org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer) SpawnLocationMarker(com.ebicep.warlords.game.option.marker.SpawnLocationMarker) WarlordsRespawnEvent(com.ebicep.warlords.events.WarlordsRespawnEvent) PlayerFlagLocation(com.ebicep.warlords.game.flags.PlayerFlagLocation)

Aggregations

DatabasePlayer (com.ebicep.warlords.database.repositories.player.pojos.general.DatabasePlayer)1 WarlordsRespawnEvent (com.ebicep.warlords.events.WarlordsRespawnEvent)1 PlayerFlagLocation (com.ebicep.warlords.game.flags.PlayerFlagLocation)1 SpawnLocationMarker (com.ebicep.warlords.game.option.marker.SpawnLocationMarker)1 CraftPlayer (org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer)1 Player (org.bukkit.entity.Player)1