use of org.spongepowered.api.ResourceKey in project SpongeCommon by SpongePowered.
the class SpongeChannelManager method handleLoginRequestPayload.
private boolean handleLoginRequestPayload(final EngineConnection connection, final ResourceKey channelKey, final int transactionId, final ChannelBuf payload) {
if (channelKey.equals(Constants.Channels.SPONGE_CLIENT_TYPE)) {
final ClientType clientType = ((MinecraftBridge) Sponge.client()).bridge$getClientType();
final ChannelBuf responsePayload = this.bufferAllocator.buffer();
responsePayload.writeString(clientType.getName());
final Packet<?> mcPacket = PacketUtil.createLoginPayloadResponse(responsePayload, transactionId);
PacketSender.sendTo(connection, mcPacket);
return true;
}
if (channelKey.equals(Constants.Channels.SPONGE_CHANNEL_REGISTRY)) {
this.handleChannelRegistry(connection, payload);
// Respond with registered channels
final ChannelBuf responsePayload = this.encodeChannelRegistry();
final Packet<?> mcPacket = PacketUtil.createLoginPayloadResponse(responsePayload, transactionId);
PacketSender.sendTo(connection, mcPacket);
return true;
}
ResourceKey actualChannelKey = channelKey;
ChannelBuf actualPayload = payload;
if (channelKey.equals(Constants.Channels.FML_LOGIN_WRAPPER_CHANNEL)) {
actualChannelKey = ResourceKey.resolve(payload.readString());
final int length = payload.readVarInt();
actualPayload = payload.readSlice(length);
}
final SpongeChannel channel = this.channels.get(actualChannelKey);
if (channel != null) {
channel.handleLoginRequestPayload(connection, transactionId, actualPayload);
return true;
}
return false;
}
use of org.spongepowered.api.ResourceKey in project SpongeCommon by SpongePowered.
the class SpongeChannelManager method handleLoginRequestPayload.
public boolean handleLoginRequestPayload(final EngineConnection connection, final ClientboundCustomQueryPacket packet) {
// Server -> Client request
final ClientboundCustomQueryPacketAccessor accessor = (ClientboundCustomQueryPacketAccessor) packet;
final ResourceKey channel = (ResourceKey) (Object) accessor.accessor$identifier();
final int transactionId = accessor.accessor$transactionId();
final ChannelBuf payload = (ChannelBuf) accessor.accessor$data();
try {
return this.handleLoginRequestPayload(connection, channel, transactionId, payload);
} finally {
ChannelBuffers.release(payload);
}
}
use of org.spongepowered.api.ResourceKey in project SpongeCommon by SpongePowered.
the class SpongeChannelManager method handlePlayPayload.
public boolean handlePlayPayload(final EngineConnection connection, final ClientboundCustomPayloadPacket packet) {
final ClientboundCustomPayloadPacketAccessor accessor = (ClientboundCustomPayloadPacketAccessor) packet;
final ResourceKey channel = (ResourceKey) (Object) accessor.accessor$identifier();
final ChannelBuf payload = (ChannelBuf) accessor.accessor$data();
return this.handlePlayPayload(connection, channel, payload);
}
use of org.spongepowered.api.ResourceKey in project SpongeCommon by SpongePowered.
the class SpongePlaceholderContextBuilder method associatedObject.
@Override
@SuppressWarnings("unchecked")
public PlaceholderContext.Builder associatedObject(@Nullable final Object associatedObject) {
if (associatedObject == null) {
this.associatedObjectSupplier = null;
} else if (associatedObject instanceof Supplier) {
return this.associatedObject((Supplier<Object>) associatedObject);
} else if (associatedObject instanceof SystemSubject) {
this.associatedObjectSupplier = Sponge::systemSubject;
} else if (associatedObject instanceof Server) {
this.associatedObjectSupplier = Sponge::server;
} else if (associatedObject instanceof Player) {
return this.associatedObject((Player) associatedObject);
} else if (associatedObject instanceof ServerWorld) {
final ResourceKey key = ((ServerWorld) associatedObject).key();
this.associatedObjectSupplier = () -> SpongeCommon.game().server().worldManager().world(key).orElse(null);
} else if (associatedObject instanceof Entity) {
final Entity entity = ((Entity) associatedObject);
final ResourceKey key = entity.serverLocation().world().key();
final UUID entityUuid = ((Entity) associatedObject).uniqueId();
this.associatedObjectSupplier = () -> SpongeCommon.game().server().worldManager().world(key).flatMap(x -> x.entity(entityUuid)).orElse(null);
} else {
// We create a weak reference here so we don't hold on to game objects.
final WeakReference<Object> objectWeakReference = new WeakReference<>(associatedObject);
this.associatedObjectSupplier = objectWeakReference::get;
}
return this;
}
use of org.spongepowered.api.ResourceKey in project SpongeCommon by SpongePowered.
the class MappedRegistryMixin method impl$cacheRegistryEntry.
@Inject(method = "registerMapping(ILnet/minecraft/resources/ResourceKey;Ljava/lang/Object;Lcom/mojang/serialization/Lifecycle;Z)Ljava/lang/Object;", at = @At("TAIL"))
private void impl$cacheRegistryEntry(final int p_243537_1_, final net.minecraft.resources.ResourceKey<T> p_243537_2_, final T p_243537_3_, final Lifecycle p_243537_4_, final boolean p_243537_5_, final CallbackInfoReturnable<T> cir) {
final net.minecraft.resources.ResourceKey<? extends Registry<T>> resourceKey = this.shadow$key();
final ResourceKey root = (ResourceKey) (Object) ((ResourceKeyAccessor<T>) resourceKey).accessor$registryName();
final ResourceKey location = (ResourceKey) (Object) resourceKey.location();
this.bridge$register(new SpongeRegistryEntry<>(new SpongeRegistryType<>(root, location), (ResourceKey) (Object) p_243537_2_.location(), p_243537_3_));
}
Aggregations