public static void InitCommands(ControllerManager controllers) { if (controllers != null) { SvCommandMethod.UpdateControllers(controllers); } List <MethodInfo> methods = new List <MethodInfo>(); methods.AddRange(typeof(ExtendedCommands).GetMethods(BindingFlags.Static | BindingFlags.Public)); methods.AddRange(typeof(IRSECommands).GetMethods(BindingFlags.Static | BindingFlags.Public)); foreach (MethodInfo method in methods) { object[] customAttributes1 = method.GetCustomAttributes(typeof(SvCommandMethod), false); if (((IEnumerable <object>)customAttributes1).Count <object>() != 0) { object[] customAttributes2 = null; SvCommandMethod svCommandMethod = customAttributes1[0] as SvCommandMethod; EventHandler <List <string> > handler = (EventHandler <List <string> >)Delegate.CreateDelegate(typeof(EventHandler <List <string> >), method); CommandSystem.Singleton.AddCommand(new Command(svCommandMethod.Names, svCommandMethod.Description, svCommandMethod.Arguments, handler, svCommandMethod.RequiredRight, customAttributes2 != null && ((IEnumerable <object>)customAttributes2).Any <object>(), method.GetCustomAttribute <TalkCommandAttribute>() != null), true); } } //CommandSystem.Singleton.SortCommands(); }
public void BuildLayout(Panel panel = null) { MethodInfo[] commandMethods = ServerInstance.Instance.Assembly.GetType("Game.Server.SvCommands").GetMethods(BindingFlags.Public | BindingFlags.Static); foreach (MethodInfo method in commandMethods) { SvCommandMethod commandMethod = method.GetCustomAttribute <SvCommandMethod>(); if (commandMethod != null) { CommandArgument[] arguments = commandMethod.Arguments; if (arguments != null && arguments.Length != 0) { foreach (var argument in arguments) { // Do something } } // remove the c_ from the method name. string name = method.Name.Replace("c_", ""); //Capitalize first letter name = char.ToUpper(name[0]) + name.Substring(1); //put spaces between capital letters name = string.Concat(name.Select(x => char.IsUpper(x) ? " " + x : x.ToString())).TrimStart(' '); string description = commandMethod.Description; //Map.Add(name+" : " + , new List<Type>() { }); } } }
public static void InitPluginCommands(CommandSystem commandSystem, PluginInfo Plugin) { ///Permission.Admin foreach (MethodInfo method in Plugin.MainClassType.GetMethods(BindingFlags.Static | BindingFlags.Public)) { object[] customAttributes1 = method.GetCustomAttributes(typeof(SvCommandMethod), false); if (((IEnumerable <object>)customAttributes1).Count <object>() != 0) { object[] customAttributes2 = null; SvCommandMethod svCommandMethod = customAttributes1[0] as SvCommandMethod; EventHandler <List <string> > handler = (EventHandler <List <string> >)Delegate.CreateDelegate(typeof(EventHandler <List <string> >), method); commandSystem.AddCommand(new Command(svCommandMethod.Names, "P:" + Plugin.Name + ": " + svCommandMethod.Description, svCommandMethod.Arguments, handler, svCommandMethod.RequiredRight, customAttributes2 != null && ((IEnumerable <object>)customAttributes2).Any <object>(), method.GetCustomAttribute <TalkCommandAttribute>() != null), true); } } }