Search in sources :

Example 1 with HoldEntry

use of mc.dragons.tools.moderation.hold.HoldLoader.HoldEntry in project DragonsOnline by UniverseCraft.

the class ModUserHook method checkAllowChat.

@Override
public boolean checkAllowChat(User user, String message) {
    WrappedUser wrapped = WrappedUser.of(user);
    PunishmentData muteData = wrapped.getActivePunishmentData(PunishmentType.MUTE);
    if (muteData != null) {
        user.getPlayer().sendMessage(PunishCommand.RECEIVE_PREFIX + ChatColor.BOLD + "You are muted" + ChatColor.RED + ".");
        wrapped.showActiveMuteReasons();
        return false;
    }
    HoldEntry entry = holdLoader.getHoldByUser(user, HoldType.MUTE);
    if (entry != null && entry.getStatus() == HoldStatus.PENDING && (Instant.now().getEpochSecond() - entry.getStartedOn()) < 60 * 60 * HoldLoader.HOLD_DURATION_HOURS) {
        user.getPlayer().sendMessage(PunishCommand.RECEIVE_PREFIX + "Your account was flagged for suspicious activity.");
        user.getPlayer().sendMessage(PunishCommand.RECEIVE_PREFIX + ChatColor.GRAY + "This suspension will be resolved in at most " + entry.getMaxExpiry());
        return false;
    }
    if (user.getRank() == Rank.DEFAULT && System.currentTimeMillis() - lastMessage.getOrDefault(user, 0L) < 1000 * plugin.getSlowMode()) {
        user.getPlayer().sendMessage(ChatColor.RED + "Slow mode is currently enabled! Please wait " + plugin.getSlowMode() + "s before sending another message, or " + "purchase a rank to bypass this!");
        return false;
    }
    lastMessage.put(user, System.currentTimeMillis());
    return true;
}
Also used : HoldEntry(mc.dragons.tools.moderation.hold.HoldLoader.HoldEntry) PunishmentData(mc.dragons.tools.moderation.punishment.PunishmentData)

Example 2 with HoldEntry

use of mc.dragons.tools.moderation.hold.HoldLoader.HoldEntry in project DragonsOnline by UniverseCraft.

the class ModUserHook method onInitialize.

@Override
public void onInitialize(User user) {
    WrappedUser wrapped = WrappedUser.of(user);
    wrapped.updateStandingLevels();
    if (user.getPlayer() != null) {
        PunishmentData banData = wrapped.getActivePunishmentData(PunishmentType.BAN);
        if (banData != null) {
            user.getPlayer().kickPlayer(ChatColor.DARK_RED + "You are banned.\n\n" + wrapped.getActiveBanReasons());
            return;
        }
        HoldEntry entry = holdLoader.getHoldByUser(user, HoldType.SUSPEND);
        if (entry != null && entry.getStatus() == HoldStatus.PENDING && (Instant.now().getEpochSecond() - entry.getStartedOn()) < 60 * 60 * HoldLoader.HOLD_DURATION_HOURS) {
            user.getPlayer().kickPlayer(ChatColor.RED + "Your account was flagged for suspicious activity and is suspended pending review.\n" + "This suspension will be resolved in at most " + entry.getMaxExpiry());
        }
    }
}
Also used : HoldEntry(mc.dragons.tools.moderation.hold.HoldLoader.HoldEntry) PunishmentData(mc.dragons.tools.moderation.punishment.PunishmentData)

Example 3 with HoldEntry

use of mc.dragons.tools.moderation.hold.HoldLoader.HoldEntry in project DragonsOnline by UniverseCraft.

the class PeriodicNotificationTask method run.

