Only create Backpacks file if Backpacks permission grantedSolved
Hey @LaserHydra,

Could you please edit the plugin so that a backpack file is only created if a player has a permission to use Backpacks. Currently there are a million backpack JSON files that are sitting empty created for players who do not have permission to use them. This is a massive and slow hassle to delete and sometimes ends up in the tens of thousands. Files should only be created if the player has the ability to use Backpacks.

Thanks if you can make this change!
If you would like, you can create a pull request on GitHub for this to speed up the process.
Thanks @LaserHydra, unfortunately I'm not on GitHub at the moment (I know).

It's just 2 changes with a single if statement for each. The Backpack.Get just creates backpacks for non-perm players in 2 situations:

#1 - Added if (permission.UserHasPermission(userIdString, UsagePermission))
        private void OnUsagePermissionChanged(string userIdString)
        {
			if (permission.UserHasPermission(userIdString, UsagePermission))
			{
				var userId = ulong.Parse(userIdString);
				Backpack.Get(userId).Initialize();
			}
        }​

#2 - Added if (_backpacks.ContainsKey(player.userID))


private void OnEntityDeath(BaseCombatEntity victim, HitInfo info)
        {
            if (victim is BasePlayer && !(victim is NPCPlayer) && !(victim is HTNPlayer))
            {
                var player = (BasePlayer) victim;
				
				if (_backpacks.ContainsKey(player.userID))
				{
					var backpack = Backpack.Get(player.userID);

					backpack.ForceClose();

					if (_config.EraseOnDeath)
						backpack.EraseContents();
					else if (_config.DropOnDeath)
						backpack.Drop(player.transform.position);
				}
            }
        }

In the first situation it gates the OnUsagePermissionChanged hook to make sure it only gets a backpack if the player has permissions. This hook might be called for something completely unrelated.

In OnEntityDeath, Backpack.Get should only be called if a backpack already exists. This way it stops on initialising a new backpack everytime a fresh player has their first death.

@LaserHydra any thoughts on this?

First of all, thanks for contributing. Since I've got my exams this week, this might go under before I get it done.

In case I don't get back to this until next week, can you ping me again if you get a chance?

Again, thanks for contributing. I'm putting this into the upcoming update.
Amazing job @LaserHydra, really appreciate it! Good luck with the studies!
5b6d791123a85.jpg Kinesis
Amazing job @LaserHydra, really appreciate it! Good luck with the studies!

Thanks!

5b5bc6885b278.png LaserHydra

Thanks!

Thanks to you for claiming the plugin , stops the kids "fool capping" all the time.

5b7d22c4ef71f.jpg pookins

Thanks to you for claiming the plugin , stops the kids "fool capping" all the time.

sorry this should be in the caps no caps feedback

Locked automatically