Search in sources :

Example 1 with Nickname

use of gg.projecteden.nexus.models.nickname.Nickname in project Nexus by ProjectEdenGG.

the class TrustProvider method init.

@Override
public void init(Player player, InventoryContents contents) {
    if (back == null)
        addCloseItem(contents);
    else
        addBackItem(contents, e -> back.run());
    List<ClickableItem> items = new ArrayList<>();
    trust.getAll().stream().map(PlayerUtils::getPlayer).sorted(Comparator.comparing(Nickname::of)).collect(Collectors.toList()).forEach(_player -> {
        if (filterType.get() != null)
            if (!trust.trusts(filterType.get(), _player))
                return;
        ItemBuilder builder = new ItemBuilder(Material.PLAYER_HEAD).skullOwner(_player).name("&e" + Nickname.of(_player));
        for (Trust.Type type : Trust.Type.values()) {
            // TODO Decorations
            if (type.equals(Type.DECORATIONS) && !Rank.of(player).isStaff())
                continue;
            if (trust.trusts(type, _player))
                builder.lore("&a" + type.camelCase());
            else
                builder.lore("&c" + type.camelCase());
        }
        builder.lore("").lore("&fClick to edit");
        items.add(ClickableItem.from(builder.build(), e -> TrustPlayerProvider.open(player, _player)));
    });
    paginator(player, contents, items);
    ItemBuilder add = new ItemBuilder(Material.LIME_CONCRETE_POWDER).name("&aAdd Trust");
    contents.set(0, 8, ClickableItem.from(add.build(), e -> Nexus.getSignMenuFactory().lines("", ARROWS, "Enter a", "player's name").prefix(Features.get(TrustFeature.class).getPrefix()).response(lines -> {
        if (lines[0].length() > 0) {
            OfflinePlayer trusted = PlayerUtils.getPlayer(lines[0]);
            TrustPlayerProvider.open(player, trusted);
        } else
            openMenu(player);
    }).open(player)));
    Trust.Type previous = filterType.get() == null ? Type.values()[0].previousWithLoop() : filterType.get().previous();
    Trust.Type current = filterType.get();
    Trust.Type next = filterType.get() == null ? Type.values()[0] : filterType.get().next();
    if (current == previous)
        previous = null;
    if (current == next)
        next = null;
    ItemBuilder item = new ItemBuilder(Material.HOPPER).name("&6Filter by:").lore("&7⬇ " + (previous == null ? "All" : previous.camelCase())).lore("&e⬇ " + (current == null ? "All" : current.camelCase())).lore("&7⬇ " + (next == null ? "All" : next.camelCase()));
    Trust.Type finalNext = next;
    contents.set(contents.inventory().getRows() - 1, 4, ClickableItem.from(item.build(), e -> {
        filterType.set(finalNext);
        refresh();
    }));
}
Also used : Nexus(gg.projecteden.nexus.Nexus) ItemBuilder(gg.projecteden.nexus.utils.ItemBuilder) Trust(gg.projecteden.nexus.models.trust.Trust) Rank(gg.projecteden.nexus.models.nerd.Rank) SmartInventory(fr.minuskube.inv.SmartInventory) Player(org.bukkit.entity.Player) ARROWS(gg.projecteden.nexus.features.menus.SignMenuFactory.ARROWS) AtomicReference(java.util.concurrent.atomic.AtomicReference) Collectors(java.util.stream.Collectors) OfflinePlayer(org.bukkit.OfflinePlayer) ArrayList(java.util.ArrayList) Features(gg.projecteden.nexus.framework.features.Features) PlayerUtils(gg.projecteden.nexus.utils.PlayerUtils) List(java.util.List) Type(gg.projecteden.nexus.models.trust.Trust.Type) InventoryProvider(fr.minuskube.inv.content.InventoryProvider) InventoryContents(fr.minuskube.inv.content.InventoryContents) MenuUtils(gg.projecteden.nexus.features.menus.MenuUtils) TrustFeature(gg.projecteden.nexus.features.trust.TrustFeature) TrustService(gg.projecteden.nexus.models.trust.TrustService) Nickname(gg.projecteden.nexus.models.nickname.Nickname) Comparator(java.util.Comparator) Material(org.bukkit.Material) ClickableItem(fr.minuskube.inv.ClickableItem) ItemBuilder(gg.projecteden.nexus.utils.ItemBuilder) ClickableItem(fr.minuskube.inv.ClickableItem) ArrayList(java.util.ArrayList) OfflinePlayer(org.bukkit.OfflinePlayer) Type(gg.projecteden.nexus.models.trust.Trust.Type) Trust(gg.projecteden.nexus.models.trust.Trust)

Example 2 with Nickname

use of gg.projecteden.nexus.models.nickname.Nickname in project Nexus by ProjectEdenGG.

the class RoleManager method update.

