Search in sources :

Example 1 with LobbyLocationMarker

use of com.ebicep.warlords.game.option.marker.LobbyLocationMarker in project Warlords by ebicep.

the class PreLobbyState method onPlayerJoinGame.

@Override
public void onPlayerJoinGame(OfflinePlayer op, boolean asSpectator) {
    if (!asSpectator) {
        Team team = Warlords.getPlayerSettings(op.getUniqueId()).getWantedTeam();
        Team finalTeam = team == null ? Team.BLUE : team;
        game.setPlayerTeam(op, finalTeam);
        List<LobbyLocationMarker> lobbies = game.getMarkers(LobbyLocationMarker.class);
        LobbyLocationMarker location = lobbies.stream().filter(e -> e.matchesTeam(finalTeam)).collect(Utils.randomElement());
        if (location == null) {
            location = lobbies.stream().collect(Utils.randomElement());
        }
        if (location != null) {
            Warlords.setRejoinPoint(op.getUniqueId(), location.getLocation());
        }
    }
}
Also used : LobbyLocationMarker(com.ebicep.warlords.game.option.marker.LobbyLocationMarker) BotManager(com.ebicep.jda.BotManager) PreGameItemOption(com.ebicep.warlords.game.option.PreGameItemOption) Utils(com.ebicep.warlords.util.warlords.Utils) GameAddon(com.ebicep.warlords.game.GameAddon) java.util(java.util) Team(com.ebicep.warlords.game.Team) SimpleDateFormat(java.text.SimpleDateFormat) Warlords(com.ebicep.warlords.Warlords) SRCalculator(com.ebicep.warlords.sr.SRCalculator) Player(org.bukkit.entity.Player) Collectors(java.util.stream.Collectors) org.bukkit(org.bukkit) com.ebicep.warlords.player(com.ebicep.warlords.player) Game(com.ebicep.warlords.game.Game) LobbyLocationMarker(com.ebicep.warlords.game.option.marker.LobbyLocationMarker) ChatUtils.sendMessage(com.ebicep.warlords.util.chat.ChatUtils.sendMessage) Option(com.ebicep.warlords.game.option.Option) Team(com.ebicep.warlords.game.Team)

Example 2 with LobbyLocationMarker

use of com.ebicep.warlords.game.option.marker.LobbyLocationMarker in project Warlords by ebicep.

the class PreLobbyState method run.

