Search in sources :

Example 1 with Minigamer

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

the class Nameplates method of.

public static String of(Player player, Player viewer) {
    final Presence presence = Presence.of(player);
    final Minigamer minigamer = PlayerManager.get(player);
    final JsonBuilder nameplate = new JsonBuilder();
    if (minigamer.isPlaying())
        if (minigamer.getTeam() != null && minigamer.getTeam().getNameTagVisibility() == NameTagVisibility.NEVER)
            nameplate.next(minigamer.getNickname());
        else
            nameplate.next(minigamer.getColoredName());
    else
        nameplate.next(presence.ingame()).next(" ").next(Nerd.of(player).getChatFormat(new ChatterService().get(viewer)));
    return nameplate.serialize();
}
Also used : JsonBuilder(gg.projecteden.nexus.utils.JsonBuilder) Presence(gg.projecteden.nexus.features.listeners.Tab.Presence) ChatterService(gg.projecteden.nexus.models.chat.ChatterService) Minigamer(gg.projecteden.nexus.features.minigames.models.Minigamer)

Example 2 with Minigamer

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

the class AbstractTaskMenu method scheduleInvClose.

// todo: use for more tasks
public void scheduleInvClose(HasPlayer _player) {
    Player player = _player.getPlayer();
    Minigamer minigamer = PlayerManager.get(player);
    // don't schedule if match just ended
    if (!minigamer.isPlaying(Sabotage.class))
        return;
    Match.MatchTasks tasks = minigamer.getMatch().getTasks();
    if (closeInvTasks.containsKey(player.getUniqueId()))
        tasks.cancel(closeInvTasks.remove(player.getUniqueId()));
    closeInvTasks.put(player.getUniqueId(), tasks.wait(20, () -> {
        player.sendMessage(Sabotage.COMPLETED_TASK_TEXT);
        player.closeInventory();
    }));
}
Also used : HasPlayer(me.lexikiq.HasPlayer) Player(org.bukkit.entity.Player) Minigamer(gg.projecteden.nexus.features.minigames.models.Minigamer) Sabotage(gg.projecteden.nexus.features.minigames.mechanics.Sabotage) Match(gg.projecteden.nexus.features.minigames.models.Match)

Example 3 with Minigamer

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

the class SabotageMatchData method endMeeting.

public void endMeeting() {
    if (votingScreen instanceof ResultsScreen)
        return;
    AbstractVoteScreen oldScreen = votingScreen;
    votingScreen = new ResultsScreen();
    meetingEnded = LocalDateTime.now();
    match.getTasks().cancel(meetingTaskID);
    match.getTasks().cancel(endMeetingTask);
    meetingTaskID = -1;
    endMeetingTask = -1;
    match.getMinigamers().forEach(minigamer -> {
        oldScreen.close(minigamer);
        votingScreen.open(minigamer);
        minigamer.getPlayer().getInventory().remove(Sabotage.VOTING_ITEM.get());
    });
    match.getTasks().wait(TimeUtils.TickTime.SECOND.x(Sabotage.POST_MEETING_DELAY), () -> {
        match.getMinigamers().forEach(minigamer -> votingScreen.close(minigamer));
        Minigamer ejected = null;
        int votes = getVotesFor(null).size();
        boolean tie = false;
        for (Minigamer minigamer : match.getAliveMinigamers()) {
            int mVotes = getVotesFor(minigamer).size();
            if (mVotes > votes) {
                ejected = minigamer;
                votes = mVotes;
                tie = false;
            } else if (mVotes == votes) {
                ejected = null;
                tie = true;
            }
        }
        String ejectedName;
        if (ejected != null) {
            ejectedName = ejected.getNickname();
        } else
            ejectedName = "Nobody";
        String display = ejectedName + " was ejected.";
        if (ejected == null)
            display += " (" + (tie ? "Tied" : "Skipped") + ")";
        // TODO: true animation
        match.showTitle(Title.title(Component.empty(), new JsonBuilder(display).build(), Title.Times.of(fade, Duration.ofSeconds(7), fade)));
        match.playSound(Sound.sound(org.bukkit.Sound.ENTITY_PLAYER_SPLASH_HIGH_SPEED, Sound.Source.PLAYER, 1.0F, 1.0F));
        clearVotes();
        votingScreen = null;
        roundStarted = LocalDateTime.now();
        match.getMinigamers().forEach(Minigamer::respawn);
        SabotageTeam team = SabotageTeam.of(ejected);
        if (team == SabotageTeam.JESTER) {
            ejected.scored();
            match.end();
        } else if (ejected != null)
            match.getMechanic().onDeath(new MinigamerDeathEvent(ejected));
    });
}
Also used : JsonBuilder(gg.projecteden.nexus.utils.JsonBuilder) AbstractVoteScreen(gg.projecteden.nexus.features.menus.sabotage.AbstractVoteScreen) ResultsScreen(gg.projecteden.nexus.features.menus.sabotage.ResultsScreen) SabotageTeam(gg.projecteden.nexus.features.minigames.models.mechanics.custom.sabotage.SabotageTeam) Minigamer(gg.projecteden.nexus.features.minigames.models.Minigamer) MinigamerDeathEvent(gg.projecteden.nexus.features.minigames.models.events.matches.minigamers.MinigamerDeathEvent)

