Skip to content

Commit

Permalink
feat(exceptions): add UnsupportedArgumentTypeException
Browse files Browse the repository at this point in the history
  • Loading branch information
StillLutto committed Jan 11, 2025
1 parent 9fbbf30 commit adbbeba
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.undefined.stellar.argument.types.custom

import com.undefined.stellar.AbstractStellarCommand
import com.undefined.stellar.argument.AbstractStellarArgument
import com.undefined.stellar.data.argument.CommandContext
import com.undefined.stellar.data.suggestion.StellarSuggestion
import com.undefined.stellar.data.suggestion.Suggestion
import com.undefined.stellar.exception.UnsupportedArgumentTypeException
import org.bukkit.command.CommandSender
import java.util.concurrent.CompletableFuture

Expand All @@ -20,6 +20,10 @@ open class ListArgument<T>(
converter: (T) -> Suggestion = { Suggestion.withText(it.toString()) },
parse: (Any?) -> T?) : this(type, { list }, converter, parse)

init {
if (type is ListArgument<*>) throw UnsupportedArgumentTypeException(type)
}

override val suggestions: MutableList<StellarSuggestion<*>>
get() = (super.suggestions + StellarSuggestion(CommandSender::class) { CompletableFuture.completedFuture(getSuggestionList(this)) }).toMutableList()

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.undefined.stellar.exception

import com.undefined.stellar.argument.AbstractStellarArgument
import java.lang.RuntimeException

class UnsupportedArgumentTypeException(val argument: AbstractStellarArgument<*>) : RuntimeException("List argument does not support ${argument::class.simpleName}!")

0 comments on commit adbbeba

Please sign in to comment.