content: package myau.mixin;
  
  import io.netty.channel.ChannelHandlerContext;
  import io.netty.util.concurrent.GenericFutureListener;
  import myau.Myau;
  import myau.event.EventManager;
  import myau.event.types.EventType;
  import myau.events.PacketEvent;
  import net.minecraft.network.NetworkManager;
  import net.minecraft.network.Packet;
  import net.minecraft.network.play.INetHandlerPlayClient;
  import net.minecraftforge.fml.relauncher.Side;
  import net.minecraftforge.fml.relauncher.SideOnly;
  import org.spongepowered.asm.mixin.Mixin;
  import org.spongepowered.asm.mixin.injection.At;
  import org.spongepowered.asm.mixin.injection.Inject;
  import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
  
  import java.util.concurrent.Future;
  
  @SideOnly(Side.CLIENT)
  @Mixin({NetworkManager.class})
  public abstract class MixinNetworkManager {
      @Inject(
              method = {"channelRead0*"},
              at = {@At("HEAD")},
              cancellable = true
      )
      private void channelRead0(ChannelHandlerContext channelHandlerContext, Packet<?> packet, CallbackInfo callbackInfo) {
          if (!packet.getClass().getName().startsWith("net.minecraft.network.play.client")) {
              if (Myau.delayManager != null && Myau.delayManager.shouldDelay((Packet<INetHandlerPlayClient>) packet)) {
                  callbackInfo.cancel();
              } else {
                  PacketEvent event = new PacketEvent(EventType.RECEIVE, packet);
                  EventManager.call(event);
                  if (event.isCancelled()) {
                      callbackInfo.cancel();
                  }
              }
          }
      }
  
      @Inject(
              method = {"sendPacket(Lnet/minecraft/network/Packet;)V"},
              at = {@At("HEAD")},
              cancellable = true
      )
      private void sendPacket(Packet<?> packet, CallbackInfo callbackInfo) {
          if (!packet.getClass().getName().startsWith("net.minecraft.network.play.server")) {
              PacketEvent event = new PacketEvent(EventType.SEND, packet);
              EventManager.call(event);
              if (event.isCancelled()) {
                  callbackInfo.cancel();
              } else if (Myau.playerStateManager != null && Myau.blinkManager != null && Myau.lagManager != null) {
                  if (!Myau.lagManager.isFlushing()) {
                      Myau.playerStateManager.handlePacket(packet);
                      if (Myau.blinkManager.isBlinking()) {
                          if (Myau.blinkManager.offerPacket(packet)) {
                              callbackInfo.cancel();
                              return;
                          }
                      }
                      if (Myau.lagManager.handlePacket(packet)) {
                          callbackInfo.cancel();
                      }
                  }
              }
          }
      }
  
      @Inject(
              method = {"sendPacket(Lnet/minecraft/network/Packet;Lio/netty/util/concurrent/GenericFutureListener;[Lio/netty/util/concurrent/GenericFutureListener;)V"},
              at = {@At("HEAD")},
              cancellable = true
      )
      private void sendPacket2(
              Packet<?> packet,
              GenericFutureListener<? extends Future<? super Void>> genericFutureListener,
              GenericFutureListener<? extends Future<? super Void>>[] arr,
              CallbackInfo callbackInfo
      ) {
          if (!packet.getClass().getName().startsWith("net.minecraft.network.play.server")) {
              if (Myau.playerStateManager != null && Myau.blinkManager != null && Myau.lagManager != null) {
                  if (!Myau.lagManager.isFlushing()) {
                      Myau.playerStateManager.handlePacket(packet);
                      if (Myau.blinkManager.isBlinking()) {
                          if (Myau.blinkManager.offerPacket(packet)) {
                              callbackInfo.cancel();
                              return;
                          }
                      }
                      if (Myau.lagManager.handlePacket(packet)) {
                          callbackInfo.cancel();
                      }
                  }
              }
          }
      }
  }
  