-
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.
Added FontArgumentType, fixed
add
output of FriendCommand
- Loading branch information
Showing
7 changed files
with
62 additions
and
13 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
45 changes: 45 additions & 0 deletions
45
progreso-client/src/main/kotlin/org/progreso/client/commands/arguments/FontArgumentType.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,45 @@ | ||
package org.progreso.client.commands.arguments | ||
|
||
import com.mojang.brigadier.StringReader | ||
import com.mojang.brigadier.arguments.ArgumentType | ||
import com.mojang.brigadier.arguments.StringArgumentType | ||
import com.mojang.brigadier.context.CommandContext | ||
import com.mojang.brigadier.exceptions.DynamicCommandExceptionType | ||
import com.mojang.brigadier.suggestion.Suggestions | ||
import com.mojang.brigadier.suggestion.SuggestionsBuilder | ||
import org.progreso.api.Api | ||
import org.progreso.client.accessors.TextAccessor | ||
import org.progreso.client.managers.minecraft.ProgresoResourceManager | ||
import java.util.concurrent.CompletableFuture | ||
|
||
class FontArgumentType : ArgumentType<String> { | ||
companion object { | ||
private val NO_SUCH_FONT = DynamicCommandExceptionType { name: Any -> | ||
TextAccessor.i18nMessage("argument.font.error", name) | ||
} | ||
|
||
private val EXAMPLES: Collection<String> = listOf("arial", "roboto") | ||
|
||
operator fun get(context: CommandContext<*>): String { | ||
return StringArgumentType.getString(context, "font") | ||
} | ||
} | ||
|
||
override fun parse(reader: StringReader): String { | ||
val argument: String = reader.readString() | ||
|
||
return ProgresoResourceManager.fonts.firstOrNull { it == argument } | ||
?: throw NO_SUCH_FONT.create(argument) | ||
} | ||
|
||
override fun <S> listSuggestions( | ||
context: CommandContext<S>, | ||
builder: SuggestionsBuilder | ||
): CompletableFuture<Suggestions> { | ||
return Api.COMMAND.suggestMatching(ProgresoResourceManager.fonts, builder) | ||
} | ||
|
||
override fun getExamples(): Collection<String> { | ||
return EXAMPLES | ||
} | ||
} |
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
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