Search in sources :

Example 1 with GroundFlagLocation

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);
                }
            }
        });
    }
}
Also used : PersistentCooldown(com.ebicep.warlords.player.cooldowns.cooldowns.PersistentCooldown) GameManager(com.ebicep.warlords.game.GameManager) DatabaseManager(com.ebicep.warlords.database.DatabaseManager) GameMenu.openMainMenu(com.ebicep.warlords.menu.GameMenu.openMainMenu) org.bukkit(org.bukkit) EventHandler(org.bukkit.event.EventHandler) AbstractPlayerClass(com.ebicep.warlords.classes.AbstractPlayerClass) ItemBuilder(com.ebicep.warlords.util.bukkit.ItemBuilder) PreLobbyState(com.ebicep.warlords.game.state.PreLobbyState) Spiritguard(com.ebicep.warlords.classes.shaman.specs.spiritguard.Spiritguard) PlayerFlagLocation(com.ebicep.warlords.game.flags.PlayerFlagLocation) org.bukkit.entity(org.bukkit.entity) BlockPhysicsEvent(org.bukkit.event.block.BlockPhysicsEvent) org.bukkit.event.player(org.bukkit.event.player) PermissionHandler(com.ebicep.warlords.permissions.PermissionHandler) GroundFlagLocation(com.ebicep.warlords.game.flags.GroundFlagLocation) InventoryClickEvent(org.bukkit.event.inventory.InventoryClickEvent) Warlords(com.ebicep.warlords.Warlords) FlagHolder(com.ebicep.warlords.game.option.marker.FlagHolder) ItemStack(org.bukkit.inventory.ItemStack) InventoryOpenEvent(org.bukkit.event.inventory.InventoryOpenEvent) VehicleExitEvent(org.bukkit.event.vehicle.VehicleExitEvent) LeaderboardManager(com.ebicep.warlords.database.leaderboards.LeaderboardManager) CooldownFilter(com.ebicep.warlords.player.cooldowns.CooldownFilter) PotionEffectType(org.bukkit.potion.PotionEffectType) Utils(com.ebicep.warlords.util.warlords.Utils) VehicleEnterEvent(org.bukkit.event.vehicle.VehicleEnterEvent) java.util(java.util) PacketUtils(com.ebicep.warlords.util.bukkit.PacketUtils) org.bukkit.event.entity(org.bukkit.event.entity) ChatUtils(com.ebicep.warlords.util.chat.ChatUtils) Action(org.bukkit.event.block.Action) WeatherChangeEvent(org.bukkit.event.weather.WeatherChangeEvent) DatabaseGameBase(com.ebicep.warlords.database.repositories.games.pojos.DatabaseGameBase) Level(java.util.logging.Level) com.ebicep.warlords.abilties(com.ebicep.warlords.abilties) Nullable(javax.annotation.Nullable) Listener(org.bukkit.event.Listener) WaitingFlagLocation(com.ebicep.warlords.game.flags.WaitingFlagLocation) org.bukkit.craftbukkit.v1_8_R3.inventory(org.bukkit.craftbukkit.v1_8_R3.inventory) InventoryType(org.bukkit.event.inventory.InventoryType) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) RegularGamesMenu(com.ebicep.warlords.party.RegularGamesMenu) BlockBreakEvent(org.bukkit.event.block.BlockBreakEvent) DebugMenuGameOptions.openMapsMenu(com.ebicep.warlords.menu.debugmenu.DebugMenuGameOptions.openMapsMenu) PlayersCollections(com.ebicep.warlords.database.repositories.player.PlayersCollections) com.ebicep.warlords.player(com.ebicep.warlords.player) ExecutionException(java.util.concurrent.ExecutionException) ChatChannels(com.ebicep.warlords.util.chat.ChatChannels) EventPriority(org.bukkit.event.EventPriority) SpawnFlagLocation(com.ebicep.warlords.game.flags.SpawnFlagLocation) EndState(com.ebicep.warlords.game.state.EndState) WaitingFlagLocation(com.ebicep.warlords.game.flags.WaitingFlagLocation) GroundFlagLocation(com.ebicep.warlords.game.flags.GroundFlagLocation) PlayerFlagLocation(com.ebicep.warlords.game.flags.PlayerFlagLocation) SpawnFlagLocation(com.ebicep.warlords.game.flags.SpawnFlagLocation) EventHandler(org.bukkit.event.EventHandler)

Example 2 with GroundFlagLocation

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();
}
Also used : GroundFlagLocation(com.ebicep.warlords.game.flags.GroundFlagLocation) FlagLocation(com.ebicep.warlords.game.flags.FlagLocation) PlayerFlagLocation(com.ebicep.warlords.game.flags.PlayerFlagLocation) GroundFlagLocation(com.ebicep.warlords.game.flags.GroundFlagLocation) Team(com.ebicep.warlords.game.Team) PlayerFlagLocation(com.ebicep.warlords.game.flags.PlayerFlagLocation)

Aggregations

GroundFlagLocation (com.ebicep.warlords.game.flags.GroundFlagLocation)2 PlayerFlagLocation (com.ebicep.warlords.game.flags.PlayerFlagLocation)2 Warlords (com.ebicep.warlords.Warlords)1 com.ebicep.warlords.abilties (com.ebicep.warlords.abilties)1 AbstractPlayerClass (com.ebicep.warlords.classes.AbstractPlayerClass)1 Spiritguard (com.ebicep.warlords.classes.shaman.specs.spiritguard.Spiritguard)1 DatabaseManager (com.ebicep.warlords.database.DatabaseManager)1 LeaderboardManager (com.ebicep.warlords.database.leaderboards.LeaderboardManager)1 DatabaseGameBase (com.ebicep.warlords.database.repositories.games.pojos.DatabaseGameBase)1 PlayersCollections (com.ebicep.warlords.database.repositories.player.PlayersCollections)1 GameManager (com.ebicep.warlords.game.GameManager)1 Team (com.ebicep.warlords.game.Team)1 FlagLocation (com.ebicep.warlords.game.flags.FlagLocation)1 SpawnFlagLocation (com.ebicep.warlords.game.flags.SpawnFlagLocation)1 WaitingFlagLocation (com.ebicep.warlords.game.flags.WaitingFlagLocation)1 FlagHolder (com.ebicep.warlords.game.option.marker.FlagHolder)1 EndState (com.ebicep.warlords.game.state.EndState)1 PreLobbyState (com.ebicep.warlords.game.state.PreLobbyState)1 GameMenu.openMainMenu (com.ebicep.warlords.menu.GameMenu.openMainMenu)1 DebugMenuGameOptions.openMapsMenu (com.ebicep.warlords.menu.debugmenu.DebugMenuGameOptions.openMapsMenu)1