Skip to content

Commit

Permalink
Update 10.1 (#107)
Browse files Browse the repository at this point in the history
* 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
BAD7777 authored Dec 12, 2024
1 parent 499358a commit 7d0370f
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 4 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ tasks {

allprojects {
group = "com.github.kaspiandev.antipopup"
version = "10"
version = "10.1"

repositories {
mavenCentral()
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
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
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ pluginManagement {

rootProject.name = "AntiPopup"
include "spigot", "shared", "nms", "v1.19.2", "v1.19.3", "v1.19.4",
"v1.20.1", "v1.20.2", "v1.20.4", "v1.20.6", "v1.21", "v1.21.2", "velocity"
"v1.20.1", "v1.20.2", "v1.20.4", "v1.20.6", "v1.21", "v1.21.2", "v1.21.4", "velocity"

3 changes: 2 additions & 1 deletion spigot/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ dependencies {
implementation project(path: ":v1.20.6", configuration: "reobf")
implementation project(path: ":v1.21", configuration: "reobf")
implementation project(path: ":v1.21.2", configuration: "reobf")
implementation project(path: ":v1.21.4", configuration: "reobf")

compileOnly "org.spigotmc:spigot-api:1.19.4-R0.1-SNAPSHOT"
compileOnly "com.viaversion:viaversion:5.0.1"
compileOnly "com.viaversion:viaversion:5.2.0"
compileOnly "org.apache.logging.log4j:log4j-core:2.19.0"

implementation "org.bstats:bstats-bukkit:3.0.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.github.kaspiandev.antipopup.nms.v1_20_6.PlayerInjector_v1_20_6;
import com.github.kaspiandev.antipopup.nms.v1_21.PlayerInjector_v1_21;
import com.github.kaspiandev.antipopup.nms.v1_21_2.PlayerInjector_v1_21_2;
import com.github.kaspiandev.antipopup.nms.v1_21_4.PlayerInjector_v1_21_4;
import com.github.kaspiandev.antipopup.spigot.api.Api;
import com.github.kaspiandev.antipopup.spigot.hook.HookManager;
import com.github.kaspiandev.antipopup.spigot.hook.viaversion.ViaVersionHook;
Expand Down Expand Up @@ -120,6 +121,7 @@ public void onEnable() {
if (config.isBlockChatReports()) {
if (!config.isExperimentalMode()) {
PlayerListener playerListener = switch (serverManager.getVersion()) {
case V_1_21_4 -> new PlayerListener(new PlayerInjector_v1_21_4());
case V_1_21_2, V_1_21_3 -> new PlayerListener(new PlayerInjector_v1_21_2());
case V_1_21, V_1_21_1 -> new PlayerListener(new PlayerInjector_v1_21());
case V_1_20_5, V_1_20_6 -> new PlayerListener(new PlayerInjector_v1_20_6());
Expand Down
21 changes: 21 additions & 0 deletions v1.21.4/build.gradle
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
}
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);
}
}

}

0 comments on commit 7d0370f

Please sign in to comment.