Example 4 with Minigamer

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

the class SabotageMatchData method getProgress.

public double getProgress() {
    double progress = 0;
    double total = 0;
    for (Map.Entry<UUID, Set<Task>> entry : tasks.entrySet()) {
        UUID uuid = entry.getKey();
        Set<Task> taskSet = entry.getValue();
        Minigamer minigamer;
        try {
            minigamer = PlayerManager.get(uuid);
        } catch (PlayerNotOnlineException e) {
            continue;
        }
        if (SabotageTeam.of(minigamer) == SabotageTeam.IMPOSTOR)
            continue;
        for (Task task : taskSet) {
            if (task.getTask().getTaskType() == Tasks.TaskType.SABOTAGE)
                continue;
            progress += task.getCompleted();
            total += task.getTaskSize();
        }
    }
    return progress / total;
}
Also used : Task(gg.projecteden.nexus.features.minigames.models.mechanics.custom.sabotage.Task) Set(java.util.Set) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) PlayerNotOnlineException(gg.projecteden.nexus.framework.exceptions.postconfigured.PlayerNotOnlineException) UUID(java.util.UUID) Map(java.util.Map) BiMap(com.google.common.collect.BiMap) HashMap(java.util.HashMap) HashBiMap(com.google.common.collect.HashBiMap) Minigamer(gg.projecteden.nexus.features.minigames.models.Minigamer)

Example 5 with Minigamer

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

the class TeamMechanic method onDeath.

@Override
public void onDeath(@NotNull MinigamerDeathEvent event) {
    // auto-balancing
    super.onDeath(event);
    if (!usesAutoBalancing())
        return;
    Match match = event.getMatch();
    Minigamer minigamer = event.getMinigamer();
    if (!minigamer.isAlive() || match.isEnded() || minigamer.getTeam() == null)
        return;
    if (minigamer.getTeam().getMinigamers(match).size() - 1 < minigamer.getTeam().getMinPlayers())
        return;
    List<BalanceWrapper> wrappers = getBalanceWrappers(match).stream().filter(wrapper -> // only try to auto-balance to other teams
    !wrapper.getTeam().equals(minigamer.getTeam()) && wrapper.percentageDiscrepancy() > 0 && wrapper.getNeededPlayers() != -1 && wrapper.extraPlayerPercentDiscrepancy() >= 0).sorted(Comparator.reverseOrder()).collect(Collectors.toList());
    if (wrappers.isEmpty())
        return;
    // select randomly if multiple teams are equal
    List<BalanceWrapper> randomWrappers = new ArrayList<>();
    randomWrappers.add(wrappers.get(0));
    double val = wrappers.get(0).extraPlayerPercentDiscrepancy();
    // iterator var
    int index = 1;
    while (index < wrappers.size() && Math.abs(wrappers.get(index).extraPlayerPercentDiscrepancy() - val) < 0.0001d) {
        randomWrappers.add(wrappers.get(index));
        index++;
    }
    // assign team
    Team team = RandomUtils.randomElement(randomWrappers).getTeam();
    minigamer.setTeam(team);
    minigamer.tell("", false);
    minigamer.tell("&3You have been auto balanced to " + team.getColoredName());
}
Also used : ArrayList(java.util.ArrayList) Team(gg.projecteden.nexus.features.minigames.models.Team) Minigamer(gg.projecteden.nexus.features.minigames.models.Minigamer) Match(gg.projecteden.nexus.features.minigames.models.Match)

Aggregations

Minigamer (gg.projecteden.nexus.features.minigames.models.Minigamer)83 EventHandler (org.bukkit.event.EventHandler)36 Match (gg.projecteden.nexus.features.minigames.models.Match)32 Player (org.bukkit.entity.Player)26 NotNull (org.jetbrains.annotations.NotNull)20 ItemStack (org.bukkit.inventory.ItemStack)19 HashMap (java.util.HashMap)17 Block (org.bukkit.block.Block)17 Location (org.bukkit.Location)15 List (java.util.List)14 Map (java.util.Map)14 Material (org.bukkit.Material)14 MatchEndEvent (gg.projecteden.nexus.features.minigames.models.events.matches.MatchEndEvent)13 ArrayList (java.util.ArrayList)13 TickTime (gg.projecteden.utils.TimeUtils.TickTime)12 Set (java.util.Set)11 Team (gg.projecteden.nexus.features.minigames.models.Team)10 MatchStartEvent (gg.projecteden.nexus.features.minigames.models.events.matches.MatchStartEvent)10 Sound (org.bukkit.Sound)10 PlayerManager (gg.projecteden.nexus.features.minigames.managers.PlayerManager)9