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 5dbf6c7d..578a8653 100644
--- a/TShockAPI/GetDataHandlers.cs
+++ b/TShockAPI/GetDataHandlers.cs
@@ -2620,9 +2620,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/PlayerData.cs b/TShockAPI/PlayerData.cs
index bab9f7a6..c84da7c7 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);
+ }
}
///
@@ -86,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;
}
///
diff --git a/TShockAPI/TSPlayer.cs b/TShockAPI/TSPlayer.cs
index 4fd65275..f6c06f85 100644
--- a/TShockAPI/TSPlayer.cs
+++ b/TShockAPI/TSPlayer.cs
@@ -1292,7 +1292,7 @@ namespace TShockAPI
}
}
- PlayerData = new PlayerData(this);
+ PlayerData = new PlayerData();
Group = TShock.Groups.GetGroupByName(TShock.Config.Settings.DefaultGuestGroupName);
tempGroup = null;
if (tempGroupTimer != null)
diff --git a/docs/changelog.md b/docs/changelog.md
index 3fa0cf9e..537361eb 100644
--- a/docs/changelog.md
+++ b/docs/changelog.md
@@ -117,6 +117,9 @@ Use past tense when adding new entries; sign your name off when you add or chang
* Added a property `TSPlayer.Hostile`, which gets pvp player mode. (@AgaSpace)
* Fixed bug where when the `UseSqlLogs` config property is true, an empty log file would still get created. (@ZakFahey)
* Fixed typo in `/gbuff`. (@sgkoishi, #2955)
+* 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`.
* Added `PlayerHooks.PrePlayerCommand` hook, which fired before command execution. (@AgaSpace)
* Added `PlayerHooks.PostPlayerCommand` hook, which fired after command execution. (@AgaSpace)