@Override public void run() { List<UUID> onlineIds = new ArrayList<>(); for (Player player : Sponge.getServer().getOnlinePlayers()) { onlineIds.add(player.getUniqueId()); } this.onlineIds = new CopyOnWriteArraySet<>(onlineIds); }
/** * Gets the {@link EventManager}. * * @return The event manager */ default EventManager getEventManager() { return Sponge.getEventManager(); }
/** * 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(); }
@Override public <T> void setProvider(Object plugin, Class<T> service, T provider) { checkNotNull(plugin, "plugin"); checkNotNull(service, "service"); checkNotNull(provider, "provider"); Optional<PluginContainer> containerOptional = this.pluginManager.fromInstance(plugin); if (!containerOptional.isPresent()) { throw new IllegalArgumentException( "The provided plugin object does not have an associated plugin container " + "(in other words, is 'plugin' actually your plugin object?)"); } PluginContainer container = containerOptional.get(); ProviderRegistration<?> oldProvider = this.providers.put(service, new Provider<>(container, service, provider)); try (CauseStackManager.StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) { frame.addContext(EventContextKeys.SERVICE_MANAGER, this); frame.pushCause(container); Sponge.getEventManager().post(SpongeEventFactory.createChangeServiceProviderEvent(frame.getCurrentCause(), this.providers.get(service), Optional.ofNullable(oldProvider))); } }
/** * Builds a {@link ShapedCraftingRecipe} from this builder. * * @param id The id of this recipe. * @param plugin The owning plugin. * @return A new {@link ShapedCraftingRecipe} * @throws IllegalStateException If not all required options * were specified * @deprecated Use {@link #build()} instead in combination with {@link #id(String)} */ @Deprecated default ShapedCraftingRecipe build(String id, Object plugin) { try (CauseStackManager.StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) { final PluginContainer container; if (plugin instanceof PluginContainer) { container = (PluginContainer) plugin; } else { container = Sponge.getPluginManager().fromInstance(plugin).orElseThrow(() -> new IllegalArgumentException( "Plugin must be a PluginContainer or plugin instance, not " + plugin)); } frame.pushCause(container); return id(id).build(); } } }
@Override public CommandResult process(CommandSource source, String commandLine) throws CommandException { final String[] argSplit = commandLine.split(" ", 2); Optional<CommandMapping> cmdOptional = get(argSplit[0], source); if (!cmdOptional.isPresent()) { throw new CommandNotFoundException(t("commands.generic.notFound"), argSplit[0]); // TODO: Fix properly to use a SpongeTranslation?? } final String arguments = argSplit.length > 1 ? argSplit[1] : ""; CommandMapping mapping = cmdOptional.get(); Optional<PluginContainer> pluginOwner = Sponge.getCommandManager().getOwner(mapping); pluginOwner.ifPresent(pluginContainer -> Sponge.getCauseStackManager().pushCause(pluginContainer)); final CommandCallable spec = mapping.getCallable(); Sponge.getCauseStackManager().pushCause(spec); try { return spec.process(source, arguments); } catch (CommandNotFoundException e) { throw new CommandException(t("No such child command: %s", e.getCommand())); } finally { if (pluginOwner.isPresent()) { Sponge.getCauseStackManager().popCause(); } Sponge.getCauseStackManager().popCause(); } }
int playerAmount = Sponge.getServer().getOnlinePlayers().size(); playerAmount = playerAmount > 200 ? 200 : playerAmount; int onlineMode = Sponge.getServer().getOnlineMode() ? 1 : 0; String minecraftVersion = Sponge.getGame().getPlatform().getMinecraftVersion().getName(); String spongeImplementation = Sponge.getPlatform().getContainer(Platform.Component.IMPLEMENTATION).getName();
Platform platform = Sponge.getPlatform(); spongeApi = platform.getContainer(Component.API).getVersion().orElse(null); spongeGame = platform.getContainer(Component.GAME).getVersion().orElse(null); spongeImpl = platform.getContainer(Component.IMPLEMENTATION).getVersion().orElse(null); pluginList = Sponge.getPluginManager().getPlugins().stream() .map(p -> p.getId() + ": " + p.getVersion().orElse(null)) .collect(Collectors.joining("; \n")); syncExecutor = Sponge.getScheduler().createSyncExecutor(this); asyncExecutor = Sponge.getScheduler().createAsyncExecutor(this); ServiceManager serviceMan = Sponge.getServiceManager(); serviceMan.setProvider(this, BlockService.class, blockService); serviceMan.setProvider(this, CacheService.class, cacheService); EventManager evenMan = Sponge.getEventManager(); evenMan.registerListeners(this, cacheService); evenMan.registerListeners(this, linkService);
public void updateCommands() { assert Sponge.getServer().isMainThread(); commands.clear(); Collection<CommandMapping> newCommands = Sponge.getCommandManager().getAll().values(); for (CommandMapping cmd : newCommands) { if (commands.containsKey(cmd.getPrimaryAlias())) continue; commands.put(cmd.getPrimaryAlias(), new CachedCommand(cmd)); } }
private void appendServerInformation() { appendHeader("Server Information"); LogListBlock log = new LogListBlock(); Runtime runtime = Runtime.getRuntime(); log.put("Java", "%s %s (%s)", System.getProperty("java.vendor"), System.getProperty("java.version"), System.getProperty("java.vendor.url")); log.put("Operating system", "%s %s (%s)", System.getProperty("os.name"), System.getProperty("os.version"), System.getProperty("os.arch")); log.put("Available processors", runtime.availableProcessors()); log.put("Free memory", runtime.freeMemory() / 1024 / 1024 + " MB"); log.put("Max memory", runtime.maxMemory() / 1024 / 1024 + " MB"); log.put("Total memory", runtime.totalMemory() / 1024 / 1024 + " MB"); //log.put("Server ID", Sponge.getServer().getServerId()); //log.put("Server name", Sponge.getServerName()); log.put("Platform", Sponge.getPlatform().getType().name()); log.put("Game version", Sponge.getPlatform().getMinecraftVersion().getName()); log.put("Player count", "%d/%d", Sponge.getServer().getOnlinePlayers().size(), Sponge.getServer().getMaxPlayers()); append(log); appendln(); }
/** * Gets the {@link GameDictionary} instance from the * {@link Game} instance. * * @see Game#getGameDictionary() * @return The game dictionary instance, or empty if unsupported */ public static Optional<GameDictionary> getDictionary() { return getGame().getGameDictionary(); }
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); }
@Override public void onForward(final Vote v) { if (debug) { logger.info("Got a forwarded vote -> " + v); } Sponge.getScheduler().createTaskBuilder() .execute(() -> { VotifierEvent event = new VotifierEvent(v, Sponge.getCauseStackManager().getCurrentCause()); Sponge.getEventManager().post(event); }) .submit(this); } }
/** * Gets the command dispatcher used for registering and dispatching * registered commands. * * @return The command dispatcher */ default CommandManager getCommandManager() { return Sponge.getCommandManager(); }
/** * Creates a new {@link Builder} to build a new * {@link WanderAITask}. * * @return A new builder */ static Builder builder() { return Sponge.getRegistry().createBuilder(Builder.class); }
public void onReload() { //run this task sync in order let it finish before the process ends database.close(); Sponge.getScheduler().getScheduledTasks(this).forEach(Task::cancel); Collection<Player> onlinePlayers = Sponge.getServer().getOnlinePlayers(); onlinePlayers.forEach(protectionManager::unprotect); init(); onlinePlayers.stream() .peek(protectionManager::protect) .parallel() .forEach(database::loadAccount); }
/** * Gets the scheduler used to schedule tasks. * * @return The scheduler */ default Scheduler getScheduler() { return Sponge.getScheduler(); }
Sponge.getEventManager().unregisterListeners(entry.getSecond()); Platform platform = Sponge.getPlatform(); String mc = platform.getContainer(Platform.Component.GAME).getVersion().orElse("?"); String sponge = platform.getContainer(Platform.Component.IMPLEMENTATION).getVersion().orElse("?"); List<WebHook> hooks = entry.getValue().stream().filter(WebHook::isEnabled).collect(Collectors.toList()); Sponge.getEventManager().registerListener(WebAPI.getInstance(), clazz, listener); customHooks.put(clazz, new Tuple<>(hooks, listener)); } catch (ClassNotFoundException e) {
/** * Gets the {@link CauseStackManager} for handling the current event cause * stack and context information. * * @return The cause stack manager */ default CauseStackManager getCauseStackManager() { return Sponge.getCauseStackManager(); }
/** * Returns the current platform, or implementation, this {@link Game} is running on. * * @return The current implementation */ default Platform getPlatform() { return Sponge.getPlatform(); }