Search in sources :

Example 1 with DiscordUser

use of gg.projecteden.nexus.models.discord.DiscordUser in project Nexus by ProjectEdenGG.

the class JoinQuit method quit.

public static void quit(Player player, QuitReason reason) {
    // Denizen Discord: https://discord.com/channels/315163488085475337/315163488085475337/929117355223695360
    if (!player.isOnline())
        return;
    if (isDuplicate(player, "quit"))
        return;
    String message = "&c[player] &5has left the server";
    if (player.hasPermission("jq.custom") && quitMessages.size() > 0)
        message = RandomUtils.randomElement(quitMessages);
    final String finalMessage = message;
    final String ingame = formatQuit(player, finalMessage);
    final Component component = AdventureUtils.fromLegacyAmpersandText(ingame);
    final Component staffComponent = AdventureUtils.fromLegacyAmpersandText(ingame + " (" + StringUtils.camelCase(reason.name()) + ")");
    OnlinePlayers.getAll().forEach(_player -> {
        if (!MuteMenuUser.hasMuted(_player, MuteMenuItem.JOIN_QUIT)) {
            if (reason != QuitReason.DISCONNECTED && Rank.of(_player).isStaff())
                _player.sendMessage(player, staffComponent, MessageType.CHAT);
            else
                _player.sendMessage(player, component, MessageType.CHAT);
        }
    });
    Jingle.QUIT.playAll();
    Tasks.async(() -> {
        DiscordUser user = new DiscordUserService().get(player);
        RoleManager.update(user);
        final String discord = discordize(finalMessage).replaceAll("\\[player]", "**" + Nickname.discordOf(player) + "**");
        Discord.send("<:red_arrow_left:331808021267218432> " + discord, TextChannel.BRIDGE);
    });
}
Also used : DiscordUser(gg.projecteden.nexus.models.discord.DiscordUser) DiscordUserService(gg.projecteden.nexus.models.discord.DiscordUserService) Component(net.kyori.adventure.text.Component)

Example 2 with DiscordUser

use of gg.projecteden.nexus.models.discord.DiscordUser in project Nexus by ProjectEdenGG.

the class JoinQuit method join.

public static void join(Player player) {
    if (isDuplicate(player, "join"))
        return;
    String message = "&a[player] &5has joined the server";
    if (player.hasPermission("jq.custom") && joinMessages.size() > 0)
        message = RandomUtils.randomElement(joinMessages);
    final String finalMessage = message;
    if (player.isOnline()) {
        final String ingame = formatJoin(player, finalMessage);
        final Component component = AdventureUtils.fromLegacyAmpersandText(ingame);
        OnlinePlayers.getAll().forEach(_player -> {
            if (!MuteMenuUser.hasMuted(_player, MuteMenuItem.JOIN_QUIT))
                _player.sendMessage(player, component, MessageType.CHAT);
        });
        if (!player.hasPlayedBefore())
            Jingle.FIRST_JOIN.playAll();
        else
            Jingle.JOIN.playAll();
        Tasks.async(() -> {
            DiscordUser user = new DiscordUserService().get(player);
            RoleManager.update(user);
            final String discord = discordize(finalMessage).replaceAll("\\[player]", "**" + Nickname.discordOf(player) + "**");
            Discord.send("<:blue_arrow_right:883811353641517126> " + discord, TextChannel.BRIDGE);
        });
    }
}
Also used : DiscordUser(gg.projecteden.nexus.models.discord.DiscordUser) DiscordUserService(gg.projecteden.nexus.models.discord.DiscordUserService) Component(net.kyori.adventure.text.Component)

Example 3 with DiscordUser

use of gg.projecteden.nexus.models.discord.DiscordUser in project Nexus by ProjectEdenGG.

the class HandlePurchaseCommand method run.

