示例#1
0
        private void BindPrefixCMD(CommandArgs args)
        {
            string Parameter = (args.Parameters.Count == 0) ? "help" : args.Parameters[0].ToLower();

            switch (Parameter)
            {
            case "add":
            case "del":
            {
                if (!BTExtensions.IsAdmin(args.Player))
                {
                    return;
                }
                string Parameter2 = (args.Parameters.Count == 1) ? "help" : args.Parameters[1].ToLower();
                switch (Parameter2)
                {
                case "g":
                case "group":
                {
                    BTExtensions.ManagePrefixGroups(args);
                    return;
                }

                case "p":
                case "prefix":
                {
                    BTExtensions.ManagePrefixesInPrefixGroups(args);
                    return;
                }

                default:
                {
                    args.Player.SendSuccessMessage("BindPrefix help (1/1):");
                    args.Player.SendInfoMessage("{0}bprefix add group [Name] [Permission] [AllowedPrefixes (1 3 10...)]\r\n" +
                                                "{0}bprefix del group [Name]\r\n" +
                                                "{0}bprefix <add/del> prefix [Name] [PrefixID]", TShock.Config.CommandSpecifier);
                    return;
                }
                }
            }

            case "list":
            {
                var Available = BTExtensions.AvailablePrefixes(args.Player);
                if (Available.Item1)
                {
                    args.Player.SendSuccessMessage("All prefixes available.");
                }
                else if (Available.Item2.Count == 0)
                {
                    args.Player.SendSuccessMessage("No prefixes available.");
                }
                else
                {
                    args.Player.SendSuccessMessage("Available prefixes: {0}.", string.Join(", ", Available.Item2));
                }
                return;
            }

            case "listgr":
            {
                if (!BTExtensions.IsAdmin(args.Player))
                {
                    return;
                }
                args.Player.SendSuccessMessage("Available prefix groups:");
                args.Player.SendInfoMessage(string.Join("\r\n", Prefixes.Select(p =>
                                                                                string.Format("Name: {0}. Permission: {1}. Prefixes: {2}.",
                                                                                              p.Name, p.Permission, string.Join(", ", p.AllowedPrefixes)))));
                return;
            }

            case "help":
            {
                List <string> Help = new List <string>
                {
                    string.Format("{0}bpr [PrefixID]", TShock.Config.CommandSpecifier),
                    string.Format("{0}bpr list [page]", TShock.Config.CommandSpecifier)
                };
                if (args.Player.HasPermission("bindtools.admin"))
                {
                    List <string> Help2 = new List <string>
                    {
                        string.Format("{0}bpr listgr [page]", TShock.Config.CommandSpecifier),
                        string.Format("{0}bpr add <group/g> [Name] [Permission] [AllowedPrefixes (1 3 10...)]", TShock.Config.CommandSpecifier),
                        string.Format("{0}bpr del <group/g> [Name]", TShock.Config.CommandSpecifier),
                        string.Format("{0}bpr <add/del> <prefix/p> [Name] [PrefixID]", TShock.Config.CommandSpecifier)
                    };
                    Help.AddRange(Help2);
                }
                int page = 1;
                if ((args.Parameters.Count > 1) &&
                    (!PaginationTools.TryParsePageNumber(args.Parameters, 1, args.Player, out page)))
                {
                    return;
                }
                PaginationTools.SendPage(args.Player, page, Help,
                                         new PaginationTools.Settings
                    {
                        HeaderFormat = "BindPrefix help ({0}/{1}):",
                        FooterFormat = "Type {0}bpr help {{0}} for more info.".SFormat(TShock.Config.CommandSpecifier)
                    }
                                         );
                return;
            }
            }

            Tuple <bool, List <int> > Allowed = BTExtensions.AvailablePrefixes(args.Player);

            if (((Allowed.Item2 == null) || (Allowed.Item2.Count == 0)) && !Allowed.Item1)
            {
                args.Player.SendErrorMessage("No prefixes allowed.");
                return;
            }
            if (args.Parameters.Count != 1)
            {
                args.Player.SendErrorMessage("/bpr [PrefixID]");
                return;
            }
            if ((args.Player.TPlayer.selectedItem > 9) && (args.Player.TPlayer.selectedItem != 58))
            {
                args.Player.SendMessage("Please select an item from your hotbar or cursor", Color.Red);
                return;
            }
            if (!int.TryParse(args.Parameters[0], out int Prefix) ||
                (Prefix < 0) || (Prefix > (Lang.prefix.Length - 1)))
            {
                args.Player.SendErrorMessage("Invalid PrefixID!");
                return;
            }
            if (((Allowed.Item2 == null) || (!Allowed.Item2.Contains(Prefix))) && !Allowed.Item1)
            {
                args.Player.SendErrorMessage("This prefix is not allowed!");
                return;
            }

            bool SSC = Main.ServerSideCharacter;

            if (!SSC)
            {
                Main.ServerSideCharacter = true;
                NetMessage.SendData((int)PacketTypes.WorldInfo, args.Player.Index, -1, NetworkText.Empty);
            }

            Item Item = args.Player.TPlayer.inventory[args.Player.TPlayer.selectedItem];

            Item.prefix = (byte)Prefix;
            args.Player.TPlayer.inventory[args.Player.TPlayer.selectedItem] = Item;
            NetMessage.SendData((int)PacketTypes.PlayerSlot, -1, -1, NetworkText.FromLiteral(Item.Name), args.Player.Index, args.Player.TPlayer.selectedItem, Prefix);
            NetMessage.SendData((int)PacketTypes.PlayerSlot, args.Player.Index, -1, NetworkText.FromLiteral(Item.Name), args.Player.Index, args.Player.TPlayer.selectedItem, Prefix);

            if (!SSC)
            {
                Main.ServerSideCharacter = false;
                NetMessage.SendData((int)PacketTypes.WorldInfo, args.Player.Index, -1, NetworkText.Empty);
            }

            args.Player.SendSuccessMessage("Successfully changed [i:{0}]'s prefix to {1} ({2})", args.Player.TPlayer.inventory[args.Player.TPlayer.selectedItem].netID, Prefix, Lang.prefix[Prefix].Value);
        }
