diff --git a/build.gradle b/build.gradle index a30fdc5..58eaec4 100644 --- a/build.gradle +++ b/build.gradle @@ -1,12 +1,12 @@ plugins { - id 'fabric-loom' version '1.0-SNAPSHOT' + id 'fabric-loom' version "1.7-SNAPSHOT" id 'maven-publish' id "org.jetbrains.kotlin.jvm" - id 'org.jetbrains.kotlin.plugin.serialization' version '1.7.10' + id 'org.jetbrains.kotlin.plugin.serialization' version '1.9.22' } -sourceCompatibility = JavaVersion.VERSION_17 -targetCompatibility = JavaVersion.VERSION_17 +sourceCompatibility = JavaVersion.VERSION_21 +targetCompatibility = JavaVersion.VERSION_21 archivesBaseName = project.archives_base_name version = project.mod_version @@ -27,12 +27,10 @@ dependencies { modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" modImplementation "net.fabricmc:fabric-language-kotlin:${project.fabric_kotlin_version}" - implementation "org.jetbrains.kotlinx:kotlinx-serialization-json:${project.kotlinx_serialization_json_version}" // jgit // implementation "org.eclipse.jgit:org.eclipse.jgit:${project.jgit_version}" - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8" } processResources { @@ -50,14 +48,14 @@ tasks.withType(JavaCompile) { options.encoding = "UTF-8" // Minecraft 1.18.1 upwards uses Java 17. - it.options.release = 17 + it.options.release = 21 } // Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task // if it is present. // If you remove this task, sources will not be generated. task sourcesJar(type: Jar, dependsOn: classes) { - classifier = "sources" +// classifier = "sources" from sourceSets.main.allSource } @@ -94,4 +92,4 @@ publishing { } } -compileKotlin.kotlinOptions.jvmTarget = "17" \ No newline at end of file +compileKotlin.kotlinOptions.jvmTarget = "21" \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 5efa888..724fd50 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,32 +1,26 @@ kotlin.code.style=official +org.gradle.parallel=true org.gradle.jvmargs=-Xmx2G # Fabric Properties # Check these on https://modmuss50.me/fabric.html -minecraft_version=1.19.2 -yarn_mappings=1.19.2+build.8 -loader_version=0.14.9 +minecraft_version=1.21.1 +yarn_mappings=1.21.1+build.3 +loader_version=0.16.2 -#Fabric api -fabric_version=0.60.0+1.19.2 -loom_version=1.0-SNAPSHOT +# Fabric API +fabric_version=0.102.1+1.21.1 +loom_version=1.7-SNAPSHOT # Mod Properties -mod_version = 0.5 +mod_version = 0.6 maven_group = net.rx.modules archives_base_name = gitmod # Kotlin -kotlin_version=1.7.10 -fabric_kotlin_version=1.8.3+kotlin.1.7.10 +kotlin_version=1.9.22 +fabric_kotlin_version=1.10.17+kotlin.1.9.22 -### Dependencies -## Aegis -colonel_version=0.2.1 -aegis_version=3.2.5 - -## jgit -jgit_version=5.10.0.202012080955-r - -## kotlin x -kotlinx_serialization_json_version=1.4.0 \ No newline at end of file +#### Dependencies +### jgit +#jgit_version=6.8.0.202311291450-r diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index ffed3a2..19cfad9 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.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/settings.gradle b/settings.gradle index e8d5d91..36ea400 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,7 +1,6 @@ pluginManagement { repositories { - jcenter() maven { name = 'Fabric' url = 'https://maven.fabricmc.net/' @@ -13,5 +12,4 @@ pluginManagement { id 'fabric-loom' version loom_version id "org.jetbrains.kotlin.jvm" version kotlin_version } - } \ No newline at end of file diff --git a/src/main/kotlin/net/rx/modules/GitMod.kt b/src/main/kotlin/net/rx/modules/GitMod.kt index 55fa64f..185b5b1 100644 --- a/src/main/kotlin/net/rx/modules/GitMod.kt +++ b/src/main/kotlin/net/rx/modules/GitMod.kt @@ -22,9 +22,9 @@ object GitMod : ModInitializer { ConfigManager.register(it) } - ServerLifecycleEvents.SERVER_STOPPED.register { - - } +// ServerLifecycleEvents.SERVER_STOPPED.register { +// +// } CommandRegistrationCallback.EVENT.register(::registerCommands) } diff --git a/src/main/kotlin/net/rx/modules/Text.kt b/src/main/kotlin/net/rx/modules/Text.kt deleted file mode 100644 index b5155a6..0000000 --- a/src/main/kotlin/net/rx/modules/Text.kt +++ /dev/null @@ -1,154 +0,0 @@ -package net.rx.modules - -import net.minecraft.text.* -import net.minecraft.util.Formatting - -fun text(block: TextBuilder.() -> Unit) = TextBuilder(block).build() - - -//class StyleBuilder { -// var color: TextColor? = null -// var bold: Boolean? = null -// var italic: Boolean? = null -// var strikethrough: Boolean? = null -// var underline: Boolean? = null -// var reset: Boolean? = null -// -// fun build(): Style { -// return Style() -// } -//} - - -class TextBuilder(block: TextBuilder.() -> Unit) { - var root: MutableText = MutableText.of(TextContent.EMPTY) - private var children: MutableList = mutableListOf() - - val NEW_LINE: MutableText - get() = MutableText.of(LiteralTextContent("\n")) - - init { - block() - } - - operator fun Formatting.plus(format: Formatting): Style { - return Style.EMPTY.withFormatting(this).withFormatting(format) - } - - operator fun Style.plus(format: Formatting): Style { - return this.withFormatting(format) - } - - operator fun Style.plus(style: Style): Style { - return style.withParent(this) - } - - infix fun MutableText.styled(formatting: Formatting): MutableText { - return this.formatted(formatting) - } - - infix fun MutableText.styled(style: Style): MutableText { - return this.setStyle(style) - } - - infix fun String.styled(format: Formatting): MutableText { - return root.append(MutableText.of(LiteralTextContent(this)).formatted(format)) - } - - infix fun String.styled(style: Style): Text { - return root.append(MutableText.of(LiteralTextContent(this)).setStyle(style)) - } - - infix fun String.styled(hex: Int): Text { - return root.append(MutableText.of(LiteralTextContent(this)).setStyle(Style.EMPTY.withColor(TextColor.fromRgb(hex)))) - } - -// infix fun String.styled(block: StyleBuilder.() -> Unit): MutableText { -// return root.append(LiteralText(this).formatted(format)) -// } - - infix fun String.onClick(block: ClickEventBuilder.() -> Unit): Text { - return root.append(MutableText.of(LiteralTextContent(this)).setStyle(Style.EMPTY.withClickEvent( - ClickEventBuilder().apply{ block }.build() - ))) - } - - /** - * Nested control - */ - operator fun String.invoke(block: TextBuilder.() -> Unit): Text { - return root.append( - MutableText.of(LiteralTextContent(this)).append(TextBuilder(block).build()) - ) - } - - /** - * Use only when alone, returns nothing - */ - operator fun String.unaryPlus() { - children.add(MutableText.of(LiteralTextContent(this))) - } - - operator fun String.unaryMinus() { - children.add(MutableText.of(LiteralTextContent(this))) - } - -// infix fun String.onHover(block: Unit.() -> Unit): MutableText { -// return LiteralText(this).setStyle(Style.EMPTY.withHoverEvent( -// HoverEventBuilder().apply{ block }.build() -// )) -// } - - infix fun styled(format: Formatting) { - root.formatted(format) - } - - infix fun styled(style: Style) { - root.styled(style) - } - - fun build(): MutableText { - children.forEach { root.append(it) } - return root - } -} - -interface BaseBuilder { - fun build(): T -} - -class ClickEventBuilder : BaseBuilder { - var action: ClickEvent.Action? = null - var value: String = "" - - override fun build() = ClickEvent(action, value) -} - -class HoverEventBuilder : BaseBuilder { - var action: HoverEvent.Action? = null - var content: T? = null - - override fun build() = HoverEvent(action, content) -} - -val test = text { - "hello world" styled Formatting.BOLD + Formatting.GREEN - NEW_LINE - "a more complex string" { - NEW_LINE - "testing" onClick { - action = ClickEvent.Action.RUN_COMMAND - value = "/git status" - } - } - -"testing" -} - -//class HoverEventBuilder { -// var action: HoverEvent.Action? = null -// var contents: ? = null -// -// fun build(): HoverEvent { -// return HoverEvent(action, contents) -// } -//} diff --git a/src/main/kotlin/net/rx/modules/commands/GitAdminCommand.kt b/src/main/kotlin/net/rx/modules/commands/GitAdminCommand.kt index c36c1cc..cce779b 100644 --- a/src/main/kotlin/net/rx/modules/commands/GitAdminCommand.kt +++ b/src/main/kotlin/net/rx/modules/commands/GitAdminCommand.kt @@ -13,7 +13,6 @@ import net.minecraft.server.network.ServerPlayerEntity import net.minecraft.text.ClickEvent import net.minecraft.util.Formatting import net.rx.modules.config.ConfigManager -import net.rx.modules.text object GitAdminCommand : Command() { override fun register(dispatcher: Dispatcher) { @@ -67,47 +66,39 @@ object GitAdminCommand : Command() { private fun reload(context: Context): Int { ConfigManager.reloadData() - val test = text { - "hello world" styled Formatting.BOLD + Formatting.GREEN - NEW_LINE - "a more complex string" { - - } - -"testing" - } context.source.sendFeedback( - gray("Successfully reloaded configuration"), true) - context.source.sendFeedback(test, true) + { gray("Successfully reloaded configuration") }, true) + return 1 } private fun addOperator(context: Context, player: ServerPlayerEntity): Int { - val out = ConfigManager.addOperator(player.entityName, player.uuid.toString()) + val out = ConfigManager.addOperator(player.name.string, player.uuid.toString()) if (out == 1) { context.source.sendFeedback( - gray("Successfully added ${player.entityName} as an operator"), true + { gray("Successfully added ${player.name} as an operator") }, true ) context.source.player?.server?.playerManager?.sendCommandTree(context.source.player) } else context.source.sendFeedback( - red("Could not added, ${player.entityName} is already an operator"), true) + { red("Could not added, ${player.name} is already an operator") }, true) return 1 } private fun removeOperator(context: Context, player: ServerPlayerEntity): Int { - val out = ConfigManager.removeOperator(player.entityName, player.uuid.toString()) + val out = ConfigManager.removeOperator(player.name.string, player.uuid.toString()) if (out == 1) { context.source.sendFeedback( - gray("Successfully removed ${player.entityName} as an operator"), true + { gray("Successfully removed ${player.name.string} as an operator") }, true ) context.source.player?.server?.playerManager?.sendCommandTree(context.source.player) } else context.source.sendFeedback( - red("Could not remove, ${player.entityName} is not an operator"), true) + { red("Could not remove, ${player.name} is not an operator") }, true) return out } @@ -130,7 +121,7 @@ object GitAdminCommand : Command() { private fun listOperators(context: Context): Int { context.source.sendFeedback( - gray("Operators: ${ConfigManager.getOperators().joinToString(",")}"), false) + { gray("Operators: ${ConfigManager.getOperators().joinToString(",")}") }, false) return 1 } } \ No newline at end of file diff --git a/src/main/kotlin/net/rx/modules/commands/RawGitCommand.kt b/src/main/kotlin/net/rx/modules/commands/RawGitCommand.kt index 4de3904..69c26ae 100644 --- a/src/main/kotlin/net/rx/modules/commands/RawGitCommand.kt +++ b/src/main/kotlin/net/rx/modules/commands/RawGitCommand.kt @@ -39,7 +39,7 @@ object RawGitCommand : Command() { print(args) if (RawGitHandler.executing) { val feedback = "${RawGitHandler.executor} is current running ${RawGitHandler.command}. Please wait.." - context.source.sendFeedback(red(feedback), true) + context.source.sendFeedback({ red(feedback) }, true) return 0 } @@ -49,7 +49,7 @@ object RawGitCommand : Command() { RawGitHandler.runGit(path, args, context.source) } - return 0 + return 1 } internal object GitSuggestionProvider : SuggestionProvider { diff --git a/src/main/kotlin/net/rx/modules/commands/Utils.kt b/src/main/kotlin/net/rx/modules/commands/Utils.kt index 26855ad..d0fe418 100644 --- a/src/main/kotlin/net/rx/modules/commands/Utils.kt +++ b/src/main/kotlin/net/rx/modules/commands/Utils.kt @@ -21,14 +21,13 @@ typealias Source = ServerCommandSource fun invalidCommand(context: Context, msg: String): Int { - context.source.sendFeedback( - red(msg), false) + context.source.sendFeedback({ red(msg) }, false) return 0 } fun infoMessage(context: Context, msg: Text): Int { context.source.sendFeedback( - msg, false) + { msg }, false) return 0 } @@ -42,6 +41,6 @@ fun infoMessage(context: Context, msg: Text): Int { //} -fun red(string: String): MutableText = MutableText.of(LiteralTextContent(string)).styled { Style.EMPTY.withColor(Formatting.RED) } -fun green(string: String): MutableText = MutableText.of(LiteralTextContent(string)).styled { Style.EMPTY.withColor(Formatting.GREEN) } -fun gray(string: String): MutableText = MutableText.of(LiteralTextContent(string)).styled { Style.EMPTY.withColor(Formatting.GRAY) } +fun red(string: String): MutableText = Text.literal(string).styled { Style.EMPTY.withColor(Formatting.RED) } +fun green(string: String): MutableText = Text.literal(string).styled { Style.EMPTY.withColor(Formatting.GREEN) } +fun gray(string: String): MutableText = Text.literal(string).styled { Style.EMPTY.withColor(Formatting.GRAY) } diff --git a/src/main/kotlin/net/rx/modules/config/ConfigManager.kt b/src/main/kotlin/net/rx/modules/config/ConfigManager.kt index dbd99fd..d7f5527 100644 --- a/src/main/kotlin/net/rx/modules/config/ConfigManager.kt +++ b/src/main/kotlin/net/rx/modules/config/ConfigManager.kt @@ -46,7 +46,7 @@ object ConfigManager { private fun initialize() { dirPath = server - .runDirectory.toPath() + .runDirectory.toAbsolutePath() .resolve("config") .resolve("gitmod") diff --git a/src/main/kotlin/net/rx/modules/git/RawGitHandler.kt b/src/main/kotlin/net/rx/modules/git/RawGitHandler.kt index eb07d26..0486f0d 100644 --- a/src/main/kotlin/net/rx/modules/git/RawGitHandler.kt +++ b/src/main/kotlin/net/rx/modules/git/RawGitHandler.kt @@ -29,29 +29,29 @@ object RawGitHandler { if (ConfigManager.config.forceGitConfig && !pathToGitConfig.toFile().exists()) { /* TODO: Make this cleaner */ source.sendFeedback( - red("Error. You do not have a gitconfig setup"), false) + { red("Error. You do not have a gitconfig setup") }, false) source.sendFeedback( - gray("To create a gitconfig, you can use the /gitconfig command. Examples:"), false) + { gray("To create a gitconfig, you can use the /gitconfig command. Examples:") }, false) source.sendFeedback( - gray(" /gitconfig user.name ${source.player?.entityName}"), false) + { gray(" /gitconfig user.name ${source.player?.name}") }, false) source.sendFeedback( - gray(" /gitconfig user.email ${source.player?.entityName}@email.com"), false) + { gray(" /gitconfig user.email ${source.player?.name}@email.com") }, false) source.sendFeedback( - gray(" /gitconfig remote.origin.url ${source.player?.entityName}:@"), false) + { gray(" /gitconfig remote.origin.url ${source.player?.name}:@") }, false) } else { source.sendFeedback( - gray("executing: git $args"), true) + { gray("executing: git $args") }, true) runGit("git -c include.path=\"${pathToGitConfig.toAbsolutePath().toString()}\" -C \"$path\" $args", source) } } fun runGit(cmd: String, source: Source) { - setAll(true, source.player!!.entityName, cmd) + setAll(true, source.player!!.name.string, cmd) val argv = ArgumentTokenizer.tokenize(cmd).toTypedArray() @@ -67,23 +67,23 @@ object RawGitHandler { if (stdout.isNotBlank()) { source.sendFeedback( - green(stdout), false) + { green(stdout) }, false) } if (stderr.isNotBlank()) { source.sendFeedback( - red(stderr), false) + { red(stderr) }, false) } if (stdout.isBlank() && stderr.isBlank()) { source.sendFeedback( - green("GitCmd successfully executed (no output)"), false) + { green("GitCmd successfully executed (no output)") }, false) } } catch(e: IOException) { e.printStackTrace() source.sendFeedback( - red("git exception in code: $e"), true) + { red("git exception in code: $e") }, true) } executor = null diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index ba46ed7..a56fff8 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -29,7 +29,7 @@ "fabricloader": ">=0.8.7", "fabric": "*", "fabric-language-kotlin": ">=1.4.30", - "minecraft": "1.19.x" + "minecraft": ">=1.21" }, "requires": { "fabric-language-kotlin": ">=1.4.30"