當前位置: 首頁>>代碼示例>>Java>>正文


Java Game.getServer方法代碼示例

本文整理匯總了Java中org.spongepowered.api.Game.getServer方法的典型用法代碼示例。如果您正苦於以下問題:Java Game.getServer方法的具體用法?Java Game.getServer怎麽用?Java Game.getServer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.spongepowered.api.Game的用法示例。


在下文中一共展示了Game.getServer方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: hookChannels

import org.spongepowered.api.Game; //導入方法依賴的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

示例2: execute

import org.spongepowered.api.Game; //導入方法依賴的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

示例3: executeAsync

import org.spongepowered.api.Game; //導入方法依賴的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

示例4: NodeClient

import org.spongepowered.api.Game; //導入方法依賴的package包/類
public NodeClient(ConnectionInfo connectionInfo, Game game){
    this.ci = connectionInfo;
    this.game = game;
    this.gsonBaker = new GsonBaker(game.getServer());
    this.service = new EventService(this, game);
}
 
開發者ID:thomas15v,項目名稱:CrossEvents,代碼行數:7,代碼來源:NodeClient.java


注:本文中的org.spongepowered.api.Game.getServer方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。