Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package tech.thatgravyboat.skyblockapi.mixins.events;

import com.llamalad7.mixinextras.injector.wrapmethod.WrapMethod;
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import net.minecraft.network.PacketListener;
import net.minecraft.network.protocol.*;
import net.minecraft.network.protocol.game.GamePacketTypes;
import org.jetbrains.annotations.NotNull;
import org.spongepowered.asm.mixin.Mixin;
import tech.thatgravyboat.skyblockapi.api.SkyBlockAPI;
import tech.thatgravyboat.skyblockapi.api.events.level.PacketReceivedEvent;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;

@Mixin(BundlerInfo.class)
public interface BundlerInfoMixin {

@WrapMethod(method = "createForPacket")
private static <T extends PacketListener, P extends BundlePacket<? super T>> BundlerInfo createForPacketWrapMethod(
final PacketType<@NotNull P> type,
final Function<Iterable<Packet<? super T>>, P> bundler,
final BundleDelimiterPacket<? super T> delimiter,
final Operation<BundlerInfo> original
) {
// Sanity check, we only want to modify clientbound bundle packets even though this method is only called for them
if (type == GamePacketTypes.CLIENTBOUND_BUNDLE) {
return original.call(type, (Function<Iterable<Packet<? super T>>, P>) (iterable) -> {
// The default capacity should be enough, if hypixel ever starts sending more than 10 packets in a bundle we can revisit this
List<Packet<? super T>> packets = new ArrayList<>();
for (var packet : iterable) {
if (!new PacketReceivedEvent(packet).post(SkyBlockAPI.getEventBus())) {
packets.add(packet);
}
}

return bundler.apply(packets);
}, delimiter);
}
return original.call(type, bundler, delimiter);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import net.minecraft.network.Connection;
import net.minecraft.network.PacketListener;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.ClientboundBundlePacket;
import org.spongepowered.asm.mixin.Mixin;
import tech.thatgravyboat.skyblockapi.api.SkyBlockAPI;
import tech.thatgravyboat.skyblockapi.api.events.level.PacketReceivedEvent;
Expand All @@ -14,6 +15,8 @@ public class ConnectionMixin {

@WrapMethod(method = "genericsFtw")
private static void genericsFtw(Packet<?> packet, PacketListener listener, Operation<Void> original) {
// The bundle packets are special and are already handled in the BundleInfoMixin
if (packet instanceof ClientboundBundlePacket) return;
if (!new PacketReceivedEvent(packet).post(SkyBlockAPI.getEventBus())) {
original.call(packet, listener);
}
Expand Down