From 2e8823434c298e3052674add48d54b83fb658cae Mon Sep 17 00:00:00 2001 From: AkjaHAsLk1IALk0MasH <46046453+AgaSpace@users.noreply.github.com> Date: Sun, 14 May 2023 10:30:52 +0700 Subject: [PATCH 1/4] Updated the PlayerData constructors. Added a new constructor with a parameter that is responsible for installing TShock items into inventory. The `TSPlayer` parameter was not used, so I labeled the constructor obsolete. --- TShockAPI/PlayerData.cs | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/TShockAPI/PlayerData.cs b/TShockAPI/PlayerData.cs index 2a8dd41f..aae27672 100644 --- a/TShockAPI/PlayerData.cs +++ b/TShockAPI/PlayerData.cs @@ -23,6 +23,7 @@ using Terraria.Localization; using Terraria.GameContent.NetModules; using Terraria.Net; using Terraria.ID; +using System; namespace TShockAPI { @@ -63,18 +64,27 @@ namespace TShockAPI public int unlockedSuperCart; public int enabledSuperCart; - public PlayerData(TSPlayer player) + /// + /// Sets the default values for the inventory. + /// + [Obsolete("The player argument is not used.")] + public PlayerData(TSPlayer player) : this(true) { } + + /// + /// Sets the default values for the inventory. + /// + /// Is it necessary to load items from TShock's config + public PlayerData(bool includingStarterInventory = true) { for (int i = 0; i < NetItem.MaxInventory; i++) - { this.inventory[i] = new NetItem(); - } - for (int i = 0; i < TShock.ServerSideCharacterConfig.Settings.StartingInventory.Count; i++) - { - var item = TShock.ServerSideCharacterConfig.Settings.StartingInventory[i]; - StoreSlot(i, item.NetId, item.PrefixId, item.Stack); - } + if (includingStarterInventory) + for (int i = 0; i < TShock.ServerSideCharacterConfig.Settings.StartingInventory.Count; i++) + { + var item = TShock.ServerSideCharacterConfig.Settings.StartingInventory[i]; + StoreSlot(i, item.NetId, item.PrefixId, item.Stack); + } } /// From 763519150a5a4ab4fdca7435cdf0dfa8c3d3e246 Mon Sep 17 00:00:00 2001 From: AkjaHAsLk1IALk0MasH <46046453+AgaSpace@users.noreply.github.com> Date: Sun, 14 May 2023 10:33:54 +0700 Subject: [PATCH 2/4] Updated the `PlayerData.StoreSlot` method Removed the ability to call a method when a slot less than 0 is specified. Added an overload that takes `NetItem` in parameters. --- TShockAPI/PlayerData.cs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/TShockAPI/PlayerData.cs b/TShockAPI/PlayerData.cs index aae27672..b2866eb1 100644 --- a/TShockAPI/PlayerData.cs +++ b/TShockAPI/PlayerData.cs @@ -96,12 +96,22 @@ namespace TShockAPI /// public void StoreSlot(int slot, int netID, byte prefix, int stack) { - if (slot > (this.inventory.Length - 1)) //if the slot is out of range then dont save + StoreSlot(slot, new NetItem(netID, stack, prefix)); + } + + /// + /// Stores an item at the specific storage slot + /// + /// + /// + public void StoreSlot(int slot, NetItem item) + { + if (slot > (this.inventory.Length - 1) || slot < 0) //if the slot is out of range then dont save { return; } - this.inventory[slot] = new NetItem(netID, stack, prefix); + this.inventory[slot] = item; } /// From b184133a7f8594e84bf8dca16d0c1525715477fd Mon Sep 17 00:00:00 2001 From: AkjaHAsLk1IALk0MasH <46046453+AgaSpace@users.noreply.github.com> Date: Sun, 14 May 2023 10:43:01 +0700 Subject: [PATCH 3/4] Updated the call to the obsolete constructor `PlayerData` --- TShockAPI/DB/CharacterManager.cs | 2 +- TShockAPI/GetDataHandlers.cs | 4 ++-- TShockAPI/TSPlayer.cs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/TShockAPI/DB/CharacterManager.cs b/TShockAPI/DB/CharacterManager.cs index 5a5e13a6..357dc746 100644 --- a/TShockAPI/DB/CharacterManager.cs +++ b/TShockAPI/DB/CharacterManager.cs @@ -79,7 +79,7 @@ namespace TShockAPI.DB public PlayerData GetPlayerData(TSPlayer player, int acctid) { - PlayerData playerData = new PlayerData(player); + PlayerData playerData = new PlayerData(false); try { diff --git a/TShockAPI/GetDataHandlers.cs b/TShockAPI/GetDataHandlers.cs index 1ef2f4f8..f82b7a8e 100644 --- a/TShockAPI/GetDataHandlers.cs +++ b/TShockAPI/GetDataHandlers.cs @@ -2619,9 +2619,9 @@ namespace TShockAPI private static bool HandleConnecting(GetDataHandlerArgs args) { var account = TShock.UserAccounts.GetUserAccountByName(args.Player.Name);// - args.Player.DataWhenJoined = new PlayerData(args.Player); + args.Player.DataWhenJoined = new PlayerData(false); args.Player.DataWhenJoined.CopyCharacter(args.Player); - args.Player.PlayerData = new PlayerData(args.Player); + args.Player.PlayerData = new PlayerData(false); args.Player.PlayerData.CopyCharacter(args.Player); if (account != null && !TShock.Config.Settings.DisableUUIDLogin) diff --git a/TShockAPI/TSPlayer.cs b/TShockAPI/TSPlayer.cs index ef5c3c22..afbd3176 100644 --- a/TShockAPI/TSPlayer.cs +++ b/TShockAPI/TSPlayer.cs @@ -1267,7 +1267,7 @@ namespace TShockAPI } } - PlayerData = new PlayerData(this); + PlayerData = new PlayerData(); Group = TShock.Groups.GetGroupByName(TShock.Config.Settings.DefaultGuestGroupName); tempGroup = null; if (tempGroupTimer != null) From 8ccb3c6210077c8ddaf90dcc799ac096a0362b39 Mon Sep 17 00:00:00 2001 From: AkjaHAsLk1IALk0MasH <46046453+AgaSpace@users.noreply.github.com> Date: Sun, 14 May 2023 10:43:12 +0700 Subject: [PATCH 4/4] Update changelog.md --- docs/changelog.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/changelog.md b/docs/changelog.md index 3f64f355..93485b3f 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -78,7 +78,9 @@ Use past tense when adding new entries; sign your name off when you add or chang * If there is no section called "Upcoming changes" below this line, please add one with `## Upcoming changes` as the first line, and then a bulleted item directly after with the first change. --> ## Upcoming changes -Your changes could be here! +* Added a constructor for `TShockAPI.PlayerData` that accepts the `includingStarterInventory` parameter, which is responsible for loading the TShock inventory. +* Declared the constructor `TShockAPI.PlayerData` accepting the argument `TShockAPI.TSPlayer` obsolete. +* Updated the `PlayerData.StoreSlot` method: Added an overload that takes `TShockAPI.NetItem`. ## TShock 5.2 * An additional option `pvpwithnoteam` is added at `PvPMode` to enable PVP with no team. (@CelestialAnarchy, #2617, @ATFGK)