org.spongepowered.api.Platform Java Examples
The following examples show how to use
org.spongepowered.api.Platform.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: InfoServlet.java From Web-API with MIT License | 6 votes |
public ServerInfo() { Server server = Sponge.getServer(); Platform platform = Sponge.getPlatform(); this.motd = server.getMotd().toBuilder().build(); this.players = server.getOnlinePlayers().size(); this.maxPlayers = server.getMaxPlayers(); if (server.getBoundAddress().isPresent()) { InetSocketAddress addr = server.getBoundAddress().get(); this.address = addr.getHostName() + (addr.getPort() == 25565 ? "" : ":" + addr.getPort()); } this.onlineMode = server.getOnlineMode(); this.resourcePack = server.getDefaultResourcePack().map(ResourcePack::getName).orElse(null); this.hasWhitelist = server.hasWhitelist(); this.uptimeTicks = server.getRunningTimeTicks(); this.tps = server.getTicksPerSecond(); this.minecraftVersion = platform.getMinecraftVersion().getName(); this.game = new CachedPluginContainer(platform.getContainer(Platform.Component.GAME)); this.api = new CachedPluginContainer(platform.getContainer(Platform.Component.API)); this.implementation = new CachedPluginContainer(platform.getContainer(Platform.Component.IMPLEMENTATION)); }
Example #2
Source File: SpongePlugin.java From BungeeTabListPlus with GNU General Public License v3.0 | 6 votes |
@Listener public void onServerAboutToStart(GameAboutToStartServerEvent event) { // register plugin message channel channel = game.getChannelRegistrar().createRawChannel(this, BridgeProtocolConstants.CHANNEL); channel.addListener(Platform.Type.SERVER, (data, connection, side) -> { if (connection instanceof PlayerConnection) { Player player = ((PlayerConnection) connection).getPlayer(); DataInput input = new DataInputStream(new ChannelBufInputStream(data)); try { bridge.onMessage(player, input); } catch (Throwable e) { rlExecutor.execute(() -> { logger.error("Unexpected error", e); }); } } }); // init bridge initBridge(); }
Example #3
Source File: Metrics.java From EagleFactions with MIT License | 5 votes |
/** * Gets the server specific data. * * @return The server specific data. */ private JsonObject getServerData() { // Minecraft specific data 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(); // OS/Java specific data String javaVersion = System.getProperty("java.version"); String osName = System.getProperty("os.name"); String osArch = System.getProperty("os.arch"); String osVersion = System.getProperty("os.version"); int coreCount = Runtime.getRuntime().availableProcessors(); JsonObject data = new JsonObject(); data.addProperty("serverUUID", serverUUID); data.addProperty("playerAmount", playerAmount); data.addProperty("onlineMode", onlineMode); data.addProperty("minecraftVersion", minecraftVersion); data.addProperty("spongeImplementation", spongeImplementation); data.addProperty("javaVersion", javaVersion); data.addProperty("osName", osName); data.addProperty("osArch", osArch); data.addProperty("osVersion", osVersion); data.addProperty("coreCount", coreCount); return data; }
Example #4
Source File: Metrics2.java From GriefPrevention with MIT License | 5 votes |
/** * Gets the server specific data. * * @return The server specific data. */ private JsonObject getServerData() { // Minecraft specific data 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(); // OS/Java specific data String javaVersion = System.getProperty("java.version"); String osName = System.getProperty("os.name"); String osArch = System.getProperty("os.arch"); String osVersion = System.getProperty("os.version"); int coreCount = Runtime.getRuntime().availableProcessors(); JsonObject data = new JsonObject(); data.addProperty("serverUUID", serverUUID); data.addProperty("playerAmount", playerAmount); data.addProperty("onlineMode", onlineMode); data.addProperty("minecraftVersion", minecraftVersion); data.addProperty("spongeImplementation", spongeImplementation); data.addProperty("javaVersion", javaVersion); data.addProperty("osName", osName); data.addProperty("osArch", osArch); data.addProperty("osVersion", osVersion); data.addProperty("coreCount", coreCount); return data; }
Example #5
Source File: SubAPI.java From SubServers-2 with Apache License 2.0 | 5 votes |
/** * Gets the Server Version * * @return Server Version */ public Version getServerVersion() { PluginContainer container = null; if (container == null) container = Util.getDespiteException(() -> (PluginContainer) Platform.class.getMethod("getContainer", Class.forName("org.spongepowered.api.Platform$Component")).invoke(Sponge.getPlatform(), Enum.valueOf((Class<Enum>) Class.forName("org.spongepowered.api.Platform$Component"), "IMPLEMENTATION")), null); if (container == null) container = Util.getDespiteException(() -> (PluginContainer) Platform.class.getMethod("getImplementation").invoke(Sponge.getPlatform()), null); return (container == null || !container.getVersion().isPresent())?null:new Version(container.getVersion().get()); }
Example #6
Source File: SpongePluginMessagingForwardingSink.java From NuVotifier with GNU General Public License v3.0 | 5 votes |
@Override public void handlePayload(ChannelBuf channelBuf, RemoteConnection remoteConnection, Platform.Type type) { byte[] msgDirBuf = channelBuf.readBytes(channelBuf.available()); try { this.handlePluginMessage(msgDirBuf); } catch (Exception e) { p.getLogger().error("There was an unknown error when processing a forwarded vote.", e); } }
Example #7
Source File: UltimateCore.java From UltimateCore with MIT License | 5 votes |
@Listener public void onStart(GameStartingServerEvent ev) { //On a client, wait until the Sponge.getServer() is available and then load UC if (Sponge.getPlatform().getType().equals(Platform.Type.CLIENT) && !this.started) { onPreInit(null); onInit(null); onPostInit(null); return; } }
Example #8
Source File: UChatBungee.java From UltimateChat with GNU General Public License v3.0 | 5 votes |
public UChatBungee(UChat plugin) { Sponge.getEventManager().registerListener(plugin.instance(), GameStartedServerEvent.class, (event) -> { this.chan = Sponge.getChannelRegistrar().createRawChannel(plugin.instance(), "bungee:uchat"); this.listener = this; this.chan.addListener(Platform.Type.SERVER, this.listener); }); }
Example #9
Source File: PlanSpongeMocker.java From Plan with GNU Lesser General Public License v3.0 | 5 votes |
private Platform mockPlatform() { Platform platform = Mockito.mock(Platform.class); MinecraftVersion version = Mockito.mock(MinecraftVersion.class); doReturn("1.12").when(version).getName(); doReturn(version).when(platform).getMinecraftVersion(); return platform; }
Example #10
Source File: PlanSpongeMocker.java From Plan with GNU Lesser General Public License v3.0 | 5 votes |
PlanSpongeMocker withGame() { Game game = Mockito.mock(Game.class); Platform platform = mockPlatform(); Server server = mockServer(); doReturn(platform).when(game).getPlatform(); doReturn(server).when(game).getServer(); doReturn(game).when(planMock).getGame(); return this; }
Example #11
Source File: MetricsLite2.java From bStats-Metrics with GNU Lesser General Public License v3.0 | 5 votes |
/** * Gets the server specific data. * * @return The server specific data. */ private JsonObject getServerData() { // Minecraft specific data int playerAmount = Math.min(Sponge.getServer().getOnlinePlayers().size(), 200); int onlineMode = Sponge.getServer().getOnlineMode() ? 1 : 0; String minecraftVersion = Sponge.getGame().getPlatform().getMinecraftVersion().getName(); String spongeImplementation = Sponge.getPlatform().getContainer(Platform.Component.IMPLEMENTATION).getName(); // OS/Java specific data String javaVersion = System.getProperty("java.version"); String osName = System.getProperty("os.name"); String osArch = System.getProperty("os.arch"); String osVersion = System.getProperty("os.version"); int coreCount = Runtime.getRuntime().availableProcessors(); JsonObject data = new JsonObject(); data.addProperty("serverUUID", serverUUID); data.addProperty("playerAmount", playerAmount); data.addProperty("onlineMode", onlineMode); data.addProperty("minecraftVersion", minecraftVersion); data.addProperty("spongeImplementation", spongeImplementation); data.addProperty("javaVersion", javaVersion); data.addProperty("osName", osName); data.addProperty("osArch", osArch); data.addProperty("osVersion", osVersion); data.addProperty("coreCount", coreCount); return data; }
Example #12
Source File: Metrics2.java From bStats-Metrics with GNU Lesser General Public License v3.0 | 5 votes |
/** * Gets the server specific data. * * @return The server specific data. */ private JsonObject getServerData() { // Minecraft specific data int playerAmount = Math.min(Sponge.getServer().getOnlinePlayers().size(), 200); int onlineMode = Sponge.getServer().getOnlineMode() ? 1 : 0; String minecraftVersion = Sponge.getGame().getPlatform().getMinecraftVersion().getName(); String spongeImplementation = Sponge.getPlatform().getContainer(Platform.Component.IMPLEMENTATION).getName(); // OS/Java specific data String javaVersion = System.getProperty("java.version"); String osName = System.getProperty("os.name"); String osArch = System.getProperty("os.arch"); String osVersion = System.getProperty("os.version"); int coreCount = Runtime.getRuntime().availableProcessors(); JsonObject data = new JsonObject(); data.addProperty("serverUUID", serverUUID); data.addProperty("playerAmount", playerAmount); data.addProperty("onlineMode", onlineMode); data.addProperty("minecraftVersion", minecraftVersion); data.addProperty("spongeImplementation", spongeImplementation); data.addProperty("javaVersion", javaVersion); data.addProperty("osName", osName); data.addProperty("osArch", osArch); data.addProperty("osVersion", osVersion); data.addProperty("coreCount", coreCount); return data; }
Example #13
Source File: Metrics.java From VirtualChest with GNU Lesser General Public License v3.0 | 5 votes |
/** * Gets the server specific data. * * @return The server specific data. */ private JsonObject getServerData() { // Minecraft specific data int playerAmount = Sponge.getServer().getOnlinePlayers().size(); playerAmount = Math.min(playerAmount, 200); int onlineMode = Sponge.getServer().getOnlineMode() ? 1 : 0; String minecraftVersion = Sponge.getGame().getPlatform().getMinecraftVersion().getName(); String spongeImplementation = Sponge.getPlatform().getContainer(Platform.Component.IMPLEMENTATION).getName(); // OS/Java specific data String javaVersion = System.getProperty("java.version"); String osName = System.getProperty("os.name"); String osArch = System.getProperty("os.arch"); String osVersion = System.getProperty("os.version"); int coreCount = Runtime.getRuntime().availableProcessors(); JsonObject data = new JsonObject(); data.addProperty("serverUUID", serverUUID); data.addProperty("playerAmount", playerAmount); data.addProperty("onlineMode", onlineMode); data.addProperty("minecraftVersion", minecraftVersion); data.addProperty("spongeImplementation", spongeImplementation); data.addProperty("javaVersion", javaVersion); data.addProperty("osName", osName); data.addProperty("osArch", osArch); data.addProperty("osVersion", osVersion); data.addProperty("coreCount", coreCount); return data; }
Example #14
Source File: VirtualChestPlugin.java From VirtualChest with GNU Lesser General Public License v3.0 | 5 votes |
private void addMetricsInformation() { PluginContainer p = Sponge.getPlatform().getContainer(Platform.Component.IMPLEMENTATION); this.metrics.addCustomChart( new Metrics.SingleLineChart("onlineInventories", () -> this.dispatcher.ids().size())); this.metrics.addCustomChart( new Metrics.AdvancedPie("placeholderapiVersion", () -> ImmutableMap.of(this.placeholderManager.getPlaceholderAPIVersion(), 1))); this.metrics.addCustomChart( new Metrics.DrilldownPie("platformImplementation", () -> ImmutableMap.of(p.getName(), ImmutableMap.of(p.getVersion().orElse("unknown"), 1)))); }
Example #15
Source File: SpongePlatformInfo.java From spark with GNU General Public License v3.0 | 4 votes |
@Override public String getVersion() { return this.game.getPlatform().getContainer(Platform.Component.IMPLEMENTATION).getVersion().orElse("unknown"); }
Example #16
Source File: Stats.java From UltimateCore with MIT License | 4 votes |
public static HashMap<String, Object> collect() { final HashMap<String, Object> data = new HashMap<>(); data.put("serverid", ServerID.getUUID()); data.put("statsversion", 1); data.put("apitype", Sponge.getPlatform().getContainer(Platform.Component.API).getName().toLowerCase()); data.put("apiversion", Sponge.getPlatform().getContainer(Platform.Component.API).getVersion().orElse("Not Available")); data.put("implname", Sponge.getPlatform().getContainer(Platform.Component.IMPLEMENTATION).getName().toLowerCase()); data.put("implversion", Sponge.getPlatform().getContainer(Platform.Component.IMPLEMENTATION).getVersion().orElse("Not Available")); data.put("servertype", Sponge.getPlatform().getType().isServer() ? "server" : "client"); data.put("mcversion", Sponge.getPlatform().getMinecraftVersion().getName()); data.put("ucversion", Sponge.getPluginManager().fromInstance(UltimateCore.get()).get().getVersion().orElse("Not Available")); data.put("playersonline", Sponge.getServer().getOnlinePlayers().size()); data.put("worldsloaded", Sponge.getServer().getWorlds().size()); data.put("osname", System.getProperty("os.name")); data.put("osarch", System.getProperty("os.arch").contains("64") ? 64 : 32); data.put("osversion", System.getProperty("os.version")); data.put("cores", Runtime.getRuntime().availableProcessors()); data.put("maxram", Runtime.getRuntime().maxMemory()); data.put("freeram", Runtime.getRuntime().freeMemory()); data.put("onlinemode", Sponge.getServer().getOnlineMode()); data.put("javaversion", System.getProperty("java.version")); data.put("modules", StringUtil.join(", ", UltimateCore.get().getModuleService().getModules().stream().map(Module::getIdentifier).collect(Collectors.toList()))); data.put("language", UltimateCore.get().getGeneralConfig().get().getNode("language", "language").getString("EN_US")); //Plugins StringBuilder pluginbuilder = new StringBuilder(); for (PluginContainer plugin : Sponge.getPluginManager().getPlugins()) { pluginbuilder.append("\n" + plugin.getId() + " / " + plugin.getName() + " / " + plugin.getVersion().orElse("Not Available")); } data.put("plugins", pluginbuilder.toString()); //Permissions plugin Optional<ProviderRegistration<PermissionService>> permplugin = Sponge.getServiceManager().getRegistration(PermissionService.class); if (permplugin.isPresent()) { data.put("permissionsplugin", permplugin.get().getPlugin().getId() + " / " + permplugin.get().getPlugin().getName() + " / " + permplugin.get().getPlugin().getVersion().orElse("Not Available")); } else { data.put("permissionsplugin", "None"); } //Economy plugin Optional<ProviderRegistration<EconomyService>> economyplugin = Sponge.getServiceManager().getRegistration(EconomyService.class); if (economyplugin.isPresent()) { data.put("economyplugin", economyplugin.get().getPlugin().getId() + " / " + economyplugin.get().getPlugin().getName() + " / " + economyplugin.get().getPlugin().getVersion().orElse("Not Available")); } else { data.put("economyplugin", "None"); } //Return return data; }
Example #17
Source File: SpongePluginMessagingForwardingSink.java From NuVotifier with GNU General Public License v3.0 | 4 votes |
public SpongePluginMessagingForwardingSink(NuVotifier p, String channel, ForwardedVoteListener listener) { super(listener); this.channelBinding = Sponge.getChannelRegistrar().createRawChannel(p, channel); this.channelBinding.addListener(Platform.Type.SERVER, this); this.p = p; }
Example #18
Source File: SpongePlugin.java From ServerListPlus with GNU General Public License v3.0 | 4 votes |
@Override public String getServerImplementation() { Platform platform = game.getPlatform(); return platform.getContainer(IMPLEMENTATION).getName() + " v" + platform.getContainer(IMPLEMENTATION).getVersion().orElse("UNKNOWN") + " (" + platform.getContainer(API).getName() + " v" + platform.getContainer(API).getVersion().orElse("UNKNOWN") + ')'; }
Example #19
Source File: WebAPI.java From Web-API with MIT License | 4 votes |
@Listener public void onPreInitialization(GamePreInitializationEvent event) { WebAPI.instance = this; Timings.STARTUP.startTiming(); 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")); // Create our config directory if it doesn't exist if (!Files.exists(configPath)) { try { Files.createDirectories(configPath); } catch (IOException e) { e.printStackTrace(); } } // Reusable sync executor to run code on main server thread syncExecutor = Sponge.getScheduler().createSyncExecutor(this); asyncExecutor = Sponge.getScheduler().createAsyncExecutor(this); // Register custom serializers TypeSerializers.getDefaultSerializers().registerType( TypeToken.of(WebHook.class), new WebHookSerializer()); TypeSerializers.getDefaultSerializers().registerType( TypeToken.of(UserPermissionStruct.class), new UserPermissionStructSerializer()); TypeSerializers.getDefaultSerializers().registerType( TypeToken.of(PermissionStruct.class), new PermissionStructSerializer()); // Setup services this.blockService = new BlockService(); this.cacheService = new CacheService(); this.linkService = new LinkService(); this.messageService = new InteractiveMessageService(); this.securityService = new SecurityService(); this.serializeService = new SerializeService(); this.serverService = new ServerService(); this.servletService = new ServletService(); this.webHookService = new WebHookService(); this.userService = new UserService(); // Register services ServiceManager serviceMan = Sponge.getServiceManager(); serviceMan.setProvider(this, BlockService.class, blockService); serviceMan.setProvider(this, CacheService.class, cacheService); serviceMan.setProvider(this, LinkService.class, linkService); serviceMan.setProvider(this, InteractiveMessageService.class, messageService); serviceMan.setProvider(this, SecurityService.class, securityService); serviceMan.setProvider(this, SerializeService.class, serializeService); serviceMan.setProvider(this, ServerService.class, serverService); serviceMan.setProvider(this, ServletService.class, servletService); serviceMan.setProvider(this, WebHookService.class, webHookService); serviceMan.setProvider(this, UserService.class, userService); // Register events of services EventManager evenMan = Sponge.getEventManager(); evenMan.registerListeners(this, cacheService); evenMan.registerListeners(this, linkService); evenMan.registerListeners(this, webHookService); // Swagger setup stuff ModelConverters.getInstance().addConverter(new SwaggerModelConverter()); Timings.STARTUP.stopTiming(); }
Example #20
Source File: PluginMessageMessenger.java From LuckPerms with MIT License | 4 votes |
@Override public void handlePayload(@NonNull ChannelBuf buf, @NonNull RemoteConnection connection, Platform.@NonNull Type type) { String msg = buf.readUTF(); this.consumer.consumeIncomingMessageAsString(msg); }
Example #21
Source File: PluginMessageMessenger.java From LuckPerms with MIT License | 4 votes |
public void init() { this.channel = this.plugin.getBootstrap().getGame().getChannelRegistrar().createRawChannel(this.plugin.getBootstrap(), CHANNEL); this.channel.addListener(Platform.Type.SERVER, this); }
Example #22
Source File: LPSpongeBootstrap.java From LuckPerms with MIT License | 4 votes |
@Override public String getServerVersion() { PluginContainer api = this.game.getPlatform().getContainer(Platform.Component.API); PluginContainer impl = this.game.getPlatform().getContainer(Platform.Component.IMPLEMENTATION); return api.getName() + ": " + api.getVersion().orElse("null") + " - " + impl.getName() + ": " + impl.getVersion().orElse("null"); }
Example #23
Source File: LPSpongeBootstrap.java From LuckPerms with MIT License | 4 votes |
@Override public String getServerBrand() { return this.game.getPlatform().getContainer(Platform.Component.IMPLEMENTATION).getName(); }
Example #24
Source File: LPSpongeBootstrap.java From LuckPerms with MIT License | 4 votes |
@Override public net.luckperms.api.platform.Platform.Type getType() { return net.luckperms.api.platform.Platform.Type.SPONGE; }