Search in sources :

Example 1 with RankHistory

use of gg.projecteden.nexus.models.hallofhistory.HallOfHistory.RankHistory in project Nexus by ProjectEdenGG.

the class HallOfHistoryCommand method removeRankConfirm.

@Async
@Permission(Group.STAFF)
@Path("removeRank <player> <current|former> <rank> <promotionDate> [resignationDate]")
void removeRankConfirm(OfflinePlayer player, String when, Rank rank, LocalDate promotion, LocalDate resignation) {
    boolean current = "current".equalsIgnoreCase(when);
    HallOfHistory history = service.get(player.getUniqueId());
    ConfirmationMenu.builder().title("Remove rank from " + player.getName() + "?").onConfirm((item) -> {
        for (RankHistory rankHistory : new ArrayList<>(history.getRankHistory())) {
            if (!new RankHistory(rank, current, promotion, resignation).equals(rankHistory))
                continue;
            history.getRankHistory().remove(rankHistory);
            service.save(history);
            send(PREFIX + "Removed the rank from &e" + player.getName());
            send(json(PREFIX + "&eClick here &3to generate a command to re-add rank").suggest("/hoh addrank " + player.getName() + " " + getRankCommandArgs(rankHistory)));
            return;
        }
        send(PREFIX + "Could not find the rank to delete");
    }).open(player());
}
Also used : StringUtils(gg.projecteden.nexus.utils.StringUtils) JsonBuilder(gg.projecteden.nexus.utils.JsonBuilder) BiFunction(java.util.function.BiFunction) OptionalDouble(java.util.OptionalDouble) Async(gg.projecteden.annotations.Async) Arg(gg.projecteden.nexus.framework.commands.models.annotations.Arg) HashMap(java.util.HashMap) Group(gg.projecteden.nexus.framework.commands.models.annotations.Permission.Group) RankHistory(gg.projecteden.nexus.models.hallofhistory.HallOfHistory.RankHistory) ArrayList(java.util.ArrayList) Nullables.isNullOrEmpty(gg.projecteden.nexus.utils.Nullables.isNullOrEmpty) ServerAge(gg.projecteden.nexus.features.commands.AgeCommand.ServerAge) Map(java.util.Map) Permission(gg.projecteden.nexus.framework.commands.models.annotations.Permission) Nickname(gg.projecteden.nexus.models.nickname.Nickname) Timespan(gg.projecteden.utils.TimeUtils.Timespan) ConfirmationMenu(gg.projecteden.nexus.features.menus.MenuUtils.ConfirmationMenu) Path(gg.projecteden.nexus.framework.commands.models.annotations.Path) Nerd(gg.projecteden.nexus.models.nerd.Nerd) Rank(gg.projecteden.nexus.models.nerd.Rank) CustomCommand(gg.projecteden.nexus.framework.commands.models.CustomCommand) Tasks(gg.projecteden.nexus.utils.Tasks) TimeUtils.shortDateFormat(gg.projecteden.utils.TimeUtils.shortDateFormat) UUID(java.util.UUID) PlayerNotFoundException(gg.projecteden.nexus.framework.exceptions.postconfigured.PlayerNotFoundException) TimeUtils.dateFormat(gg.projecteden.utils.TimeUtils.dateFormat) EdenSocialMediaSite(gg.projecteden.nexus.features.socialmedia.SocialMedia.EdenSocialMediaSite) HallOfHistory(gg.projecteden.nexus.models.hallofhistory.HallOfHistory) Utils(gg.projecteden.nexus.utils.Utils) OfflinePlayer(org.bukkit.OfflinePlayer) StringUtils.stripColor(gg.projecteden.nexus.utils.StringUtils.stripColor) Aliases(gg.projecteden.nexus.framework.commands.models.annotations.Aliases) TickTime(gg.projecteden.utils.TimeUtils.TickTime) List(java.util.List) ChronoUnit(java.time.temporal.ChronoUnit) CommandEvent(gg.projecteden.nexus.framework.commands.models.events.CommandEvent) LocalDate(java.time.LocalDate) NerdService(gg.projecteden.nexus.models.nerd.NerdService) HallOfHistoryService(gg.projecteden.nexus.models.hallofhistory.HallOfHistoryService) Comparator(java.util.Comparator) HallOfHistory(gg.projecteden.nexus.models.hallofhistory.HallOfHistory) RankHistory(gg.projecteden.nexus.models.hallofhistory.HallOfHistory.RankHistory) Path(gg.projecteden.nexus.framework.commands.models.annotations.Path) Async(gg.projecteden.annotations.Async) Permission(gg.projecteden.nexus.framework.commands.models.annotations.Permission)