@Override
public State run() {
    if (hasEnoughPlayers() || timerHasBeenSkipped) {
        timerHasBeenSkipped = false;
        if (timer % 20 == 0) {
            int time = timer / 20;
            game.forEachOnlinePlayerWithoutSpectators((player, team) -> {
                giveLobbyScoreboard(false, player);
                player.setAllowFlight(false);
            });
            if (time == 30) {
                game.forEachOnlinePlayerWithoutSpectators((player, team) -> {
                    sendMessage(player, false, ChatColor.YELLOW + "The game starts in " + ChatColor.GREEN + "30 " + ChatColor.YELLOW + "seconds!");
                    player.playSound(player.getLocation(), Sound.NOTE_STICKS, 1, 1);
                });
            } else if (time == 20) {
                game.forEachOnlinePlayerWithoutSpectators((player, team) -> {
                    sendMessage(player, false, ChatColor.YELLOW + "The game starts in 20 seconds!");
                    player.playSound(player.getLocation(), Sound.NOTE_STICKS, 1, 1);
                });
            } else if (time == 10) {
                game.forEachOnlinePlayerWithoutSpectators((player, team) -> {
                    sendMessage(player, false, ChatColor.YELLOW + "The game starts in " + ChatColor.GOLD + "10 " + ChatColor.YELLOW + "seconds!");
                    player.playSound(player.getLocation(), Sound.NOTE_STICKS, 1, 1);
                });
            } else if (time <= 5 && time != 0) {
                game.forEachOnlinePlayerWithoutSpectators((player, team) -> {
                    String s = time == 1 ? "!" : "s!";
                    sendMessage(player, false, ChatColor.YELLOW + "The game starts in " + ChatColor.RED + time + ChatColor.YELLOW + " second" + s);
                    player.playSound(player.getLocation(), Sound.NOTE_STICKS, 1, 1);
                });
            } else if (time == 0) {
                game.forEachOnlinePlayerWithoutSpectators((player, team) -> {
                    player.playSound(player.getLocation(), "gamestart", 1, 1);
                    player.setAllowFlight(false);
                });
            }
        }
        if (timer <= 0) {
            // this is needed for when we support more teams in the future
            if (!game.getAddons().contains(GameAddon.PRIVATE_GAME)) {
                // separating internalPlayers into even teams because it might be uneven bc internalPlayers couldve left
                // balancing based on specs
                // parties first
                int sameTeamPartyLimit = 2;
                HashMap<Team, List<Player>> partyMembers = new HashMap<Team, List<Player>>() {

                    {
                        put(Team.BLUE, new ArrayList<>());
                        put(Team.RED, new ArrayList<>());
                    }
                };
                game.onlinePlayersWithoutSpectators().filter(e -> e.getValue() != null).forEach(e -> {
                    Player player = e.getKey();
                    Team team = e.getValue();
                    // TODO Test this logic if player are not online if this happens (we do not have player objects in this case)
                    if (partyMembers.values().stream().anyMatch(list -> list.contains(player))) {
                        return;
                    }
                    Warlords.partyManager.getPartyFromAny(player.getUniqueId()).ifPresent(party -> {
                        List<Player> partyPlayersInGame = party.getAllPartyPeoplePlayerOnline().stream().filter(p -> game.getPlayers().containsKey(p.getUniqueId())).collect(Collectors.toList());
                        // check if party has more than limit to get on one team, if so then skip party, they get normally balanced
                        if (partyPlayersInGame.size() > sameTeamPartyLimit) {
                            return;
                        }
                        List<Player> bluePlayers = partyMembers.get(Team.BLUE);
                        List<Player> redPlayers = partyMembers.get(Team.RED);
                        List<Player> partyPlayers = new ArrayList<>(partyPlayersInGame);
                        Collections.shuffle(partyPlayers);
                        int teamSizeDiff = Math.abs(bluePlayers.size() - redPlayers.size());
                        // check if whole party can go on the same team to get an even amount of internalPlayers on each team
                        if (teamSizeDiff > partyPlayers.size()) {
                            if (bluePlayers.size() > redPlayers.size())
                                bluePlayers.addAll(partyPlayers);
                            else
                                redPlayers.addAll(partyPlayers);
                        } else {
                            bluePlayers.addAll(partyPlayers);
                        }
                    });
                });
                HashMap<String, Integer> playersSR = new HashMap<>();
                SRCalculator.playersSR.forEach((key, value1) -> playersSR.put(key.getUuid(), value1 == null ? 500 : value1));
                HashMap<Player, Team> bestTeam = new HashMap<>();
                int bestBlueSR = 0;
                int bestRedSR = 0;
                int bestTeamSRDifference = Integer.MAX_VALUE;
                int maxSRDiff = 200;
                for (int i = 0; i < 5000; i++) {
                    HashMap<Player, Team> teams = new HashMap<>();
                    HashMap<Classes, List<Player>> playerSpecs = new HashMap<>();
                    game.onlinePlayersWithoutSpectators().filter(e -> e.getValue() != null).forEach(e -> {
                        Player player = e.getKey();
                        Team team = e.getValue();
                        PlayerSettings playerSettings = Warlords.getPlayerSettings(player.getUniqueId());
                        playerSpecs.computeIfAbsent(playerSettings.getSelectedClass(), v -> new ArrayList<>()).add(player);
                    });
                    // specs that dont have an even amount of players to redistribute later
                    List<Player> playersLeft = new ArrayList<>();
                    // distributing specs evenly
                    playerSpecs.forEach((classes, playerList) -> {
                        int amountOfTargetSpecsOnBlue = (int) teams.entrySet().stream().filter(playerTeamEntry -> playerTeamEntry.getValue() == Team.BLUE && Warlords.getPlayerSettings(playerTeamEntry.getKey().getUniqueId()).getSelectedClass() == classes).count();
                        int amountOfTargetSpecsOnRed = (int) teams.entrySet().stream().filter(playerTeamEntry -> playerTeamEntry.getValue() == Team.RED && Warlords.getPlayerSettings(playerTeamEntry.getKey().getUniqueId()).getSelectedClass() == classes).count();
                        for (Player player : playerList) {
                            // add to red team
                            if (amountOfTargetSpecsOnBlue > amountOfTargetSpecsOnRed) {
                                teams.put(player, Team.RED);
                                amountOfTargetSpecsOnRed++;
                            } else // add to blue team
                            if (amountOfTargetSpecsOnRed > amountOfTargetSpecsOnBlue) {
                                teams.put(player, Team.BLUE);
                                amountOfTargetSpecsOnBlue++;
                            } else // same amount on each team - add to playersleft to redistribute
                            {
                                playersLeft.add(player);
                            }
                        }
                    });
                    // start on team with least amount of players
                    int blueSR = teams.entrySet().stream().filter(playerTeamEntry -> playerTeamEntry.getValue() == Team.BLUE).mapToInt(value -> playersSR.getOrDefault(value.getKey().getUniqueId().toString(), 500)).sum();
                    int redSR = teams.entrySet().stream().filter(playerTeamEntry -> playerTeamEntry.getValue() == Team.RED).mapToInt(value -> playersSR.getOrDefault(value.getKey().getUniqueId().toString(), 500)).sum();
                    // .collect(Collectors.toList());
                    for (Player player : playersLeft) {
                        if (redSR > blueSR) {
                            teams.put(player, Team.BLUE);
                            blueSR += playersSR.getOrDefault(player.getUniqueId().toString(), 500);
                        } else {
                            teams.put(player, Team.RED);
                            redSR += playersSR.getOrDefault(player.getUniqueId().toString(), 500);
                        }
                    }
                    int bluePlayers = (int) teams.entrySet().stream().filter(playerTeamEntry -> playerTeamEntry.getValue() == Team.BLUE).count();
                    int redPlayers = (int) teams.entrySet().stream().filter(playerTeamEntry -> playerTeamEntry.getValue() == Team.RED).count();
                    // uneven teams
                    if ((bluePlayers + redPlayers) % 2 != 0) {
                        int srDiffRed = Math.abs(redSR - 3500 - blueSR);
                        int srDiffBlue = Math.abs(blueSR - 3500 - redSR);
                        if ((bluePlayers > redPlayers && srDiffRed > maxSRDiff && srDiffRed > 0) || (redPlayers > bluePlayers && srDiffBlue > maxSRDiff && srDiffBlue > 0)) {
                            maxSRDiff++;
                            continue;
                        }
                    } else {
                        if (Math.abs(redSR - blueSR) > maxSRDiff) {
                            maxSRDiff++;
                            continue;
                        }
                    }
                    if (Math.abs(bluePlayers - redPlayers) > 1) {
                        maxSRDiff++;
                        continue;
                    }
                    if (Math.abs(redSR - blueSR) < bestTeamSRDifference) {
                        bestTeam = teams;
                        bestBlueSR = blueSR;
                        bestRedSR = redSR;
                        bestTeamSRDifference = Math.abs(redSR - blueSR);
                    }
                }
                boolean failSafeActive = false;
                boolean secondFailSafeActive = false;
                // INCASE COULDNT BALANCE
                if (bestTeam.isEmpty()) {
                    failSafeActive = true;
                    HashMap<Player, Team> teams = new HashMap<>();
                    HashMap<Classes, List<Player>> playerSpecs = new HashMap<>();
                    // all players are online or else they wouldve been removed from queue
                    game.onlinePlayersWithoutSpectators().filter(e -> e.getValue() != null).forEach(e -> {
                        Player player = e.getKey();
                        Team team = e.getValue();
                        PlayerSettings playerSettings = Warlords.getPlayerSettings(player.getUniqueId());
                        playerSpecs.computeIfAbsent(playerSettings.getSelectedClass(), v -> new ArrayList<>()).add(player);
                    });
                    List<Player> playersLeft = new ArrayList<>();
                    // distributing specs evenly
                    playerSpecs.forEach((classes, playerList) -> {
                        int amountOfTargetSpecsOnBlue = (int) teams.entrySet().stream().filter(playerTeamEntry -> playerTeamEntry.getValue() == Team.BLUE && Warlords.getPlayerSettings(playerTeamEntry.getKey().getUniqueId()).getSelectedClass() == classes).count();
                        int amountOfTargetSpecsOnRed = (int) teams.entrySet().stream().filter(playerTeamEntry -> playerTeamEntry.getValue() == Team.RED && Warlords.getPlayerSettings(playerTeamEntry.getKey().getUniqueId()).getSelectedClass() == classes).count();
                        for (Player player : playerList) {
                            // add to red team
                            if (amountOfTargetSpecsOnBlue > amountOfTargetSpecsOnRed) {
                                teams.put(player, Team.RED);
                                amountOfTargetSpecsOnRed++;
                            } else // add to blue team
                            if (amountOfTargetSpecsOnRed > amountOfTargetSpecsOnBlue) {
                                teams.put(player, Team.BLUE);
                                amountOfTargetSpecsOnBlue++;
                            } else // same amount on each team - add to playersleft to redistribute
                            {
                                playersLeft.add(player);
                            }
                        }
                    });
                    // start on team with least amount of players
                    int amountOnBlue = (int) teams.entrySet().stream().filter(playerTeamEntry -> playerTeamEntry.getValue() == Team.BLUE).count();
                    int amountOnRed = (int) teams.entrySet().stream().filter(playerTeamEntry -> playerTeamEntry.getValue() == Team.RED).count();
                    final boolean[] toBlueTeam = { amountOnBlue <= amountOnRed };
                    playersLeft.stream().sorted(Comparator.comparing(o -> Warlords.getPlayerSettings(o.getUniqueId()).getSelectedClass().specType)).forEachOrdered(player -> {
                        if (toBlueTeam[0]) {
                            teams.put(player, Team.BLUE);
                        } else {
                            teams.put(player, Team.RED);
                        }
                        toBlueTeam[0] = !toBlueTeam[0];
                    });
                    bestTeam = teams;
                    bestBlueSR = teams.entrySet().stream().filter(playerTeamEntry -> playerTeamEntry.getValue() == Team.BLUE).mapToInt(value -> playersSR.getOrDefault(value.getKey().getUniqueId().toString(), 500)).sum();
                    bestRedSR = teams.entrySet().stream().filter(playerTeamEntry -> playerTeamEntry.getValue() == Team.RED).mapToInt(value -> playersSR.getOrDefault(value.getKey().getUniqueId().toString(), 500)).sum();
                    bestTeamSRDifference = Math.abs(bestBlueSR - bestRedSR);
                }
                if (bestTeamSRDifference > 5000) {
                    secondFailSafeActive = true;
                    HashMap<Player, Team> teams = new HashMap<>();
                    HashMap<Classes, List<Player>> playerSpecs = new HashMap<>();
                    game.onlinePlayersWithoutSpectators().filter(e -> e.getValue() != null).forEach(e -> {
                        Player player = e.getKey();
                        Team team = e.getValue();
                        PlayerSettings playerSettings = Warlords.getPlayerSettings(player.getUniqueId());
                        playerSpecs.computeIfAbsent(playerSettings.getSelectedClass(), v -> new ArrayList<>()).add(player);
                    });
                    int blueSR = 0;
                    int redSR = 0;
                    for (List<Player> value : playerSpecs.values()) {
                        for (Player player : value) {
                            if (blueSR > redSR) {
                                teams.put(player, Team.RED);
                                redSR += playersSR.getOrDefault(player.getUniqueId().toString(), 500);
                            } else {
                                teams.put(player, Team.BLUE);
                                blueSR += playersSR.getOrDefault(player.getUniqueId().toString(), 500);
                            }
                        }
                    }
                    bestTeam = teams;
                    bestBlueSR = blueSR;
                    bestRedSR = redSR;
                    bestTeamSRDifference = Math.abs(bestBlueSR - bestRedSR);
                }
                bestTeam.forEach((player, team) -> {
                    game.setPlayerTeam(player, team);
                    ArmorManager.resetArmor(player, Warlords.getPlayerSettings(player.getUniqueId()).getSelectedClass(), team);
                    LobbyLocationMarker location = LobbyLocationMarker.getFirstLobbyLocation(game, team);
                    if (location != null) {
                        player.teleport(location.getLocation());
                    }
                });
                int bluePlayers = (int) bestTeam.entrySet().stream().filter(playerTeamEntry -> playerTeamEntry.getValue() == Team.BLUE).count();
                int redPlayers = (int) bestTeam.entrySet().stream().filter(playerTeamEntry -> playerTeamEntry.getValue() == Team.RED).count();
                for (Map.Entry<UUID, Team> uuidTeamEntry : game.getPlayers().entrySet()) {
                    Player value = Bukkit.getPlayer(uuidTeamEntry.getKey());
                    if (value == null)
                        continue;
                    if (value.hasPermission(WARLORDS_DATABASE_MESSAGEFEED)) {
                        value.sendMessage(ChatColor.DARK_AQUA + "----- BALANCE INFORMATION -----");
                        value.sendMessage(ChatColor.GREEN + "Max SR Diff: " + maxSRDiff);
                        value.sendMessage(ChatColor.GREEN + "SR Diff: " + bestTeamSRDifference);
                        value.sendMessage(ChatColor.BLUE + "Blue Players: " + ChatColor.GOLD + bluePlayers + ChatColor.GRAY + " - " + ChatColor.BLUE + "SR: " + ChatColor.GOLD + bestBlueSR);
                        value.sendMessage(ChatColor.RED + "Red Players: " + ChatColor.GOLD + redPlayers + ChatColor.GRAY + " - " + ChatColor.RED + "SR: " + ChatColor.GOLD + bestRedSR);
                        value.sendMessage(ChatColor.GREEN + "Fail Safe: " + ChatColor.GOLD + failSafeActive);
                        value.sendMessage(ChatColor.GREEN + "Second Fail Safe: " + ChatColor.GOLD + secondFailSafeActive);
                        value.sendMessage(ChatColor.DARK_AQUA + "-------------------------------");
                        bestTeam.entrySet().stream().sorted(Map.Entry.comparingByValue()).forEach(playerTeamEntry -> {
                            Classes classes = Warlords.getPlayerSettings(playerTeamEntry.getKey().getUniqueId()).getSelectedClass();
                            value.sendMessage(playerTeamEntry.getValue().teamColor() + playerTeamEntry.getKey().getName() + ChatColor.GRAY + " - " + classes.specType.chatColor + classes.name + ChatColor.GRAY + " - " + ChatColor.GOLD + playersSR.get(playerTeamEntry.getKey().getUniqueId().toString()));
                        });
                        value.sendMessage(ChatColor.DARK_AQUA + "-------------------------------");
                    }
                }
            }
            if (game.getPlayers().size() >= 14) {
                boolean isPrivate = game.getAddons().contains(GameAddon.PRIVATE_GAME);
                BotManager.sendMessageToNotificationChannel("[GAME] A " + (isPrivate ? "" : "Public ") + "**" + game.getMap().getMapName() + "** started with **" + game.getPlayers().size() + (game.getPlayers().size() == 1 ? "** player!" : "** players!"), isPrivate, !isPrivate);
            }
            return new PlayingState(game);
        }
        timer--;
    } else {
        resetTimer();
        game.forEachOnlinePlayerWithoutSpectators((player, team) -> giveLobbyScoreboard(false, player));
    }
    return null;
}
Also used : BotManager(com.ebicep.jda.BotManager) PreGameItemOption(com.ebicep.warlords.game.option.PreGameItemOption) Utils(com.ebicep.warlords.util.warlords.Utils) GameAddon(com.ebicep.warlords.game.GameAddon) java.util(java.util) Team(com.ebicep.warlords.game.Team) SimpleDateFormat(java.text.SimpleDateFormat) Warlords(com.ebicep.warlords.Warlords) SRCalculator(com.ebicep.warlords.sr.SRCalculator) Player(org.bukkit.entity.Player) Collectors(java.util.stream.Collectors) org.bukkit(org.bukkit) com.ebicep.warlords.player(com.ebicep.warlords.player) Game(com.ebicep.warlords.game.Game) LobbyLocationMarker(com.ebicep.warlords.game.option.marker.LobbyLocationMarker) ChatUtils.sendMessage(com.ebicep.warlords.util.chat.ChatUtils.sendMessage) Option(com.ebicep.warlords.game.option.Option) LobbyLocationMarker(com.ebicep.warlords.game.option.marker.LobbyLocationMarker) Player(org.bukkit.entity.Player) Team(com.ebicep.warlords.game.Team)

