public void Register(PublicCommand cmd, PulsarPlugin plugin)
        {
            foreach (string alias in cmd.CommandAliases())
            {
                string lowerAlias = alias.ToLower();

                if (conflictingPublicAliases.TryGetValue(lowerAlias, out PulsarPlugin plugin2))
                {
                    string name  = plugin != null ? plugin.Name : "Pulsar Plugin Loader";
                    string name2 = plugin2 != null ? plugin2.Name : "Pulsar Plugin Loader";
                    Logger.Info($"Conflicting public alias: {lowerAlias} from {name} and {name2}");
                }
                else
                {
                    if (publicCommands.TryGetValue(lowerAlias, out Tuple <PublicCommand, PulsarPlugin> t))
                    {
                        conflictingPublicAliases.Add(lowerAlias, plugin);
                        publicCommands.Remove(lowerAlias);
                        string name  = plugin != null ? plugin.Name : "Pulsar Plugin Loader";
                        string name2 = t.Item2 != null ? t.Item2.Name : "Pulsar Plugin Loader";
                        Logger.Info($"Conflicting public alias: {lowerAlias} from {name} and {name2}");
                    }
                    else
                    {
                        publicCommands.Add(lowerAlias, new Tuple <PublicCommand, PulsarPlugin>(cmd, plugin));
                    }
                }
            }
        }
Esempio n. 2
0
        //Called for every plugin loaded
        public static void RegisterEventHandlers(string name, PulsarPlugin plugin)
        {
            Assembly asm = plugin.GetType().Assembly;

            foreach (Type classType in asm.GetTypes())
            {
                foreach (MethodInfo method in classType.GetMethods())
                {
                    ParameterInfo[] param = method.GetParameters();
                    if (method.GetCustomAttributes(typeof(EventHandler), false).Any() && method.ReturnType == typeof(void) &&
                        param.Count() == 1 && (param[0].ParameterType.IsSubclassOf(typeof(Event)) || param[0].ParameterType == typeof(Event)))
                    {
                        if (EventHandlers.TryGetValue(param[0].ParameterType, out List <MethodInfo> methods))
                        {
                            methods.Add(method);
                        }
                        else
                        {
                            methods = new List <MethodInfo> {
                                method
                            };
                            EventHandlers.Add(param[0].ParameterType, methods);
                        }
                    }
                }
            }
        }
        private void LoadCommandsFromAssembly(Assembly asm, PulsarPlugin plugin)
        {
            Type ChatCmd   = typeof(ChatCommand);
            Type PublicCmd = typeof(PublicCommand);

            foreach (Type t in asm.GetTypes())
            {
                if (ChatCmd.IsAssignableFrom(t) && !t.IsAbstract && !t.IsInterface)
                {
                    Register((ChatCommand)Activator.CreateInstance(t), plugin);
                }
                else if (PublicCmd.IsAssignableFrom(t) && !t.IsAbstract && !t.IsInterface)
                {
                    Register((PublicCommand)Activator.CreateInstance(t), plugin);
                }
            }
        }
        public void OnPluginLoaded(string name, PulsarPlugin plugin)
        {
            Assembly asm = plugin.GetType().Assembly;

            LoadCommandsFromAssembly(asm, plugin);
        }
        public override void Execute(string arguments)
        {
            PhotonPlayer player = PLNetworkManager.Instance.LocalPlayer.GetPhotonPlayer();
            int          page   = 1;

            if (!string.IsNullOrWhiteSpace(arguments))
            {
                if (!int.TryParse(arguments, out page))
                {
                    PulsarPlugin plugin = PluginManager.Instance.GetPlugin(arguments);
                    if (plugin == null)
                    {
                        foreach (PulsarPlugin p in PluginManager.Instance.GetAllPlugins())
                        {
                            if (p.HarmonyIdentifier().ToLower() == arguments.ToLower())
                            {
                                plugin = p;
                                break;
                            }
                        }
                    }
                    if (plugin != null)
                    {
                        Messaging.Echo(player, $"[&%~[C4 {plugin.Name} ]&%~] - {plugin.ShortDescription}");
                        Messaging.Echo(player, $"Version: {plugin.Version}");
                        if (!string.IsNullOrWhiteSpace(plugin.LongDescription))
                        {
                            Messaging.Echo(player, plugin.LongDescription);
                        }
                    }
                    else
                    {
                        Messaging.Echo(player, $"Plugin {arguments} not found");
                    }
                    return;
                }
            }

            int pluginsPerPage = (PLXMLOptionsIO.Instance.CurrentOptions.GetStringValueAsInt("ChatNumLines") * 5 + 10) - 2;
            IOrderedEnumerable <PulsarPlugin> plugins = PluginManager.Instance.GetAllPlugins().OrderBy(t => t.Name);
            int pages = Mathf.CeilToInt(plugins.Count() / (float)pluginsPerPage);

            page--; //Pages start from 1
            if (page < 0)
            {
                page = 0;
            }

            Messaging.Echo(player, pages == 1 && page == 0 ? "[&%~[C4 Plugin List: ]&%~] :" : $"[&%~[C4 Plugin List: ]&%~] Page {page + 1} : {pages}");
            for (int i = 0; i < pluginsPerPage; i++)
            {
                int index = i + page * pluginsPerPage;
                if (i + page * pluginsPerPage >= plugins.Count())
                {
                    break;
                }
                PulsarPlugin plugin = plugins.ElementAt(index);
                Messaging.Echo(player, $"{plugin.Name} - {plugin.ShortDescription}");
            }
            Messaging.Echo(player, "Use [&%~[C2 /plugin <plugin> ]&%~] for details about a specific plugin");
        }