@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()); }
/** * Creates a new {@link Builder} to build a pagination list. * * @return The new builder */ static Builder builder() { return Sponge.getServiceManager().provideUnchecked(PaginationService.class).builder(); }
@Override protected Object getValue(String choice) throws IllegalArgumentException { return Sponge.getGame().getServiceManager().provideUnchecked(UserStorageService.class).get(choice) .orElseThrow(() -> new IllegalArgumentException("Input value '" + choice + "' was not a user!")); }
@Override protected Iterable<String> getChoices(CommandSource source) { return Sponge.getGame().getServiceManager().provideUnchecked(UserStorageService.class).getAll().stream() .map(GameProfile::getName) .filter(Optional::isPresent) .map(Optional::get) .collect(ImmutableList.toImmutableList()); }
@Override public void parse(CommandSource source, CommandArgs args, CommandContext context) throws ArgumentParseException { // If we're not completing, then we want to use the UserStorageService directly // to get any direct match. @Nullable Text key = getKey(); if (key != null && !context.hasAny(CommandContext.TAB_COMPLETION)) { if (this.returnSource && !args.hasNext()) { context.putArg(key, tryReturnSource(source, args)); return; } CommandArgs.Snapshot state = args.getSnapshot(); String element = args.next(); try { Optional<User> match = Sponge.getServiceManager().provideUnchecked(UserStorageService.class).get(element); if (match.isPresent()) { context.putArg(key, match.get()); return; } } catch (IllegalArgumentException ignored) { // Intentionally ignored // If it's not an exact match, we just let this carry on to parse using the pattern element } args.applySnapshot(state); } super.parse(source, args, context); }
@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()); }
@Override protected Iterable<String> getChoices(CommandSource source) { return Sponge.getGame().getServiceManager().provideUnchecked(UserStorageService.class).getAll().stream() .map(GameProfile::getName) .filter(Optional::isPresent) .map(Optional::get) .collect(GuavaCollectors.toImmutableList()); }
/** * Creates a new {@link Builder} to build a pagination list * * @return The new builder */ static Builder builder() { return Sponge.getServiceManager().provideUnchecked(PaginationService.class).builder(); }
/** * Gets the {@link User} who owns this home. * * @return The {@link User} */ default User getUser() { return Sponge.getServiceManager().provideUnchecked(UserStorageService.class).get(getOwnersUniqueId()).orElseThrow(() -> new IllegalStateException("user")); } }
@Override protected Object getValue(String choice) throws IllegalArgumentException { return Sponge.getGame().getServiceManager().provideUnchecked(UserStorageService.class).get(choice).get(); } }
/** * Modifies a home's location, if it exists, otherwise creates a home. This is subject to Nucleus' standard checks. * * @param cause The {@link Cause} of the change. The {@link PluginContainer} must be the root cause. * @param user The {@link UUID} of the user to modify the home for. * @param name The name of the home to modify or create. * @param location The location of the home. * @param rotation The rotation of the player when they return to this home. * @throws NucleusException if the home could not be created, due to home limits, or a plugin cancelled the event. * @throws NoSuchPlayerException if the supplied UUID does not map to a known user */ default void modifyOrCreateHome(Cause cause, UUID user, String name, Location<World> location, Vector3d rotation) throws NucleusException, NoSuchPlayerException { modifyOrCreateHome(cause, Sponge.getServiceManager().provideUnchecked(UserStorageService.class).get(user).orElseThrow(NoSuchPlayerException::new), name, location, rotation); }
default void createHome(Cause cause, UUID user, String name, Location<World> location, Vector3d rotation) throws NucleusException, NoSuchPlayerException { createHome(cause, Sponge.getServiceManager().provideUnchecked(UserStorageService.class).get(user).orElseThrow(NoSuchPlayerException::new), name, location, rotation); }
private void setupSpongeMockLocal() { PowerMockito.mockStatic(Sponge.class); ServiceManager manager = Mockito.mock(ServiceManager.class); UserStorageService service = getMockUserStorageService(); Server server = Mockito.mock(Server.class); Mockito.when(server.getPlayer(Mockito.anyString())).thenReturn(Optional.empty()); Mockito.when(server.getOnlinePlayers()).thenReturn(ImmutableList.of()); Mockito.when(Sponge.getServer()).thenReturn(server); Mockito.when(manager.provideUnchecked(UserStorageService.class)).thenReturn(service); Mockito.when(Sponge.getServiceManager()).thenReturn(manager); }
public Database(Logger logger, Settings settings, String tableName) throws SQLException { this.logger = logger; this.tableName = tableName; SQLConfig sqlConfig = settings.getGeneral().getSQL(); Path configDir = settings.getConfigDir(); this.storageType = sqlConfig.getType(); String jdbcConnection = buildJDBCUrl(sqlConfig, configDir); this.dataSource = Sponge.getServiceManager().provideUnchecked(SqlService.class).getDataSource(jdbcConnection); }
@Listener public void startup(GamePreInitializationEvent event) { try { loadConfig(); } catch (IOException e) { // Failed to load configuration logger.warn("Failed to load bStats config!", e); return; } if (Sponge.getServiceManager().isRegistered(Metrics.class)) { Metrics provider = Sponge.getServiceManager().provideUnchecked(Metrics.class); provider.linkMetrics(this); } else { Sponge.getServiceManager().setProvider(plugin.getInstance().get(), Metrics.class, this); this.linkMetrics(this); startSubmitting(); } }
@Listener public void startup(GamePreInitializationEvent event) { try { loadConfig(); } catch (IOException e) { // Failed to load configuration logger.warn("Failed to load bStats config!", e); return; } if (Sponge.getServiceManager().isRegistered(Metrics.class)) { Metrics provider = Sponge.getServiceManager().provideUnchecked(Metrics.class); provider.linkMetrics(this); } else { Sponge.getServiceManager().setProvider(plugin.getInstance().get(), Metrics.class, this); this.linkMetrics(this); startSubmitting(); } }