Search in sources :

Example 1 with PermissionLevel

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.");
    }
}
Also used : User(mc.dragons.core.gameobject.user.User) PermissionLevel(mc.dragons.core.gameobject.user.permission.PermissionLevel)

Example 2 with PermissionLevel

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.");
}
Also used : PermissionLevel(mc.dragons.core.gameobject.user.permission.PermissionLevel)

Example 3 with PermissionLevel

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;
}
Also used : Document(org.bson.Document) AbstractLightweightLoader(mc.dragons.core.storage.loader.AbstractLightweightLoader) Iterables(com.google.common.collect.Iterables) MongoConfig(mc.dragons.core.storage.mongo.MongoConfig) MessageData(mc.dragons.core.gameobject.user.chat.MessageData) PermissionUtil(mc.dragons.core.util.PermissionUtil) Date(java.util.Date) User(mc.dragons.core.gameobject.user.User) HashMap(java.util.HashMap) PaginationUtil(mc.dragons.core.storage.mongo.pagination.PaginationUtil) ArrayList(java.util.ArrayList) PaginatedResult(mc.dragons.core.storage.mongo.pagination.PaginatedResult) GameObjectType(mc.dragons.core.gameobject.GameObjectType) Report(mc.dragons.tools.moderation.report.ReportLoader.Report) PermissionLevel(mc.dragons.core.gameobject.user.permission.PermissionLevel) Map(java.util.Map) StringUtil(mc.dragons.core.util.StringUtil) UserLoader(mc.dragons.core.gameobject.user.UserLoader) UUID(java.util.UUID) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) Dragons(mc.dragons.core.Dragons) List(java.util.List) FindIterable(com.mongodb.client.FindIterable) DeleteResult(com.mongodb.client.result.DeleteResult) Report(mc.dragons.tools.moderation.report.ReportLoader.Report) PermissionLevel(mc.dragons.core.gameobject.user.permission.PermissionLevel) Document(org.bson.Document)

Example 4 with PermissionLevel

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;
}
Also used : Document(org.bson.Document) AbstractLightweightLoader(mc.dragons.core.storage.loader.AbstractLightweightLoader) Iterables(com.google.common.collect.Iterables) MongoConfig(mc.dragons.core.storage.mongo.MongoConfig) MessageData(mc.dragons.core.gameobject.user.chat.MessageData) PermissionUtil(mc.dragons.core.util.PermissionUtil) Date(java.util.Date) User(mc.dragons.core.gameobject.user.User) HashMap(java.util.HashMap) PaginationUtil(mc.dragons.core.storage.mongo.pagination.PaginationUtil) ArrayList(java.util.ArrayList) PaginatedResult(mc.dragons.core.storage.mongo.pagination.PaginatedResult) GameObjectType(mc.dragons.core.gameobject.GameObjectType) Report(mc.dragons.tools.moderation.report.ReportLoader.Report) PermissionLevel(mc.dragons.core.gameobject.user.permission.PermissionLevel) Map(java.util.Map) StringUtil(mc.dragons.core.util.StringUtil) UserLoader(mc.dragons.core.gameobject.user.UserLoader) UUID(java.util.UUID) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) Dragons(mc.dragons.core.Dragons) List(java.util.List) FindIterable(com.mongodb.client.FindIterable) DeleteResult(com.mongodb.client.result.DeleteResult) Report(mc.dragons.tools.moderation.report.ReportLoader.Report) Document(org.bson.Document) PermissionLevel(mc.dragons.core.gameobject.user.permission.PermissionLevel)

Example 5 with PermissionLevel

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);
    });
}
Also used : TextComponent(net.md_5.bungee.api.chat.TextComponent) Document(org.bson.Document) HoverEvent(net.md_5.bungee.api.chat.HoverEvent) Arrays(java.util.Arrays) UserLoader(mc.dragons.core.gameobject.user.UserLoader) PermissionUtil(mc.dragons.core.util.PermissionUtil) Text(net.md_5.bungee.api.chat.hover.content.Text) ClickEvent(net.md_5.bungee.api.chat.ClickEvent) SystemProfileFlag(mc.dragons.core.gameobject.user.permission.SystemProfile.SystemProfileFlags.SystemProfileFlag) Dragons(mc.dragons.core.Dragons) TextComponent(net.md_5.bungee.api.chat.TextComponent) PermissionLevel(mc.dragons.core.gameobject.user.permission.PermissionLevel) ChatColor(org.bukkit.ChatColor) MathUtil(mc.dragons.core.util.MathUtil) Bukkit(org.bukkit.Bukkit) HoverEvent(net.md_5.bungee.api.chat.HoverEvent) ClickEvent(net.md_5.bungee.api.chat.ClickEvent) Text(net.md_5.bungee.api.chat.hover.content.Text) PermissionLevel(mc.dragons.core.gameobject.user.permission.PermissionLevel)

Aggregations

PermissionLevel (mc.dragons.core.gameobject.user.permission.PermissionLevel)7 User (mc.dragons.core.gameobject.user.User)4 Document (org.bson.Document)4 UUID (java.util.UUID)3 Dragons (mc.dragons.core.Dragons)3 UserLoader (mc.dragons.core.gameobject.user.UserLoader)3 PaginatedResult (mc.dragons.core.storage.mongo.pagination.PaginatedResult)3 PermissionUtil (mc.dragons.core.util.PermissionUtil)3 Report (mc.dragons.tools.moderation.report.ReportLoader.Report)3 Iterables (com.google.common.collect.Iterables)2 FindIterable (com.mongodb.client.FindIterable)2 DeleteResult (com.mongodb.client.result.DeleteResult)2 Instant (java.time.Instant)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 Collectors (java.util.stream.Collectors)2 GameObjectType (mc.dragons.core.gameobject.GameObjectType)2