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));
                    }
                }
            }
        }
示例#2
0
        public void ExecutePublicCommand()
        {
            ICommand command = new PublicCommand(new string[] { "foo" });

            ValueEnvironment parent   = new ValueEnvironment(ValueEnvironmentType.Public);
            ValueEnvironment localenv = new ValueEnvironment(parent, ValueEnvironmentType.Local);
            ValueEnvironment childenv = new ValueEnvironment(localenv);

            command.Execute(null, childenv);

            Assert.IsFalse(childenv.ContainsValue("foo"));
            Assert.IsTrue(parent.ContainsValue("foo"));
            Assert.IsFalse(localenv.ContainsValue("foo"));
        }
示例#3
0
        public void ParsePublicVariables()
        {
            Parser parser = new Parser("public foo, bar");

            ICommand command = parser.ParseCommand();

            Assert.IsNotNull(command);
            Assert.IsInstanceOfType(command, typeof(PublicCommand));

            PublicCommand pubcmd = (PublicCommand)command;

            Assert.AreEqual(2, pubcmd.Names.Count);
            Assert.AreEqual("foo", pubcmd.Names.First());
            Assert.AreEqual("bar", pubcmd.Names.Skip(1).First());
        }
示例#4
0
        public override void Execute(string arguments, int SenderID)
        {
            if (PLNetworkManager.Instance.LocalPlayer.GetPhotonPlayer().IsMasterClient)
            {
                IOrderedEnumerable <Tuple <PublicCommand, PulsarPlugin> > publicCommands = ChatCommandRouter.Instance.GetPublicCommands();

                if (publicCommands.Count() <= 1)
                {
                    return;
                }

                PLPlayer sender = PLServer.Instance.GetPlayerFromPlayerID(SenderID);
                int      page   = 1;
                if (!string.IsNullOrWhiteSpace(arguments))
                {
                    if (!int.TryParse(arguments, out page))
                    {
                        if (arguments[0] == '!')
                        {
                            arguments = arguments.Substring(1);
                        }
                        Tuple <PublicCommand, PulsarPlugin> t = ChatCommandRouter.Instance.GetPublicCommand(arguments);
                        if (t != null)
                        {
                            PublicCommand cmd  = t.Item1;
                            string        name = t.Item2 != null ? t.Item2.Name : "Pulsar Plugin Loader";

                            Messaging.Echo(sender, $"[&%~[C3 !{cmd.CommandAliases()[0]} ]&%~] - {cmd.Description()} <color=#ff6600ff>[{name}]</color>");
                            Messaging.Echo(sender, $"Aliases: !{string.Join($", !", cmd.CommandAliases())}");
                            Messaging.Echo(sender, $"Usage: {cmd.UsageExamples()[0]}");
                            for (int i = 1; i < cmd.UsageExamples().Length; i++)
                            {
                                Messaging.Echo(sender, $"       {cmd.UsageExamples()[i]}");
                            }
                        }
                        else
                        {
                            Messaging.Echo(sender, $"Command !{arguments} not found");
                        }
                        return;
                    }
                }

                int commandsPerPage = 13 /*(PLXMLOptionsIO.Instance.CurrentOptions.GetStringValueAsInt("ChatNumLines") * 5 + 10) - 2*/; //Minimum value
                int pages           = Mathf.CeilToInt(publicCommands.Count() / (float)commandsPerPage);

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

                string header = pages == 1 && page == 0 ? $"[&%~[C3 Available Commands: ]&%~]" : $"[&%~[C3 Available Commands: ]&%~] Page {page + 1} : {pages}";
                Messaging.Echo(sender, header);
                for (int i = 0; i < commandsPerPage; i++)
                {
                    int index = i + page * commandsPerPage;
                    if (i + page * commandsPerPage >= publicCommands.Count())
                    {
                        break;
                    }
                    PublicCommand command = publicCommands.ElementAt(index).Item1;
                    Messaging.Echo(sender, $"!{command.CommandAliases()[0]} - {command.Description()}");
                }
                Messaging.Echo(sender, "Use [&%~[C2 !help <command> ]&%~] for details about a specific command");
            }
        }