示例#2
0
        private void BindGlobalCMD(CommandArgs args)
        {
            string Parameter = (args.Parameters.Count == 0) ? "help" : args.Parameters[0].ToLower();

            switch (Parameter)
            {
            case "add":
            case "del":
            {
                if (!BTExtensions.IsAdmin(args.Player))
                {
                    return;
                }
                BTExtensions.ManageGlobalBinds(args);
                break;
            }

            case "list":
            {
                int page = 1;
                if ((args.Parameters.Count > 1) &&
                    (!PaginationTools.TryParsePageNumber(args.Parameters, 1, args.Player, out page)))
                {
                    return;
                }

                var GBinds = (from BTGlobalBind b in GlobalBinds
                              where args.Player.HasPermission(b.Permission)
                              select(string.Format("Item: [i:{0}]. Name: {1}. Commands: {2}. Permission: {3}. Awaiting: {4}. Looping: {5}. Slot: {6}. Prefix: {7}.",
                                                   b.ItemID,
                                                   b.Name,
                                                   string.Join("; ", b.Commands),
                                                   b.Permission,
                                                   b.Awaiting,
                                                   b.Looping,
                                                   ((b.Slot == -1) ? "Any" : (b.Slot == 58) ? "Cursor" : "Hotbar-" + (b.Slot + 1)),
                                                   ((b.Prefix == -1) ? "Any" : (b.Prefix == 0) ? "None" : Lang.prefix[b.Prefix].Value)))).ToList();

                PaginationTools.SendPage(args.Player, page, GBinds,
                                         new PaginationTools.Settings
                    {
                        HeaderFormat           = "Global binds ({0}/{1}):",
                        FooterFormat           = "Type {0}bgl list b {{0}} for more info.".SFormat(TShock.Config.CommandSpecifier),
                        NothingToDisplayString = "There are currently no global binds you allowed to use."
                    }
                                         );
                break;
            }

            case "help":
            {
                List <string> Help = new List <string>
                {
                    string.Format("{0}bgl list [page]", TShock.Config.CommandSpecifier),
                };
                if (args.Player.HasPermission("bindtools.admin"))
                {
                    List <string> Help2 = new List <string>
                    {
                        string.Format("{0}bgl add [Name] [ItemID] [Permission] [SlotID] [PrefixID] [Looping] [Awaiting] commands; separated; by semicolon", TShock.Config.CommandSpecifier),
                        string.Format("{0}bgl del [Name]", TShock.Config.CommandSpecifier),
                        "SlotID: -1 for any; 1-10 - hotbar; 100 for cursor",
                        "PrefixID: -1 for any; Looping: true/false; Awaiting: true/false",
                    };
                    Help.AddRange(Help2);
                }
                int page = 1;
                if ((args.Parameters.Count > 1) &&
                    (!PaginationTools.TryParsePageNumber(args.Parameters, 1, args.Player, out page)))
                {
                    return;
                }
                PaginationTools.SendPage(args.Player, page, Help,
                                         new PaginationTools.Settings
                    {
                        HeaderFormat = "BindGlobal help ({0}/{1}):",
                        FooterFormat = "Type {0}bgl help {{0}} for more info.".SFormat(TShock.Config.CommandSpecifier)
                    }
                                         );
                break;
            }
            }
        }