Skip to content

Commit

Permalink
feat: add array responses
Browse files Browse the repository at this point in the history
  • Loading branch information
LupusVirtute committed Jan 22, 2023
1 parent b8ae3c1 commit 8364b73
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>org.lupus</groupId>
<artifactId>LCommandFramework</artifactId>
<version>0.7.3</version>
<version>0.7.31</version>

<name>LCommandFramework</name>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
package org.lupus.commands.core.components.command.response

import net.kyori.adventure.text.Component
import net.kyori.adventure.text.ComponentLike
import net.kyori.adventure.text.JoinConfiguration
import net.kyori.adventure.text.minimessage.MiniMessage
import org.lupus.commands.core.components.command.response.arrays.ArrayResponseType
import org.lupus.commands.core.components.command.response.arrays.ComponentLikeResponse
import org.lupus.commands.core.components.command.response.arrays.StringResponse
import org.lupus.commands.core.data.CommandLupi
import org.lupus.commands.core.utils.StringUtil

class ArrayResponseComponent(command: CommandLupi) : CommandResponseComponent(command, Array::class.java) {
val arrayResponseTypes = mutableListOf(ComponentLikeResponse(command), StringResponse(command))

override fun run(input: Any): Component {
input as Array<*>
if (input.first() is String) {
if (!StringUtil.isThatI18nSyntax(input.first() as String)) {
return MiniMessage.miniMessage().deserialize(input.first() as String)
}

return StringUtil.getI18nSyntax(command.pluginRegistering, (input as Array<String>).toList()).getI18nResponse()
}
for (arrayResponseType in arrayResponseTypes) {
if (arrayResponseType.check(input)) {
return arrayResponseType.componentResponse(input)
}
}
return Component.text("")
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.lupus.commands.core.components.command.response.arrays

import net.kyori.adventure.text.Component
import org.lupus.commands.core.data.CommandLupi

interface ArrayResponseType {
val command: CommandLupi
fun check(array: Array<*>): Boolean
fun componentResponse(array: Array<*>): Component
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.lupus.commands.core.components.command.response.arrays

import net.kyori.adventure.text.Component
import net.kyori.adventure.text.ComponentLike
import net.kyori.adventure.text.JoinConfiguration
import net.kyori.adventure.text.minimessage.MiniMessage
import org.lupus.commands.core.data.CommandLupi

class ComponentLikeResponse(override val command: CommandLupi) : ArrayResponseType {
override fun check(array: Array<*>): Boolean {
return array.first() is ComponentLike
}

override fun componentResponse(array: Array<*>): Component {
return Component.join(
JoinConfiguration.separator(
MiniMessage.miniMessage().deserialize("\n")
),
(array as Array<out ComponentLike>).toList()
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.lupus.commands.core.components.command.response.arrays

import net.kyori.adventure.text.Component
import net.kyori.adventure.text.minimessage.MiniMessage
import org.lupus.commands.core.data.CommandLupi
import org.lupus.commands.core.utils.StringUtil

class StringResponse(override val command: CommandLupi) : ArrayResponseType {

override fun check(array: Array<*>): Boolean {
return array.first() is String
}

override fun componentResponse(array: Array<*>): Component {
if (!StringUtil.isThatI18nSyntax(array.first() as String)) {
return MiniMessage.miniMessage().deserialize(array.first() as String)
}

return StringUtil.getI18nSyntax(command.pluginRegistering, (array as Array<String>).toList()).getI18nResponse()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import org.lupus.commands.core.scanner.modifiers.any.*
import org.lupus.commands.core.scanner.modifiers.clazz.ContinuousMod
import org.lupus.commands.core.scanner.modifiers.clazz.HelpMod
import org.lupus.commands.core.scanner.modifiers.fields.DependencyModifier
import org.lupus.commands.core.scanner.modifiers.fields.NamedDependencyModifier
import org.lupus.commands.core.scanner.modifiers.method.CMDPassMod
import org.lupus.commands.core.scanner.modifiers.method.DefaultMod
import org.lupus.commands.core.scanner.modifiers.method.FilterPassMod
Expand All @@ -26,5 +27,5 @@ object DefaultModifiers {
SyntaxMod,
)
val paramModifiers = mutableListOf<ParameterModifier>()
val fieldsModifier = mutableListOf<FieldsModifier>(DependencyModifier)
val fieldsModifier = mutableListOf(DependencyModifier, NamedDependencyModifier)
}

0 comments on commit 8364b73

Please sign in to comment.