Search in sources :

Example 1 with PaginatedResult

use of mc.dragons.core.storage.mongo.pagination.PaginatedResult in project DragonsOnline by UniverseCraft.

the class GuildAdminCommand method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (!requirePermission(sender, PermissionLevel.ADMIN))
        return true;
    User user = user(sender);
    if (args.length == 0) {
        sender.sendMessage(ChatColor.YELLOW + "/guildadmin new <Owner> <GuildName>");
        sender.sendMessage(ChatColor.YELLOW + "/guildadmin list [Page#]");
        sender.sendMessage(ChatColor.YELLOW + "/guildadmin info <GuildID>");
        sender.sendMessage(ChatColor.YELLOW + "/guildadmin members <GuildID>");
        sender.sendMessage(ChatColor.YELLOW + "/guildadmin of <Player>");
        sender.sendMessage(ChatColor.YELLOW + "/guildadmin setxp <GuildID> <XP>");
        sender.sendMessage(ChatColor.YELLOW + "/guildadmin addxp <GuildID> <XP>");
        sender.sendMessage(ChatColor.YELLOW + "/guildadmin desc <GuildID> <Description>");
        sender.sendMessage(ChatColor.YELLOW + "/guildadmin forcejoin <GuildID> [Player=you]");
        sender.sendMessage(ChatColor.YELLOW + "/guildadmin forceleave <GuildID> [Player=you]");
        sender.sendMessage(ChatColor.YELLOW + "/guildadmin setowner <GuildID> [Player=you]");
        sender.sendMessage(ChatColor.YELLOW + "/guildadmin delete <GuildID>");
    } else if (args[0].equalsIgnoreCase("new")) {
        if (args.length < 3) {
            sender.sendMessage(ChatColor.RED + "Usage: /guildadmin new <Owner> <GuildName>");
            return true;
        }
        User owner = lookupUser(sender, args[1]);
        if (owner == null)
            return true;
        String guildName = StringUtil.concatArgs(args, 2);
        Guild guild = guildLoader.addGuild(owner.getUUID(), guildName);
        owner.updateListName();
        sender.sendMessage(ChatColor.GREEN + "Created guild #" + guild.getId() + ": " + guildName);
    } else if (args[0].equalsIgnoreCase("list")) {
        Integer page = 1;
        if (args.length > 1) {
            page = parseInt(sender, args[1]);
            if (page == null)
                return true;
        }
        PaginatedResult<Guild> results = guildLoader.getAllGuilds(page);
        sender.sendMessage(ChatColor.GREEN + "Listing all guilds (Page " + page + " of " + results.getPages() + ", " + results.getTotal() + " total)");
        for (Guild guild : results.getPage()) {
            sender.sendMessage(ChatColor.GRAY + "- #" + guild.getId() + ": " + guild.getName() + " (owner: " + userLoader.loadObject(guild.getOwner()).getName() + ")");
        }
    } else if (args[0].equalsIgnoreCase("info")) {
        if (args.length == 1) {
            sender.sendMessage(ChatColor.RED + "Usage: /guildadmin info <GuildID>");
            return true;
        }
        Guild guild = lookupGuild(sender, args[1]);
        if (guild == null)
            return true;
        sender.sendMessage(ChatColor.GREEN + "Guild #" + guild.getId());
        sender.sendMessage(ChatColor.GRAY + "Name: " + ChatColor.RESET + guild.getName());
        sender.sendMessage(ChatColor.GRAY + "Description: " + ChatColor.RESET + guild.getDescription());
        sender.sendMessage(ChatColor.GRAY + "XP: " + ChatColor.RESET + guild.getXP());
        sender.sendMessage(ChatColor.GRAY + "Owner: " + ChatColor.RESET + userLoader.loadObject(guild.getOwner()).getName());
        sender.sendMessage(ChatColor.GRAY + "# Members: " + ChatColor.RESET + guild.getMembers().size());
    } else if (args[0].equalsIgnoreCase("of")) {
        if (args.length == 1) {
            sender.sendMessage(ChatColor.RED + "Usage: /guildadmin of <Player>");
            return true;
        }
        User test = lookupUser(sender, args[1]);
        if (test == null)
            return true;
        sender.sendMessage(ChatColor.GREEN + "Listing all guilds that " + args[1] + " is in:");
        for (Guild guild : guildLoader.getAllGuildsWithRaw(test.getUUID())) {
            sender.sendMessage(ChatColor.GRAY + "- #" + guild.getId() + ": " + guild.getName() + " (owner: " + userLoader.loadObject(guild.getOwner()).getName() + ")");
        }
    } else if (args[0].equalsIgnoreCase("members")) {
        if (args.length == 1) {
            sender.sendMessage(ChatColor.RED + "Usage: /guildadmin members <GuildID>");
            return true;
        }
        Guild guild = lookupGuild(sender, args[1]);
        if (guild == null)
            return true;
        sender.sendMessage(ChatColor.GREEN + "Guild " + guild.getName() + " has " + (guild.getMembers().size() + 1) + " members:" + ChatColor.GOLD + userLoader.loadObject(guild.getOwner()).getName() + " (Owner)" + ChatColor.GRAY + ", " + StringUtil.parseList(guild.getMembers().stream().map(uuid -> userLoader.loadObject(uuid).getName()).collect(Collectors.toList())));
    } else if (args[0].equalsIgnoreCase("setxp")) {
        if (args.length < 3) {
            sender.sendMessage(ChatColor.RED + "Usage: /guildadmin setxp <GuildID> <XP>");
            return true;
        }
        Guild guild = lookupGuild(sender, args[1]);
        if (guild == null)
            return true;
        guild.setXP(Integer.valueOf(args[2]));
        sender.sendMessage(ChatColor.GREEN + "Set XP of guild " + guild.getName() + " to " + guild.getXP());
    } else if (args[0].equalsIgnoreCase("addxp")) {
        if (args.length < 3) {
            sender.sendMessage(ChatColor.RED + "Usage: /guildadmin addxp <GuildID> <XP>");
            return true;
        }
        Guild guild = lookupGuild(sender, args[1]);
        if (guild == null)
            return true;
        guild.addXP(Integer.valueOf(args[2]));
        sender.sendMessage(ChatColor.GREEN + "Added " + args[2] + " XP to guild " + guild.getName() + " (total XP: " + guild.getXP() + ")");
    } else if (args[0].equalsIgnoreCase("desc")) {
        if (args.length < 3) {
            sender.sendMessage(ChatColor.RED + "Usage: /guildadmin desc <GuildID> <Description>");
            return true;
        }
        Guild guild = lookupGuild(sender, args[1]);
        if (guild == null)
            return true;
        String desc = StringUtil.concatArgs(args, 2);
        guild.setDescription(desc);
        sender.sendMessage(ChatColor.GREEN + "Set description of guild " + guild.getName() + " to " + desc);
    } else if (args[0].equalsIgnoreCase("forcejoin")) {
        if (args.length < 2) {
            sender.sendMessage(ChatColor.RED + "Usage: /guildadmin forcejoin <GuildID> [Player=you]");
            return true;
        }
        Guild guild = lookupGuild(sender, args[1]);
        if (guild == null)
            return true;
        User joiningUser = user;
        UUID joining = user.getUUID();
        if (args.length >= 3) {
            joiningUser = lookupUser(sender, args[2]);
            if (joiningUser == null)
                return true;
            joining = joiningUser.getUUID();
        }
        guild.getMembers().add(joining);
        guild.save();
        joiningUser.updateListName();
        sender.sendMessage(ChatColor.GREEN + "Added user " + joiningUser.getName() + " to guild " + guild.getName());
    } else if (args[0].equalsIgnoreCase("forceleave")) {
        if (args.length < 2) {
            sender.sendMessage(ChatColor.RED + "Usage: /guildadmin forceleave <GuildID> [Player=you]");
            return true;
        }
        Guild guild = lookupGuild(sender, args[1]);
        if (guild == null)
            return true;
        User leavingUser = user;
        UUID leaving = user.getUUID();
        if (args.length >= 3) {
            leavingUser = lookupUser(sender, args[2]);
            if (leavingUser == null)
                return true;
            leaving = leavingUser.getUUID();
        }
        guild.getMembers().remove(leaving);
        guild.save();
        leavingUser.updateListName();
        sender.sendMessage(ChatColor.GREEN + "Removed user " + leavingUser.getName() + " from guild " + guild.getName());
    } else if (args[0].equalsIgnoreCase("setowner")) {
        if (args.length < 2) {
            sender.sendMessage(ChatColor.RED + "Usage: /guildadmin setowner <GuildID> [Player=you]");
            return true;
        }
        Guild guild = lookupGuild(sender, args[1]);
        if (guild == null)
            return true;
        User ownerUser = user;
        UUID owner = user.getUUID();
        if (args.length >= 3) {
            ownerUser = lookupUser(sender, args[2]);
            if (ownerUser == null)
                return true;
            owner = ownerUser.getUUID();
        }
        UUID formerOwner = guild.getOwner();
        guild.getMembers().add(guild.getOwner());
        guild.setOwner(owner);
        guild.getMembers().remove(owner);
        guild.save();
        userLoader.loadObject(formerOwner).updateListName();
        ownerUser.updateListName();
        sender.sendMessage(ChatColor.GREEN + "Set owner of guid " + guild.getName() + " to " + ownerUser.getName());
    } else if (args[0].equalsIgnoreCase("delete")) {
        if (args.length == 1) {
            sender.sendMessage(ChatColor.RED + "Usage: /guildadmin delete <GuildID>");
            return true;
        }
        Guild guild = lookupGuild(sender, args[1]);
        if (guild == null)
            return true;
        guildLoader.deleteGuild(guild.getId());
        for (UUID uuid : guild.getMembers()) {
            userLoader.loadObject(uuid).updateListName();
        }
        sender.sendMessage(ChatColor.GREEN + "Deleted guild " + guild.getName() + " successfully.");
    } else {
        sender.sendMessage(ChatColor.RED + "Invalid sub-command! /guildadmin");
    }
    return true;
}
Also used : StringUtil(mc.dragons.core.util.StringUtil) CommandSender(org.bukkit.command.CommandSender) DragonsCommandExecutor(mc.dragons.core.commands.DragonsCommandExecutor) PermissionLevel(mc.dragons.core.gameobject.user.permission.PermissionLevel) Guild(mc.dragons.social.guild.GuildLoader.Guild) User(mc.dragons.core.gameobject.user.User) ChatColor(org.bukkit.ChatColor) Command(org.bukkit.command.Command) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) Dragons(mc.dragons.core.Dragons) PaginatedResult(mc.dragons.core.storage.mongo.pagination.PaginatedResult) User(mc.dragons.core.gameobject.user.User) Guild(mc.dragons.social.guild.GuildLoader.Guild) UUID(java.util.UUID)

