Question How to make players have an independent inventory in specified world?

Noy

New member
Jan 8, 2023
15
1
0
1
Hi! I am making a plugin that generates a custom world, and I want the players to have an indenpendent inventory in this world (which means, when a player enters this world, they will have a new inventory, and will switch back as long as they leave).

The problem is that if I implement this feature by myself, there may be some special cases which will make a mess:
  • The player lose their connection in the custom world (this may be solved by using PDC)
  • The server shutdown when there're still players in the custom world (this may be solved by using PDC)
  • The server restart without my plugin enabled (so the inventory won't recover, which can't be solve by using PDC)
  • The world is deleted when the server is not running
  • ...

So I would like to ask what is the most elegant solution, thank you!
 

stefvanschie

Moderator
Staff member
Dec 17, 2021
134
7
24
18
I think these issues can be resolved if you reset the player's inventory to their original one when they leave the server or the server stops. Additionally, when a player joins the server, you can check if they're about to join in the custom world and set their inventory to the independent one.

If a player loses their connection or the server shuts down, the players will have their old inventory restored. If the custom world is deleted, then they'll join with their old inventory as intended. If the custom world is not deleted, they'll get their inventory back when joining. If the server is restarted without your plugin, the players will also have their old inventory.
 

Noy

New member
Jan 8, 2023
15
1
0
1
I think these issues can be resolved if you reset the player's inventory to their original one when they leave the server or the server stops. Additionally, when a player joins the server, you can check if they're about to join in the custom world and set their inventory to the independent one.

If a player loses their connection or the server shuts down, the players will have their old inventory restored. If the custom world is deleted, then they'll join with their old inventory as intended. If the custom world is not deleted, they'll get their inventory back when joining. If the server is restarted without your plugin, the players will also have their old inventory.
Yeah you are right, that can absolutely solve my problem, thank you!

My purpose to ask this question here is just think that if there is any official support to do this, since there may always be some unexpected situations that after my plugin restored player's inventory, something bad happened (for example, a server crash?) which make the original inventory lost forever.

EDIT: apologize for my broken English