Skip to content

Commit

Permalink
impl paperweight + starting to fix declarative cmd bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt-MX committed Jun 13, 2024
1 parent 525d665 commit 4ddce3d
Show file tree
Hide file tree
Showing 15 changed files with 73 additions and 27 deletions.
15 changes: 15 additions & 0 deletions .idea/modules/plugin/ktgui.plugin.test.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions api/.gradle/caches/paperweight/taskCache/reobfJar.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Command: C:\Users\Mangr\.gradle\jdks\adoptium-21-x64-hotspot-windows\bin\java.exe -Xmx1G -classpath C:\Users\Mangr\.gradle\caches\modules-2\files-2.1\net.fabricmc\tiny-remapper\0.10.1\c293b2384ae12af74f407fa3aaa553bba4ac6763\tiny-remapper-0.10.1-fat.jar net.fabricmc.tinyremapper.Main D:\PC\Projects\KtBukkitGui\api\build\libs\ktgui-2.4.0-dev-all.jar D:\PC\Projects\KtBukkitGui\api\build\libs\api-2.4.0.jar C:\Users\Mangr\.gradle\caches\paperweight-userdev\383bcea64446e2cc830258ba4061f82beae144700277ae2c736ef37b9c989d6c\module\io.papermc.paper\dev-bundle\1.20.4-R0.1-SNAPSHOT\paperweight\setupCache\extractDevBundle.dir\data\mojang+yarn-spigot-reobf.tiny mojang+yarn spigot C:\Users\Mangr\.gradle\caches\paperweight-userdev\383bcea64446e2cc830258ba4061f82beae144700277ae2c736ef37b9c989d6c\module\io.papermc.paper\dev-bundle\1.20.4-R0.1-SNAPSHOT\paperweight\setupCache\applyMojangMappedPaperclipPatch.jar --threads=1
Finished after 2799.54 ms.
12 changes: 5 additions & 7 deletions api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ plugins {
kotlin("jvm") version "1.7.10"
id("com.github.johnrengelman.shadow") version "7.0.0"
`maven-publish`
id("io.papermc.paperweight.userdev") version "1.7.1"
}

val paper_version: String by rootProject
Expand All @@ -15,8 +14,8 @@ repositories {

dependencies {
// compileOnly(kotlin("reflect"))
implementation(kotlin("reflect"))
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.10")
shadow(implementation(kotlin("reflect"))!!)
// implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.7.10")

paperweight.paperDevBundle(paper_version)
}
Expand All @@ -39,10 +38,9 @@ tasks {
}
shadowJar {
mergeServiceFiles()
// exclude {
//// it.path.startsWith("kotlin") && !it.path.contains("reactive")
// it.name.startsWith("kotlin")
// }
}
assemble {
dependsOn(reobfJar)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ open class DeclarativeCommandBuilder(
coolDownCallback.ifPresentOrElse({ it.invoke(context) }) {
context.reply(
!"&cPlease wait ${
coolDown.get().timeRemaining(context.sender).pretty()
coolDown.get().durationRemaining(context.sender).pretty()
} before running the command again."
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class DeclarativeCommandWrapper(
}

override fun tabComplete(sender: CommandSender, alias: String, args: Array<out String>): MutableList<String> {
val context = SuggestionInvocation(Optional.of(sender), alias, args.toList())
val context = SuggestionInvocation(Optional.of(sender), alias, args.toList().subList(0, args.size - 1))

val (newContext, finalCommand) = builder.getCurrentCommand(context)
val outArgs = finalCommand?.getSuggestions(newContext)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ class DoubleArgument(
name: String,
typeName: String
) : Argument<Double>(name, typeName, SingleArgumentConsumer()) {
var min: Double = 0.0
var min: Double = Double.MIN_VALUE
var max: Double = Double.MAX_VALUE

override fun validate(stringValue: String?): Boolean {
stringValue ?: return false
stringValue ?: return isOptional()

val doubleValue = stringValue.toDoubleOrNull() ?: return false

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ class IntArgument(
name: String,
typeName: String
) : Argument<Int>(name, typeName, SingleArgumentConsumer()) {
var min: Int = 0
var min: Int = Int.MIN_VALUE
var max: Int = Int.MAX_VALUE

override fun validate(stringValue: String?): Boolean {
stringValue ?: return false
stringValue ?: return isOptional()

val intValue = stringValue.toIntOrNull() ?: return false

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ class LongArgument(
name: String,
typeName: String
) : Argument<Long>(name, typeName, SingleArgumentConsumer()) {
var min: Long = 0
var min: Long = Long.MIN_VALUE
var max: Long = Long.MAX_VALUE

override fun validate(stringValue: String?): Boolean {
stringValue ?: return false
stringValue ?: return isOptional()

val intValue = stringValue.toIntOrNull() ?: return false

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ class ActionCoolDown<T>(
return max(-1L, expire - (System.currentTimeMillis() - cache.getOrDefault(user, 0)))
}

fun durationRemaining(user: T) : Duration {
return Duration.ofMillis(timeRemaining(user))
}

fun test(user: T, block: (Duration) -> Unit): Unit? {
val timeLeft = timeRemaining(user)
val valid = timeLeft < 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class ChainSoundBuilder {
steps.add(Step(Step.Type.SOUND, sound))
}

@JvmName("waitTicks")
fun wait(ticks: Long) {
this.steps.add(Step(Step.Type.WAIT, ticks))
}
Expand Down
4 changes: 3 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
kotlin("jvm") version "1.7.10"
id("io.papermc.paperweight.userdev") version "1.7.1" apply false
}

val version = "2.4.0"
Expand All @@ -9,6 +10,7 @@ rootProject.version = version
subprojects {
apply(plugin = "java")
apply(plugin = "org.jetbrains.kotlin.jvm")
apply(plugin = "io.papermc.paperweight.userdev")

repositories {
mavenCentral()
Expand All @@ -17,7 +19,7 @@ subprojects {
maven("https://repo.extendedclip.com/content/repositories/placeholderapi/")
}
dependencies {
compileOnly("org.jetbrains.kotlin:kotlin-stdlib:1.7.10")
// compileOnly("org.jetbrains.kotlin:kotlin-stdlib:1.7.10")
compileOnly("me.clip:placeholderapi:2.11.1")
}

Expand Down
2 changes: 2 additions & 0 deletions plugin/.gradle/caches/paperweight/taskCache/reobfJar.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Command: C:\Users\Mangr\.gradle\jdks\adoptium-21-x64-hotspot-windows\bin\java.exe -Xmx1G -classpath C:\Users\Mangr\.gradle\caches\modules-2\files-2.1\net.fabricmc\tiny-remapper\0.10.1\c293b2384ae12af74f407fa3aaa553bba4ac6763\tiny-remapper-0.10.1-fat.jar net.fabricmc.tinyremapper.Main D:\PC\Projects\KtBukkitGui\plugin\build\libs\ktgui-plugin-2.4.0-dev-all.jar D:\PC\Projects\KtBukkitGui\plugin\build\libs\plugin-unspecified.jar C:\Users\Mangr\.gradle\caches\paperweight-userdev\383bcea64446e2cc830258ba4061f82beae144700277ae2c736ef37b9c989d6c\module\io.papermc.paper\dev-bundle\1.20.4-R0.1-SNAPSHOT\paperweight\setupCache\extractDevBundle.dir\data\mojang+yarn-spigot-reobf.tiny mojang+yarn spigot C:\Users\Mangr\.gradle\caches\paperweight-userdev\383bcea64446e2cc830258ba4061f82beae144700277ae2c736ef37b9c989d6c\module\io.papermc.paper\dev-bundle\1.20.4-R0.1-SNAPSHOT\paperweight\setupCache\applyMojangMappedPaperclipPatch.jar --threads=1
Finished after 1731.16 ms.
20 changes: 11 additions & 9 deletions plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ plugins {
id("com.github.johnrengelman.shadow") version "7.1.2"
`maven-publish`
id("org.ajoberstar.grgit") version "4.1.0"
id("io.papermc.paperweight.userdev") version "1.7.1"
}

val paper_version: String by rootProject
Expand All @@ -17,7 +16,7 @@ repositories {
}

dependencies {
shadow(implementation(project(":api"))!!)
shadow(implementation(project(":api", "reobf"))!!)
shadow(implementation("co.pvphub:ProtocolLibDsl:-SNAPSHOT")!!)
compileOnly("com.comphenix.protocol:ProtocolLib:4.7.0")

Expand Down Expand Up @@ -50,12 +49,15 @@ tasks {
build {
dependsOn(shadowJar)
}
}
shadowJar {
archiveBaseName.set("ktgui-plugin")
archiveClassifier.set("")
archiveVersion.set(rootProject.version.toString())

minimize {
exclude("kotlin/**")
}

tasks.withType<com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar> {
archiveBaseName.set("ktgui-plugin")
archiveClassifier.set("")
archiveVersion.set(rootProject.version.toString())
exclude { it.name.startsWith("kotlin") }
mergeServiceFiles()
mergeServiceFiles()
}
}
21 changes: 19 additions & 2 deletions plugin/src/main/kotlin/com/mattmx/ktgui/KotlinGui.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@ import com.mattmx.ktgui.cooldown.ActionCoolDown
import com.mattmx.ktgui.designer.GuiDesigner
import com.mattmx.ktgui.examples.*
import com.mattmx.ktgui.scheduling.sync
import com.mattmx.ktgui.sound.playSound
import com.mattmx.ktgui.sound.sound
import com.mattmx.ktgui.sound.soundBuilder
import com.mattmx.ktgui.utils.not
import com.mattmx.ktgui.utils.pretty
import org.bukkit.Bukkit
import org.bukkit.Sound
import org.bukkit.command.CommandSender
import org.bukkit.entity.Player
import org.bukkit.event.inventory.InventoryType
Expand Down Expand Up @@ -201,6 +205,18 @@ class KotlinGui : JavaPlugin() {
"ktgui-cmd-examples" {
buildAutomaticPermissions("ktgui.examples.command")

("sound") {
runs<Player> {
val sound = soundBuilder {
sound(Sound.ENTITY_ENDERMAN_DEATH)
wait(1)
sound(Sound.BLOCK_NOTE_BLOCK_BANJO) pitch 2f
} relative true

sender.playSound(sound)
}
}

val coords by relativeCoords()

coords invalid { reply(!"&cInvalid coords provided") }
Expand Down Expand Up @@ -258,6 +274,7 @@ class KotlinGui : JavaPlugin() {

val cooldownPeriod by longArgument()
cooldownPeriod optional true
// fixme: args optional don't work
("cooldown" / cooldownPeriod) {

cooldown(Duration.ofSeconds(3))
Expand All @@ -280,8 +297,8 @@ class KotlinGui : JavaPlugin() {
val objects = hashMapOf<String, HashMap<String, String>>()

val objectId by stringArgument()
objectId range (3..16) matches "[a-z0-9_]".toRegex()
objectId invalid { reply(!"Invalid object ID") }
objectId range (3..16) matches "[a-z0-9_]{3,16}".toRegex()
objectId invalid { reply(!"Invalid object ID $provided") }

("create" / objectId) {
runs<CommandSender> {
Expand Down
3 changes: 3 additions & 0 deletions plugin/src/main/resources/plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@ authors: [ MattMX ]
website: https://github.com/Matt-MX/KtPaperGui
description: Declarative GUI Library for Paper.

depend:
- MCKotlin-Paper

softdepend:
- PlaceholderAPI

0 comments on commit 4ddce3d

Please sign in to comment.