Example 2 with PaginatedResult

use of mc.dragons.core.storage.mongo.pagination.PaginatedResult in project DragonsOnline by UniverseCraft.

the class ModUserHook method onVerifiedJoin.

@Override
public void onVerifiedJoin(User user) {
    WrappedUser wrapped = WrappedUser.of(user);
    Player player = user.getPlayer();
    Set<User> alts = IPAnalysisUtil.scanAlts(Dragons.getInstance().getPersistentStorageManager(), user).stream().filter(u -> WrappedUser.of(u).getActivePunishmentData(PunishmentType.BAN) != null).collect(Collectors.toSet());
    if (alts.size() > 0) {
        alertHandler.sendSuspiciousJoinMessage(ChatColor.GRAY + "[" + ChatColor.RED + "Join" + ChatColor.GRAY + "] User " + user.getName() + " shares an IP address with " + alts.size() + " currently banned user" + (alts.size() > 1 ? "s" : ""));
    }
    PaginatedResult<Report> watchlist = reportLoader.getReportsByTypeStatusAndTarget(ReportType.WATCHLIST, List.of(ReportStatus.OPEN, ReportStatus.SUSPENDED), user, 1);
    if (watchlist.getTotal() > 0) {
        watchlist.getPage().get(0).setStatus(ReportStatus.OPEN);
        alertHandler.sendSuspiciousJoinMessage(ChatColor.GRAY + "[" + ChatColor.RED + "Join" + ChatColor.GRAY + "] User " + user.getName() + " is currently on the watchlist (Report #" + watchlist.getPage().get(0).getId() + ")");
    }
    if (wrapped.reportWasHandled()) {
        player.sendMessage(ChatColor.GOLD + "" + ChatColor.ITALIC + "Your recent report was handled and closed. Thank you!");
        wrapped.setReportHandled(false);
    }
    PaginatedResult<Report> waiting = reportLoader.getAuthorizedUnreviewedReports(1, user.getActivePermissionLevel(), user.getUUID());
    if (waiting.getTotal() > 0) {
        player.sendMessage(ChatColor.LIGHT_PURPLE + "There are " + waiting.getTotal() + " reports in your moderation queue! To get started, do " + ChatColor.DARK_PURPLE + "/modqueue");
    }
    int i = 0;
    for (PunishmentData punishment : wrapped.getPunishmentHistory()) {
        if (punishment.getType() == PunishmentType.WARNING && !punishment.isWarningAcknowledged()) {
            String reason = punishment.getReason();
            player.sendMessage(" ");
            player.sendMessage(PunishCommand.RECEIVE_PREFIX + ChatColor.BOLD + "You received a warning since the last time you were online.");
            if (!reason.equals(" ")) {
                player.sendMessage(PunishCommand.RECEIVE_PREFIX + "Reason: " + reason);
            }
            player.sendMessage(PunishCommand.RECEIVE_PREFIX + ChatColor.GRAY + "Repeated warnings may result in a mute or ban.");
            player.spigot().sendMessage(StringUtil.clickableHoverableText(PunishCommand.RECEIVE_PREFIX + ChatColor.RESET + "[Click here to acknowledge warning]", "/acknowledgewarning " + i, "Click to acknowledge this warning"));
            player.sendMessage("");
        }
        i++;
    }
}
Also used : Document(org.bson.Document) ReportLoader(mc.dragons.tools.moderation.report.ReportLoader) HoldType(mc.dragons.tools.moderation.hold.HoldLoader.HoldType) User(mc.dragons.core.gameobject.user.User) HashMap(java.util.HashMap) Player(org.bukkit.entity.Player) IPAnalysisUtil(mc.dragons.tools.moderation.analysis.IPAnalysisUtil) UserHook(mc.dragons.core.gameobject.user.UserHook) PaginatedResult(mc.dragons.core.storage.mongo.pagination.PaginatedResult) StaffAlertMessageHandler(mc.dragons.core.networking.StaffAlertMessageHandler) Report(mc.dragons.tools.moderation.report.ReportLoader.Report) ReportStatus(mc.dragons.tools.moderation.report.ReportLoader.ReportStatus) HoldLoader(mc.dragons.tools.moderation.hold.HoldLoader) Map(java.util.Map) PunishmentType(mc.dragons.tools.moderation.punishment.PunishmentType) StringUtil(mc.dragons.core.util.StringUtil) HoldEntry(mc.dragons.tools.moderation.hold.HoldLoader.HoldEntry) Set(java.util.Set) Rank(mc.dragons.core.gameobject.user.Rank) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) StandingLevelType(mc.dragons.tools.moderation.punishment.StandingLevelType) Dragons(mc.dragons.core.Dragons) PunishCommand(mc.dragons.tools.moderation.punishment.command.PunishCommand) List(java.util.List) PunishmentData(mc.dragons.tools.moderation.punishment.PunishmentData) ChatColor(org.bukkit.ChatColor) ReportType(mc.dragons.tools.moderation.report.ReportLoader.ReportType) HoldStatus(mc.dragons.tools.moderation.hold.HoldLoader.HoldStatus) Player(org.bukkit.entity.Player) User(mc.dragons.core.gameobject.user.User) Report(mc.dragons.tools.moderation.report.ReportLoader.Report) PunishmentData(mc.dragons.tools.moderation.punishment.PunishmentData)

Example 3 with PaginatedResult

use of mc.dragons.core.storage.mongo.pagination.PaginatedResult in project DragonsOnline by UniverseCraft.

