-
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.
- Loading branch information
Showing
10 changed files
with
131 additions
and
44 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
44 changes: 44 additions & 0 deletions
44
...tlin/com/projectcitybuild/pcbridge/paper/core/support/brigadier/arguments/EnumArgument.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,44 @@ | ||
package com.projectcitybuild.pcbridge.paper.core.support.brigadier.arguments | ||
|
||
import com.mojang.brigadier.arguments.ArgumentType | ||
import com.mojang.brigadier.arguments.StringArgumentType | ||
import com.mojang.brigadier.context.CommandContext | ||
import com.mojang.brigadier.exceptions.CommandSyntaxException | ||
import com.mojang.brigadier.exceptions.SimpleCommandExceptionType | ||
import com.mojang.brigadier.suggestion.Suggestions | ||
import com.mojang.brigadier.suggestion.SuggestionsBuilder | ||
import io.papermc.paper.command.brigadier.MessageComponentSerializer | ||
import io.papermc.paper.command.brigadier.argument.CustomArgumentType | ||
import net.kyori.adventure.text.Component | ||
import net.kyori.adventure.text.format.NamedTextColor | ||
import java.util.concurrent.CompletableFuture | ||
|
||
class EnumArgument<T : Enum<T>>( | ||
private val enumClass: Class<T>, | ||
) : CustomArgumentType.Converted<T, String> { | ||
override fun convert(nativeType: String): T { | ||
return try { | ||
enumClass.enumConstants?.firstOrNull { it.name.equals(nativeType, ignoreCase = true) } | ||
?: throw IllegalArgumentException("Invalid value: $nativeType") | ||
} catch (e: IllegalArgumentException) { | ||
val message = MessageComponentSerializer.message() | ||
.serialize(Component.text("Invalid value: $nativeType", NamedTextColor.RED)) | ||
|
||
throw CommandSyntaxException(SimpleCommandExceptionType(message), message) | ||
} | ||
} | ||
|
||
override fun getNativeType(): ArgumentType<String> { | ||
return StringArgumentType.word() | ||
} | ||
|
||
override fun <S : Any> listSuggestions( | ||
context: CommandContext<S>, | ||
builder: SuggestionsBuilder, | ||
): CompletableFuture<Suggestions> { | ||
enumClass.enumConstants?.forEach { value -> | ||
builder.suggest(value.name) | ||
} | ||
return builder.buildFuture() | ||
} | ||
} |
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
21 changes: 21 additions & 0 deletions
21
.../kotlin/com/projectcitybuild/pcbridge/paper/core/support/component/ComponentExtensions.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 com.projectcitybuild.pcbridge.paper.core.support.component | ||
|
||
import net.kyori.adventure.text.Component | ||
import net.kyori.adventure.text.TextComponent | ||
|
||
/** | ||
* Joins a collection of components together with the given [separator] | ||
* inserted in between each collection element | ||
*/ | ||
fun List<TextComponent.Builder>.join(separator: Component): TextComponent.Builder { | ||
val component = Component.text() | ||
withIndex().forEach { entry -> | ||
component.append(entry.value) | ||
|
||
val isLast = entry.index == size - 1 | ||
if (!isLast) { | ||
component.append(separator) | ||
} | ||
} | ||
return component | ||
} |
2 changes: 1 addition & 1 deletion
2
...e/paper/core/extensions/EnumExtensions.kt → ...cbridge/paper/core/support/kotlin/Enum.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
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
7 changes: 7 additions & 0 deletions
7
...ain/kotlin/com/projectcitybuild/pcbridge/paper/features/builds/data/EditableBuildField.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,7 @@ | ||
package com.projectcitybuild.pcbridge.paper.features.builds.data | ||
|
||
enum class EditableBuildField { | ||
NAME, | ||
DESCRIPTION, | ||
LORE, | ||
} |
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