Skip to content

Commit

Permalink
Merge pull request #651 from AtditC/update-alts-command
Browse files Browse the repository at this point in the history
/alts enhancement
  • Loading branch information
BennyDoesStuff authored May 14, 2020
2 parents 93eb660 + bf9429a commit 376a527
Showing 1 changed file with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ public static void lookupip(CommandContext cmd, CommandSender sender) {
});
}

@SuppressWarnings("DuplicatedCode")
@Command(aliases = "alts", desc = "Lookup alts of a user", min = 1, max = 1, usage = "(name)")
@CommandPermissions("tgm.lookup")
public static void alts(CommandContext cmd, CommandSender sender) {
Expand All @@ -262,12 +263,44 @@ public static void alts(CommandContext cmd, CommandSender sender) {
sender.sendMessage(ChatColor.GREEN + response.getLookupUser().getName() + " has no known alts.");
return;
}

String name = response.getLookupUser().getName();
List<String> alts = new ArrayList<>(Arrays.asList(
"",
ChatColor.AQUA + name + (name.endsWith("s") ? "'" : "'s") + " known alts:"
));
alts.addAll(response.getUsers().stream().map(user -> ChatColor.GRAY + " - " + ChatColor.WHITE + user.getName()).collect(Collectors.toList()));

for (UserProfile user : response.getUsers()) {
boolean isBanned = false;
boolean isMuted = false;

PunishmentsListResponse punishmentsListResponse = TGM.get().getTeamClient().getPunishments(new PunishmentsListRequest(user.getName(), null));
if (!punishmentsListResponse.isNotFound()) {
for (Punishment punishment : punishmentsListResponse.getPunishments()) {
if (punishment.getType().toUpperCase().equals("BAN") && punishment.isActive()) {
isBanned = true;
break;
}

if (punishment.getType().toUpperCase().equals("MUTE") && punishment.isActive()) {
isMuted = true;
}
}
}

ChatColor chatColor = ChatColor.WHITE;

if (isMuted) {
chatColor = ChatColor.YELLOW;
}

if (isBanned) {
chatColor = ChatColor.RED;
}

alts.add(ChatColor.GRAY + " - " + chatColor + user.getName());
}

alts.add(" ");
sender.sendMessage(alts.toArray(new String[0]));
}
Expand Down

0 comments on commit 376a527

Please sign in to comment.