the class ViewReportCommand method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (!requirePermission(sender, SystemProfileFlag.HELPER))
        return true;
    if (args.length == 0) {
        sender.sendMessage(ChatColor.RED + "/viewreport <ID>");
        return true;
    }
    Integer id = parseInt(sender, args[0]);
    if (id == null)
        return true;
    Report report = reportLoader.getReportById(id);
    if (report == null) {
        sender.sendMessage(ChatColor.RED + "No report with ID " + args[0] + " was found!");
        return true;
    }
    PermissionLevel req = report.getType() == ReportType.CHAT ? PermissionLevel.HELPER : PermissionLevel.MODERATOR;
    if (report.getData().containsKey("permissionReq")) {
        req = PermissionLevel.valueOf(report.getData().getString("permissionReq"));
    }
    boolean canEdit = hasPermission(sender, req) && (hasPermission(sender, PermissionLevel.ADMIN) || !report.getTargets().contains(user(sender)));
    boolean closed = report.getStatus() != ReportStatus.OPEN;
    // Helpers can only view open chat reports, or chat reports that they've reviewed
    // Moderators can only view open reports, or reports that they've reviewed
    // Appeals team and admins can view all reports
    boolean canView = hasPermission(sender, SystemProfileFlag.APPEALS_TEAM) || hasPermission(sender, PermissionLevel.ADMIN) || hasPermission(sender, SystemProfileFlag.MODERATION) && (!closed || report.getReviewedBy().equals(user(sender))) || hasPermission(sender, SystemProfileFlag.HELPER) && report.getType() == ReportType.CHAT && (!closed || report.getReviewedBy().equals(user(sender)));
    TextComponent nextReport = StringUtil.clickableHoverableText(ChatColor.GRAY + " [Next Report]", "/modqueue", "Click to handle next report in queue");
    if (!canView) {
        sender.sendMessage(ChatColor.RED + "You do not have sufficient permission to view this report! (#" + report.getId() + ")");
        sender.spigot().sendMessage(nextReport);
        return true;
    }
    if (args.length == 1) {
        sender.sendMessage(ChatColor.DARK_GREEN + "Report #" + report.getId() + ": " + report.getType() + "/" + report.getStatus());
        TextComponent snapshots = null;
        if (report.getData().containsKey("states") && report.getData().getList("states", String.class).size() > 0) {
            snapshots = StringUtil.clickableHoverableText(ChatColor.AQUA + "[User Snapshots]", "/viewreport " + id + " snapshots", "Click to view snapshots of the reported player(s)");
        }
        if (canEdit) {
            if (closed) {
                sender.spigot().sendMessage(StringUtil.clickableHoverableText(ChatColor.YELLOW + "[Re-Open] ", "/viewreport " + id + " status OPEN", "Re-open this report for further action or review"), snapshots == null ? StringUtil.plainText("") : snapshots);
            } else {
                TextComponent confirm = StringUtil.clickableHoverableText(ChatColor.GREEN + "[Confirm] ", "/viewreport " + id + " confirm", "Confirm report and apply punishment(s)", "Closes the report");
                TextComponent insufficient = StringUtil.clickableHoverableText(ChatColor.YELLOW + "[Insufficient] ", "/viewreport " + id + " insufficient", "Insufficient evidence to confirm report", "Closes the report");
                TextComponent watchlist = report.getType() == ReportType.WATCHLIST ? StringUtil.plainText("") : StringUtil.clickableHoverableText(ChatColor.YELLOW + "[Watchlist] ", "/viewreport " + id + " watch", "Insufficient evidence to confirm report, but high suspicion", "Closes the report and places the user on a watchlist for further monitoring");
                TextComponent escalate = StringUtil.clickableHoverableText(ChatColor.GOLD + "[Escalate] ", "/viewreport " + id + " escalate", "Escalate report for review by a senior staff member", "Does not close the report");
                TextComponent duplicate = StringUtil.clickableHoverableText(ChatColor.GRAY + "[Duplicated] ", "/viewreport " + id + " duplicate", "This report is a duplicate of another report", "Closes the report");
                TextComponent cancel = report.getStatus() != ReportStatus.OPEN || !report.getFiledBy().contains(user(sender)) ? StringUtil.plainText("") : StringUtil.clickableHoverableText(ChatColor.GRAY + "[Cancel] ", "/viewreport " + id + " cancel", "Cancel this report", "Closes the report");
                TextComponent skip = StringUtil.clickableHoverableText(ChatColor.GRAY + "[Skip] ", "/viewreport " + id + " skip", "Skip this report and go to the next one in the queue", "Does not close the report");
                TextComponent addNote = StringUtil.clickableHoverableText(ChatColor.WHITE + "" + ChatColor.ITALIC + "  [+Add Note]", "/viewreport " + id + " note ", true, "Add a note to this report", "Does not close the report");
                sender.spigot().sendMessage(confirm, insufficient, watchlist, escalate, duplicate, cancel, skip, addNote);
                if (snapshots != null) {
                    sender.spigot().sendMessage(snapshots);
                }
            }
        } else {
            sender.sendMessage(ChatColor.GRAY + "- You do not have sufficient permission to modify this report -");
            if (snapshots != null) {
                sender.spigot().sendMessage(snapshots);
            }
        }
        sender.sendMessage(ChatColor.GRAY + "Filed Against: " + ChatColor.RESET + StringUtil.parseList(report.getTargets().stream().map(u -> u.getName()).collect(Collectors.toList())));
        if (report.getFiledBy() != null) {
            sender.sendMessage(ChatColor.GRAY + "Filed By: " + ChatColor.RESET + StringUtil.parseList(report.getFiledBy().stream().map(u -> u.getName()).collect(Collectors.toList())));
        }
        sender.sendMessage(ChatColor.GRAY + "Filing Date: " + ChatColor.RESET + StringUtil.DATE_FORMAT.format(report.getFiledOn()));
        if (!hasPermission(sender, SystemProfileFlag.DEVELOPMENT)) {
            if (report.getData().containsKey("message")) {
                sender.sendMessage(ChatColor.GRAY + "Message: " + ChatColor.RESET + report.getData().getString("message"));
            } else if (report.getData().containsKey("reason")) {
                sender.sendMessage(ChatColor.GRAY + "Reason: " + ChatColor.RESET + report.getData().getString("reason"));
            }
        }
        if (report.getReviewedBy() != null) {
            sender.sendMessage(ChatColor.GRAY + "Primary Reviewer: " + ChatColor.RESET + report.getReviewedBy().getName());
        } else {
            sender.sendMessage(ChatColor.GRAY + "Unreviewed.");
        }
        if (report.getData().size() > 0 && hasPermission(sender, SystemProfileFlag.DEVELOPMENT)) {
            sender.sendMessage(ChatColor.GRAY + "Internal Data: ");
            for (Entry<String, Object> entry : report.getData().entrySet()) {
                sender.sendMessage(ChatColor.GRAY + "- " + entry.getKey() + ChatColor.GRAY + ": " + ChatColor.RESET + entry.getValue());
            }
        }
        if (report.getNotes().size() > 0) {
            sender.sendMessage(ChatColor.GRAY + "Notes:");
            for (String note : report.getNotes()) {
                sender.sendMessage(ChatColor.GRAY + "- " + ChatColor.RESET + note);
            }
        }
        PaginatedResult<Report> linked = reportLoader.getRecentReportsByTargets(report.getTargets(), report.getFiledOn().toInstant().getEpochSecond(), report.getId(), 1);
        if (linked.getTotal() > 0) {
            sender.spigot().sendMessage(StringUtil.clickableHoverableText(ChatColor.YELLOW + "[Possible Duplicates]", "/viewreport " + report.getId() + " linked", "Click to view possible duplicate reports"));
        }
        return true;
    } else if (args[1].equalsIgnoreCase("linked")) {
        Integer page = 1;
        if (args.length > 2) {
            page = parseInt(sender, args[2]);
            if (page == null)
                return true;
        }
        PaginatedResult<Report> linked = reportLoader.getRecentReportsByTargets(report.getTargets(), report.getFiledOn().toInstant().getEpochSecond(), report.getId(), 1);
        TableGenerator tg = new TableGenerator(Alignment.LEFT, Alignment.LEFT, Alignment.LEFT, Alignment.LEFT, Alignment.LEFT, Alignment.LEFT);
        tg.addRow(ChatColor.YELLOW + "ID", ChatColor.YELLOW + "Status", ChatColor.YELLOW + "Targets");
        for (Report r : linked.getPage()) {
            String targets = r.getTargets().get(0).getName();
            if (r.getTargets().size() > 1) {
                targets += " +" + (r.getTargets().size() - 1);
            }
            tg.addRowEx("/viewreport " + r.getId(), "Click to view report #" + r.getId(), ChatColor.GRAY + "" + r.getId(), ChatColor.RESET + r.getStatus().toString(), targets);
        }
        tg.display(sender);
    } else if (args[1].equalsIgnoreCase("duplicate")) {
        if (!canEdit) {
            sender.sendMessage(ChatColor.RED + "You do not have sufficient permission to edit this report");
            return true;
        }
        if (closed) {
            sender.sendMessage(ChatColor.RED + "This report is closed!");
            return true;
        }
        report.addNote("Marked as a duplicate by " + sender.getName());
        report.setStatus(ReportStatus.NO_ACTION);
        if (report.getData().containsKey("holdId")) {
            holdLoader.getHoldById(report.getData().getInteger("holdId")).setStatus(HoldStatus.CLOSED_ACTION);
        }
        report.setReviewedBy(user(sender));
        sender.sendMessage(ChatColor.GREEN + "Marked this report as a duplicate.");
        sender.spigot().sendMessage(nextReport);
    } else if (args[1].equalsIgnoreCase("cancel")) {
        if (!canEdit) {
            sender.sendMessage(ChatColor.RED + "You do not have sufficient permission to edit this report");
            return true;
        }
        if (closed) {
            sender.sendMessage(ChatColor.RED + "This report is closed!");
            return true;
        }
        report.addNote("Cancelled by " + sender.getName());
        report.setStatus(ReportStatus.NO_ACTION);
        if (report.getData().containsKey("holdId")) {
            holdLoader.getHoldById(report.getData().getInteger("holdId")).setStatus(HoldStatus.CLOSED_ACTION);
        }
        report.setReviewedBy(user(sender));
        sender.sendMessage(ChatColor.GREEN + "Cancelled this report.");
        sender.spigot().sendMessage(nextReport);
    } else if (args[1].equalsIgnoreCase("skip")) {
        if (!canEdit) {
            sender.sendMessage(ChatColor.RED + "You do not have sufficient permission to edit this report");
            return true;
        }
        if (closed) {
            sender.sendMessage(ChatColor.RED + "This report is closed!");
            return true;
        }
        report.addSkippedBy(user(sender));
        sender.sendMessage(ChatColor.GREEN + "Skipped this report.");
        Bukkit.dispatchCommand(sender, "modqueue");
    } else if (args[1].equalsIgnoreCase("snapshots")) {
        sender.sendMessage(ChatColor.GRAY + "User Snapshots:");
        for (String token : report.getData().getList("states", String.class)) {
            UUID uuid = UUID.fromString(token);
            Document data = stateLoader.getState(uuid);
            if (data == null) {
                sender.sendMessage(ChatColor.GRAY + "- " + ChatColor.RED + "Could not load snapshot " + uuid);
                continue;
            }
            sender.spigot().sendMessage(StringUtil.clickableHoverableText(ChatColor.GRAY + "- " + ChatColor.RESET + userLoader.loadObject(UUID.fromString(data.getString("originalUser"))).getName() + ChatColor.GRAY + " (" + data.getString("originalTime") + ")", "/setstate " + uuid, true, "Click to go to this snapshot"));
        }
    } else if (args[1].equalsIgnoreCase("confirm")) {
        if (!canEdit) {
            sender.sendMessage(ChatColor.RED + "You do not have sufficient permission to edit this report");
            return true;
        }
        if (closed && !report.getReviewedBy().equals(user(sender))) {
            sender.sendMessage(ChatColor.RED + "This report is closed!");
            return true;
        }
        if (!closed && report.getData().containsKey("confirmCommand") && !report.getData().getString("confirmCommand").isEmpty()) {
            report.setStatus(ReportStatus.ACTION_TAKEN);
            if (report.getData().containsKey("holdId")) {
                holdLoader.getHoldById(report.getData().getInteger("holdId")).setStatus(HoldStatus.CLOSED_ACTION);
            }
            player(sender).performCommand(report.getData().getString("confirmCommand"));
            sender.sendMessage(ChatColor.GREEN + "Report closed successfully.");
            sender.spigot().sendMessage(nextReport);
        } else {
            sender.sendMessage(ChatColor.DARK_GREEN + "Select a punishment code to apply:");
            for (PunishmentCode code : PunishmentCode.values()) {
                if (code.isHidden())
                    continue;
                sender.spigot().sendMessage(StringUtil.clickableHoverableText(" " + code.getCode() + ChatColor.GRAY + " - " + code.getName(), "/viewreport " + id + " apply " + code.getCode() + " ", true, new String[] { ChatColor.YELLOW + "" + ChatColor.BOLD + code.getName(), ChatColor.GRAY + code.getDescription(), "", ChatColor.DARK_GRAY + "Level " + code.getStandingLevel() + " - " + code.getType() }));
            }
        }
    } else if (args[1].equalsIgnoreCase("escalate")) {
        if (!canEdit) {
            sender.sendMessage(ChatColor.RED + "You do not have sufficient permission to edit this report");
            return true;
        }
        if (closed) {
            sender.sendMessage(ChatColor.RED + "This report is closed!");
            return true;
        }
        report.addNote("Escalated for further action (by " + sender.getName() + ")");
        PermissionLevel permissionReq = null;
        for (PermissionLevel level : PermissionLevel.values()) {
            if (level.ordinal() == user(sender).getActivePermissionLevel().ordinal() + 1) {
                permissionReq = level;
                break;
            }
        }
        if (permissionReq == null) {
            sender.sendMessage(ChatColor.RED + "You don't have anyone to escalate this report to!");
            return true;
        }
        report.getData().append("permissionReq", permissionReq.toString());
        sender.sendMessage(ChatColor.GREEN + "Escalated this report for further action by a senior staff member.");
        sender.spigot().sendMessage(nextReport);
    } else if (args[1].equalsIgnoreCase("insufficient")) {
        if (!canEdit) {
            sender.sendMessage(ChatColor.RED + "You do not have sufficient permission to edit this report");
            return true;
        }
        if (closed) {
            sender.sendMessage(ChatColor.RED + "This report is closed!");
            return true;
        }
        report.addNote("Marked as insufficient evidence (by " + sender.getName() + ")");
        report.setStatus(ReportStatus.NO_ACTION);
        if (report.getData().containsKey("holdId")) {
            holdLoader.getHoldById(report.getData().getInteger("holdId")).setStatus(HoldStatus.CLOSED_NOACTION);
        }
        report.setReviewedBy(user(sender));
        sender.sendMessage(ChatColor.GREEN + "Marked report as insufficient evidence.");
        sender.spigot().sendMessage(nextReport);
    } else if (args[1].equalsIgnoreCase("watch")) {
        if (!canEdit) {
            sender.sendMessage(ChatColor.RED + "You do not have sufficient permission to edit this report");
            return true;
        }
        if (closed) {
            sender.sendMessage(ChatColor.RED + "This report is closed!");
            return true;
        }
        report.addNote("Marked as insufficient evidence and watchlisted (by " + sender.getName() + ")");
        report.setStatus(ReportStatus.NO_ACTION);
        if (report.getData().containsKey("holdId")) {
            holdLoader.getHoldById(report.getData().getInteger("holdId")).setStatus(HoldStatus.CLOSED_NOACTION);
        }
        report.setReviewedBy(user(sender));
        for (User target : report.getTargets()) {
            reportLoader.fileWatchlistReport(target, user(sender), "Moved to watchlist from report #" + report.getId());
        }
        sender.sendMessage(ChatColor.GREEN + "Marked report as insufficient evidence and placed users on the watchlist.");
        sender.spigot().sendMessage(nextReport);
    } else if (args[1].equalsIgnoreCase("apply")) {
        if (!canEdit) {
            sender.sendMessage(ChatColor.RED + "You do not have sufficient permission to edit this report");
            return true;
        }
        if (closed && !report.getReviewedBy().equals(user(sender))) {
            sender.sendMessage(ChatColor.RED + "This report is closed!");
            return true;
        }
        PunishmentCode code = PunishmentCode.parseCode(sender, args[2]);
        if (code == null)
            return true;
        String extraInfo = StringUtil.concatArgs(args, 3);
        sender.sendMessage(ChatColor.GREEN + "This report has been marked as closed. The following actions were taken:");
        for (User target : report.getTargets()) {
            AppliedPunishmentData result = WrappedUser.of(target).autoPunish(code, "Report #" + report.getId() + (extraInfo.isBlank() ? "" : " - " + extraInfo), user(sender));
            sender.sendMessage(ChatColor.GRAY + "- " + result.type + " applied to " + target.getName() + " (" + StringUtil.parseSecondsToTimespan(result.duration) + ")");
        }
        report.setStatus(ReportStatus.ACTION_TAKEN);
        report.setReviewedBy(user(sender));
        if (report.getData().containsKey("holdId")) {
            int holdId = report.getData().getInteger("holdId");
            holdLoader.getHoldById(holdId).setStatus(HoldStatus.CLOSED_ACTION);
        }
        report.getFiledBy().forEach(u -> WrappedUser.of(u).setReportHandled(true));
        sender.spigot().sendMessage(StringUtil.clickableHoverableText(ChatColor.GRAY + " [+Punishment]", "/viewreport " + report.getId() + " confirm", "Apply another punishment to this report"), nextReport);
    } else if (args[1].equalsIgnoreCase("note")) {
        if (!canEdit) {
            sender.sendMessage(ChatColor.RED + "You do not have sufficient permission to edit this report");
            return true;
        }
        if (closed) {
            sender.sendMessage(ChatColor.RED + "This report is closed!");
            return true;
        }
        if (args.length == 2) {
            sender.sendMessage(ChatColor.RED + "/vrep <ID> note <Note>");
            return true;
        }
        report.addNote(StringUtil.concatArgs(args, 2) + " (by " + sender.getName() + ")");
        sender.sendMessage(ChatColor.GREEN + "Note added successfully.");
        return true;
    } else if (args[1].equalsIgnoreCase("status")) {
        if (!canEdit) {
            sender.sendMessage(ChatColor.RED + "You do not have sufficient permission to edit this report");
            return true;
        }
        if (args.length == 2) {
            sender.sendMessage(ChatColor.RED + "/vrep <ID> status <OPEN|NO_ACTION|ACTION_TAKEN>");
            return true;
        }
        ReportStatus status = StringUtil.parseEnum(sender, ReportStatus.class, args[2]);
        if (status == null)
            return true;
        report.setStatus(status);
        report.addNote("Status set to " + status + " by " + sender.getName());
        if (status != ReportStatus.OPEN) {
            report.setReviewedBy(user(sender));
        }
        if (report.getData().containsKey("holdId")) {
            HoldEntry hold = holdLoader.getHoldById(report.getData().getInteger("holdId"));
            if (status == ReportStatus.NO_ACTION) {
                hold.setStatus(HoldStatus.CLOSED_NOACTION);
            } else if (status == ReportStatus.ACTION_TAKEN) {
                hold.setStatus(HoldStatus.CLOSED_ACTION);
            } else if (status == ReportStatus.OPEN) {
                hold.setStatus(HoldStatus.PENDING);
            }
        }
        sender.sendMessage(ChatColor.GREEN + "Status changed successfully.");
        sender.spigot().sendMessage(nextReport);
        return true;
    }
    return true;
}
Also used : TextComponent(net.md_5.bungee.api.chat.TextComponent) User(mc.dragons.core.gameobject.user.User) WrappedUser(mc.dragons.tools.moderation.WrappedUser) Report(mc.dragons.tools.moderation.report.ReportLoader.Report) PaginatedResult(mc.dragons.core.storage.mongo.pagination.PaginatedResult) TableGenerator(mc.dragons.core.util.TableGenerator) PunishmentCode(mc.dragons.tools.moderation.punishment.PunishmentCode) PermissionLevel(mc.dragons.core.gameobject.user.permission.PermissionLevel) Document(org.bson.Document) AppliedPunishmentData(mc.dragons.tools.moderation.WrappedUser.AppliedPunishmentData) HoldEntry(mc.dragons.tools.moderation.hold.HoldLoader.HoldEntry) UUID(java.util.UUID) ReportStatus(mc.dragons.tools.moderation.report.ReportLoader.ReportStatus)

