use of com.ebicep.warlords.game.flags.WaitingFlagLocation in project Warlords by ebicep.
the class WarlordsEvents method onFlagChange.
@EventHandler
public void onFlagChange(WarlordsFlagUpdatedEvent event) {
// Bukkit.broadcastMessage(event.getTeam() + " " + event.getOld().getClass().getSimpleName() + " => " + event.getNew().getClass().getSimpleName());
if (event.getOld() instanceof PlayerFlagLocation) {
((PlayerFlagLocation) event.getOld()).getPlayer().setCarriedFlag(null);
}
if (event.getNew() instanceof PlayerFlagLocation) {
PlayerFlagLocation pfl = (PlayerFlagLocation) event.getNew();
WarlordsPlayer player = pfl.getPlayer();
player.setCarriedFlag(event.getInfo());
// removing invis for assassins
OrderOfEviscerate.removeCloak(player, false);
if (event.getOld() instanceof PlayerFlagLocation) {
// PLAYER -> PLAYER only happens if the multiplier gets to a new scale
if (pfl.getComputedHumanMultiplier() % 10 == 0) {
event.getGame().forEachOnlinePlayerWithoutSpectators((p, t) -> {
p.sendMessage("§eThe " + event.getTeam().coloredPrefix() + " §eflag carrier now takes §c" + pfl.getComputedHumanMultiplier() + "% §eincreased damage!");
});
event.getGame().spectators().forEach(uuid -> {
if (Bukkit.getPlayer(uuid) != null) {
Player p = Bukkit.getPlayer(uuid);
p.sendMessage("§eThe " + event.getTeam().coloredPrefix() + " §eflag carrier now takes §c" + pfl.getComputedHumanMultiplier() + "% §eincreased damage!");
}
});
}
} else {
// eg GROUND -> PLAYER
// or SPAWN -> PLAYER
ChatColor enemyColor = event.getTeam().enemy().teamColor();
event.getGame().forEachOnlinePlayerWithoutSpectators((p, t) -> {
p.sendMessage(enemyColor + player.getName() + " §epicked up the " + event.getTeam().coloredPrefix() + " §eflag!");
PacketUtils.sendTitle(p, "", enemyColor + player.getName() + " §epicked up the " + event.getTeam().coloredPrefix() + " §eflag!", 0, 60, 0);
if (t == event.getTeam()) {
p.playSound(player.getLocation(), "ctf.friendlyflagtaken", 500, 1);
} else {
p.playSound(player.getLocation(), "ctf.enemyflagtaken", 500, 1);
}
});
event.getGame().spectators().forEach(uuid -> {
if (Bukkit.getPlayer(uuid) != null) {
Player p = Bukkit.getPlayer(uuid);
p.sendMessage(enemyColor + player.getName() + " §epicked up the " + event.getTeam().coloredPrefix() + " §eflag!");
PacketUtils.sendTitle(p, "", enemyColor + player.getName() + " §epicked up the " + event.getTeam().coloredPrefix() + " §eflag!", 0, 60, 0);
}
});
}
} else if (event.getNew() instanceof SpawnFlagLocation) {
WarlordsPlayer toucher = ((SpawnFlagLocation) event.getNew()).getFlagReturner();
if (event.getOld() instanceof GroundFlagLocation) {
if (toucher != null) {
toucher.addFlagReturn();
event.getGame().forEachOnlinePlayer((p, t) -> {
ChatColor color = event.getTeam().teamColor();
p.sendMessage(color + toucher.getName() + " §ehas returned the " + event.getTeam().coloredPrefix() + " §eflag!");
PacketUtils.sendTitle(p, "", color + toucher.getName() + " §ehas returned the " + event.getTeam().coloredPrefix() + " §eflag!", 0, 60, 0);
if (t == event.getTeam()) {
p.playSound(p.getLocation(), "ctf.flagreturned", 500, 1);
}
});
} else {
event.getGame().forEachOnlinePlayer((p, t) -> {
p.sendMessage("§eThe " + event.getTeam().coloredPrefix() + " §eflag has returned to its base.");
});
}
}
} else if (event.getNew() instanceof GroundFlagLocation) {
if (event.getOld() instanceof PlayerFlagLocation) {
PlayerFlagLocation pfl = (PlayerFlagLocation) event.getOld();
pfl.getPlayer().updateArmor();
String flag = event.getTeam().coloredPrefix();
ChatColor playerColor = event.getTeam().enemy().teamColor();
event.getGame().forEachOnlinePlayer((p, t) -> {
PacketUtils.sendTitle(p, "", playerColor + pfl.getPlayer().getName() + " §ehas dropped the " + flag + " §eflag!", 0, 60, 0);
p.sendMessage(playerColor + pfl.getPlayer().getName() + " §ehas dropped the " + flag + " §eflag!");
});
}
} else if (event.getNew() instanceof WaitingFlagLocation && ((WaitingFlagLocation) event.getNew()).getScorer() != null) {
WarlordsPlayer player = ((WaitingFlagLocation) event.getNew()).getScorer();
player.addFlagCap();
event.getGame().forEachOnlinePlayer((p, t) -> {
String message = player.getColoredName() + " §ecaptured the " + event.getInfo().getTeam().coloredPrefix() + " §eflag!";
p.sendMessage(message);
PacketUtils.sendTitle(p, "", message, 0, 60, 0);
if (t != null) {
if (event.getTeam() == t) {
p.playSound(player.getLocation(), "ctf.enemycapturedtheflag", 500, 1);
} else {
p.playSound(player.getLocation(), "ctf.enemyflagcaptured", 500, 1);
}
}
});
}
}
Aggregations