-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b8ae3c1
commit 8364b73
Showing
6 changed files
with
69 additions
and
10 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
21 changes: 13 additions & 8 deletions
21
src/main/java/org/lupus/commands/core/components/command/response/ArrayResponseComponent.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,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("") | ||
} | ||
|
||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...main/java/org/lupus/commands/core/components/command/response/arrays/ArrayResponseType.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 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 | ||
} |
22 changes: 22 additions & 0 deletions
22
.../java/org/lupus/commands/core/components/command/response/arrays/ComponentLikeResponse.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,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() | ||
) | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/org/lupus/commands/core/components/command/response/arrays/StringResponse.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,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() | ||
} | ||
} |
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