Exemplo n.º 1
0
 public static void GBAdd(BTGlobalBind Bind)
 {
     db.Query("INSERT INTO GlobalBinds (Name, ItemID, Permission, Commands, Awaiting, Looping, Slot, Prefix) " +
              "VALUES (@0, @1, @2, @3, @4, @5, @6, @7);", Bind.Name, Bind.ItemID, Bind.Permission,
              string.Join("~;*;~", Bind.Commands), (Bind.Awaiting ? 1 : 0),
              (Bind.Looping ? 1 : 0), Bind.Slot, Bind.Prefix);
 }
Exemplo n.º 2
0
        public static void ManageGlobalBinds(CommandArgs args)
        {
            bool Add = args.Parameters[0].ToLower() == "add";

            if (Add)
            {
                if (args.Parameters.Count < 9)
                {
                    args.Player.SendErrorMessage(TShock.Config.CommandSpecifier + "bindglobal add [Name] [ItemID] [Permission] [SlotID] [PrefixID] [Looping] [Awaiting] commands; separated; by semicolon\r\n" +
                                                 "SlotID: -1 for any; 1-10 - hotbar; 100 for cursor\r\n" +
                                                 "PrefixID: -1 for any; Looping: true/false; Awaiting: true/false");
                    return;
                }
                string Name = args.Parameters[1];
                if (GlobalBinds.Any(b => b.Name == Name))
                {
                    args.Player.SendErrorMessage("Global bind with '{0}' name already exists.", Name);
                    return;
                }
                if (!int.TryParse(args.Parameters[2], out int ItemID) ||
                    (ItemID < 0) || (ItemID > (Main.maxItemTypes - 1)))
                {
                    args.Player.SendErrorMessage("Invalid ItemID!");
                    return;
                }
                string Permission = args.Parameters[3];
                if (!int.TryParse(args.Parameters[4], out int Slot) ||
                    ((Slot < 1) && (Slot != -1)) || ((Slot > 10) && (Slot != 100)))
                {
                    args.Player.SendErrorMessage("Invalid SlotID!");
                    return;
                }
                if (!int.TryParse(args.Parameters[5], out int Prefix) ||
                    ((Prefix < 0) && (Prefix != -1)) || (Prefix > (Lang.prefix.Length - 1)))
                {
                    args.Player.SendErrorMessage("Invalid PrefixID!");
                    return;
                }
                if (!bool.TryParse(args.Parameters[6], out bool Looping))
                {
                    args.Player.SendErrorMessage("Invalid Looping value!");
                    return;
                }
                if (!bool.TryParse(args.Parameters[7], out bool Awaiting))
                {
                    args.Player.SendErrorMessage("Invalid Awaiting value!");
                    return;
                }

                string   NewMsg   = string.Join(" ", args.Message.Replace("\"", "\\\"").Split(' ').Skip(9));
                string[] Commands = string.Join(" ", ParseParameters(NewMsg)).Split(';');

                for (int i = 0; i < Commands.Length; i++)
                {
                    Commands[i] = Commands[i].TrimStart(' ');
                }

                var GB = new BTGlobalBind(Name, ItemID, Commands, Permission,
                                          ((Slot == 100) ? 58 : (Slot == -1) ? -1 : (Slot - 1)), Prefix, Looping, Awaiting);
                GlobalBinds.Add(GB);
                BTDatabase.GBAdd(GB);
                args.Player.SendSuccessMessage("Successfully added new global bind with given name: {0}.", Name);
            }
            else
            {
                if (args.Parameters.Count != 2)
                {
                    args.Player.SendErrorMessage(TShock.Config.CommandSpecifier + "bindglobal del [Name]");
                    return;
                }
                string Name    = args.Parameters[1];
                bool   Success = false;
                foreach (var b in GlobalBinds)
                {
                    if (b.Name == Name)
                    {
                        Success = true;
                        GlobalBinds.Remove(b);
                        break;
                    }
                }
                if (Success)
                {
                    args.Player.SendSuccessMessage("Successfully deleted global bind with given name: {0}.", Name);
                    BTDatabase.GBDelete(Name);
                }
                else
                {
                    args.Player.SendErrorMessage("Invalid GlobalBind name!");
                }
            }
        }
Exemplo n.º 3
0
 public static void GBUpdate(BTGlobalBind Bind)
 {
     GBDelete(Bind.Name);
     GBAdd(Bind);
 }