Example 4 with PaginatedResult

use of mc.dragons.core.storage.mongo.pagination.PaginatedResult in project DragonsOnline by UniverseCraft.

the class WatchlistCommand method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (!requirePermission(sender, SystemProfileFlag.MODERATION))
        return true;
    if (args.length == 0) {
        sender.sendMessage(ChatColor.RED + "/watchlist list [page#] [--offline]");
        sender.sendMessage(ChatColor.RED + "/watchlist add <player> [reason]");
        sender.sendMessage(ChatColor.RED + "/watchlist remove <player>");
        return true;
    } else if (args[0].equalsIgnoreCase("list")) {
        List<ReportStatus> filter = new ArrayList<>();
        filter.add(ReportStatus.OPEN);
        if (StringUtil.getFlagIndex(args, "--offline", 0) != -1) {
            filter.add(ReportStatus.SUSPENDED);
        }
        Integer page = 1;
        if (args.length > 1) {
            page = parseInt(sender, args[1]);
            if (page == null)
                return true;
        }
        PaginatedResult<Report> reports = reportLoader.getReportsByTypeAndStatus(ReportType.WATCHLIST, filter, page);
        sender.sendMessage(ChatColor.DARK_GREEN + "" + reports.getTotal() + " results returned (Page " + reports.getPageIndex() + " of " + reports.getPages() + ")");
        for (Report report : reports.getPage()) {
            // Well-defined because watchlist reports only ever have one target
            User target = report.getTargets().get(0);
            target.safeResyncData();
            boolean online = target.getServerName() != null;
            String username = target.getName();
            sender.spigot().sendMessage(StringUtil.clickableHoverableText(ChatColor.RED + "[-] ", "/watchlist remove " + report.getTargets().get(0).getName(), "Click to remove " + username + " from the watchlist"), StringUtil.clickableHoverableText(ChatColor.YELLOW + "[i] ", "/viewreport " + report.getId(), "Click to view " + username + "'s watchlist info"), StringUtil.plainText(ChatColor.GRAY + "#" + report.getId() + ChatColor.RESET + " " + username + ChatColor.GRAY + " (" + (online ? "ONLINE" : "OFFLINE") + ")"));
        }
    } else if (args[0].equalsIgnoreCase("add")) {
        if (args.length <= 1) {
            sender.sendMessage(ChatColor.RED + "/watchlist add <player> [reason]");
            return true;
        }
        User target = lookupUser(sender, args[1]);
        if (target == null)
            return true;
        reportLoader.fileWatchlistReport(target, user(sender), StringUtil.concatArgs(args, 2));
        sender.sendMessage(ChatColor.GREEN + "Added " + target.getName() + " to the watchlist.");
    } else if (args[0].equalsIgnoreCase("remove")) {
        if (args.length <= 1) {
            sender.sendMessage(ChatColor.RED + "/watchlist remove <player>");
            return true;
        }
        User target = lookupUser(sender, args[1]);
        if (target == null)
            return true;
        PaginatedResult<Report> reports = reportLoader.getReportsByTypeStatusAndTarget(ReportType.WATCHLIST, ReportStatus.OPEN, target, 1);
        if (reports.getTotal() == 0) {
            sender.sendMessage(ChatColor.RED + "That player is not on the watchlist!");
        } else {
            reports.getPage().get(0).setStatus(ReportStatus.NO_ACTION);
            sender.sendMessage(ChatColor.GREEN + "Removed " + target.getName() + " from the watchlist.");
        }
    } else {
        sender.sendMessage(ChatColor.RED + "/watchlist");
    }
    return true;
}
Also used : User(mc.dragons.core.gameobject.user.User) Report(mc.dragons.tools.moderation.report.ReportLoader.Report) PaginatedResult(mc.dragons.core.storage.mongo.pagination.PaginatedResult) ArrayList(java.util.ArrayList) List(java.util.List)

