Search in sources :

Example 1 with CmdData

use of mc.dragons.tools.moderation.util.CmdUtil.CmdData in project DragonsOnline by UniverseCraft.

the class PunishCommand method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (!requirePlayer(sender) || !requirePermission(sender, SystemProfileFlag.HELPER))
        return true;
    if (args.length == 0) {
        sender.sendMessage(ChatColor.RED + "Specify a player and code! /punish <player1 [player2 ...]> <code> [extra info]");
        return true;
    }
    CmdData data = CmdUtil.parse(sender, "/punish <players> <code> ", args);
    if (data == null)
        return true;
    int level = data.code.getStandingLevel();
    boolean canApply = data.code.canApply(user(sender));
    boolean notMod = !hasPermission(sender, SystemProfileFlag.MODERATION);
    List<WrappedUser> wrapped = data.targets.stream().map(u -> WrappedUser.of(u)).collect(Collectors.toList());
    int minEffectiveLevel = -1;
    for (WrappedUser w : wrapped) {
        w.updateStandingLevels();
        if (canApply) {
            // Punish immediately
            PunishmentType type = w.autoPunish(data.code, data.extraInfo, user(sender)).type;
            String punishment = "Punished";
            if (type == PunishmentType.BAN) {
                punishment = "Banned";
            } else if (type == PunishmentType.MUTE) {
                punishment = "Muted";
            } else if (type == PunishmentType.KICK) {
                punishment = "Kicked";
            } else if (type == PunishmentType.WARNING) {
                punishment = "Warned";
            }
            sender.sendMessage(ChatColor.GREEN + "Punishment applied to " + w.getUser().getName() + ": " + punishment + " for " + data.code.getName());
        }
        if (level >= 10 && notMod) {
            Report review = reportLoader.fileStaffReport(data.targets, user(sender), "Post Review: " + data.formatInternalReason(), "");
            sender.sendMessage(ChatColor.GRAY + " A senior staff member will review this punishment. (Escalation Report ID: " + review.getId() + ")");
        }
    }
    if (!canApply) {
        // Generate escalation report
        Report r = reportLoader.fileStaffReport(data.targets, user(sender), data.formatInternalReason(), "punish " + StringUtil.parseList(data.targets.stream().map(u -> u.getUUID().toString()).collect(Collectors.toList()), " ") + " " + data.code.getCode() + (data.extraInfo.isBlank() ? "" : " " + data.extraInfo) + " -uuid");
        boolean held = false;
        if (r != null && minEffectiveLevel > 1) {
            held = true;
            HoldEntry hold = holdLoader.newHold(data.targets, user(sender), data.formatInternalReason(), r, true, data.code.getType() == StandingLevelType.BAN ? HoldType.SUSPEND : HoldType.MUTE);
            r.getData().append("holdId", hold.getId());
            r.save();
        }
        sender.sendMessage(ChatColor.GREEN + (held ? "Placed a " + HoldLoader.HOLD_DURATION_HOURS + "-hour hold and escalated" : "Escalated") + " this issue for review by a senior staff member.");
    }
    return true;
}
Also used : WrappedUser(mc.dragons.tools.moderation.WrappedUser) PunishmentType(mc.dragons.tools.moderation.punishment.PunishmentType) StringUtil(mc.dragons.core.util.StringUtil) ReportLoader(mc.dragons.tools.moderation.report.ReportLoader) CommandSender(org.bukkit.command.CommandSender) HoldType(mc.dragons.tools.moderation.hold.HoldLoader.HoldType) HoldEntry(mc.dragons.tools.moderation.hold.HoldLoader.HoldEntry) SystemProfileFlag(mc.dragons.core.gameobject.user.permission.SystemProfile.SystemProfileFlags.SystemProfileFlag) Collectors(java.util.stream.Collectors) StandingLevelType(mc.dragons.tools.moderation.punishment.StandingLevelType) List(java.util.List) Report(mc.dragons.tools.moderation.report.ReportLoader.Report) DragonsCommandExecutor(mc.dragons.core.commands.DragonsCommandExecutor) CmdUtil(mc.dragons.tools.moderation.util.CmdUtil) HoldLoader(mc.dragons.tools.moderation.hold.HoldLoader) CmdData(mc.dragons.tools.moderation.util.CmdUtil.CmdData) ChatColor(org.bukkit.ChatColor) Command(org.bukkit.command.Command) HoldEntry(mc.dragons.tools.moderation.hold.HoldLoader.HoldEntry) Report(mc.dragons.tools.moderation.report.ReportLoader.Report) CmdData(mc.dragons.tools.moderation.util.CmdUtil.CmdData) WrappedUser(mc.dragons.tools.moderation.WrappedUser) PunishmentType(mc.dragons.tools.moderation.punishment.PunishmentType)

