public void AddBindTool(BindTool NewBT, bool Database) { List <BindTool> Removed = new List <BindTool>(); foreach (BindTool PT in bindTools) { if ((PT.item == NewBT.item) && ((PT.slot == NewBT.slot) || ((PT.slot != -1) && (NewBT.slot == -1)) || ((PT.slot == -1) && (NewBT.slot != -1))) && ((PT.prefix == NewBT.prefix) || ((PT.prefix != -1) && (NewBT.prefix == -1)) || ((PT.prefix == -1) && (NewBT.prefix != -1)))) { Removed.Add(PT); if (Database && tsPlayer.IsLoggedIn) { BTDatabase.BTDelete(tsPlayer.Account.ID, PT.item, PT.slot, PT.prefix); } } } bindTools = (from BindTool b in bindTools where !Removed.Contains(b) select b).ToList(); bindTools.Add(NewBT); if (Database && tsPlayer.IsLoggedIn) { BTDatabase.BTAdd(tsPlayer.Account.ID, NewBT); } }
public override void Initialize() { ServerApi.Hooks.NetGreetPlayer.Register(this, OnGreet); ServerApi.Hooks.ServerLeave.Register(this, OnLeave); PlayerHooks.PlayerPostLogin += OnLogin; GetDataHandlers.PlayerUpdate += OnPlayerUpdate; GeneralHooks.ReloadEvent += OnReload; Commands.ChatCommands.Add(new Command(BTPermissions.BTool, BindToolCMD, "bindtool", "bt") { AllowServer = false, HelpText = string.Format("Use '{0}bt help'.", TShock.Config.CommandSpecifier) }); Commands.ChatCommands.Add(new Command(BTPermissions.BWait, BindWaitCMD, "bindwait", "bw") { AllowServer = false, HelpText = string.Format("Use '{0}bw help'.", TShock.Config.CommandSpecifier) }); Commands.ChatCommands.Add(new Command(BTPermissions.BGlobal, BindGlobalCMD, "bindglobal", "bgl") { HelpText = string.Format("Use '{0}bgl help'.", TShock.Config.CommandSpecifier) }); Commands.ChatCommands.Add(new Command(BTPermissions.BPrefix, BindPrefixCMD, "bprefix", "bindprefix", "bpr") { AllowServer = false, HelpText = string.Format("Use '{0}bgl help'.", TShock.Config.CommandSpecifier) }); BTDatabase.DBConnect(); }
public BTPlayer(int Index) { tsPlayer = TShock.Players[Index]; bindTools = (tsPlayer.User == null) ? new List <BindTool>() : BTDatabase.BTGet(tsPlayer.User.ID); awaitingCommands = new List <string>(); }
public BTPlayer(int Index) { TSPlayer = TShock.Players[Index]; BindTools = (TSPlayer.IsLoggedIn) ? BTDatabase.BTGet(TSPlayer.User.ID) : new List <BindTool>(); AwaitingCommands = new List <string>(); }
public BTPlayer(int Index) { tsPlayer = TShock.Players[Index]; // f*****g shit but i don't care how user or tsplayer becomes null bindTools = (tsPlayer?.Account is UserAccount user) ? BTDatabase.BTGet(user.ID) : new List <BindTool>(); awaitingCommands = new List <string>(); }
public void RemoveBindTool(int item, int slot, int prefix) { if ((slot == -1) && (prefix == -1)) { if (tsPlayer.IsLoggedIn) { BTDatabase.BTDelete(tsPlayer.Account.ID, item); } bindTools = (from BindTool b in bindTools where (b.item != item) select b).ToList(); } else if (slot == -1) { if (tsPlayer.IsLoggedIn) { BTDatabase.BTDelete(tsPlayer.Account.ID, item, slot); } bindTools = (from BindTool b in bindTools where !((b.item == item) && (b.prefix == prefix)) select b).ToList(); } else if (prefix == -1) { if (tsPlayer.IsLoggedIn) { BTDatabase.BTDelete(tsPlayer.Account.ID, item, prefix, false); } bindTools = (from BindTool b in bindTools where !((b.item == item) && (b.prefix == prefix)) select b).ToList(); } else { if (tsPlayer.IsLoggedIn) { BTDatabase.BTDelete(tsPlayer.Account.ID, item, slot, prefix); } bindTools = (from BindTool b in bindTools where !((b.item == item) && (b.slot == slot) && (b.prefix == prefix)) select b).ToList(); } }
public static void ManagePrefixesInPrefixGroups(CommandArgs args) { bool Add = (args.Parameters[0] == "add"); if (args.Parameters.Count < 3) { args.Player.SendErrorMessage("{0}bprefix " + (Add ? "add" : "del") + " prefix [PrefixGroupName] [PrefixID]", TShock.Config.CommandSpecifier); return; } int Index = -1; string Name = args.Parameters[2]; for (int i = 0; i < Prefixes.Count; i++) { if (Prefixes[i].Name == Name) { Index = i; break; } } if (Index == -1) { args.Player.SendErrorMessage("Invalid PrefixGroup name!"); return; } if (!int.TryParse(args.Parameters[3], out int Prefix) || (Prefix < 0) || (Prefix > (Lang.prefix.Length - 1))) { args.Player.SendErrorMessage("Invalid PrefixID!"); return; } if (Add) { Prefixes[Index].AllowedPrefixes.Add(Prefix); } else { Prefixes[Index].AllowedPrefixes.Remove(Prefix); } BTDatabase.PUpdate(Prefixes[Index]); args.Player.SendSuccessMessage("Successfully {0} prefix", (Add ? "added new" : "deleted")); }
public override void Initialize() { ServerApi.Hooks.NetGreetPlayer.Register(this, OnGreet); ServerApi.Hooks.ServerLeave.Register(this, OnLeave); PlayerHooks.PlayerPostLogin += OnLogin; GetDataHandlers.PlayerUpdate += OnPlayerUpdate; Commands.ChatCommands.Add(new Command("bindtool", BindToolCMD, "bindtool", "bt") { AllowServer = false, HelpText = string.Format("Use '{0}bindtool help'.", TShock.Config.CommandSpecifier) }); Commands.ChatCommands.Add(new Command("bindwait", BindWaitCMD, "bindwait", "bw") { AllowServer = false, HelpText = string.Format("Use '{0}bindwait help'.", TShock.Config.CommandSpecifier) }); BTDatabase.DBConnect(); }
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!"); } } }
public static void ManagePrefixGroups(CommandArgs args) { bool Add = args.Parameters[0].ToLower() == "add"; if (Add) { if (args.Parameters.Count < 5) { args.Player.SendErrorMessage(TShock.Config.CommandSpecifier + "bprefix add group [Name] [Permission] [AllowedPrefixes (1 3 10...)]"); return; } string Name = args.Parameters[2]; if (Prefixes.Any(b => b.Name == Name)) { args.Player.SendErrorMessage("Prefix group with '{0}' name already exists.", Name); return; } string Permission = args.Parameters[3]; List <int> AllowedPrefixes = new List <int>(); for (int i = 4; i < args.Parameters.Count; i++) { if (!int.TryParse(args.Parameters[i], out int PrefixID) || (PrefixID < 0) || (PrefixID > (Lang.prefix.Length - 1))) { args.Player.SendErrorMessage("Invalid PrefixID '{0}'!", args.Parameters[i]); continue; } AllowedPrefixes.Add(PrefixID); } var BTP = new BTPrefix(Name, Permission, AllowedPrefixes); Prefixes.Add(BTP); BTDatabase.PAdd(BTP); args.Player.SendSuccessMessage("Successfully added new prefix group with given name: {0}.", Name); } else { if (args.Parameters.Count != 3) { args.Player.SendErrorMessage(TShock.Config.CommandSpecifier + "bprefix del group [Name]"); return; } string Name = args.Parameters[2]; bool Success = false; foreach (var p in Prefixes) { if (p.Name == Name) { Success = true; Prefixes.Remove(p); break; } } if (Success) { args.Player.SendSuccessMessage("Successfully deleted prefix group with given name: {0}.", Name); BTDatabase.PDelete(Name); } else { args.Player.SendErrorMessage("Invalid PrefixGroup name!"); } } }
private void OnReload(ReloadEventArgs args) { BTDatabase.GBGet(); BTDatabase.PGet(); }