mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +00:00
Implement command completion suggestions.
This commit is contained in:
parent
5d2589b10f
commit
84cf749344
115 changed files with 4684 additions and 2695 deletions
|
|
@ -2,8 +2,8 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Brigadier.NET;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using MinecraftClient.Commands;
|
||||
using MinecraftClient.CommandHandler;
|
||||
using MinecraftClient.CommandHandler.Patch;
|
||||
|
||||
namespace MinecraftClient
|
||||
{
|
||||
|
|
@ -25,34 +25,19 @@ namespace MinecraftClient
|
|||
/// </summary>
|
||||
public abstract string CmdDesc { get; }
|
||||
|
||||
public abstract void RegisterCommand(McClient handler, CommandDispatcher<CommandSource> dispatcher);
|
||||
|
||||
/// <summary>
|
||||
/// Get the translated version of command description.
|
||||
/// </summary>
|
||||
/// <returns>Translated command description</returns>
|
||||
public string GetCmdDescTranslated()
|
||||
{
|
||||
string s = (string.IsNullOrEmpty(CmdUsage) || string.IsNullOrEmpty(CmdDesc)) ? "" : ": "; // If either one is empty, no colon :
|
||||
return CmdUsage + s + CmdDesc;
|
||||
}
|
||||
char cmdChar = Settings.Config.Main.Advanced.InternalCmdChar.ToChar();
|
||||
|
||||
public void LogUsage(Logger.ILogger logger)
|
||||
{
|
||||
logger.Info($"{Translations.Get("error.usage")}: {Settings.Config.Main.Advanced.InternalCmdChar.ToChar()}{CmdUsage}");
|
||||
}
|
||||
|
||||
|
||||
public static int LogExecuteResult(Logger.ILogger logger, bool result)
|
||||
{
|
||||
logger.Info(Translations.Get(result ? "general.done" : "general.fail"));
|
||||
return result ? 1 : 0;
|
||||
}
|
||||
|
||||
public static int LogExecuteResult(Logger.ILogger logger, int result)
|
||||
{
|
||||
logger.Info(Translations.Get(result > 0 ? "general.done" : "general.fail"));
|
||||
return result;
|
||||
StringBuilder sb = new();
|
||||
string s = (string.IsNullOrEmpty(CmdUsage) || string.IsNullOrEmpty(CmdDesc)) ? string.Empty : ": "; // If either one is empty, no colon :
|
||||
sb.Append("§e").Append(cmdChar).Append(CmdUsage).Append("§r").Append(s).AppendLine(CmdDesc);
|
||||
sb.Append(McClient.dispatcher.GetAllUsageString(CmdName, false));
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -61,18 +46,9 @@ namespace MinecraftClient
|
|||
public abstract string CmdUsage { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Perform the command
|
||||
/// Register the command.
|
||||
/// </summary>
|
||||
/// <param name="command">The full command, eg: 'mycommand arg1 arg2'</param>
|
||||
/// <param name="localVars">Local variables passed along with the command (may be null)</param>
|
||||
/// <returns>A confirmation/error message, or "" if no message</returns>
|
||||
public abstract string Run(McClient handler, string command, Dictionary<string, object>? localVars);
|
||||
|
||||
/// <summary>
|
||||
/// Return a list of aliases for this command.
|
||||
/// Override this method if you wish to put aliases to the command
|
||||
/// </summary>
|
||||
public virtual IEnumerable<string> GetCMDAliases() { return Array.Empty<string>(); }
|
||||
public abstract void RegisterCommand(McClient handler, CommandDispatcher<CmdResult> dispatcher);
|
||||
|
||||
/// <summary>
|
||||
/// Check if at least one argument has been passed to the command
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue