Skip to content

Commit

Permalink
Added FontArgumentType, fixed add output of FriendCommand
Browse files Browse the repository at this point in the history
  • Loading branch information
ya-ilya committed Sep 14, 2023
1 parent 6636372 commit 0105703
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package org.progreso.client.commands

import com.mojang.brigadier.arguments.FloatArgumentType
import com.mojang.brigadier.arguments.StringArgumentType
import com.mojang.brigadier.builder.LiteralArgumentBuilder
import org.progreso.api.command.AbstractCommand
import org.progreso.client.Client
import org.progreso.client.Client.Companion.config
import org.progreso.client.commands.arguments.FontArgumentType
import org.progreso.client.gui.createDefaultTextRenderer
import org.progreso.client.gui.customTextRenderer
import org.progreso.client.managers.minecraft.ProgresoResourceManager
Expand All @@ -17,17 +17,17 @@ object FontCommand : AbstractCommand() {
override fun build(builder: LiteralArgumentBuilder<Any>) {
builder.then(
literal("load").then(
argument("font", StringArgumentType.string())
argument("font", FontArgumentType())
.then(
argument("size", FloatArgumentType.floatArg()).executesSuccess { context ->
loadFont(
StringArgumentType.getString(context, "font"),
FontArgumentType[context],
FloatArgumentType.getFloat(context, "size")
)
}
)
.executesSuccess { context ->
loadFont(StringArgumentType.getString(context, "font"))
loadFont(FontArgumentType[context])
}
)
)
Expand Down Expand Up @@ -74,7 +74,7 @@ object FontCommand : AbstractCommand() {
)
} catch (ex: ProgresoResourceManagerException) {
errorLocalized(
"command.font.not_found_error",
"argument.font.error",
fontName
)
} catch (ex: Exception) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ object FriendCommand : AbstractCommand() {
if (FriendManager.isFriend(player.profile.name)) {
errorLocalized(
"command.friend.add_error",
player
player.profile.name
)
} else {
FriendManager.addFriendByName(player.profile.name)
infoLocalized(
"command.friend.add",
player
player.profile.name
)
}
}
Expand Down
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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import com.mojang.brigadier.exceptions.DynamicCommandExceptionType
import com.mojang.brigadier.suggestion.Suggestions
import com.mojang.brigadier.suggestion.SuggestionsBuilder
import net.minecraft.client.network.PlayerListEntry
import net.minecraft.command.CommandSource
import org.progreso.api.Api
import org.progreso.client.Client.Companion.mc
import org.progreso.client.accessors.TextAccessor
import java.util.concurrent.CompletableFuture

class PlayerArgumentType : ArgumentType<PlayerListEntry?> {
class PlayerArgumentType : ArgumentType<PlayerListEntry> {
companion object {
private val NO_SUCH_PLAYER = DynamicCommandExceptionType { name: Any ->
TextAccessor.i18nMessage("argument.player.error", name)
Expand Down Expand Up @@ -45,7 +45,7 @@ class PlayerArgumentType : ArgumentType<PlayerListEntry?> {
context: CommandContext<S>,
builder: SuggestionsBuilder
): CompletableFuture<Suggestions> {
return CommandSource.suggestMatching(mc.networkHandler.playerList.map { it.profile.name }, builder)
return Api.COMMAND.suggestMatching(mc.networkHandler.playerList.map { it.profile.name }, builder)
}

override fun getExamples(): Collection<String> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ object ESP : AbstractModule() {

private val renderMap = mutableMapOf<Entity, Color>()

fun SettingContainer.espSetting(name: String, render: Boolean, color: Color): ReadWriteProperty<Any?, Pair<Boolean, Color>> {
fun SettingContainer.espSetting(
name: String,
render: Boolean,
color: Color
): ReadWriteProperty<Any?, Pair<Boolean, Color>> {
return object : ReadWriteProperty<Any?, Pair<Boolean, Color>> {
private val groupSetting = setting(name)
private var renderSetting by groupSetting.setting("Render", render)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"argument.font.error": "Font '%s' not found",
"argument.friend.error": "Friend '%s' not found",
"argument.module.error": "Module '%s' not found",
"argument.player.error": "Player '%s' not found",
Expand All @@ -24,7 +25,6 @@
"command.config.current": "Current %s config: %s",

"command.font.load": "Loaded %s font",
"command.font.not_found_error": "Font %s not found in fonts folder",
"command.font.unknown_error": "Unknown error has occurred when loading %s font",
"command.font.reset": "Font reset to default font",
"command.font.list": "Fonts: %s",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"argument.font.error": "Шрифт '%s' не найден",
"argument.friend.error": "У вас нету друга с именем %s",
"argument.module.error": "Модуль '%s' не найден",
"argument.player.error": "Игрок '%s' не найден",
Expand All @@ -24,7 +25,6 @@
"command.config.current": "Текущий '%s' конфиг: %s",

"command.font.load": "Шрифт '%s' загружен",
"command.font.not_found_error": "Шрифт '%s' не найден в папке шрифтов",
"command.font.unknown_error": "Произошла неизвестная ошибка при загрузке шрифта '%s'",
"command.font.reset": "Шрифт сброшен до шрифта по умолчанию",
"command.font.list": "Шрифты: %s",
Expand Down

0 comments on commit 0105703

Please sign in to comment.