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


Java Platform类代码示例

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


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

示例1: validateSpongeVersion

import org.spongepowered.api.Platform; //导入依赖的package包/类
private boolean validateSpongeVersion() {
	PluginContainer container = Sponge.getPlatform().getContainer(Platform.Component.IMPLEMENTATION);
	if (container.getName().equals("SpongeForge")) {
		try {
			String version = container.getVersion().orElseThrow(Exception::new);
			version = version.substring(Math.max(version.length() - 4, 0));
			int spongeVersion = Integer.parseInt(version);
			if (spongeVersion < 2132) {
				this.logger.error(String.format("Failed to initialize StickyChunk due to outdated SpongeForge (%s). StickyChunk requires SF 2132+", spongeVersion));
				return false;
			}
		} catch (Exception ignored) {
		}
	}
	return true;
}
 
开发者ID:DevOnTheRocks,项目名称:StickyChunk,代码行数:17,代码来源:StickyChunk.java

示例2: getInfo

import org.spongepowered.api.Platform; //导入依赖的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

示例3: register

import org.spongepowered.api.Platform; //导入依赖的package包/类
private <M extends Message> void register(Class<M> messageClass, int messageId, @Nullable Platform.Type side,
        @Nullable MessageHandler<M> handler) {
    checkNotNull(messageClass, "messageClass");
    checkArgument(messageId >= 0 && messageId <= 255, "MessageId (%s) must scale between 0 and 255", messageId);
    final byte messageId0 = (byte) messageId;
    if (side == null) {
        validate(messageClass, messageId0, Platform.Type.CLIENT);
        validate(messageClass, messageId0, Platform.Type.SERVER);
    } else {
        checkArgument(side.isKnown(), "Platform side must be known");
        validate(messageClass, messageId0, side);
    }
    final IndexedMessageRegistration registration = new IndexedMessageRegistration(messageClass);
    registration.opcode = messageId0;
    if (handler != null) {
        registration.handlers.add(handler);
    }
    if (side == null) {
        applyRegistration(getRegistrations(Platform.Type.CLIENT), messageClass, messageId0, handler);
        applyRegistration(getRegistrations(Platform.Type.SERVER), messageClass, messageId0, handler);
    } else {
        applyRegistration(getRegistrations(side), messageClass, messageId0, handler);
    }
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:25,代码来源:LanternIndexedMessageChannel.java

示例4: validate

import org.spongepowered.api.Platform; //导入依赖的package包/类
private void validate(Class<? extends Message> messageClass, byte messageId, Platform.Type side) {
    Constructor<?> constructor = null;
    try {
        constructor = messageClass.getConstructor();
    } catch (NoSuchMethodException ignored) {
    } catch (SecurityException e) {
        throw new RuntimeException(e);
    }
    checkState(constructor != null, "%s is missing a empty public constructor", messageClass.getName());
    final RegistrationLookup registrations = getRegistrations(Platform.Type.CLIENT);
    checkState(!registrations.classToRegistration.containsKey(messageClass) ||
            registrations.classToRegistration.get(messageClass).opcode == null,
            "MessageClass (%s) is already registered on the %s side!",
            messageClass.getName(), side.name().toLowerCase());
    checkState(!registrations.opcodeToRegistration.containsKey(messageId),
            "MessageId (%s) is already registered on the %s side! For %s",
            messageId, side.name().toLowerCase(), registrations.opcodeToRegistration.get(messageId).messageType.getName());
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:19,代码来源:LanternIndexedMessageChannel.java

示例5: completeSpec

import org.spongepowered.api.Platform; //导入依赖的package包/类
@Override
public void completeSpec(PluginContainer pluginContainer, CommandSpec.Builder specBuilder) {
    specBuilder
            .description(t("commands.version.description"))
            .executor((src, args) -> {
                final Platform platform = Lantern.getGame().getPlatform();
                PluginContainer plugin = platform.getContainer(Platform.Component.GAME);
                src.sendMessage(t("commands.version.minecraft", plugin.getVersion().orElse(UNKNOWN),
                        LanternMinecraftVersion.CURRENT.getProtocol()));
                plugin = platform.getContainer(Platform.Component.IMPLEMENTATION);
                src.sendMessage(t("commands.version.implementation", plugin.getName(), plugin.getVersion().orElse(UNKNOWN)));
                plugin = platform.getContainer(Platform.Component.API);
                src.sendMessage(t("commands.version.api", plugin.getName(), plugin.getVersion().orElse(UNKNOWN)));
                return CommandResult.success();
            });
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:17,代码来源:CommandVersion.java

示例6: onServerAboutToStart

import org.spongepowered.api.Platform; //导入依赖的package包/类
@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();
}
 
开发者ID:CodeCrafter47,项目名称:BungeeTabListPlus,代码行数:23,代码来源:SpongePlugin.java

示例7: getServerData

import org.spongepowered.api.Platform; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:codeHusky,项目名称:HuskyUI-Plugin,代码行数:38,代码来源:Metrics.java

示例8: handlePayload

import org.spongepowered.api.Platform; //导入依赖的package包/类
@Override
public void handlePayload(ChannelBuf data, RemoteConnection connection, Platform.Type side) {
    for (Map.Entry<Predicate<ChannelBuf>, Consumer<ChannelBuf>> entry : map.entrySet()) {
       if (entry.getKey().test(data)) {
           entry.getValue().accept(data);
           map.remove(entry.getKey());
           return;
       }
    }
}
 
开发者ID:pie-flavor,项目名称:SpongyCord,代码行数:11,代码来源:SpongyCord.java

示例9: getServerVersion

import org.spongepowered.api.Platform; //导入依赖的package包/类
@Override
public String getServerVersion() {
    return getGame().getPlatform().getContainer(Platform.Component.API).getName() + ": " +
            getGame().getPlatform().getContainer(Platform.Component.API).getVersion().orElse("null") + " - " +
            getGame().getPlatform().getContainer(Platform.Component.IMPLEMENTATION).getName() + ": " +
            getGame().getPlatform().getContainer(Platform.Component.IMPLEMENTATION).getVersion().orElse("null");
}
 
开发者ID:lucko,项目名称:LuckPerms,代码行数:8,代码来源:LPSpongePlugin.java

示例10: getServerVersion

import org.spongepowered.api.Platform; //导入依赖的package包/类
@Override
protected String getServerVersion() {
    final Platform platform = Sponge.getPlatform();

    StringBuilder result = new StringBuilder();

    result.append(platform.getImplementation().getName());
    platform.getImplementation().getVersion().ifPresent(version -> result.append(' ').append(version));
    result.append(" (MC: ").append(platform.getMinecraftVersion().getName()).append(')');

    return result.toString();
}
 
开发者ID:Minecrell,项目名称:statslite,代码行数:13,代码来源:SpongeStatsLite.java

示例11: handle

import org.spongepowered.api.Platform; //导入依赖的package包/类
@Override
public void handle(NetworkContext context, MessageForgeHandshakeInStart message) {
    final Attribute<ForgeServerHandshakePhase> phase = context.getChannel().attr(ForgeHandshakePhase.PHASE);
    final NetworkSession session = context.getSession();
    if (phase.get() != null && phase.get() != ForgeServerHandshakePhase.START) {
        session.disconnect(t("Retrieved unexpected forge handshake start message."));
        return;
    }
    final boolean fml = session.getChannel().attr(NetworkSession.FML_MARKER).get();

    final Set<String> channels = new HashSet<>(Sponge.getChannelRegistrar()
            .getRegisteredChannels(Platform.Type.SERVER));
    if (fml) {
        channels.add("FML");
        channels.add("FML|HS");
        channels.add("FML|MP");
    }
    if (!channels.isEmpty()) {
        session.send(new MessagePlayInOutRegisterChannels(channels));
    }
    // Disable Forge for now, we need to send the registries and stuff,
    // which isn't actually used. We may also remove the protocol in the
    // future if sponge uses completely it's own protocol.
    if (false && fml) {
        phase.set(ForgeServerHandshakePhase.HELLO);
        session.send(new MessageForgeHandshakeInOutHello());
        Lantern.getLogger().info("{}: Start forge handshake.", session.getGameProfile().getName().get());
    } else {
        Lantern.getLogger().info("{}: Skip forge handshake.", session.getGameProfile().getName().get());
        phase.set(ForgeServerHandshakePhase.DONE);
        session.setProtocolState(ProtocolState.PLAY);
        session.initPlayer();
    }
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:35,代码来源:HandlerForgeHandshakeInStart.java

示例12: addListener

import org.spongepowered.api.Platform; //导入依赖的package包/类
@Override
public void addListener(Platform.Type side, RawDataListener listener) {
    checkNotNull(listener, "listener");
    checkNotNull(side, "side");
    if (side == Platform.Type.SERVER) {
        this.serverDataListeners.add(listener);
    }
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:9,代码来源:LanternRawDataChannel.java

示例13: handlePayload

import org.spongepowered.api.Platform; //导入依赖的package包/类
@Override
void handlePayload(ByteBuffer buf, RemoteConnection connection) {
    for (RawDataListener listener : this.serverDataListeners) {
        // We slice the buffer, to preserve the reader index for all the listeners,
        // the buffer shouldn't be modified in any way
        listener.handlePayload(buf.slice(), connection, Platform.Type.SERVER);
    }
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:9,代码来源:LanternRawDataChannel.java

示例14: getRegistrations

import org.spongepowered.api.Platform; //导入依赖的package包/类
private RegistrationLookup getRegistrations(Platform.Type side) {
    final RegistrationLookup registrations;
    if (this.registrations.containsKey(side)) {
        registrations = this.registrations.get(side);
    } else {
        this.registrations.put(side, registrations = new RegistrationLookup());
    }
    return registrations;
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:10,代码来源:LanternIndexedMessageChannel.java

示例15: encode

import org.spongepowered.api.Platform; //导入依赖的package包/类
private void encode(Message message, ByteBuffer buf) {
    final IndexedMessageRegistration registration = getRegistrations(Platform.Type.SERVER).classToRegistration.get(message.getClass());
    checkArgument(registration != null, "The specified message type %s is not registered", message.getClass().getName());

    final ByteBuffer content = ByteBufferAllocator.unpooled().buffer();
    message.writeTo(content);
    //noinspection ConstantConditions
    buf.writeByte(registration.opcode);
    buf.writeBytes(content);
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:11,代码来源:LanternIndexedMessageChannel.java


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