/** * Gets the game's instance of the service manager, which is the gateway * to various services provided by Sponge (command registration and so on). * * <p>Services registered by other plugins may be available too.</p> * * @return The service manager */ default ServiceManager getServiceManager() { return Sponge.getServiceManager(); }
/** * 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 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); }
public SpongeOnlineUUIDWrapper() { Optional<UserStorageService> userStorage = Sponge.getServiceManager().provide(UserStorageService.class); userStorage.ifPresent(userStorageService -> this.userStorageService = userStorageService); }
public SpongeEconHandler() { if (Sponge.getServiceManager().isRegistered(EconomyService.class)) { econ = Sponge.getServiceManager().provide(EconomyService.class).get(); } }
private static <T> Optional<T> getService(Class<T> clazz) { return Sponge.getServiceManager().provide(clazz); }
private PermissionService getPermissionService() { Optional<PermissionService> optSrv = Sponge.getServiceManager().provide(PermissionService.class); if (!optSrv.isPresent()) throw new NotFoundException("Permission service was not found"); return optSrv.get(); } }
@JsonIgnore public Optional<User> getUser() { Optional<UserStorageService> optSrv = Sponge.getServiceManager().provide(UserStorageService.class); return optSrv.flatMap(srv -> srv.get(uuid)); }
private EconomyService getEconomyService() { Optional<EconomyService> optSrv = Sponge.getServiceManager().provide(EconomyService.class); if (!optSrv.isPresent()) throw new NotFoundException("Economy service was not found"); return optSrv.get(); } }
@Override public boolean isBanned() { Optional<BanService> service = Sponge.getServiceManager().provide(BanService.class); return service.isPresent() && service.get().isBanned(this.player.getProfile()); } }
/** * Creates a new {@link Builder} to build a pagination list * * @return The new builder */ static Builder builder() { return Sponge.getServiceManager().provideUnchecked(PaginationService.class).builder(); }
public static void onPreInit(Object plugin) { Sponge.getServiceManager().setProvider(plugin, NucleusAPIMetaService.class, new NucleusAPIMetaService(VERSION, SEMVER, isRelease.isEmpty())); }
/** * 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")); } }
private boolean isBanned(GameProfile profile) { Optional<ProviderRegistration<BanService>> banService = Sponge.getServiceManager().getRegistration(BanService.class); boolean banned = false; if (banService.isPresent()) { banned = banService.get().getProvider().isBanned(profile); } return banned; }
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); }
/** * 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); }
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); }
@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); }); }
@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(); }
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); }