From 920ea1229d489fe88efa7df9e817225e76265371 Mon Sep 17 00:00:00 2001 From: TudbuT Date: Fri, 4 Oct 2024 02:37:15 +0200 Subject: [PATCH] fix ping causing bad packet events --- .../client/event/events/PrePacketEvent.java | 30 +++++++++++++++++++ .../client/feature/modules/ingame/Ping.java | 7 ++--- .../com/baseband/client/mixin/MixinProxy.java | 9 ++---- 3 files changed, 36 insertions(+), 10 deletions(-) create mode 100644 Client/src/main/java/de/com/baseband/client/event/events/PrePacketEvent.java diff --git a/Client/src/main/java/de/com/baseband/client/event/events/PrePacketEvent.java b/Client/src/main/java/de/com/baseband/client/event/events/PrePacketEvent.java new file mode 100644 index 0000000..8cfd962 --- /dev/null +++ b/Client/src/main/java/de/com/baseband/client/event/events/PrePacketEvent.java @@ -0,0 +1,30 @@ +package de.com.baseband.client.event.events; + +import de.com.baseband.client.event.CancellableEvent; +import net.minecraft.network.Packet; + +public abstract class PrePacketEvent extends CancellableEvent { + + private final Packet packet; + + public PrePacketEvent(Packet packet) { + this.packet = packet; + } + + public Packet getPacket() { + return packet; + } + + public static class Send extends PrePacketEvent { + public Send(Packet packet) { + super(packet); + } + } + + public static class Receive extends PrePacketEvent { + public Receive(Packet packet) { + super(packet); + } + } + +} \ No newline at end of file diff --git a/Client/src/main/java/de/com/baseband/client/feature/modules/ingame/Ping.java b/Client/src/main/java/de/com/baseband/client/feature/modules/ingame/Ping.java index 983f95c..20f48c6 100644 --- a/Client/src/main/java/de/com/baseband/client/feature/modules/ingame/Ping.java +++ b/Client/src/main/java/de/com/baseband/client/feature/modules/ingame/Ping.java @@ -1,8 +1,7 @@ package de.com.baseband.client.feature.modules.ingame; import de.com.baseband.client.BaseBand; -import de.com.baseband.client.event.events.PacketEvent; -import de.com.baseband.client.event.events.PlayerDestroyEvent; +import de.com.baseband.client.event.events.PrePacketEvent; import de.com.baseband.client.feature.Feature; import de.com.baseband.client.feature.category.Ingame; import de.com.baseband.client.registry.annotation.Config; @@ -97,7 +96,7 @@ public class Ping extends Feature { } } - public void onPacket(PacketEvent.Send e) { + public void onPacket(PrePacketEvent.Send e) { if(allowSend == e.getPacket() || notIngame()) return; if (e.getPacket() instanceof CPacketKeepAlive || holdAll) { @@ -107,7 +106,7 @@ public class Ping extends Feature { } } - public void onPacket(PacketEvent.Receive e) { + public void onPacket(PrePacketEvent.Receive e) { if(allowRecv == e.getPacket() || notIngame()) return; if (e.getPacket() instanceof SPacketKeepAlive || holdAll) { diff --git a/Client/src/main/java/de/com/baseband/client/mixin/MixinProxy.java b/Client/src/main/java/de/com/baseband/client/mixin/MixinProxy.java index 32092b4..af178f6 100644 --- a/Client/src/main/java/de/com/baseband/client/mixin/MixinProxy.java +++ b/Client/src/main/java/de/com/baseband/client/mixin/MixinProxy.java @@ -1,10 +1,7 @@ package de.com.baseband.client.mixin; import de.com.baseband.client.BaseBand; -import de.com.baseband.client.event.events.DamageBlockEvent; -import de.com.baseband.client.event.events.MotionUpdateEvent; -import de.com.baseband.client.event.events.MoveEvent; -import de.com.baseband.client.event.events.PacketEvent; +import de.com.baseband.client.event.events.*; import de.com.baseband.client.feature.Features; import de.com.baseband.client.feature.modules.chat.ChatExtras; import de.com.baseband.client.feature.modules.client.Client; @@ -66,12 +63,12 @@ public class MixinProxy { } public static void onPacketReceive(Packet p_channelRead0_2_, CallbackInfo ci) { - if (BaseBand.publish(new PacketEvent.Receive(p_channelRead0_2_)).isCancelled()) + if (BaseBand.publish(new PrePacketEvent.Receive(p_channelRead0_2_)).isCancelled() || BaseBand.publish(new PacketEvent.Receive(p_channelRead0_2_)).isCancelled()) ci.cancel(); } public static void onPacketSend(Packet packetIn, CallbackInfo ci) { - if (BaseBand.publish(new PacketEvent.Send(packetIn)).isCancelled()) + if (BaseBand.publish(new PrePacketEvent.Send(packetIn)).isCancelled() || BaseBand.publish(new PacketEvent.Send(packetIn)).isCancelled()) ci.cancel(); }