Example 2 with RankHistory

use of gg.projecteden.nexus.models.hallofhistory.HallOfHistory.RankHistory in project Nexus by ProjectEdenGG.

the class HallOfHistoryCommand method staffTime.

@Async
@Path("staffTime [page]")
public void staffTime(@Arg("1") int page) {
    LocalDate now = LocalDate.now();
    HallOfHistoryService service = new HallOfHistoryService();
    Map<UUID, Long> staffTimeMap = new HashMap<>();
    for (HallOfHistory hallOfHistory : service.getAll()) {
        long days = 0;
        days: for (LocalDate date = ServerAge.getEPOCH().toLocalDate(); date.isBefore(now); date = date.plusDays(1)) {
            for (RankHistory rankHistory : hallOfHistory.getRankHistory()) {
                LocalDate from = rankHistory.getPromotionDate();
                LocalDate to = rankHistory.getResignationDate();
                if (from == null)
                    continue;
                if (to == null)
                    to = now;
                if (Utils.isBetween(date, from, to)) {
                    ++days;
                    continue days;
                }
            }
        }
        if (days == 0)
            continue;
        staffTimeMap.put(hallOfHistory.getUuid(), days);
    }
    send(PREFIX + "Staff times");
    BiFunction<UUID, String, JsonBuilder> formatter = (uuid, index) -> {
        String time = Timespan.ofSeconds(staffTimeMap.get(uuid) * (TickTime.DAY.get() / 20)).format();
        return json(index + " &e" + time + " &7- " + Nerd.of(uuid).getNameFormat());
    };
    paginate(Utils.sortByValueReverse(staffTimeMap).keySet(), formatter, "/hoh staffTime", page);
}
Also used : StringUtils(gg.projecteden.nexus.utils.StringUtils) JsonBuilder(gg.projecteden.nexus.utils.JsonBuilder) BiFunction(java.util.function.BiFunction) OptionalDouble(java.util.OptionalDouble) Async(gg.projecteden.annotations.Async) Arg(gg.projecteden.nexus.framework.commands.models.annotations.Arg) HashMap(java.util.HashMap) Group(gg.projecteden.nexus.framework.commands.models.annotations.Permission.Group) RankHistory(gg.projecteden.nexus.models.hallofhistory.HallOfHistory.RankHistory) ArrayList(java.util.ArrayList) Nullables.isNullOrEmpty(gg.projecteden.nexus.utils.Nullables.isNullOrEmpty) ServerAge(gg.projecteden.nexus.features.commands.AgeCommand.ServerAge) Map(java.util.Map) Permission(gg.projecteden.nexus.framework.commands.models.annotations.Permission) Nickname(gg.projecteden.nexus.models.nickname.Nickname) Timespan(gg.projecteden.utils.TimeUtils.Timespan) ConfirmationMenu(gg.projecteden.nexus.features.menus.MenuUtils.ConfirmationMenu) Path(gg.projecteden.nexus.framework.commands.models.annotations.Path) Nerd(gg.projecteden.nexus.models.nerd.Nerd) Rank(gg.projecteden.nexus.models.nerd.Rank) CustomCommand(gg.projecteden.nexus.framework.commands.models.CustomCommand) Tasks(gg.projecteden.nexus.utils.Tasks) TimeUtils.shortDateFormat(gg.projecteden.utils.TimeUtils.shortDateFormat) UUID(java.util.UUID) PlayerNotFoundException(gg.projecteden.nexus.framework.exceptions.postconfigured.PlayerNotFoundException) TimeUtils.dateFormat(gg.projecteden.utils.TimeUtils.dateFormat) EdenSocialMediaSite(gg.projecteden.nexus.features.socialmedia.SocialMedia.EdenSocialMediaSite) HallOfHistory(gg.projecteden.nexus.models.hallofhistory.HallOfHistory) Utils(gg.projecteden.nexus.utils.Utils) OfflinePlayer(org.bukkit.OfflinePlayer) StringUtils.stripColor(gg.projecteden.nexus.utils.StringUtils.stripColor) Aliases(gg.projecteden.nexus.framework.commands.models.annotations.Aliases) TickTime(gg.projecteden.utils.TimeUtils.TickTime) List(java.util.List) ChronoUnit(java.time.temporal.ChronoUnit) CommandEvent(gg.projecteden.nexus.framework.commands.models.events.CommandEvent) LocalDate(java.time.LocalDate) NerdService(gg.projecteden.nexus.models.nerd.NerdService) HallOfHistoryService(gg.projecteden.nexus.models.hallofhistory.HallOfHistoryService) Comparator(java.util.Comparator) HashMap(java.util.HashMap) HallOfHistory(gg.projecteden.nexus.models.hallofhistory.HallOfHistory) LocalDate(java.time.LocalDate) JsonBuilder(gg.projecteden.nexus.utils.JsonBuilder) HallOfHistoryService(gg.projecteden.nexus.models.hallofhistory.HallOfHistoryService) RankHistory(gg.projecteden.nexus.models.hallofhistory.HallOfHistory.RankHistory) UUID(java.util.UUID) Path(gg.projecteden.nexus.framework.commands.models.annotations.Path) Async(gg.projecteden.annotations.Async)

