Search in sources :

Example 1 with PunishmentCode

use of mc.dragons.tools.moderation.punishment.PunishmentCode in project DragonsOnline by UniverseCraft.

the class CmdUtil method parse.

public static CmdData parse(CommandSender sender, String suggestCommand, String[] args, String... flags) {
    CmdData data = new CmdData();
    int uuidFlagIndex = StringUtil.getFlagIndex(args, "-uuid", 0);
    int reasonIndex = 0;
    data.targets = new ArrayList<>();
    List<String> targetUserErrors = new ArrayList<>();
    for (int i = 0; i < args.length; i++) {
        PunishmentCode test = PunishmentCode.getByCode(args[i]);
        if (test == null) {
            User target = uuidFlagIndex == -1 ? userLoader.loadObject(args[i]) : userLoader.loadObject(UUID.fromString(args[i]));
            if (target == null) {
                targetUserErrors.add(DragonsCommandExecutor.ERR_USER_NOT_FOUND + " (\"" + args[i] + "\")");
            }
            data.targets.add(target);
            reasonIndex = i + 1;
        } else {
            if (i == 0) {
                sender.sendMessage(ChatColor.RED + "Specify a player! " + suggestCommand);
                return null;
            }
            data.code = test;
            reasonIndex = i + 1;
            break;
        }
    }
    if (data.code != null && targetUserErrors.size() > 0) {
        for (String error : targetUserErrors) {
            sender.sendMessage(error);
        }
        return null;
    }
    if (targetUserErrors.size() > 0) {
        return null;
    }
    if (data.code == null) {
        sender.sendMessage(ChatColor.RED + "Invalid punishment code! Valid codes are:");
        PunishmentCode.showPunishmentCodes(sender, suggestCommand.replaceAll(Pattern.quote("<players>"), StringUtil.parseList(data.targets.stream().map(u -> u.getName()).collect(Collectors.toList()), " ")));
        return null;
    }
    int minFlagIndex = uuidFlagIndex;
    for (String flag : flags) {
        int index = StringUtil.getFlagIndex(args, flag, 0);
        if (minFlagIndex == -1 || index < minFlagIndex)
            minFlagIndex = index;
    }
    data.extraInfo = StringUtil.concatArgs(args, reasonIndex, minFlagIndex);
    return data;
}
Also used : User(mc.dragons.core.gameobject.user.User) ArrayList(java.util.ArrayList) PunishmentCode(mc.dragons.tools.moderation.punishment.PunishmentCode)

Example 2 with PunishmentCode

use of mc.dragons.tools.moderation.punishment.PunishmentCode in project DragonsOnline by UniverseCraft.

the class NSPunishCommands method kick.

private void kick(CommandSender sender, String[] args) {
    if (!requirePermission(sender, SystemProfileFlag.HELPER))
        return;
    if (args.length < 2) {
        sender.sendMessage(ChatColor.RED + "/kick <player> <code> [extra info]");
        return;
    }
    User target = lookupUser(sender, args[0]);
    if (target == null)
        return;
    PunishmentCode code = PunishmentCode.parseCode(sender, args[1]);
    if (code == null)
        return;
    String extraInfo = StringUtil.concatArgs(args, 2);
    String reason = code.getDescription() + (extraInfo.isEmpty() ? "" : " (" + extraInfo + ")");
    WrappedUser wtarget = WrappedUser.of(target);
    int id = wtarget.punish(PunishmentType.KICK, code, code.getStandingLevel(), extraInfo, user(sender));
    wtarget.raiseStandingLevel(code.getType(), code.getStandingLevel());
    if (wtarget.getUser().getServerName() != null && !dragons.getServerName().equals(wtarget.getUser().getServerName())) {
        LOGGER.trace("Forwarding punishment on " + wtarget.getUser().getName() + " to " + wtarget.getUser().getServerName());
        handler.forwardPunishment(wtarget.getUser(), id, PunishmentType.KICK, reason, -1L);
    }
    sender.sendMessage(ChatColor.GREEN + "Kicked " + target.getName() + ": " + code.getName());
}
Also used : WrappedUser(mc.dragons.tools.moderation.WrappedUser) User(mc.dragons.core.gameobject.user.User) PunishmentCode(mc.dragons.tools.moderation.punishment.PunishmentCode) WrappedUser(mc.dragons.tools.moderation.WrappedUser)

Example 3 with PunishmentCode

use of mc.dragons.tools.moderation.punishment.PunishmentCode in project DragonsOnline by UniverseCraft.

the class NSPunishCommands method warn.

