Search in sources :

Example 1 with SystemProfileFlag

use of mc.dragons.core.gameobject.user.permission.SystemProfile.SystemProfileFlags.SystemProfileFlag in project DragonsOnline by UniverseCraft.

the class ReportsCommand 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 + "/reports <all|all-open|escalation|chat|internal|regular|hold|watchlist|by <player>|on <player>> [-page <#>]");
        sender.sendMessage(ChatColor.GRAY + "Note: Moderators can only use /reports <watchlist|by|on>");
        return true;
    }
    int pageFlagIndex = StringUtil.getFlagIndex(args, "-page", 0);
    Integer page = 1;
    if (pageFlagIndex != -1) {
        page = parseInt(sender, args[++pageFlagIndex]);
        if (page == null)
            return true;
    }
    SystemProfileFlag req = SystemProfileFlag.APPEALS_TEAM;
    PaginatedResult<Report> results = null;
    if (args[0].equalsIgnoreCase("all-open")) {
        results = reportLoader.getReportsByStatus(ReportStatus.OPEN, page);
    } else if (args[0].equalsIgnoreCase("all")) {
        results = reportLoader.getAllReports(page);
    } else if (args[0].equalsIgnoreCase("escalation")) {
        results = reportLoader.getReportsByType(ReportType.STAFF_ESCALATION, page);
    } else if (args[0].equalsIgnoreCase("chat")) {
        results = reportLoader.getReportsByType(ReportType.CHAT, page);
    } else if (args[0].equalsIgnoreCase("internal")) {
        results = reportLoader.getReportsByType(ReportType.AUTOMATED, page);
    } else if (args[0].equalsIgnoreCase("regular")) {
        results = reportLoader.getReportsByType(ReportType.REGULAR, page);
    } else if (args[0].equalsIgnoreCase("hold")) {
        results = reportLoader.getReportsByType(ReportType.HOLD, page);
    } else if (args[0].equalsIgnoreCase("watchlist")) {
        req = SystemProfileFlag.MODERATION;
        results = reportLoader.getReportsByTypeAndStatus(ReportType.WATCHLIST, ReportStatus.OPEN, page);
    } else if (args[0].equalsIgnoreCase("by")) {
        if (args.length == 1) {
            sender.sendMessage(ChatColor.RED + "/reports by <player>");
            return true;
        }
        User filter = lookupUser(sender, args[1]);
        if (filter == null)
            return true;
        results = reportLoader.getReportsByFiler(filter, page);
    } else if (args[0].equalsIgnoreCase("on")) {
        req = SystemProfileFlag.MODERATION;
        if (args.length == 1) {
            sender.sendMessage(ChatColor.RED + "/reports on <player>");
            return true;
        }
        User filter = lookupUser(sender, args[1]);
        if (filter == null)
            return true;
        if (filter.equals(user(sender)) && !hasPermission(sender, PermissionLevel.ADMIN)) {
            sender.sendMessage(ChatColor.RED + "You cannot look up reports on yourself!");
            return true;
        }
        results = reportLoader.getReportsByTarget(filter, page);
    } else {
        sender.sendMessage(ChatColor.RED + "Invalid usage!");
        return true;
    }
    if (!hasPermission(sender, PermissionLevel.ADMIN) && !requirePermission(sender, req))
        return true;
    if (results.getTotal() == 0) {
        sender.sendMessage(ChatColor.RED + "No results returned for this query!");
        return true;
    }
    TableGenerator tg = new TableGenerator(Alignment.LEFT, Alignment.LEFT, Alignment.LEFT, Alignment.LEFT, Alignment.LEFT, Alignment.LEFT);
    tg.addRow(COL_ID, COL_TARGET, COL_PREVIEW, COL_TYPE, COL_STATUS, COL_FILER);
    String idPrefix = ChatColor.AQUA + "";
    String dataPrefix = ChatColor.GRAY + "";
    for (Report report : results.getPage()) {
        String targets = report.getTargets().get(0).getName();
        if (report.getTargets().size() > 1) {
            targets += " +" + (report.getTargets().size() - 1);
        }
        String by = "";
        if (report.getFiledBy().size() > 0) {
            by = report.getFiledBy().get(0).getName();
        }
        if (report.getFiledBy().size() > 1) {
            by += " +" + (report.getFiledBy().size() - 1);
        }
        tg.addRowEx("/viewreport " + report.getId(), ChatColor.GRAY + "Click to view report #" + report.getId(), idPrefix + "#" + report.getId(), dataPrefix + targets, dataPrefix + StringUtil.truncateWithEllipsis(report.getPreview(), 30), dataPrefix + report.getType(), dataPrefix + report.getStatus(), dataPrefix + by);
    }
    sender.sendMessage(ChatColor.GREEN + "Page " + page + " of " + results.getPages() + " (" + results.getTotal() + " results)");
    tg.display(sender);
    return true;
}
Also used : SystemProfileFlag(mc.dragons.core.gameobject.user.permission.SystemProfile.SystemProfileFlags.SystemProfileFlag) User(mc.dragons.core.gameobject.user.User) Report(mc.dragons.tools.moderation.report.ReportLoader.Report) TableGenerator(mc.dragons.core.util.TableGenerator)

Aggregations

User (mc.dragons.core.gameobject.user.User)1 SystemProfileFlag (mc.dragons.core.gameobject.user.permission.SystemProfile.SystemProfileFlags.SystemProfileFlag)1 TableGenerator (mc.dragons.core.util.TableGenerator)1 Report (mc.dragons.tools.moderation.report.ReportLoader.Report)1