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();
}));
}
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");
}
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(", "))));
}
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);
}
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;
}
Aggregations