当前位置: 首页>>代码示例>>Java>>正文


Java Server类代码示例

本文整理汇总了Java中org.spongepowered.api.Server的典型用法代码示例。如果您正苦于以下问题:Java Server类的具体用法?Java Server怎么用?Java Server使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Server类属于org.spongepowered.api包,在下文中一共展示了Server类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getInfo

import org.spongepowered.api.Server; //导入依赖的package包/类
@Endpoint(method = HttpMethod.GET, path = "/", perm = "get")
public void getInfo(ServletData data) {
    Optional<Boolean> optRes = WebAPI.runOnMain(() -> {
        Server server = Sponge.getServer();
        Platform platform = Sponge.getPlatform();

        data.addData("motd", server.getMotd().toPlain(), false);
        data.addData("players", server.getOnlinePlayers().size(), false);
        data.addData("maxPlayers", server.getMaxPlayers(), false);
        data.addData("address", server.getBoundAddress().map(Object::toString).orElse(null), false);
        data.addData("onlineMode", server.getOnlineMode(), false);
        data.addData("resourcePack", server.getDefaultResourcePack().orElse(null), false);
        data.addData("hasWhitelist", server.hasWhitelist(), false);

        data.addData("uptimeTicks", server.getRunningTimeTicks(), false);
        data.addData("tps", server.getTicksPerSecond(), false);
        data.addData("minecraftVersion", platform.getMinecraftVersion().getName(), false);

        data.addData("game", platform.getContainer(Platform.Component.GAME), true);
        data.addData("api", platform.getContainer(Platform.Component.API), true);
        data.addData("implementation", platform.getContainer(Platform.Component.IMPLEMENTATION), true);
        return true;
    });

    data.addData("ok", optRes.orElse(false), false);
}
 
开发者ID:Valandur,项目名称:Web-API,代码行数:27,代码来源:InfoServlet.java

示例2: toJson

import org.spongepowered.api.Server; //导入依赖的package包/类
@Override
public void toJson(Server object, SerializerManager serializerManager, JSONWriter writer) {
    writer.object()
            .key("maxPlayers").value(object.getMaxPlayers())
            .key("port").value(object.getBoundAddress().map(InetSocketAddress::getPort).orElse(-1))
            .key("ip").value(object.getBoundAddress().map(InetSocketAddress::getAddress).map(InetAddress::getHostAddress).orElse(""));

    writer.key("players");
    serializerManager.serialize(object.getOnlinePlayers(), writer);

    writer.key("worlds");
    serializerManager.serialize(object.getWorlds(), writer);

    writer
            .key("motd").value(object.getMotd().toPlain())
            .endObject();
}
 
开发者ID:UniversalMinecraftAPI,项目名称:UniversalMinecraftAPI,代码行数:18,代码来源:ServerSerializer.java

示例3: hookChannels

import org.spongepowered.api.Server; //导入依赖的package包/类
@Listener
public void hookChannels(GameInitializationEvent event) {
    Game game = event.getGame();
    Server server = game.getServer();
    Method getNetworkSystem = null;
    for (Method m : server.getClass().getMethods()) {
        if ("net.minecraft.network.NetworkSystem".equals(m.getReturnType().getName())) {
            getNetworkSystem = m;
        }
    }
    if (getNetworkSystem == null) {
        throw new RuntimeException("Could not find getNetworkSystem in " + server);
    }
    try {
        Object networkSystem = getNetworkSystem.invoke(server);
        SpongeChannelInitializer channelInitializer = new SpongeChannelInitializer(game);
        @SuppressWarnings("unchecked")
        List<ChannelFuture> endpoints = (List) Reflection.getField(networkSystem.getClass(), "field_151274_e", networkSystem);
        for (ChannelFuture endpoint : endpoints) {
            endpoint.channel().pipeline().addFirst(channelInitializer);
        }
    } catch (IllegalAccessException | NoSuchFieldException | InvocationTargetException e) {
        e.printStackTrace();
    }
}
 
开发者ID:ReplayMod,项目名称:SpongeRecording,代码行数:26,代码来源:SpongeImplementation.java

示例4: saveall