Example 3 with RankHistory

use of gg.projecteden.nexus.models.hallofhistory.HallOfHistory.RankHistory in project Nexus by ProjectEdenGG.

the class HallOfHistoryCommand method promotionTimes.

@Path("promotionTimes [page]")
void promotionTimes(@Arg("1") int page) {
    HallOfHistoryService service = new HallOfHistoryService();
    Map<UUID, Long> promotionTimeMap = new HashMap<>();
    for (HallOfHistory hallOfHistory : service.getAll()) {
        Nerd nerd = Nerd.of(hallOfHistory.getUuid());
        List<RankHistory> history = hallOfHistory.getRankHistory();
        history.sort(Comparator.comparing(RankHistory::getPromotionDate));
        if (nerd.getFirstJoin().isBefore(ServerAge.getEPOCH().minusYears(1)))
            continue;
        long days = nerd.getFirstJoin().toLocalDate().until(history.get(0).getPromotionDate(), ChronoUnit.DAYS);
        if (days > 0)
            promotionTimeMap.put(hallOfHistory.getUuid(), days);
    }
    OptionalDouble average = promotionTimeMap.values().stream().mapToLong(Long::valueOf).average();
    send(PREFIX + "Promotion times  |  Average: " + StringUtils.getNf().format(average.orElse(0)) + " days");
    BiFunction<UUID, String, JsonBuilder> formatter = (uuid, index) -> {
        String time = Timespan.ofSeconds(promotionTimeMap.get(uuid) * (TickTime.DAY.get() / 20)).format();
        return json(index + " &e" + Nickname.of(uuid) + " &7- " + time);
    };
    paginate(Utils.sortByValue(promotionTimeMap).keySet(), formatter, "/hoh promotionTimes", page);
}
Also used : StringUtils(gg.projecteden.nexus.utils.StringUtils) JsonBuilder(gg.projecteden.nexus.utils.JsonBuilder) BiFunction(java.util.function.BiFunction) OptionalDouble(java.util.OptionalDouble) Async(gg.projecteden.annotations.Async) Arg(gg.projecteden.nexus.framework.commands.models.annotations.Arg) HashMap(java.util.HashMap) Group(gg.projecteden.nexus.framework.commands.models.annotations.Permission.Group) RankHistory(gg.projecteden.nexus.models.hallofhistory.HallOfHistory.RankHistory) ArrayList(java.util.ArrayList) Nullables.isNullOrEmpty(gg.projecteden.nexus.utils.Nullables.isNullOrEmpty) ServerAge(gg.projecteden.nexus.features.commands.AgeCommand.ServerAge) Map(java.util.Map) Permission(gg.projecteden.nexus.framework.commands.models.annotations.Permission) Nickname(gg.projecteden.nexus.models.nickname.Nickname) Timespan(gg.projecteden.utils.TimeUtils.Timespan) ConfirmationMenu(gg.projecteden.nexus.features.menus.MenuUtils.ConfirmationMenu) Path(gg.projecteden.nexus.framework.commands.models.annotations.Path) Nerd(gg.projecteden.nexus.models.nerd.Nerd) Rank(gg.projecteden.nexus.models.nerd.Rank) CustomCommand(gg.projecteden.nexus.framework.commands.models.CustomCommand) Tasks(gg.projecteden.nexus.utils.Tasks) TimeUtils.shortDateFormat(gg.projecteden.utils.TimeUtils.shortDateFormat) UUID(java.util.UUID) PlayerNotFoundException(gg.projecteden.nexus.framework.exceptions.postconfigured.PlayerNotFoundException) TimeUtils.dateFormat(gg.projecteden.utils.TimeUtils.dateFormat) EdenSocialMediaSite(gg.projecteden.nexus.features.socialmedia.SocialMedia.EdenSocialMediaSite) HallOfHistory(gg.projecteden.nexus.models.hallofhistory.HallOfHistory) Utils(gg.projecteden.nexus.utils.Utils) OfflinePlayer(org.bukkit.OfflinePlayer) StringUtils.stripColor(gg.projecteden.nexus.utils.StringUtils.stripColor) Aliases(gg.projecteden.nexus.framework.commands.models.annotations.Aliases) TickTime(gg.projecteden.utils.TimeUtils.TickTime) List(java.util.List) ChronoUnit(java.time.temporal.ChronoUnit) CommandEvent(gg.projecteden.nexus.framework.commands.models.events.CommandEvent) LocalDate(java.time.LocalDate) NerdService(gg.projecteden.nexus.models.nerd.NerdService) HallOfHistoryService(gg.projecteden.nexus.models.hallofhistory.HallOfHistoryService) Comparator(java.util.Comparator) HashMap(java.util.HashMap) HallOfHistory(gg.projecteden.nexus.models.hallofhistory.HallOfHistory) Nerd(gg.projecteden.nexus.models.nerd.Nerd) OptionalDouble(java.util.OptionalDouble) JsonBuilder(gg.projecteden.nexus.utils.JsonBuilder) HallOfHistoryService(gg.projecteden.nexus.models.hallofhistory.HallOfHistoryService) RankHistory(gg.projecteden.nexus.models.hallofhistory.HallOfHistory.RankHistory) UUID(java.util.UUID) Path(gg.projecteden.nexus.framework.commands.models.annotations.Path)

