/** * Gets whether the class of the type of service is already registered with * this manager. This does not register or unregister any services. * * @param service The service class * @return True if there is a provider for the desired service */ default boolean isRegistered(Class<?> service) { return provide(service).isPresent(); }
/** * Gets whether the class of the type of service is already registered with * this manager. This does not register or unregister any services. * * @param service The service class * @return True if there is a provider for the desired service */ default boolean isRegistered(Class<?> service) { return provide(service).isPresent(); }
public SpongeOnlineUUIDWrapper() { Optional<UserStorageService> userStorage = Sponge.getServiceManager().provide(UserStorageService.class); userStorage.ifPresent(userStorageService -> this.userStorageService = userStorageService); }
private static <T> Optional<T> getService(Class<T> clazz) { return Sponge.getServiceManager().provide(clazz); }
@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(); } }
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(); } }
@Override public boolean isBanned() { Optional<BanService> service = Sponge.getServiceManager().provide(BanService.class); return service.isPresent() && service.get().isBanned(this.player.getProfile()); } }
public SpongeEconHandler() { if (Sponge.getServiceManager().isRegistered(EconomyService.class)) { econ = Sponge.getServiceManager().provide(EconomyService.class).get(); } }
@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); }
/** * Gets a specific player by name or UUID. * * @param nameOrUuid Either the name or UUID of the player. Use {@link #getPlayer(UUID)}} if the UUID is * already parsed. * @return An optional containing the player, or empty if not found. */ public Optional<CachedPlayer> getPlayer(String nameOrUuid) { if (Util.isValidUUID(nameOrUuid)) { return getPlayer(UUID.fromString(nameOrUuid)); } Optional<CachedPlayer> player = players.values().stream().filter(p -> p.getName().equalsIgnoreCase(nameOrUuid)).findAny(); if (player.isPresent()) return player.flatMap(p -> getPlayer(p.getUUID())); return WebAPI.runOnMain(() -> { Optional<UserStorageService> optSrv = Sponge.getServiceManager().provide(UserStorageService.class); if (!optSrv.isPresent()) throw new InternalServerErrorException("User storage service is not available"); Optional<User> optUser = optSrv.get().get(nameOrUuid); return optUser.<CachedPlayer>map(CachedPlayer::new); }); }
/** * Gets a specific player by UUID. * @param uuid The UUID of the player. * @return An optional containing the cached player if found, or empty otherwise. */ public Optional<CachedPlayer> getPlayer(UUID uuid) { if (!players.containsKey(uuid)) { return WebAPI.runOnMain(() -> { Optional<UserStorageService> optSrv = Sponge.getServiceManager().provide(UserStorageService.class); if (!optSrv.isPresent()) throw new InternalServerErrorException("User storage service is not available"); Optional<User> optUser = optSrv.get().get(uuid); return optUser.<CachedPlayer>map(CachedPlayer::new); }); } final CachedPlayer res = players.get(uuid); if (res.isExpired()) { return WebAPI.runOnMain(() -> { Optional<Player> player = Sponge.getServer().getPlayer(uuid); return player.map(this::updatePlayer); }); } else { return Optional.of(res); } }
@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 CommandResult execute(CommandSource src, CommandContext args) throws CommandException { String namespace = args.<String>getOne("namespace").orElse(((Player) src).getUniqueId().toString()); if (!namespace.equals(((Player) src).getUniqueId().toString()) && !area.commandListOtherPermissions.hasPermission(src)) { src.sendMessage(Text.of(TextColors.RED, "You don't have permission to list areas of other namespaces!")); return CommandResult.empty(); } PaginationService paginationService = Sponge.getServiceManager().provide(PaginationService.class).get(); PaginationList.Builder builder = paginationService.builder(); String[] files = new File(new File(CraftBookPlugin.inst().getWorkingDirectory(), "areas"), namespace).list(); List<Text> contents = new ArrayList<>(); for (String file : files) if (file != null) contents.add(Text.of(file)); builder.contents(contents).title(Text.of("Areas")).sendTo(src); return CommandResult.success(); } }
@Override public void setupDataSource() throws DBInitException { Optional<SqlService> sqlServiceProvider = Sponge.getServiceManager().provide(SqlService.class); if (!sqlServiceProvider.isPresent()) { return; } String host = config.get(DatabaseSettings.MYSQL_HOST); String port = config.get(DatabaseSettings.MYSQL_PORT); String database = config.get(DatabaseSettings.MYSQL_DATABASE); String launchOptions = config.get(DatabaseSettings.MYSQL_LAUNCH_OPTIONS); if (launchOptions.isEmpty() || !launchOptions.startsWith("?") || launchOptions.endsWith("&")) { logger.error("Launch Options were faulty, using default (?rewriteBatchedStatements=true&useSSL=false)"); launchOptions = "?rewriteBatchedStatements=true&useSSL=false"; } String url = host + ":" + port + "/" + database + launchOptions; String username = config.get(DatabaseSettings.MYSQL_USER); String password = config.get(DatabaseSettings.MYSQL_PASS); try { this.dataSource = sqlServiceProvider.get().getDataSource( "jdbc:mysql://" + username + ":" + password + "@" + url ); } catch (SQLException e) { throw new DBInitException(e); } }
@Override public void msgPaginated(Translatable title, @Nullable Translatable header, final Iterable<Text.Builder> text) { PaginationList.Builder build = pex.getGame().getServiceManager().provide(PaginationService.class).get().builder(); build.title(fmt().hl(fmt().header(fmt().tr(title))).build()); if (header != null) { build.header(fmt().tr(header).color(TextColors.GRAY).build()); } build.contents(Iterables.transform(text, input -> input.color(TextColors.DARK_AQUA).build())) .sendTo(commandSource); } }
private void sendPaginatedMessage(Node node, CommandSource source) { PaginationService paginationService = Sponge.getServiceManager().provide(PaginationService.class).get(); PaginationList.Builder builder = paginationService.builder(); List<Text> contents = node.getSubcategories().stream() .map(category -> Text.builder("> " + category.getName()).color(TextColors.GRAY).onClick(TextActions.executeCallback(commandSource -> { if (commandSource instanceof Player) { sendPaginatedMessage(node.getChild(category), source); } })).build()).collect(Collectors.toList()); for (Package p : node.getPackages()) { contents.add(Text.builder(p.getName()).color(TextColors.WHITE).append(Text.builder(" - ").color(TextColors.GRAY).build()) .append(Text.builder("$x".replace("$", plugin.getServerInformation().getAccount().getCurrency().getSymbol()) .replace("x", "" + p.getEffectivePrice())).color(TextColors.GREEN).build()) .onClick(TextActions.executeCallback(commandSource -> { if (commandSource instanceof Player) { plugin.getPlatform().executeAsync(new SendCheckoutLinkTask(plugin, p.getId(), (Player) commandSource)); } })).build()); } builder.title(Text.builder(plugin.getI18n().get("sponge_listing")).color(TextColors.AQUA).build()).contents(contents).padding(Text.of("-")).sendTo(source); }
this.timings = new Timings(this); logger.info(t("Pre-init of %s v%s", PomData.NAME, PomData.VERSION)); sql = services.provide(SqlService.class); scheduler = game.getScheduler();