import org.spongepowered.api.Server; //导入依赖的package包/类
@Alias(value = "save-all")
@Command(desc = "Saves all or a specific world to disk.")
public void saveall(CommandSource context, @Optional World world)
{
    i18n.send(context, NEUTRAL, "Saving...");
    Server server = Sponge.getServer();
    if (world != null)
    {
        server.saveWorldProperties(world.getProperties()); // TODO is this saving the world?
        // TODO world.getEntities().stream().filter(entity -> entity instanceof Player).forEach(player -> player.saveData());
        i18n.send(context, POSITIVE, "World {world} has been saved to disk!", world);
        return;
    }
    Profiler.startProfiling("save-worlds");
    for (World aWorld : server.getWorlds())
    {
        server.saveWorldProperties(aWorld.getProperties()); // TODO is this saving the world?
    }
    // TODO this.core.getServer().savePlayers();
    i18n.send(context, POSITIVE, "All worlds have been saved to disk!");
    i18n.send(context, POSITIVE, "The saving took {integer#time} milliseconds.", Profiler.endProfiling("save-worlds", MILLISECONDS));
}
 
开发者ID:CubeEngine,项目名称:modules-main,代码行数:23,代码来源:SaveCommands.java

示例5: resolveServerVariable

import org.spongepowered.api.Server; //导入依赖的package包/类
private String resolveServerVariable(Server server, DataKey<String> key) {
    apiLock.readLock().lock();
    try {
        ServerVariable variable = serverVariablesByName.get(key.getParameter());
        if (variable != null) {
            String replacement = null;
            try {
                replacement = variable.getReplacement();
            } catch (Throwable th) {
                logger.warn("An exception occurred while resolving a variable provided by a third party plugin", th);
            }
            return replacement;
        }
        return null;
    } finally {
        apiLock.readLock().unlock();
    }
}
 
开发者ID:CodeCrafter47,项目名称:BungeeTabListPlus,代码行数:19,代码来源:SpongePlugin.java

示例6: getSourceName

import org.spongepowered.api.Server; //导入依赖的package包/类
public static String getSourceName(String source, Server server) {
	if (source.length() == EServer.UUID_LENGTH) {
		try {
			Optional<Player> player = server.getPlayer(UUID.fromString(source));
			if (player.isPresent()) {
				return player.get().getName();
			}
		} catch(IllegalArgumentException e) {}
	}
	return source;
}
 
开发者ID:EverCraft,项目名称:EverAPI,代码行数:12,代码来源:Sanction.java

示例7: getPardonSourceName

import org.spongepowered.api.Server; //导入依赖的package包/类
public default Optional<String> getPardonSourceName(Server server) {
	if (this.getSource().length() == EServer.UUID_LENGTH) {
		try {
			Optional<Player> player = server.getPlayer(UUID.fromString(this.getSource()));
			if (player.isPresent()) {
				return  Optional.of(player.get().getName());
			}
		} catch(IllegalArgumentException e) {}
	}
	return Optional.of(this.getSource());
}
 
开发者ID:EverCraft,项目名称:EverAPI,代码行数:12,代码来源:Sanction.java

示例8: FileNewsRepository

import org.spongepowered.api.Server; //导入依赖的package包/类
public FileNewsRepository(File file, TextSerializer textSerializer, Server server, UserStorageService userStorageService) throws IOException {
    super();
    this.file = file;
    this.server = server;
    this.textSerializer = textSerializer;
    this.userStorageService = userStorageService;
    this.allNews = load();
}
 
开发者ID:vorburger,项目名称:ch.vorburger.minecraft.osgi,代码行数:9,代码来源:FileNewsRepository.java

示例9: fileNewsRepository

import org.spongepowered.api.Server; //导入依赖的package包/类
private FileNewsRepository fileNewsRepository() throws IOException {
    // TODO move somewhere else
    Server mockServer = Mockito.mock(Server.class /* TODO , MoreAnswers.exception() */);
    UserStorageService mockUserStorageService = Mockito.mock(UserStorageService.class /* TODO , MoreAnswers.exception() */);
    Mockito.when(mockUserStorageService.get(Mockito.any(UUID.class))).thenReturn(Optional.of(mockUser));
    return new FileNewsRepository(FILE, newTestTextSerializer(), mockServer, mockUserStorageService);
}
 
开发者ID:vorburger,项目名称:ch.vorburger.minecraft.osgi,代码行数:8,代码来源:NewsRepositoryTest.java

示例10: registerSerializers

