use of mc.dragons.core.gameobject.user.permission.PermissionLevel in project DragonsOnline by UniverseCraft.
the class SystemLogonCommand method changeActiveLevel.
private void changeActiveLevel(CommandSender sender, String[] args) {
if (!requirePlayer(sender))
return;
User user = user(sender);
if (!requireLogin(sender))
return;
if (user.getSystemProfile() == null) {
sender.sendMessage(ChatColor.RED + "You're not logged in to a system profile.");
return;
}
PermissionLevel level = StringUtil.parseEnum(sender, PermissionLevel.class, args[1]);
if (level == null)
return;
boolean result = user.setActivePermissionLevel(level);
if (result) {
sender.sendMessage(ChatColor.GREEN + "Changed active permission level to " + args[1]);
} else {
sender.sendMessage(ChatColor.RED + "Could not change active permission level: requested permission level exceeds maximum level for this profile.");
}
}
use of mc.dragons.core.gameobject.user.permission.PermissionLevel in project DragonsOnline by UniverseCraft.
the class SystemLogonCommand method createProfile.
private void createProfile(CommandSender sender, String[] args) {
if (!requirePermission(sender, PermissionLevel.ADMIN))
return;
if (args.length < 5) {
sender.sendMessage(ChatColor.RED + "/syslogon create <profile> <username> <password> <max. permission level>");
return;
}
PermissionLevel level = StringUtil.parseEnum(sender, PermissionLevel.class, args[4]);
if (level == null)
return;
if (level.compareTo(PermissionLevel.ADMIN) > 0 && !hasPermission(sender, PermissionLevel.SYSOP))
return;
systemProfileLoader.createProfile(args[1], args[2], args[3], level);
sender.sendMessage(ChatColor.GREEN + "Created system profile successfully.");
}
use of mc.dragons.core.gameobject.user.permission.PermissionLevel in project DragonsOnline by UniverseCraft.
the class ReportLoader method fileStaffReport.
public Report fileStaffReport(List<User> targets, User staff, String message, String confirmCommand) {
if (staff.getActivePermissionLevel().ordinal() == PermissionLevel.SYSOP.ordinal()) {
return null;
}
PermissionLevel permissionReq = null;
for (PermissionLevel level : PermissionLevel.values()) {
if (level.ordinal() == staff.getActivePermissionLevel().ordinal() + 1) {
permissionReq = level;
break;
}
}
Document data = new Document().append("type", ReportType.STAFF_ESCALATION.toString()).append("target", targets.stream().map(u -> u.getUUID().toString()).collect(Collectors.toList())).append("priority", // Escalations go to the very tippity top of the queue
100).append("filedBy", List.of(staff.getUUID().toString())).append("data", new Document("message", message).append("confirmCommand", confirmCommand).append("permissionReq", permissionReq.toString()).append("states", getStateTokens(targets)));
Report report = fileReport(data);
reportNotify(report.getId(), staff.getName() + " escalated an issue with " + StringUtil.parseList(targets.stream().map(u -> u.getName()).collect(Collectors.toList())) + ": " + message);
return report;
}
use of mc.dragons.core.gameobject.user.permission.PermissionLevel in project DragonsOnline by UniverseCraft.
the class ReportLoader method fileHoldReport.
public Report fileHoldReport(List<User> targets, User staff, String reason, int holdId, boolean escalate) {
Document internalData = new Document("reason", reason).append("holdId", holdId).append("states", getStateTokens(targets));
if (escalate) {
PermissionLevel permissionReq = null;
for (PermissionLevel level : PermissionLevel.values()) {
if (level.ordinal() == staff.getActivePermissionLevel().ordinal() + 1) {
permissionReq = level;
break;
}
}
internalData.append("permissionReq", permissionReq.toString());
}
Document data = new Document().append("type", ReportType.HOLD.toString()).append("target", targets.stream().map(u -> u.getUUID().toString()).collect(Collectors.toList())).append("priority", // Escalations go to the very tippity top of the queue
escalate ? 100 : 0).append("filedBy", List.of(staff.getUUID().toString())).append("data", internalData.append("states", getStateTokens(targets)));
Report report = fileReport(data);
reportNotify(report.getId(), staff.getName() + " placed a hold on " + StringUtil.parseList(targets.stream().map(u -> u.getName()).collect(Collectors.toList())) + ": " + reason);
return report;
}
use of mc.dragons.core.gameobject.user.permission.PermissionLevel in project DragonsOnline by UniverseCraft.
the class StaffAlertMessageHandler method receive.
@Override
public void receive(String serverFrom, Document data) {
PermissionLevel level = PermissionLevel.valueOf(data.getString("permissionLevel"));
String subtype = data.getString("subtype");
TextComponent message;
if (subtype.equals("laggyServer")) {
message = new TextComponent("Server " + serverFrom + " is experiencing severe lag (" + MathUtil.round(data.getDouble("tps")) + "TPS, " + data.getInteger("players") + " players). Click to restart the instance!");
message.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text("Click to restart instance " + serverFrom)));
message.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/restartinstance " + serverFrom));
} else if (subtype.equals("generic")) {
message = new TextComponent("[" + serverFrom + "] " + data.getString("message"));
} else if (subtype.equals("report")) {
message = new TextComponent(ChatColor.GRAY + data.getString("message") + ChatColor.GRAY + " [" + ChatColor.UNDERLINE + "Click to View" + ChatColor.GRAY + "]");
message.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new Text("Click to view report #" + data.getInteger("reportId"))));
message.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/viewreport " + data.getInteger("reportId")));
} else if (subtype.equals("susjoin")) {
message = new TextComponent(data.getString("message"));
} else {
message = new TextComponent("[" + serverFrom + "] Unrecognized staff alert message: " + data.toJson());
level = PermissionLevel.DEVELOPER;
}
final PermissionLevel fLevel = level;
UserLoader.allUsers().stream().filter(u -> PermissionUtil.verifyActivePermissionLevel(u, fLevel, false)).forEach(u -> {
if (subtype.equals("report") && (!PermissionUtil.verifyActiveProfileFlag(u, SystemProfileFlag.MODERATION, false) || !u.getData().getEmbedded(Arrays.asList("modnotifs", "reports"), true)))
return;
if (subtype.equals("susjoin") && (!PermissionUtil.verifyActiveProfileFlag(u, SystemProfileFlag.MODERATION, false) || !u.getData().getEmbedded(Arrays.asList("modnotifs", "susjoin"), true)))
return;
u.getPlayer().spigot().sendMessage(new TextComponent(ChatColor.RED + "" + ChatColor.BOLD + "Staff Alert: " + ChatColor.RESET), message);
});
}
Aggregations