Example 3 with LobbyLocationMarker

use of com.ebicep.warlords.game.option.marker.LobbyLocationMarker in project Warlords by ebicep.

the class DebugMenuPlayerOptions method openPlayerMenu.

public static void openPlayerMenu(Player player, WarlordsPlayer target) {
    if (target == null)
        return;
    String targetName = target.getName();
    Menu menu = new Menu("Player Options: " + targetName, 9 * 5);
    ItemStack[] firstRow = { new ItemBuilder(Material.EXP_BOTTLE).name(ChatColor.GREEN + "Energy").get(), new ItemBuilder(Material.INK_SACK, 1, (byte) 8).name(ChatColor.GREEN + "Cooldown").get(), new ItemBuilder(Material.DIAMOND_CHESTPLATE).name(ChatColor.GREEN + "Damage").get(), new ItemBuilder(Material.RABBIT_FOOT).name(ChatColor.GREEN + "Crits").get(), new ItemBuilder(Material.AIR).get(), new ItemBuilder(new Potion(PotionType.INSTANT_DAMAGE), 1, true).name(ChatColor.GREEN + "Kill").flags(ItemFlag.HIDE_POTION_EFFECTS).get(), new ItemBuilder(Material.WOOL, 1, (short) (Warlords.getPlayerSettings(player.getUniqueId()).getWantedTeam() == Team.BLUE ? 14 : 11)).name(ChatColor.GREEN + "Swap to the " + (Warlords.getPlayerSettings(player.getUniqueId()).getWantedTeam() == Team.BLUE ? Team.RED.coloredPrefix() : Team.BLUE.coloredPrefix()) + ChatColor.GREEN + " team").get() };
    ItemStack[] secondRow = { new ItemBuilder(Material.SUGAR).name(ChatColor.GREEN + "Modify Speed").get(), new ItemBuilder(new Potion(PotionType.INSTANT_HEAL), 1, true).name(ChatColor.GREEN + "Add Health").flags(ItemFlag.HIDE_POTION_EFFECTS).get(), new ItemBuilder(Material.DIAMOND_SWORD).name(ChatColor.GREEN + "Take Damage").flags(ItemFlag.HIDE_ATTRIBUTES).get(), new ItemBuilder(Material.BREWING_STAND_ITEM).name(ChatColor.GREEN + "Cooldowns").get(), new ItemBuilder(Material.EYE_OF_ENDER).name(ChatColor.GREEN + "Teleport To").get(), new ItemBuilder(Material.BANNER).name(ChatColor.GREEN + "Flag Options").get(), new ItemBuilder(Material.NETHER_STAR).name(ChatColor.GREEN + "Change Spec").get() };
    for (int i = 0; i < firstRow.length; i++) {
        int index = i + 1;
        menu.setItem(index, 1, firstRow[i], (m, e) -> {
            switch(index) {
                case 1:
                    Bukkit.getServer().dispatchCommand(player, "wl energy " + (target.isInfiniteEnergy() ? "enable" : "disable") + " " + targetName);
                    break;
                case 2:
                    Bukkit.getServer().dispatchCommand(player, "wl cooldown " + (target.isDisableCooldowns() ? "enable" : "disable") + " " + targetName);
                    break;
                case 3:
                    Bukkit.getServer().dispatchCommand(player, "wl damage " + (target.isTakeDamage() ? "disable" : "enable") + " " + targetName);
                    break;
                case 4:
                    Bukkit.getServer().dispatchCommand(player, "wl crits " + (target.isCanCrit() ? "disable" : "enable") + " " + targetName);
                    break;
                case 6:
                    Bukkit.getServer().dispatchCommand(player, "kill " + targetName);
                    break;
                case 7:
                    Game game = target.getGame();
                    Team currentTeam = target.getTeam();
                    Team otherTeam = target.getTeam().enemy();
                    game.setPlayerTeam(player, otherTeam);
                    target.setTeam(otherTeam);
                    target.getGameState().updatePlayerName(target);
                    Warlords.getPlayerSettings(target.getUuid()).setWantedTeam(otherTeam);
                    LobbyLocationMarker randomLobbyLocation = LobbyLocationMarker.getRandomLobbyLocation(game, otherTeam);
                    if (randomLobbyLocation != null) {
                        Location teleportDestination = MapSymmetryMarker.getSymmetry(game).getOppositeLocation(game, currentTeam, otherTeam, target.getLocation(), randomLobbyLocation.getLocation());
                        target.teleport(teleportDestination);
                    }
                    ArmorManager.resetArmor(Bukkit.getPlayer(target.getUuid()), Warlords.getPlayerSettings(target.getUuid()).getSelectedClass(), otherTeam);
                    player.sendMessage(ChatColor.RED + "DEV: " + currentTeam.teamColor() + target.getName() + "§a was swapped to the " + otherTeam.coloredPrefix() + " §ateam");
                    openPlayerMenu(player, target);
                    break;
            }
        });
    }
    for (int i = 0; i < secondRow.length; i++) {
        int index = i + 1;
        menu.setItem(index, 2, secondRow[i], (m, e) -> {
            switch(index) {
                case 1:
                    // TODO
                    break;
                case 2:
                    openAmountMenu(player, target, "heal");
                    break;
                case 3:
                    openAmountMenu(player, target, "takedamage");
                    break;
                case 4:
                    openCooldownsMenu(player, target);
                    break;
                case 5:
                    openTeleportLocations(player, target);
                    break;
                case 6:
                    openFlagOptionMenu(player, target);
                    break;
                case 7:
                    openSpecMenu(player, target);
                    break;
            }
        });
    }
    menu.setItem(3, 4, MENU_BACK, (m, e) -> {
        if (player.getUniqueId() == target.getUuid()) {
            DebugMenu.openDebugMenu(player);
        } else {
            openTeamMenu(player);
        }
    });
    menu.setItem(4, 4, MENU_CLOSE, ACTION_CLOSE_MENU);
    menu.openForPlayer(player);
}
Also used : LobbyLocationMarker(com.ebicep.warlords.game.option.marker.LobbyLocationMarker) ItemBuilder(com.ebicep.warlords.util.bukkit.ItemBuilder) Game(com.ebicep.warlords.game.Game) Potion(org.bukkit.potion.Potion) Team(com.ebicep.warlords.game.Team) Menu(com.ebicep.warlords.menu.Menu) ItemStack(org.bukkit.inventory.ItemStack) Location(org.bukkit.Location) PlayerFlagLocation(com.ebicep.warlords.game.flags.PlayerFlagLocation) GroundFlagLocation(com.ebicep.warlords.game.flags.GroundFlagLocation) SpawnFlagLocation(com.ebicep.warlords.game.flags.SpawnFlagLocation)

