use of mc.dragons.tools.moderation.WrappedUser 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;
}
use of mc.dragons.tools.moderation.WrappedUser in project DragonsOnline by UniverseCraft.
the class UnPunishCommands 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 and code! /" + label + " <player> <revocation code>");
// sender.sendMessage(ChatColor.GRAY + "Warning: It is recommended to use /removepunishment to remove a specific punishment. This command revokes only the first applicable punishment.");
return true;
}
if (args.length == 1) {
sender.sendMessage(ChatColor.RED + "Select a revocation code below:");
for (RevocationCode code : RevocationCode.values()) {
sender.spigot().sendMessage(StringUtil.clickableHoverableText(ChatColor.GRAY + "- " + ChatColor.RESET + code.getCode() + ChatColor.GRAY + " - " + code.getDescription(), "/" + label + " " + args[0] + " " + code.getCode(), code.getDescription()));
}
return true;
}
User targetUser = lookupUser(sender, args[0]);
RevocationCode code = RevocationCode.parseCode(sender, args[1]);
if (targetUser == null || code == null)
return true;
WrappedUser wrapped = WrappedUser.of(targetUser);
PunishmentType type = label.equalsIgnoreCase("unban") ? PunishmentType.BAN : PunishmentType.MUTE;
List<PunishmentData> history = wrapped.getPunishmentHistory();
PunishmentData record = null;
int id = -1;
for (int i = 0; i < history.size(); i++) {
if (history.get(i).getType() == type && !history.get(i).hasExpired() && !history.get(i).isRevoked()) {
id = i;
record = history.get(i);
break;
}
}
if (record == null) {
sender.sendMessage(ChatColor.RED + "This player does not have any active punishments matching those criteria!");
return true;
}
if (!record.getIssuedBy().equals(user(sender)) && !hasPermission(sender, SystemProfileFlag.APPEALS_TEAM) || !hasPermission(sender, code.getPermissionToApply())) {
sender.sendMessage(ChatColor.RED + "You do not have permission to revoke this punishment!");
return true;
}
wrapped.unpunish(id, code, user(sender));
// Check if we need to tell a different server to immediately revoke the punishment
if (targetUser.getServerName() != null && !targetUser.getServerName().equals(dragons.getServerName())) {
handler.forwardUnpunishment(targetUser, id);
}
sender.sendMessage(ChatColor.GREEN + "Punishment revoked successfully.");
return true;
}
use of mc.dragons.tools.moderation.WrappedUser 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;
}
use of mc.dragons.tools.moderation.WrappedUser 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());
}
use of mc.dragons.tools.moderation.WrappedUser 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());
}
Aggregations