public void registerPermission(CommandCallable command, String permission) { Sponge.getGame().getServiceManager().getRegistration(PermissionService.class).ifPresent((permissionService -> { PermissionDescription.Builder permissionBuilder = permissionService.getProvider().newDescriptionBuilder(SpongeWorldEdit.inst()); permissionBuilder.id(permission).register(); })); }
@Override public Collection<MessageReceiver> getMembers() { PermissionService service = Sponge.getGame().getServiceManager().provideUnchecked(PermissionService.class); return service.getLoadedCollections().values().stream() .flatMap(input -> input.getLoadedWithPermission(this.permission).entrySet().stream() .filter(Map.Entry::getValue) .map(entry -> entry.getKey().getCommandSource().orElse(null)) .filter(source -> source != null)) .collect(ImmutableSet.toImmutableSet()); }
@GET @Path("/collection/{id}") @Permission({ "collection", "one" }) @ApiOperation( value = "Get collection", notes = "Gets a specific subject collection") public SubjectCollection getCollection(@PathParam("id") String id) throws NotFoundException { PermissionService srv = getPermissionService(); try { if (!srv.hasCollection(id).get()) throw new NotFoundException("Collection with id " + id + " could not be found"); return srv.loadCollection(id).get(); } catch (InterruptedException e) { throw new ClientErrorException(e.getMessage(), Response.Status.REQUEST_TIMEOUT); } catch (ExecutionException e) { throw new InternalServerErrorException(e.getMessage()); } }
@GET @Path("/collection") @Permission({ "collection", "list" }) @ExplicitDetails @ApiOperation( value = "List collections", notes = "Gets a list of all the subject collections, for example groups, users, etc.") public Set<SubjectCollection> listCollections() { PermissionService srv = getPermissionService(); try { Set<SubjectCollection> colls = new HashSet<>(); for (String id : srv.getAllIdentifiers().get()) { colls.add(srv.loadCollection(id).get()); } return colls; } catch (InterruptedException e) { throw new ClientErrorException(e.getMessage(), Response.Status.REQUEST_TIMEOUT); } catch (ExecutionException e) { throw new InternalServerErrorException(e.getMessage()); } }
List<Subject> toSubjectList(List<Map.Entry<String, String>> parents) { ImmutableList.Builder<Subject> ret = ImmutableList.builder(); for (Map.Entry<String, String> ent : parents) { SubjectCollection collection = this.service.getSubjects(ent.getKey()); ret.add(collection.get(ent.getValue())); } return ret.build(); }
@Override public Collection<MessageReceiver> getMembers() { PermissionService service = Sponge.getGame().getServiceManager().provideUnchecked(PermissionService.class); return service.getKnownSubjects().values().stream() .flatMap(input -> input.getAllWithPermission(this.permission).entrySet().stream() .filter(Map.Entry::getValue) .map(entry -> entry.getKey().getCommandSource().orElse(null)) .filter(source -> source != null)) .collect(GuavaCollectors.toImmutableSet()); }
@Listener public void init(GamePostInitializationEvent event) { instance = this; initStuff(false); Sponge.getServiceManager().provide(PermissionService.class).ifPresent(svc -> { svc.getDefaults().getTransientSubjectData().setPermission(Sets.newHashSet(), "magibridge.chat", Tristate.TRUE); svc.getDefaults().getTransientSubjectData().setPermission(Sets.newHashSet(), "magibridge.mention", Tristate.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 checkPermission(String playerName, String perm) { if (playerName.equals("console")) { return true; } UUID uuid = getUUID(playerName); return loader.getGame().getServiceManager().provide(PermissionService.class).get().getUserSubjects().get(uuid.toString()).hasPermission(perm); }
@GET @Path("/collection/{id}/subject/{subId}") @Permission({ "collection", "subject", "one" }) @ApiOperation( value = "Get subject", notes = "Gets one specific subject belonging to a certain collection") public Subject getSubject(@PathParam("id") String id, @PathParam("subId") String subId) throws NotFoundException { PermissionService srv = getPermissionService(); try { if (!srv.hasCollection(id).get()) throw new NotFoundException("Collection with id " + id + " could not be found"); SubjectCollection coll = srv.loadCollection(id).get(); if (!coll.hasSubject(subId).get()) throw new NotFoundException("Subject with id " + id + " could not be found"); return coll.loadSubject(subId).get(); } catch (InterruptedException e) { throw new ClientErrorException(e.getMessage(), Response.Status.REQUEST_TIMEOUT); } catch (ExecutionException e) { throw new InternalServerErrorException(e.getMessage()); } }
@GET @Path("/collection/{id}/subject") @Permission({ "collection", "subject", "list" }) @ExplicitDetails @ApiOperation( value = "List subjects", notes = "List all subjects belonging to a certain collection") public Set<Subject> listSubjects(@PathParam("id") String id) throws NotFoundException { PermissionService srv = getPermissionService(); try { if (!srv.hasCollection(id).get()) throw new NotFoundException("Collection with id " + id + " could not be found"); Set<Subject> subjects = new HashSet<>(); SubjectCollection coll = srv.loadCollection(id).get(); for (String subId : coll.getAllIdentifiers().get()) { subjects.add(coll.loadSubject(subId).get()); } return subjects; } catch (InterruptedException e) { throw new ClientErrorException(e.getMessage(), Response.Status.REQUEST_TIMEOUT); } catch (ExecutionException e) { throw new InternalServerErrorException(e.getMessage()); } }
@Override public void register() { ProviderRegistration<PermissionService> provider = Sponge.getServiceManager().getRegistration(PermissionService.class).orElse(null); if(provider == null) { CraftBookPlugin.spongeInst().getLogger().warn("Missing Permissions Provider. Permissions will not work as expected!"); return; } PermissionDescription.Builder permissionBuilder = provider.getProvider().newDescriptionBuilder(CraftBookPlugin.inst()); permissionDescription = permissionBuilder.id(getNode()).description(Text.of(getDescription())).assign(getDefaultRole(), true).register(); }