Search in sources :

Example 1 with Arena

use of gg.projecteden.nexus.features.minigames.models.Arena in project Nexus by ProjectEdenGG.

the class MinigamesCommand method list.

@Path("list [filter]")
@Permission(PERMISSION_USE)
void list(String filter) {
    JsonBuilder json = json(PREFIX);
    final List<Arena> arenas = ArenaManager.getAll(filter).stream().sorted(Comparator.comparing(Arena::getName).thenComparing(arena -> MatchManager.find(arena) != null)).toList();
    final Iterator<Arena> iterator = arenas.iterator();
    while (iterator.hasNext()) {
        Arena arena = iterator.next();
        Match match = MatchManager.find(arena);
        if (match == null)
            json.next("&3" + arena.getName());
        else
            json.next("&e" + arena.getName()).hover(match.getMinigamers().stream().map(Minigamer::getNickname).collect(Collectors.joining(", ")));
        if (iterator.hasNext())
            json.group().next("&3, ").group();
    }
    send(json);
}
Also used : JsonBuilder(gg.projecteden.nexus.utils.JsonBuilder) Arena(gg.projecteden.nexus.features.minigames.models.Arena) Match(gg.projecteden.nexus.features.minigames.models.Match) Path(gg.projecteden.nexus.framework.commands.models.annotations.Path) Permission(gg.projecteden.nexus.framework.commands.models.annotations.Permission)

Example 2 with Arena

use of gg.projecteden.nexus.features.minigames.models.Arena in project Nexus by ProjectEdenGG.

the class PotionEffectEditorMenu method init.

