Skip to content

Commit

Permalink
added packet delay
Browse files Browse the repository at this point in the history
  • Loading branch information
cqb13 committed Aug 20, 2024
1 parent bfb300d commit 955cd54
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/main/java/cqb13/NumbyHack/NumbyHack.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public void onInitialize() {
Modules.get().add(new NewChunks());
Modules.get().add(new NoStrip());
Modules.get().add(new Number81());
Modules.get().add(new PacketDelay());
Modules.get().add(new RaidCaptainNotifier());
Modules.get().add(new RideStats());
Modules.get().add(new SafeFire());
Expand Down
49 changes: 49 additions & 0 deletions src/main/java/cqb13/NumbyHack/modules/general/PacketDelay.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package cqb13.NumbyHack.modules.general;

import cqb13.NumbyHack.NumbyHack;
import meteordevelopment.meteorclient.events.packets.PacketEvent;
import meteordevelopment.meteorclient.settings.PacketListSetting;
import meteordevelopment.meteorclient.settings.Setting;
import meteordevelopment.meteorclient.settings.SettingGroup;
import meteordevelopment.meteorclient.systems.modules.Module;
import meteordevelopment.meteorclient.utils.network.PacketUtils;
import meteordevelopment.orbit.EventHandler;
import meteordevelopment.orbit.EventPriority;
import net.minecraft.network.packet.Packet;

import java.util.Set;
import java.util.ArrayList;

public class PacketDelay extends Module {
private final SettingGroup sgGeneral = settings.getDefaultGroup();

private final Setting<Set<Class<? extends Packet<?>>>> c2sPackets = sgGeneral.add(new PacketListSetting.Builder()
.name("C2S-packets")
.description("Client-to-server packets to delay.")
.filter(aClass -> PacketUtils.getC2SPackets().contains(aClass))
.build()
);

private static ArrayList<Packet<?>> delayedPackets = new ArrayList<>();

public PacketDelay() {
super(NumbyHack.CATEGORY, "packet-delay", "Allows you to delay the packets you send to a server.");
runInMainMenu = true;
}

@EventHandler(priority = EventPriority.HIGHEST + 1)
private void onSendPacket(PacketEvent.Send event) {
if (c2sPackets.get().contains(event.packet.getClass())) {
delayedPackets.add(event.packet);
event.cancel();
}
}

@Override
public void onDeactivate() {
for (Packet<?> packet : delayedPackets) {
mc.getNetworkHandler().sendPacket(packet);
}
delayedPackets.clear();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import meteordevelopment.meteorclient.utils.player.ChatUtils;
import meteordevelopment.orbit.EventHandler;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.mob.PillagerEntity;
import net.minecraft.nbt.NbtCompound;

Expand Down

0 comments on commit 955cd54

Please sign in to comment.