public static void update(DiscordUser user) {
    if (Discord.getGuild() == null)
        return;
    DiscordUserService service = new DiscordUserService();
    String name = Name.of(user);
    if (name == null)
        return;
    if (ignore.contains(user.getUniqueId()))
        return;
    String nickname = Nickname.of(user);
    Color roleColor = user.getRank().getDiscordColor();
    if (roleColor == null) {
        user.setRoleId(null);
        service.save(user);
        return;
    }
    debug("Updating role for " + user.getNickname());
    if (user.getRoleId() == null) {
        debug("  No role found, searching");
        List<Role> rolesByName = Discord.getGuild().getRolesByName(name, true);
        if (rolesByName.size() > 0) {
            debug("    Found matching username role");
            user.setRoleId(rolesByName.get(0).getId());
            service.save(user);
        } else {
            List<Role> rolesByNickname = Discord.getGuild().getRolesByName(nickname, true);
            if (rolesByNickname.size() > 0) {
                debug("    Found matching nickname role");
                user.setRoleId(rolesByNickname.get(0).getId());
                service.save(user);
            } else {
                debug("    No matching role found, creating a new one");
                Discord.getGuild().createRole().setName(nickname).setColor(roleColor).queue();
                return;
            }
        }
    }
    Role role = Discord.getGuild().getRoleById(user.getRoleId());
    if (role == null) {
        debug("  Unable to retrieve role, deleted?");
        return;
    }
    debug("  Role found, checking for updates");
    boolean update = false;
    net.dv8tion.jda.api.managers.RoleManager manager = role.getManager();
    if (!roleColor.equals(role.getColor())) {
        debug("    Updating color to " + roleColor);
        update = true;
        manager.setColor(roleColor);
    }
    if (!role.getName().equals(nickname)) {
        debug("    Updating nickname to " + nickname);
        update = true;
        manager.setName(nickname);
    }
    if (update)
        manager.queue(success -> Nexus.debug("      Updated role"), error -> {
            throw new RuntimeException(error);
        });
    else
        debug("    No updates needed");
}
Also used : Role(net.dv8tion.jda.api.entities.Role) Nexus(gg.projecteden.nexus.Nexus) Color(java.awt.Color) DiscordUser(gg.projecteden.nexus.models.discord.DiscordUser) Arrays(java.util.Arrays) List(java.util.List) Role(net.dv8tion.jda.api.entities.Role) DiscordUserService(gg.projecteden.nexus.models.discord.DiscordUserService) Nickname(gg.projecteden.nexus.models.nickname.Nickname) Dev(gg.projecteden.nexus.utils.PlayerUtils.Dev) UUID(java.util.UUID) Name(gg.projecteden.nexus.utils.Name) Discord(gg.projecteden.nexus.features.discord.Discord) Color(java.awt.Color) DiscordUserService(gg.projecteden.nexus.models.discord.DiscordUserService)

Example 3 with Nickname

use of gg.projecteden.nexus.models.nickname.Nickname in project Nexus by ProjectEdenGG.

the class VoteCommand method onlineCounts.

@Async
@Permission(Group.ADMIN)
@Path("onlineCounts")
void onlineCounts() {
    Map<Integer, List<Player>> activeVotes = new HashMap<>();
    for (Player player : OnlinePlayers.getAll()) {
        Voter voter = service.get(player);
        int count = voter.getActiveVotes().size();
        List<Player> players = activeVotes.getOrDefault(count, new ArrayList<>());
        players.add(player);
        activeVotes.put(count, players);
    }
    send(PREFIX + "Vote counts");
    Utils.sortByKeyReverse(activeVotes).forEach((count, players) -> send("&e" + count + " &7- " + players.stream().map(Nickname::of).collect(Collectors.joining(", "))));
}
Also used : Player(org.bukkit.entity.Player) HashMap(java.util.HashMap) Voter(gg.projecteden.nexus.models.voter.Voter) ArrayList(java.util.ArrayList) List(java.util.List) Nickname(gg.projecteden.nexus.models.nickname.Nickname) Path(gg.projecteden.nexus.framework.commands.models.annotations.Path) Async(gg.projecteden.annotations.Async) Permission(gg.projecteden.nexus.framework.commands.models.annotations.Permission)

Example 4 with Nickname

use of gg.projecteden.nexus.models.nickname.Nickname in project Nexus by ProjectEdenGG.

the class ScoreboardCommand method list.