private void warn(CommandSender sender, String[] args) {
    if (!requirePermission(sender, SystemProfileFlag.HELPER))
        return;
    if (args.length < 2) {
        sender.sendMessage(ChatColor.RED + "/warn <player> <code> [extra info]");
        return;
    }
    User target = lookupUser(sender, args[0]);
    if (target == null)
        return;
    PunishmentCode code = PunishmentCode.parseCode(sender, args[1]);
    if (code == null)
        return;
    String extraInfo = StringUtil.concatArgs(args, 2);
    String reason = code.getDescription() + (extraInfo.isEmpty() ? "" : " (" + extraInfo + ")");
    WrappedUser wtarget = WrappedUser.of(target);
    int id = wtarget.punish(PunishmentType.WARNING, code, code.getStandingLevel(), extraInfo, user(sender));
    wtarget.raiseStandingLevel(code.getType(), code.getStandingLevel());
    if (wtarget.getUser().getServerName() != null && !dragons.getServerName().equals(wtarget.getUser().getServerName())) {
        LOGGER.trace("Forwarding punishment on " + wtarget.getUser().getName() + " to " + wtarget.getUser().getServerName());
        handler.forwardPunishment(wtarget.getUser(), id, PunishmentType.WARNING, reason, -1L);
    }
    sender.sendMessage(ChatColor.GREEN + "Warned " + target.getName() + ": " + code.getName());
}
Also used : WrappedUser(mc.dragons.tools.moderation.WrappedUser) User(mc.dragons.core.gameobject.user.User) PunishmentCode(mc.dragons.tools.moderation.punishment.PunishmentCode) WrappedUser(mc.dragons.tools.moderation.WrappedUser)

Example 4 with PunishmentCode

use of mc.dragons.tools.moderation.punishment.PunishmentCode in project DragonsOnline by UniverseCraft.

