Java Code Examples for org.spongepowered.api.service.permission.Subject#getIdentifier()

The following examples show how to use org.spongepowered.api.service.permission.Subject#getIdentifier() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UCPerms56.java    From UltimateChat with GNU General Public License v3.0 5 votes vote down vote up
public HashMap<Integer, Subject> getPlayerGroups(User player) {
    HashMap<Integer, Subject> subs = new HashMap<>();
    for (Subject sub : player.getParents()) {
        if (sub.getContainingCollection().equals(getGroups()) && (sub.getIdentifier() != null)) {
            subs.put(sub.getParents().size(), sub);
        }
    }
    return subs;
}
 
Example 2
Source File: GriefPreventionPlugin.java    From GriefPrevention with MIT License 4 votes vote down vote up
public static void addEventLogEntry(Event event, Location<World> location, String sourceId, String targetId, Subject permissionSubject, String permission, String trust, Tristate result) {
    final String eventName = event.getClass().getSimpleName().replace('$', '.').replace(".Impl", "");
    final String eventLocation = location == null ? "none" : location.getBlockPosition().toString();
    for (GPDebugData debugEntry : GriefPreventionPlugin.instance.getDebugUserMap().values()) {
        final CommandSource debugSource = debugEntry.getSource();
        final User debugUser = debugEntry.getTarget();
        if (debugUser != null) {
            if (permissionSubject == null) {
                continue;
            }
            // Check event source user
            if (!permissionSubject.getIdentifier().equals(debugUser.getUniqueId().toString())) {
                continue;
            }
        }

        String messageUser = permissionSubject.getIdentifier();
        if (permissionSubject instanceof User) {
            messageUser = ((User) permissionSubject).getName();
        }
        // record
        if (debugEntry.isRecording()) {
            String messageFlag = permission;
            permission = permission.replace("griefprevention.flag.", "");
            messageFlag = GPPermissionHandler.getFlagFromPermission(permission).toString();
            final String messageSource = sourceId == null ? "none" : sourceId;
            String messageTarget = targetId == null ? "none" : targetId;
            if (messageTarget.endsWith(".0")) {
                messageTarget = messageTarget.substring(0, messageTarget.length() - 2);
            }
            if (trust == null) {
                trust = "none";
            }

            debugEntry.addRecord(messageFlag, trust, messageSource, messageTarget, eventLocation, messageUser, result);
            continue;
        }

        final Text textEvent = Text.of(GP_TEXT, TextColors.GRAY, "Event: ", TextColors.GREEN, eventName, "\n");
        final Text textCause = Text.of(GP_TEXT, TextColors.GRAY, "Cause: ", TextColors.LIGHT_PURPLE, sourceId, "\n");
        final Text textLocation = Text.of(GP_TEXT, TextColors.GRAY, "Location: ", TextColors.WHITE, eventLocation == null ? "NONE" : eventLocation);
        final Text textUser = Text.of(TextColors.GRAY, "User: ", TextColors.GOLD, messageUser, "\n");
        final Text textLocationAndUser = Text.of(textLocation, " ", textUser);
        Text textContext = null;
        Text textPermission = null;
        if (targetId != null) {
            textContext = Text.of(GP_TEXT, TextColors.GRAY, "Target: ", TextColors.YELLOW, GPPermissionHandler.getPermissionIdentifier(targetId), "\n");
        }
        if (permission != null) {
            textPermission = Text.of(GP_TEXT, TextColors.GRAY, "Permission: ", TextColors.RED, permission, "\n");
        }
        Text.Builder textBuilder = Text.builder().append(textEvent);
        if (textContext != null) {
            textBuilder.append(textContext);
        } else {
            textBuilder.append(textCause);
        }
        if (textPermission != null) {
            textBuilder.append(textPermission);
        }
        textBuilder.append(textLocationAndUser);
        debugSource.sendMessage(textBuilder.build());
    }
}