Example 4 with RankHistory

use of gg.projecteden.nexus.models.hallofhistory.HallOfHistory.RankHistory in project Nexus by ProjectEdenGG.

the class HallOfHistoryCommand method view.

@Async
@Path("view <player>")
void view(OfflinePlayer target) {
    line(4);
    Nerd nerd = Nerd.of(target);
    send("&e&l" + nerd.getNickname());
    line();
    if (!nerd.getNickname().equals(nerd.getName()))
        send("  &eIGN: &3" + nerd.getName());
    if (!nerd.getPronouns().isEmpty())
        send("  &ePronouns: &3" + String.join(", ", nerd.getPronouns().stream().map(Enum::toString).toList()));
    line();
    HallOfHistory hallOfHistory = service.get(target.getUniqueId());
    for (RankHistory rankHistory : hallOfHistory.getRankHistory()) {
        JsonBuilder builder = new JsonBuilder();
        builder.next("  " + (rankHistory.isCurrent() ? "&2Current" : "&cFormer") + " " + rankHistory.getRank().getChatColor() + rankHistory.getRank().getName());
        if (isStaff())
            builder.next("  &c[x]").command("/hoh removerank " + target.getName() + " " + getRankCommandArgs(rankHistory));
        send(builder);
        send("    &ePromotion Date: &3" + shortDateFormat(rankHistory.getPromotionDate()));
        if (rankHistory.getResignationDate() != null)
            send("    &eResignation Date: &3" + shortDateFormat(rankHistory.getResignationDate()));
    }
    line();
    if (!isNullOrEmpty(nerd.getAbout()))
        send("  &eAbout me: &3" + nerd.getAbout());
    if (nerd.isMeetMeVideo()) {
        line();
        String url = EdenSocialMediaSite.WEBSITE.getUrl() + "/meet/" + nerd.getName().toLowerCase();
        send(json("  &eMeet Me!&c " + url).url(url));
    }
}
Also used : JsonBuilder(gg.projecteden.nexus.utils.JsonBuilder) HallOfHistory(gg.projecteden.nexus.models.hallofhistory.HallOfHistory) RankHistory(gg.projecteden.nexus.models.hallofhistory.HallOfHistory.RankHistory) Nerd(gg.projecteden.nexus.models.nerd.Nerd) Path(gg.projecteden.nexus.framework.commands.models.annotations.Path) Async(gg.projecteden.annotations.Async)

