Skip to content

Commit 7d0370f

Browse files
authored
Update 10.1 (#107)
* 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
1 parent 499358a commit 7d0370f

File tree

7 files changed

+114
-4
lines changed

7 files changed

+114
-4
lines changed

build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ tasks {
2020

2121
allprojects {
2222
group = "com.github.kaspiandev.antipopup"
23-
version = "10"
23+
version = "10.1"
2424

2525
repositories {
2626
mavenCentral()

gradle.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
userdevVer=1.7.1
22
shadowVer=8.1.7
33
tinyRemapperVer=0.10.3
4-
packetEventsVer=2.6.0
4+
packetEventsVer=2.7.0

settings.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ pluginManagement {
77

88
rootProject.name = "AntiPopup"
99
include "spigot", "shared", "nms", "v1.19.2", "v1.19.3", "v1.19.4",
10-
"v1.20.1", "v1.20.2", "v1.20.4", "v1.20.6", "v1.21", "v1.21.2", "velocity"
10+
"v1.20.1", "v1.20.2", "v1.20.4", "v1.20.6", "v1.21", "v1.21.2", "v1.21.4", "velocity"
1111

spigot/build.gradle

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ dependencies {
2222
implementation project(path: ":v1.20.6", configuration: "reobf")
2323
implementation project(path: ":v1.21", configuration: "reobf")
2424
implementation project(path: ":v1.21.2", configuration: "reobf")
25+
implementation project(path: ":v1.21.4", configuration: "reobf")
2526

2627
compileOnly "org.spigotmc:spigot-api:1.19.4-R0.1-SNAPSHOT"
27-
compileOnly "com.viaversion:viaversion:5.0.1"
28+
compileOnly "com.viaversion:viaversion:5.2.0"
2829
compileOnly "org.apache.logging.log4j:log4j-core:2.19.0"
2930

3031
implementation "org.bstats:bstats-bukkit:3.0.0"

spigot/src/main/java/com/github/kaspiandev/antipopup/spigot/AntiPopup.java

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import com.github.kaspiandev.antipopup.nms.v1_20_6.PlayerInjector_v1_20_6;
1414
import com.github.kaspiandev.antipopup.nms.v1_21.PlayerInjector_v1_21;
1515
import com.github.kaspiandev.antipopup.nms.v1_21_2.PlayerInjector_v1_21_2;
16+
import com.github.kaspiandev.antipopup.nms.v1_21_4.PlayerInjector_v1_21_4;
1617
import com.github.kaspiandev.antipopup.spigot.api.Api;
1718
import com.github.kaspiandev.antipopup.spigot.hook.HookManager;
1819
import com.github.kaspiandev.antipopup.spigot.hook.viaversion.ViaVersionHook;
@@ -120,6 +121,7 @@ public void onEnable() {
120121
if (config.isBlockChatReports()) {
121122
if (!config.isExperimentalMode()) {
122123
PlayerListener playerListener = switch (serverManager.getVersion()) {
124+
case V_1_21_4 -> new PlayerListener(new PlayerInjector_v1_21_4());
123125
case V_1_21_2, V_1_21_3 -> new PlayerListener(new PlayerInjector_v1_21_2());
124126
case V_1_21, V_1_21_1 -> new PlayerListener(new PlayerInjector_v1_21());
125127
case V_1_20_5, V_1_20_6 -> new PlayerListener(new PlayerInjector_v1_20_6());

v1.21.4/build.gradle

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
plugins {
2+
id "java"
3+
id "io.papermc.paperweight.userdev" version "${userdevVer}"
4+
}
5+
6+
dependencies {
7+
compileOnly project(path: ":shared")
8+
compileOnly project(path: ":nms")
9+
10+
paperweightDevelopmentBundle "io.papermc.paper:dev-bundle:1.21.4-R0.1-SNAPSHOT"
11+
pluginRemapper "net.fabricmc:tiny-remapper:${tinyRemapperVer}:fat"
12+
}
13+
14+
java {
15+
disableAutoTargetJvm()
16+
toolchain {
17+
languageVersion.set(JavaLanguageVersion.of(21))
18+
}
19+
sourceCompatibility = JavaVersion.VERSION_17
20+
targetCompatibility = JavaVersion.VERSION_17
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
package com.github.kaspiandev.antipopup.nms.v1_21_4;
2+
3+
import com.github.kaspiandev.antipopup.spigot.nms.PacketInjector;
4+
import io.netty.channel.*;
5+
import net.minecraft.network.Connection;
6+
import net.minecraft.network.chat.ChatType;
7+
import net.minecraft.network.chat.Component;
8+
import net.minecraft.network.protocol.game.ClientboundPlayerChatPacket;
9+
import net.minecraft.network.protocol.game.ClientboundSystemChatPacket;
10+
import net.minecraft.server.network.ServerCommonPacketListenerImpl;
11+
import net.minecraft.server.network.ServerGamePacketListenerImpl;
12+
import org.bukkit.craftbukkit.entity.CraftPlayer;
13+
import org.bukkit.entity.Player;
14+
15+
import java.lang.reflect.Field;
16+
import java.lang.reflect.InaccessibleObjectException;
17+
18+
@SuppressWarnings("unused")
19+
public class PlayerInjector_v1_21_4 implements PacketInjector {
20+
21+
private static final String HANDLER_NAME = "antipopup_handler";
22+
private static Field connectionField;
23+
24+
static {
25+
try {
26+
for (Field field : ServerCommonPacketListenerImpl.class.getDeclaredFields()) {
27+
if (field.getType().equals(Connection.class)) {
28+
field.setAccessible(true);
29+
connectionField = field;
30+
break;
31+
}
32+
}
33+
} catch (SecurityException | InaccessibleObjectException e) {
34+
throw new RuntimeException(e);
35+
}
36+
}
37+
38+
public void inject(Player player) {
39+
ChannelDuplexHandler duplexHandler = new ChannelDuplexHandler() {
40+
@Override
41+
public void write(ChannelHandlerContext ctx, Object packet, ChannelPromise promise) throws Exception {
42+
if (packet instanceof ClientboundPlayerChatPacket chatPacket) {
43+
Component content = chatPacket.unsignedContent();
44+
if (content == null) {
45+
content = Component.literal(chatPacket.body().content());
46+
}
47+
ChatType.Bound chatType = chatPacket.chatType();
48+
49+
((CraftPlayer) player).getHandle().connection.send(
50+
new ClientboundSystemChatPacket(chatType.decorate(content), false));
51+
return;
52+
}
53+
super.write(ctx, packet, promise);
54+
}
55+
};
56+
57+
ServerGamePacketListenerImpl listener = ((CraftPlayer) player).getHandle().connection;
58+
Channel channel = getConnection(listener).channel;
59+
ChannelPipeline pipeline = channel.pipeline();
60+
61+
if (pipeline.get(HANDLER_NAME) != null) {
62+
pipeline.remove(HANDLER_NAME);
63+
}
64+
65+
channel.eventLoop().submit(() -> {
66+
channel.pipeline().addBefore("packet_handler", HANDLER_NAME, duplexHandler);
67+
});
68+
}
69+
70+
public void uninject(Player player) {
71+
ServerGamePacketListenerImpl listener = ((CraftPlayer) player).getHandle().connection;
72+
Channel channel = getConnection(listener).channel;
73+
channel.eventLoop().submit(() -> {
74+
channel.pipeline().remove(HANDLER_NAME);
75+
});
76+
}
77+
78+
private Connection getConnection(ServerGamePacketListenerImpl listener) {
79+
try {
80+
return (Connection) connectionField.get(listener);
81+
} catch (IllegalAccessException e) {
82+
throw new RuntimeException(e);
83+
}
84+
}
85+
86+
}

0 commit comments

Comments
 (0)