@Permission(Group.STAFF)
@Path("list")
void list() {
    String collect = OnlinePlayers.getAll().stream().map(player -> new ScoreboardService().get(player)).filter(ScoreboardUser::isActive).map(Nickname::of).collect(Collectors.joining("&3, &e"));
    send(PREFIX + "Active scoreboards: ");
    send("&e" + collect);
}
Also used : JsonBuilder(gg.projecteden.nexus.utils.JsonBuilder) TabCompleteIgnore(gg.projecteden.nexus.framework.commands.models.annotations.TabCompleteIgnore) Group(gg.projecteden.nexus.framework.commands.models.annotations.Permission.Group) MinigamerQuitEvent(gg.projecteden.nexus.features.minigames.models.events.matches.MinigamerQuitEvent) WrittenBookMenu(gg.projecteden.nexus.features.menus.BookBuilder.WrittenBookMenu) MatchJoinEvent(gg.projecteden.nexus.features.minigames.models.events.matches.MatchJoinEvent) EventHandler(org.bukkit.event.EventHandler) McMMOScoreboardRevertEvent(com.gmail.nossr50.events.scoreboard.McMMOScoreboardRevertEvent) MatchEndEvent(gg.projecteden.nexus.features.minigames.models.events.matches.MatchEndEvent) Permission(gg.projecteden.nexus.framework.commands.models.annotations.Permission) Nickname(gg.projecteden.nexus.models.nickname.Nickname) Listener(org.bukkit.event.Listener) PlayerJoinEvent(org.bukkit.event.player.PlayerJoinEvent) Description(gg.projecteden.nexus.framework.commands.models.annotations.Description) Path(gg.projecteden.nexus.framework.commands.models.annotations.Path) NonNull(lombok.NonNull) CustomCommand(gg.projecteden.nexus.framework.commands.models.CustomCommand) HideFromHelp(gg.projecteden.nexus.framework.commands.models.annotations.HideFromHelp) ScoreboardService(gg.projecteden.nexus.models.scoreboard.ScoreboardService) Collectors(java.util.stream.Collectors) ScoreboardUser(gg.projecteden.nexus.models.scoreboard.ScoreboardUser) OfflinePlayer(org.bukkit.OfflinePlayer) Aliases(gg.projecteden.nexus.framework.commands.models.annotations.Aliases) CommandEvent(gg.projecteden.nexus.framework.commands.models.events.CommandEvent) PlayerQuitEvent(org.bukkit.event.player.PlayerQuitEvent) OnlinePlayers(gg.projecteden.nexus.utils.PlayerUtils.OnlinePlayers) PlayerChangedWorldEvent(org.bukkit.event.player.PlayerChangedWorldEvent) NoArgsConstructor(lombok.NoArgsConstructor) ScoreboardUser(gg.projecteden.nexus.models.scoreboard.ScoreboardUser) ScoreboardService(gg.projecteden.nexus.models.scoreboard.ScoreboardService) Path(gg.projecteden.nexus.framework.commands.models.annotations.Path) Permission(gg.projecteden.nexus.framework.commands.models.annotations.Permission)

Example 5 with Nickname

use of gg.projecteden.nexus.models.nickname.Nickname in project Nexus by ProjectEdenGG.

the class IngameBridgeListener method parseMentions.

public static String parseMentions(String message) {
    if (message != null && message.contains("@")) {
        Matcher matcher = Pattern.compile("@[\\w]+").matcher(message);
        while (matcher.find()) {
            String group = matcher.group();
            String search = group.replace("@", "");
            Nerd nerd = new NerdService().findExact(search);
            if (nerd != null) {
                DiscordUser mentioned = new DiscordUserService().get(nerd);
                if (mentioned.getUserId() != null) {
                    message = message.replace(group, "<@" + mentioned.getUserId() + ">");
                } else {
                    Nickname fromNickname = new NicknameService().getFromNickname(search);
                    if (fromNickname != null) {
                        mentioned = new DiscordUserService().get(fromNickname);
                        if (mentioned.getUserId() != null)
                            message = message.replace(group, "<@" + mentioned.getUserId() + ">");
                    }
                }
            }
        }
    }
    return message;
}
Also used : DiscordUser(gg.projecteden.nexus.models.discord.DiscordUser) Matcher(java.util.regex.Matcher) DiscordUserService(gg.projecteden.nexus.models.discord.DiscordUserService) NicknameService(gg.projecteden.nexus.models.nickname.NicknameService) Nerd(gg.projecteden.nexus.models.nerd.Nerd) NerdService(gg.projecteden.nexus.models.nerd.NerdService) Nickname(gg.projecteden.nexus.models.nickname.Nickname)

Aggregations

Nickname (gg.projecteden.nexus.models.nickname.Nickname)6 Path (gg.projecteden.nexus.framework.commands.models.annotations.Path)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Async (gg.projecteden.annotations.Async)2 Nexus (gg.projecteden.nexus.Nexus)2 Permission (gg.projecteden.nexus.framework.commands.models.annotations.Permission)2 DiscordUser (gg.projecteden.nexus.models.discord.DiscordUser)2 DiscordUserService (gg.projecteden.nexus.models.discord.DiscordUserService)2 Collectors (java.util.stream.Collectors)2 OfflinePlayer (org.bukkit.OfflinePlayer)2 Player (org.bukkit.entity.Player)2 McMMOScoreboardRevertEvent (com.gmail.nossr50.events.scoreboard.McMMOScoreboardRevertEvent)1 ClickableItem (fr.minuskube.inv.ClickableItem)1 SmartInventory (fr.minuskube.inv.SmartInventory)1 InventoryContents (fr.minuskube.inv.content.InventoryContents)1 InventoryProvider (fr.minuskube.inv.content.InventoryProvider)1 Discord (gg.projecteden.nexus.features.discord.Discord)1 WrittenBookMenu (gg.projecteden.nexus.features.menus.BookBuilder.WrittenBookMenu)1 MenuUtils (gg.projecteden.nexus.features.menus.MenuUtils)1