@Path("<data...>")
void run(String data) {
    Nexus.log("Purchase caught; processing... " + data);
    String[] args = data.split("\\|");
    Purchase purchase = Purchase.builder().id(UUID.randomUUID()).name(args[0]).uuid(UUID.fromString(uuidFormat(args[1]))).transactionId(args[2]).price(Double.parseDouble(args[3])).currency(args[4]).timestamp(LocalDateTime.parse(args[6] + " " + args[5], formatter)).email(args[7]).ip(args[8]).packageId(args[9]).packagePrice(Double.parseDouble(args[10])).packageExpiry(args[11]).packageName(args[12]).purchaserName(args[13]).purchaserUuid(UUID.fromString(uuidFormat(args[14]))).build();
    String discordMessage = purchase.toDiscordString();
    final ContributorService contributorService = new ContributorService();
    final Contributor contributor = contributorService.get(purchase.getPurchaserUuid());
    Package packageType = Package.getPackage(purchase.getPackageId());
    if (packageType == null)
        discordMessage += "\nPackage not recognized!";
    else {
        if (purchase.getPrice() > 0) {
            send(purchase.getUuid(), PREFIX + "Thank you for buying &e" + purchase.getPackageName() + "&3! " + "Your contribution is &3&ogreatly &3appreciated and will be put to good use.");
            if (contributor.isBroadcasts())
                if (packageType == Package.CUSTOM_DONATION) {
                    Koda.say("Thank you for your custom donation, " + purchase.getNickname() + "! " + "We greatly appreciate your selfless contribution &4❤");
                    // this is not necessarily what they donated
                    // if they make a custom donation and purchase items at the same
                    // time, i have no way to break down the price from the payload
                    // but that is very rare, so its better than nothing i guess
                    contributor.giveCredit(purchase.getPrice());
                } else
                    Koda.say("Thank you for your purchase, " + purchase.getNickname() + "! " + "Enjoy your " + purchase.getPackageName() + " perk!");
            if (packageType.getCategory() == StoreCategory.BOOSTS)
                send(purchase.getUuid(), PREFIX + "Make sure you activate your boost with &c/boost menu");
            if (isV4Uuid(purchase.getPurchaserUuid())) {
                new BadgeUserService().edit(purchase.getPurchaserUuid(), badgeUser -> badgeUser.give(Badge.SUPPORTER));
                DiscordUser user = new DiscordUserService().get(purchase.getPurchaserUuid());
                if (user.getUserId() != null)
                    Discord.addRole(user.getUserId(), Role.SUPPORTER);
                else
                    discordMessage += "\nUser does not have a linked discord account";
            }
        } else {
            send(purchase.getUuid(), PREFIX + "Your free " + purchase.getPackageName() + " has been successfully processed, enjoy!");
        }
        packageType.apply(purchase.getUuid());
        discordMessage += "\nPurchase successfully processed.";
    }
    Discord.send(discordMessage, TextChannel.ADMIN_LOG);
    contributor.add(purchase);
    contributorService.save(contributor);
}
Also used : DiscordUser(gg.projecteden.nexus.models.discord.DiscordUser) Purchase(gg.projecteden.nexus.models.store.Contributor.Purchase) ContributorService(gg.projecteden.nexus.models.store.ContributorService) Contributor(gg.projecteden.nexus.models.store.Contributor) BadgeUserService(gg.projecteden.nexus.models.badge.BadgeUserService) DiscordUserService(gg.projecteden.nexus.models.discord.DiscordUserService) Path(gg.projecteden.nexus.framework.commands.models.annotations.Path)

Example 4 with DiscordUser

use of gg.projecteden.nexus.models.discord.DiscordUser in project Nexus by ProjectEdenGG.

the class TeamMechanic method getVoiceChannelMember.

