Search in sources :

Example 1 with DropFlagEvent

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();
            }
        }
    }
}
Also used : MinigamePlayer(au.com.mineauz.minigames.MinigamePlayer) DropFlagEvent(au.com.mineauz.minigames.events.DropFlagEvent) CTFFlag(au.com.mineauz.minigames.CTFFlag) Team(au.com.mineauz.minigames.minigame.Team) Minigame(au.com.mineauz.minigames.minigame.Minigame) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Aggregations

CTFFlag (au.com.mineauz.minigames.CTFFlag)1 MinigamePlayer (au.com.mineauz.minigames.MinigamePlayer)1 DropFlagEvent (au.com.mineauz.minigames.events.DropFlagEvent)1 Minigame (au.com.mineauz.minigames.minigame.Minigame)1 Team (au.com.mineauz.minigames.minigame.Team)1 Location (org.bukkit.Location)1 EventHandler (org.bukkit.event.EventHandler)1