@Override
public void run() {
    for (User user : UserLoader.allUsers()) {
        if (!PermissionUtil.verifyActiveProfileFlag(user, SystemProfileFlag.HELPER, false))
            continue;
        List<HoldEntry> holds = holdLoader.getActiveHoldsByFiler(user).stream().filter(h -> {
            Report report = reportLoader.getReportById(h.getReportId());
            return report.getType() == ReportType.HOLD && (!report.getData().containsKey("permissionReq") || // escalations don't notify because someone else needs to review them.
            PermissionUtil.verifyActivePermissionLevel(user, PermissionLevel.valueOf(report.getData().getString("permissionReq")), false));
        }).collect(Collectors.toList());
        List<TextComponent> components = new ArrayList<>();
        components.add(StringUtil.plainText(ChatColor.GOLD + "" + ChatColor.BOLD + "! " + ChatColor.YELLOW + "You have placed " + ChatColor.GOLD + holds.size() + ChatColor.YELLOW + " hold(s) that still need reviewing: "));
        holds.stream().map(h -> StringUtil.clickableHoverableText(ChatColor.GRAY + "" + h.getId() + "." + h.getReportId() + " ", "/viewreport " + h.getReportId(), "Click to view the report for hold " + h.getId() + "-" + h.getReportId())).forEach(c -> components.add(c));
        if (holds.size() > 0) {
            user.getPlayer().spigot().sendMessage(components.toArray(new BaseComponent[] {}));
        }
    }
}
Also used : StringUtil(mc.dragons.core.util.StringUtil) ReportLoader(mc.dragons.tools.moderation.report.ReportLoader) UserLoader(mc.dragons.core.gameobject.user.UserLoader) PermissionUtil(mc.dragons.core.util.PermissionUtil) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) HoldEntry(mc.dragons.tools.moderation.hold.HoldLoader.HoldEntry) User(mc.dragons.core.gameobject.user.User) SystemProfileFlag(mc.dragons.core.gameobject.user.permission.SystemProfile.SystemProfileFlags.SystemProfileFlag) Collectors(java.util.stream.Collectors) Dragons(mc.dragons.core.Dragons) ArrayList(java.util.ArrayList) TextComponent(net.md_5.bungee.api.chat.TextComponent) List(java.util.List) Report(mc.dragons.tools.moderation.report.ReportLoader.Report) BaseComponent(net.md_5.bungee.api.chat.BaseComponent) PermissionLevel(mc.dragons.core.gameobject.user.permission.PermissionLevel) HoldLoader(mc.dragons.tools.moderation.hold.HoldLoader) ChatColor(org.bukkit.ChatColor) ReportType(mc.dragons.tools.moderation.report.ReportLoader.ReportType) TextComponent(net.md_5.bungee.api.chat.TextComponent) BaseComponent(net.md_5.bungee.api.chat.BaseComponent) User(mc.dragons.core.gameobject.user.User) HoldEntry(mc.dragons.tools.moderation.hold.HoldLoader.HoldEntry) Report(mc.dragons.tools.moderation.report.ReportLoader.Report) ArrayList(java.util.ArrayList)

Example 4 with HoldEntry

use of mc.dragons.tools.moderation.hold.HoldLoader.HoldEntry 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 5 with HoldEntry

use of mc.dragons.tools.moderation.hold.HoldLoader.HoldEntry in project DragonsOnline by UniverseCraft.

