/FileExtraction/Java_unseen/ionar2_summit/src/main/java/com/salhack/summit/module/exploit/PortalGodMode.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.network.EventServerPacket;
import com.salhack.summit.module.Module;
import net.minecraft.network.play.client.CPacketConfirmTeleport;
import net.minecraft.network.play.server.SPacketRespawn;

public class PortalGodMode extends Module
{
    public PortalGodMode()
    {
        super("PortalGodMode", new String[] {"PGM"}, "Portal God Mode, cancels the CPacketConfirmTeleport packet", "NONE", 0xDB2441, ModuleType.EXPLOIT);
    }
    
    private boolean _shouldCancelPacket = false;
    private int _prevDimensionId = -420;
    
    @Override
    public void toggleNoSave()
    {
        
    }
    
    @Override
    public void onEnable()
    {
        super.onEnable();
        _shouldCancelPacket = false;
        _prevDimensionId = mc.player.dimension;
    }
    
    @EventHandler
    private Listener<EventServerPacket> onServerPacket  = new Listener<>(event ->
    {
        if (event.getStage() != MinecraftEvent.Stage.Pre)
            return;
        
        if (event.getPacket() instanceof SPacketRespawn)
        {
            SPacketRespawn packet = (SPacketRespawn) event.getPacket();
            
            if (packet.getDimensionID() != _prevDimensionId)
            {
                _prevDimensionId = packet.getDimensionID();
                _shouldCancelPacket = true;
            }
            return;
        }
    });
    
    @EventHandler
    private Listener<EventClientPacket> onClientPacket = new Listener<>(event ->
    {
        if (event.getStage() != MinecraftEvent.Stage.Pre)
            return;
        
        if (event.getPacket() instanceof CPacketConfirmTeleport && _shouldCancelPacket)
            event.cancel();
    });
}
