public void HandlePlayerCommand(string cmd, string[] args, Player sender) { Console.WriteLine(String.Format("Handling String /{0} with arge: {1}", cmd, String.Join(" ", args))); foreach (PluginInfo pi in ServerInstance.Instance.PluginManager.LoadedPlugins) { pi.MainClass.OnCommand(sender, cmd, args); } //TODO check Permissions if (!commandDictionary.ContainsKey(cmd)) { return; } Command c = (Command)Activator.CreateInstance(commandDictionary[cmd], new object[] { ServerInstance.Instance.Server }); if (c == null) { return; } CommandAttribute pluginAttribute = Attribute.GetCustomAttribute(c.GetType(), typeof(CommandAttribute), true) as CommandAttribute; if (pluginAttribute != null) { c.Command_Name = pluginAttribute.CommandName; c.Description = pluginAttribute.Description; c.UsageMessage = pluginAttribute.Usage; c.Permissions = pluginAttribute.Permission; c.PluginName = pluginAttribute.Plugin; c.ReloadPlugin(); } //TODO Send error! //Checking Perms //Todo make sure this is working correctly if (!ServerInstance.Instance.PermissionManager.PlayerHasPerm(sender, c.Permissions)) { //Error! new PluginHelper(Server.Instance).SendMessageToClient(sender, "Error! you do not have permission to access that command!"); return; } c.runCommand(sender, args); }
public void AddCommand(Command cmdclass, PluginBase plugin) { if (cmdclass == null) { return; } //TODO Notify of Override if (!cmdclass.GetType().IsDefined(typeof(CommandAttribute), true)) { Console.WriteLine("Error Loading Command! Missing Correct Syntax! Command : " + cmdclass.GetType().FullName); return; } PermissionAttribute pa = Attribute.GetCustomAttribute(cmdclass.GetType(), typeof(PermissionAttribute), true) as PermissionAttribute; if (pa != null) { ServerInstance.Instance.PermissionManager.AddPermissionAttribute(pa); } CommandAttribute pluginAttribute = Attribute.GetCustomAttribute(cmdclass.GetType(), typeof(CommandAttribute), true) as CommandAttribute; if (pluginAttribute != null) { cmdclass.Command_Name = pluginAttribute.CommandName; cmdclass.Description = pluginAttribute.Description; cmdclass.UsageMessage = pluginAttribute.Usage; cmdclass.Permissions = pluginAttribute.Permission; cmdclass.PluginName = pluginAttribute.Plugin; cmdclass.ReloadPlugin(); } else //MAYBE if (cmdclass.Permissions == null || cmdclass.Command_Name == null || cmdclass.Description == null || cmdclass.UsageMessage == null)//Skip Console Commands! { Console.WriteLine("Error Loading Command! Error with Syntax! Command : " + cmdclass.GetType().FullName); return; } Console.WriteLine("Loaded Command /" + cmdclass.Command_Name); commandDictionary[cmdclass.Command_Name] = cmdclass.GetType(); }