-
-
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
15 changed files
with
96 additions
and
140 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
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
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
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
45 changes: 45 additions & 0 deletions
45
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,45 @@ | ||
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 net.minecraft.network.ProtocolInfo; | ||
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 = "setupInboundProtocol", at = @At("HEAD")) | ||
private <T extends PacketListener> void badpackets_cleanOldListener(ProtocolInfo<T> info, T listener, CallbackInfo ci) { | ||
badpackets_cleanListener(); | ||
} | ||
|
||
@Inject(method = "channelInactive", at = @At("HEAD")) | ||
private void badpackets_cleanListener(ChannelHandlerContext ctx, CallbackInfo ci) { | ||
badpackets_cleanListener(); | ||
} | ||
|
||
@Inject(method = "handleDisconnection", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/PacketListener;onDisconnect(Lnet/minecraft/network/DisconnectionDetails;)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
Oops, something went wrong.