diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9a904436b2..b45c50c05c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -23,13 +23,12 @@ jobs: with: java-version: 21 distribution: temurin - cache: maven - - id: build - name: ${{ (github.repository == 'PGMDev/PGM' && github.ref == 'refs/heads/dev') && 'Deploy JAR' || 'Build' }} - run: | - mvn --batch-mode ${{ (github.repository == 'PGMDev/PGM' && github.ref == 'refs/heads/dev') && - 'deploy' || - 'install' }} + # Configures gradle with caching + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v4 + # Run "gradlew publish" for origin/dev and "gradlew build" for PRs or elsewhere + - name: Execute Gradle ${{ (github.repository == 'PGMDev/PGM' && github.ref == 'refs/heads/dev') && 'Publish' || 'Build' }} + run: ./gradlew ${{ (github.repository == 'PGMDev/PGM' && github.ref == 'refs/heads/dev') && 'publish' || 'build' }} env: GITHUB_TOKEN: ${{ (github.repository == 'PGMDev/PGM' && github.ref == 'refs/heads/dev') && secrets.GITHUB_TOKEN || '' }} - id: artifact @@ -37,5 +36,5 @@ jobs: uses: actions/upload-artifact@v4 with: name: PGM.jar - path: target/PGM.jar + path: build/libs/PGM.jar if-no-files-found: error diff --git a/.gitignore b/.gitignore index 41de1580fd..05c7e7ab13 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,10 @@ target/ dependency-reduced-pom.xml +# Gradle generated files +build/ +.gradle + # Mac OSX generated files .DS_Store diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts new file mode 100644 index 0000000000..c3f7477d22 --- /dev/null +++ b/buildSrc/build.gradle.kts @@ -0,0 +1,15 @@ +plugins { + // Support convention plugins written in Kotlin. Convention plugins are build scripts in 'src/main' that automatically become available as plugins in the main build. + `kotlin-dsl` +} + +repositories { + // Use the plugin portal to apply community plugins in convention plugins. + gradlePluginPortal() +} + +dependencies { + implementation("com.gradleup.shadow:shadow-gradle-plugin:8.3.0") + implementation("com.diffplug.spotless:spotless-plugin-gradle:7.0.0.BETA4") + implementation("de.skuzzle.restrictimports:restrict-imports-gradle-plugin:2.6.0") +} diff --git a/buildSrc/src/main/kotlin/buildlogic.java-conventions.gradle.kts b/buildSrc/src/main/kotlin/buildlogic.java-conventions.gradle.kts new file mode 100644 index 0000000000..16ed84a4f2 --- /dev/null +++ b/buildSrc/src/main/kotlin/buildlogic.java-conventions.gradle.kts @@ -0,0 +1,80 @@ +plugins { + `java-library` + id("com.diffplug.spotless") + id("de.skuzzle.restrictimports") +} + +java { + toolchain { + languageVersion = JavaLanguageVersion.of(21) + } +} + +repositories { + mavenLocal() + mavenCentral() + maven("https://oss.sonatype.org/content/repositories/snapshots/") // Snapshots + maven("https://repo.viaversion.com/") // Viaversion + maven("https://repo.pgm.fyi/snapshots") // Sportpaper & other pgm-specific stuff + maven("https://repo.dmulloy2.net/repository/public/") // ProtocolLib repo + maven("https://repo.papermc.io/repository/maven-public/") // Paper builds & paperweight plugin +} + +dependencies { + api("org.jdom:jdom2:2.0.6.1") + api("net.kyori:adventure-api:4.17.0") + api("net.kyori:adventure-text-serializer-plain:4.17.0") + api("net.kyori:adventure-platform-bukkit:4.3.4") + api("org.incendo:cloud-core:2.0.0") + api("org.incendo:cloud-annotations:2.0.0") + api("org.incendo:cloud-paper:2.0.0-beta.10") + api("org.incendo:cloud-minecraft-extras:2.0.0-beta.10") + api("me.lucko:commodore:2.2") + api("fr.mrmicky:fastboard:2.1.3") + api("fr.minuskube.inv:smart-invs:1.2.7") { exclude("*") } + api("org.eclipse.jgit:org.eclipse.jgit:6.7.0.202309050840-r") { exclude("*") } + api("net.objecthunter:exp4j:0.4.9-pgm") + api("org.reflections:reflections:0.10.2") + + // Optional plugin deps + compileOnly("com.comphenix.protocol:ProtocolLib:5.1.0") + compileOnly("com.viaversion:viaversion-api:5.0.0") + + // Minecraft includes these (or equivalents) + compileOnly("it.unimi.dsi:fastutil:8.1.0") + compileOnly("com.google.guava:guava:17.0") + compileOnly("com.google.code.gson:gson:2.10.1") + compileOnly("commons-lang:commons-lang:2.6") +} + +group = "tc.oc.pgm" +version = "0.16-SNAPSHOT" +description = "The original PvP Game Manager for Minecraft" + +tasks { + withType() { + options.encoding = "UTF-8" + } + withType() { + options.encoding = "UTF-8" + } +} + +spotless { + ratchetFrom = "origin/dev" + java { + removeUnusedImports() + palantirJavaFormat("2.47.0").style("GOOGLE").formatJavadoc(true) + } +} + +restrictImports { + group { + reason = "Use org.jetbrains.annotations to add annotations" + bannedImports = listOf("javax.annotation.**") + } + group { + reason = "Use tc.oc.pgm.util.Assert to add assertions" + bannedImports = listOf("com.google.common.base.Preconditions.**", "java.util.Objects.requireNonNull") + } +} \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/extensions.kt b/buildSrc/src/main/kotlin/extensions.kt new file mode 100644 index 0000000000..a173b541f0 --- /dev/null +++ b/buildSrc/src/main/kotlin/extensions.kt @@ -0,0 +1,16 @@ +import org.gradle.api.Project +import java.io.ByteArrayOutputStream + + +fun Project.latestCommitHash(): String { + return runGitCommand(listOf("rev-parse", "--short", "HEAD")) +} + +fun Project.runGitCommand(args: List): String { + val byteOut = ByteArrayOutputStream() + exec { + commandLine = listOf("git") + args + standardOutput = byteOut + } + return byteOut.toString(Charsets.UTF_8.name()).trim() +} \ No newline at end of file diff --git a/core/build.gradle.kts b/core/build.gradle.kts new file mode 100644 index 0000000000..5b0fec2b9c --- /dev/null +++ b/core/build.gradle.kts @@ -0,0 +1,95 @@ +import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar + +plugins { + id("buildlogic.java-conventions") + `maven-publish` + id("com.gradleup.shadow") +} + +dependencies { + compileOnly("dev.pgm.paper:paper-api:1.8_1.21.1-SNAPSHOT") + + implementation(project(":util")) + runtimeOnly(project(":platform-sportpaper")) { exclude("*") } + runtimeOnly(project(":platform-modern")) { exclude("*") } +} + + +tasks.named("shadowJar") { + manifest { + attributes["paperweight-mappings-namespace"] = "mojang" + } + archiveFileName = "PGM.jar" + destinationDirectory = rootProject.projectDir.resolve("build/libs") + + minimize { + // Exclude from minimization as they're required at runtime + exclude(project(":platform-sportpaper")) + exclude(project(":platform-modern")) + } + + dependencies { + exclude(dependency("com.mojang:brigadier")) // Added by commodore + // Several compile-only annotation dependencies + exclude(dependency("org.jetbrains:annotations")) + exclude(dependency("org.checkerframework:checker-qual")) + exclude(dependency("org.apiguardian:apiguardian-api")) + } + + fun pgmRelocate(basePckg: String) = relocate(basePckg, "tc.oc.pgm.lib.$basePckg") + + pgmRelocate("org.incendo.cloud") + pgmRelocate("io.leangen.geantyref") + pgmRelocate("me.lucko.commodore") + pgmRelocate("fr.mrmicky") + pgmRelocate("org.jdom2") + pgmRelocate("org.eclipse.jgit") + pgmRelocate("org.slf4j") + + exclude("META-INF/**") + exclude("**/*.html") + exclude("javax/**") // Unsure why this is even added + + // Trim unused parts of javassist + exclude("javassist/bytecode/analysis/**") + exclude("javassist/bytecode/stackmap/**") + exclude("javassist/compiler/**") +} + +publishing { + publications.create("pgm") { + groupId = rootProject.group as String + artifactId = project.name + version = rootProject.version as String + + artifact(tasks["shadowJar"]) + } + repositories { + maven { + name = "ghPackages" + url = uri("https://github.com/PGMDev/PGM") + credentials { + username = System.getenv("GITHUB_ACTOR") + password = System.getenv("GITHUB_TOKEN") + } + } + } +} + +tasks { + processResources { + filesMatching(listOf("plugin.yml")) { + expand( + "name" to project.name, + "description" to project.description, + "mainClass" to "tc.oc.pgm.PGMPlugin", + "version" to project.version, + "commitHash" to project.latestCommitHash(), + "url" to "https://pgm.dev/") + } + } + + named("build") { + dependsOn(shadowJar) + } +} \ No newline at end of file diff --git a/core/pom.xml b/core/pom.xml deleted file mode 100644 index fffc37667e..0000000000 --- a/core/pom.xml +++ /dev/null @@ -1,178 +0,0 @@ - - 4.0.0 - - - tc.oc.pgm.PGMPlugin - - - - ../pom.xml - 0.16-SNAPSHOT - tc.oc.pgm - pgm - - - Core - core - jar - - - - - tc.oc.pgm - util - 0.16-SNAPSHOT - - - - tc.oc.pgm - platform-all - 0.16-SNAPSHOT - runtime - - - - PGM-${project.version}-${git.commit.id.abbrev} - - - - ${basedir}/src/main/resources - true - - - - - org.apache.maven.plugins - maven-compiler-plugin - - - - org.incendo - cloud-annotations - 2.0.0-rc.2 - - - - - - - org.apache.maven.plugins - maven-shade-plugin - 3.5.3 - - false - true - - - tc.oc.*:*:* - org.jdom:jdom2:* - net.kyori:*:* - org.incendo:cloud-*:* - io.leangen.geantyref:*:* - me.lucko:commodore - fr.mrmicky:*:* - org.eclipse.jgit:org.eclipse.jgit:* - org.slf4j:slf4j-api:* - fr.minuskube.inv:smart-invs - net.objecthunter:exp4j:* - io.github.bananapuncher714:nbteditor:* - org.reflections:reflections:* - org.javassist:javassist:* - - - - - *:* - - META-INF/** - - - - tc.oc.pgm:platform-all:* - - ** - - - - org.javassist:javassist:* - - - **/*.java~ - **/*.html - javassist/compiler/** - javassist/bytecode/analysis/** - javassist/bytecode/stackmap/** - - - - - - org.incendo.cloud - tc.oc.pgm.lib.org.incendo.cloud - - - io.leangen.geantyref - tc.oc.pgm.lib.io.leangen.geantyref - - - me.lucko.commodore - tc.oc.pgm.lib.me.lucko.commodore - - - fr.mrmicky - tc.oc.pgm.lib.fr.mrmicky - - - org.jdom2 - tc.oc.pgm.lib.org.jdom2 - - - org.eclipse.jgit - tc.oc.pgm.lib.org.eclipse.jgit - - - org.slf4j - tc.oc.pgm.lib.org.slf4j - - - - - - mojang - - - - - - - package - - shade - - - - - - - maven-antrun-plugin - 3.1.0 - - - jar - package - - - - - - - run - - - - - - - diff --git a/core/src/main/java/tc/oc/pgm/command/ShowXmlCommand.java b/core/src/main/java/tc/oc/pgm/command/ShowXmlCommand.java index 0b1f99b49d..02867f5a49 100644 --- a/core/src/main/java/tc/oc/pgm/command/ShowXmlCommand.java +++ b/core/src/main/java/tc/oc/pgm/command/ShowXmlCommand.java @@ -6,7 +6,7 @@ import com.google.common.io.ByteArrayDataInput; import com.google.common.io.ByteArrayDataOutput; import com.google.common.io.ByteStreams; -import java.awt.*; +import java.awt.Desktop; import java.io.IOException; import java.net.InetAddress; import java.net.UnknownHostException; diff --git a/core/src/main/resources/plugin.yml b/core/src/main/resources/plugin.yml index 4ca131674b..61e6472092 100644 --- a/core/src/main/resources/plugin.yml +++ b/core/src/main/resources/plugin.yml @@ -1,7 +1,7 @@ name: PGM api-version: 1.20.6 softdepend: [ViaVersion, ProtocolLib] -description: ${project.parent.description} -main: ${project.mainClass} -version: ${project.version} (git-${git.commit.id.abbrev}) -website: ${project.parent.url} +description: ${description} +main: ${mainClass} +version: ${version} (git-${commitHash}) +website: ${url} diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000000..a4b76b9530 Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000000..9355b41557 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,7 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip +networkTimeout=10000 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100755 index 0000000000..f5feea6d6b --- /dev/null +++ b/gradlew @@ -0,0 +1,252 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# 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/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +# This is normally unused +# 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 -P "${APP_HOME:-./}" > /dev/null && printf '%s +' "$PWD" ) || exit + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +fi + +# Increase the maximum file descriptors if we can. +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=SC2039,SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +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, 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" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/platform/platform-all/pom.xml b/platform/platform-all/pom.xml deleted file mode 100644 index 3269c0bfdd..0000000000 --- a/platform/platform-all/pom.xml +++ /dev/null @@ -1,63 +0,0 @@ - - 4.0.0 - - ../pom.xml - 0.16-SNAPSHOT - tc.oc.pgm - platform - - - platform-all - jar - - - - tc.oc.pgm - platform-modern - 0.16-SNAPSHOT - runtime - - - - tc.oc.pgm - platform-sportpaper - 0.16-SNAPSHOT - runtime - - - - - - org.apache.maven.plugins - maven-shade-plugin - 3.4.1 - - false - false - - - tc.oc.pgm:*:* - - - - - *:* - - META-INF/** - - - - - - - package - - shade - - - - - - - diff --git a/platform/platform-modern/build.gradle.kts b/platform/platform-modern/build.gradle.kts new file mode 100644 index 0000000000..60828e931d --- /dev/null +++ b/platform/platform-modern/build.gradle.kts @@ -0,0 +1,10 @@ +plugins { + id("buildlogic.java-conventions") + id("io.papermc.paperweight.userdev") version "1.7.4" +} + +dependencies { + implementation(project(":util")) + paperweight.paperDevBundle("1.21.1-R0.1-SNAPSHOT") +} +paperweight.reobfArtifactConfiguration = io.papermc.paperweight.userdev.ReobfArtifactConfiguration.MOJANG_PRODUCTION diff --git a/platform/platform-modern/pom.xml b/platform/platform-modern/pom.xml deleted file mode 100644 index a7794c417c..0000000000 --- a/platform/platform-modern/pom.xml +++ /dev/null @@ -1,51 +0,0 @@ - - - 4.0.0 - - ../pom.xml - 0.16-SNAPSHOT - tc.oc.pgm - platform - - - platform-modern - jar - - - - io.papermc.paper - paper-api - 1.21.1-R0.1-SNAPSHOT - provided - - - io.papermc.paper - paper - 1.21.1-R0.1-SNAPSHOT - provided - - - - com.google.guava - guava - 32.1.2-jre - provided - - - - com.mojang - authlib - 6.0.54 - provided - - - com.mojang - datafixerupper - 7.0.14 - provided - - - - \ No newline at end of file diff --git a/platform/platform-sportpaper/build.gradle.kts b/platform/platform-sportpaper/build.gradle.kts new file mode 100644 index 0000000000..6af8a21a48 --- /dev/null +++ b/platform/platform-sportpaper/build.gradle.kts @@ -0,0 +1,8 @@ +plugins { + id("buildlogic.java-conventions") +} + +dependencies { + implementation(project(":util")) + compileOnly("app.ashcon:sportpaper:1.8.8-R0.1-SNAPSHOT") +} diff --git a/platform/platform-sportpaper/pom.xml b/platform/platform-sportpaper/pom.xml deleted file mode 100644 index 4f95ea63f4..0000000000 --- a/platform/platform-sportpaper/pom.xml +++ /dev/null @@ -1,26 +0,0 @@ - - - 4.0.0 - - ../pom.xml - 0.16-SNAPSHOT - tc.oc.pgm - platform - - - platform-sportpaper - jar - - - - - app.ashcon - sportpaper - 1.8.8-R0.1-SNAPSHOT - provided - - - - \ No newline at end of file diff --git a/platform/pom.xml b/platform/pom.xml deleted file mode 100644 index 858b96f2ee..0000000000 --- a/platform/pom.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - 4.0.0 - - tc.oc.pgm - pgm - 0.16-SNAPSHOT - - - platform - pom - - platform-sportpaper - platform-modern - platform-all - - - - - tc.oc.pgm - util - 0.16-SNAPSHOT - provided - - - \ No newline at end of file diff --git a/pom.xml b/pom.xml deleted file mode 100644 index 0a5de4abd7..0000000000 --- a/pom.xml +++ /dev/null @@ -1,394 +0,0 @@ - - 4.0.0 - - - 21 - 21 - UTF-8 - none - - - PGM - The original PvP Game Manager for Minecraft. - 2011 - - https://pgm.dev/ - - https://github.com/PGMDev/PGM/issues - - - scm:git:git://github.com/PGMDev/PGM - - - - - electroid - Ashcon Partovi - - - - tc.oc.pgm - pgm - 0.16-SNAPSHOT - pom - - - util - core - server - platform - - - - - sonatype-oss - https://oss.sonatype.org/content/repositories/snapshots - - - spigotmc-org - https://hub.spigotmc.org/nexus/content/repositories/snapshots - - - jitpack-io - https://jitpack.io/ - - - viaversion-com - https://repo.viaversion.com/ - - - pgm-fyi - https://repo.pgm.fyi/snapshots - - - dmulloy2-repo - https://repo.dmulloy2.net/repository/public/ - - - CodeMC - https://repo.codemc.org/repository/maven-public/ - - - paper - https://repo.papermc.io/repository/maven-public/ - - - - - - github - https://maven.pkg.github.com/PGMDev/PGM - - - - - - - org.spigotmc. - spigot-api - 1.8.8-R0.1-SNAPSHOT - test - - - - - dev.pgm.paper - paper-api - 1.8_1.21.1-SNAPSHOT - provided - - - - - it.unimi.dsi - fastutil - 8.1.0 - provided - - - com.google.guava - guava - 17.0 - provided - - - com.google.code.gson - gson - 2.10.1 - provided - - - commons-lang - commons-lang - 2.6 - provided - - - - - com.viaversion - viaversion-api - 5.0.0 - provided - true - - - - - com.comphenix.protocol - ProtocolLib - 5.1.0 - - - - - org.jdom - jdom2 - 2.0.6.1 - compile - - - - - net.kyori - adventure-api - 4.17.0 - compile - - - net.kyori - adventure-text-serializer-plain - 4.17.0 - compile - - - net.kyori - adventure-platform-bukkit - 4.3.4 - compile - - - - org.spigotmc - spigot-api - - - - - - - org.incendo - cloud-core - 2.0.0 - compile - - - org.incendo - cloud-annotations - 2.0.0 - compile - - - org.incendo - cloud-paper - 2.0.0-beta.10 - compile - - - org.incendo - cloud-minecraft-extras - 2.0.0-beta.10 - compile - - - - me.lucko - commodore - 2.2 - compile - - - - - fr.mrmicky - FastBoard - 2.1.3 - compile - - - - - io.github.bananapuncher714 - nbteditor - 7.18.5 - - - - - fr.minuskube.inv - smart-invs - 1.2.7 - compile - - - org.spigotmc - spigot-api - - - - - - - org.eclipse.jgit - org.eclipse.jgit - 6.7.0.202309050840-r - compile - - - - - - net.objecthunter - exp4j - 0.4.9-pgm - compile - - - - - org.reflections - reflections - 0.10.2 - - - - org.junit.jupiter - junit-jupiter - 5.9.2 - test - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.11.0 - - - - - pl.project13.maven - git-commit-id-plugin - 4.9.10 - - - - revision - - - - - false - false - - - - - - com.diffplug.spotless - spotless-maven-plugin - 2.43.0 - - origin/dev - - - - 2.47.0 - - true - - - - - - - check - - - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - 3.5.0 - - false - true - - - - - org.apache.maven.plugins - maven-enforcer-plugin - 3.2.1 - - - de.skuzzle.enforcer - restrict-imports-enforcer-rule - 2.1.0 - - - - - - enforce-jdk - - enforce - - - - - - [${maven.compiler.target},) - - - - - - - enforce-imports - process-sources - - enforce - - - - - Use org.jetbrains.annotations to add annotations - javax.annotation.** - - - Use tc.oc.pgm.util.Assert to add assertions - - com.google.common.base.Preconditions.** - java.util.Objects.requireNonNull - - - - - - - - - - org.apache.maven.plugins - maven-surefire-plugin - 3.1.2 - - - - diff --git a/server/build.gradle.kts b/server/build.gradle.kts new file mode 100644 index 0000000000..a608736ef2 --- /dev/null +++ b/server/build.gradle.kts @@ -0,0 +1,10 @@ +plugins { + id("buildlogic.java-conventions") +} + +dependencies { + implementation("app.ashcon:sportpaper:1.8.8-R0.1-SNAPSHOT") + implementation(project(":core")) + implementation(project(":util")) + implementation("log4j:log4j:1.2.12") +} \ No newline at end of file diff --git a/server/pom.xml b/server/pom.xml deleted file mode 100644 index ef6cbfbd87..0000000000 --- a/server/pom.xml +++ /dev/null @@ -1,120 +0,0 @@ - - 4.0.0 - - - tc.oc.pgm.server.PGMServer - - - - ../pom.xml - 0.16-SNAPSHOT - tc.oc.pgm - pgm - - - Server - An out-of-the-box Bukkit server preloaded with PGM. - server - jar - - - - app.ashcon - sportpaper - 1.8.8-R0.1-SNAPSHOT - compile - - - - tc.oc.pgm - core - 0.16-SNAPSHOT - - - - - log4j - log4j - 1.2.12 - - - - PGM-Server-${project.version}-${git.commit.id.abbrev} - - - org.apache.maven.plugins - maven-jar-plugin - 3.3.0 - - - - true - ${project.mainClass} - - - - - - - org.apache.maven.plugins - maven-shade-plugin - 3.4.1 - - false - - false - - - tc.oc.pgm:core:* - app.ashcon:sportpaper:* - log4j:log4j:* - - - - - log4j:log4j:* - - META-INF/** - - - - app.ashcon:sportpaper:* - - META-INF/MANIFEST.MF - - - - - - - package - - shade - - - - - - - - maven-antrun-plugin - 3.1.0 - - - package - - - - - - - run - - - - - - - diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 0000000000..24cf709d65 --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1,9 @@ +rootProject.name = "pgm" + +include(":util") +include(":platform-sportpaper") +include(":platform-modern") +include(":core") +include(":server") +project(":platform-sportpaper").projectDir = file("platform/platform-sportpaper") +project(":platform-modern").projectDir = file("platform/platform-modern") diff --git a/util/build.gradle.kts b/util/build.gradle.kts new file mode 100644 index 0000000000..b00980da4e --- /dev/null +++ b/util/build.gradle.kts @@ -0,0 +1,20 @@ +plugins { + id("buildlogic.java-conventions") +} + +dependencies { + compileOnly("dev.pgm.paper:paper-api:1.8_1.21.1-SNAPSHOT") + testImplementation("io.papermc.paper:paper-api:1.21.1-R0.1-SNAPSHOT") + testImplementation("org.junit.jupiter:junit-jupiter:5.9.2") +} + +sourceSets { + main { + resources { + srcDirs( + "src/main/resources", + "src/main/i18n/templates", + "src/main/i18n/translations") + } + } +} diff --git a/util/pom.xml b/util/pom.xml deleted file mode 100644 index 36b1904326..0000000000 --- a/util/pom.xml +++ /dev/null @@ -1,31 +0,0 @@ - - 4.0.0 - - ../pom.xml - 0.16-SNAPSHOT - tc.oc.pgm - pgm - - - Util - util - jar - - - - - src/main/i18n/templates - - **/*.properties - - - - src/main/i18n/translations - - **/*.properties - - - - - diff --git a/util/src/main/java/tc/oc/pgm/util/nms/reflect/Refl.java b/util/src/main/java/tc/oc/pgm/util/nms/reflect/Refl.java deleted file mode 100644 index d0809e2098..0000000000 --- a/util/src/main/java/tc/oc/pgm/util/nms/reflect/Refl.java +++ /dev/null @@ -1,204 +0,0 @@ -package tc.oc.pgm.util.nms.reflect; - -import java.util.Map; -import java.util.Set; -import java.util.concurrent.Callable; -import org.bukkit.Material; -import org.bukkit.Server; -import org.bukkit.World; -import org.bukkit.entity.Entity; -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; -import org.bukkit.inventory.meta.SkullMeta; - -public interface Refl { - - @Reflect.CB("inventory.CraftMetaItem.unhandledTags") - Map getUnhandledTags(ItemMeta item); - - @Reflect.CB("inventory.CraftMetaSkull.profile") - void setSkullProfile(SkullMeta meta, Object profile); - - @Reflect.CB("entity.CraftPlayer.getHandle()") - Object getPlayerHandle(Player player); - - @Reflect.CB("entity.CraftEntity.getHandle()") - Object getEntityHandle(Entity entity); - - @Reflect.NMS("EntityFireball.dirX") - void setFireballDirX(Object fireball, double amount); - - @Reflect.NMS("EntityFireball.dirY") - void setFireballDirY(Object fireball, double amount); - - @Reflect.NMS("EntityFireball.dirZ") - void setFireballDirZ(Object fireball, double amount); - - @Reflect.NMS("Entity.getWorld()") - Object getNmsWorldFromEntity(Object handle); - - @Reflect.NMS("Entity.getId()") - int getEntityId(Object handle); - - @Reflect.NMS("WorldServer.getTracker()") - Object getEntityTracker(Object worldServer); - - @Reflect.NMS("EntityTracker.trackedEntities") - Object getTrackedEntities(Object entityTracker); - - @Reflect.NMS(value = "IntHashMap.get()", parameters = int.class) - Object getIntHashMapMethod(Object intHashMap, int id); - - @Reflect.NMS("EntityTrackerEntry.trackedPlayers") - Set getTrackedPlayers(Object trackerEntry); - - @Reflect.NMS("EntityPlayer.getBukkitEntity()") - Player getBukkitPlayer(Object nmsHandle); - - @Reflect.NMS("EntityPlayer.ping") - int getPlayerPing(Object handle); - - @Reflect.CB("CraftWorld.getHandle()") - Object getWorldHandle(World world); - - @Reflect.NMS("World.getTime()") - long getWorldTime(Object handle); - - @Reflect.CB("CraftServer.getHandle()") - Object getCraftServerHandle(Server server); - - @Reflect.CB("entity.CraftLivingEntity.getHandle()") - Object getCraftEntityHandle(LivingEntity entity); - - @Reflect.NMS("EntityLiving.getAbsorptionHearts()") - float getAbsorptionHearts(Object entity); - - @Reflect.NMS(value = "EntityLiving.setAbsorptionHearts()", parameters = float.class) - void setAbsorptionHearts(Object entity, float hearts); - - @Reflect.NMS("DedicatedPlayerList.getServer()") - Object getNMSServer(Object handle); - - @Reflect.NMS(value = "MinecraftServer.a()", parameters = Callable.class) - void addCallableToMainThread(Object nmsServer, Callable callable); - - @Reflect.NMS(value = "Item.canDestroySpecialBlock()", parameters = IBlockData.class) - boolean canDestroySpecialBlock(Object nmsItem, Object blockData); - - @Reflect.NMS("Material.isAlwaysDestroyable()") - boolean isAlwaysDestroyable(Object material); - - @Reflect.CB("inventory.CraftItemStack") - interface CraftItemStack { - @Reflect.StaticMethod(value = "asCraftCopy", parameters = ItemStack.class) - ItemStack asCraftCopy(ItemStack itemStack); - } - - @Reflect.NMS("NBTBase") - interface NBTBase {} - - @Reflect.NMS("NBTTagString") - interface NBTTagString { - - @Reflect.Constructor(String.class) - Object build(String string); - - @Reflect.Method("a_") - @Reflect.Method("c_") - String getString(Object item); - }; - - @Reflect.NMS("NBTTagList") - interface NBTTagList { - - @Reflect.Field("list") - Object getListField(Object self); - - @Reflect.Constructor - Object build(); - - @Reflect.Method("size") - int size(Object self); - - @Reflect.Method(value = "get", parameters = int.class) - Object get(Object self, int index); - - @Reflect.Method(value = "add", parameters = NBTBase.class) - void add(Object self, Object value); - - @Reflect.Method("isEmpty") - boolean isEmpty(Object self); - } - - @Reflect.NMS("NBTTagCompound") - interface NBTTagCompound { - - @Reflect.Constructor - Object build(); - - @Reflect.Method(value = "getString", parameters = String.class) - String getString(Object self, String parameter); - - @Reflect.Method(value = "getLong", parameters = String.class) - long getLong(Object self, String parameter); - - @Reflect.Method(value = "getDouble", parameters = String.class) - double getDouble(Object self, String parameter); - - @Reflect.Method(value = "getInt", parameters = String.class) - int getInt(Object self, String parameter); - - @Reflect.Method( - value = "setString", - parameters = {String.class, String.class}) - void setString(Object self, String parameter, String value); - - @Reflect.Method( - value = "setLong", - parameters = {String.class, long.class}) - void setLong(Object self, String parameter, long value); - - @Reflect.Method( - value = "setDouble", - parameters = {String.class, double.class}) - void setDouble(Object self, String parameter, double value); - - @Reflect.Method( - value = "setInt", - parameters = {String.class, int.class}) - void setInt(Object self, String parameter, int value); - } - - @Reflect.CB("util.CraftMagicNumbers") - interface CraftMagicNumbers { - @Reflect.StaticMethod(value = "getItem", parameters = Material.class) - Object getItem(Material material); - - @Reflect.StaticMethod(value = "getBlock", parameters = Material.class) - Object getBlock(Material material); - } - - @Reflect.NMS("Block") - interface Block { - - @Reflect.StaticMethod(value = "getByName", parameters = String.class) - Object getBlockByName(String name); - - @Reflect.StaticMethod(value = "getId", parameters = Block.class) - int getId(Object self); - - @Reflect.Method("getBlockData") - Object getBlockData(Object self); - - @Reflect.Method(value = "q", parameters = IBlockData.class) - Object getMaterial(Object self, Object blockData); - } - - @Reflect.NMS("IBlockData") - interface IBlockData { - @Reflect.Method("getMaterial") - Object getMaterial(Object self); - } -} diff --git a/util/src/main/java/tc/oc/pgm/util/nms/reflect/Reflect.java b/util/src/main/java/tc/oc/pgm/util/nms/reflect/Reflect.java deleted file mode 100644 index ea1bf688f2..0000000000 --- a/util/src/main/java/tc/oc/pgm/util/nms/reflect/Reflect.java +++ /dev/null @@ -1,108 +0,0 @@ -package tc.oc.pgm.util.nms.reflect; - -import java.lang.annotation.Repeatable; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; - -@Retention(RetentionPolicy.RUNTIME) -public @interface Reflect { - @Retention(RetentionPolicy.RUNTIME) - @Repeatable(NMS.List.class) - @interface NMS { - String value(); - - Class[] parameters() default {}; - - @Retention(RetentionPolicy.RUNTIME) - @interface List { - NMS[] value(); - } - } - - @Retention(RetentionPolicy.RUNTIME) - @Repeatable(CB.List.class) - @interface CB { - String value(); - - Class[] parameters() default {}; - - @Retention(RetentionPolicy.RUNTIME) - @interface List { - CB[] value(); - } - } - - @Retention(RetentionPolicy.RUNTIME) - @Repeatable(B.List.class) - @interface B { - String value(); - - Class[] parameters() default {}; - - @Retention(RetentionPolicy.RUNTIME) - @interface List { - B[] value(); - } - } - - @Retention(RetentionPolicy.RUNTIME) - @Repeatable(Direct.List.class) - @interface Direct { - String value(); - - Class[] parameters() default {}; - - @Retention(RetentionPolicy.RUNTIME) - @interface List { - Direct[] value(); - } - } - - @Retention(RetentionPolicy.RUNTIME) - @Repeatable(StaticMethod.List.class) - @interface StaticMethod { - String value(); - - Class[] parameters() default {}; - - @Retention(RetentionPolicy.RUNTIME) - @interface List { - StaticMethod[] value(); - } - } - - @Retention(RetentionPolicy.RUNTIME) - @Repeatable(Method.List.class) - @interface Method { - String value(); - - Class[] parameters() default {}; - - @Retention(RetentionPolicy.RUNTIME) - @interface List { - Method[] value(); - } - } - - @Retention(RetentionPolicy.RUNTIME) - @Repeatable(Field.List.class) - @interface Field { - String value(); - - @Retention(RetentionPolicy.RUNTIME) - @interface List { - Field[] value(); - } - } - - @Retention(RetentionPolicy.RUNTIME) - @Repeatable(Constructor.List.class) - @interface Constructor { - Class[] value() default {}; - - @Retention(RetentionPolicy.RUNTIME) - @interface List { - Constructor[] value(); - } - } -} diff --git a/util/src/main/java/tc/oc/pgm/util/nms/reflect/ReflectionProxy.java b/util/src/main/java/tc/oc/pgm/util/nms/reflect/ReflectionProxy.java deleted file mode 100644 index bef587b27a..0000000000 --- a/util/src/main/java/tc/oc/pgm/util/nms/reflect/ReflectionProxy.java +++ /dev/null @@ -1,361 +0,0 @@ -package tc.oc.pgm.util.nms.reflect; - -import java.lang.reflect.Constructor; -import java.lang.reflect.Field; -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.Method; -import java.lang.reflect.Proxy; -import java.util.Arrays; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; -import java.util.function.Function; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import tc.oc.pgm.util.reflect.MinecraftReflectionUtils; -import tc.oc.pgm.util.reflect.ReflectionUtils; - -public class ReflectionProxy implements InvocationHandler { - - static Map> functionMap = new ConcurrentHashMap<>(); - - static ReflectionProxy INSTANCE = new ReflectionProxy(); - - public static T getProxy(Class classType) { - return (T) - Proxy.newProxyInstance( - ReflectionProxy.class.getClassLoader(), new Class[] {classType}, INSTANCE); - } - - @Override - public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { - return functionMap - .computeIfAbsent( - method, - (input) -> { - Class declaringClass = method.getDeclaringClass(); - Class parentClass = getAnnotatedClass(declaringClass); - if (parentClass == null) { - return processComponent(method, args); - } else { - return processComponent(method, args, parentClass); - } - }) - .apply(args); - } - - @Nullable - private static Function processComponent(Method method, Object[] args) { - if (method.getDeclaredAnnotationsByType(Reflect.NMS.class).length > 0) { - return processNMSComponent(method, args); - } else if (method.getDeclaredAnnotationsByType(Reflect.CB.class).length > 0) { - return processCBComponent(method, args); - } else if (method.getDeclaredAnnotationsByType(Reflect.B.class).length > 0) { - return processBukkitComponent(method, args); - } - throw new RuntimeException("Error processing Method: " + method); - } - - @Nullable - private static Function processComponent( - Method method, Object[] args, Class parentClass) { - if (method.getDeclaredAnnotationsByType(Reflect.StaticMethod.class).length > 0) { - return processStaticMethod(method, parentClass); - } else if (method.getDeclaredAnnotationsByType(Reflect.Method.class).length > 0) { - return processMethod(method, args, parentClass); - } else if (method.getDeclaredAnnotationsByType(Reflect.Field.class).length > 0) { - return processField(method, args, parentClass); - } else if (method.getDeclaredAnnotationsByType(Reflect.Constructor.class).length > 0) { - return processConstructor(method, parentClass); - } - throw new RuntimeException("Error processing method: " + method); - } - - private static Function processStaticMethod( - Method method, Class parentClass) { - for (Reflect.StaticMethod staticMethod : - method.getDeclaredAnnotationsByType(Reflect.StaticMethod.class)) { - try { - Method reflectedMethod = - parentClass.getMethod( - staticMethod.value(), processParameters(staticMethod.parameters())); - return (input) -> ReflectionUtils.callMethod(reflectedMethod, null, input); - } catch (NoSuchMethodException e) { - } - } - throw new RuntimeException("Method not found for " + method); - } - - private static Function processMethod( - Method method, Object[] args, Class parentClass) { - for (Reflect.Method reflectMethod : method.getDeclaredAnnotationsByType(Reflect.Method.class)) { - try { - Method reflectedMethod = - parentClass.getMethod( - reflectMethod.value(), processParameters(reflectMethod.parameters())); - return callMethod(args, reflectedMethod); - } catch (NoSuchMethodException ignored) { - } - } - throw new RuntimeException("Method not found for " + method); - } - - @Nullable - private static Function processField( - Method method, Object[] args, Class parentClass) { - for (Reflect.Field field : method.getDeclaredAnnotationsByType(Reflect.Field.class)) { - try { - Field reflectedField = parentClass.getDeclaredField(field.value()); - reflectedField.setAccessible(true); - return performActionOnField(args, reflectedField); - } catch (NoSuchFieldException ignored) { - } - } - throw new RuntimeException("Field not found for " + method); - } - - @NotNull - private static Function processConstructor( - Method method, Class parentClass) { - for (Reflect.Constructor constructor : - method.getDeclaredAnnotationsByType(Reflect.Constructor.class)) { - try { - Constructor reflectedConstructor = - parentClass.getConstructor(processParameters(constructor.value())); - return (input) -> ReflectionUtils.callConstructor(reflectedConstructor, input); - } catch (NoSuchMethodException ignored) { - } - } - throw new RuntimeException("Constructor not found for " + method); - } - - @Nullable - private static Function processBukkitComponent(Method method, Object[] args) { - for (Reflect.B bukkit : method.getDeclaredAnnotationsByType(Reflect.B.class)) { - String methodPath = bukkit.value(); - Class[] parameters = bukkit.parameters(); - - String[] split = splitClassAndMethod(methodPath); - - String className = split[0]; - String methodName = split[1]; - - Class parentClass; - try { - parentClass = MinecraftReflectionUtils.getBukkitClass(className); - } catch (RuntimeException ignored) { - continue; - } - - if (methodName.endsWith("()")) { - Method reflectedMethod = parseStandaloneMethod(parentClass, methodName, parameters); - if (reflectedMethod != null) { - return callMethod(args, reflectedMethod); - } - } else { - Field reflectedField = parseStandaloneField(parentClass, methodName); - if (reflectedField != null) { - return performActionOnField(args, reflectedField); - } - } - } - throw new RuntimeException("Error processing Method: " + method); - } - - @Nullable - private static Function processCBComponent(Method method, Object[] args) { - for (Reflect.CB cb : method.getDeclaredAnnotationsByType(Reflect.CB.class)) { - String methodPath = cb.value(); - Class[] parameters = cb.parameters(); - - String[] split = splitClassAndMethod(methodPath); - - String className = split[0]; - String methodName = split[1]; - - Class parentClass; - try { - parentClass = MinecraftReflectionUtils.getCraftBukkitClass(className); - } catch (RuntimeException ignored) { - continue; - } - - if (methodName.endsWith("()")) { - Method reflectedMethod = parseStandaloneMethod(parentClass, methodName, parameters); - if (reflectedMethod != null) { - return callMethod(args, reflectedMethod); - } - } else { - Field reflectedField = parseStandaloneField(parentClass, methodName); - if (reflectedField != null) { - return performActionOnField(args, reflectedField); - } - } - } - throw new RuntimeException("Error processing Method: " + method); - } - - @Nullable - private static Function processNMSComponent(Method method, Object[] args) { - for (Reflect.NMS nms : method.getDeclaredAnnotationsByType(Reflect.NMS.class)) { - String methodPath = nms.value(); - Class[] parameters = nms.parameters(); - - String[] split = splitClassAndMethod(methodPath); - - String className = split[0]; - String methodName = split[1]; - - Class parentClass; - parentClass = findNMSClass(className); - if (parentClass == null) continue; - - if (methodName.endsWith("()")) { - Method reflectedMethod = parseStandaloneMethod(parentClass, methodName, parameters); - if (reflectedMethod != null) { - return callMethod(args, reflectedMethod); - } - } else { - Field reflectedField = parseStandaloneField(parentClass, methodName); - if (reflectedField != null) { - return performActionOnField(args, reflectedField); - } - } - } - throw new RuntimeException("Error processing Method: " + method); - } - - @Nullable - private static Function performActionOnField( - Object[] args, Field reflectedField) { - if (args.length == 0) { - throw new UnsupportedOperationException("Annotated fields must have more than 0 parameters!"); - } else if (args.length == 1) { - return (input) -> ReflectionUtils.readField(input[0], reflectedField); - } else if (args.length == 2) { - return (input) -> { - ReflectionUtils.setField(input[0], input[1], reflectedField); - return null; - }; - } else { - throw new UnsupportedOperationException("Annotated fields must have less than 3 parameters!"); - } - } - - private static Function callMethod(Object[] args, Method reflectedMethod) { - if (args.length > 1) { - return (input) -> - ReflectionUtils.callMethod( - reflectedMethod, input[0], Arrays.copyOfRange(input, 1, input.length)); - } else { - return (input) -> ReflectionUtils.callMethod(reflectedMethod, input[0]); - } - } - - @Nullable - private static Field parseStandaloneField(Class parentClass, String methodName) { - Field reflectedField; - try { - reflectedField = parentClass.getDeclaredField(methodName); - reflectedField.setAccessible(true); - } catch (NoSuchFieldException e) { - return null; - } - return reflectedField; - } - - @Nullable - private static Method parseStandaloneMethod( - Class parentClass, String methodName, Class[] parameters) { - Method reflectedMethod; - methodName = methodName.substring(0, methodName.length() - 2); - try { - if (parameters.length > 0) { - reflectedMethod = parentClass.getMethod(methodName, processParameters(parameters)); - } else { - reflectedMethod = parentClass.getMethod(methodName); - } - reflectedMethod.setAccessible(true); - } catch (NoSuchMethodException e) { - return null; - } - return reflectedMethod; - } - - private static Class[] processParameters(Class[] givenParameters) { - Class[] parameters = new Class[givenParameters.length]; - - for (int i = 0; i < givenParameters.length; i++) { - try { - Class annotatedClass = getAnnotatedClass(givenParameters[i]); - if (annotatedClass != null) { - parameters[i] = annotatedClass; - break; - } - } catch (RuntimeException ignored) { - } - parameters[i] = givenParameters[i]; - } - - return parameters; - } - - @NotNull - private static String[] splitClassAndMethod(String fieldMethodPath) { - String[] split = new String[2]; - int index = fieldMethodPath.lastIndexOf("."); - split[0] = fieldMethodPath.substring(0, index); - split[1] = fieldMethodPath.substring(index + 1); - return split; - } - - private static Class getAnnotatedClass(Class declaringClass) { - if (declaringClass.isAnnotationPresent(Reflect.Direct.class)) { - for (Reflect.Direct direct : - declaringClass.getDeclaredAnnotationsByType(Reflect.Direct.class)) { - Class parentClass = ReflectionUtils.getClassFromName(direct.value()); - if (parentClass != null) { - return parentClass; - } - } - throw new RuntimeException("Class not found for " + declaringClass); - } else if (declaringClass.isAnnotationPresent(Reflect.NMS.class)) { - for (Reflect.NMS nms : declaringClass.getDeclaredAnnotationsByType(Reflect.NMS.class)) { - Class parentClass = findNMSClass(nms.value()); - if (parentClass != null) { - return parentClass; - } - } - throw new RuntimeException("Class not found for " + declaringClass); - } else if (declaringClass.isAnnotationPresent(Reflect.CB.class)) { - for (Reflect.CB cb : declaringClass.getDeclaredAnnotationsByType(Reflect.CB.class)) { - try { - return MinecraftReflectionUtils.getCraftBukkitClass(cb.value()); - } catch (RuntimeException ignored) { - } - } - throw new RuntimeException("Class not found for " + declaringClass); - } else if (declaringClass.isAnnotationPresent(Reflect.B.class)) { - for (Reflect.B bukkit : declaringClass.getDeclaredAnnotationsByType(Reflect.B.class)) { - try { - return MinecraftReflectionUtils.getBukkitClass(bukkit.value()); - } catch (RuntimeException ignored) { - } - } - throw new RuntimeException("Class not found for " + declaringClass); - } - return null; - } - - private static Class findNMSClass(String className) { - Class parentClass = null; - try { - parentClass = MinecraftReflectionUtils.getNMSClassLegacy(className); - } catch (RuntimeException ignored) { - } - try { - parentClass = MinecraftReflectionUtils.getNMSClassNew(className); - } catch (RuntimeException ignored) { - } - return parentClass; - } -} diff --git a/util/src/main/java/tc/oc/pgm/util/platform/AbstractPlatform.java b/util/src/main/java/tc/oc/pgm/util/platform/AbstractPlatform.java deleted file mode 100644 index 3dacc37f21..0000000000 --- a/util/src/main/java/tc/oc/pgm/util/platform/AbstractPlatform.java +++ /dev/null @@ -1,10 +0,0 @@ -package tc.oc.pgm.util.platform; - -public abstract class AbstractPlatform { - - public AbstractPlatform() { - Supports support = getClass().getAnnotation(Supports.class); - } - - public abstract T getInstance(Class clazz); -} diff --git a/util/src/main/java/tc/oc/pgm/util/reflect/MinecraftReflectionUtils.java b/util/src/main/java/tc/oc/pgm/util/reflect/MinecraftReflectionUtils.java deleted file mode 100644 index 2fbfe3a3d8..0000000000 --- a/util/src/main/java/tc/oc/pgm/util/reflect/MinecraftReflectionUtils.java +++ /dev/null @@ -1,49 +0,0 @@ -package tc.oc.pgm.util.reflect; - -import io.github.bananapuncher714.nbteditor.NBTEditor; -import org.bukkit.Bukkit; - -public interface MinecraftReflectionUtils { - String VERSION = Bukkit.getServer().getClass().getPackage().getName().split("\\.")[3]; - - NBTEditor.MinecraftVersion MINECRAFT_VERSION = NBTEditor.getMinecraftVersion(); - - double VERSION_NUMBER = parseVersionNumber(); - - static double parseVersionNumber() { - String[] split = VERSION.split("_"); - - double version = Double.parseDouble(split[1]); - ; - - if (split.length > 2) { - version += 0.1 * Double.parseDouble(split[2].substring(1)); - } - - return version; - } - - static Class getBukkitClass(String classPath) { - return ReflectionUtils.getClassFromName("org.bukkit." + classPath); - } - - static Class getCraftBukkitClass(String classPath) { - return ReflectionUtils.getClassFromName("org.bukkit.craftbukkit." + VERSION + "." + classPath); - } - - static Class getNMSClassOriginal(String classPath, String newPath) { - if (MINECRAFT_VERSION.lessThanOrEqualTo(NBTEditor.MinecraftVersion.v1_16)) { - return ReflectionUtils.getClassFromName("net.minecraft.server." + VERSION + "." + classPath); - } else { - return ReflectionUtils.getClassFromName("net.minecraft." + newPath); - } - } - - static Class getNMSClassLegacy(String classPath) { - return ReflectionUtils.getClassFromName("net.minecraft.server." + VERSION + "." + classPath); - } - - static Class getNMSClassNew(String classPath) { - return ReflectionUtils.getClassFromName("net.minecraft." + classPath); - } -} diff --git a/util/src/main/java/tc/oc/pgm/util/tablist/TabEntry.java b/util/src/main/java/tc/oc/pgm/util/tablist/TabEntry.java index 6085349e0e..eff1346282 100644 --- a/util/src/main/java/tc/oc/pgm/util/tablist/TabEntry.java +++ b/util/src/main/java/tc/oc/pgm/util/tablist/TabEntry.java @@ -1,6 +1,5 @@ package tc.oc.pgm.util.tablist; -import java.awt.*; import java.util.UUID; import net.kyori.adventure.text.Component; import org.bukkit.GameMode; diff --git a/util/src/test/java/tc/oc/pgm/util/xml/ParseRangeTest.java b/util/src/test/java/tc/oc/pgm/util/xml/ParseRangeTest.java index 54e3dde93b..01821526d7 100644 --- a/util/src/test/java/tc/oc/pgm/util/xml/ParseRangeTest.java +++ b/util/src/test/java/tc/oc/pgm/util/xml/ParseRangeTest.java @@ -7,8 +7,8 @@ import org.jdom2.Attribute; import org.jdom2.Document; import org.jdom2.Namespace; -import org.junit.Test; import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; import tc.oc.pgm.util.Pair; public final class ParseRangeTest { @@ -24,17 +24,16 @@ private static Node dummyNode(String value) { @Test public void testParsedMathematicalRanges() throws InvalidXMLException { - final List>> mathematicalFormatRanges = - Lists.newArrayList( - Pair.of("[1,5]", Range.closed(1, 5)), - Pair.of("[1,oo)", Range.atLeast(1)), - Pair.of("(-oo,5]", Range.atMost(5)), - Pair.of("(1,20)", Range.open(1, 20)), - Pair.of("(1,oo)", Range.greaterThan(1)), - Pair.of("(-oo,80)", Range.lessThan(80)), - Pair.of("(-oo,oo)", Range.all()), - Pair.of("(1,5]", Range.openClosed(1, 5)), - Pair.of("[1,5)", Range.closedOpen(1, 5))); + final List>> mathematicalFormatRanges = Lists.newArrayList( + Pair.of("[1,5]", Range.closed(1, 5)), + Pair.of("[1,oo)", Range.atLeast(1)), + Pair.of("(-oo,5]", Range.atMost(5)), + Pair.of("(1,20)", Range.open(1, 20)), + Pair.of("(1,oo)", Range.greaterThan(1)), + Pair.of("(-oo,80)", Range.lessThan(80)), + Pair.of("(-oo,oo)", Range.all()), + Pair.of("(1,5]", Range.openClosed(1, 5)), + Pair.of("[1,5)", Range.closedOpen(1, 5))); for (Pair> mathematicalFormatRange : mathematicalFormatRanges) { Range parsedRange = @@ -46,20 +45,19 @@ public void testParsedMathematicalRanges() throws InvalidXMLException { @Test public void testParsedVanillaRanges() throws InvalidXMLException { - final List>> vanillaFormatRanges = - Lists.newArrayList( - Pair.of("1..5", Range.closed(1D, 5D)), - Pair.of(" 1 ..5 ", Range.closed(1D, 5D)), - Pair.of("1..", Range.atLeast(1D)), - Pair.of("..5", Range.atMost(5D)), - Pair.of("-oo..1", Range.atMost(1D)), - Pair.of("1..oo", Range.atLeast(1D)), - Pair.of("-oo..oo", Range.all()), - Pair.of("-oo ..", Range.all()), - Pair.of(" ..oo", Range.all()), - Pair.of(".5..5", Range.closed(0.5D, 5D)), - Pair.of("0.5 ..5 ", Range.closed(0.5D, 5D)), - Pair.of("..", Range.all())); + final List>> vanillaFormatRanges = Lists.newArrayList( + Pair.of("1..5", Range.closed(1D, 5D)), + Pair.of(" 1 ..5 ", Range.closed(1D, 5D)), + Pair.of("1..", Range.atLeast(1D)), + Pair.of("..5", Range.atMost(5D)), + Pair.of("-oo..1", Range.atMost(1D)), + Pair.of("1..oo", Range.atLeast(1D)), + Pair.of("-oo..oo", Range.all()), + Pair.of("-oo ..", Range.all()), + Pair.of(" ..oo", Range.all()), + Pair.of(".5..5", Range.closed(0.5D, 5D)), + Pair.of("0.5 ..5 ", Range.closed(0.5D, 5D)), + Pair.of("..", Range.all())); for (Pair> vanillaFormatRange : vanillaFormatRanges) { Range parsedRange = @@ -71,19 +69,18 @@ public void testParsedVanillaRanges() throws InvalidXMLException { @Test public void testFaultyVanillaRanges() { - final List faultyRanges = - Lists.newArrayList( - "oo..1", - "oo..oo", - "5..1", - "oo..oo", - "-oo..-oo", - "oo..-oo", - "4..-oo", - "===..5", - "3..###", - "3..wow", - "amazing..3"); + final List faultyRanges = Lists.newArrayList( + "oo..1", + "oo..oo", + "5..1", + "oo..oo", + "-oo..-oo", + "oo..-oo", + "4..-oo", + "===..5", + "3..###", + "3..wow", + "amazing..3"); for (String faultyRange : faultyRanges) { AtomicReference> faultyResult = new AtomicReference<>(null); @@ -111,9 +108,8 @@ public void testBoundedRanges() { AtomicReference> faultyResult = new AtomicReference<>(null); Assertions.assertThrows( InvalidXMLException.class, - () -> - faultyResult.set( - XMLUtils.parseBoundedNumericRange(dummyNode(nonBoundedRange), Integer.class)), + () -> faultyResult.set( + XMLUtils.parseBoundedNumericRange(dummyNode(nonBoundedRange), Integer.class)), () -> "\"" + nonBoundedRange + "\"" + " parsed faulty to result: " + faultyResult.get()); } }