the class ViewPunishmentsCommand 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 + "Specify a player! /viewpunishments <player>");
        return true;
    }
    boolean mod = hasPermission(sender, SystemProfileFlag.MODERATION);
    Player targetPlayer = Bukkit.getPlayerExact(args[0]);
    User targetUser = lookupUser(sender, args[0]);
    if (targetUser == null)
        return true;
    WrappedUser wrapped = WrappedUser.of(targetUser);
    PunishmentData banData = wrapped.getActivePunishmentData(PunishmentType.BAN);
    PunishmentData muteData = wrapped.getActivePunishmentData(PunishmentType.MUTE);
    sender.sendMessage(ChatColor.GOLD + "Punishment History for User " + targetUser.getName());
    if (targetPlayer == null) {
        sender.sendMessage(ChatColor.YELLOW + "" + ChatColor.ITALIC + "This player is offline. Showing cached data.");
    }
    if (!mod) {
        sender.sendMessage(ChatColor.GRAY + "- You only have access to see punishments and holds that you have applied -");
    }
    if (mod) {
        sender.sendMessage(ChatColor.YELLOW + "Active Punishments:");
        if (banData == null || banData.hasExpired() || banData.isRevoked()) {
            sender.sendMessage(ChatColor.WHITE + "- Not banned");
        } else {
            sender.sendMessage(ChatColor.WHITE + "- Banned: " + banData.getReason() + " (" + (banData.isPermanent() ? "Permanent" : "Until " + StringUtil.DATE_FORMAT.format(banData.getExpiry()) + ")"));
        }
        if (muteData == null || muteData.hasExpired() || muteData.isRevoked()) {
            sender.sendMessage(ChatColor.WHITE + "- Not muted");
        } else {
            sender.sendMessage(ChatColor.WHITE + "- Muted: " + muteData.getReason() + " (" + (muteData.isPermanent() ? "Permanent" : "Until " + StringUtil.DATE_FORMAT.format(muteData.getExpiry()) + ")"));
        }
    }
    sender.sendMessage(ChatColor.YELLOW + "Past Punishments:");
    int i = 1;
    for (PunishmentData entry : wrapped.getPunishmentHistory()) {
        if ((entry.getIssuedBy() == null || !entry.getIssuedBy().equals(user(sender))) && !mod) {
            i++;
            continue;
        }
        String duration = "";
        if (entry.isPermanent())
            duration = "(Permanent)";
        else if (entry.getExpiry() != null)
            duration = "(Until " + StringUtil.DATE_FORMAT.format(entry.getExpiry()) + ")";
        String removed = "";
        if (entry.hasExpired()) {
            removed = ChatColor.GREEN + " (Expired)";
        } else if (entry.isRevoked()) {
            removed = ChatColor.AQUA + " (Revoked: " + entry.getRevocationCode().getDescription() + ")";
        }
        sender.sendMessage(ChatColor.DARK_GREEN + "#" + i + ": " + ChatColor.RED + entry.getType() + ": " + ChatColor.WHITE + entry.getReason() + " " + duration + removed);
        i++;
    }
    List<HoldEntry> holds = holdLoader.getActiveHoldsByUser(targetUser).stream().filter(h -> h.getBy().equals(user(sender)) || mod).collect(Collectors.toList());
    if (holds.size() > 0) {
        sender.spigot().sendMessage(StringUtil.plainText(ChatColor.YELLOW + "Pending Holds: " + ChatColor.RESET + holds.size()), StringUtil.clickableHoverableText(ChatColor.GRAY + " [View Holds]", "/viewholds " + targetUser.getName(), "Click to view active holds on this user"));
    }
    if (targetPlayer == null) {
        // User was only constructed for querying purposes. Since they're not really online, remove them from local registry
        userLoader.unregister(targetUser);
    }
    return true;
}
Also used : WrappedUser(mc.dragons.tools.moderation.WrappedUser) PunishmentType(mc.dragons.tools.moderation.punishment.PunishmentType) StringUtil(mc.dragons.core.util.StringUtil) CommandSender(org.bukkit.command.CommandSender) HoldEntry(mc.dragons.tools.moderation.hold.HoldLoader.HoldEntry) User(mc.dragons.core.gameobject.user.User) Player(org.bukkit.entity.Player) SystemProfileFlag(mc.dragons.core.gameobject.user.permission.SystemProfile.SystemProfileFlags.SystemProfileFlag) Collectors(java.util.stream.Collectors) List(java.util.List) DragonsCommandExecutor(mc.dragons.core.commands.DragonsCommandExecutor) HoldLoader(mc.dragons.tools.moderation.hold.HoldLoader) PunishmentData(mc.dragons.tools.moderation.punishment.PunishmentData) ChatColor(org.bukkit.ChatColor) Command(org.bukkit.command.Command) Bukkit(org.bukkit.Bukkit) Player(org.bukkit.entity.Player) WrappedUser(mc.dragons.tools.moderation.WrappedUser) User(mc.dragons.core.gameobject.user.User) HoldEntry(mc.dragons.tools.moderation.hold.HoldLoader.HoldEntry) PunishmentData(mc.dragons.tools.moderation.punishment.PunishmentData) WrappedUser(mc.dragons.tools.moderation.WrappedUser)

Aggregations

HoldEntry (mc.dragons.tools.moderation.hold.HoldLoader.HoldEntry)11 User (mc.dragons.core.gameobject.user.User)7 List (java.util.List)6 Collectors (java.util.stream.Collectors)6 StringUtil (mc.dragons.core.util.StringUtil)6 WrappedUser (mc.dragons.tools.moderation.WrappedUser)6 SystemProfileFlag (mc.dragons.core.gameobject.user.permission.SystemProfile.SystemProfileFlags.SystemProfileFlag)5 ChatColor (org.bukkit.ChatColor)5 DragonsCommandExecutor (mc.dragons.core.commands.DragonsCommandExecutor)4 HoldLoader (mc.dragons.tools.moderation.hold.HoldLoader)4 PunishmentData (mc.dragons.tools.moderation.punishment.PunishmentData)4 PunishmentType (mc.dragons.tools.moderation.punishment.PunishmentType)4 Report (mc.dragons.tools.moderation.report.ReportLoader.Report)4 Command (org.bukkit.command.Command)4 CommandSender (org.bukkit.command.CommandSender)4 PermissionLevel (mc.dragons.core.gameobject.user.permission.PermissionLevel)3 ReportLoader (mc.dragons.tools.moderation.report.ReportLoader)3 TextComponent (net.md_5.bungee.api.chat.TextComponent)3 ArrayList (java.util.ArrayList)2 UUID (java.util.UUID)2