本文整理汇总了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();
}
}
示例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();
}
示例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()));
}
示例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);
}