diff --git a/build.gradle.kts b/build.gradle.kts index 6a6f77a..8baac69 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,15 +1,14 @@ import java.io.ByteArrayOutputStream plugins { - kotlin("jvm") version "1.6.10" - kotlin("kapt") version "1.6.10" - id("com.github.johnrengelman.shadow") version "7.0.0" + kotlin("jvm") version "2.0.21" + id("com.gradleup.shadow") version "8.3.3" `maven-publish` `java-library` } group = "net.azisaba.spicyazisaban" -version = "0.3.0-${getBranch()}-${getGitHash()}${if (hasUncommittedChanges()) "-debug" else ""}" +version = "1.0.0-${getBranch()}-${getGitHash()}${if (hasUncommittedChanges()) "-debug" else ""}" java { toolchain.languageVersion.set(JavaLanguageVersion.of(17)) @@ -33,7 +32,7 @@ fun getGitHash(): String { standardOutput = stdout } stdout.toString().trim() - } catch (e: Exception) { + } catch (_: Exception) { val ref = file("./.git/HEAD").readText().replace("^.*: (.*)$".toRegex(), "$1").trim(' ', '\n') println("Reading file ${file("./.git/$ref").absolutePath}") file("./.git/$ref").readText().trim(' ', '\n').substring(0..7) @@ -48,7 +47,7 @@ fun hasUncommittedChanges(): Boolean { standardOutput = stdout } stdout.toString().trim().isNotBlank() - } catch (e: Exception) { + } catch (_: Exception) { false } } @@ -78,8 +77,7 @@ subprojects { apply { plugin("org.jetbrains.kotlin.jvm") - plugin("org.jetbrains.kotlin.kapt") - plugin("com.github.johnrengelman.shadow") + plugin("com.gradleup.shadow") plugin("maven-publish") plugin("java-library") } @@ -91,23 +89,12 @@ subprojects { } tasks { - compileKotlin { - kotlinOptions.jvmTarget = "17" - } - - compileTestKotlin { - kotlinOptions.jvmTarget = "17" - } - test { useJUnitPlatform() } - kapt { - this.javacOptions { this.option("source", 17) } - } - processResources { + doNotTrackState("bungee.yml should be updated every time") filteringCharset = "UTF-8" from(sourceSets.main.get().resources.srcDirs) { include("**") @@ -121,18 +108,6 @@ subprojects { filter("tokens" to tokenReplacementMap) } - from(sourceSets.main.get().allSource.srcDirs) { - include("**") - - val tokenReplacementMap = mapOf( - "version" to project.version, - "name" to project.rootProject.name, - "debugBuild" to hasUncommittedChanges().toString(), - "devBuild" to (getBranch() != "main").toString(), - ) - - filter("tokens" to tokenReplacementMap) - } duplicatesStrategy = DuplicatesStrategy.INCLUDE @@ -173,23 +148,6 @@ subprojects { } dependencies { - implementation("xyz.acrylicstyle.util:maven:0.16.6") - implementation("net.blueberrymc:native-util:2.1.0") - implementation("org.jetbrains.kotlin:kotlin-stdlib:1.6.10") - implementation("xyz.acrylicstyle.util:all:0.16.6") { - exclude("com.google.guava", "guava") - exclude("org.reflections", "reflections") - exclude("org.json", "json") - exclude("org.yaml", "snakeyaml") - exclude("xyz.acrylicstyle.util", "maven") - } - implementation("xyz.acrylicstyle:sequelize4j:0.6.3") { - exclude("xyz.acrylicstyle", "java-util-all") - } - implementation("xyz.acrylicstyle:minecraft-util:1.0.0") { - exclude("xyz.acrylicstyle", "java-util-all") - } - compileOnly("org.mariadb.jdbc:mariadb-java-client:2.7.3") testImplementation("org.junit.jupiter:junit-jupiter:5.8.1") } } @@ -221,10 +179,6 @@ allprojects { } } -println("Deleting cached bungee.yml") -file("./build/resources/main/bungee.yml").apply { - if (exists()) delete() -} println("Version: ${project.version}") println("Debug build: ${hasUncommittedChanges()}") println("Dev build: ${project.version.toString().contains("-dev")}") diff --git a/bungee/src/main/kotlin/net/azisaba/spicyAzisaBan/bungee/BungeePlugin.kt b/bungee/src/main/kotlin/net/azisaba/spicyAzisaBan/bungee/BungeePlugin.kt index c717238..c9f76e1 100644 --- a/bungee/src/main/kotlin/net/azisaba/spicyAzisaBan/bungee/BungeePlugin.kt +++ b/bungee/src/main/kotlin/net/azisaba/spicyAzisaBan/bungee/BungeePlugin.kt @@ -5,12 +5,12 @@ import net.azisaba.spicyAzisaBan.SpicyAzisaBan import net.azisaba.spicyAzisaBan.bungee.listener.EventListeners import net.azisaba.spicyAzisaBan.bungee.listener.LockdownListener import net.azisaba.spicyAzisaBan.bungee.listener.PlayerDataUpdaterListener +import net.azisaba.spicyAzisaBan.remapper.JarUtils import net.blueberrymc.nativeutil.NativeUtil import net.md_5.bungee.api.plugin.Plugin -import util.maven.Dependency -import util.maven.JarUtils -import util.maven.MavenRepository -import util.maven.Repository +import org.eclipse.aether.util.graph.visitor.NodeListGenerator +import org.eclipse.aether.util.graph.visitor.PreorderDependencyNodeConsumerVisitor +import xyz.acrylicstyle.util.maven.MavenResolver import java.io.File import java.net.URLClassLoader import java.util.logging.Logger @@ -23,36 +23,29 @@ class BungeePlugin: Plugin() { init { val dataFolder = File("plugins/SpicyAzisaBan") LOGGER.info("Data folder: ${dataFolder.absolutePath}") - val maven = MavenRepository() - maven.addRepository(Repository.mavenLocal()) - maven.addRepository(Repository.mavenCentral()) - maven.addDependency(Dependency.resolve('c' + "om.google.guava:guava:31.0.1-jre")) - maven.addDependency(Dependency.resolve("org.reflections:reflections:0.10.2")) - maven.addDependency(Dependency.resolve('o' + "rg.json:json:20210307")) - maven.addDependency(Dependency.resolve("org.yaml:snakeyaml:1.29")) - maven.addDependency(Dependency.resolve('o' + "rg.mariadb.jdbc:mariadb-java-client:2.7.3")) - maven.addExclude("log4j", "log4j") - var hasError = false - val files = maven.newFetcher(File(dataFolder, "libraries")).withMessageReporter { msg, throwable -> - if (throwable == null) { - LOGGER.info(msg) - } else { - LOGGER.warning(msg) + val nodeListGenerator = NodeListGenerator() + MavenResolver("plugins/SpicyAzisaBan/libraries") + .addMavenCentral() + .addDependency('c' + "om.google.guava:guava:31.0.1-jre") + .addDependency('o' + "rg.reflections:reflections:0.10.2") + .addDependency('o' + "rg.json:json:20210307") + .addDependency('o' + "rg.yaml:snakeyaml:1.29") + .addDependency('o' + "rg.mariadb.jdbc:mariadb-java-client:3.5.0") + .resolve { node, list -> node.artifact.groupId != "log4j" } + .forEach { + it.root.accept(PreorderDependencyNodeConsumerVisitor(nodeListGenerator)) } - throwable?.let { - hasError = true - it.printStackTrace() - } - }.downloadAllDependencies() - if (hasError) LOGGER.warning("Failed to download some dependencies.") - val cl = BungeePlugin::class.java.classLoader - val urls = files.filterNotNull() - .map { file -> JarUtils.remapJarWithClassPrefix(file, "-remapped", "net.azisaba.spicyAzisaBan.libs") } - .map { file -> file.toURI().toURL() } + val dedupe = nodeListGenerator.nodes.sortedByDescending { it.version }.distinctBy { it.artifact.groupId to it.artifact.artifactId } + nodeListGenerator.nodes.retainAll(dedupe) + val urls = nodeListGenerator.paths + .map { it.toFile() } + .map { JarUtils.remapJarWithClassPrefix(it, "-remapped", "net.azisaba.spicyAzisaBan.libs") } + .map { it.toURI().toURL() } .toTypedArray() + val cl = BungeePlugin::class.java.classLoader val libraryLoader = URLClassLoader(urls) NativeUtil.setObject(cl::class.java.getDeclaredField("libraryLoader"), cl, libraryLoader) - LOGGER.info("Loaded libraries (" + files.size + "):") + LOGGER.info("Loaded libraries (" + urls.size + "):") urls.forEach { url -> LOGGER.info(" - ${url.path}") } diff --git a/cli/src/main/kotlin/net/azisaba/spicyAzisaBan/cli/actor/CLIActor.kt b/cli/src/main/kotlin/net/azisaba/spicyAzisaBan/cli/actor/CLIActor.kt index 794af53..dd3f4af 100644 --- a/cli/src/main/kotlin/net/azisaba/spicyAzisaBan/cli/actor/CLIActor.kt +++ b/cli/src/main/kotlin/net/azisaba/spicyAzisaBan/cli/actor/CLIActor.kt @@ -6,7 +6,6 @@ import net.azisaba.spicyAzisaBan.common.PlayerActor import net.azisaba.spicyAzisaBan.common.ServerInfo import net.azisaba.spicyAzisaBan.common.chat.Component import net.azisaba.spicyAzisaBan.common.title.Title -import util.UUIDUtil import java.net.SocketAddress import java.util.UUID @@ -26,7 +25,7 @@ object CLIActor: PlayerActor, Actor { override fun isOnline(): Boolean = true override val name: String = "CONSOLE" - override val uniqueId: UUID = UUIDUtil.NIL + override val uniqueId: UUID = UUID(0, 0) override fun sendMessage(component: Component) { println((component as SimpleComponent).getText()) diff --git a/common/build.gradle.kts b/common/build.gradle.kts index f5e16ca..f21ff80 100644 --- a/common/build.gradle.kts +++ b/common/build.gradle.kts @@ -1,3 +1,22 @@ dependencies { - api("xyz.acrylicstyle.java-util:common:1.0.0-SNAPSHOT") + api("xyz.acrylicstyle.java-util:common:2.1.0") + api("xyz.acrylicstyle.java-util:maven:2.1.0") + api("net.blueberrymc:native-util:2.1.2") + api("org.jetbrains.kotlin:kotlin-stdlib:2.0.21") + api("xyz.acrylicstyle.util:all:0.16.6") { + exclude("com.google.guava", "guava") + exclude("org.reflections", "reflections") + exclude("org.json", "json") + exclude("org.yaml", "snakeyaml") + exclude("xyz.acrylicstyle.util", "maven") + } + api("xyz.acrylicstyle:sequelize4j:0.6.3") { + exclude("xyz.acrylicstyle", "java-util-all") + } + api("xyz.acrylicstyle:minecraft-util:1.0.0") { + exclude("xyz.acrylicstyle", "java-util-all") + } + api("org.ow2.asm:asm:9.7.1") + api("org.ow2.asm:asm-commons:9.7.1") + compileOnlyApi("org.mariadb.jdbc:mariadb-java-client:3.5.0") } diff --git a/common/src/main/java/net/azisaba/spicyAzisaBan/remapper/JarUtils.java b/common/src/main/java/net/azisaba/spicyAzisaBan/remapper/JarUtils.java new file mode 100644 index 0000000..76e763d --- /dev/null +++ b/common/src/main/java/net/azisaba/spicyAzisaBan/remapper/JarUtils.java @@ -0,0 +1,140 @@ + +package net.azisaba.spicyAzisaBan.remapper; + +import com.google.common.io.ByteStreams; +import org.jetbrains.annotations.NotNull; +import org.objectweb.asm.ClassReader; +import org.objectweb.asm.ClassWriter; +import org.objectweb.asm.commons.ClassRemapper; +import org.objectweb.asm.commons.Remapper; + +import java.io.*; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.List; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; +import java.util.zip.ZipOutputStream; + +public class JarUtils { + /** + * Remap the class names. + * @param src source jar (zip) file + * @param fileSuffix suffix to apply to src file name. + * @param prefix class name prefix without trailing dot or slash + * @return destination file + * @throws IOException if an I/O error occurs + */ + @NotNull + public static File remapJarWithClassPrefix(@NotNull File src, @NotNull String fileSuffix, @NotNull String prefix) throws IOException { + return remapJarWithClassPrefix(src, fileSuffix, prefix, new PrefixClassRemapper(prefix)); + } + + /** + * Remap the class names. + * @param src source jar (zip) file + * @param fileSuffix suffix to apply to src file name. + * @param prefix class name prefix without trailing dot or slash + * @return destination file + * @throws IOException if an I/O error occurs + */ + @NotNull + public static File remapJarWithClassPrefix(@NotNull File src, @NotNull String fileSuffix, @NotNull String prefix, @NotNull Remapper remapper) throws IOException { + String[] split = src.getName().split("\\."); + StringBuilder name = new StringBuilder(split[0]); + for (int i = 1; i < split.length - 1; i++) name.append('.').append(split[i]); + String extension = ""; + if (split.length > 1) extension = "." + split[split.length - 1]; + File dst = new File(src.getParentFile(), name + fileSuffix + extension); + remapJarWithClassPrefix(src, dst, prefix, remapper); + return dst; + } + + public static void remapJarWithClassPrefix(@NotNull File src, @NotNull File dst, @NotNull String prefix) throws IOException { + remapJarWithClassPrefix(src, dst, prefix, new PrefixClassRemapper(prefix)); + } + + public static void remapJarWithClassPrefix(@NotNull File src, @NotNull File dst, @NotNull String prefix, @NotNull Remapper remapper) throws IOException { + ZipFile zipFile = new ZipFile(src); + Enumeration entries = zipFile.entries(); + ZipOutputStream out = new ZipOutputStream(new FileOutputStream(dst)); + while (entries.hasMoreElements()) { + ZipEntry entry = entries.nextElement(); + if (entry.getName().endsWith(".class")) { + out.putNextEntry(new ZipEntry(prefix.replace('.', '/') + '/' + entry.getName())); + byte[] bytes = remapClassWithClassPrefix(zipFile.getInputStream(entry), prefix, remapper); + ByteStreams.copy(new ByteArrayInputStream(bytes), out); + } else { + out.putNextEntry(new ZipEntry(entry.getName())); + if (entry.getName().equals("META-INF/MANIFEST.MF")) { + StringBuilder sb = new StringBuilder(); + for (String line : readLines(zipFile.getInputStream(entry))) { + if (line.startsWith("#")) { + sb.append(line); + } else { + String[] split = line.split(": "); + if (split.length == 1) { + sb.append(split[0]); + } else { + sb.append(split[0]).append(": "); + StringBuilder value = new StringBuilder(); + for (int i = 1; i < split.length; i++) value.append(split[i]); + if (!split[0].equals("Import-Package") && line.matches("^\\D+\\..+")) { + sb.append(remapper.map(value.toString()).replace('/', '.')); + } else { + sb.append(value); + } + } + } + sb.append("\n"); + } + writeString(out, sb.toString()); + } else if (entry.getName().startsWith("META-INF/services/")) { + StringBuilder sb = new StringBuilder(); + for (String line : readLines(zipFile.getInputStream(entry))) { + if (line.startsWith("#")) { + sb.append(line); + } else if (line.matches("^\\D+\\..+")) { // if not blank: + sb.append(remapper.map(line).replace('/', '.')); + } + sb.append("\n"); + } + writeString(out, sb.toString()); + out.closeEntry(); + String service = entry.getName().replaceFirst("META-INF/services/(.*)", "$1"); + out.putNextEntry(new ZipEntry("META-INF/services/" + remapper.map(service).replace('/', '.'))); + writeString(out, sb.toString()); + } else { + ByteStreams.copy(zipFile.getInputStream(entry), out); + } + } + out.closeEntry(); + } + zipFile.close(); + out.close(); + } + + public static byte[] remapClassWithClassPrefix(@NotNull InputStream in, @NotNull String prefix, @NotNull Remapper remapper) throws IOException { + ClassReader cr = new ClassReader(in); + ClassWriter cw = new ClassWriter(0); + cr.accept(new ClassRemapper(cw, remapper), 0); + return cw.toByteArray(); + } + + public static void writeString(@NotNull OutputStream out, @NotNull String s) throws IOException { + OutputStreamWriter writer = new OutputStreamWriter(out); + writer.write(s); + writer.flush(); + } + + @NotNull + public static List readLines(@NotNull InputStream in) throws IOException { + try (InputStreamReader inputStreamReader = new InputStreamReader(in); + BufferedReader reader = new BufferedReader(inputStreamReader)) { + List list = new ArrayList<>(); + String s; + while ((s = reader.readLine()) != null) list.add(s); + return list; + } + } +} diff --git a/common/src/main/java/net/azisaba/spicyAzisaBan/remapper/PrefixClassRemapper.java b/common/src/main/java/net/azisaba/spicyAzisaBan/remapper/PrefixClassRemapper.java new file mode 100644 index 0000000..297faf2 --- /dev/null +++ b/common/src/main/java/net/azisaba/spicyAzisaBan/remapper/PrefixClassRemapper.java @@ -0,0 +1,34 @@ +package net.azisaba.spicyAzisaBan.remapper; + +import org.jetbrains.annotations.NotNull; +import org.objectweb.asm.commons.Remapper; + +public class PrefixClassRemapper extends Remapper { + private final String prefix; + + /** + * Constructs a new PrefixClassRemapper. + * @param prefix prefix without trailing dot. + */ + public PrefixClassRemapper(@NotNull String prefix) { + this.prefix = prefix.replace('.', '/'); + } + + @NotNull + @Override + public String map(String internalName) { + // Packages included in JDK + if (internalName.startsWith("java/") + || internalName.startsWith("javax/") + || internalName.startsWith("jdk/") + || internalName.startsWith("sun/") + || internalName.startsWith("com/sun/") + || internalName.startsWith("org/ietf/jgss/") + || internalName.startsWith("org/w3c/dom/") + || internalName.startsWith("org/xml/sax/") + || internalName.startsWith("org/jcp/xml/dsig/internal") + || internalName.startsWith("org/graalvm/") + ) return internalName; + return prefix + "/" + internalName; + } +} diff --git a/common/src/main/kotlin/net/azisaba/spicyAzisaBan/SpicyAzisaBan.kt b/common/src/main/kotlin/net/azisaba/spicyAzisaBan/SpicyAzisaBan.kt index 61244e2..3bce816 100644 --- a/common/src/main/kotlin/net/azisaba/spicyAzisaBan/SpicyAzisaBan.kt +++ b/common/src/main/kotlin/net/azisaba/spicyAzisaBan/SpicyAzisaBan.kt @@ -143,7 +143,7 @@ abstract class SpicyAzisaBan { initDatabase() if (getPlatformType() != PlatformType.CLI) { DatabaseMigration.run().complete() - LOGGER.info("Supported event types: ${EventType.values().joinToString(", ") { it.name.lowercase() }}") + LOGGER.info("Supported event types: ${EventType.entries.joinToString(", ") { it.name.lowercase() }}") } val currentDatabaseVersion = settings.getDatabaseVersion().complete() if (currentDatabaseVersion != SQLConnection.CURRENT_DATABASE_VERSION) { diff --git a/common/src/main/kotlin/net/azisaba/spicyAzisaBan/common/chat/ClickEvent.kt b/common/src/main/kotlin/net/azisaba/spicyAzisaBan/common/chat/ClickEvent.kt index 3f10405..39d934e 100644 --- a/common/src/main/kotlin/net/azisaba/spicyAzisaBan/common/chat/ClickEvent.kt +++ b/common/src/main/kotlin/net/azisaba/spicyAzisaBan/common/chat/ClickEvent.kt @@ -1,7 +1,7 @@ package net.azisaba.spicyAzisaBan.common.chat class ClickEvent { - class Action<@Suppress("unused") T> { + class Action { companion object { val RUN_COMMAND = Action() } diff --git a/common/src/main/kotlin/net/azisaba/spicyAzisaBan/common/chat/HoverEvent.kt b/common/src/main/kotlin/net/azisaba/spicyAzisaBan/common/chat/HoverEvent.kt index fa492d4..6ddcfcb 100644 --- a/common/src/main/kotlin/net/azisaba/spicyAzisaBan/common/chat/HoverEvent.kt +++ b/common/src/main/kotlin/net/azisaba/spicyAzisaBan/common/chat/HoverEvent.kt @@ -1,7 +1,7 @@ package net.azisaba.spicyAzisaBan.common.chat class HoverEvent { - class Action<@Suppress("unused") T> { + class Action { companion object { val SHOW_TEXT = Action>() } diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 41d9927..249e583 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 8049c68..1e2fbf0 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index 1b6c787..a69d9cb 100755 --- a/gradlew +++ b/gradlew @@ -205,6 +205,12 @@ set -- \ 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. diff --git a/gradlew.bat b/gradlew.bat index 107acd3..f127cfd 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -14,7 +14,7 @@ @rem limitations under the License. @rem -@if "%DEBUG%" == "" @echo off +@if "%DEBUG%"=="" @echo off @rem ########################################################################## @rem @rem Gradle startup script for Windows @@ -25,7 +25,7 @@ if "%OS%"=="Windows_NT" setlocal set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. +if "%DIRNAME%"=="" set DIRNAME=. set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% @@ -40,7 +40,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute +if %ERRORLEVEL% equ 0 goto execute echo. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. @@ -75,13 +75,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar :end @rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd +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! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 +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 diff --git a/velocity/build.gradle.kts b/velocity/build.gradle.kts index 88ae119..b404175 100644 --- a/velocity/build.gradle.kts +++ b/velocity/build.gradle.kts @@ -1,12 +1,11 @@ repositories { - maven { url = uri("https://nexus.velocitypowered.com/repository/maven-public/") } + maven { url = uri("https://repo.papermc.io/repository/maven-public/") } } dependencies { implementation(project(":common")) - compileOnly("com.velocitypowered:velocity-api:3.0.1") - kapt("com.velocitypowered:velocity-api:3.0.1") - testImplementation("com.velocitypowered:velocity-api:3.0.1") + compileOnly("com.velocitypowered:velocity-api:3.4.0-SNAPSHOT") + testImplementation("com.velocitypowered:velocity-api:3.4.0-SNAPSHOT") } tasks { diff --git a/velocity/src/main/kotlin/net/azisaba/spicyAzisaBan/velocity/VelocityPlugin.kt b/velocity/src/main/kotlin/net/azisaba/spicyAzisaBan/velocity/VelocityPlugin.kt index 78b7ab2..a4af385 100644 --- a/velocity/src/main/kotlin/net/azisaba/spicyAzisaBan/velocity/VelocityPlugin.kt +++ b/velocity/src/main/kotlin/net/azisaba/spicyAzisaBan/velocity/VelocityPlugin.kt @@ -7,21 +7,19 @@ import com.velocitypowered.api.plugin.Plugin import com.velocitypowered.api.proxy.ProxyServer import net.azisaba.spicyAzisaBan.SABConfig import net.azisaba.spicyAzisaBan.SpicyAzisaBan +import net.azisaba.spicyAzisaBan.remapper.JarUtils import net.azisaba.spicyAzisaBan.velocity.listener.EventListeners import net.azisaba.spicyAzisaBan.velocity.listener.LockdownListener import net.azisaba.spicyAzisaBan.velocity.listener.PlayerDataUpdaterListener +import org.eclipse.aether.util.graph.visitor.NodeListGenerator +import org.eclipse.aether.util.graph.visitor.PreorderDependencyNodeConsumerVisitor import org.slf4j.Logger -import util.maven.Dependency -import util.maven.JarUtils -import util.maven.MavenRepository -import util.maven.Repository -import java.io.File -import java.nio.file.Path +import xyz.acrylicstyle.util.maven.MavenResolver @Plugin( id = "spicyazisaban", name = "SpicyAzisaBan", - version = "some-version", + version = "dev", authors = ["AzisabaNetwork"], url = "https://github.com/AzisabaNetwork/SpicyAzisaBan" ) @@ -30,47 +28,35 @@ class VelocityPlugin @Inject constructor(val server: ProxyServer, private val lo lateinit var instance: VelocityPlugin } - private val urlsToBeAdded: List - init { instance = this - val dataFolder = File("plugins/SpicyAzisaBan") - logger.info("Data folder: ${dataFolder.absolutePath}") - val maven = MavenRepository() - maven.addRepository(Repository.mavenLocal()) - maven.addRepository(Repository.mavenCentral()) - maven.addDependency(Dependency.resolve('c' + "om.google.guava:guava:31.0.1-jre")) - maven.addDependency(Dependency.resolve("org.reflections:reflections:0.10.2")) - maven.addDependency(Dependency.resolve('o' + "rg.json:json:20210307")) - maven.addDependency(Dependency.resolve("org.yaml:snakeyaml:1.29")) - maven.addDependency(Dependency.resolve('o' + "rg.mariadb.jdbc:mariadb-java-client:2.7.3")) - maven.addExclude("log4j", "log4j") - var hasError = false - val files = maven.newFetcher(File(dataFolder, "libraries")).withMessageReporter { msg, throwable -> - if (throwable == null) { - logger.info(msg) - } else { - logger.warn(msg) - } - throwable?.let { - hasError = true - it.printStackTrace() - } - }.downloadAllDependencies() - if (hasError) logger.warn("Failed to download some dependencies.") - urlsToBeAdded = files - .filterNotNull() - .map { file -> JarUtils.remapJarWithClassPrefix(file, "-remapped", "net.azisaba.spicyAzisaBan.libs") } - .mapNotNull { file -> file.toPath() } } @Subscribe - fun onProxyInitialization(@Suppress("UNUSED_PARAMETER") e: ProxyInitializeEvent) { + fun onProxyInitialization(@Suppress("unused") e: ProxyInitializeEvent) { try { - for (path in urlsToBeAdded) { - server.pluginManager.addToClasspath(this, path) - logger.info("Loaded library $path") - } + val nodeListGenerator = NodeListGenerator() + MavenResolver("plugins/SpicyAzisaBan/libraries") + .addMavenCentral() + .addDependency('c' + "om.google.guava:guava:31.0.1-jre") + .addDependency('o' + "rg.reflections:reflections:0.10.2") + .addDependency('o' + "rg.json:json:20210307") + .addDependency('o' + "rg.yaml:snakeyaml:1.29") + .addDependency('o' + "rg.mariadb.jdbc:mariadb-java-client:3.5.0") + .resolve { node, list -> node.artifact.groupId != "log4j" } + .forEach { + it.root.accept(PreorderDependencyNodeConsumerVisitor(nodeListGenerator)) + } + val dedupe = nodeListGenerator.nodes.sortedByDescending { it.version }.distinctBy { it.artifact.groupId to it.artifact.artifactId } + nodeListGenerator.nodes.retainAll(dedupe) + nodeListGenerator.paths + .map { it.toFile() } + .map { JarUtils.remapJarWithClassPrefix(it, "-remapped", "net.azisaba.spicyAzisaBan.libs") } + .map { it.toPath() } + .onEach { + server.pluginManager.addToClasspath(this, it) + logger.info("Loaded library $it") + } SpicyAzisaBan.debugLevel = 5 SpicyAzisaBanVelocity(server).doEnable() if (!SABConfig.debugBuild) SpicyAzisaBan.debugLevel = 0 diff --git a/velocity/src/main/kotlin/net/azisaba/spicyAzisaBan/velocity/listener/EventListeners.kt b/velocity/src/main/kotlin/net/azisaba/spicyAzisaBan/velocity/listener/EventListeners.kt index a38714b..1441f16 100644 --- a/velocity/src/main/kotlin/net/azisaba/spicyAzisaBan/velocity/listener/EventListeners.kt +++ b/velocity/src/main/kotlin/net/azisaba/spicyAzisaBan/velocity/listener/EventListeners.kt @@ -16,7 +16,7 @@ import net.azisaba.spicyAzisaBan.util.Util.disconnect import net.azisaba.spicyAzisaBan.util.Util.send import net.azisaba.spicyAzisaBan.velocity.VelocityPlayerActor import net.azisaba.spicyAzisaBan.velocity.util.VelocityUtil.toVelocity -import net.kyori.adventure.text.TextComponent +import net.kyori.adventure.text.Component import util.kt.promise.rewrite.catch object EventListeners { @@ -24,13 +24,13 @@ object EventListeners { fun onLogin(e: LoginEvent): EventTask = EventTask.async { var denied = false PunishmentChecker.checkLockdown(VelocityPlayerActor(e.player)) { reason -> - e.result = ResultedEvent.ComponentResult.denied(TextComponent.ofChildren(*reason.toVelocity())) + e.result = ResultedEvent.ComponentResult.denied(Component.textOfChildren(*reason.toVelocity())) denied = true } if (!denied) { PlayerData.createOrUpdate(VelocityPlayerActor(e.player)).catch { it.printStackTrace() } PunishmentChecker.checkGlobalBan(VelocityPlayerActor(e.player)) { reason -> - e.result = ResultedEvent.ComponentResult.denied(TextComponent.ofChildren(*reason.toVelocity())) + e.result = ResultedEvent.ComponentResult.denied(Component.textOfChildren(*reason.toVelocity())) } } } @@ -45,6 +45,7 @@ object EventListeners { }.complete() } + @Suppress("DEPRECATION") @Subscribe fun onPlayerChat(e: PlayerChatEvent): EventTask = EventTask.async { val actor = VelocityPlayerActor(e.player) diff --git a/velocity/src/main/kotlin/net/azisaba/spicyAzisaBan/velocity/util/VelocityComponent.kt b/velocity/src/main/kotlin/net/azisaba/spicyAzisaBan/velocity/util/VelocityComponent.kt index b8a529e..d1199d7 100644 --- a/velocity/src/main/kotlin/net/azisaba/spicyAzisaBan/velocity/util/VelocityComponent.kt +++ b/velocity/src/main/kotlin/net/azisaba/spicyAzisaBan/velocity/util/VelocityComponent.kt @@ -14,7 +14,7 @@ data class VelocityComponent(var component: KComponent): Component { override fun setHoverEvent(action: HoverEvent.Action, value: T) { if (action == HoverEvent.Action.SHOW_TEXT) { @Suppress("UNCHECKED_CAST") - component = component.hoverEvent(TextComponent.ofChildren(*(value as Array).toVelocity())) + component = component.hoverEvent(KComponent.textOfChildren(*(value as Array).toVelocity())) } } diff --git a/velocity/src/main/resources/velocity-plugin.json b/velocity/src/main/resources/velocity-plugin.json new file mode 100644 index 0000000..2cae781 --- /dev/null +++ b/velocity/src/main/resources/velocity-plugin.json @@ -0,0 +1,11 @@ +{ + "id": "spicyazisaban", + "name": "SpicyAzisaBan", + "version": "@version@", + "url": "https://github.com/AzisabaNetwork/SpicyAzisaBan", + "authors": [ + "AzisabaNetwork" + ], + "dependencies": [], + "main": "net.azisaba.spicyAzisaBan.velocity.VelocityPlugin" +}