Example 4 with LobbyLocationMarker

use of com.ebicep.warlords.game.option.marker.LobbyLocationMarker in project Warlords by ebicep.

the class PreLobbyState method onPlayerReJoinGame.

@Override
public void onPlayerReJoinGame(Player player) {
    State.super.onPlayerReJoinGame(player);
    Team team = game.getPlayerTeam(player.getUniqueId());
    player.getActivePotionEffects().clear();
    if (team == null) {
        player.getInventory().clear();
        player.setAllowFlight(true);
        player.setGameMode(GameMode.SPECTATOR);
    } else {
        player.getInventory().clear();
        player.setAllowFlight(false);
        player.setGameMode(GameMode.ADVENTURE);
        for (PreGameItemOption item : items) {
            if (item != null) {
                player.getInventory().setItem(item.getSlot(), item.getItem(game, player));
            }
        }
        ArmorManager.resetArmor(player, Warlords.getPlayerSettings(player.getUniqueId()).getSelectedClass(), team);
    }
    LobbyLocationMarker location = LobbyLocationMarker.getRandomLobbyLocation(game, team);
    if (location != null) {
        player.teleport(location.getLocation());
        Warlords.setRejoinPoint(player.getUniqueId(), location.getLocation());
    } else {
        System.out.println("Unable to warp player to lobby!, no lobby marker found");
    }
}
Also used : LobbyLocationMarker(com.ebicep.warlords.game.option.marker.LobbyLocationMarker) Team(com.ebicep.warlords.game.Team) PreGameItemOption(com.ebicep.warlords.game.option.PreGameItemOption)

