Search in sources :

Example 11 with IMixinEntityPlayerMP

use of org.spongepowered.common.interfaces.entity.player.IMixinEntityPlayerMP in project SpongeCommon by SpongePowered.

the class ExperienceLevelValueProcessor method offerToStore.

@Override
public DataTransactionResult offerToStore(ValueContainer<?> container, Integer value) {
    final ImmutableBoundedValue<Integer> newValue = constructImmutableValue(value);
    if (supports(container)) {
        final EntityPlayer player = (EntityPlayer) container;
        final Integer oldValue = player.experienceLevel;
        player.experienceTotal = ExperienceHolderUtils.xpAtLevel(value);
        player.experience = 0;
        player.experienceLevel = value;
        ((IMixinEntityPlayerMP) container).refreshExp();
        final ImmutableBoundedValue<Integer> oldImmutableValue = constructImmutableValue(oldValue);
        return DataTransactionResult.successReplaceResult(newValue, oldImmutableValue);
    }
    return DataTransactionResult.failResult(newValue);
}
Also used : EntityPlayer(net.minecraft.entity.player.EntityPlayer) IMixinEntityPlayerMP(org.spongepowered.common.interfaces.entity.player.IMixinEntityPlayerMP)

Example 12 with IMixinEntityPlayerMP

use of org.spongepowered.common.interfaces.entity.player.IMixinEntityPlayerMP in project SpongeCommon by SpongePowered.

the class PacketUtil method onProcessPacket.

@SuppressWarnings({ "rawtypes", "unchecked", "unused" })
public static void onProcessPacket(Packet packetIn, INetHandler netHandler) {
    if (netHandler instanceof NetHandlerPlayServer) {
        try (CauseStackManager.StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) {
            EntityPlayerMP packetPlayer = ((NetHandlerPlayServer) netHandler).player;
            Sponge.getCauseStackManager().pushCause(packetPlayer);
            // If true, logic was handled in Pre so return
            if (firePreEvents(packetIn, packetPlayer)) {
                return;
            }
            boolean ignoreCreative = false;
            // } else
            if (creativeCheck(packetIn, packetPlayer)) {
                long packetDiff = System.currentTimeMillis() - lastInventoryOpenPacketTimeStamp;
                // If the time between packets is small enough, mark the current packet to be ignored for our event handler.
                if (packetDiff < 100) {
                    ignoreCreative = true;
                }
            }
            // Don't process movement capture logic if player hasn't moved
            boolean ignoreMovementCapture = false;
            if (packetIn instanceof CPacketPlayer) {
                CPacketPlayer movingPacket = ((CPacketPlayer) packetIn);
                if (movingPacket instanceof CPacketPlayer.Rotation) {
                    ignoreMovementCapture = true;
                } else if (packetPlayer.posX == movingPacket.x && packetPlayer.posY == movingPacket.y && packetPlayer.posZ == movingPacket.z) {
                    ignoreMovementCapture = true;
                }
            }
            if (ignoreMovementCapture || (packetIn instanceof CPacketClientSettings)) {
                packetIn.processPacket(netHandler);
            } else {
                final ItemStackSnapshot cursor = ItemStackUtil.snapshotOf(packetPlayer.inventory.getItemStack());
                final PhaseTracker phaseTracker = PhaseTracker.getInstance();
                IPhaseState<? extends PacketContext<?>> packetState = TrackingPhases.PACKET.getStateForPacket(packetIn);
                if (packetState == null) {
                    throw new IllegalArgumentException("Found a null packet phase for packet: " + packetIn.getClass());
                }
                PhaseContext<?> context = EMPTY;
                if (!TrackingPhases.PACKET.isPacketInvalid(packetIn, packetPlayer, packetState)) {
                    context = packetState.createPhaseContext().source(packetPlayer).packetPlayer(packetPlayer).packet(packetIn).cursor(cursor).ignoreCreative(ignoreCreative);
                    TrackingPhases.PACKET.populateContext(packetIn, packetPlayer, packetState, context);
                    context.owner((Player) packetPlayer);
                    context.notifier((Player) packetPlayer);
                }
                try (PhaseContext<?> packetContext = context.buildAndSwitch()) {
                    packetIn.processPacket(netHandler);
                }
                if (packetIn instanceof CPacketClientStatus) {
                    // update the reference of player
                    packetPlayer = ((NetHandlerPlayServer) netHandler).player;
                }
                ((IMixinEntityPlayerMP) packetPlayer).setPacketItem(ItemStack.EMPTY);
            }
        }
    } else {
        // client
        packetIn.processPacket(netHandler);
    }
}
Also used : CPacketClientStatus(net.minecraft.network.play.client.CPacketClientStatus) CPacketPlayer(net.minecraft.network.play.client.CPacketPlayer) IMixinEntityPlayerMP(org.spongepowered.common.interfaces.entity.player.IMixinEntityPlayerMP) NetHandlerPlayServer(net.minecraft.network.NetHandlerPlayServer) PhaseTracker(org.spongepowered.common.event.tracking.PhaseTracker) CauseStackManager(org.spongepowered.api.event.CauseStackManager) ItemStackSnapshot(org.spongepowered.api.item.inventory.ItemStackSnapshot) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) IMixinEntityPlayerMP(org.spongepowered.common.interfaces.entity.player.IMixinEntityPlayerMP) CPacketClientSettings(net.minecraft.network.play.client.CPacketClientSettings)

Aggregations

IMixinEntityPlayerMP (org.spongepowered.common.interfaces.entity.player.IMixinEntityPlayerMP)12 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)5 SPacketEntityEffect (net.minecraft.network.play.server.SPacketEntityEffect)4 PotionEffect (net.minecraft.potion.PotionEffect)4 WorldServer (net.minecraft.world.WorldServer)4 IMixinEntity (org.spongepowered.common.interfaces.entity.IMixinEntity)4 EntityPlayer (net.minecraft.entity.player.EntityPlayer)3 SPacketRespawn (net.minecraft.network.play.server.SPacketRespawn)3 Player (org.spongepowered.api.entity.living.player.Player)3 World (org.spongepowered.api.world.World)3 IMixinWorldServer (org.spongepowered.common.interfaces.world.IMixinWorldServer)3 Vector3d (com.flowpowered.math.vector.Vector3d)2 Entity (net.minecraft.entity.Entity)2 NetHandlerPlayServer (net.minecraft.network.NetHandlerPlayServer)2 CPacketPlayer (net.minecraft.network.play.client.CPacketPlayer)2 SPacketEntityStatus (net.minecraft.network.play.server.SPacketEntityStatus)2 SPacketSpawnPosition (net.minecraft.network.play.server.SPacketSpawnPosition)2 MinecraftServer (net.minecraft.server.MinecraftServer)2 BlockPos (net.minecraft.util.math.BlockPos)2 CauseStackManager (org.spongepowered.api.event.CauseStackManager)2