import org.spongepowered.api.Server; //导入依赖的package包/类
private void registerSerializers() {
    uma.getSerializerManager().registerSerializer(CatalogType.class, new CatalogTypeSerializer());
    uma.getSerializerManager().registerSerializer(Dimension.class, new DimensionSerializer());
    uma.getSerializerManager().registerSerializer(Location.class, new LocationSerializer());
    uma.getSerializerManager().registerSerializer(Player.class, new PlayerSerializer());
    uma.getSerializerManager().registerSerializer(Transform.class, new TransformSerializer());
    uma.getSerializerManager().registerSerializer(Server.class, new ServerSerializer());
    uma.getSerializerManager().registerSerializer(World.class, new WorldSerializer());
}
 
开发者ID:UniversalMinecraftAPI,项目名称:UniversalMinecraftAPI,代码行数:10,代码来源:SpongeUniversalMinecraftAPI.java

示例11: execute

import org.spongepowered.api.Server; //导入依赖的package包/类
public CommandResult execute(CommandSource src, CommandContext ctx) throws CommandException
{
	Game game = EssentialCmds.getEssentialCmds().getGame();
	Server server = game.getServer();
	Player player = ctx.<Player> getOne("player").get();
	Optional<String> reason = ctx.<String> getOne("reason");

	if (server.getPlayer(player.getUniqueId()).isPresent())
	{
		Text finalKickMessage = Text.of(TextColors.GOLD, src.getName() + " kicked " + player.getName());

		if (reason.isPresent())
		{
			Text reas = TextSerializers.formattingCode('&').deserialize(reason.get());
			Text kickMessage = Text.of(TextColors.GOLD, src.getName() + " kicked " + player.getName() + " for ", TextColors.RED);
			finalKickMessage = Text.builder().append(kickMessage).append(reas).build();
			player.kick(reas);
		}
		else
		{
			player.kick();
		}

		MessageChannel.TO_ALL.send(finalKickMessage);
		src.sendMessage(Text.of(TextColors.GREEN, "Success! ", TextColors.YELLOW, "Player kicked."));
	}
	else
	{
		src.sendMessage(Text.of(TextColors.DARK_RED, "Error! ", TextColors.RED, "Player doesn't appear to be online!"));
	}

	return CommandResult.success();
}
 
开发者ID:hsyyid,项目名称:EssentialCmds,代码行数:34,代码来源:KickExecutor.java

示例12: executeAsync

import org.spongepowered.api.Server; //导入依赖的package包/类
@Override
public void executeAsync(CommandSource src, CommandContext args)
{
	Game game = EssentialCmds.getEssentialCmds().getGame();
	Server server = game.getServer();
	src.sendMessage(Text.of(TextColors.GOLD, "[MOTD]: ", server.getMotd()));
}
 
开发者ID:hsyyid,项目名称:EssentialCmds,代码行数:8,代码来源:MotdExecutor.java

示例13: onReload

import org.spongepowered.api.Server; //导入依赖的package包/类
public void onReload() {
    //run this task sync in order let it finish before the process ends
    database.close();

    Server server = Sponge.getServer();
    server.getOnlinePlayers().forEach(protectionManager::unprotect);

    init();

    server.getOnlinePlayers().stream()
            .peek(protectionManager::protect)
            .forEach(database::loadAccount);
}
 
开发者ID:games647,项目名称:FlexibleLogin,代码行数:14,代码来源:FlexibleLogin.java

示例14: getPlayer

import org.spongepowered.api.Server; //导入依赖的package包/类
public static Player getPlayer(CommandSource src, VirtualTool vt) {
    final Server server = vt.getGame().getServer();
    return server.getPlayer(((Player) src.getCommandSource().get()).getUniqueId()).get();
}
 
开发者ID:poqdavid,项目名称:VirtualTool,代码行数:5,代码来源:Tools.java

示例15: getPlayerE

import org.spongepowered.api.Server; //导入依赖的package包/类
public static EntityPlayerMP getPlayerE(CommandSource src, VirtualTool vt) {
    final Server server = vt.getGame().getServer();
    return (EntityPlayerMP) server.getPlayer(((Player) src.getCommandSource().get()).getUniqueId()).get();
}
 
开发者ID:poqdavid,项目名称:VirtualTool,代码行数:5,代码来源:Tools.java


注:本文中的org.spongepowered.api.Server类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。