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());
}
}
Aggregations