@ApiModelProperty(value = "The unique id of this subject collection", required = true) public String getId() { return value.getIdentifier(); }
@Override public Optional<Map.Entry<String, String>> getSubjectIdentifier() { return Optional.of(Maps.immutableEntry(commandSource.getContainingCollection().getIdentifier(), commandSource.getIdentifier())); }
@Override public boolean removeParent(Set<Context> contexts, Subject parent) { contexts = ImmutableSet.copyOf(contexts); while (true) { Map.Entry<String, String> removeEnt = Maps.immutableEntry(parent.getContainingCollection().getIdentifier(), parent.getIdentifier()); List<Map.Entry<String, String>> oldParents = this.parents.get(contexts); List<Map.Entry<String, String>> newParents; if (oldParents == null || !oldParents.contains(removeEnt)) { return false; } newParents = new ArrayList<>(oldParents); newParents.remove(removeEnt); if (updateCollection(this.parents, contexts, oldParents, Collections.unmodifiableList(newParents))) { return true; } } }
@Override public boolean addParent(Set<Context> contexts, Subject parent) { contexts = ImmutableSet.copyOf(contexts); while (true) { Map.Entry<String, String> newEnt = Maps.immutableEntry(parent.getContainingCollection().getIdentifier(), parent.getIdentifier()); List<Map.Entry<String, String>> oldParents = this.parents.get(contexts); List<Map.Entry<String, String>> newParents = ImmutableList.<Map.Entry<String, String>>builder() .addAll(oldParents == null ? Collections.emptyList() : oldParents) .add(newEnt) .build(); if (oldParents != null && oldParents.contains(newEnt)) { return false; } if (updateCollection(this.parents, contexts, oldParents, newParents)) { return true; } } }
public static String getHighestGroup(Player player) { try { if (!Sponge.getGame().getServiceManager().getRegistration(PermissionService.class).isPresent()) return ""; PermissionService ps = Sponge.getGame().getServiceManager().getRegistration(PermissionService.class).get().getProvider(); HashMap<Integer, Subject> subs = new HashMap<Integer, Subject>(); for (SubjectReference sub : player.getParents()) { if (sub.getCollectionIdentifier().equals(ps.getGroupSubjects().getIdentifier()) && (sub.getSubjectIdentifier() != null)) { Subject subj = sub.resolve().get(); subs.put(subj.getParents().size(), subj); } } return subs.isEmpty() ? "" : subs.get(Collections.max(subs.keySet())).getFriendlyIdentifier().isPresent() ? subs.get(Collections.max(subs.keySet())).getFriendlyIdentifier().get() : ""; } catch (InterruptedException | ExecutionException e) { } return ""; }
@Override public boolean addParent(final Set<Context> set, final Subject subject) { return wasSuccess(data.update(input -> input.addParent(parSet(set), subject.getContainingCollection().getIdentifier(), subject.getIdentifier()))); }
@Override public boolean removeParent(final Set<Context> set, final Subject subject) { return wasSuccess(data.update(input -> input.removeParent(parSet(set), subject.getContainingCollection().getIdentifier(), subject.getIdentifier()))); }