@Nullable
public static Member getVoiceChannelMember(@NotNull OptionalPlayer hasPlayer) {
    Player player = hasPlayer.getPlayer();
    if (player == null)
        return null;
    Guild guild = Discord.getGuild();
    if (guild == null)
        return null;
    DiscordUser discordUser = new DiscordUserService().get(player);
    Member member = discordUser.getMember();
    if (member == null) {
        // user has no linked account, find a disc account with matching (nick)name
        Optional<Member> optionalMember = guild.getMembers().stream().filter(fmember -> (fmember.getNickname() != null && fmember.getNickname().equalsIgnoreCase(Name.of(player))) || fmember.getUser().getName().equalsIgnoreCase(Name.of(player))).findAny();
        if (optionalMember.isPresent())
            member = optionalMember.get();
        else
            return null;
    }
    if (member.getVoiceState() == null || !member.getVoiceState().inAudioChannel())
        return null;
    return member;
}
Also used : MatchTasks(gg.projecteden.nexus.features.minigames.models.Match.MatchTasks) VoiceChannelCategory(gg.projecteden.utils.DiscordId.VoiceChannelCategory) JsonBuilder(gg.projecteden.nexus.utils.JsonBuilder) LocalDateTime(java.time.LocalDateTime) OptionalPlayer(me.lexikiq.OptionalPlayer) HashMap(java.util.HashMap) Member(net.dv8tion.jda.api.entities.Member) Player(org.bukkit.entity.Player) MatchData(gg.projecteden.nexus.features.minigames.models.MatchData) Name(gg.projecteden.nexus.utils.Name) Match(gg.projecteden.nexus.features.minigames.models.Match) MinigamerQuitEvent(gg.projecteden.nexus.features.minigames.models.events.matches.MinigamerQuitEvent) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Guild(net.dv8tion.jda.api.entities.Guild) MatchEndEvent(gg.projecteden.nexus.features.minigames.models.events.matches.MatchEndEvent) RandomUtils(gg.projecteden.nexus.utils.RandomUtils) Component(net.kyori.adventure.text.Component) Map(java.util.Map) Team(gg.projecteden.nexus.features.minigames.models.Team) Minigames(gg.projecteden.nexus.features.minigames.Minigames) ChatColor(net.md_5.bungee.api.ChatColor) Nexus(gg.projecteden.nexus.Nexus) DiscordUserService(gg.projecteden.nexus.models.discord.DiscordUserService) Minigamer(gg.projecteden.nexus.features.minigames.models.Minigamer) Set(java.util.Set) EqualsAndHashCode(lombok.EqualsAndHashCode) Collectors(java.util.stream.Collectors) Discord(gg.projecteden.nexus.features.discord.Discord) Arena(gg.projecteden.nexus.features.minigames.models.Arena) MinigamerDeathEvent(gg.projecteden.nexus.features.minigames.models.events.matches.minigamers.MinigamerDeathEvent) DiscordId(gg.projecteden.utils.DiscordId) MatchTaskType(gg.projecteden.nexus.features.minigames.models.Match.MatchTasks.MatchTaskType) TickTime(gg.projecteden.utils.TimeUtils.TickTime) Nullable(org.jetbrains.annotations.Nullable) DiscordUser(gg.projecteden.nexus.models.discord.DiscordUser) List(java.util.List) Data(lombok.Data) Optional(java.util.Optional) NotNull(org.jetbrains.annotations.NotNull) Comparator(java.util.Comparator) Collections(java.util.Collections) MultiplayerMechanic(gg.projecteden.nexus.features.minigames.models.mechanics.multiplayer.MultiplayerMechanic) DiscordUser(gg.projecteden.nexus.models.discord.DiscordUser) OptionalPlayer(me.lexikiq.OptionalPlayer) Player(org.bukkit.entity.Player) DiscordUserService(gg.projecteden.nexus.models.discord.DiscordUserService) Guild(net.dv8tion.jda.api.entities.Guild) Member(net.dv8tion.jda.api.entities.Member) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with DiscordUser

use of gg.projecteden.nexus.models.discord.DiscordUser in project Nexus by ProjectEdenGG.

the class BridgeCommand method updateRoleColors.

@Async
@Path("updateRoleColors <rank>")
void updateRoleColors(Rank rank) {
    int updated = 0;
    for (DiscordUser user : service.getAll()) {
        if (user.getRoleId() == null || user.getUuid() == null)
            continue;
        Rank playerRank = Rank.of(user);
        if (playerRank != rank)
            continue;
        net.dv8tion.jda.api.entities.Role role = Discord.getGuild().getRoleById(user.getRoleId());
        if (role == null)
            continue;
        role.getManager().setColor(rank.getDiscordColor()).queue();
        ++updated;
    }
    send("Updated " + updated + " roles");
}
Also used : DiscordUser(gg.projecteden.nexus.models.discord.DiscordUser) Role(net.dv8tion.jda.api.entities.Role) Rank(gg.projecteden.nexus.models.nerd.Rank) Path(gg.projecteden.nexus.framework.commands.models.annotations.Path) Async(gg.projecteden.annotations.Async)

Aggregations

DiscordUser (gg.projecteden.nexus.models.discord.DiscordUser)18 DiscordUserService (gg.projecteden.nexus.models.discord.DiscordUserService)15 Path (gg.projecteden.nexus.framework.commands.models.annotations.Path)8 Async (gg.projecteden.annotations.Async)7 JsonBuilder (gg.projecteden.nexus.utils.JsonBuilder)4 Role (net.dv8tion.jda.api.entities.Role)4 Nexus (gg.projecteden.nexus.Nexus)3 Discord (gg.projecteden.nexus.features.discord.Discord)3 Permission (gg.projecteden.nexus.framework.commands.models.annotations.Permission)3 Nickname (gg.projecteden.nexus.models.nickname.Nickname)3 List (java.util.List)3 Component (net.kyori.adventure.text.Component)3 BadgeUserService (gg.projecteden.nexus.models.badge.BadgeUserService)2 Rank (gg.projecteden.nexus.models.nerd.Rank)2 Name (gg.projecteden.nexus.utils.Name)2 DiscordId (gg.projecteden.utils.DiscordId)2 TextChannel (gg.projecteden.utils.DiscordId.TextChannel)2 Color (java.awt.Color)2 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2