/FileExtraction/Java_unseen/ionar2_summit/src/main/java/com/salhack/summit/module/exploit/PacketCanceller.java
package com.salhack.summit.module.exploit;

import com.salhack.summit.events.MinecraftEvent;
import com.salhack.summit.events.bus.EventHandler;
import com.salhack.summit.events.bus.Listener;
import com.salhack.summit.events.network.EventClientPacket;
import com.salhack.summit.events.player.EventPlayerUpdate;
import com.salhack.summit.module.Module;
import com.salhack.summit.module.Value;
import net.minecraft.network.Packet;
import net.minecraft.network.play.client.*;

import java.util.ArrayList;

public final class PacketCanceller extends Module
{
    public final Value<Boolean> CancelCPacketInput = new Value<Boolean>("Input", new String[] {"CPacketInput"}, "Cancels this packet", true);
    public final Value<Boolean> CancelPosition = new Value<Boolean>("Position", new String[] {"Position"}, "Cancels this packet", true);
    public final Value<Boolean> CancelPositionRotation = new Value<Boolean>("PositionRotation", new String[] {"PositionRotation"}, "Cancels this packet", true);
    public final Value<Boolean> CancelRotation = new Value<Boolean>("Rotation", new String[] {"Rotation"}, "Cancels this packet", true);
    public final Value<Boolean> CancelCPacketPlayerAbilities = new Value<Boolean>("PlayerAbilities", new String[] {"CPacketPlayerAbilities"}, "Cancels this packet", true);
    public final Value<Boolean> CancelCPacketPlayerDigging = new Value<Boolean>("PlayerDigging", new String[] {"CPacketPlayerDigging"}, "Cancels this packet", true);
    public final Value<Boolean> CancelCPacketPlayerTryUseItem = new Value<Boolean>("PlayerTryUseItem", new String[] {"CPacketPlayerTryUseItem"}, "Cancels this packet", true);
    public final Value<Boolean> CancelCPacketPlayerTryUseItemOnBlock = new Value<Boolean>("PlayerTryUseItemOnBlock", new String[] {"CPacketPlayerTryUseItemOnBlock"}, "Cancels this packet", true);
    public final Value<Boolean> CancelCPacketEntityAction = new Value<Boolean>("EntityAction", new String[] {"CPacketEntityAction"}, "Cancels this packet", true);
    public final Value<Boolean> CancelCPacketUseEntity = new Value<Boolean>("UseEntity", new String[] {"CPacketUseEntity"}, "Cancels this packet", true);
    public final Value<Boolean> CancelCPacketVehicleMove = new Value<Boolean>("VehicleMove", new String[] {"CPacketVehicleMove"}, "Cancels this packet", true);
    
    public PacketCanceller()
    {
        super("PacketCanceller", new String[]
        { "PacketCanceller" }, "Packet canceller for certian packets", "NONE", 0xF20E5B, ModuleType.EXPLOIT);
        setMetaData(getMetaData());
    }
    
    private int PacketsCanelled = 0;
    private ArrayList<Packet<?>> PacketsToIgnore = new ArrayList<>();
    
    @Override
    public void onDisable()
    {
        super.onDisable();
        
        PacketsCanelled = 0;
    }
    
    @Override
    public void toggleNoSave()
    {
        
    }
    
    public String getMetaData()
    {
        return String.valueOf(PacketsCanelled);
    }

    @EventHandler
    private Listener<EventPlayerUpdate> onPlayerUpdate  = new Listener<>(event ->
    {
        setMetaData(getMetaData());
    });
    
    @EventHandler
    private Listener<EventClientPacket> onClientPacket = new Listener<>(event ->
    {
        if (event.getStage() != MinecraftEvent.Stage.Pre)
            return;
        
        if ((event.getPacket() instanceof CPacketInput && CancelCPacketInput.getValue())
            || (event.getPacket() instanceof CPacketPlayer.Position && CancelPosition.getValue())
            || (event.getPacket() instanceof CPacketPlayer.PositionRotation && CancelPositionRotation.getValue())
            || (event.getPacket() instanceof CPacketPlayer.Rotation && CancelRotation.getValue())
            || (event.getPacket() instanceof CPacketPlayerAbilities && CancelCPacketPlayerAbilities.getValue())
            || (event.getPacket() instanceof CPacketPlayerDigging && CancelCPacketPlayerDigging.getValue())
            || (event.getPacket() instanceof CPacketPlayerTryUseItem && CancelCPacketPlayerTryUseItem.getValue())
            || (event.getPacket() instanceof CPacketPlayerTryUseItemOnBlock && CancelCPacketPlayerTryUseItemOnBlock.getValue())
            || (event.getPacket() instanceof CPacketEntityAction && CancelCPacketEntityAction.getValue())
            || (event.getPacket() instanceof CPacketUseEntity && CancelCPacketUseEntity.getValue())
            || (event.getPacket() instanceof CPacketVehicleMove && CancelCPacketVehicleMove.getValue()))
        {
            if (PacketsToIgnore.contains(event.getPacket()))
            {
                PacketsToIgnore.remove(event.getPacket());
                return;
            }
            
            ++PacketsCanelled;
            event.cancel();
            return;
        }
    });
    
    public void AddIgnorePacket(Packet<?> p_Packet)
    {
        PacketsToIgnore.add(p_Packet);
    }
}
