Search in sources :

Example 1 with MatchData

use of gg.projecteden.nexus.features.minigames.models.MatchData 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 2 with MatchData

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

the class Minigames method registerMatchDatas.

public static void registerMatchDatas() {
    try {
        String path = Minigames.class.getPackage().getName();
        Set<Class<? extends MatchData>> matchDataTypes = new Reflections(path + ".models.matchdata").getSubTypesOf(MatchData.class);
        for (Class<?> matchDataType : matchDataTypes) {
            if (matchDataType.getAnnotation(MatchDataFor.class) == null)
                continue;
            for (MechanicType mechanicType : MechanicType.values()) for (Class<? extends Mechanic> superclass : mechanicType.get().getSuperclasses()) for (Class<? extends Mechanic> applicableMechanic : matchDataType.getAnnotation(MatchDataFor.class).value()) if (applicableMechanic.equals(superclass))
                try {
                    Constructor<?> constructor = matchDataType.getConstructor(Match.class);
                    constructor.setAccessible(true);
                    matchDataMap.put(mechanicType.get(), constructor);
                } catch (NoSuchMethodException ex) {
                    Nexus.warn("MatchData " + matchDataType.getSimpleName() + " has no Match constructor");
                }
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
Also used : Mechanic(gg.projecteden.nexus.features.minigames.models.mechanics.Mechanic) MatchData(gg.projecteden.nexus.features.minigames.models.MatchData) MatchDataFor(gg.projecteden.nexus.features.minigames.models.annotations.MatchDataFor) MechanicType(gg.projecteden.nexus.features.minigames.models.mechanics.MechanicType) Reflections(org.reflections.Reflections)

Aggregations

MatchData (gg.projecteden.nexus.features.minigames.models.MatchData)2 Arena (gg.projecteden.nexus.features.minigames.models.Arena)1 MatchTasks (gg.projecteden.nexus.features.minigames.models.Match.MatchTasks)1 Team (gg.projecteden.nexus.features.minigames.models.Team)1 MatchDataFor (gg.projecteden.nexus.features.minigames.models.annotations.MatchDataFor)1 Mechanic (gg.projecteden.nexus.features.minigames.models.mechanics.Mechanic)1 MechanicType (gg.projecteden.nexus.features.minigames.models.mechanics.MechanicType)1 Reflections (org.reflections.Reflections)1