public override void HandleAddedToManager(PluginManager manager) { foreach (FieldInfo field in GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Instance)) { object[] attributes = field.GetCustomAttributes(typeof(OnlinePlayersAttribute), true); if (attributes.Length > 0) { PluginFieldInfo pluginField = new PluginFieldInfo(this, field); if (pluginField.GenericArguments.Length != 2 || pluginField.GenericArguments[0] != typeof(Player)) { Puts($"The {field.Name} field is not a Hash with the player key! (online players will not be tracked)"); continue; } if (!pluginField.LookupMethod("Add", pluginField.GenericArguments)) { Puts($"The {field.Name} field does not support adding Player keys! (online players will not be tracked)"); continue; } if (!pluginField.LookupMethod("Remove", typeof(Player))) { Puts($"The {field.Name} field does not support removing Player keys! (online players will not be tracked)"); continue; } if (pluginField.GenericArguments[1].GetField("Player") == null) { Puts($"The {pluginField.GenericArguments[1].Name} class does not have a public Player field! (online players will not be tracked)"); continue; } onlinePlayerFields.Add(pluginField); } } foreach (MethodInfo method in GetType().GetMethods(BindingFlags.NonPublic | BindingFlags.Instance)) { object[] attributes = method.GetCustomAttributes(typeof(ChatCommandAttribute), true); if (attributes.Length <= 0) { continue; } ChatCommandAttribute attribute = attributes[0] as ChatCommandAttribute; cmd.AddChatCommand(attribute?.Command, this, method.Name); } base.HandleAddedToManager(manager); }
public override void HandleAddedToManager(PluginManager manager) { foreach (MethodInfo method in GetType().GetMethods(BindingFlags.NonPublic | BindingFlags.Instance)) { object[] attributes = method.GetCustomAttributes(typeof(ConsoleCommandAttribute), true); if (attributes.Length > 0) { ConsoleCommandAttribute attribute = attributes[0] as ConsoleCommandAttribute; cmd.AddConsoleCommand(attribute?.Command, this, method.Name); continue; } attributes = method.GetCustomAttributes(typeof(ChatCommandAttribute), true); if (attributes.Length > 0) { ChatCommandAttribute attribute = attributes[0] as ChatCommandAttribute; cmd.AddChatCommand(attribute?.Command, this, method.Name); } } base.HandleAddedToManager(manager); }
public override void HandleAddedToManager(PluginManager manager) { foreach (FieldInfo field in GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Instance)) { object[] attributes = field.GetCustomAttributes(typeof(OnlinePlayersAttribute), true); if (attributes.Length > 0) { PluginFieldInfo pluginField = new PluginFieldInfo(this, field); if (pluginField.GenericArguments.Length != 2 || pluginField.GenericArguments[0] != typeof(BasePlayer)) { Puts($"The {field.Name} field is not a Hash with a BasePlayer key! (online players will not be tracked)"); continue; } if (!pluginField.LookupMethod("Add", pluginField.GenericArguments)) { Puts($"The {field.Name} field does not support adding BasePlayer keys! (online players will not be tracked)"); continue; } if (!pluginField.LookupMethod("Remove", typeof(BasePlayer))) { Puts($"The {field.Name} field does not support removing BasePlayer keys! (online players will not be tracked)"); continue; } if (pluginField.GenericArguments[1].GetField("Player") == null) { Puts($"The {pluginField.GenericArguments[1].Name} class does not have a public Player field! (online players will not be tracked)"); continue; } if (!pluginField.HasValidConstructor(typeof(BasePlayer))) { Puts($"The {field.Name} field is using a class which contains no valid constructor (online players will not be tracked)"); continue; } onlinePlayerFields.Add(pluginField); } } foreach (MethodInfo method in GetType().GetMethods(BindingFlags.NonPublic | BindingFlags.Instance)) { object[] attributes = method.GetCustomAttributes(typeof(ConsoleCommandAttribute), true); if (attributes.Length > 0) { ConsoleCommandAttribute attribute = attributes[0] as ConsoleCommandAttribute; if (attribute != null) { cmd.AddConsoleCommand(attribute.Command, this, method.Name); } continue; } attributes = method.GetCustomAttributes(typeof(ChatCommandAttribute), true); if (attributes.Length > 0) { ChatCommandAttribute attribute = attributes[0] as ChatCommandAttribute; if (attribute != null) { cmd.AddChatCommand(attribute.Command, this, method.Name); } } } if (onlinePlayerFields.Count > 0) { foreach (BasePlayer player in BasePlayer.activePlayerList) { AddOnlinePlayer(player); } } base.HandleAddedToManager(manager); }
public override void HandleAddedToManager(PluginManager manager) { int i; FieldInfo[] fields = base.GetType().GetFields(BindingFlags.Instance | BindingFlags.NonPublic); for (i = 0; i < (int)fields.Length; i++) { FieldInfo fieldInfo = fields[i]; if (fieldInfo.GetCustomAttributes(typeof(OnlinePlayersAttribute), true).Length != 0) { CSharpPlugin.PluginFieldInfo pluginFieldInfo = new CSharpPlugin.PluginFieldInfo(this, fieldInfo); if ((int)pluginFieldInfo.GenericArguments.Length != 2 || pluginFieldInfo.GenericArguments[0] != typeof(BasePlayer)) { base.Puts(String.Concat("The ", fieldInfo.Name, " field is not a Hash with a BasePlayer key! (online players will not be tracked)"), Array.Empty <object>()); } else if (!pluginFieldInfo.LookupMethod("Add", pluginFieldInfo.GenericArguments)) { base.Puts(String.Concat("The ", fieldInfo.Name, " field does not support adding BasePlayer keys! (online players will not be tracked)"), Array.Empty <object>()); } else if (!pluginFieldInfo.LookupMethod("Remove", new Type[] { typeof(BasePlayer) })) { base.Puts(String.Concat("The ", fieldInfo.Name, " field does not support removing BasePlayer keys! (online players will not be tracked)"), Array.Empty <object>()); } else if (pluginFieldInfo.GenericArguments[1].GetField("Player") == null) { base.Puts(String.Concat("The ", pluginFieldInfo.GenericArguments[1].Name, " class does not have a public Player field! (online players will not be tracked)"), Array.Empty <object>()); } else if (pluginFieldInfo.HasValidConstructor(new Type[] { typeof(BasePlayer) })) { this.onlinePlayerFields.Add(pluginFieldInfo); } else { base.Puts(String.Concat("The ", fieldInfo.Name, " field is using a class which contains no valid constructor (online players will not be tracked)"), Array.Empty <object>()); } } } MethodInfo[] methods = base.GetType().GetMethods(BindingFlags.Instance | BindingFlags.NonPublic); for (i = 0; i < (int)methods.Length; i++) { MethodInfo methodInfo = methods[i]; object[] customAttributes = methodInfo.GetCustomAttributes(typeof(ConsoleCommandAttribute), true); if (customAttributes.Length == 0) { customAttributes = methodInfo.GetCustomAttributes(typeof(ChatCommandAttribute), true); if (customAttributes.Length != 0) { ChatCommandAttribute chatCommandAttribute = customAttributes[0] as ChatCommandAttribute; if (chatCommandAttribute != null) { this.cmd.AddChatCommand(chatCommandAttribute.Command, this, methodInfo.Name); } } } else { ConsoleCommandAttribute consoleCommandAttribute = customAttributes[0] as ConsoleCommandAttribute; if (consoleCommandAttribute != null) { this.cmd.AddConsoleCommand(consoleCommandAttribute.Command, this, methodInfo.Name); } } } if (this.onlinePlayerFields.Count > 0) { foreach (BasePlayer basePlayer in BasePlayer.activePlayerList) { this.AddOnlinePlayer(basePlayer); } } base.HandleAddedToManager(manager); }