Aggregations

Async (gg.projecteden.annotations.Async)4 Path (gg.projecteden.nexus.framework.commands.models.annotations.Path)4 HallOfHistory (gg.projecteden.nexus.models.hallofhistory.HallOfHistory)4 RankHistory (gg.projecteden.nexus.models.hallofhistory.HallOfHistory.RankHistory)4 Nerd (gg.projecteden.nexus.models.nerd.Nerd)4 JsonBuilder (gg.projecteden.nexus.utils.JsonBuilder)4 ServerAge (gg.projecteden.nexus.features.commands.AgeCommand.ServerAge)3 ConfirmationMenu (gg.projecteden.nexus.features.menus.MenuUtils.ConfirmationMenu)3 EdenSocialMediaSite (gg.projecteden.nexus.features.socialmedia.SocialMedia.EdenSocialMediaSite)3 CustomCommand (gg.projecteden.nexus.framework.commands.models.CustomCommand)3 Aliases (gg.projecteden.nexus.framework.commands.models.annotations.Aliases)3 Arg (gg.projecteden.nexus.framework.commands.models.annotations.Arg)3 Permission (gg.projecteden.nexus.framework.commands.models.annotations.Permission)3 Group (gg.projecteden.nexus.framework.commands.models.annotations.Permission.Group)3 CommandEvent (gg.projecteden.nexus.framework.commands.models.events.CommandEvent)3 PlayerNotFoundException (gg.projecteden.nexus.framework.exceptions.postconfigured.PlayerNotFoundException)3 HallOfHistoryService (gg.projecteden.nexus.models.hallofhistory.HallOfHistoryService)3 NerdService (gg.projecteden.nexus.models.nerd.NerdService)3 Rank (gg.projecteden.nexus.models.nerd.Rank)3 Nickname (gg.projecteden.nexus.models.nickname.Nickname)3