Example 2 with CmdData

use of mc.dragons.tools.moderation.util.CmdUtil.CmdData 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 3 with CmdData

use of mc.dragons.tools.moderation.util.CmdUtil.CmdData in project DragonsOnline by UniverseCraft.

the class HoldCommand method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (!requirePlayer(sender) || !requirePermission(sender, SystemProfileFlag.HELPER))
        return true;
    User user = user(sender);
    if (args.length == 0) {
        sender.sendMessage(ChatColor.RED + "Specify a player and code! /hold <player1 [player2 ...]> <code> [extra info]");
        return true;
    }
    int forceEscalateIndex = StringUtil.getFlagIndex(args, "--forceEscalate", 0);
    CmdData data = CmdUtil.parse(sender, "/hold <players> <code> ", args, "--forceEscalate");
    if (data == null)
        return true;
    boolean error = false;
    for (User target : data.targets) {
        if (WrappedUser.of(target).getStandingLevel(data.code.getType()) + data.code.getStandingLevel() <= 1) {
            sender.sendMessage(ChatColor.RED + "This code (" + data.code.getCode() + ") is not sufficient to place a hold on user " + target.getName());
            error = true;
        }
    }
    if (error) {
        sender.sendMessage(ChatColor.RED + "Could not place hold.");
        return true;
    }
    boolean canApply = data.code.canApply(user);
    HoldEntry hold = holdLoader.newHold(data.targets, user, data.formatInternalReason(), null, forceEscalateIndex != -1 || !canApply, data.code.getType() == StandingLevelType.BAN ? HoldType.SUSPEND : HoldType.MUTE);
    if (hold == null) {
        sender.sendMessage(ChatColor.RED + "Could not place hold: An internal error occurred.");
    } else {
        sender.sendMessage(ChatColor.GREEN + "Hold placed successfully. Report ID: " + hold.getReportId());
    }
    return true;
}
Also used : WrappedUser(mc.dragons.tools.moderation.WrappedUser) User(mc.dragons.core.gameobject.user.User) HoldEntry(mc.dragons.tools.moderation.hold.HoldLoader.HoldEntry) CmdData(mc.dragons.tools.moderation.util.CmdUtil.CmdData)

Example 4 with CmdData

use of mc.dragons.tools.moderation.util.CmdUtil.CmdData in project DragonsOnline by UniverseCraft.

the class EscalateCommand method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    if (!requirePlayer(sender) || !requirePermission(sender, PermissionLevel.HELPER))
        return true;
    User reporter = user(sender);
    if (args.length < 2) {
        sender.sendMessage(ChatColor.RED + "Specify a player and code! /escalate <player1 [player2 ...]> <code> [extra info]");
        return true;
    }
    CmdData data = CmdUtil.parse(sender, "/escalate <players> <code> ", args);
    if (data == null)
        return true;
    if (reportLoader.fileStaffReport(data.targets, reporter, data.formatInternalReason(), "") == null) {
        sender.sendMessage(ChatColor.RED + "You have nobody to escalate this report to!");
    } else {
        sender.sendMessage(ChatColor.GREEN + "Escalated issue successfully.");
    }
    return true;
}
Also used : User(mc.dragons.core.gameobject.user.User) CmdData(mc.dragons.tools.moderation.util.CmdUtil.CmdData)

Aggregations

CmdData (mc.dragons.tools.moderation.util.CmdUtil.CmdData)4 User (mc.dragons.core.gameobject.user.User)3 WrappedUser (mc.dragons.tools.moderation.WrappedUser)3 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 DragonsCommandExecutor (mc.dragons.core.commands.DragonsCommandExecutor)2 SystemProfileFlag (mc.dragons.core.gameobject.user.permission.SystemProfile.SystemProfileFlags.SystemProfileFlag)2 StringUtil (mc.dragons.core.util.StringUtil)2 HoldEntry (mc.dragons.tools.moderation.hold.HoldLoader.HoldEntry)2 CmdUtil (mc.dragons.tools.moderation.util.CmdUtil)2 ChatColor (org.bukkit.ChatColor)2 Command (org.bukkit.command.Command)2 CommandSender (org.bukkit.command.CommandSender)2 Pattern (java.util.regex.Pattern)1 HoldLoader (mc.dragons.tools.moderation.hold.HoldLoader)1 HoldType (mc.dragons.tools.moderation.hold.HoldLoader.HoldType)1 PunishmentCode (mc.dragons.tools.moderation.punishment.PunishmentCode)1 PunishmentType (mc.dragons.tools.moderation.punishment.PunishmentType)1 StandingLevelType (mc.dragons.tools.moderation.punishment.StandingLevelType)1 ReportLoader (mc.dragons.tools.moderation.report.ReportLoader)1