Skip to content

Commit

Permalink
fix: gradle, list argument not properly suggesting & some small refac…
Browse files Browse the repository at this point in the history
…toring
  • Loading branch information
StillLutto committed Jan 15, 2025
1 parent a28c07b commit a6ba619
Show file tree
Hide file tree
Showing 40 changed files with 144 additions and 95 deletions.
15 changes: 6 additions & 9 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar

plugins {
java
kotlin("jvm") version "1.9.22"
Expand All @@ -9,7 +7,7 @@ plugins {

apply(plugin = "maven-publish")
val projectGroupId = "com.undefined"
val projectVersion = "0.0.43"
val projectVersion = "0.0.70"
val projectArtifactId = "stellar"

group = projectGroupId
Expand Down Expand Up @@ -71,17 +69,16 @@ allprojects {
}

dependencies {
implementation(project(":spigot:api"))
implementation(project(":common"))
api(project(":spigot:api"))
api(project(":spigot:common"))
}

tasks {
publish {
finalizedBy(project(":paper:common").tasks["publish"])
finalizedBy(project(":paper:api").tasks["publish"])
}
withType<ShadowJar> {
archiveFileName = "${project.name}-${project.version}.jar"
archiveClassifier = "spigot"
shadowJar {
archiveClassifier = ""
}
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
Expand Down
18 changes: 15 additions & 3 deletions common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,21 @@ plugins {
kotlin("jvm") version "1.9.22"
}

val versionVar = version
val groupIdVar = "com.undefined"
val artifactIdVar = "stellar"
val projectVersion = version
val projectGroupId = "com.undefined"
val projectArtifactId = "stellar"

//publishing {
// publications {
// register<MavenPublication>("maven") {
// groupId = projectGroupId
// artifactId = projectArtifactId
// version = projectVersion.toString()
//
// from(components["java"])
// }
// }
//}

dependencies {
compileOnly("org.spigotmc:spigot-api:1.21.4-R0.1-SNAPSHOT")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,60 +91,60 @@ open class ArgumentHandler {
fun addBooleanArgument(name: String): BooleanArgument =
addArgument { BooleanArgument(base, name) }

fun <T> addListArgument(
fun <T> addAdvancedListArgument(
name: String,
list: List<T>,
converter: (T) -> Suggestion,
parse: (Any?) -> T
converter: (T) -> Suggestion = { Suggestion.withText(it.toString()) },
parse: (Any?) -> T?
): ListArgument<T> = addArgument { ListArgument(StringArgument(base, name, StringType.WORD), list, converter, parse) }

fun <T> addListArgument(
fun <T> addAdvancedListArgument(
type: AbstractStellarArgument<*>,
list: List<T>,
converter: (T) -> Suggestion,
parse: (Any?) -> T
converter: (T) -> Suggestion = { Suggestion.withText(it.toString()) },
parse: (Any?) -> T?
): ListArgument<T> = addArgument { ListArgument(type, list, converter, parse) }

fun <T> addListArgument(
fun <T> addAdvancedListArgument(
name: String,
list: CommandContext<CommandSender>.() -> List<T>,
converter: (T) -> Suggestion,
parse: (Any?) -> T
converter: (T) -> Suggestion = { Suggestion.withText(it.toString()) },
parse: (Any?) -> T?
): ListArgument<T> = addArgument { ListArgument(StringArgument(base, name, StringType.WORD), list, converter, parse) }

fun <T> addListArgument(
fun <T> addAdvancedListArgument(
type: AbstractStellarArgument<*>,
list: CommandContext<CommandSender>.() -> List<T>,
converter: (T) -> Suggestion,
parse: (Any?) -> T
converter: (T) -> Suggestion = { Suggestion.withText(it.toString()) },
parse: (Any?) -> T?
): ListArgument<T> = addArgument { ListArgument(type, list, converter, parse) }

fun <T> addBasicListArgument(
fun <T> addListArgument(
name: String,
list: List<T>,
converter: (T) -> String,
parse: (Any?) -> T
converter: (T) -> String = { it.toString() },
parse: (Any?) -> T?
): ListArgument<T> = addArgument { ListArgument(StringArgument(base, name, StringType.WORD), list, { Suggestion.withText(converter(it)) }, parse) }

fun <T> addBasicListArgument(
fun <T> addListArgument(
type: AbstractStellarArgument<*>,
list: List<T>,
converter: (T) -> String,
parse: (Any?) -> T
converter: (T) -> String = { it.toString() },
parse: (Any?) -> T?
): ListArgument<T> = addArgument { ListArgument(type, list, { Suggestion.withText(converter(it)) }, parse) }

fun <T> addBasicListArgument(
fun <T> addListArgument(
name: String,
list: CommandContext<CommandSender>.() -> List<T>,
converter: (T) -> String,
parse: (Any?) -> T
converter: (T) -> String = { it.toString() },
parse: (Any?) -> T?
): ListArgument<T> = addArgument { ListArgument(StringArgument(base, name, StringType.WORD), list, { Suggestion.withText(converter(it)) }, parse) }

fun <T> addBasicListArgument(
fun <T> addListArgument(
type: AbstractStellarArgument<*>,
list: CommandContext<CommandSender>.() -> List<T>,
converter: (T) -> String,
parse: (Any?) -> T
converter: (T) -> String = { it.toString() },
parse: (Any?) -> T?
): ListArgument<T> = addArgument { ListArgument(type, list, { Suggestion.withText(converter(it)) }, parse) }

fun addStringListArgument(name: String, list: List<String>, type: StringType = StringType.WORD, parse: (Any?) -> Any? = { it }): ListArgument<String> =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ enum class EnumFormatting(val action: (String) -> String) {
LOWERCASE({ it.lowercase() }),
UPPERCASE({ it.uppercase() }),
CAPITALIZED({ it.lowercase().replaceFirstChar { char -> char.uppercase() } }),
NONE({ it }),
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ open class ListArgument<T>(

override val suggestions: MutableList<StellarSuggestion<*>>
get() = (super.suggestions + StellarSuggestion(CommandSender::class) { input ->
CompletableFuture.completedFuture(getSuggestionList(this).filter { it.text.startsWith(input, true) })
CompletableFuture.completedFuture(getSuggestionList(this).filter {
println(input)
it.text.startsWith(input, true)
})
}).toMutableList()

fun getSuggestionList(context: CommandContext<CommandSender>): List<Suggestion> = list(context).map(converter)
Expand Down
32 changes: 11 additions & 21 deletions paper/api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,17 @@ val artifactIdVar = "stellar"
group = groupIdVar
version = versionVar

publishing {
repositories {
maven {
name = "UndefinedCreations"
url = uri("https://repo.undefinedcreations.com/releases")
credentials(PasswordCredentials::class) {
username = System.getenv("MAVEN_NAME")
password = System.getenv("MAVEN_SECRET")
}
}
}
publications {
register<MavenPublication>("maven") {
groupId = groupIdVar
artifactId = artifactIdVar
version = versionVar.toString()

from(components["java"])
}
}
}
//publishing {
// publications {
// register<MavenPublication>("maven") {
// groupId = groupIdVar
// artifactId = artifactIdVar
// version = versionVar.toString()
//
// from(components["java"])
// }
// }
//}

dependencies {
compileOnly("io.papermc.paper:paper-api:1.21.3-R0.1-SNAPSHOT")
Expand Down
2 changes: 1 addition & 1 deletion server/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ val artifactIdVar = "stellar"

dependencies {
compileOnly("io.papermc.paper:paper-api:1.21.3-R0.1-SNAPSHOT")
implementation(project(":paper:api"))
implementation(project(":spigot:api"))
}

tasks {
Expand Down
40 changes: 36 additions & 4 deletions server/src/main/kotlin/com/undefined/stellar/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,51 @@ package com.undefined.stellar

import com.undefined.stellar.argument.custom.EnumFormatting
import com.undefined.stellar.data.suggestion.Suggestion
import org.bukkit.World.Environment
import org.bukkit.entity.Player
import org.bukkit.plugin.java.JavaPlugin
import java.util.concurrent.CompletableFuture

enum class EntityType {
ACACIA_BOAT,
ACACIA_CHEST_BOAT,
ALLAY,
AREA_EFFECT_CLOUD,
ARMADILLO,
ARMOR_STAND,
ARROW,
AXOLOTL,
BAT,
BEE,
BIRCH_BOAT,
BIRCH_CHEST_BOAT,
BLAZE,
BLOCK_DISPLAY,
BOGGED,
BREEZE,
BREEZE_WIND_CHARGE,
CAMEL,
CAT,
CAVE_SPIDER,
CHERRY_BOAT,
CHERRY_CHEST_BOAT,
CHEST_MINECART,
CHICKEN,
COD,
COMMAND_BLOCK_MINECART,
COW,
CREAKING,
SPIDER,
MINECART
}

class Main : JavaPlugin() {

override fun onEnable() {
StellarCommand("test", "t")
.addEnumArgument<Environment>("env", EnumFormatting.LOWERCASE)
.addEnumArgument<EntityType>("type", EnumFormatting.LOWERCASE)
.addExecution<Player> {
val env = getArgument<Environment>("env")
sender.sendMessage(env.name)
val type = getArgument<EntityType>("type")
sender.sendMessage(type.name)
}
.addStringArgument("test")
.addFutureSuggestion<Player> {
Expand Down
2 changes: 1 addition & 1 deletion spigot/api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ publishing {

dependencies {
compileOnly("org.spigotmc:spigot-api:1.21.4-R0.1-SNAPSHOT")
implementation(project(":spigot:common"))
api(project(":spigot:common"))
implementation(project(":spigot:v1_13"))
implementation(project(":spigot:v1_13_1"))
implementation(project(":spigot:v1_13_2"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import org.jetbrains.annotations.ApiStatus
class StellarCommand(name: String, permissions: List<String> = listOf(), aliases: List<String> = listOf()) : AbstractStellarCommand<StellarCommand>(name) {

constructor(name: String, vararg aliases: String) : this(name, aliases = aliases.toList())
constructor(name: String, permission: String, vararg aliases: String) : this(name, listOf(permission), aliases.toList())
constructor(name: String, permission: String, aliases: List<String>) : this(name, listOf(permission), aliases)

init {
Expand Down
17 changes: 16 additions & 1 deletion spigot/common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,24 @@ plugins {
kotlin("jvm") version "1.9.22"
}

val projectVersion = version
val projectGroupId = "com.undefined"
val projectArtifactId = "stellar"

publishing {
publications {
register<MavenPublication>("maven") {
groupId = projectGroupId
artifactId = projectArtifactId
version = projectVersion.toString()

from(components["java"])
}
}
}

dependencies {
compileOnly("org.spigotmc:spigot-api:1.20.6-R0.1-SNAPSHOT")
api("com.mojang:authlib:1.5.21")
api(project(":common"))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ object BrigadierCommandHelper {
val stellarContext = CommandContextAdapter.getStellarCommandContext(context)
val completions: CompletableFuture<List<com.undefined.stellar.data.suggestion.Suggestion>> = CompletableFuture.supplyAsync {
val suggestions: MutableList<com.undefined.stellar.data.suggestion.Suggestion> = mutableListOf()
for (suggestion in command.suggestions) suggestions.addAll(suggestion.get(stellarContext).get())
for (suggestion in command.suggestions) suggestions.addAll(suggestion.get(stellarContext, builder.remaining).get())
suggestions
}
return CommandAdapter.getMojangSuggestions(builder, completions)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ object BrigadierCommandHelper {
val stellarContext = CommandContextAdapter.getStellarCommandContext(context)
val completions: CompletableFuture<List<com.undefined.stellar.data.suggestion.Suggestion>> = CompletableFuture.supplyAsync {
val suggestions: MutableList<com.undefined.stellar.data.suggestion.Suggestion> = mutableListOf()
for (suggestion in command.suggestions) suggestions.addAll(suggestion.get(stellarContext).get())
for (suggestion in command.suggestions) suggestions.addAll(suggestion.get(stellarContext, builder.remaining).get())
suggestions
}
return CommandAdapter.getMojangSuggestions(builder, completions)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ object BrigadierCommandHelper {
val stellarContext = CommandContextAdapter.getStellarCommandContext(context)
val completions: CompletableFuture<List<com.undefined.stellar.data.suggestion.Suggestion>> = CompletableFuture.supplyAsync {
val suggestions: MutableList<com.undefined.stellar.data.suggestion.Suggestion> = mutableListOf()
for (suggestion in command.suggestions) suggestions.addAll(suggestion.get(stellarContext).get())
for (suggestion in command.suggestions) suggestions.addAll(suggestion.get(stellarContext, builder.remaining).get())
suggestions
}
return CommandAdapter.getMojangSuggestions(builder, completions)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ object BrigadierCommandHelper {
val stellarContext = CommandContextAdapter.getStellarCommandContext(context)
val completions: CompletableFuture<List<com.undefined.stellar.data.suggestion.Suggestion>> = CompletableFuture.supplyAsync {
val suggestions: MutableList<com.undefined.stellar.data.suggestion.Suggestion> = mutableListOf()
for (suggestion in command.suggestions) suggestions.addAll(suggestion.get(stellarContext).get())
for (suggestion in command.suggestions) suggestions.addAll(suggestion.get(stellarContext, builder.remaining).get())
suggestions
}
return CommandAdapter.getMojangSuggestions(builder, completions)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ object BrigadierCommandHelper {
val stellarContext = CommandContextAdapter.getStellarCommandContext(context)
val completions: CompletableFuture<List<com.undefined.stellar.data.suggestion.Suggestion>> = CompletableFuture.supplyAsync {
val suggestions: MutableList<com.undefined.stellar.data.suggestion.Suggestion> = mutableListOf()
for (suggestion in command.suggestions) suggestions.addAll(suggestion.get(stellarContext).get())
for (suggestion in command.suggestions) suggestions.addAll(suggestion.get(stellarContext, builder.remaining).get())
suggestions
}
return CommandAdapter.getMojangSuggestions(builder, completions)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ object BrigadierCommandHelper {
val stellarContext = CommandContextAdapter.getStellarCommandContext(context)
val completions: CompletableFuture<List<com.undefined.stellar.data.suggestion.Suggestion>> = CompletableFuture.supplyAsync {
val suggestions: MutableList<com.undefined.stellar.data.suggestion.Suggestion> = mutableListOf()
for (suggestion in command.suggestions) suggestions.addAll(suggestion.get(stellarContext).get())
for (suggestion in command.suggestions) suggestions.addAll(suggestion.get(stellarContext, builder.remaining).get())
suggestions
}
return CommandAdapter.getMojangSuggestions(builder, completions)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ object BrigadierCommandHelper {
val stellarContext = CommandContextAdapter.getStellarCommandContext(context)
val completions: CompletableFuture<List<com.undefined.stellar.data.suggestion.Suggestion>> = CompletableFuture.supplyAsync {
val suggestions: MutableList<com.undefined.stellar.data.suggestion.Suggestion> = mutableListOf()
for (suggestion in command.suggestions) suggestions.addAll(suggestion.get(stellarContext).get())
for (suggestion in command.suggestions) suggestions.addAll(suggestion.get(stellarContext, builder.remaining).get())
suggestions
}
return CommandAdapter.getMojangSuggestions(builder, completions)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ object BrigadierCommandHelper {
val stellarContext = CommandContextAdapter.getStellarCommandContext(context)
val completions: CompletableFuture<List<com.undefined.stellar.data.suggestion.Suggestion>> = CompletableFuture.supplyAsync {
val suggestions: MutableList<com.undefined.stellar.data.suggestion.Suggestion> = mutableListOf()
for (suggestion in command.suggestions) suggestions.addAll(suggestion.get(stellarContext).get())
for (suggestion in command.suggestions) suggestions.addAll(suggestion.get(stellarContext, builder.remaining).get())
suggestions
}
return CommandAdapter.getMojangSuggestions(builder, completions)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ object BrigadierCommandHelper {
val stellarContext = CommandContextAdapter.getStellarCommandContext(context)
val completions: CompletableFuture<List<com.undefined.stellar.data.suggestion.Suggestion>> = CompletableFuture.supplyAsync {
val suggestions: MutableList<com.undefined.stellar.data.suggestion.Suggestion> = mutableListOf()
for (suggestion in command.suggestions) suggestions.addAll(suggestion.get(stellarContext).get())
for (suggestion in command.suggestions) suggestions.addAll(suggestion.get(stellarContext, builder.remaining).get())
suggestions
}
return CommandAdapter.getMojangSuggestions(builder, completions)
Expand Down
Loading

0 comments on commit a6ba619

Please sign in to comment.