Commands: one plugin - one command manager, sender as player
Kotlin 1.9.20
Genref update
This commit is contained in:
redtea committed 2024-06-27 01:22:23 +03:00
1 parent 95edc90da4
commit 9dfd6c8d39
32 files changed
+264 -116

No files matched your search

+11
View File
@@ -1,3 +1,5 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins { plugins {
id("java") id("java")
kotlin("jvm") kotlin("jvm")
@@ -20,6 +22,7 @@ repositories {
dependencies { dependencies {
compileOnly("org.spigotmc:spigot-api:1.16.5-R0.1-SNAPSHOT") compileOnly("org.spigotmc:spigot-api:1.16.5-R0.1-SNAPSHOT")
implementation(kotlin("stdlib-jdk8"))
} }
tasks.test { tasks.test {
@@ -110,3 +113,11 @@ signing {
useGpgCmd() useGpgCmd()
sign(publishing.publications.getByName("maven")) sign(publishing.publications.getByName("maven"))
} }
val compileKotlin: KotlinCompile by tasks
compileKotlin.kotlinOptions {
jvmTarget = "1.8"
}
val compileTestKotlin: KotlinCompile by tasks
compileTestKotlin.kotlinOptions {
jvmTarget = "1.8"
}
+1 -1
View File
@@ -1,7 +1,7 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins { plugins {
kotlin("jvm") version "1.9.0" kotlin("jvm") version "1.9.20"
id("io.codearte.nexus-staging") version "0.30.0" id("io.codearte.nexus-staging") version "0.30.0"
} }
+11
View File
@@ -1,3 +1,5 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins { plugins {
id("java") id("java")
kotlin("jvm") kotlin("jvm")
@@ -22,6 +24,7 @@ dependencies {
compileOnly("org.spigotmc:spigot-api:1.16.5-R0.1-SNAPSHOT") compileOnly("org.spigotmc:spigot-api:1.16.5-R0.1-SNAPSHOT")
compileOnly(project(":extensions")) compileOnly(project(":extensions"))
implementation(kotlin("reflect")) implementation(kotlin("reflect"))
implementation(kotlin("stdlib-jdk8"))
} }
tasks.test { tasks.test {
@@ -121,3 +124,11 @@ tasks.shadowJar {
} }
} }
val compileKotlin: KotlinCompile by tasks
compileKotlin.kotlinOptions {
jvmTarget = "1.8"
}
val compileTestKotlin: KotlinCompile by tasks
compileTestKotlin.kotlinOptions {
jvmTarget = "1.8"
}
@@ -21,7 +21,7 @@ interface Command {
* @author itzRedTea * @author itzRedTea
* @since 1.0.0 * @since 1.0.0
*/ */
fun execute(invoker: ExecutorContext) fun execute(context: ExecutorContext)
/** /**
* Invokes when command must be executed * Invokes when command must be executed
* @param sender who executes this command * @param sender who executes this command
@@ -34,10 +34,7 @@ interface Command {
fun tabComplete(sender: CommandSender, args: Array<String>): List<String> fun tabComplete(sender: CommandSender, args: Array<String>): List<String>
fun hasNotPermission(sender: CommandSender): Boolean = fun hasNotPermission(sender: CommandSender): Boolean = context.permission != ""
context.permission != "" && (!sender.hasPermission(context.permission)).also { && (!sender.hasPermission(context.permission))
if(it) MessagesService.byTag("#no-perm")(sender)
}
} }
@@ -6,45 +6,39 @@ import org.bukkit.OfflinePlayer
import org.bukkit.World import org.bukkit.World
import org.bukkit.entity.Player import org.bukkit.entity.Player
import tech.carcadex.kotlinbukkitkit.commands.exceptions.ArgumentNotFoundException import tech.carcadex.kotlinbukkitkit.commands.exceptions.ArgumentNotFoundException
import tech.carcadex.kotlinbukkitkit.commands.exceptions.TypeParseException import tech.carcadex.kotlinbukkitkit.commands.exceptions.CommandExecuteException
import tech.carcadex.kotlinbukkitkit.commands.service.MessagesService
fun ExecutorContext.string(index: Int): String = argument(index) ?: throw ArgumentNotFoundException(index) fun ExecutorContext.string(index: Int): String = argument(index) ?: throw ArgumentNotFoundException(index)
fun ExecutorContext.stringOrNull(index: Int): String? = argument(index) fun ExecutorContext.stringOrNull(index: Int): String? = argument(index)
fun ExecutorContext.integer(index: Int): Int = try { fun ExecutorContext.integer(index: Int): Int = try {
argument(index)?.toInt() argument(index)?.toInt()
} catch (e: NumberFormatException) { } catch (e: NumberFormatException) {
MessagesService.byTag("#not-a-number")(sender) throw CommandExecuteException("#not-a-number")
throw TypeParseException()
} ?: throw ArgumentNotFoundException(index) } ?: throw ArgumentNotFoundException(index)
fun ExecutorContext.integerOrNull(index: Int): Int? = argument(index)?.toIntOrNull() fun ExecutorContext.integerOrNull(index: Int): Int? = argument(index)?.toIntOrNull()
fun ExecutorContext.double(index: Int): Double = try { fun ExecutorContext.double(index: Int): Double = try {
argument(index)?.toDouble() argument(index)?.toDouble()
} catch (e: NumberFormatException) { } catch (e: NumberFormatException) {
MessagesService.byTag("#not-a-number")(sender) throw CommandExecuteException("#not-a-number")
throw TypeParseException()
} ?: throw ArgumentNotFoundException(index) } ?: throw ArgumentNotFoundException(index)
fun ExecutorContext.doubleOrNull(index: Int): Double? = argument(index)?.toDoubleOrNull() fun ExecutorContext.doubleOrNull(index: Int): Double? = argument(index)?.toDoubleOrNull()
fun ExecutorContext.materialOrNull(index: Int): Material? = Material.matchMaterial(string(index)) fun ExecutorContext.materialOrNull(index: Int): Material? = Material.matchMaterial(string(index))
fun ExecutorContext.material(index: Int): Material = fun ExecutorContext.material(index: Int): Material =
materialOrNull(index) ?: run { materialOrNull(index) ?: run {
MessagesService.byTag("#no-such-material")(sender) throw CommandExecuteException("#no-such-material")
throw TypeParseException()
} }
fun ExecutorContext.worldOrNull(index: Int): World? = Bukkit.getWorld(argument(index) ?: "") fun ExecutorContext.worldOrNull(index: Int): World? = Bukkit.getWorld(argument(index) ?: "")
fun ExecutorContext.world(index: Int): World = fun ExecutorContext.world(index: Int): World =
worldOrNull(index) ?: run { worldOrNull(index) ?: run {
MessagesService.byTag("#no-such-world")(sender) throw CommandExecuteException("#no-such-world")
throw TypeParseException()
} }
fun ExecutorContext.playerOrNull(index: Int): Player? = Bukkit.getPlayer(argument(index) ?: "") fun ExecutorContext.playerOrNull(index: Int): Player? = Bukkit.getPlayer(argument(index) ?: "")
fun ExecutorContext.player(index: Int): Player = fun ExecutorContext.player(index: Int): Player =
playerOrNull(index) ?: run { playerOrNull(index) ?: run {
MessagesService.byTag("#no-such-player")(sender) throw CommandExecuteException("#no-such-player")
throw TypeParseException()
} }
fun ExecutorContext.offlinePlayer(index: Int): OfflinePlayer = Bukkit.getOfflinePlayer(argument(index) ?: "") fun ExecutorContext.offlinePlayer(index: Int): OfflinePlayer = Bukkit.getOfflinePlayer(argument(index) ?: "")
@@ -1,21 +1,13 @@
package tech.carcadex.kotlinbukkitkit.commands.dsl package tech.carcadex.kotlinbukkitkit.commands.dsl
import org.bukkit.Bukkit
import org.bukkit.Material
import org.bukkit.OfflinePlayer
import org.bukkit.World
import org.bukkit.command.CommandSender import org.bukkit.command.CommandSender
import org.bukkit.entity.Player import org.bukkit.entity.Player
import tech.carcadex.kotlinbukkitkit.commands.exceptions.ArgumentNotFoundException
import tech.carcadex.kotlinbukkitkit.commands.exceptions.NotPlayerException import tech.carcadex.kotlinbukkitkit.commands.exceptions.NotPlayerException
import tech.carcadex.kotlinbukkitkit.commands.exceptions.TypeParseException
import tech.carcadex.kotlinbukkitkit.commands.service.MessagesService
class ExecutorContext(val sender: CommandSender, val args: Array<String>) { class ExecutorContext(val sender: CommandSender, val args: Array<String>) {
val player: Player val player: Player
get() { get() {
if (sender !is Player) { if (sender !is Player) {
MessagesService.byTag("#for-player-only")(sender)
throw NotPlayerException() throw NotPlayerException()
} }
return sender return sender
@@ -1,17 +1,24 @@
package tech.carcadex.kotlinbukkitkit.commands.dsl.builder package tech.carcadex.kotlinbukkitkit.commands.dsl.builder
import org.bukkit.command.CommandSender
import org.bukkit.plugin.Plugin import org.bukkit.plugin.Plugin
import tech.carcadex.kotlinbukkitkit.commands.dsl.Command import tech.carcadex.kotlinbukkitkit.commands.dsl.Command
import tech.carcadex.kotlinbukkitkit.commands.dsl.CommandContext import tech.carcadex.kotlinbukkitkit.commands.dsl.CommandContext
import tech.carcadex.kotlinbukkitkit.commands.dsl.ExecutorContext import tech.carcadex.kotlinbukkitkit.commands.dsl.ExecutorContext
import tech.carcadex.kotlinbukkitkit.commands.dsl.leaf.CommandLeaf import tech.carcadex.kotlinbukkitkit.commands.dsl.leaf.CommandLeaf
import tech.carcadex.kotlinbukkitkit.commands.dsl.node.CommandNodeImpl import tech.carcadex.kotlinbukkitkit.commands.dsl.node.CommandNodeImpl
import tech.carcadex.kotlinbukkitkit.commands.exceptions.CommandExecuteException
import tech.carcadex.kotlinbukkitkit.commands.exceptions.LeafCommandHasNotExecutorException import tech.carcadex.kotlinbukkitkit.commands.exceptions.LeafCommandHasNotExecutorException
import tech.carcadex.kotlinbukkitkit.commands.manager.CommandManagerInternal
import tech.carcadex.kotlinbukkitkit.commands.manager.commandManager
import tech.carcadex.kotlinbukkitkit.commands.manager.commandManagerInternal
import tech.carcadex.kotlinbukkitkit.commands.register.CommandRegister import tech.carcadex.kotlinbukkitkit.commands.register.CommandRegister
import tech.carcadex.kotlinbukkitkit.commands.service.TabCompleteService
class CommandBuilder( class CommandBuilder(
val context: CommandContext, val context: CommandContext,
var tabComplete: Collection<String> = emptyList(), val plugin: Plugin,
var tabComplete: List<(CommandSender) -> List<String>> = emptyList(),
val subs: MutableMap<String, Command> = mutableMapOf(), val subs: MutableMap<String, Command> = mutableMapOf(),
var executor: (ExecutorContext.() -> Unit)? = null var executor: (ExecutorContext.() -> Unit)? = null
) { ) {
@@ -22,7 +29,7 @@ class CommandBuilder(
} }
fun CommandBuilder.subCommand(name: String, permission: String, tabComplete: Collection<String>, invoke: CommandBuilder.() -> Unit) { fun CommandBuilder.subCommand(name: String, permission: String, tabComplete: Collection<String>, invoke: CommandBuilder.() -> Unit) {
subs[name.lowercase()] = createCommand(name, permission, tabComplete, invoke) subs[name.lowercase()] = plugin.createCommand(name, permission, tabComplete, invoke)
} }
fun CommandBuilder.executor(executor: ExecutorContext.() -> Unit) { fun CommandBuilder.executor(executor: ExecutorContext.() -> Unit) {
@@ -30,38 +37,41 @@ fun CommandBuilder.executor(executor: ExecutorContext.() -> Unit) {
} }
private fun createCommand(name: String, permission: String, tabComplete: Collection<String>, invoke: CommandBuilder.() -> Unit): Command { private fun Plugin.createCommand(name: String, permission: String, tabComplete: Collection<String>, invoke: CommandBuilder.() -> Unit): Command {
val builder = CommandBuilder(CommandContext(name)) val builder = CommandBuilder(CommandContext(name), this)
builder.permission = permission builder.permission = permission
builder.tabComplete = tabComplete builder.tabComplete = commandManagerInternal().tabCompleteService.parseTags(tabComplete.toList())
builder.invoke() builder.invoke()
return createCommand(builder) return createCommand(builder)
} }
private fun createCommand(builder: CommandBuilder): Command { private fun createCommand(builder: CommandBuilder): Command {
return if (builder.subs.isEmpty()) { return if (builder.subs.isEmpty()) {
if (builder.executor == null) throw LeafCommandHasNotExecutorException(builder.context.name) if (builder.executor == null) throw LeafCommandHasNotExecutorException(builder.context.name)
CommandLeaf(builder.context, builder.executor!!, builder.tabComplete.toList()) CommandLeaf(builder.context, builder.executor!!, (builder.tabComplete.toList()))
} else { } else {
CommandNodeImpl(builder.context, builder.subs) CommandNodeImpl(builder.context, builder.subs,
if(builder.executor != null) CommandLeaf(builder.context, builder.executor!!, builder.tabComplete) else null)
} }
} }
fun Plugin.simpleCommand(name: String, permission: String, tabComplete: Collection<String>, executor: ExecutorContext.() -> Unit) { fun Plugin.simpleCommand(name: String, permission: String, tabComplete: Collection<String>, executor: ExecutorContext.() -> Unit) {
val command = createCommand(CommandBuilder(CommandContext(name), registerCommand(createCommand(CommandBuilder(CommandContext(name),
executor = executor).apply { executor = executor, plugin = this).apply {
this.permission = permission this.permission = permission
this.tabComplete = tabComplete this.tabComplete = commandManagerInternal().tabCompleteService.parseTags(tabComplete.toList())
}) }))
CommandRegister.register(this, { sender, _, _, args -> command.execute(ExecutorContext(sender, args)); true },
command.context.aliases, command.context.description, command.context.usage, { sender, _, _, args ->
command.tabComplete(sender, args)
}
)
} }
fun Plugin.command(name: String, permission: String, tabComplete: Collection<String>, invoke: CommandBuilder.() -> Unit) { fun Plugin.command(name: String, permission: String, tabComplete: Collection<String>, invoke: CommandBuilder.() -> Unit) {
val command = createCommand(name, permission, tabComplete, invoke) registerCommand(createCommand(name, permission, tabComplete, invoke))
CommandRegister.register(this, { sender, _, _, args -> command.execute(ExecutorContext(sender, args)); true }, }
private fun Plugin.registerCommand(command: Command) {
CommandRegister.register(this, { sender, _, _, args -> try {
command.execute(ExecutorContext(sender, args))
} catch (e: CommandExecuteException) {
commandManager().readMessage(e.messageTag)(sender)
}; true },
command.context.aliases, command.context.description, command.context.usage, { sender, _, _, args -> command.context.aliases, command.context.description, command.context.usage, { sender, _, _, args ->
command.tabComplete(sender, args) command.tabComplete(sender, args)
} }
@@ -5,21 +5,20 @@ import tech.carcadex.kotlinbukkitkit.commands.dsl.Command
import tech.carcadex.kotlinbukkitkit.commands.dsl.CommandContext import tech.carcadex.kotlinbukkitkit.commands.dsl.CommandContext
import tech.carcadex.kotlinbukkitkit.commands.dsl.ExecutorContext import tech.carcadex.kotlinbukkitkit.commands.dsl.ExecutorContext
import tech.carcadex.kotlinbukkitkit.commands.exceptions.ArgumentNotFoundException import tech.carcadex.kotlinbukkitkit.commands.exceptions.ArgumentNotFoundException
import tech.carcadex.kotlinbukkitkit.commands.service.MessagesService import tech.carcadex.kotlinbukkitkit.commands.exceptions.CommandExecuteException
import tech.carcadex.kotlinbukkitkit.commands.service.TabCompleteService
class CommandLeaf( class CommandLeaf(
override val context: CommandContext, override val context: CommandContext,
private val executor: (ExecutorContext.() -> Unit), private val executor: (ExecutorContext.() -> Unit),
completeTags: List<String> = emptyList() private val completer: List<(CommandSender) -> List<String>>
) : Command { ) : Command {
private val completer = TabCompleteService.parseTags(completeTags)
override fun execute(context: ExecutorContext) { override fun execute(context: ExecutorContext) {
if(hasNotPermission(context.sender)) return if(hasNotPermission(context.sender))
throw CommandExecuteException("#no-perm")
try { try {
executor(context) executor(context)
} catch (e: ArgumentNotFoundException) { } catch (e: ArgumentNotFoundException) {
MessagesService.byTag("#wrong-usage")(context.sender) throw CommandExecuteException("#wrong-usage")
} }
} }
@@ -5,13 +5,15 @@ import tech.carcadex.kotlinbukkitkit.commands.dsl.Command
import tech.carcadex.kotlinbukkitkit.commands.dsl.CommandContext import tech.carcadex.kotlinbukkitkit.commands.dsl.CommandContext
import tech.carcadex.kotlinbukkitkit.commands.dsl.CommandNode import tech.carcadex.kotlinbukkitkit.commands.dsl.CommandNode
import tech.carcadex.kotlinbukkitkit.commands.dsl.ExecutorContext import tech.carcadex.kotlinbukkitkit.commands.dsl.ExecutorContext
import tech.carcadex.kotlinbukkitkit.commands.exceptions.CommandExecuteException
import tech.carcadex.kotlinbukkitkit.commands.service.MessagesService import tech.carcadex.kotlinbukkitkit.commands.service.MessagesService
class CommandNodeImpl( class CommandNodeImpl(
override val context: CommandContext, override val context: CommandContext,
private val subs: MutableMap<String, Command> = mutableMapOf() private val subs: MutableMap<String, Command> = mutableMapOf(),
private val default: Command? = null
) : CommandNode { ) : CommandNode {
private var default: Command? = null
override fun execute(context: ExecutorContext) { override fun execute(context: ExecutorContext) {
if(hasNotPermission(context.sender)) return if(hasNotPermission(context.sender)) return
if(context.args.isNotEmpty() && context.args[0].lowercase() in subs) subs[context.args[0].lowercase()]?.execute( if(context.args.isNotEmpty() && context.args[0].lowercase() in subs) subs[context.args[0].lowercase()]?.execute(
@@ -19,7 +21,7 @@ class CommandNodeImpl(
else { else {
if(default != null) { if(default != null) {
default!!.execute(ExecutorContext(context.sender, context.args)) default!!.execute(ExecutorContext(context.sender, context.args))
} else MessagesService.byTag("#wrong-usage")(context.sender) } else throw CommandExecuteException("#wrong-usage")
} }
} }
@@ -0,0 +1,4 @@
package tech.carcadex.kotlinbukkitkit.commands.exceptions
open class CommandExecuteException(val messageTag: String) : RuntimeException() {
}
@@ -1,6 +1,4 @@
package tech.carcadex.kotlinbukkitkit.commands.exceptions package tech.carcadex.kotlinbukkitkit.commands.exceptions
import java.lang.RuntimeException class NotPlayerException() : CommandExecuteException(messageTag = "#for-player-only") {
class NotPlayerException : RuntimeException() {
} }
@@ -1,4 +0,0 @@
package tech.carcadex.kotlinbukkitkit.commands.exceptions
class TypeParseException() : RuntimeException() {
}
@@ -10,11 +10,18 @@ interface CommandManager {
fun register(func: KFunction<Unit>) fun register(func: KFunction<Unit>)
fun tabComplete(tag: String, func: (CommandSender) -> List<String>) fun tabComplete(tag: String, func: (CommandSender) -> List<String>)
fun message(tag: String, func: (CommandSender) -> Unit) fun message(tag: String, func: (CommandSender) -> Unit)
fun readMessage(tag: String): (CommandSender) -> Unit
companion object { companion object {
private val registeredManagers = mutableMapOf<Plugin, CommandManager>()
@JvmStatic @JvmStatic
fun get(plugin: Plugin): CommandManager = CommandManagerImpl(plugin) fun get(plugin: Plugin): CommandManager =
registeredManagers[plugin] ?: run {
registeredManagers[plugin] = CommandManagerInternal(plugin)
get(plugin)
}
} }
} }
fun Plugin.commandManager(): CommandManager = CommandManagerImpl(this) fun Plugin.commandManager(): CommandManager = CommandManager.get(this)
internal fun Plugin.commandManagerInternal(): CommandManagerInternal = CommandManager.get(this) as CommandManagerInternal
@@ -4,26 +4,26 @@ import org.bukkit.command.CommandExecutor
import org.bukkit.command.CommandSender import org.bukkit.command.CommandSender
import org.bukkit.command.TabCompleter import org.bukkit.command.TabCompleter
import org.bukkit.plugin.Plugin import org.bukkit.plugin.Plugin
import tech.carcadex.kotlinbukkitkit.commands.exceptions.NotPlayerException
import tech.carcadex.kotlinbukkitkit.commands.reflection.CommandParams import tech.carcadex.kotlinbukkitkit.commands.reflection.CommandParams
import tech.carcadex.kotlinbukkitkit.commands.reflection.Parser import tech.carcadex.kotlinbukkitkit.commands.reflection.Parser
import tech.carcadex.kotlinbukkitkit.commands.reflection.Parser.paramsFromAnnotations import tech.carcadex.kotlinbukkitkit.commands.reflection.Parser.paramsFromAnnotations
import tech.carcadex.kotlinbukkitkit.commands.reflection.annotations.Command import tech.carcadex.kotlinbukkitkit.commands.reflection.annotations.Command
import tech.carcadex.kotlinbukkitkit.commands.exceptions.TypeParseException import tech.carcadex.kotlinbukkitkit.commands.exceptions.CommandExecuteException
import tech.carcadex.kotlinbukkitkit.commands.register.CommandRegister import tech.carcadex.kotlinbukkitkit.commands.register.CommandRegister
import tech.carcadex.kotlinbukkitkit.commands.service.MessagesService import tech.carcadex.kotlinbukkitkit.commands.service.MessagesService
import tech.carcadex.kotlinbukkitkit.commands.reflection.service.SubCommandsService import tech.carcadex.kotlinbukkitkit.commands.reflection.service.SubCommandsService
import tech.carcadex.kotlinbukkitkit.commands.service.TabCompleteService import tech.carcadex.kotlinbukkitkit.commands.service.TabCompleteService
import kotlin.reflect.KFunction import kotlin.reflect.KFunction
import kotlin.reflect.full.createType import kotlin.reflect.full.createType
import kotlin.reflect.full.findAnnotations
import kotlin.reflect.full.hasAnnotation import kotlin.reflect.full.hasAnnotation
import kotlin.reflect.full.isSubtypeOf import kotlin.reflect.full.isSubtypeOf
import kotlin.reflect.jvm.javaType import kotlin.reflect.jvm.javaType
class CommandManagerInternal(private val plugin: Plugin) : CommandManager {
val messagesService = MessagesService()
class CommandManagerImpl(private val plugin: Plugin) : CommandManager { val tabCompleteService = TabCompleteService()
private val subCommandsService = SubCommandsService(messagesService, tabCompleteService)
private fun register( private fun register(
commandExecutor: CommandExecutor, commandParams: CommandParams, tabCompleter: TabCompleter = commandExecutor: CommandExecutor, commandParams: CommandParams, tabCompleter: TabCompleter =
TabCompleter { _, _, _, _ -> mutableListOf() } TabCompleter { _, _, _, _ -> mutableListOf() }
@@ -39,10 +39,10 @@ class CommandManagerImpl(private val plugin: Plugin) : CommandManager {
} }
override fun register(commandClass: Any) { override fun register(commandClass: Any) {
if(commandClass::class.objectInstance == null) { if((commandClass::class.findAnnotations(Command::class).isEmpty())) {
throw IllegalArgumentException("commandClass is not a object!") throw IllegalArgumentException("commandClass has not contains Command annotation!")
} }
val (name, subs) = SubCommandsService.registerRootCommand(commandClass) val (name, subs) = subCommandsService.registerRootCommand(commandClass)
val subsNames = mutableListOf<String>() val subsNames = mutableListOf<String>()
subs.forEach { subs.forEach {
subsNames.addAll(it.context.aliases) subsNames.addAll(it.context.aliases)
@@ -50,10 +50,10 @@ class CommandManagerImpl(private val plugin: Plugin) : CommandManager {
val context = paramsFromAnnotations(commandClass::class) val context = paramsFromAnnotations(commandClass::class)
register(CommandExecutor { sender, _, _, args -> register(CommandExecutor { sender, _, _, args ->
if (context.perm != null && !sender.hasPermission(context.perm)) { if (context.perm != null && !sender.hasPermission(context.perm)) {
MessagesService.byTag("#no-perm")(sender) messagesService.byTag("#no-perm")(sender)
return@CommandExecutor true return@CommandExecutor true
} }
SubCommandsService.handleCommand(name, sender, args); subCommandsService.handleCommand(name, sender, args);
true true
}, },
context, context,
@@ -87,19 +87,19 @@ class CommandManagerImpl(private val plugin: Plugin) : CommandManager {
register(CommandExecutor { sender, _, _, argsFromExecutor -> register(CommandExecutor { sender, _, _, argsFromExecutor ->
if (cmd.perm != null && !sender.hasPermission(cmd.perm)) { if (cmd.perm != null && !sender.hasPermission(cmd.perm)) {
MessagesService.byTag("#no-perm")(sender) messagesService.byTag("#no-perm")(sender)
return@CommandExecutor true return@CommandExecutor true
} }
try { try {
func.callBy( func.callBy(
Parser.paramMap(cmd, argsFromExecutor, argsSize, sender, argsParsers, func) Parser.paramMap(cmd, argsFromExecutor, argsSize, sender, argsParsers, func)
) )
} catch (ignored: TypeParseException) { } catch (e: CommandExecuteException) {
} catch (ignored: NotPlayerException) { messagesService.byTag(e.messageTag)(sender)
} catch (e: IllegalArgumentException) { } catch (e: IllegalArgumentException) {
MessagesService.byTag("#wrong-usage")(sender) messagesService.byTag("#wrong-usage")(sender)
} catch (e: Throwable) {
messagesService.byTag("#unknown-error")(sender)
} }
return@CommandExecutor true return@CommandExecutor true
@@ -107,20 +107,21 @@ class CommandManagerImpl(private val plugin: Plugin) : CommandManager {
}, },
cmd, cmd,
cmd.completeTags.let { cmd.completeTags.let {
TabCompleteService.completerReflection(it.toMutableList(), tabCompleteService.completerReflection(it.toMutableList(),
func.parameters.map { it.type.javaType as Class<*> }) func.parameters.map { it.type.javaType as Class<*> })
} }
?: TabCompleter { _, _, _, _ -> mutableListOf() }
) )
} else throw IllegalArgumentException("It must be a command!") } else throw IllegalArgumentException("It must be a command!")
} }
override fun tabComplete(tag: String, func: (CommandSender) -> List<String>) { override fun tabComplete(tag: String, func: (CommandSender) -> List<String>) {
TabCompleteService.register(tag, func) tabCompleteService.register(tag, func)
} }
override fun message(tag: String, func: (CommandSender) -> Unit) { override fun message(tag: String, func: (CommandSender) -> Unit) {
MessagesService.register(tag, func) messagesService.register(tag, func)
} }
override fun readMessage(tag: String): (CommandSender) -> Unit = messagesService.byTag(tag)
} }
@@ -1,7 +1,7 @@
package tech.carcadex.kotlinbukkitkit.commands.reflection package tech.carcadex.kotlinbukkitkit.commands.reflection
import org.bukkit.command.CommandSender import org.bukkit.command.CommandSender
import tech.carcadex.kotlinbukkitkit.commands.exceptions.TypeParseException import tech.carcadex.kotlinbukkitkit.commands.exceptions.CommandExecuteException
import tech.carcadex.kotlinbukkitkit.commands.exceptions.UnsupportedTypeException import tech.carcadex.kotlinbukkitkit.commands.exceptions.UnsupportedTypeException
import tech.carcadex.kotlinbukkitkit.commands.reflection.annotations.* import tech.carcadex.kotlinbukkitkit.commands.reflection.annotations.*
import tech.carcadex.kotlinbukkitkit.commands.service.MessagesService import tech.carcadex.kotlinbukkitkit.commands.service.MessagesService
@@ -59,19 +59,17 @@ object Parser {
try { try {
TypeService.byType(argType.type)(context) TypeService.byType(argType.type)(context)
} catch (e: Throwable) { } catch (e: Throwable) {
if (context.errorMessage != null) MessagesService.byTag(context.errorMessage!!)(sender) throw CommandExecuteException(context.errorMessage ?: "#empty")
throw TypeParseException()
} }
} }
} else if (!clazz.isEnum) throw UnsupportedTypeException("Type ${argType.type.javaType.typeName} is not supported") } else if (!clazz.isEnum) throw UnsupportedTypeException("Type ${argType.type.javaType.typeName} is not supported")
else { else {
enums[argIndex] = { it, sender -> enums[argIndex] = { it, _ ->
var res: Enum<*>? = null; var res: Enum<*>? = null;
for (e in clazz.enumConstants) { for (e in clazz.enumConstants) {
if ((e as Enum<*>).name.equals(it, ignoreCase = true)) res = e; if ((e as Enum<*>).name.equals(it, ignoreCase = true)) res = e;
} }
if (res == null) MessagesService.byTag("#no-such-enum")(sender) res ?: throw CommandExecuteException("#no-such-enum")
res ?: throw TypeParseException()
} }
argsParsers.add { _, _ -> {} } argsParsers.add { _, _ -> {} }
} }
@@ -102,8 +100,6 @@ object Parser {
instanceAtStart: Boolean = false, instanceAtStart: Boolean = false,
instance: Any = Any() instance: Any = Any()
): MutableMap<KParameter, Any?> { ): MutableMap<KParameter, Any?> {
val tempArgs = if (cmd.isLastOptional && argsFromExecutor.size < argsSize) argsFromExecutor.copyOf(argsSize)
else argsFromExecutor
val finalArgs = mutableListOf<Any?>() val finalArgs = mutableListOf<Any?>()
if(instanceAtStart) finalArgs.add(instance) if(instanceAtStart) finalArgs.add(instance)
@@ -113,7 +109,7 @@ object Parser {
) )
) )
finalArgs.add(sender) finalArgs.add(sender)
finalArgs.addAll(tempArgs.mapIndexed { i, it -> finalArgs.addAll(argsFromExecutor.mapIndexed { i, it ->
if (it == null) return@mapIndexed null if (it == null) return@mapIndexed null
argsParsers[i + 1](it, sender) argsParsers[i + 1](it, sender)
}) })
@@ -9,12 +9,12 @@ import tech.carcadex.kotlinbukkitkit.commands.reflection.CommandParams
import tech.carcadex.kotlinbukkitkit.commands.reflection.Parser import tech.carcadex.kotlinbukkitkit.commands.reflection.Parser
import tech.carcadex.kotlinbukkitkit.commands.reflection.annotations.Command import tech.carcadex.kotlinbukkitkit.commands.reflection.annotations.Command
import tech.carcadex.kotlinbukkitkit.commands.reflection.annotations.Default import tech.carcadex.kotlinbukkitkit.commands.reflection.annotations.Default
import tech.carcadex.kotlinbukkitkit.commands.exceptions.TypeParseException import tech.carcadex.kotlinbukkitkit.commands.exceptions.CommandExecuteException
import kotlin.reflect.KFunction import kotlin.reflect.KFunction
import kotlin.reflect.full.* import kotlin.reflect.full.*
import kotlin.reflect.jvm.javaType import kotlin.reflect.jvm.javaType
object SubCommandsService { class SubCommandsService(private val messagesService: MessagesService, private val tabCompleteService: TabCompleteService) {
data class SubCommand(val name: String, val context: CommandParams, data class SubCommand(val name: String, val context: CommandParams,
val executor: (sender: CommandSender, args: Array<String>) -> Boolean, val tabCompleter: TabCompleter) val executor: (sender: CommandSender, args: Array<String>) -> Boolean, val tabCompleter: TabCompleter)
@@ -44,7 +44,7 @@ object SubCommandsService {
if(args.isNotEmpty()) for(sub in subs[rootCommand.lowercase()]!!) { if(args.isNotEmpty()) for(sub in subs[rootCommand.lowercase()]!!) {
if(sub.name == args[0]) { if(sub.name == args[0]) {
if (sub.context.perm != null && sub.context.perm != "" && !sender.hasPermission(sub.context.perm)) { if (sub.context.perm != null && sub.context.perm != "" && !sender.hasPermission(sub.context.perm)) {
MessagesService.byTag("#no-perm")(sender) messagesService.byTag("#no-perm")(sender)
return return
} }
sub.executor(sender, args.copyOfRange(1, args.size)) sub.executor(sender, args.copyOfRange(1, args.size))
@@ -70,18 +70,18 @@ object SubCommandsService {
} }
val executor: (sender: CommandSender, args: Array<String>) -> Boolean = { sender, argsFromExecutor -> val executor: (sender: CommandSender, args: Array<String>) -> Boolean = { sender, argsFromExecutor ->
if (context.perm != null && !sender.hasPermission(context.perm)) { if (context.perm != null && !sender.hasPermission(context.perm)) {
MessagesService.byTag("#no-perm")(sender) messagesService.byTag("#no-perm")(sender)
true true
} else { } else {
try { try {
func.callBy(Parser.paramMap(context, argsFromExecutor, argsSize, sender, argsParsers, func, true, rootCommand)) func.callBy(Parser.paramMap(context, argsFromExecutor, argsSize, sender, argsParsers, func, true, rootCommand))
true true
} catch (ignored: TypeParseException) { } catch (ignored: CommandExecuteException) {
false false
} catch (ignored: NotPlayerException) { } catch (ignored: NotPlayerException) {
false false
} catch (e: IllegalArgumentException) { } catch (e: IllegalArgumentException) {
MessagesService.byTag("#wrong-usage")(sender) messagesService.byTag("#wrong-usage")(sender)
false false
} }
@@ -89,7 +89,7 @@ object SubCommandsService {
} }
return SubCommand(name, context, executor, context.completeTags.let { return SubCommand(name, context, executor, context.completeTags.let {
TabCompleteService.completerReflection(it.toMutableList(), tabCompleteService.completerReflection(it.toMutableList(),
func.parameters.map { it.type.javaType as Class<*> }) func.parameters.map { it.type.javaType as Class<*> })
} }
?: TabCompleter { _, _, _, _ -> mutableListOf() }) ?: TabCompleter { _, _, _, _ -> mutableListOf() })
@@ -3,7 +3,7 @@ package tech.carcadex.kotlinbukkitkit.commands.service
import org.bukkit.ChatColor import org.bukkit.ChatColor
import org.bukkit.command.CommandSender import org.bukkit.command.CommandSender
object MessagesService { class MessagesService {
private val messages = mutableMapOf<String, (CommandSender) -> Unit>() private val messages = mutableMapOf<String, (CommandSender) -> Unit>()
init { init {
@@ -15,7 +15,9 @@ object MessagesService {
messages["#no-such-enum"] = { it.sendMessage("${ChatColor.RED}No such value for this enum was found") } messages["#no-such-enum"] = { it.sendMessage("${ChatColor.RED}No such value for this enum was found") }
messages["#not-a-number"] = { it.sendMessage("${ChatColor.RED}It is not a number") } messages["#not-a-number"] = { it.sendMessage("${ChatColor.RED}It is not a number") }
messages["#wrong-usage"] = { it.sendMessage("${ChatColor.RED}Wrong usage of command") } messages["#wrong-usage"] = { it.sendMessage("${ChatColor.RED}Wrong usage of command") }
messages["#unknown-error"] = { it.sendMessage("${ChatColor.RED}Something went wrong") }
messages["#no-perm"] = { it.sendMessage("${ChatColor.RED}You have not permissions for this command!") } messages["#no-perm"] = { it.sendMessage("${ChatColor.RED}You have not permissions for this command!") }
messages["#empty"] = { }
} }
fun register(tag: String, func: (CommandSender) -> Unit) { fun register(tag: String, func: (CommandSender) -> Unit) {
@@ -3,9 +3,8 @@ package tech.carcadex.kotlinbukkitkit.commands.service
import org.bukkit.Bukkit import org.bukkit.Bukkit
import org.bukkit.command.CommandSender import org.bukkit.command.CommandSender
import org.bukkit.command.TabCompleter import org.bukkit.command.TabCompleter
import kotlin.collections.ArrayList
object TabCompleteService { class TabCompleteService {
private val completes = mutableMapOf<String, (CommandSender) -> List<String>>() private val completes = mutableMapOf<String, (CommandSender) -> List<String>>()
init { init {
//REGISTER DEFAULT COMPLETES //REGISTER DEFAULT COMPLETES
+11
View File
@@ -1,3 +1,5 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins { plugins {
id("java") id("java")
kotlin("jvm") kotlin("jvm")
@@ -29,6 +31,7 @@ dependencies {
api(project(":extensions")) api(project(":extensions"))
api(project(":utility")) api(project(":utility"))
compileOnly("org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.1") compileOnly("org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.1")
implementation(kotlin("stdlib-jdk8"))
} }
tasks.test { tasks.test {
@@ -119,3 +122,11 @@ signing {
useGpgCmd() useGpgCmd()
sign(publishing.publications.getByName("maven")) sign(publishing.publications.getByName("maven"))
} }
val compileKotlin: KotlinCompile by tasks
compileKotlin.kotlinOptions {
jvmTarget = "1.8"
}
val compileTestKotlin: KotlinCompile by tasks
compileTestKotlin.kotlinOptions {
jvmTarget = "1.8"
}
+11
View File
@@ -1,3 +1,5 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins { plugins {
id("java") id("java")
kotlin("jvm") kotlin("jvm")
@@ -21,6 +23,7 @@ repositories {
dependencies { dependencies {
compileOnly("org.spigotmc:spigot-api:1.16.5-R0.1-SNAPSHOT") compileOnly("org.spigotmc:spigot-api:1.16.5-R0.1-SNAPSHOT")
api(project(":architecture")) api(project(":architecture"))
implementation(kotlin("stdlib-jdk8"))
} }
tasks.test { tasks.test {
@@ -111,3 +114,11 @@ signing {
useGpgCmd() useGpgCmd()
sign(publishing.publications.getByName("maven")) sign(publishing.publications.getByName("maven"))
} }
val compileKotlin: KotlinCompile by tasks
compileKotlin.kotlinOptions {
jvmTarget = "1.8"
}
val compileTestKotlin: KotlinCompile by tasks
compileTestKotlin.kotlinOptions {
jvmTarget = "1.8"
}
+11
View File
@@ -1,3 +1,5 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins { plugins {
id("java") id("java")
kotlin("jvm") kotlin("jvm")
@@ -24,6 +26,7 @@ dependencies {
implementation("com.google.devtools.ksp:symbol-processing-api:1.9.0-1.0.11") implementation("com.google.devtools.ksp:symbol-processing-api:1.9.0-1.0.11")
implementation("com.squareup:kotlinpoet:1.10.1") implementation("com.squareup:kotlinpoet:1.10.1")
implementation("com.squareup:kotlinpoet-ksp:1.10.1") implementation("com.squareup:kotlinpoet-ksp:1.10.1")
implementation(kotlin("stdlib-jdk8"))
} }
tasks.test { tasks.test {
@@ -114,3 +117,11 @@ signing {
useGpgCmd() useGpgCmd()
sign(publishing.publications.getByName("maven")) sign(publishing.publications.getByName("maven"))
} }
val compileKotlin: KotlinCompile by tasks
compileKotlin.kotlinOptions {
jvmTarget = "1.8"
}
val compileTestKotlin: KotlinCompile by tasks
compileTestKotlin.kotlinOptions {
jvmTarget = "1.8"
}
@@ -15,6 +15,8 @@ import com.squareup.kotlinpoet.ksp.writeTo
import tech.carcadex.kotlinbukkitkit.genref.plugin.annotations.OnDisable import tech.carcadex.kotlinbukkitkit.genref.plugin.annotations.OnDisable
import tech.carcadex.kotlinbukkitkit.genref.plugin.annotations.Plugin import tech.carcadex.kotlinbukkitkit.genref.plugin.annotations.Plugin
import tech.carcadex.kotlinbukkitkit.architecture.KotlinPlugin import tech.carcadex.kotlinbukkitkit.architecture.KotlinPlugin
import tech.carcadex.kotlinbukkitkit.genref.plugin.annotations.OnConfigReload
import tech.carcadex.kotlinbukkitkit.genref.plugin.annotations.OnLoad
import java.nio.file.Path import java.nio.file.Path
import java.nio.file.Paths import java.nio.file.Paths
import kotlin.io.path.deleteIfExists import kotlin.io.path.deleteIfExists
@@ -71,8 +73,9 @@ class PluginVisitor(private val codeGenerator: CodeGenerator,
@OptIn(KspExperimental::class) @OptIn(KspExperimental::class)
override fun visitFunctionDeclaration(function: KSFunctionDeclaration, data: Unit) { override fun visitFunctionDeclaration(function: KSFunctionDeclaration, data: Unit) {
if (function.getAnnotationsByType(OnDisable::class).any()) disable(function) if (function.getAnnotationsByType(OnDisable::class).any()) disable(function)
if(function.getAnnotationsByType(Plugin::class).any()) enable(function) if(function.getAnnotationsByType(Plugin::class).any()) enable(function)
if(function.getAnnotationsByType(OnConfigReload::class).any()) configReload(function)
if(function.getAnnotationsByType(OnLoad::class).any()) load(function)
} }
fun disable(function: KSFunctionDeclaration) { fun disable(function: KSFunctionDeclaration) {
@@ -98,6 +101,29 @@ class PluginVisitor(private val codeGenerator: CodeGenerator,
.build()) .build())
} }
fun load(function: KSFunctionDeclaration) {
funcs.add(FunSpec.builder("onPluginLoad")
.addCode(CodeBlock.of("""
plugin = this
${function.simpleName.getShortName()}()
""".trimIndent()))
.returns(Unit::class)
.addModifiers(KModifier.OVERRIDE)
.build())
}
fun configReload(function: KSFunctionDeclaration) {
funcs.add(FunSpec.builder("onConfigReload")
.addCode(CodeBlock.of("""
plugin = this
${function.simpleName.getShortName()}()
""".trimIndent()))
.returns(Unit::class)
.addModifiers(KModifier.OVERRIDE)
.build())
}
} }
@@ -0,0 +1,5 @@
package tech.carcadex.kotlinbukkitkit.genref.plugin.annotations
@Target(AnnotationTarget.FUNCTION)
@Retention(AnnotationRetention.SOURCE)
annotation class OnConfigReload()
@@ -0,0 +1,5 @@
package tech.carcadex.kotlinbukkitkit.genref.plugin.annotations
@Target(AnnotationTarget.FUNCTION)
@Retention(AnnotationRetention.SOURCE)
annotation class OnLoad()
+10 -10
View File
@@ -1,18 +1,18 @@
version=1.0.0.4-SNAPSHOT version=lastest
signing.gnupg.executable=C:/Program Files (x86)/GnuPG/bin/gpg.exe signing.gnupg.executable=gpg.exe
signing.gnupg.useLegacyGpg=false signing.gnupg.useLegacyGpg=false
signing.gnupg.keyName=0D0AC475D4E1770131FF571149B3C697DD0584C4 signing.gnupg.keyName=secret
signing.gnupg.passphrase=ere112 signing.gnupg.passphrase=secret
ossrhUsername=itzRedTea ossrhUsername=secret
ossrhPassword=Au~Ra~258+++ ossrhPassword=secret
nexusUsername=itzRedTea nexusUsername=secret
nexusPassword=Au~Ra~258+++ nexusPassword=secret
sonatype.stagingProfileId=iRedTea sonatype.stagingProfileId=secret
password=Au~Ra~258+++ password=secret
kotlin.code.style=official kotlin.code.style=official
+1 -1
View File
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.1-bin.zip distributionUrl=https\://services.gradle.org/distributions/gradle-8.1-bin.zip
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
+11
View File
@@ -1,3 +1,5 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins { plugins {
id("java") id("java")
kotlin("jvm") kotlin("jvm")
@@ -25,6 +27,7 @@ dependencies {
api(project(":extensions")) api(project(":extensions"))
api(project(":utility")) api(project(":utility"))
compileOnly("org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.1") compileOnly("org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.1")
implementation(kotlin("stdlib-jdk8"))
} }
tasks.test { tasks.test {
@@ -115,3 +118,11 @@ signing {
useGpgCmd() useGpgCmd()
sign(publishing.publications.getByName("maven")) sign(publishing.publications.getByName("maven"))
} }
val compileKotlin: KotlinCompile by tasks
compileKotlin.kotlinOptions {
jvmTarget = "1.8"
}
val compileTestKotlin: KotlinCompile by tasks
compileTestKotlin.kotlinOptions {
jvmTarget = "1.8"
}
+11
View File
@@ -1,3 +1,5 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins { plugins {
id("java") id("java")
kotlin("jvm") kotlin("jvm")
@@ -31,6 +33,7 @@ dependencies {
implementation("net.kyori:adventure-api:4.14.0") implementation("net.kyori:adventure-api:4.14.0")
implementation("net.kyori:adventure-platform-bukkit:4.3.0") implementation("net.kyori:adventure-platform-bukkit:4.3.0")
implementation(files(parent!!.files("messages/libs/MiniMessages.jar"))) //using universal minimessages, implementation(files(parent!!.files("messages/libs/MiniMessages.jar"))) //using universal minimessages,
implementation(kotlin("stdlib-jdk8"))
} }
tasks.test { tasks.test {
@@ -121,3 +124,11 @@ signing {
useGpgCmd() useGpgCmd()
sign(publishing.publications.getByName("maven")) sign(publishing.publications.getByName("maven"))
} }
val compileKotlin: KotlinCompile by tasks
compileKotlin.kotlinOptions {
jvmTarget = "1.8"
}
val compileTestKotlin: KotlinCompile by tasks
compileTestKotlin.kotlinOptions {
jvmTarget = "1.8"
}
+11
View File
@@ -1,3 +1,5 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins { plugins {
id("java") id("java")
kotlin("jvm") kotlin("jvm")
@@ -24,6 +26,7 @@ dependencies {
api(project(":architecture")) api(project(":architecture"))
api(project(":extensions")) api(project(":extensions"))
compileOnly("org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.1") compileOnly("org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.1")
implementation(kotlin("stdlib-jdk8"))
} }
tasks.test { tasks.test {
@@ -114,3 +117,11 @@ signing {
useGpgCmd() useGpgCmd()
sign(publishing.publications.getByName("maven")) sign(publishing.publications.getByName("maven"))
} }
val compileKotlin: KotlinCompile by tasks
compileKotlin.kotlinOptions {
jvmTarget = "1.8"
}
val compileTestKotlin: KotlinCompile by tasks
compileTestKotlin.kotlinOptions {
jvmTarget = "1.8"
}
@@ -0,0 +1,5 @@
package tech.carcadex.kotlinbukkitkit
object KBKInfo {
const val KBK_VERSION = "1.0.0.3";
}
+11
View File
@@ -1,3 +1,5 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins { plugins {
id("java") id("java")
kotlin("jvm") kotlin("jvm")
@@ -24,6 +26,7 @@ dependencies {
api(project(":architecture")) api(project(":architecture"))
api(project(":utility")) api(project(":utility"))
compileOnly("org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.1") compileOnly("org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.1")
implementation(kotlin("stdlib-jdk8"))
} }
tasks.test { tasks.test {
@@ -114,3 +117,11 @@ signing {
useGpgCmd() useGpgCmd()
sign(publishing.publications.getByName("maven")) sign(publishing.publications.getByName("maven"))
} }
val compileKotlin: KotlinCompile by tasks
compileKotlin.kotlinOptions {
jvmTarget = "1.8"
}
val compileTestKotlin: KotlinCompile by tasks
compileTestKotlin.kotlinOptions {
jvmTarget = "1.8"
}
+11
View File
@@ -1,3 +1,5 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins { plugins {
id("java") id("java")
kotlin("jvm") kotlin("jvm")
@@ -24,6 +26,7 @@ dependencies {
api(project(":architecture")) api(project(":architecture"))
api(project(":extensions")) api(project(":extensions"))
compileOnly("org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.1") compileOnly("org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.1")
implementation(kotlin("stdlib-jdk8"))
} }
tasks.test { tasks.test {
@@ -114,3 +117,11 @@ signing {
useGpgCmd() useGpgCmd()
sign(publishing.publications.getByName("maven")) sign(publishing.publications.getByName("maven"))
} }
val compileKotlin: KotlinCompile by tasks
compileKotlin.kotlinOptions {
jvmTarget = "1.8"
}
val compileTestKotlin: KotlinCompile by tasks
compileTestKotlin.kotlinOptions {
jvmTarget = "1.8"
}