-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #271 from MrJeremyFisher/ctplus-1.20
CombatTagPlus 1.20.4
- Loading branch information
Showing
7 changed files
with
159 additions
and
27 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
30 changes: 30 additions & 0 deletions
30
plugins/combattagplus-paper/src/main/java/net/minelink/ctplus/nms/NpcNetworkManager.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 |
---|---|---|
@@ -1,10 +1,40 @@ | ||
package net.minelink.ctplus.nms; | ||
|
||
import net.minecraft.network.Connection; | ||
import net.minecraft.network.PacketListener; | ||
import net.minecraft.network.protocol.PacketFlow; | ||
import net.minelink.ctplus.util.EmptyChannel; | ||
|
||
import java.lang.reflect.Field; | ||
|
||
public class NpcNetworkManager extends Connection { | ||
public NpcNetworkManager() { | ||
super(PacketFlow.SERVERBOUND); | ||
channel = new EmptyChannel(null); | ||
} | ||
|
||
@Override | ||
public void setListener(PacketListener packetListener) { | ||
// Will need to be remapped by version, See: https://mappings.cephx.dev/YOUR_VERSION/net/minecraft/network/Connection.html for mappings | ||
Field connectionPacketListener = null; | ||
Field connectionDisconnectListener = null; | ||
|
||
try { | ||
connectionPacketListener = Connection.class.getDeclaredField("q"); // net.minecraft.network.Connection.packetListener | ||
connectionPacketListener.setAccessible(true); | ||
|
||
connectionDisconnectListener = Connection.class.getDeclaredField("p"); // net.minecraft.network.Connection.disconnectListener | ||
connectionDisconnectListener.setAccessible(true); | ||
} catch (NoSuchFieldException e) { | ||
throw new RuntimeException(e); | ||
} | ||
|
||
|
||
try { | ||
connectionPacketListener.set(this, packetListener); // q -> private volatile PacketListener packetListener | ||
connectionDisconnectListener.set(this, null); // p -> private volatile PacketListener disconnectListener | ||
} catch (Throwable e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} |
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
6 changes: 5 additions & 1 deletion
6
plugins/combattagplus-paper/src/main/java/net/minelink/ctplus/nms/NpcPlayerConnection.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 |
---|---|---|
@@ -1,12 +1,16 @@ | ||
package net.minelink.ctplus.nms; | ||
|
||
import net.minecraft.network.Connection; | ||
import net.minecraft.network.protocol.Packet; | ||
import net.minecraft.network.protocol.PacketFlow; | ||
import net.minecraft.server.MinecraftServer; | ||
import net.minecraft.server.level.ServerPlayer; | ||
import net.minecraft.server.network.CommonListenerCookie; | ||
import net.minecraft.server.network.ServerGamePacketListenerImpl; | ||
|
||
public class NpcPlayerConnection extends ServerGamePacketListenerImpl { | ||
public NpcPlayerConnection(ServerPlayer player) { | ||
super(MinecraftServer.getServer(), new NpcNetworkManager(), player); | ||
super(MinecraftServer.getServer(), new NpcNetworkManager(), player, new CommonListenerCookie(player.gameProfile, -1, player.clientInformation())); | ||
} | ||
|
||
} |
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
84 changes: 84 additions & 0 deletions
84
plugins/combattagplus-paper/src/main/java/net/minelink/ctplus/util/EmptyChannel.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,84 @@ | ||
package net.minelink.ctplus.util; | ||
|
||
|
||
import io.netty.channel.AbstractChannel; | ||
import io.netty.channel.Channel; | ||
import io.netty.channel.ChannelConfig; | ||
import io.netty.channel.ChannelMetadata; | ||
import io.netty.channel.ChannelOutboundBuffer; | ||
import io.netty.channel.DefaultChannelConfig; | ||
import io.netty.channel.EventLoop; | ||
|
||
import java.net.SocketAddress; | ||
|
||
/** | ||
* Fake connection channel for NPC players | ||
*/ | ||
public class EmptyChannel extends AbstractChannel { | ||
private final ChannelConfig config = new DefaultChannelConfig(this); | ||
|
||
public EmptyChannel(Channel parent) { | ||
super(parent); | ||
} | ||
|
||
@Override | ||
public ChannelConfig config() { | ||
config.setAutoRead(true); | ||
return config; | ||
} | ||
|
||
@Override | ||
protected void doBeginRead() throws Exception { | ||
} | ||
|
||
@Override | ||
protected void doBind(SocketAddress arg0) throws Exception { | ||
} | ||
|
||
@Override | ||
protected void doClose() throws Exception { | ||
} | ||
|
||
@Override | ||
protected void doDisconnect() throws Exception { | ||
} | ||
|
||
@Override | ||
protected void doWrite(ChannelOutboundBuffer arg0) throws Exception { | ||
} | ||
|
||
@Override | ||
public boolean isActive() { | ||
return false; | ||
} | ||
|
||
@Override | ||
protected boolean isCompatible(EventLoop arg0) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean isOpen() { | ||
return false; | ||
} | ||
|
||
@Override | ||
protected SocketAddress localAddress0() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public ChannelMetadata metadata() { | ||
return new ChannelMetadata(true); | ||
} | ||
|
||
@Override | ||
protected AbstractUnsafe newUnsafe() { | ||
return null; | ||
} | ||
|
||
@Override | ||
protected SocketAddress remoteAddress0() { | ||
return null; | ||
} | ||
} |
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