diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 54c9559..1ebe2fd 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -8,7 +8,7 @@ jobs: build: if: "github.event_name == 'workflow_dispatch'" - runs-on: ubuntu-20.04 + runs-on: ubuntu-22.04 steps: - uses: actions/checkout@v2.4.2 diff --git a/build.gradle b/build.gradle index ec171b8..7f87890 100644 --- a/build.gradle +++ b/build.gradle @@ -20,7 +20,7 @@ tasks { allprojects { group = "com.github.kaspiandev.antipopup" - version = "10.1" + version = "11" repositories { mavenCentral() @@ -39,7 +39,7 @@ allprojects { } maven { name = "codemc" - url = "https://repo.codemc.io/repository/maven-releases/" + url = "https://repo.codemc.io/repository/maven-public/" } } diff --git a/gradle.properties b/gradle.properties index 9d221d3..c4fc188 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -userdevVer=1.7.1 +userdevVer=2.0.0-beta.16 shadowVer=8.1.7 tinyRemapperVer=0.10.3 -packetEventsVer=2.7.0 +packetEventsVer=2.8.0-SNAPSHOT diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 7f93135..9bbc975 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 48c0a02..37f853b 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,7 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip +networkTimeout=10000 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index 0adc8e1..faf9300 100755 --- a/gradlew +++ b/gradlew @@ -15,6 +15,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # +# SPDX-License-Identifier: Apache-2.0 +# ############################################################################## # @@ -55,7 +57,7 @@ # Darwin, MinGW, and NonStop. # # (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt # within the Gradle project. # # You can find Gradle at https://github.com/gradle/gradle/. @@ -84,7 +86,7 @@ done # shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} # Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) -APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum @@ -145,7 +147,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then case $MAX_FD in #( max*) # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC3045 + # shellcheck disable=SC2039,SC3045 MAX_FD=$( ulimit -H -n ) || warn "Could not query maximum file descriptor limit" esac @@ -153,7 +155,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then '' | soft) :;; #( *) # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. - # shellcheck disable=SC3045 + # shellcheck disable=SC2039,SC3045 ulimit -n "$MAX_FD" || warn "Could not set maximum file descriptor limit to $MAX_FD" esac @@ -202,11 +204,11 @@ fi # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' -# Collect all arguments for the java command; -# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of -# shell script including quotes and variable substitutions, so put them in -# double quotes to make sure that they get re-expanded; and -# * put everything else in single quotes, so that it's not re-expanded. +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. set -- \ "-Dorg.gradle.appname=$APP_BASE_NAME" \ diff --git a/gradlew.bat b/gradlew.bat index 93e3f59..9b42019 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -1,92 +1,94 @@ -@rem -@rem Copyright 2015 the original author or authors. -@rem -@rem Licensed under the Apache License, Version 2.0 (the "License"); -@rem you may not use this file except in compliance with the License. -@rem You may obtain a copy of the License at -@rem -@rem https://www.apache.org/licenses/LICENSE-2.0 -@rem -@rem Unless required by applicable law or agreed to in writing, software -@rem distributed under the License is distributed on an "AS IS" BASIS, -@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -@rem See the License for the specific language governing permissions and -@rem limitations under the License. -@rem - -@if "%DEBUG%"=="" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%"=="" set DIRNAME=. -@rem This is normally unused -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Resolve any "." and ".." in APP_HOME to make it shorter. -for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if %ERRORLEVEL% equ 0 goto execute - -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto execute - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* - -:end -@rem End local scope for the variables with windows NT shell -if %ERRORLEVEL% equ 0 goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -set EXIT_CODE=%ERRORLEVEL% -if %EXIT_CODE% equ 0 set EXIT_CODE=1 -if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% -exit /b %EXIT_CODE% - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem +@rem SPDX-License-Identifier: Apache-2.0 +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/settings.gradle b/settings.gradle index 84ae390..d62b93e 100644 --- a/settings.gradle +++ b/settings.gradle @@ -7,5 +7,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", "v1.21", "v1.21.2", "v1.21.4", "velocity" + "v1.20.1", "v1.20.2", "v1.20.4", "v1.20.6", "v1.21", + "v1.21.2", "v1.21.4", "v1.21.5", "velocity" diff --git a/spigot/build.gradle b/spigot/build.gradle index aafec65..354bbd2 100644 --- a/spigot/build.gradle +++ b/spigot/build.gradle @@ -23,6 +23,7 @@ dependencies { implementation project(path: ":v1.21", configuration: "reobf") implementation project(path: ":v1.21.2", configuration: "reobf") implementation project(path: ":v1.21.4", configuration: "reobf") + implementation project(path: ":v1.21.5", configuration: "reobf") compileOnly "org.spigotmc:spigot-api:1.19.4-R0.1-SNAPSHOT" compileOnly "com.viaversion:viaversion:5.2.0" diff --git a/spigot/src/main/java/com/github/kaspiandev/antipopup/spigot/AntiPopup.java b/spigot/src/main/java/com/github/kaspiandev/antipopup/spigot/AntiPopup.java index 634add0..dec6931 100644 --- a/spigot/src/main/java/com/github/kaspiandev/antipopup/spigot/AntiPopup.java +++ b/spigot/src/main/java/com/github/kaspiandev/antipopup/spigot/AntiPopup.java @@ -14,6 +14,7 @@ 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.nms.v1_21_5.PlayerInjector_v1_21_5; 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; @@ -121,6 +122,7 @@ public void onEnable() { if (config.isBlockChatReports()) { if (!config.isExperimentalMode()) { PlayerListener playerListener = switch (serverManager.getVersion()) { + case V_1_21_5 -> new PlayerListener(new PlayerInjector_v1_21_5()); 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()); diff --git a/v1.21.5/build.gradle b/v1.21.5/build.gradle new file mode 100644 index 0000000..1bb1f56 --- /dev/null +++ b/v1.21.5/build.gradle @@ -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.5-R0.1-SNAPSHOT" + //pluginRemapper "net.fabricmc:tiny-remapper:0.11.1:fat" +} + +java { + disableAutoTargetJvm() + toolchain { + languageVersion.set(JavaLanguageVersion.of(21)) + } + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 +} diff --git a/v1.21.5/src/main/java/com/github/kaspiandev/antipopup/nms/v1_21_5/PlayerInjector_v1_21_5.java b/v1.21.5/src/main/java/com/github/kaspiandev/antipopup/nms/v1_21_5/PlayerInjector_v1_21_5.java new file mode 100644 index 0000000..72a6f9e --- /dev/null +++ b/v1.21.5/src/main/java/com/github/kaspiandev/antipopup/nms/v1_21_5/PlayerInjector_v1_21_5.java @@ -0,0 +1,86 @@ +package com.github.kaspiandev.antipopup.nms.v1_21_5; + +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_5 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); + } + } + +}