Example 5 with LobbyLocationMarker

use of com.ebicep.warlords.game.option.marker.LobbyLocationMarker in project Warlords by ebicep.

the class GameMenu method openTeamMenu.

public static void openTeamMenu(Player player) {
    Team selectedTeam = Warlords.getPlayerSettings(player.getUniqueId()).getWantedTeam();
    Menu menu = new Menu("Team Selector", 9 * 4);
    List<Team> values = new ArrayList<>(Arrays.asList(Team.values()));
    for (int i = 0; i < values.size(); i++) {
        Team team = values.get(i);
        ItemBuilder builder = new ItemBuilder(team.getItem()).name(team.teamColor() + team.getName()).flags(ItemFlag.HIDE_ENCHANTS);
        List<String> lore = new ArrayList<>();
        if (team == selectedTeam) {
            lore.add(ChatColor.GREEN + "Currently selected!");
            builder.enchant(Enchantment.OXYGEN, 1);
        } else {
            lore.add(ChatColor.YELLOW + "Click to select!");
        }
        builder.lore(lore);
        menu.setItem(9 / 2 - values.size() % 2 + i * 2 - 1, 1, builder.get(), (m, e) -> {
            if (selectedTeam != team) {
                player.sendMessage(ChatColor.GREEN + "You have joined the " + team.teamColor() + team.getName() + ChatColor.GREEN + " team!");
                Optional<Game> playerGame = Warlords.getGameManager().getPlayerGame(player.getUniqueId());
                if (playerGame.isPresent()) {
                    Game game = playerGame.get();
                    Team oldTeam = game.getPlayerTeam(player.getUniqueId());
                    game.setPlayerTeam(player, team);
                    LobbyLocationMarker randomLobbyLocation = LobbyLocationMarker.getRandomLobbyLocation(game, team);
                    if (randomLobbyLocation != null) {
                        Location teleportDestination = MapSymmetryMarker.getSymmetry(game).getOppositeLocation(game, oldTeam, team, player.getLocation(), randomLobbyLocation.getLocation());
                        player.teleport(teleportDestination);
                        Warlords.setRejoinPoint(player.getUniqueId(), teleportDestination);
                    }
                }
                ArmorManager.resetArmor(player, Warlords.getPlayerSettings(player.getUniqueId()).getSelectedClass(), team);
                Warlords.getPlayerSettings(player.getUniqueId()).setWantedTeam(team);
            }
            openTeamMenu(player);
        });
    }
    menu.setItem(4, 3, Menu.MENU_CLOSE, ACTION_CLOSE_MENU);
    menu.openForPlayer(player);
}
Also used : LobbyLocationMarker(com.ebicep.warlords.game.option.marker.LobbyLocationMarker) ItemBuilder(com.ebicep.warlords.util.bukkit.ItemBuilder) Game(com.ebicep.warlords.game.Game) Team(com.ebicep.warlords.game.Team)

