-
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 AltCommand and AltArgumentType
- Loading branch information
Showing
15 changed files
with
131 additions
and
12 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
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
38 changes: 38 additions & 0 deletions
38
progreso-api/src/main/kotlin/org/progreso/api/command/arguments/AltArgumentType.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,38 @@ | ||
package org.progreso.api.command.arguments | ||
|
||
import com.mojang.brigadier.StringReader | ||
import com.mojang.brigadier.arguments.ArgumentType | ||
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.api.alt.AltAccount | ||
import org.progreso.api.managers.AltManager | ||
import java.util.concurrent.CompletableFuture | ||
|
||
class AltArgumentType : ArgumentType<AltAccount> { | ||
companion object { | ||
private val NO_SUCH_ALT = DynamicCommandExceptionType { name: Any -> | ||
Api.TEXT.i18nMessage("argument.alt.error", name) | ||
} | ||
|
||
operator fun get(context: CommandContext<*>): AltAccount { | ||
return context.getArgument("alt", AltAccount::class.java) | ||
} | ||
} | ||
|
||
override fun parse(reader: StringReader): AltAccount { | ||
val argument = reader.readString() | ||
|
||
return AltManager.getAltByNameOrNull(argument) | ||
?: throw NO_SUCH_ALT.create(argument) | ||
} | ||
|
||
override fun <S : Any?> listSuggestions( | ||
context: CommandContext<S>, | ||
builder: SuggestionsBuilder | ||
): CompletableFuture<Suggestions> { | ||
return Api.COMMAND.suggestMatching(AltManager.alts.map { it.username }, builder) | ||
} | ||
} |
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
46 changes: 46 additions & 0 deletions
46
progreso-client/src/main/kotlin/org/progreso/client/commands/AltCommand.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,46 @@ | ||
package org.progreso.client.commands | ||
|
||
import com.mojang.brigadier.arguments.StringArgumentType | ||
import com.mojang.brigadier.arguments.StringArgumentType.string | ||
import com.mojang.brigadier.builder.LiteralArgumentBuilder | ||
import org.progreso.api.alt.AltAccount | ||
import org.progreso.api.command.AbstractCommand | ||
import org.progreso.api.command.arguments.AltArgumentType | ||
import org.progreso.api.managers.AltManager | ||
|
||
@AbstractCommand.Register("alt") | ||
object AltCommand : AbstractCommand() { | ||
override fun build(builder: LiteralArgumentBuilder<Any>) { | ||
builder.then( | ||
literal("add") | ||
.then( | ||
literal("offline").then( | ||
argument("name", string()).executesSuccess { context -> | ||
val name = StringArgumentType.getString(context, "name") | ||
|
||
AltManager.addAlt(AltAccount.Offline(name)) | ||
infoLocalized("command.alt.add", name) | ||
} | ||
) | ||
) | ||
) | ||
|
||
builder.then( | ||
literal("remove").then( | ||
argument("alt", AltArgumentType()).executesSuccess { context -> | ||
val alt = AltArgumentType[context] | ||
|
||
AltManager.removeAlt(alt) | ||
infoLocalized("command.alt.remove", alt.username) | ||
} | ||
) | ||
) | ||
|
||
builder.then(literal("list").executesSuccess { | ||
infoLocalized( | ||
AltManager.alts.ifEmpty("command.alt.list", "command.alt.list_empty"), | ||
AltManager.alts.joinToString() | ||
) | ||
}) | ||
} | ||
} |
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
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