Search in sources :

Example 1 with ServerboundResourcePackPacketAccessor

use of org.spongepowered.common.accessor.network.protocol.game.ServerboundResourcePackPacketAccessor in project SpongeCommon by SpongePowered.

the class ResourcePackState method unwind.

@Override
public void unwind(BasicPacketContext phaseContext) {
    final net.minecraft.server.level.ServerPlayer player = phaseContext.getPacketPlayer();
    final ServerGamePacketListenerImpl connection = player.connection;
    final ServerGamePacketListenerImplBridge mixinHandler = (ServerGamePacketListenerImplBridge) connection;
    final ServerboundResourcePackPacketAccessor resource = phaseContext.getPacket();
    final ResourcePackStatusEvent.ResourcePackStatus status;
    ResourcePack pack;
    switch(resource.accessor$action()) {
        case ACCEPTED:
            pack = mixinHandler.bridge$popReceivedResourcePack(true);
            status = ResourcePackStatusEvent.ResourcePackStatus.ACCEPTED;
            break;
        case DECLINED:
            pack = mixinHandler.bridge$popReceivedResourcePack(false);
            status = ResourcePackStatusEvent.ResourcePackStatus.DECLINED;
            break;
        case SUCCESSFULLY_LOADED:
            pack = mixinHandler.bridge$popAcceptedResourcePack();
            status = ResourcePackStatusEvent.ResourcePackStatus.SUCCESSFULLY_LOADED;
            break;
        case FAILED_DOWNLOAD:
            pack = mixinHandler.bridge$popAcceptedResourcePack();
            status = ResourcePackStatusEvent.ResourcePackStatus.FAILED;
            break;
        default:
            throw new AssertionError();
    }
    if (pack == null) {
        return;
    }
    SpongeCommon.post(SpongeEventFactory.createResourcePackStatusEvent(PhaseTracker.getCauseStackManager().currentCause(), pack, (ServerPlayer) player, status));
}
Also used : ResourcePack(org.spongepowered.api.resourcepack.ResourcePack) ServerPlayer(org.spongepowered.api.entity.living.player.server.ServerPlayer) ServerGamePacketListenerImplBridge(org.spongepowered.common.bridge.server.network.ServerGamePacketListenerImplBridge) ServerboundResourcePackPacketAccessor(org.spongepowered.common.accessor.network.protocol.game.ServerboundResourcePackPacketAccessor) ServerGamePacketListenerImpl(net.minecraft.server.network.ServerGamePacketListenerImpl) ResourcePackStatusEvent(org.spongepowered.api.event.entity.living.player.ResourcePackStatusEvent)

Aggregations

ServerGamePacketListenerImpl (net.minecraft.server.network.ServerGamePacketListenerImpl)1 ServerPlayer (org.spongepowered.api.entity.living.player.server.ServerPlayer)1 ResourcePackStatusEvent (org.spongepowered.api.event.entity.living.player.ResourcePackStatusEvent)1 ResourcePack (org.spongepowered.api.resourcepack.ResourcePack)1 ServerboundResourcePackPacketAccessor (org.spongepowered.common.accessor.network.protocol.game.ServerboundResourcePackPacketAccessor)1 ServerGamePacketListenerImplBridge (org.spongepowered.common.bridge.server.network.ServerGamePacketListenerImplBridge)1