use of au.com.mineauz.minigames.events.DropFlagEvent in project Minigames by AddstarMC.
the class CTFMechanic method dropFlag.
@EventHandler
private void dropFlag(PlayerDeathEvent event) {
MinigamePlayer ply = pdata.getMinigamePlayer(event.getEntity());
if (ply == null)
return;
if (ply.isInMinigame()) {
Minigame mgm = ply.getMinigame();
if (mgm.isFlagCarrier(ply)) {
CTFFlag flag = mgm.getFlagCarrier(ply);
Location loc = flag.spawnFlag(ply.getPlayer().getLocation());
if (loc != null) {
DropFlagEvent ev = new DropFlagEvent(mgm, flag, ply);
Bukkit.getPluginManager().callEvent(ev);
if (!ev.isCancelled()) {
String id = MinigameUtils.createLocationID(loc);
Team team = mgm.getFlagCarrier(ply).getTeam();
mgm.addDroppedFlag(id, flag);
mgm.removeFlagCarrier(ply);
if (team != null)
mdata.sendMinigameMessage(mgm, MinigameUtils.formStr("player.ctf.dropped", ply.getName(), team.getChatColor() + team.getDisplayName() + ChatColor.WHITE), null, null);
else
mdata.sendMinigameMessage(mgm, MinigameUtils.formStr("player.ctf.droppedNeutral", ply.getName()), null, null);
flag.stopCarrierParticleEffect();
flag.startReturnTimer();
}
} else {
flag.respawnFlag();
mgm.removeFlagCarrier(ply);
flag.stopCarrierParticleEffect();
}
}
}
}
Aggregations