Example 5 with PaginatedResult

use of mc.dragons.core.storage.mongo.pagination.PaginatedResult in project DragonsOnline by UniverseCraft.

the class GuildCommand method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (!requirePlayer(sender))
        return true;
    Player player = player(sender);
    User user = user(sender);
    List<Guild> guilds = guildLoader.getAllGuildsWithRaw(user.getUUID());
    if (args.length == 0) {
        if (guilds.size() == 0) {
            sender.sendMessage(ChatColor.GRAY + "You don't belong to a guild.");
        } else {
            sender.sendMessage(ChatColor.GRAY + "Your guilds: " + ChatColor.WHITE + StringUtil.parseList(guilds.stream().map(g -> g.getName()).collect(Collectors.toList()), ChatColor.GRAY + ", " + ChatColor.WHITE));
        }
        sender.sendMessage(ChatColor.YELLOW + "/guild list" + ChatColor.AQUA + " lists all public guilds.");
        sender.sendMessage(ChatColor.YELLOW + "/guild join <GuildName>" + ChatColor.AQUA + " requests to join a guild.");
        sender.sendMessage(ChatColor.YELLOW + "/guild info <GuildName>" + ChatColor.AQUA + " views information about a guild.");
        sender.sendMessage(ChatColor.YELLOW + "/guild motd <Message of the day|REMOVE>" + ChatColor.AQUA + " sets the guild's MOTD.");
        sender.sendMessage(ChatColor.YELLOW + "/guild themecolor <GRAY|GREEN|BLUE|GOLD|RED|PURPLE>" + ChatColor.AQUA + " sets the guild's theme color.");
        sender.sendMessage(ChatColor.YELLOW + "/guild invite <Player>" + ChatColor.AQUA + " invites a player to your guild.");
        sender.sendMessage(ChatColor.YELLOW + "/guild pending" + ChatColor.AQUA + " view pending applications to your guild.");
        sender.sendMessage(ChatColor.YELLOW + "/guild accept <Player>" + ChatColor.AQUA + " accepts a player to your guild.");
        sender.sendMessage(ChatColor.YELLOW + "/guild reject <Player>" + ChatColor.AQUA + " rejects a player from your guild.");
        sender.sendMessage(ChatColor.YELLOW + "/guild kick <Player>" + ChatColor.AQUA + " kicks a player from your guild.");
        sender.sendMessage(ChatColor.YELLOW + "/guild [un]ban <Player>" + ChatColor.AQUA + " (un)bans a player from your guild.");
        sender.sendMessage(ChatColor.YELLOW + "/guild access <ALL|REQUEST|INVITE|UNLISTED>" + ChatColor.AQUA + " sets your guild access level.");
        sender.sendMessage(ChatColor.YELLOW + "/guild broadcast <Message>" + ChatColor.AQUA + " broadcasts to all your guild members.");
        sender.sendMessage(ChatColor.YELLOW + "/guild setowner <Player>" + ChatColor.AQUA + " set a new owner of your guild.");
        sender.sendMessage(ChatColor.YELLOW + "/guild leave [GuildName]" + ChatColor.AQUA + " leave your current guild.");
    } else if (args[0].equalsIgnoreCase("list")) {
        Integer page = 1;
        if (args.length > 1) {
            page = parseInt(sender, args[1]);
            if (page == null)
                return true;
        }
        PaginatedResult<Guild> results = guildLoader.getAllGuilds(page);
        sender.sendMessage(ChatColor.GREEN + "Listing all guilds (Page " + page + " of " + results.getPages() + ", " + results.getTotal() + " total)");
        for (Guild guild : results.getPage()) {
            sender.sendMessage(ChatColor.GRAY + "- " + ChatColor.YELLOW + guild.getName() + ChatColor.GRAY + " (" + guild.getMembers().size() + " members, " + guild.getXP() + " XP)");
        }
    } else if (args[0].equalsIgnoreCase("join")) {
        if (args.length == 1) {
            sender.sendMessage(ChatColor.RED + "/guild join <GuildName>");
            return true;
        }
        Guild guild = lookupGuild(sender, args[1]);
        if (guild == null)
            return true;
        if (guild.getMembers().contains(user.getUUID())) {
            sender.sendMessage(ChatColor.RED + "You already belong to this guild!");
            return true;
        }
        if (guild.getBlacklist().contains(user.getUUID())) {
            sender.sendMessage(ChatColor.RED + "You are banned from this guild!");
            return true;
        }
        if (guild.getAccessLevel() == GuildAccessLevel.ALL) {
            guild.getMembers().add(player.getUniqueId());
            guild.save();
            sender.sendMessage(ChatColor.GREEN + "Joined guild " + ChatColor.AQUA + guild.getName() + ChatColor.GREEN + " successfully!");
            guild.update(GuildEvent.JOIN, user);
            return true;
        } else if (guild.getAccessLevel() == GuildAccessLevel.REQUEST) {
            guild.getPending().add(player.getUniqueId());
            guild.save();
            // TODO notify guild members
            sender.sendMessage(ChatColor.GREEN + "Requested to join guild " + ChatColor.AQUA + guild.getName() + ChatColor.GREEN + ".");
            return true;
        } else if (guild.getAccessLevel() == GuildAccessLevel.INVITE || guild.getAccessLevel() == GuildAccessLevel.UNLISTED) {
            if (guild.getInvited().contains(player.getUniqueId())) {
                guild.getInvited().remove(player.getUniqueId());
                guild.getMembers().add(player.getUniqueId());
                guild.save();
                sender.sendMessage(ChatColor.GREEN + "Accepted invitation and joined guild " + ChatColor.AQUA + guild.getName() + ChatColor.GREEN + " successfully!");
                guild.update(GuildEvent.JOIN, user);
                user.updateListName();
            } else {
                sender.sendMessage(ChatColor.RED + "This guild is invite-only!");
            }
        }
    } else if (args[0].equalsIgnoreCase("info")) {
        if (args.length == 1) {
            sender.sendMessage(ChatColor.RED + "/guild info <GuildName>");
            return true;
        }
        Guild guild = lookupGuild(sender, args[1]);
        if (guild == null)
            return true;
        if (guild.getAccessLevel() == GuildAccessLevel.UNLISTED && !guild.getMembers().contains(player.getUniqueId())) {
            sender.sendMessage(ChatColor.RED + "This guild is unlisted!");
            return true;
        }
        sender.sendMessage(guild.getThemeColor().secondary() + "Information for guild " + guild.getThemeColor().primary() + "" + ChatColor.BOLD + guild.getName());
        sender.sendMessage(ChatColor.GRAY + "Description: " + ChatColor.WHITE + guild.getDescription());
        sender.sendMessage(ChatColor.GRAY + "XP: " + ChatColor.WHITE + guild.getXP() + ChatColor.GRAY + "  -  Members: " + ChatColor.WHITE + guild.getMembers().size());
        sender.sendMessage(ChatColor.GRAY + "Status: " + ChatColor.WHITE + guild.getAccessLevel().friendlyName());
        sender.sendMessage(ChatColor.GRAY + "Owner: " + ChatColor.WHITE + userLoader.loadObject(guild.getOwner()).getName());
        sender.sendMessage(ChatColor.GRAY + "Members: (" + guild.getMembers().size() + ") " + ChatColor.WHITE + StringUtil.parseList(guild.getMembers().stream().map(uuid -> userLoader.loadObject(uuid).getName()).collect(Collectors.toList())));
    } else if (args[0].equalsIgnoreCase("motd") || args[0].equalsIgnoreCase("themecolor") || args[0].equalsIgnoreCase("access")) {
        String setting;
        switch(args[0].toLowerCase()) {
            case "motd":
                setting = "Message of the day";
                break;
            case "themecolor":
                setting = "Theme color";
                break;
            case "access":
                setting = "Access level";
                break;
            default:
                setting = "[Error parsing option parameter]";
                break;
        }
        if (guilds.size() == 0) {
            sender.sendMessage(ChatColor.RED + "You don't belong to a guild!");
            return true;
        }
        if (args.length == 1) {
            for (Guild guild : guilds) {
                if (setting.equalsIgnoreCase("Message of the day")) {
                    sender.sendMessage(guild.getThemeColor().primary() + "" + ChatColor.BOLD + guild.getName() + ": " + guild.getThemeColor().secondary() + guild.getMOTD());
                } else if (setting.equalsIgnoreCase("Theme color")) {
                    sender.sendMessage(guild.getThemeColor().primary() + "" + ChatColor.BOLD + guild.getName() + ": " + guild.getThemeColor().secondary() + guild.getThemeColor().toString());
                } else if (setting.equalsIgnoreCase("Access level")) {
                    sender.sendMessage(guild.getThemeColor().primary() + "" + ChatColor.BOLD + guild.getName() + ": " + guild.getThemeColor().secondary() + guild.getAccessLevel().friendlyName());
                }
            }
            return true;
        }
        List<Guild> ownedGuilds = guilds.stream().filter(g -> g.getOwner().equals(user.getUUID())).collect(Collectors.toList());
        Guild target = null;
        if (ownedGuilds.size() == 1) {
            target = ownedGuilds.get(0);
        } else {
            if (args.length > 2) {
                target = lookupGuild(sender, args[1]);
                if (target == null)
                    return true;
                if (!guilds.contains(target)) {
                    sender.sendMessage(ChatColor.RED + "You don't belong to that guild!");
                    return true;
                }
            } else {
                sender.sendMessage(ChatColor.RED + "You own multiple guilds! Select one guild to set its " + setting + ".");
                sender.sendMessage(ChatColor.RED + "/guild motd <" + StringUtil.parseList(ownedGuilds.stream().map(g -> g.getName()).collect(Collectors.toList()), "|") + ">" + " <" + setting + ">");
                return true;
            }
        }
        if (!target.getOwner().equals(user.getUUID())) {
            sender.sendMessage(ChatColor.RED + "You must be the guild owner to set the " + setting + "!");
            return true;
        }
        int motdIndex = ownedGuilds.size() == 1 ? 1 : 2;
        String value = StringUtil.concatArgs(args, motdIndex);
        if (setting.equalsIgnoreCase("Message of the day")) {
            if (value.equalsIgnoreCase("REMOVE")) {
                target.setMOTD("");
                sender.sendMessage(ChatColor.GREEN + "Removed guild MOTD successfully.");
                return true;
            }
            target.setMOTD(value);
            sender.sendMessage(ChatColor.GREEN + "Updated guild MOTD successfully. Members will see this upon joining.");
        } else if (setting.equalsIgnoreCase("Theme color")) {
            GuildThemeColor themeColor = StringUtil.parseEnum(sender, GuildThemeColor.class, value);
            if (themeColor == null) {
                return true;
            }
            if (target.getXP() < themeColor.xpreq()) {
                sender.sendMessage(ChatColor.RED + "Your guild must have at least " + themeColor.xpreq() + " XP to unlock this theme color! (Currently have " + target.getXP() + ")");
                return true;
            }
            target.setThemeColor(themeColor);
            sender.sendMessage(ChatColor.GREEN + "Updated guild theme color successfully.");
            sender.sendMessage(ChatColor.GRAY + "Primary Color: " + themeColor.primary() + "" + ChatColor.BOLD + themeColor.primary().name());
            sender.sendMessage(ChatColor.GRAY + "Secondary Color: " + themeColor.secondary() + themeColor.secondary().name());
            sender.sendMessage(ChatColor.GRAY + "Tab List Tag: " + themeColor.tag() + "[" + target.getName() + "]");
            return true;
        } else if (setting.equalsIgnoreCase("Access level")) {
            GuildAccessLevel level = StringUtil.parseEnum(sender, GuildAccessLevel.class, value);
            if (level == null) {
                return true;
            }
            target.setAccessLevel(level);
            sender.sendMessage(ChatColor.GREEN + "Updated guild access level to " + ChatColor.AQUA + level.friendlyName());
            return true;
        }
    } else if (args[0].equalsIgnoreCase("invite")) {
        if (guilds.size() == 0) {
            sender.sendMessage(ChatColor.RED + "You don't belong to any guilds!");
            return true;
        }
        Guild inviting = guilds.get(0);
        if (args.length == 1) {
            sender.sendMessage(ChatColor.RED + "/guild invite <Player>");
            return true;
        }
        if (guilds.size() > 1) {
            if (args.length > 2) {
                inviting = lookupGuild(sender, args[2]);
                if (inviting == null)
                    return true;
            } else {
                sender.sendMessage(ChatColor.RED + "You belong to multiple guilds! Select one guild to invite this player to.");
                sender.sendMessage(ChatColor.RED + "/guild invite <Player> <GuildName>");
                return true;
            }
        }
        User invited = lookupUser(sender, args[1]);
        if (invited == null)
            return true;
        if (inviting.getInvited().contains(invited.getUUID())) {
            sender.sendMessage(ChatColor.RED + "This player is already on this guild's invite list!");
            return true;
        }
        if (inviting.getMembers().contains(invited.getUUID())) {
            sender.sendMessage(ChatColor.RED + "This player is already a member of this guild!");
            return true;
        }
        if (invited.getUUID().equals(user.getUUID())) {
            sender.sendMessage(ChatColor.RED + "You can't invite yourself!");
            return true;
        }
        inviting.getInvited().add(invited.getUUID());
        inviting.save();
        if (invited.getPlayer() != null) {
            invited.getPlayer().sendMessage(ChatColor.GREEN + "You were invited to join the guild " + ChatColor.AQUA + inviting.getName() + ChatColor.GREEN + "!");
            invited.getPlayer().sendMessage(ChatColor.YELLOW + "/guild join " + inviting.getName() + ChatColor.GREEN + " to join!");
        }
        sender.sendMessage(ChatColor.GREEN + "Invited " + ChatColor.AQUA + invited.getName() + ChatColor.GREEN + " to join " + ChatColor.AQUA + inviting.getName());
    } else if (args[0].equalsIgnoreCase("pending")) {
        if (guilds.size() == 0) {
            sender.sendMessage(ChatColor.RED + "You don't belong to any guilds!");
            return true;
        }
        Guild query = guilds.get(0);
        if (guilds.size() > 1) {
            if (args.length > 1) {
                query = lookupGuild(sender, args[1]);
                if (query == null)
                    return true;
                if (!guilds.contains(query)) {
                    sender.sendMessage(ChatColor.RED + "You don't belong to that guild!");
                    return true;
                }
            } else {
                sender.sendMessage(ChatColor.RED + "You belong to multiple guilds! Select one guild to query.");
                sender.sendMessage(ChatColor.RED + "/guild pending <GuildName>");
                return true;
            }
        }
        if (query.getPending().size() == 0) {
            sender.sendMessage(ChatColor.RED + "This guild has no pending applications!");
            return true;
        }
        sender.sendMessage(ChatColor.GREEN + "There are " + query.getPending().size() + " applications to your guild:");
        for (UUID pending : query.getPending()) {
            User applicant = userLoader.loadObject(pending);
            sender.sendMessage(ChatColor.GRAY + "- " + applicant.getName() + " [Lv " + applicant.getLevel() + "] [" + applicant.getRank().getShortName() + "]");
        }
    } else if (args[0].equalsIgnoreCase("accept") || args[0].equalsIgnoreCase("reject") || args[0].equalsIgnoreCase("kick") || args[0].equalsIgnoreCase("ban") || args[0].equalsIgnoreCase("unban")) {
        if (guilds.size() == 0) {
            sender.sendMessage(ChatColor.RED + "You don't belong to any guilds!");
            return true;
        }
        if (args.length == 1) {
            sender.sendMessage(ChatColor.RED + "/guild " + args[0].toLowerCase() + " <Player>");
            return true;
        }
        User target = lookupUser(sender, args[1]);
        if (target == null)
            return true;
        List<Guild> shared = new ArrayList<>();
        if (args[0].equalsIgnoreCase("accept") || args[0].equalsIgnoreCase("reject")) {
            shared = guilds.stream().filter(g -> g.getPending().contains(target.getUUID())).collect(Collectors.toList());
        } else if (args[0].equalsIgnoreCase("unban")) {
            shared = guilds.stream().filter(g -> g.getBlacklist().contains(target.getUUID())).collect(Collectors.toList());
        } else {
            shared = guilds.stream().filter(g -> g.getMembers().contains(target.getUUID())).collect(Collectors.toList());
        }
        if (shared.size() == 0) {
            sender.sendMessage(ChatColor.RED + "Invalid user for the specified guild!");
            return true;
        }
        Guild guild = shared.get(0);
        if (shared.size() > 1) {
            if (args.length > 2) {
                boolean found = false;
                for (Guild test : shared) {
                    if (test.getName().equalsIgnoreCase(args[2])) {
                        guild = test;
                        found = true;
                        break;
                    }
                }
                if (!found) {
                    sender.sendMessage(ChatColor.RED + "You do not share this guild with " + target.getName() + "!");
                    sender.sendMessage(ChatColor.RED + "/guild " + args[0].toLowerCase() + " " + target.getName() + " <" + StringUtil.parseList(shared.stream().map(g -> g.getName()).collect(Collectors.toList()), "|") + ">");
                    return true;
                }
            } else {
                sender.sendMessage(ChatColor.RED + "You share multiple guilds with " + target.getName() + "!");
                sender.sendMessage(ChatColor.RED + "/guild " + args[0].toLowerCase() + " " + target.getName() + " <" + StringUtil.parseList(shared.stream().map(g -> g.getName()).collect(Collectors.toList()), "|") + ">");
                return true;
            }
        }
        if (!guild.getOwner().equals(user.getUUID())) {
            sender.sendMessage(ChatColor.RED + "You must be the owner of the guild to perform this action!");
            // TODO more fine-grained permissions checking with internal ranks, etc.
            return true;
        } else if (args[0].equalsIgnoreCase("accept")) {
            guild.getPending().remove(target.getUUID());
            guild.getMembers().add(target.getUUID());
            guild.save();
            sender.sendMessage(ChatColor.GREEN + "Accepted " + ChatColor.AQUA + target.getName() + ChatColor.GREEN + " into " + ChatColor.AQUA + guild.getName());
            if (target.getPlayer() != null) {
                target.getPlayer().sendMessage(ChatColor.GREEN + "You were accepted into the guild " + ChatColor.AQUA + guild.getName());
            }
            guild.update(GuildEvent.JOIN, target);
            target.updateListName();
        } else if (args[0].equalsIgnoreCase("reject")) {
            guild.getPending().remove(target.getUUID());
            guild.save();
            sender.sendMessage(ChatColor.GREEN + "Rejected " + ChatColor.AQUA + target.getName() + ChatColor.GREEN + " from " + ChatColor.AQUA + guild.getName());
            if (target.getPlayer() != null) {
                target.getPlayer().sendMessage(ChatColor.RED + "You were rejected from the guild " + ChatColor.YELLOW + guild.getName());
            }
        } else if (args[0].equalsIgnoreCase("kick")) {
            if (guild.getOwner().equals(target.getUUID())) {
                sender.sendMessage(ChatColor.RED + "You can't kick the guild owner!");
                return true;
            }
            guild.update(GuildEvent.KICK, target);
            guild.getMembers().remove(target.getUUID());
            guild.save();
            sender.sendMessage(ChatColor.GREEN + "Kicked " + ChatColor.AQUA + target.getName() + ChatColor.GREEN + " from " + ChatColor.AQUA + guild.getName());
            if (target.getPlayer() != null) {
                target.getPlayer().sendMessage(ChatColor.RED + "You were kicked from the guild " + ChatColor.YELLOW + guild.getName());
            }
            target.updateListName();
            target.updatePrimaryNameTag();
        } else if (args[0].equalsIgnoreCase("ban")) {
            if (guild.getOwner().equals(target.getUUID())) {
                sender.sendMessage(ChatColor.RED + "You can't ban the guild owner!");
                return true;
            }
            guild.update(GuildEvent.BAN, target);
            guild.getMembers().remove(target.getUUID());
            guild.getBlacklist().add(target.getUUID());
            guild.save();
            sender.sendMessage(ChatColor.GREEN + "Banned " + ChatColor.AQUA + target.getName() + ChatColor.GREEN + " from " + ChatColor.AQUA + guild.getName());
            if (target.getPlayer() != null) {
                target.getPlayer().sendMessage(ChatColor.RED + "You were banned from the guild " + ChatColor.YELLOW + guild.getName());
            }
            target.updateListName();
            target.updatePrimaryNameTag();
        } else if (args[0].equalsIgnoreCase("unban")) {
            guild.getBlacklist().remove(target.getUUID());
            guild.save();
            sender.sendMessage(ChatColor.GREEN + "Unbanned " + ChatColor.AQUA + target.getName() + ChatColor.GREEN + " from " + ChatColor.AQUA + guild.getName());
            if (target.getPlayer() != null) {
                target.getPlayer().sendMessage(ChatColor.GREEN + "You were unbanned from the guild " + ChatColor.AQUA + guild.getName());
            }
            guild.update(GuildEvent.UNBAN, target);
        }
    } else if (args[0].equalsIgnoreCase("broadcast") || args[0].equalsIgnoreCase("bc") || args[0].equalsIgnoreCase("chat")) {
        if (guilds.size() == 0) {
            sender.sendMessage(ChatColor.RED + "You don't belong to a guild!");
            return true;
        }
        if (args.length == 1) {
            sender.sendMessage(ChatColor.RED + "/guild broadcast <Message>");
            return true;
        }
        String message = StringUtil.concatArgs(args, 1);
        Guild guild = guilds.get(0);
        if (guilds.size() > 1) {
            if (args.length > 2) {
                guild = lookupGuild(sender, args[1]);
                if (guild == null)
                    return true;
                message = StringUtil.concatArgs(args, 2);
                if (!guilds.contains(guild)) {
                    sender.sendMessage(ChatColor.RED + "You don't belong to that guild!");
                    return true;
                }
            } else {
                sender.sendMessage(ChatColor.RED + "You belong to multiple guilds! Select a guild to broadcast to.");
                sender.sendMessage(ChatColor.RED + "/guild broadcast <GuildName> <Message>");
                return true;
            }
        }
        String formatted = ChatColor.GRAY + "@" + guild.getName() + " " + guild.getThemeColor().primary() + "" + ChatColor.BOLD + user.getName() + " " + guild.getThemeColor().secondary() + message;
        GuildLoader.getGuildMessageHandler().send(guild.getName(), formatted);
    } else if (args[0].equalsIgnoreCase("setowner")) {
        if (guilds.size() == 0) {
            sender.sendMessage(ChatColor.RED + "You don't belong to a guild!");
            return true;
        }
        Guild guild = guilds.get(0);
        if (guilds.size() > 1) {
            if (args.length > 2) {
                guild = lookupGuild(sender, args[2]);
                if (guild == null)
                    return true;
                if (!guilds.contains(guild)) {
                    sender.sendMessage(ChatColor.RED + "You don't belong to that guild!");
                    return true;
                }
            } else {
                sender.sendMessage(ChatColor.RED + "You belong to multiple guilds! Select a guild to transfer ownership of.");
                sender.sendMessage(ChatColor.RED + "/guild setowner <Player> <GuildName>");
                return true;
            }
        }
        if (!guild.getOwner().equals(user.getUUID())) {
            sender.sendMessage(ChatColor.RED + "You're not the current owner of this guild!");
            return true;
        }
        User target = lookupUser(sender, args[1]);
        if (target == null)
            return true;
        if (target.getUUID().equals(user.getUUID())) {
            sender.sendMessage(ChatColor.RED + "You are already the owner of this guild!");
            return true;
        }
        if (!guild.getMembers().contains(target.getUUID())) {
            sender.sendMessage(ChatColor.RED + "That player is not a member of this guild!");
            return true;
        }
        guild.getMembers().add(guild.getOwner());
        guild.setOwner(target.getUUID());
        guild.getMembers().remove(target.getUUID());
        sender.sendMessage(ChatColor.GREEN + "Transferred ownership of " + ChatColor.AQUA + guild.getName() + ChatColor.GREEN + " to " + ChatColor.AQUA + target.getName());
        if (target.getPlayer() != null) {
            target.getPlayer().sendMessage(ChatColor.GREEN + "You are now the owner of " + ChatColor.AQUA + guild.getName());
        }
        guild.update(GuildEvent.TRANSFER_OWNERSHIP, target);
        user.updateListName();
        target.updateListName();
        user.updatePrimaryNameTag();
        target.updatePrimaryNameTag();
    } else if (args[0].equalsIgnoreCase("leave")) {
        if (guilds.size() == 0) {
            sender.sendMessage(ChatColor.RED + "You don't belong to a guild!");
            return true;
        }
        Guild guild = guilds.get(0);
        if (guilds.size() > 1) {
            if (args.length > 1) {
                guild = lookupGuild(sender, args[1]);
                if (guild == null)
                    return true;
                if (!guilds.contains(guild)) {
                    sender.sendMessage(ChatColor.RED + "You don't belong to that guild!");
                    return true;
                }
            } else {
                sender.sendMessage(ChatColor.RED + "You belong to multiple guilds! Select a guild to leave.");
                sender.sendMessage(ChatColor.RED + "/guild leave <GuildName>");
                return true;
            }
        }
        if (guild.getOwner().equals(user.getUUID())) {
            sender.sendMessage(ChatColor.RED + "You are the owner of this guild! If you want to leave, you must delegate a new owner first.");
            sender.sendMessage(ChatColor.RED + "/guild setowner <Player>");
            return true;
        }
        guild.update(GuildEvent.LEAVE, user);
        guild.getMembers().remove(user.getUUID());
        guild.save();
        sender.sendMessage(ChatColor.GREEN + "Left guild " + ChatColor.AQUA + guild.getName() + ChatColor.GREEN + " successfully.");
        user.updateListName();
        user.updatePrimaryNameTag();
        return true;
    } else {
        sender.sendMessage(ChatColor.RED + "Invalid usage! Do /guild for help");
    }
    return true;
}
Also used : StringUtil(mc.dragons.core.util.StringUtil) CommandSender(org.bukkit.command.CommandSender) GuildEvent(mc.dragons.social.guild.GuildLoader.GuildEvent) Guild(mc.dragons.social.guild.GuildLoader.Guild) User(mc.dragons.core.gameobject.user.User) UUID(java.util.UUID) Player(org.bukkit.entity.Player) Collectors(java.util.stream.Collectors) Dragons(mc.dragons.core.Dragons) ArrayList(java.util.ArrayList) PaginatedResult(mc.dragons.core.storage.mongo.pagination.PaginatedResult) List(java.util.List) DragonsCommandExecutor(mc.dragons.core.commands.DragonsCommandExecutor) GuildThemeColor(mc.dragons.social.guild.GuildLoader.GuildThemeColor) GuildAccessLevel(mc.dragons.social.guild.GuildLoader.GuildAccessLevel) ChatColor(org.bukkit.ChatColor) Command(org.bukkit.command.Command) GuildAccessLevel(mc.dragons.social.guild.GuildLoader.GuildAccessLevel) Player(org.bukkit.entity.Player) User(mc.dragons.core.gameobject.user.User) PaginatedResult(mc.dragons.core.storage.mongo.pagination.PaginatedResult) Guild(mc.dragons.social.guild.GuildLoader.Guild) GuildThemeColor(mc.dragons.social.guild.GuildLoader.GuildThemeColor) ArrayList(java.util.ArrayList) List(java.util.List) UUID(java.util.UUID)

Aggregations

PaginatedResult (mc.dragons.core.storage.mongo.pagination.PaginatedResult)6 User (mc.dragons.core.gameobject.user.User)5 ArrayList (java.util.ArrayList)3 List (java.util.List)3 UUID (java.util.UUID)3 Collectors (java.util.stream.Collectors)3 Dragons (mc.dragons.core.Dragons)3 StringUtil (mc.dragons.core.util.StringUtil)3 Report (mc.dragons.tools.moderation.report.ReportLoader.Report)3 Document (org.bson.Document)3 ChatColor (org.bukkit.ChatColor)3 DragonsCommandExecutor (mc.dragons.core.commands.DragonsCommandExecutor)2 PermissionLevel (mc.dragons.core.gameobject.user.permission.PermissionLevel)2 Guild (mc.dragons.social.guild.GuildLoader.Guild)2 HoldEntry (mc.dragons.tools.moderation.hold.HoldLoader.HoldEntry)2 ReportStatus (mc.dragons.tools.moderation.report.ReportLoader.ReportStatus)2 Command (org.bukkit.command.Command)2 CommandSender (org.bukkit.command.CommandSender)2 Player (org.bukkit.entity.Player)2 Instant (java.time.Instant)1