@Override
public void init(Player player, InventoryContents contents) {
    addBackItem(contents, e -> menus.getTeamMenus().openPotionEffectsMenu(player, arena, team));
    contents.set(0, 3, ClickableItem.from(nameItem(Material.REDSTONE, "&eDuration", "||&eCurrent value: &3" + potionEffect.getDuration()), e -> openAnvilMenu(player, arena, team, potionEffect, String.valueOf(potionEffect.getDuration()), (p, text) -> {
        if (Utils.isInt(text)) {
            team.getLoadout().getEffects().remove(potionEffect);
            potionEffect = new PotionEffectBuilder(potionEffect).duration(Integer.parseInt(text)).build();
            team.getLoadout().getEffects().add(potionEffect);
            arena.write();
            Tasks.wait(1, () -> {
                // Since potion effects don't have setters, pass-by-reference is broken, so we
                // have to do some hacky waits to get the menu to open with the correct object
                player.closeInventory();
                Tasks.wait(1, () -> menus.getTeamMenus().openPotionEffectEditorMenu(player, arena, team, potionEffect));
            });
            return AnvilGUI.Response.text(text);
        } else {
            PlayerUtils.send(player, PREFIX + "You must use an integer for the duration.");
            return AnvilGUI.Response.close();
        }
    })));
    contents.set(0, 5, ClickableItem.from(nameItem(Material.GLOWSTONE_DUST, "&eAmplifier", "||&eCurrent value: &3" + (potionEffect.getAmplifier() + 1)), e -> openAnvilMenu(player, arena, team, potionEffect, String.valueOf(potionEffect.getAmplifier()), (p, text) -> {
        if (Utils.isInt(text)) {
            team.getLoadout().getEffects().remove(potionEffect);
            potionEffect = new PotionEffectBuilder(potionEffect).amplifier(Integer.parseInt(text) - 1).build();
            team.getLoadout().getEffects().add(potionEffect);
            arena.write();
            Tasks.wait(1, () -> {
                player.closeInventory();
                Tasks.wait(1, () -> menus.getTeamMenus().openPotionEffectEditorMenu(player, arena, team, potionEffect));
            });
            return AnvilGUI.Response.text(text);
        } else {
            PlayerUtils.send(player, PREFIX + "You must use an integer for the amplifier.");
            return AnvilGUI.Response.close();
        }
    })));
    contents.set(0, 8, ClickableItem.from(nameItem(Material.END_CRYSTAL, "&eSave"), e -> arena.write()));
    int row = 2;
    int column = 0;
    for (PotionEffectType effect : PotionEffectType.values()) {
        if (effect == null)
            continue;
        ItemStack potionItem = new ItemBuilder(Material.POTION).name("&e" + StringUtils.camelCase(effect.getName().replace("_", " "))).potionEffect(new PotionEffectBuilder(effect).duration(5).amplifier(0)).potionEffectColor(effect.getColor()).build();
        if (effect == potionEffect.getType())
            potionItem.setType(Material.SPLASH_POTION);
        contents.set(row, column, ClickableItem.from(potionItem, e -> {
            team.getLoadout().getEffects().remove(potionEffect);
            potionEffect = new PotionEffectBuilder(potionEffect).type(effect).build();
            team.getLoadout().getEffects().add(potionEffect);
            arena.write();
            Tasks.wait(1, () -> {
                player.closeInventory();
                Tasks.wait(1, () -> menus.getTeamMenus().openPotionEffectEditorMenu(player, arena, team, potionEffect));
            });
        }));
        if (column == 8) {
            column = 0;
            row++;
        } else {
            column++;
        }
    }
}
Also used : ItemBuilder(gg.projecteden.nexus.utils.ItemBuilder) StringUtils(gg.projecteden.nexus.utils.StringUtils) Minigames.menus(gg.projecteden.nexus.features.minigames.Minigames.menus) NonNull(lombok.NonNull) BiFunction(java.util.function.BiFunction) Tasks(gg.projecteden.nexus.utils.Tasks) Player(org.bukkit.entity.Player) Arena(gg.projecteden.nexus.features.minigames.models.Arena) Utils(gg.projecteden.nexus.utils.Utils) ItemStack(org.bukkit.inventory.ItemStack) PotionEffect(org.bukkit.potion.PotionEffect) PlayerUtils(gg.projecteden.nexus.utils.PlayerUtils) InventoryProvider(fr.minuskube.inv.content.InventoryProvider) InventoryContents(fr.minuskube.inv.content.InventoryContents) MenuUtils(gg.projecteden.nexus.features.menus.MenuUtils) PotionEffectBuilder(gg.projecteden.nexus.utils.PotionEffectBuilder) AnvilGUI(net.wesjd.anvilgui.AnvilGUI) PREFIX(gg.projecteden.nexus.features.minigames.Minigames.PREFIX) Team(gg.projecteden.nexus.features.minigames.models.Team) Material(org.bukkit.Material) PotionEffectType(org.bukkit.potion.PotionEffectType) ClickableItem(fr.minuskube.inv.ClickableItem) ItemBuilder(gg.projecteden.nexus.utils.ItemBuilder) PotionEffectType(org.bukkit.potion.PotionEffectType) ItemStack(org.bukkit.inventory.ItemStack) PotionEffectBuilder(gg.projecteden.nexus.utils.PotionEffectBuilder)

Example 3 with Arena

use of gg.projecteden.nexus.features.minigames.models.Arena in project Nexus by ProjectEdenGG.

the class TeamMechanic method nextTurn.

public void nextTurn(@NotNull Match match) {
    Arena arena = match.getArena();
    MatchData matchData = match.getMatchData();
    MatchTasks tasks = match.getTasks();
    if (match.isEnded() || matchData == null)
        return;
    if (matchData.getTurnTeam() != null) {
        onTurnEnd(match, matchData.getTurnTeam());
        matchData.setTurnTeam(null);
    }
    if (shouldBeOver(match)) {
        end(match);
        return;
    }
    if (matchData.getTurns() >= match.getArena().getMaxTurns()) {
        match.broadcast("Max turns reached, ending game");
        match.end();
        return;
    }
    if (matchData.getTurnTeamList().isEmpty()) {
        matchData.setTurnTeamList(new ArrayList<>(match.getAliveTeams()));
        if (shuffleTurnList())
            Collections.shuffle(matchData.getTurnTeamList());
    }
    tasks.cancel(MatchTaskType.TURN);
    Team team = matchData.getTurnTeamList().get(0);
    matchData.getTurnTeamList().remove(team);
    matchData.setTurnTeam(team);
    match.getScoreboard().update();
    onTurnStart(match, team);
    tasks.register(MatchTaskType.TURN, tasks.wait(arena.getTurnTime() * TickTime.SECOND.get(), () -> nextTurn(match)));
}
Also used : MatchTasks(gg.projecteden.nexus.features.minigames.models.Match.MatchTasks) Team(gg.projecteden.nexus.features.minigames.models.Team) MatchData(gg.projecteden.nexus.features.minigames.models.MatchData) Arena(gg.projecteden.nexus.features.minigames.models.Arena)

