本文整理匯總了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);
}