Skip to content

Commit

Permalink
9 (#94)
Browse files Browse the repository at this point in the history
* Initial 1.21 update
  • Loading branch information
KaspianDev authored Jul 1, 2024
1 parent 78b7730 commit 7664384
Show file tree
Hide file tree
Showing 26 changed files with 260 additions and 48 deletions.
6 changes: 1 addition & 5 deletions 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 = "8.1"
version = "9"

repositories {
mavenCentral()
Expand All @@ -43,10 +43,6 @@ allprojects {
}
}

java {
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21
}
}

tasks.register("buildAndMove", Copy) {
Expand Down
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
userdevVer=1.7.0
userdevVer=1.7.1
shadowVer=8.1.7
tinyRemapperVer=0.10.3
packetEventsVer=2.4.0
Binary file removed lib/packetevents-api-2.2.1.jar
Binary file not shown.
Binary file removed lib/packetevents-spigot-2.2.1.jar
Binary file not shown.
Binary file removed lib/packetevents-velocity-2.2.1.jar
Binary file not shown.
6 changes: 6 additions & 0 deletions nms/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,9 @@ plugins {
dependencies {
compileOnly "org.spigotmc:spigot-api:1.19.4-R0.1-SNAPSHOT"
}

java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
}
}
3 changes: 2 additions & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ 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", "velocity"
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", "velocity"

8 changes: 7 additions & 1 deletion shared/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,11 @@ dependencies {
implementation "dev.dejvokep:boosted-yaml:1.3"
implementation "net.kyori:adventure-text-serializer-gson:4.14.0"
implementation "net.kyori:adventure-platform-bukkit:4.3.1"
implementation files("../lib/packetevents-api-2.2.1.jar")
implementation "com.github.retrooper:packetevents-api:${packetEventsVer}"
}

java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ public boolean isShowPopup() {
return document.getBoolean("show-popup");
}

public boolean isExperimentalMode() {
return document.getOptionalBoolean("experimental-mode").orElse(false);
}

public void save() {
try {
document.save();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,21 @@
import com.github.retrooper.packetevents.event.PacketListenerPriority;
import com.github.retrooper.packetevents.event.PacketReceiveEvent;
import com.github.retrooper.packetevents.event.PacketSendEvent;
import com.github.retrooper.packetevents.protocol.chat.ChatType;
import com.github.retrooper.packetevents.protocol.chat.ChatTypes;
import com.github.retrooper.packetevents.protocol.chat.message.ChatMessage;
import com.github.retrooper.packetevents.protocol.chat.message.ChatMessage_v1_19_1;
import com.github.retrooper.packetevents.protocol.chat.message.ChatMessage_v1_19_3;
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
import com.github.retrooper.packetevents.protocol.packettype.PacketTypeCommon;
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerChatMessage;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerJoinGame;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerServerData;
import com.github.retrooper.packetevents.wrapper.play.server.WrapperPlayServerSystemChatMessage;
import com.github.retrooper.packetevents.wrapper.status.server.WrapperStatusServerResponse;
import com.google.gson.JsonObject;
import net.kyori.adventure.text.Component;

public class PacketEventsListener extends PacketListenerAbstract {

Expand Down Expand Up @@ -45,6 +53,20 @@ public void onPacketSend(PacketSendEvent event) {
} else if (packetType == PacketType.Play.Server.PLAYER_CHAT_HEADER
&& !platform.getApConfig().isSendHeader()) {
event.setCancelled(true);
} else if (platform.getApConfig().isExperimentalMode() && packetType == PacketType.Play.Server.CHAT_MESSAGE) {
WrapperPlayServerChatMessage wrapper = new WrapperPlayServerChatMessage(event);
ChatMessage chatMessage = wrapper.getMessage();
if (chatMessage instanceof ChatMessage_v1_19_1 message_v1_19_1) {
event.setCancelled(true);
ChatType.Bound formatting = message_v1_19_1.getChatFormatting();
Component component = message_v1_19_1.getType().getChatDecoration().decorate(message_v1_19_1.getChatContent(), formatting);
event.getUser().sendPacket(new WrapperPlayServerSystemChatMessage(false, component));
} else if (chatMessage instanceof ChatMessage_v1_19_3 message_v1_19_3) {
event.setCancelled(true);
ChatType.Bound formatting = message_v1_19_3.getChatFormatting();
Component component = message_v1_19_3.getType().getChatDecoration().decorate(message_v1_19_3.getChatContent(), formatting);
event.getUser().sendPacket(new WrapperPlayServerSystemChatMessage(false, component));
}
}
}

Expand Down
File renamed without changes.
11 changes: 9 additions & 2 deletions spigot/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,23 @@ dependencies {
implementation project(path: ":v1.20.2", configuration: "reobf")
implementation project(path: ":v1.20.4", configuration: "reobf")
implementation project(path: ":v1.20.6", configuration: "reobf")
implementation project(path: ":v1.21", configuration: "reobf")

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

implementation "org.bstats:bstats-bukkit:3.0.0"
implementation files("../lib/packetevents-spigot-2.2.1.jar")
implementation "com.github.retrooper:packetevents-spigot:${packetEventsVer}"
implementation "com.tcoded:FoliaLib:0.2.3"
}

java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
}
}