Example 4 with Arena

use of gg.projecteden.nexus.features.minigames.models.Arena in project Nexus by ProjectEdenGG.

the class TeamMechanic method announceWinners.

@Override
public void announceWinners(@NotNull Match match) {
    Arena arena = match.getArena();
    Map<Team, Integer> scores = match.getScores();
    int winningScore = getWinningScore(scores.values());
    List<Team> winners = getWinningTeams(winningScore, scores);
    String announcement = null;
    if (winningScore == 0)
        announcement = "No teams scored in ";
    else if (arena.getTeams().size() == winners.size())
        announcement = "All teams tied in ";
    JsonBuilder builder = new JsonBuilder();
    builder.next(announcement == null ? getWinnersComponent(winners) : Component.text(announcement));
    builder.next(arena);
    if (winningScore != 0)
        builder.next(" (" + winningScore + ")");
    Minigames.broadcast(builder);
}
Also used : JsonBuilder(gg.projecteden.nexus.utils.JsonBuilder) Team(gg.projecteden.nexus.features.minigames.models.Team) Arena(gg.projecteden.nexus.features.minigames.models.Arena)

Example 5 with Arena

use of gg.projecteden.nexus.features.minigames.models.Arena in project Nexus by ProjectEdenGG.

the class TeamMechanic method basicBalanceCheck.

public final boolean basicBalanceCheck(@NotNull List<Minigamer> minigamers) {
    if (minigamers.isEmpty())
        return false;
    Match match = minigamers.get(0).getMatch();
    Arena arena = match.getArena();
    List<Team> teams = new ArrayList<>(arena.getTeams());
    int required = 0;
    for (Team team : teams) required += team.getMinPlayers();
    if (match.getMinigamers().size() < required) {
        error("Not enough players to meet team requirements!", match);
        return false;
    }
    return true;
}
Also used : ArrayList(java.util.ArrayList) Team(gg.projecteden.nexus.features.minigames.models.Team) Arena(gg.projecteden.nexus.features.minigames.models.Arena) Match(gg.projecteden.nexus.features.minigames.models.Match)

Aggregations

Arena (gg.projecteden.nexus.features.minigames.models.Arena)39 InventoryProvider (fr.minuskube.inv.content.InventoryProvider)20 ClickableItem (fr.minuskube.inv.ClickableItem)19 InventoryContents (fr.minuskube.inv.content.InventoryContents)19 MenuUtils (gg.projecteden.nexus.features.menus.MenuUtils)19 Player (org.bukkit.entity.Player)19 ItemStack (org.bukkit.inventory.ItemStack)19 Material (org.bukkit.Material)18 NonNull (lombok.NonNull)16 Minigames.menus (gg.projecteden.nexus.features.minigames.Minigames.menus)14 Team (gg.projecteden.nexus.features.minigames.models.Team)13 Tasks (gg.projecteden.nexus.utils.Tasks)11 ArrayList (java.util.ArrayList)10 List (java.util.List)9 CustomMechanicSettings (gg.projecteden.nexus.features.minigames.menus.annotations.CustomMechanicSettings)8 Nullables.isNullOrAir (gg.projecteden.nexus.utils.Nullables.isNullOrAir)8 Minigames (gg.projecteden.nexus.features.minigames.Minigames)7 ArenaManager (gg.projecteden.nexus.features.minigames.managers.ArenaManager)7 Nullables (gg.projecteden.nexus.utils.Nullables)7 Match (gg.projecteden.nexus.features.minigames.models.Match)6