Small command changes.
This commit is contained in:
parent
1fff1a96c7
commit
a00de9d18a
@ -12,7 +12,7 @@ namespace DiIiS_NA.GameServer.CommandManager
|
|||||||
{
|
{
|
||||||
public class CommandGroup
|
public class CommandGroup
|
||||||
{
|
{
|
||||||
private static readonly Logger Logger = LogManager.CreateLogger("CmdGrp");
|
private static readonly Logger Logger = LogManager.CreateLogger(nameof(CommandGroup));
|
||||||
|
|
||||||
private CommandGroupAttribute Attributes { get; set; }
|
private CommandGroupAttribute Attributes { get; set; }
|
||||||
|
|
||||||
@ -29,7 +29,7 @@ namespace DiIiS_NA.GameServer.CommandManager
|
|||||||
{
|
{
|
||||||
foreach (var method in GetType().GetMethods())
|
foreach (var method in GetType().GetMethods())
|
||||||
{
|
{
|
||||||
object[] attributes = method.GetCustomAttributes(typeof(CommandAttribute), true);
|
var attributes = method.GetCustomAttributes(typeof(CommandAttribute), true);
|
||||||
if (attributes.Length == 0) continue;
|
if (attributes.Length == 0) continue;
|
||||||
|
|
||||||
var attribute = (CommandAttribute)attributes[0];
|
var attribute = (CommandAttribute)attributes[0];
|
||||||
@ -46,7 +46,7 @@ namespace DiIiS_NA.GameServer.CommandManager
|
|||||||
{
|
{
|
||||||
foreach (var method in GetType().GetMethods())
|
foreach (var method in GetType().GetMethods())
|
||||||
{
|
{
|
||||||
object[] attributes = method.GetCustomAttributes(typeof(DefaultCommand), true);
|
var attributes = method.GetCustomAttributes(typeof(DefaultCommand), true);
|
||||||
if (attributes.Length == 0) continue;
|
if (attributes.Length == 0) continue;
|
||||||
if (method.Name.ToLower() == "fallback") continue;
|
if (method.Name.ToLower() == "fallback") continue;
|
||||||
|
|
||||||
@ -111,10 +111,9 @@ namespace DiIiS_NA.GameServer.CommandManager
|
|||||||
|
|
||||||
public string GetHelp(string command)
|
public string GetHelp(string command)
|
||||||
{
|
{
|
||||||
foreach (var pair in _commands.Where(pair => command == pair.Key.Name))
|
var commandData = _commands.FirstOrDefault(pair => command == pair.Key.Name);
|
||||||
{
|
if (commandData.Key?.Help is {} help && !string.IsNullOrWhiteSpace(help))
|
||||||
return pair.Key.Help;
|
return help;
|
||||||
}
|
|
||||||
|
|
||||||
return string.Empty;
|
return string.Empty;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,10 +14,7 @@ namespace DiIiS_NA.GameServer.CommandManager
|
|||||||
private static readonly Logger Logger = LogManager.CreateLogger(nameof(CommandManager));
|
private static readonly Logger Logger = LogManager.CreateLogger(nameof(CommandManager));
|
||||||
private static readonly Dictionary<CommandGroupAttribute, CommandGroup> CommandGroups = new();
|
private static readonly Dictionary<CommandGroupAttribute, CommandGroup> CommandGroups = new();
|
||||||
|
|
||||||
static CommandManager()
|
static CommandManager() => RegisterCommandGroups();
|
||||||
{
|
|
||||||
RegisterCommandGroups();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void RegisterCommandGroups()
|
private static void RegisterCommandGroups()
|
||||||
{
|
{
|
||||||
@ -30,7 +27,8 @@ namespace DiIiS_NA.GameServer.CommandManager
|
|||||||
if (groupAttribute.Name == null) continue;
|
if (groupAttribute.Name == null) continue;
|
||||||
if (groupAttribute.Name.Contains(" "))
|
if (groupAttribute.Name.Contains(" "))
|
||||||
{
|
{
|
||||||
Logger.Warn($"Command group name '{groupAttribute.Name}' contains spaces (which is $[red]$not$[/]$ allowed). Command group will be ignored.");
|
Logger.Warn($"Command group name '{groupAttribute.Name}' contains spaces (which is $[red]$not$[/]$ allowed). $[red]$Command group will be ignored.$[/]$");
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CommandsConfig.Instance.DisabledGroupsData.Contains(groupAttribute.Name))
|
if (CommandsConfig.Instance.DisabledGroupsData.Contains(groupAttribute.Name))
|
||||||
@ -147,10 +145,10 @@ namespace DiIiS_NA.GameServer.CommandManager
|
|||||||
if (line[0] != CommandsConfig.Instance.CommandPrefix) // if line does not start with command-prefix
|
if (line[0] != CommandsConfig.Instance.CommandPrefix) // if line does not start with command-prefix
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
line = line.Substring(1); // advance to actual command.
|
line = line[1..]; // advance to actual command.
|
||||||
command = line.Split(' ')[0].ToLower(); // get command
|
command = line.Split(' ')[0].ToLower(); // get command
|
||||||
parameters = String.Empty;
|
parameters = String.Empty;
|
||||||
if (line.Contains(' ')) parameters = line.Substring(line.IndexOf(' ') + 1).Trim(); // get parameters if any.
|
if (line.Contains(' ')) parameters = line[(line.IndexOf(' ') + 1)..].Trim(); // get parameters if any.
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
user.block.title