Skip to content

Commit

Permalink
feat #36 : add commodore and mojang brigadier for tab completion
Browse files Browse the repository at this point in the history
  • Loading branch information
fhebuterne committed May 20, 2024
1 parent 5d65b3f commit 5044d16
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 0 deletions.
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ allprojects {
maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/")
maven("https://oss.sonatype.org/content/repositories/snapshots")
maven("https://jitpack.io")
maven("https://libraries.minecraft.net")
}

defaultDependencies()
Expand Down
2 changes: 2 additions & 0 deletions buildSrc/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ object Versions {
const val exposedGradlePlugin = "0.2.1"
const val jacoco = "0.8.7"
const val sqlite = "3.30.1"
const val commodore = "2.2"
const val brigadier = "1.0.18"
}
9 changes: 9 additions & 0 deletions common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ dependencies {
// Spigot doesn't have this dependency
implementation("org.slf4j:slf4j-api:${Versions.slf4j}")
implementation("org.slf4j:slf4j-simple:${Versions.slf4j}")
implementation("me.lucko:commodore:${Versions.commodore}")
compileOnly("com.mojang:brigadier:${Versions.brigadier}")

// Plugin dependency
if (buildVersion == null) {
Expand Down Expand Up @@ -81,8 +83,15 @@ tasks.shadowJar {
relocate("org.slf4j", "fr.fabienhebuterne.marketplace.libs.org.slf4j")
relocate("com.google", "fr.fabienhebuterne.marketplace.libs.com.google")

// relocate mc libs
relocate("me.lucko.commodore", "fr.fabienhebuterne.marketplace.libs.commodore")

exclude("DebugProbesKt.bin")
exclude("module-info.class")

dependencies {
exclude(dependency("com.mojang:brigadier"))
}
}

tasks.build {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import fr.fabienhebuterne.marketplace.storage.LogsRepository
import fr.fabienhebuterne.marketplace.storage.MailsRepository
import fr.fabienhebuterne.marketplace.storage.mysql.*
import fr.fabienhebuterne.marketplace.utils.BootstrapLoader
import fr.fabienhebuterne.marketplace.utils.CommodoreService
import me.lucko.commodore.CommodoreProvider
import net.milkbowl.vault.economy.Economy
import org.bukkit.Bukkit
import org.bukkit.command.Command
Expand All @@ -49,6 +51,7 @@ import org.slf4j.Logger
import org.slf4j.LoggerFactory
import java.time.Clock


// Used only to include slf4j for spigot and include with gradle shadowJar minimize()
var logger: Logger = LoggerFactory.getLogger(MarketPlace::class.java)

Expand Down Expand Up @@ -140,6 +143,11 @@ class MarketPlace(override var loader: JavaPlugin) : BootstrapLoader {
val expirationService: ExpirationService by kodein.instance()
expirationService.startTaskExpiration()

if (CommodoreProvider.isSupported()) {
val marketPlaceCommand = this.loader.getCommand("marketplace")
CommodoreService().init(this.loader, marketPlaceCommand)
}

isReload = false
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package fr.fabienhebuterne.marketplace.utils

import com.mojang.brigadier.tree.LiteralCommandNode
import me.lucko.commodore.Commodore
import me.lucko.commodore.CommodoreProvider
import me.lucko.commodore.file.CommodoreFileReader
import org.bukkit.command.Command
import org.bukkit.plugin.java.JavaPlugin

class CommodoreService {

fun init(plugin: JavaPlugin, command: Command) {
val commodore: Commodore = CommodoreProvider.getCommodore(plugin)
val marketPlaceCommand: LiteralCommandNode<Any> =
CommodoreFileReader.INSTANCE.parse(plugin.getResource("marketplace.commodore"))
commodore.register(command, marketPlaceCommand)
}

}
Empty file removed common/src/main/resources/.gitkeep
Empty file.
16 changes: 16 additions & 0 deletions common/src/main/resources/marketplace.commodore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
marketplace {
add {
unit_price brigadier:double;
}
listings {
player_or_uuid brigadier:string single_word;
}
mails {
player_or_uuid brigadier:string single_word;
}
logs {
player_or_uuid brigadier:string single_word;
}
reload;
help;
}

0 comments on commit 5044d16

Please sign in to comment.