use of com.ebicep.warlords.game.flags.GroundFlagLocation 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);
}
}
});
}
}
use of com.ebicep.warlords.game.flags.GroundFlagLocation in project Warlords by ebicep.
the class FlagHolder method getToolbarName.
@Override
default String getToolbarName(WarlordsPlayer player) {
FlagLocation flag = getFlag();
Team team = getTeam();
Team playerTeam = player.getTeam();
StringBuilder builder = new StringBuilder();
if (flag.getLocation().getWorld() != player.getLocation().getWorld())
return "";
double flagDistance = Math.round(flag.getLocation().distance(player.getLocation()) * 10) / 10.0;
builder.append(team.teamColor()).append(ChatColor.BOLD);
if (playerTeam != team) {
builder.append("ENEMY ");
} else {
builder.append("YOUR ");
}
if (flag instanceof PlayerFlagLocation || flag instanceof GroundFlagLocation) {
if (flag instanceof GroundFlagLocation && playerTeam != team) {
// This is directly copied from the older code, but seems wrong...
builder.append("ENEMY ");
}
builder.append("Flag ");
if (flag instanceof PlayerFlagLocation) {
builder.append(ChatColor.WHITE).append("is stolen ");
} else if (flag instanceof GroundFlagLocation) {
builder.append(ChatColor.GOLD).append("is dropped ");
}
builder.append(ChatColor.RED).append(flagDistance).append("m ").append(ChatColor.WHITE).append("away!");
} else {
builder.append(ChatColor.GREEN).append("Flag is safe");
}
return builder.toString();
}
Aggregations