the class ReportCommand method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (!requirePlayer(sender))
        return true;
    boolean helper = hasPermission(sender, SystemProfileFlag.HELPER);
    if (args.length < 1) {
        sender.sendMessage(ChatColor.RED + "/report <player> [reason for reporting]");
        if (helper) {
            sender.sendMessage(ChatColor.RED + "/report <player1 [player2 ...]> <code> [extra info]" + ChatColor.GRAY + " - recommended for staff");
        }
        return true;
    }
    User reporter = user(sender);
    CmdData data = null;
    boolean regular = true;
    if (helper) {
        data = CmdUtil.parse(sender, "/report <players> <code> ", args);
        if (data != null)
            regular = false;
    }
    if (regular) {
        data = new CmdData();
        User target = userLoader.loadObject(args[0]);
        if (target == null)
            return true;
        data.targets = List.of(target);
    }
    if (data.targets.contains(reporter) && !reporter.getLocalData().getBoolean("canSelfReport", false)) {
        sender.sendMessage(ChatColor.RED + "You can't report yourself!");
        return true;
    }
    if (args.length == 1) {
        sender.sendMessage(" ");
        sender.sendMessage(ChatColor.YELLOW + "" + ChatColor.BOLD + "What are you reporting " + StringUtil.parseList(data.targets.stream().map(u -> u.getName()).collect(Collectors.toList())) + " for?");
        if (helper) {
            for (PunishmentCode c : PunishmentCode.values()) {
                if (c.isHidden())
                    continue;
                sender.spigot().sendMessage(StringUtil.clickableHoverableText(" " + c.getCode() + ChatColor.GRAY + " - " + c.getName(), "/report " + args[0] + " " + c.getCode() + " ", true, new String[] { ChatColor.YELLOW + "" + ChatColor.BOLD + c.getName(), ChatColor.GRAY + c.getDescription(), "", ChatColor.DARK_GRAY + "Level " + c.getStandingLevel() + " - " + c.getType(), hasPermission(sender, c.getRequiredFlagToApply()) ? ChatColor.DARK_GRAY + "Can Be Applied Immediately" : ChatColor.RED + "Requires review by a senior staff member", ChatColor.DARK_GRAY + "" + ChatColor.UNDERLINE + "Click to Apply Punishment" }));
            }
        } else {
            for (String[] reason : GENERIC_REASONS) {
                TextComponent option = new TextComponent(ChatColor.GRAY + " • " + ChatColor.AQUA + reason[0]);
                option.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text(ChatColor.GRAY + reason[1])));
                option.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/report " + args[0] + " " + reason[0]));
                reporter.getPlayer().spigot().sendMessage(option);
            }
        }
        sender.sendMessage(" ");
        sender.sendMessage(ChatColor.GRAY + "Click on one of the reasons above to continue with the report.");
        sender.sendMessage(" ");
        return true;
    }
    if (helper && !regular) {
        List<WrappedUser> wrapped = data.targets.stream().map(u -> WrappedUser.of(u)).collect(Collectors.toList());
        String targetsString = StringUtil.parseList(data.targets.stream().map(u -> u.getName()).collect(Collectors.toList()), " ");
        String targetsCommas = StringUtil.parseList(data.targets.stream().map(u -> u.getName()).collect(Collectors.toList()));
        wrapped.forEach(u -> u.updateStandingLevels());
        int minEffectiveLevel = -1;
        for (WrappedUser w : wrapped) {
            int oldLevel = w.getStandingLevel(data.code.getType());
            int effectiveLevel = data.code.getStandingLevel() + oldLevel;
            if (minEffectiveLevel == -1 || effectiveLevel < minEffectiveLevel)
                minEffectiveLevel = effectiveLevel;
        }
        boolean canApply = hasPermission(sender, data.code.getRequiredFlagToApply()) && hasPermission(sender, data.code.getRequiredPermissionToApply());
        if (!canApply && minEffectiveLevel <= 1) {
            // Only one option
            Bukkit.dispatchCommand(sender, "/escalate " + targetsString + " " + data.code.getCode() + " " + data.extraInfo);
            return true;
        }
        sender.sendMessage(ChatColor.DARK_GREEN + "What action would you like to take?");
        if (canApply) {
            sender.spigot().sendMessage(StringUtil.clickableHoverableText(ChatColor.GRAY + " • " + ChatColor.GREEN + "Apply punishment immediately.", "/punish " + targetsString + " " + data.code.getCode() + " " + data.extraInfo, "Click to punish " + targetsCommas + " for " + data.code.getName()));
        }
        if (minEffectiveLevel > 1) {
            if (canApply) {
                // If they can't apply, then this will do the same thing as Place hold and escalate
                sender.spigot().sendMessage(StringUtil.clickableHoverableText(ChatColor.GRAY + " • " + ChatColor.GREEN + "Hold account(s) for my review.", "/hold " + targetsString + " " + data.code.getCode() + " " + data.extraInfo, "Click to place a hold on " + targetsCommas, "You will be able to take action on this hold at a later date."));
            }
            sender.spigot().sendMessage(StringUtil.clickableHoverableText(ChatColor.GRAY + " • " + ChatColor.GREEN + "Hold account(s) for senior staff review.", "/hold " + targetsString + " " + data.code.getCode() + (data.extraInfo.isBlank() ? "" : " " + data.extraInfo) + " --forceEscalate", "Click to escalate this issue and place a hold on " + targetsCommas));
        }
        sender.spigot().sendMessage(StringUtil.clickableHoverableText(ChatColor.GRAY + " • " + ChatColor.GREEN + "Forward this issue to senior staff.", "/escalate " + targetsString + " " + data.code.getCode() + " " + data.extraInfo, "Click to escalate this issue. No hold will be placed."));
        return true;
    }
    String reason = StringUtil.concatArgs(args, 1);
    User target = data.targets.get(0);
    if (reason.equalsIgnoreCase("Language or Spamming")) {
        Bukkit.dispatchCommand(sender, "chatreport " + args[0]);
        return true;
    }
    if (reason.equalsIgnoreCase("Other Violation")) {
        sender.sendMessage(ChatColor.RED + "To report a different violation, use /report <player> <reason for reporting>");
        return true;
    }
    if (!reason.contains(CONFIRMATION_FLAG)) {
        sender.sendMessage(" ");
        sender.sendMessage(ChatColor.YELLOW + "" + ChatColor.BOLD + "Please review your report before submitting.");
        sender.sendMessage(ChatColor.GREEN + "Reporting: " + ChatColor.GRAY + target.getName());
        sender.sendMessage(ChatColor.GREEN + "Reason: " + ChatColor.GRAY + reason);
        sender.sendMessage(" ");
        sender.spigot().sendMessage(StringUtil.clickableHoverableText(ChatColor.DARK_GREEN + "" + ChatColor.BOLD + "[Submit]", "/report " + args[0] + " " + reason + CONFIRMATION_FLAG, "By submitting, you confirm that this report is accurate to the best of your knowledge.\n" + "You will not be able to modify this report once it has been submitted."), new TextComponent(" "), StringUtil.hoverableText(ChatColor.GRAY + "" + ChatColor.BOLD + "[Cancel]", "You can always create a new report with " + ChatColor.YELLOW + "/report <player>" + ChatColor.GRAY + "."));
        sender.sendMessage(" ");
        return true;
    }
    reason = reason.replaceAll(Pattern.quote(CONFIRMATION_FLAG), "");
    boolean escalated = false;
    if (hasPermission(sender, SystemProfileFlag.HELPER)) {
        if (reportLoader.fileStaffReport(target, reporter, reason, "") != null) {
            escalated = true;
        }
    }
    if (!escalated) {
        reportLoader.fileUserReport(target, reporter, reason);
    }
    sender.sendMessage(ChatColor.GREEN + "Your report against " + target.getName() + " was filed successfully. We will review it as soon as possible." + (reporter.isVerified() ? " As a verified user, your reports are prioritized for review." : ""));
    sender.spigot().sendMessage(StringUtil.clickableHoverableText(ChatColor.GRAY + " [Click to Block Player]", "/block " + target.getName(), "Click to block " + target.getName()));
    return true;
}
Also used : WrappedUser(mc.dragons.tools.moderation.WrappedUser) HoverEvent(net.md_5.bungee.api.chat.HoverEvent) StringUtil(mc.dragons.core.util.StringUtil) CommandSender(org.bukkit.command.CommandSender) Text(net.md_5.bungee.api.chat.hover.content.Text) ClickEvent(net.md_5.bungee.api.chat.ClickEvent) User(mc.dragons.core.gameobject.user.User) SystemProfileFlag(mc.dragons.core.gameobject.user.permission.SystemProfile.SystemProfileFlags.SystemProfileFlag) Collectors(java.util.stream.Collectors) TextComponent(net.md_5.bungee.api.chat.TextComponent) List(java.util.List) DragonsCommandExecutor(mc.dragons.core.commands.DragonsCommandExecutor) CmdUtil(mc.dragons.tools.moderation.util.CmdUtil) CmdData(mc.dragons.tools.moderation.util.CmdUtil.CmdData) ChatColor(org.bukkit.ChatColor) Command(org.bukkit.command.Command) Pattern(java.util.regex.Pattern) PunishmentCode(mc.dragons.tools.moderation.punishment.PunishmentCode) Bukkit(org.bukkit.Bukkit) TextComponent(net.md_5.bungee.api.chat.TextComponent) HoverEvent(net.md_5.bungee.api.chat.HoverEvent) WrappedUser(mc.dragons.tools.moderation.WrappedUser) User(mc.dragons.core.gameobject.user.User) CmdData(mc.dragons.tools.moderation.util.CmdUtil.CmdData) ClickEvent(net.md_5.bungee.api.chat.ClickEvent) Text(net.md_5.bungee.api.chat.hover.content.Text) PunishmentCode(mc.dragons.tools.moderation.punishment.PunishmentCode) WrappedUser(mc.dragons.tools.moderation.WrappedUser)

