use of net.minecraft.network.play.client.CPacketClientSettings 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);
}
}
Aggregations