本文整理汇总了Java中org.spongepowered.api.Platform.Type方法的典型用法代码示例。如果您正苦于以下问题:Java Platform.Type方法的具体用法?Java Platform.Type怎么用?Java Platform.Type使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.spongepowered.api.Platform
的用法示例。
在下文中一共展示了Platform.Type方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
}
示例2: 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());
}
示例3: 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;
}
}
}
示例4: 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);
}
}
示例5: 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;
}
示例6: handlePayload
import org.spongepowered.api.Platform; //导入方法依赖的package包/类
@Override
public void handlePayload(ChannelBuf channelBuf, RemoteConnection remoteConnection, Platform.Type type) {
try {
String message = new String(channelBuf.array(), StandardCharsets.UTF_8);
JSONObject jsonObject = new JSONObject(message);
Vote v = new Vote(jsonObject);
listener.onForward(v);
} catch (Exception e) {
p.getLogger().error("There was an unknown error when processing a forwarded vote.", e);
}
}
示例7: handlePayload
import org.spongepowered.api.Platform; //导入方法依赖的package包/类
@Override
public void handlePayload(@Nonnull ChannelBuf buf, @Nonnull RemoteConnection connection, @Nonnull Platform.Type type) {
String msg = buf.readUTF();
onMessage(msg, null);
}
示例8: registerMessage
import org.spongepowered.api.Platform; //导入方法依赖的package包/类
@Override
public <M extends Message> void registerMessage(Class<M> messageClass, int messageId, Platform.Type side, MessageHandler<M> handler) {
register(messageClass, messageId, checkNotNull(side, "side"), checkNotNull(handler, "handler"));
}
示例9: addHandler
import org.spongepowered.api.Platform; //导入方法依赖的package包/类
@Override
public <M extends Message> void addHandler(Class<M> messageClass, Platform.Type side, MessageHandler<M> handler) {
applyHandler(getRegistrations(checkNotNull(side, "side")), messageClass, checkNotNull(handler, "handler"));
}
示例10: validateRegistration
import org.spongepowered.api.Platform; //导入方法依赖的package包/类
private void validateRegistration(Class<? extends Message> messageClass, Platform.Type side) {
final IndexedMessageRegistration registration = getRegistrations(side).classToRegistration.get(messageClass);
checkArgument(registration != null && registration.opcode != null,
"%s is not registered on the side: %s", messageClass.getName(), side.name().toLowerCase());
}
示例11: getRegisteredChannels
import org.spongepowered.api.Platform; //导入方法依赖的package包/类
@Override
public Set<String> getRegisteredChannels(Platform.Type side) {
return ImmutableSet.copyOf(this.bindings.keySet());
}