Aggregations

Team (com.ebicep.warlords.game.Team)5 LobbyLocationMarker (com.ebicep.warlords.game.option.marker.LobbyLocationMarker)5 Game (com.ebicep.warlords.game.Game)4 PreGameItemOption (com.ebicep.warlords.game.option.PreGameItemOption)3 BotManager (com.ebicep.jda.BotManager)2 Warlords (com.ebicep.warlords.Warlords)2 GameAddon (com.ebicep.warlords.game.GameAddon)2 Option (com.ebicep.warlords.game.option.Option)2 com.ebicep.warlords.player (com.ebicep.warlords.player)2 SRCalculator (com.ebicep.warlords.sr.SRCalculator)2 ItemBuilder (com.ebicep.warlords.util.bukkit.ItemBuilder)2 ChatUtils.sendMessage (com.ebicep.warlords.util.chat.ChatUtils.sendMessage)2 Utils (com.ebicep.warlords.util.warlords.Utils)2 SimpleDateFormat (java.text.SimpleDateFormat)2 java.util (java.util)2 Collectors (java.util.stream.Collectors)2 org.bukkit (org.bukkit)2 Player (org.bukkit.entity.Player)2 GroundFlagLocation (com.ebicep.warlords.game.flags.GroundFlagLocation)1 PlayerFlagLocation (com.ebicep.warlords.game.flags.PlayerFlagLocation)1