Example 5 with PunishmentCode

use of mc.dragons.tools.moderation.punishment.PunishmentCode 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)

Aggregations

User (mc.dragons.core.gameobject.user.User)6 PunishmentCode (mc.dragons.tools.moderation.punishment.PunishmentCode)6 WrappedUser (mc.dragons.tools.moderation.WrappedUser)5 TextComponent (net.md_5.bungee.api.chat.TextComponent)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 UUID (java.util.UUID)1 Pattern (java.util.regex.Pattern)1 Collectors (java.util.stream.Collectors)1 DragonsCommandExecutor (mc.dragons.core.commands.DragonsCommandExecutor)1 PermissionLevel (mc.dragons.core.gameobject.user.permission.PermissionLevel)1 SystemProfileFlag (mc.dragons.core.gameobject.user.permission.SystemProfile.SystemProfileFlags.SystemProfileFlag)1 PaginatedResult (mc.dragons.core.storage.mongo.pagination.PaginatedResult)1 StringUtil (mc.dragons.core.util.StringUtil)1 TableGenerator (mc.dragons.core.util.TableGenerator)1 AppliedPunishmentData (mc.dragons.tools.moderation.WrappedUser.AppliedPunishmentData)1 HoldEntry (mc.dragons.tools.moderation.hold.HoldLoader.HoldEntry)1 StandingLevelType (mc.dragons.tools.moderation.punishment.StandingLevelType)1 Report (mc.dragons.tools.moderation.report.ReportLoader.Report)1 ReportStatus (mc.dragons.tools.moderation.report.ReportLoader.ReportStatus)1