generated from UndefinedCreations/Template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: basically recode this entire system
- Loading branch information
1 parent
d868b18
commit f98a0cd
Showing
114 changed files
with
831 additions
and
1,467 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
common/src/main/kotlin/com/undefined/stellar/StellarCommands.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
package com.undefined.stellar | ||
|
||
import org.jetbrains.annotations.ApiStatus | ||
|
||
object StellarCommands { | ||
@ApiStatus.Internal | ||
val commands: MutableList<AbstractStellarCommand<*>> = mutableListOf() | ||
@ApiStatus.Internal | ||
fun getStellarCommand(command: String): AbstractStellarCommand<*>? = commands.firstOrNull { it.name == command || it.aliases.contains(command) } | ||
} |
26 changes: 21 additions & 5 deletions
26
common/src/main/kotlin/com/undefined/stellar/data/argument/CommandContext.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,26 @@ | ||
package com.undefined.stellar.data.argument | ||
|
||
import java.util.* | ||
import com.undefined.stellar.exception.ArgumentCastMismatchException | ||
import org.bukkit.command.CommandSender | ||
|
||
typealias CommandNode = LinkedList<Any?> | ||
typealias CommandNode = HashMap<String, (CommandContext<CommandSender>) -> Any?> | ||
|
||
@Suppress("UNCHECKED_CAST", "UNUSED") | ||
class CommandContext<T : CommandSender>(val arguments: CommandNode, val source: T, val input: String) { | ||
|
||
inline fun <reified T> getArgument(name: String): T { | ||
val argument = arguments[name] ?: throw NoSuchElementException("No argument with the name $name") | ||
val context = this as CommandContext<CommandSender> | ||
return argument(context) as? T | ||
?: throw ArgumentCastMismatchException("Argument of index $name cannot be cast into ${T::class.simpleName}!") | ||
} | ||
|
||
inline fun <reified T> getArgument(index: Int): T = | ||
arguments.values.toList()[index](this as CommandContext<CommandSender>) as? T | ||
?: throw ArgumentCastMismatchException("Argument of index $index cannot be cast into ${T::class.simpleName}!") | ||
|
||
operator fun get(index: Int) = arguments.values.toList()[index](this as CommandContext<CommandSender>) | ||
operator fun get(name: String) = (arguments[name] | ||
?: throw NoSuchElementException("No argument with the name $name"))(this as CommandContext<CommandSender>) | ||
|
||
class CommandContext(val arguments: CommandNode, val input: String) { | ||
fun <T> getSubCommand(int: Int): T = arguments[int] as T | ||
operator fun get(int: Int) = arguments[int] | ||
} |
11 changes: 0 additions & 11 deletions
11
common/src/main/kotlin/com/undefined/stellar/data/execution/CustomStellarExecution.kt
This file was deleted.
Oops, something went wrong.
11 changes: 0 additions & 11 deletions
11
common/src/main/kotlin/com/undefined/stellar/data/execution/CustomStellarRunnable.kt
This file was deleted.
Oops, something went wrong.
10 changes: 10 additions & 0 deletions
10
common/src/main/kotlin/com/undefined/stellar/data/execution/ReturnableStellarExecution.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.undefined.stellar.data.execution | ||
|
||
import com.undefined.stellar.data.argument.CommandContext | ||
import org.bukkit.command.CommandSender | ||
|
||
data class ReturnableStellarExecution<C : CommandSender, V : Any?>(val execution: CommandContext<C>.(V) -> Unit) { | ||
operator fun invoke(context: CommandContext<CommandSender>, value: V) { | ||
execution(context as? CommandContext<C> ?: return, value) | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
common/src/main/kotlin/com/undefined/stellar/data/execution/ReturnableStellarRunnable.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.undefined.stellar.data.execution | ||
|
||
import com.undefined.stellar.data.argument.CommandContext | ||
import org.bukkit.command.CommandSender | ||
|
||
data class ReturnableStellarRunnable<C : CommandSender, V : Any?>(val runnable: CommandContext<C>.(V) -> Boolean) { | ||
operator fun invoke(context: CommandContext<CommandSender>, value: V): Boolean { | ||
return runnable(context as? CommandContext<C> ?: return true, value) | ||
} | ||
} |
9 changes: 4 additions & 5 deletions
9
common/src/main/kotlin/com/undefined/stellar/data/execution/StellarExecution.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,10 @@ | ||
package com.undefined.stellar.data.execution | ||
|
||
import com.undefined.stellar.data.argument.CommandContext | ||
import org.bukkit.command.CommandSender | ||
import kotlin.reflect.KClass | ||
import kotlin.reflect.safeCast | ||
|
||
data class StellarExecution<T : CommandSender>(val kClass: KClass<T>, val execution: T.() -> Unit) { | ||
fun run(sender: CommandSender) { | ||
execution.invoke(kClass.safeCast(sender) ?: return) | ||
data class StellarExecution<T : CommandSender>(val execution: CommandContext<T>.() -> Unit) { | ||
operator fun invoke(context: CommandContext<CommandSender>) { | ||
execution(context as? CommandContext<T> ?: return) | ||
} | ||
} |
9 changes: 4 additions & 5 deletions
9
common/src/main/kotlin/com/undefined/stellar/data/execution/StellarRunnable.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,10 @@ | ||
package com.undefined.stellar.data.execution | ||
|
||
import com.undefined.stellar.data.argument.CommandContext | ||
import org.bukkit.command.CommandSender | ||
import kotlin.reflect.KClass | ||
import kotlin.reflect.safeCast | ||
|
||
data class StellarRunnable<T : CommandSender>(val kClass: KClass<T>, val execution: T.() -> Boolean) { | ||
fun run(sender: CommandSender): Boolean { | ||
return execution.invoke(kClass.safeCast(sender) ?: return false) | ||
data class StellarRunnable<C : CommandSender>(val execution: CommandContext<C>.() -> Boolean) { | ||
fun run(context: CommandContext<CommandSender>): Boolean { | ||
return execution(context as? CommandContext<C> ?: return true) | ||
} | ||
} |
8 changes: 3 additions & 5 deletions
8
common/src/main/kotlin/com/undefined/stellar/data/requirement/StellarRequirement.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,9 @@ | ||
package com.undefined.stellar.data.requirement | ||
|
||
import org.bukkit.command.CommandSender | ||
import kotlin.reflect.KClass | ||
import kotlin.reflect.safeCast | ||
|
||
data class StellarRequirement<T : CommandSender>(val kClass: KClass<T>, val execution: T.() -> Boolean) { | ||
fun run(sender: CommandSender): Boolean { | ||
return execution.invoke(kClass.safeCast(sender) ?: return false) | ||
data class StellarRequirement<C : CommandSender>(val execution: C.() -> Boolean) { | ||
operator fun invoke(sender: CommandSender): Boolean { | ||
return execution(sender as? C ?: return true) | ||
} | ||
} |
9 changes: 3 additions & 6 deletions
9
common/src/main/kotlin/com/undefined/stellar/data/suggestion/StellarSuggestion.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,8 @@ | ||
package com.undefined.stellar.data.suggestion | ||
|
||
import com.undefined.stellar.data.argument.CommandContext | ||
import org.bukkit.command.CommandSender | ||
import kotlin.reflect.KClass | ||
import kotlin.reflect.safeCast | ||
|
||
data class StellarSuggestion<T : CommandSender>(val kClass: KClass<T>, val suggestion: T.(input: String) -> List<Suggestion>) { | ||
fun get(sender: CommandSender, input: String): List<Suggestion> { | ||
return suggestion(kClass.safeCast(sender) ?: return listOf(), input) | ||
} | ||
data class StellarSuggestion<C : CommandSender>(val suggestion: CommandContext<C>.() -> List<Suggestion>) { | ||
fun get(context: CommandContext<C>): List<Suggestion> = suggestion(context) | ||
} |
3 changes: 3 additions & 0 deletions
3
common/src/main/kotlin/com/undefined/stellar/exception/ArgumentCastMismatchException.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package com.undefined.stellar.exception | ||
|
||
class ArgumentCastMismatchException(message: String) : RuntimeException() |
3 changes: 3 additions & 0 deletions
3
common/src/main/kotlin/com/undefined/stellar/exception/LiteralArgumentMismatchException.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package com.undefined.stellar.exception | ||
|
||
class LiteralArgumentMismatchException : RuntimeException("This argument is of type Literal, thus you cannot get it's value!") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.