public void CallCommand(string commandString, ServerPlayer sender) { try { var name = GetCommandName(commandString).Trim(); var args = GetCommandArguments(commandString); var commandParamTypes = new ChatCommandParameter[args.Length]; for (var i = 0; i < args.Length; i++) { if (args[i].GetType() == typeof(string)) { commandParamTypes[i] = ChatCommandParameter.String; } if (args[i].GetType() == typeof(string[])) { commandParamTypes[i] = ChatCommandParameter.ArrayOfString; } if (args[i].GetType() == typeof(bool)) { commandParamTypes[i] = ChatCommandParameter.Boolean; } if (args[i].GetType() == typeof(bool[])) { commandParamTypes[i] = ChatCommandParameter.ArrayOfBoolean; } if (args[i].GetType() == typeof(double)) { commandParamTypes[i] = ChatCommandParameter.Number; } if (args[i].GetType() == typeof(double[])) { commandParamTypes[i] = ChatCommandParameter.ArrayOfNumber; } if (args[i].GetType() == typeof(ServerPlayer)) { commandParamTypes[i] = ChatCommandParameter.Player; } if (args[i].GetType() == typeof(ServerPlayer[])) { commandParamTypes[i] = ChatCommandParameter.ArrayOfPlayer; } } //Get the command object var command = GetCommand(name, commandParamTypes); if (command == null) { SendMessage($"No command exists by that name and accepts those parameters", sender); return; } } catch (Exception ex) { Server.Logger.Error("[CHAT] Command Invokation Error", ex); SendMessage("Something went wrong when processing that command.", sender); } }
public ExtendedChatCommandParameter(ChatCommandParameter param, ParameterInfo info) { Parameter = param; DefaultValue = info.IsOptional ? info.DefaultValue.ToString() : null; Name = info.Name; }