-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Create v1.21.4 * Delete v1.21.4 * Create build.gradle * Create PlayerInjector_v1_21_4.java * Update settings.gradle * Update build.gradle * Update gradle.properties * Update build.gradle * Update AntiPopup.java
- Loading branch information
Showing
7 changed files
with
114 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
userdevVer=1.7.1 | ||
shadowVer=8.1.7 | ||
tinyRemapperVer=0.10.3 | ||
packetEventsVer=2.6.0 | ||
packetEventsVer=2.7.0 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
plugins { | ||
id "java" | ||
id "io.papermc.paperweight.userdev" version "${userdevVer}" | ||
} | ||
|
||
dependencies { | ||
compileOnly project(path: ":shared") | ||
compileOnly project(path: ":nms") | ||
|
||
paperweightDevelopmentBundle "io.papermc.paper:dev-bundle:1.21.4-R0.1-SNAPSHOT" | ||
pluginRemapper "net.fabricmc:tiny-remapper:${tinyRemapperVer}:fat" | ||
} | ||
|
||
java { | ||
disableAutoTargetJvm() | ||
toolchain { | ||
languageVersion.set(JavaLanguageVersion.of(21)) | ||
} | ||
sourceCompatibility = JavaVersion.VERSION_17 | ||
targetCompatibility = JavaVersion.VERSION_17 | ||
} |
86 changes: 86 additions & 0 deletions
86
...1.4/src/main/java/com/github/kaspiandev/antipopup/nms/v1_21_4/PlayerInjector_v1_21_4.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,86 @@ | ||
package com.github.kaspiandev.antipopup.nms.v1_21_4; | ||
|
||
import com.github.kaspiandev.antipopup.spigot.nms.PacketInjector; | ||
import io.netty.channel.*; | ||
import net.minecraft.network.Connection; | ||
import net.minecraft.network.chat.ChatType; | ||
import net.minecraft.network.chat.Component; | ||
import net.minecraft.network.protocol.game.ClientboundPlayerChatPacket; | ||
import net.minecraft.network.protocol.game.ClientboundSystemChatPacket; | ||
import net.minecraft.server.network.ServerCommonPacketListenerImpl; | ||
import net.minecraft.server.network.ServerGamePacketListenerImpl; | ||
import org.bukkit.craftbukkit.entity.CraftPlayer; | ||
import org.bukkit.entity.Player; | ||
|
||
import java.lang.reflect.Field; | ||
import java.lang.reflect.InaccessibleObjectException; | ||
|
||
@SuppressWarnings("unused") | ||
public class PlayerInjector_v1_21_4 implements PacketInjector { | ||
|
||
private static final String HANDLER_NAME = "antipopup_handler"; | ||
private static Field connectionField; | ||
|
||
static { | ||
try { | ||
for (Field field : ServerCommonPacketListenerImpl.class.getDeclaredFields()) { | ||
if (field.getType().equals(Connection.class)) { | ||
field.setAccessible(true); | ||
connectionField = field; | ||
break; | ||
} | ||
} | ||
} catch (SecurityException | InaccessibleObjectException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
public void inject(Player player) { | ||
ChannelDuplexHandler duplexHandler = new ChannelDuplexHandler() { | ||
@Override | ||
public void write(ChannelHandlerContext ctx, Object packet, ChannelPromise promise) throws Exception { | ||
if (packet instanceof ClientboundPlayerChatPacket chatPacket) { | ||
Component content = chatPacket.unsignedContent(); | ||
if (content == null) { | ||
content = Component.literal(chatPacket.body().content()); | ||
} | ||
ChatType.Bound chatType = chatPacket.chatType(); | ||
|
||
((CraftPlayer) player).getHandle().connection.send( | ||
new ClientboundSystemChatPacket(chatType.decorate(content), false)); | ||
return; | ||
} | ||
super.write(ctx, packet, promise); | ||
} | ||
}; | ||
|
||
ServerGamePacketListenerImpl listener = ((CraftPlayer) player).getHandle().connection; | ||
Channel channel = getConnection(listener).channel; | ||
ChannelPipeline pipeline = channel.pipeline(); | ||
|
||
if (pipeline.get(HANDLER_NAME) != null) { | ||
pipeline.remove(HANDLER_NAME); | ||
} | ||
|
||
channel.eventLoop().submit(() -> { | ||
channel.pipeline().addBefore("packet_handler", HANDLER_NAME, duplexHandler); | ||
}); | ||
} | ||
|
||
public void uninject(Player player) { | ||
ServerGamePacketListenerImpl listener = ((CraftPlayer) player).getHandle().connection; | ||
Channel channel = getConnection(listener).channel; | ||
channel.eventLoop().submit(() -> { | ||
channel.pipeline().remove(HANDLER_NAME); | ||
}); | ||
} | ||
|
||
private Connection getConnection(ServerGamePacketListenerImpl listener) { | ||
try { | ||
return (Connection) connectionField.get(listener); | ||
} catch (IllegalAccessException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
} |