tasks {
build {
dependsOn(shadowJar)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@
import com.github.kaspiandev.antipopup.nms.v1_20_2.PlayerInjector_v1_20_2;
import com.github.kaspiandev.antipopup.nms.v1_20_4.PlayerInjector_v1_20_4;
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.spigot.api.Api;
import com.github.kaspiandev.antipopup.spigot.hook.HookManager;
import com.github.kaspiandev.antipopup.spigot.hook.viaversion.ViaVersionHook;
import com.github.kaspiandev.antipopup.spigot.hook.viaversion.Via_1_19_to_1_19_1;
import com.github.kaspiandev.antipopup.spigot.hook.viaversion.Via_1_20_4_to_1_20_5;
import com.github.kaspiandev.antipopup.spigot.listeners.ChatListener;
import com.github.kaspiandev.antipopup.spigot.nms.PlayerListener;
import com.github.kaspiandev.antipopup.spigot.platform.SpigotPlatform;
import com.github.kaspiandev.antipopup.spigot.hook.viaversion.Via_1_19_to_1_19_1;
import com.github.retrooper.packetevents.PacketEvents;
import com.github.retrooper.packetevents.manager.server.ServerManager;
import com.github.retrooper.packetevents.manager.server.ServerVersion;
Expand Down Expand Up @@ -63,7 +64,7 @@ public static AntiPopup getInstance() {
public void onLoad() {
instance = this;
PacketEvents.setAPI(SpigotPacketEventsBuilder.build(this));
PacketEvents.getAPI().getSettings().debug(false).bStats(false).checkForUpdates(false);
PacketEvents.getAPI().getSettings().debug(false).checkForUpdates(false);
PacketEvents.getAPI().load();
getLogger().info("Loaded PacketEvents.");
}
Expand Down Expand Up @@ -115,29 +116,34 @@ public void onEnable() {
}

if (config.isBlockChatReports()) {
PlayerListener playerListener = switch (serverManager.getVersion()) {
case V_1_20_5, V_1_20_6 -> new PlayerListener(new PlayerInjector_v1_20_6());
case V_1_20_3, V_1_20_4 -> new PlayerListener(new PlayerInjector_v1_20_4());
case V_1_20_2 -> new PlayerListener(new PlayerInjector_v1_20_2());
case V_1_20, V_1_20_1 -> new PlayerListener(new PlayerInjector_v1_20_1());
case V_1_19_4 -> new PlayerListener(new PlayerInjector_v1_19_4());
case V_1_19_3 -> new PlayerListener(new PlayerInjector_v1_19_3());
case V_1_19_1, V_1_19_2 -> new PlayerListener(new PlayerInjector_v1_19_2());
default -> throw new IllegalStateException("No valid injector found for the server version!");
};

pluginManager.registerEvents(playerListener, this);
getLogger().info("Hooked on " + serverManager.getVersion().getReleaseName());

Objects.requireNonNull(this.getCommand("antipopup")).setExecutor(new CommandRegister(config));
getLogger().info("Commands registered.");

if (config.isFilterNotSecure()) {
((org.apache.logging.log4j.core.Logger) LogManager.getRootLogger()).addFilter(new LogFilter());
getLogger().info("Logger filter enabled.");
if (!config.isExperimentalMode()) {
PlayerListener playerListener = switch (serverManager.getVersion()) {
case V_1_21 -> new PlayerListener(new PlayerInjector_v1_21());
case V_1_20_5, V_1_20_6 -> new PlayerListener(new PlayerInjector_v1_20_6());
case V_1_20_3, V_1_20_4 -> new PlayerListener(new PlayerInjector_v1_20_4());
case V_1_20_2 -> new PlayerListener(new PlayerInjector_v1_20_2());
case V_1_20, V_1_20_1 -> new PlayerListener(new PlayerInjector_v1_20_1());
case V_1_19_4 -> new PlayerListener(new PlayerInjector_v1_19_4());
case V_1_19_3 -> new PlayerListener(new PlayerInjector_v1_19_3());
case V_1_19_1, V_1_19_2 -> new PlayerListener(new PlayerInjector_v1_19_2());
default -> throw new IllegalStateException("No valid injector found for the server version!");
};

pluginManager.registerEvents(playerListener, this);
getLogger().info("Hooked on " + serverManager.getVersion().getReleaseName());
} else {
getLogger().info("Experimental mode is on");
}
}

Objects.requireNonNull(this.getCommand("antipopup")).setExecutor(new CommandRegister(config));
getLogger().info("Commands registered.");

if (config.isFilterNotSecure()) {
((org.apache.logging.log4j.core.Logger) LogManager.getRootLogger()).addFilter(new LogFilter());
getLogger().info("Logger filter enabled.");
}

foliaLib.getImpl().runLater(() -> {
if (config.isAutoSetup()) Api.setupAntiPopup(80, true);
if (config.isFirstRun()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import com.github.kaspiandev.antipopup.spigot.hook.Hook;
import com.github.retrooper.packetevents.PacketEvents;
import com.github.retrooper.packetevents.manager.server.ServerVersion;
import com.viaversion.viaversion.ViaVersionPlugin;
import com.viaversion.viaversion.api.Via;

import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
Expand Down Expand Up @@ -31,6 +33,9 @@ public String getPluginName() {

@Override
public void register() {
if (Via.getAPI().getVersion().startsWith("4")) {
throw new IllegalStateException("ViaVersion 4 is not supported anymore. Update to ViaVersion 5 for hooks to work!");
}
ServerVersion serverVersion = PacketEvents.getAPI().getServerManager().getVersion();
Iterator<Class<? extends ViaProtocolModifier<?>>> iterator = modifiers.iterator();
while (iterator.hasNext())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import com.github.retrooper.packetevents.manager.server.ServerVersion;
import com.github.retrooper.packetevents.manager.server.VersionComparison;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.protocols.protocol1_19_1to1_19.Protocol1_19_1To1_19;
import com.viaversion.viaversion.protocols.protocol1_19to1_18_2.ClientboundPackets1_19;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.protocols.v1_18_2to1_19.packet.ClientboundPackets1_19;
import com.viaversion.viaversion.protocols.v1_19to1_19_1.Protocol1_19To1_19_1;

public class Via_1_19_to_1_19_1 extends ViaProtocolModifier<Protocol1_19_1To1_19> {
public class Via_1_19_to_1_19_1 extends ViaProtocolModifier<Protocol1_19To1_19_1> {

public Via_1_19_to_1_19_1() {
super(VersionComparison.EQUALS, ServerVersion.V_1_19);
Expand All @@ -15,13 +15,13 @@ public Via_1_19_to_1_19_1() {
@Override
public void modify() {
protocol.appendClientbound(ClientboundPackets1_19.SERVER_DATA, (wrapper) -> {
wrapper.set(Type.BOOLEAN, 1, true);
wrapper.set(Types.BOOLEAN, 1, true);
});
}

@Override
public Class<Protocol1_19_1To1_19> getProtocolClass() {
return Protocol1_19_1To1_19.class;
public Class<Protocol1_19To1_19_1> getProtocolClass() {
return Protocol1_19To1_19_1.class;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,26 @@

import com.github.retrooper.packetevents.manager.server.ServerVersion;
import com.github.retrooper.packetevents.manager.server.VersionComparison;
import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.packet.ClientboundPackets1_20_3;
import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.Protocol1_20_5To1_20_3;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.protocols.v1_20_2to1_20_3.packet.ClientboundPackets1_20_3;
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.Protocol1_20_3To1_20_5;

public class Via_1_20_4_to_1_20_5 extends ViaProtocolModifier<Protocol1_20_5To1_20_3> {
public class Via_1_20_4_to_1_20_5 extends ViaProtocolModifier<Protocol1_20_3To1_20_5> {

public Via_1_20_4_to_1_20_5() {
super(VersionComparison.OLDER_THAN, ServerVersion.V_1_20_5);
}

@Override
public void modify() {
protocol.appendClientbound(ClientboundPackets1_20_3.JOIN_GAME, (wrapper) -> {
wrapper.set(Type.BOOLEAN, 6, true); // Enforces secure chat
protocol.appendClientbound(ClientboundPackets1_20_3.LOGIN, (wrapper) -> {
wrapper.set(Types.BOOLEAN, 6, true); // Enforces secure chat
});
}

@Override
public Class<Protocol1_20_5To1_20_3> getProtocolClass() {
return Protocol1_20_5To1_20_3.class;
public Class<Protocol1_20_3To1_20_5> getProtocolClass() {
return Protocol1_20_3To1_20_5.class;
}

}
6 changes: 6 additions & 0 deletions v1.19.2/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@ dependencies {
paperweightDevelopmentBundle "io.papermc.paper:dev-bundle:1.19.2-R0.1-SNAPSHOT"
pluginRemapper "net.fabricmc:tiny-remapper:${tinyRemapperVer}:fat"
}

java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
}
}
6 changes: 6 additions & 0 deletions v1.19.3/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@ dependencies {
paperweightDevelopmentBundle "io.papermc.paper:dev-bundle:1.19.3-R0.1-SNAPSHOT"
pluginRemapper "net.fabricmc:tiny-remapper:${tinyRemapperVer}:fat"
}

java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
}
}
6 changes: 6 additions & 0 deletions v1.19.4/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@ dependencies {
paperweightDevelopmentBundle "io.papermc.paper:dev-bundle:1.19.4-R0.1-SNAPSHOT"
pluginRemapper "net.fabricmc:tiny-remapper:${tinyRemapperVer}:fat"
}

java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
}
}
6 changes: 6 additions & 0 deletions v1.20.1/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@ dependencies {
paperweightDevelopmentBundle "io.papermc.paper:dev-bundle:1.20.1-R0.1-SNAPSHOT"
pluginRemapper "net.fabricmc:tiny-remapper:${tinyRemapperVer}:fat"
}

java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
}
}
6 changes: 6 additions & 0 deletions v1.20.2/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@ dependencies {
pluginRemapper "net.fabricmc:tiny-remapper:${tinyRemapperVer}:fat"
compileOnly "net.kyori:adventure-platform-bukkit:4.3.1"
}

java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
}
}
6 changes: 6 additions & 0 deletions v1.20.4/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@ dependencies {
paperweightDevelopmentBundle "io.papermc.paper:dev-bundle:1.20.4-R0.1-SNAPSHOT"
pluginRemapper "net.fabricmc:tiny-remapper:${tinyRemapperVer}:fat"
}

java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
}
}
9 changes: 9 additions & 0 deletions v1.20.6/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,12 @@ dependencies {
paperweightDevelopmentBundle "io.papermc.paper:dev-bundle:1.20.6-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
}
21 changes: 21 additions & 0 deletions v1.21/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-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
}
Loading

0 comments on commit 7664384

Please sign in to comment.