From 8c2998016a0adaea1e469b729738a9d3b7037ba4 Mon Sep 17 00:00:00 2001 From: Danielle Voznyy Date: Sat, 21 Oct 2023 20:19:28 -0400 Subject: [PATCH 1/7] Convert platform into a paper plugin, delete unnecessary plugin.yml in util package --- idofront-catalog-shaded/build.gradle.kts | 10 ++------- .../mineinabyss/idofront/IdofrontPlugin.java | 6 +++++ .../src/main/resources/paper-plugin.yml | 6 +++++ ...mineinabyss.conventions.papermc.gradle.kts | 2 +- idofront-util/src/main/resources/plugin.yml | 22 ------------------- 5 files changed, 15 insertions(+), 31 deletions(-) create mode 100644 idofront-catalog-shaded/src/main/java/com/mineinabyss/idofront/IdofrontPlugin.java create mode 100644 idofront-catalog-shaded/src/main/resources/paper-plugin.yml delete mode 100644 idofront-util/src/main/resources/plugin.yml diff --git a/idofront-catalog-shaded/build.gradle.kts b/idofront-catalog-shaded/build.gradle.kts index 98e7ca5..23fdd0a 100644 --- a/idofront-catalog-shaded/build.gradle.kts +++ b/idofront-catalog-shaded/build.gradle.kts @@ -1,6 +1,7 @@ plugins { id("com.mineinabyss.conventions.kotlin.jvm") id("com.mineinabyss.conventions.copyjar") + id("com.mineinabyss.conventions.papermc") } dependencies { @@ -10,14 +11,7 @@ dependencies { } } -tasks { - shadowJar { - archiveBaseName.set("mineinabyss") - archiveClassifier.set("") - archiveExtension.set("platform") - } -} - copyJar { + jarName.set("idofront-platform-$version.jar") excludePlatformDependencies.set(false) } diff --git a/idofront-catalog-shaded/src/main/java/com/mineinabyss/idofront/IdofrontPlugin.java b/idofront-catalog-shaded/src/main/java/com/mineinabyss/idofront/IdofrontPlugin.java new file mode 100644 index 0000000..d2013f7 --- /dev/null +++ b/idofront-catalog-shaded/src/main/java/com/mineinabyss/idofront/IdofrontPlugin.java @@ -0,0 +1,6 @@ +package com.mineinabyss.idofront; + +import org.bukkit.plugin.java.JavaPlugin; + +public class IdofrontPlugin extends JavaPlugin { +} diff --git a/idofront-catalog-shaded/src/main/resources/paper-plugin.yml b/idofront-catalog-shaded/src/main/resources/paper-plugin.yml new file mode 100644 index 0000000..895adcf --- /dev/null +++ b/idofront-catalog-shaded/src/main/resources/paper-plugin.yml @@ -0,0 +1,6 @@ +name: Idofront +version: ${plugin_version} +author: Offz +load: STARTUP +main: com.mineinabyss.idofront.IdofrontPlugin +api-version: '1.20' diff --git a/idofront-gradle/src/main/kotlin/com.mineinabyss.conventions.papermc.gradle.kts b/idofront-gradle/src/main/kotlin/com.mineinabyss.conventions.papermc.gradle.kts index 42ab089..08ce70e 100644 --- a/idofront-gradle/src/main/kotlin/com.mineinabyss.conventions.papermc.gradle.kts +++ b/idofront-gradle/src/main/kotlin/com.mineinabyss.conventions.papermc.gradle.kts @@ -16,7 +16,7 @@ dependencies { tasks { processResources { - filesMatching("plugin.yml") { + filesMatching(setOf("plugin.yml", "paper-plugin.yml")) { expand(mutableMapOf("plugin_version" to version)) } } diff --git a/idofront-util/src/main/resources/plugin.yml b/idofront-util/src/main/resources/plugin.yml deleted file mode 100644 index 30cadb9..0000000 --- a/idofront-util/src/main/resources/plugin.yml +++ /dev/null @@ -1,22 +0,0 @@ -name: MineInAbyss -version: ${plugin_version} -author: Derongan -main: com.mineinabyss.plugin.MineInAbyssPluginImpl -api-version: 1.17 -depend: [ Geary, Geary-Commons, DeeperWorld, Looty, Guiy ] -softdepend: [ Vault, Multiverse-Core, MCCosmetics, HMCCosmetics, GSit, DiscordSRV, chatty, ModelEngine ] - -prefix: MiA -description: A mod that adds abyss effects - -commands: - mineinabyss: - aliases: [ mia ] - -permissions: - mineinabyss.stopdescent: - description: Allows players to leave a run - mineinabyss.start: - description: Allows players to start a run - mineinabyss.stats: - description: Allows players to see their stats From 8725026efee7206209a5fc3c881615eb1f6a6f7b Mon Sep 17 00:00:00 2001 From: Danielle Voznyy Date: Sat, 21 Oct 2023 20:32:14 -0400 Subject: [PATCH 2/7] Delete platform loader code --- README.md | 5 +- gradle.properties | 2 +- idofront-catalog/build.gradle.kts | 1 - idofront-platform-loader/build.gradle.kts | 5 -- .../platforms/DelegateClassLoader.java | 35 ---------- .../platforms/LibraryLoaderInjector.java | 70 ------------------- .../idofront/platforms/PlatformProvider.java | 33 --------- .../idofront/platforms/Platforms.java | 30 -------- settings.gradle.kts | 1 - 9 files changed, 2 insertions(+), 180 deletions(-) delete mode 100644 idofront-platform-loader/build.gradle.kts delete mode 100644 idofront-platform-loader/src/main/java/com/mineinabyss/idofront/platforms/DelegateClassLoader.java delete mode 100644 idofront-platform-loader/src/main/java/com/mineinabyss/idofront/platforms/LibraryLoaderInjector.java delete mode 100644 idofront-platform-loader/src/main/java/com/mineinabyss/idofront/platforms/PlatformProvider.java delete mode 100644 idofront-platform-loader/src/main/java/com/mineinabyss/idofront/platforms/Platforms.java diff --git a/README.md b/README.md index f22252b..7d64e28 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ Helper functions for finding annotated classes at runtime, we use it to register Gradle [version catalog](https://docs.gradle.org/current/userguide/platforms.html#sub:version-catalog) containing our commonly used dependencies, including all idofront projects. [**`idofront-catalog-shaded`**](https://wiki.mineinabyss.com/idofront/platforms/) - -Packaged version of our catalog. Used with our platform loader to load dependencies at runtime. +A Paper plugin with all the dependencies shaded, intended to be used by our other plugins using Paper's `join-classpath` option. [**`idofront-commands`**](https://wiki.mineinabyss.com/idofront/command-dsl/) - A DSL for quickly building Minecraft commands. @@ -40,9 +40,6 @@ Super simple logging functions with MiniMessage support. [**`idofront-nms`**](https://wiki.mineinabyss.com/idofront/nms/) - TypeAliases and `toNMS()`, `toBukkit()` functions for many NMS classes -[**`idofront-platform-loader`**](https://wiki.mineinabyss.com/idofront/platforms/) - -Loads dependencies from a jar file, isolating them from other plugins. - [**`idofront-serializers`**](https://wiki.mineinabyss.com/idofront/serialization/) - Config-centric serializers for many Bukkit classes for kotlinx.serialization, including ItemStack, Recipes, or Components (via MiniMessage.) diff --git a/gradle.properties b/gradle.properties index 5069302..ad59fee 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ group=com.mineinabyss -version=0.19 +version=0.20 diff --git a/idofront-catalog/build.gradle.kts b/idofront-catalog/build.gradle.kts index a47bed4..2e50ebf 100644 --- a/idofront-catalog/build.gradle.kts +++ b/idofront-catalog/build.gradle.kts @@ -25,7 +25,6 @@ catalog { "idofront-features", "idofront-fonts", "idofront-logging", - "idofront-platform-loader", "idofront-serializers", "idofront-text-components", "idofront-util", diff --git a/idofront-platform-loader/build.gradle.kts b/idofront-platform-loader/build.gradle.kts deleted file mode 100644 index b012112..0000000 --- a/idofront-platform-loader/build.gradle.kts +++ /dev/null @@ -1,5 +0,0 @@ -plugins { - id("com.mineinabyss.conventions.kotlin.jvm") - id("com.mineinabyss.conventions.papermc") - id("com.mineinabyss.conventions.publication") -} diff --git a/idofront-platform-loader/src/main/java/com/mineinabyss/idofront/platforms/DelegateClassLoader.java b/idofront-platform-loader/src/main/java/com/mineinabyss/idofront/platforms/DelegateClassLoader.java deleted file mode 100644 index cbdd7b6..0000000 --- a/idofront-platform-loader/src/main/java/com/mineinabyss/idofront/platforms/DelegateClassLoader.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.mineinabyss.idofront.platforms; - -import java.net.URL; -import java.net.URLClassLoader; -import java.util.Collection; - -/** - * Classloader that contains a list of loaders that will be delegated to. - */ -public class DelegateClassLoader extends URLClassLoader { - private final Collection parents; - - DelegateClassLoader(Collection parents) { - super(new URL[0]); - this.parents = parents; - } - - @Override - protected Class loadClass(String name, boolean resolve) throws ClassNotFoundException { - for (ClassLoader loader: parents) { - try { - return loader.loadClass(name); - } catch (NoClassDefFoundError | ClassNotFoundException ignored) { - } - } - return super.loadClass(name, resolve); - } - - @Override - public String toString() { - return "DelegateClassLoader{" + - "parents=" + parents + - '}'; - } -} diff --git a/idofront-platform-loader/src/main/java/com/mineinabyss/idofront/platforms/LibraryLoaderInjector.java b/idofront-platform-loader/src/main/java/com/mineinabyss/idofront/platforms/LibraryLoaderInjector.java deleted file mode 100644 index ee7958d..0000000 --- a/idofront-platform-loader/src/main/java/com/mineinabyss/idofront/platforms/LibraryLoaderInjector.java +++ /dev/null @@ -1,70 +0,0 @@ -package com.mineinabyss.idofront.platforms; - -import org.bukkit.Bukkit; -import org.bukkit.plugin.Plugin; -import org.bukkit.plugin.ServicePriority; -import org.bukkit.plugin.java.PluginClassLoader; -import sun.misc.Unsafe; - -import javax.annotation.Nullable; -import java.io.File; -import java.lang.reflect.Field; -import java.net.URLClassLoader; -import java.util.List; -import java.util.Optional; -import java.util.function.Function; - -/** - * A helper class that uses reflection to inject dependencies into Spigot's library loader. - */ -public class LibraryLoaderInjector { - /** - * Injects a jar file into a plugin's dependencies for loading. Will ensure a shared classloader is used - * if separate plugins inject using this method. - */ - static void inject(Plugin plugin, File injectFile) throws ReflectiveOperationException { - // Read library loader - PluginClassLoader pluginClassLoader = (PluginClassLoader) plugin.getClass().getClassLoader(); - var libraryLoader = getLibraryClassLoaderFor(pluginClassLoader); - - // Get or load a service which extends the built-in java Function class, so it can be shared across classloaders - var services = Bukkit.getServicesManager(); - @SuppressWarnings("unchecked") - var platformProvider = (Optional>) services.getKnownServices().stream() - .filter(it -> it.getName().equals(PlatformProvider.class.getName())) - .map(services::load) - .findFirst(); - - var platformLoader = platformProvider.orElseGet(() -> { - var service = new PlatformProviderImpl(); - services.register(PlatformProvider.class, service, plugin, ServicePriority.Low); - return service; - }).apply(injectFile); - - // Update the library loader to delegate to our platform *after* the plugin's own libraries - ClassLoader newLoader; - if (libraryLoader == null) newLoader = platformLoader; - else newLoader = new DelegateClassLoader(List.of(libraryLoader, platformLoader)); - Bukkit.getServicesManager(); - setLibraryClassLoaderFor(pluginClassLoader, newLoader); - } - - @Nullable - static ClassLoader getLibraryClassLoaderFor(ClassLoader pluginClassLoader) throws NoSuchFieldException, IllegalAccessException { - Field unsafeField = Unsafe.class.getDeclaredField("theUnsafe"); - unsafeField.setAccessible(true); - Unsafe unsafe = (Unsafe) unsafeField.get(null); - Field libraryLoaderField = PluginClassLoader.class.getDeclaredField("libraryLoader"); - long libraryLoaderOffset = unsafe.objectFieldOffset(libraryLoaderField); - - return (ClassLoader) unsafe.getObject(pluginClassLoader, libraryLoaderOffset); - } - - static void setLibraryClassLoaderFor(ClassLoader pluginClassLoader, ClassLoader libraryLoader) throws NoSuchFieldException, IllegalAccessException { - Field unsafeField = Unsafe.class.getDeclaredField("theUnsafe"); - unsafeField.setAccessible(true); - Unsafe unsafe = (Unsafe) unsafeField.get(null); - Field libraryLoaderField = PluginClassLoader.class.getDeclaredField("libraryLoader"); - unsafe.putObject(pluginClassLoader, unsafe.objectFieldOffset(libraryLoaderField), libraryLoader); - } -} diff --git a/idofront-platform-loader/src/main/java/com/mineinabyss/idofront/platforms/PlatformProvider.java b/idofront-platform-loader/src/main/java/com/mineinabyss/idofront/platforms/PlatformProvider.java deleted file mode 100644 index 6759f54..0000000 --- a/idofront-platform-loader/src/main/java/com/mineinabyss/idofront/platforms/PlatformProvider.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.mineinabyss.idofront.platforms; - -import org.bukkit.plugin.java.JavaPluginLoader; -import org.bukkit.plugin.java.PluginClassLoader; - -import java.io.File; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.HashMap; -import java.util.Map; -import java.util.function.Function; - -interface PlatformProvider extends Function { -} - -class PlatformProviderImpl implements PlatformProvider { - private final Map alreadyLoaded = new HashMap<>(); - - @Override - public URLClassLoader apply(File file) { - var cached = alreadyLoaded.get(file); - if (cached == null) { - try { - cached = new URLClassLoader(new URL[]{file.toURI().toURL()}, JavaPluginLoader.class.getClassLoader()); - alreadyLoaded.put(file, cached); - } catch (MalformedURLException e) { - e.printStackTrace(); - } - } - return cached; - } -} diff --git a/idofront-platform-loader/src/main/java/com/mineinabyss/idofront/platforms/Platforms.java b/idofront-platform-loader/src/main/java/com/mineinabyss/idofront/platforms/Platforms.java deleted file mode 100644 index 4a1c1ff..0000000 --- a/idofront-platform-loader/src/main/java/com/mineinabyss/idofront/platforms/Platforms.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.mineinabyss.idofront.platforms; - -import org.bukkit.plugin.Plugin; - -import java.io.File; -import java.util.Arrays; -import java.util.function.Predicate; - -public class Platforms { - /** - * Loads a .platform file in the plugins folder that starts with a platformName. - */ - public static void load(Plugin plugin, String platformName) throws ReflectiveOperationException { - load(plugin, file -> file.getName().endsWith(".platform") && file.getName().startsWith(platformName)); - } - - /** - * Loads a file matching a predicate out of the plugin folder. - */ - public static void load(Plugin plugin, Predicate predicate) throws ReflectiveOperationException { - var files = plugin.getDataFolder().getParentFile().listFiles(); - if (files == null) return; - var injectFile = Arrays.stream(files) - .filter(predicate) - .findFirst(); - if (injectFile.isEmpty()) return; - - LibraryLoaderInjector.inject(plugin, injectFile.get()); - } -} diff --git a/settings.gradle.kts b/settings.gradle.kts index 4a024e2..22ee12b 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -21,7 +21,6 @@ include( "idofront-features", "idofront-fonts", "idofront-logging", - "idofront-platform-loader", "idofront-nms", "idofront-serializers", "idofront-text-components", From e00bfabae3dd37255f0bbcda356d6fea9cb46c16 Mon Sep 17 00:00:00 2001 From: Danielle Voznyy Date: Sat, 21 Oct 2023 21:55:11 -0400 Subject: [PATCH 3/7] Exclude idofront dependencies in runtimeClasspath, include them in shaded catalog, auto register command map --- idofront-catalog-shaded/build.gradle.kts | 7 ++++++- .../commands/entrypoint/CommandDSLEntrypoint.kt | 17 +++++++++-------- ...m.mineinabyss.conventions.copyjar.gradle.kts | 16 +++++++++++++--- settings.gradle.kts | 8 ++++---- 4 files changed, 32 insertions(+), 16 deletions(-) diff --git a/idofront-catalog-shaded/build.gradle.kts b/idofront-catalog-shaded/build.gradle.kts index 23fdd0a..0fa8a66 100644 --- a/idofront-catalog-shaded/build.gradle.kts +++ b/idofront-catalog-shaded/build.gradle.kts @@ -9,9 +9,14 @@ dependencies { libs.findBundle("platform").get().get().forEach { implementation(it) } + + rootProject.subprojects + .filter { it.name.startsWith("idofront-") } + .filter { it.name !in setOf("idofront-catalog", "idofront-catalog-shaded") } + .forEach {implementation(project(it.path)) } } copyJar { - jarName.set("idofront-platform-$version.jar") + jarName.set("idofront-$version.jar") excludePlatformDependencies.set(false) } diff --git a/idofront-commands/src/main/kotlin/com/mineinabyss/idofront/commands/entrypoint/CommandDSLEntrypoint.kt b/idofront-commands/src/main/kotlin/com/mineinabyss/idofront/commands/entrypoint/CommandDSLEntrypoint.kt index 458e7bc..95bd62c 100644 --- a/idofront-commands/src/main/kotlin/com/mineinabyss/idofront/commands/entrypoint/CommandDSLEntrypoint.kt +++ b/idofront-commands/src/main/kotlin/com/mineinabyss/idofront/commands/entrypoint/CommandDSLEntrypoint.kt @@ -40,16 +40,17 @@ class CommandDSLEntrypoint( } } - + override fun command(vararg names: String, desc: String, init: Command.() -> Unit): Command? { val pluginName: String = plugin.name.lowercase() - - // For each command name, register it with bukkit as it is a top-level command - for (name in names) { - plugin.getCommand(name) - ?.setExecutor(commandExecutor) - ?: plugin.logger.warning("Error registering command $name. Make sure it is defined in your plugin.yml") - } + val name = names.first() + // register command with bukkit as a top-level command + plugin.server.commandMap.register(name, "$pluginName:$name", + object : org.bukkit.command.Command(name, desc, "/$name", names.drop(1)) { + override fun execute(sender: CommandSender, commandLabel: String, args: Array): Boolean { + return commandExecutor.onCommand(sender, this, commandLabel, args) + } + }) // Add as a subcommand subcommands.getOrPut(names.toList()) { mutableListOf() } += { sender, arguments -> diff --git a/idofront-gradle/src/main/kotlin/com.mineinabyss.conventions.copyjar.gradle.kts b/idofront-gradle/src/main/kotlin/com.mineinabyss.conventions.copyjar.gradle.kts index 794ac95..c8f1b60 100644 --- a/idofront-gradle/src/main/kotlin/com.mineinabyss.conventions.copyjar.gradle.kts +++ b/idofront-gradle/src/main/kotlin/com.mineinabyss.conventions.copyjar.gradle.kts @@ -43,10 +43,20 @@ tasks.assemble { findByName("runtimeClasspath")?.apply { val libs = rootProject.extensions.getByType().named("libs") val deps = libs.findBundle("platform").get().get() - deps.forEach { - exclude(group = it.group, module = it.name) + + val unwantedPlatformDeps = allDependencies.map {it.group to it.name}.intersect(deps.map { it.group to it.name }.toSet()) + unwantedPlatformDeps.forEach { + exclude(group = it.first, module = it.second) } - println("Excluding ${deps.size} dependencies from runtimeClasspath that are present in mineinabyss.platform") + + println("Excluded ${unwantedPlatformDeps.size} platform dependencies from runtimeClasspath") + + val unwantedIdoDeps = allDependencies.map { it.name }.filter { it.startsWith("idofront") } + unwantedIdoDeps.forEach { module -> + exclude(group = "com.mineinabyss", module = module) + } + + println("Excluded ${unwantedIdoDeps.size} Idofront dependencies from runtimeClasspath") } runtimeClasspath { exclude(group = "org.jetbrains.kotlin") diff --git a/settings.gradle.kts b/settings.gradle.kts index 22ee12b..dce1827 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -11,8 +11,7 @@ rootProject.name = "idofront" includeBuild("idofront-gradle") -include( - "idofront-autoscan", +val projects = listOf( "idofront-catalog", "idofront-catalog-shaded", "idofront-commands", @@ -24,5 +23,6 @@ include( "idofront-nms", "idofront-serializers", "idofront-text-components", - "idofront-util", -) + "idofront-util",) + +include(projects) From cd82874c8d89a0e8e1be81d7e646cb57be396cc1 Mon Sep 17 00:00:00 2001 From: Danielle Voznyy Date: Sat, 21 Oct 2023 22:09:09 -0400 Subject: [PATCH 4/7] Update versioning code for gradle plugins --- idofront-gradle/build.gradle.kts | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/idofront-gradle/build.gradle.kts b/idofront-gradle/build.gradle.kts index bf43ccb..27c6b47 100644 --- a/idofront-gradle/build.gradle.kts +++ b/idofront-gradle/build.gradle.kts @@ -1,3 +1,4 @@ +import org.jetbrains.kotlin.util.* import java.util.* // Load properties from root gradle.properties @@ -12,20 +13,21 @@ plugins { //TODO duplicated code, try to get version from other project somehow val releaseVersion: String? = System.getenv("RELEASE_VERSION") -val extVersion = project.ext["version"] as String +val isSnapshot = System.getenv("IS_SNAPSHOT") == "true" fun getNextVersion(): String { - if (releaseVersion != null) { - val (majorTarget, minorTarget) = extVersion.split(".") - try { - val (major, minor, patch) = releaseVersion.removePrefix("v").split(".") - if (majorTarget == major && minorTarget == minor) { - return "$major.$minor.${patch.toInt() + 1}" - } - } catch (_: Exception) { + if (isSnapshot) return "$version".suffixIfNot("-SNAPSHOT") + if (releaseVersion == null) return "$version" + + val (majorTarget, minorTarget) = version.toString().split(".") + try { + val (major, minor, patch) = releaseVersion.removePrefix("v").removeSuffix("-SNAPSHOT").split(".") + if (majorTarget == major && minorTarget == minor) { + return "$major.$minor.${patch.toInt() + 1}" } - return "$majorTarget.$minorTarget.0" - } else return extVersion + } catch (_: Exception) { + } + return "$majorTarget.$minorTarget.0" } version = getNextVersion() From 122773939e6ff8584d55c441cd16528b6c8af5e4 Mon Sep 17 00:00:00 2001 From: Danielle Voznyy Date: Sat, 21 Oct 2023 23:43:44 -0400 Subject: [PATCH 5/7] Fix rest of publication logic for idofront-gradle --- idofront-gradle/build.gradle.kts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/idofront-gradle/build.gradle.kts b/idofront-gradle/build.gradle.kts index 27c6b47..4396212 100644 --- a/idofront-gradle/build.gradle.kts +++ b/idofront-gradle/build.gradle.kts @@ -14,6 +14,7 @@ plugins { //TODO duplicated code, try to get version from other project somehow val releaseVersion: String? = System.getenv("RELEASE_VERSION") val isSnapshot = System.getenv("IS_SNAPSHOT") == "true" +version = project.ext["version"] as String fun getNextVersion(): String { if (isSnapshot) return "$version".suffixIfNot("-SNAPSHOT") @@ -48,7 +49,11 @@ dependencies { publishing { repositories { - maven("https://repo.mineinabyss.com/releases") { + maven { + val repo = "https://repo.mineinabyss.com/" + val isSnapshot = System.getenv("IS_SNAPSHOT") == "true" + val url = if (isSnapshot) repo + "snapshots" else repo + "releases" + setUrl(url) credentials { username = project.findProperty("mineinabyssMavenUsername") as String? password = project.findProperty("mineinabyssMavenPassword") as String? From 7977641fe49d95b2b4d61edcf833fcbaec13abfa Mon Sep 17 00:00:00 2001 From: Danielle Voznyy Date: Sun, 22 Oct 2023 00:23:10 -0400 Subject: [PATCH 6/7] Return to including deps via platform bundles, allDependencies doesn't work right until resolved (when changes can't be made) --- ....mineinabyss.conventions.copyjar.gradle.kts | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/idofront-gradle/src/main/kotlin/com.mineinabyss.conventions.copyjar.gradle.kts b/idofront-gradle/src/main/kotlin/com.mineinabyss.conventions.copyjar.gradle.kts index c8f1b60..c8073a4 100644 --- a/idofront-gradle/src/main/kotlin/com.mineinabyss.conventions.copyjar.gradle.kts +++ b/idofront-gradle/src/main/kotlin/com.mineinabyss.conventions.copyjar.gradle.kts @@ -1,3 +1,5 @@ +import kotlin.jvm.optionals.getOrNull + plugins { java com.github.johnrengelman.shadow @@ -42,21 +44,15 @@ tasks.assemble { configurations { findByName("runtimeClasspath")?.apply { val libs = rootProject.extensions.getByType().named("libs") - val deps = libs.findBundle("platform").get().get() + val deps = libs.findBundle("platform").getOrNull()?.getOrNull() ?: emptyList() + val idoDeps = libs.findBundle("idofront-core").getOrNull()?.getOrNull() ?: emptyList() - val unwantedPlatformDeps = allDependencies.map {it.group to it.name}.intersect(deps.map { it.group to it.name }.toSet()) - unwantedPlatformDeps.forEach { + val unwanted = (deps + idoDeps).map { it.group to it.name } + unwanted.forEach { exclude(group = it.first, module = it.second) } - println("Excluded ${unwantedPlatformDeps.size} platform dependencies from runtimeClasspath") - - val unwantedIdoDeps = allDependencies.map { it.name }.filter { it.startsWith("idofront") } - unwantedIdoDeps.forEach { module -> - exclude(group = "com.mineinabyss", module = module) - } - - println("Excluded ${unwantedIdoDeps.size} Idofront dependencies from runtimeClasspath") + println("Excluded ${unwanted.size} platform dependencies from runtimeClasspath") } runtimeClasspath { exclude(group = "org.jetbrains.kotlin") From 1fed27e2dca3e801ccf9bd8bdcb342bf1d3d9862 Mon Sep 17 00:00:00 2001 From: Danielle Voznyy Date: Sun, 22 Oct 2023 18:08:27 -0400 Subject: [PATCH 7/7] Fix tab completion on custom commands, incorrect prefix --- .../commands/entrypoint/CommandDSLEntrypoint.kt | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/idofront-commands/src/main/kotlin/com/mineinabyss/idofront/commands/entrypoint/CommandDSLEntrypoint.kt b/idofront-commands/src/main/kotlin/com/mineinabyss/idofront/commands/entrypoint/CommandDSLEntrypoint.kt index 95bd62c..0ec298a 100644 --- a/idofront-commands/src/main/kotlin/com/mineinabyss/idofront/commands/entrypoint/CommandDSLEntrypoint.kt +++ b/idofront-commands/src/main/kotlin/com/mineinabyss/idofront/commands/entrypoint/CommandDSLEntrypoint.kt @@ -10,6 +10,7 @@ import com.mineinabyss.idofront.commands.execution.CommandExecutionFailedExcepti import com.mineinabyss.idofront.commands.execution.IdofrontCommandExecutor import com.mineinabyss.idofront.messaging.error import org.bukkit.command.CommandSender +import org.bukkit.command.TabCompleter import org.bukkit.plugin.java.JavaPlugin //TODO allow for holding arguments here. The current limitation is that only one instance of the command holder is @@ -45,11 +46,21 @@ class CommandDSLEntrypoint( val pluginName: String = plugin.name.lowercase() val name = names.first() // register command with bukkit as a top-level command - plugin.server.commandMap.register(name, "$pluginName:$name", + plugin.server.commandMap.register(name, pluginName, object : org.bukkit.command.Command(name, desc, "/$name", names.drop(1)) { override fun execute(sender: CommandSender, commandLabel: String, args: Array): Boolean { return commandExecutor.onCommand(sender, this, commandLabel, args) } + + override fun tabComplete( + sender: CommandSender, + alias: String, + args: Array? + ): List { + if(commandExecutor is TabCompleter) + return commandExecutor.onTabComplete(sender, this, alias, args) ?: emptyList() + return emptyList() + } }) // Add as a subcommand