-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
simplify handler mixins, fixed memory leak
closes #19
- Loading branch information
Showing
11 changed files
with
70 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
src/main/java/lol/bai/badpackets/impl/handler/PacketHandlerHolder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package lol.bai.badpackets.impl.handler; | ||
|
||
public interface PacketHandlerHolder<T extends AbstractPacketHandler<?>> { | ||
|
||
T badpackets_handler(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/main/java/lol/bai/badpackets/impl/mixin/MixinConnection.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package lol.bai.badpackets.impl.mixin; | ||
|
||
import io.netty.channel.ChannelHandlerContext; | ||
import lol.bai.badpackets.impl.handler.PacketHandlerHolder; | ||
import net.minecraft.network.Connection; | ||
import net.minecraft.network.PacketListener; | ||
import org.jetbrains.annotations.Nullable; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.Unique; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
@Mixin(Connection.class) | ||
public class MixinConnection { | ||
|
||
@Shadow | ||
@Nullable | ||
private volatile PacketListener packetListener; | ||
|
||
@Inject(method = "setListener", at = @At("HEAD")) | ||
private void badpackets_cleanOldListener(PacketListener $$0, CallbackInfo ci) { | ||
badpackets_cleanListener(); | ||
} | ||
|
||
@Inject(method = "channelInactive", at = @At("HEAD")) | ||
private void badpackets_cleanListener(ChannelHandlerContext $$0, CallbackInfo ci) { | ||
badpackets_cleanListener(); | ||
} | ||
|
||
@Inject(method = "handleDisconnection", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/PacketListener;onDisconnect(Lnet/minecraft/network/chat/Component;)V")) | ||
private void badpackets_cleanListener(CallbackInfo ci) { | ||
badpackets_cleanListener(); | ||
} | ||
|
||
@Unique | ||
private void badpackets_cleanListener() { | ||
if (this.packetListener instanceof PacketHandlerHolder<?> holder) { | ||
holder.badpackets_handler().remove(); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters