Hey
I want to save the Enderchests of all Players in a MySQL Database.
When a player opens an Enderchest, the Items, should be pulled from db, because I want be able to change the Items through the database (not only in game).
I think I need a Event to detect, if the player places / removes a block in the enderchest (because I have to update the mysql content).
The location of the items in the enderchest doesnāt matter.
I have to save the items with their block name + count (autogroup stacks), because I have to edit them through my webpage.
Can you guys give me some keywords ?
Enderchest block place / remove event
Count blocks / items
Event when player opens enderchest.
DB Columns:
uuid
object array (objects containing minecraft item name/id and block count)
I hope you understand, what I want to do hereā¦
Greets
use inventorycloseevent and inventoryopenevent, you dont need to save data every time player places a single item into the chests. You will end up with lots of pointless queries
easy but not recommended - use base64
better way: for each itemstack property use its own column,
storing more than one information into a single column is breaking main database logic.
As the table index use uuid . UUIDs save as a string, not as a binary data
For both saving and loading use asynchronous tasks.
jup, i know that this solution isnāt very smart
inventorycloseevent, inventoryopenevent are they for enderchests ?
problem: what is, if a player puts items in his chests and the client crashes before he closes the chest ?
ā player opens the chest again, the plugin overrides his itemsā¦
I would do it like this:
inventorycloseevent
get the content of the chest (how can I do this?)
split it in columns ā save items in my database
inventoryopenevent
get item columns from the database and create a enderchestinventory
object (how is the name of this, when there is one?)
i belive the closeeven should be fired even if player disconnects.
Maybe it would be simpler to use instead of inventoryopeneven playerinteractblockevent or either playerinteractentityevent (one of them should be fired when player rightclicks an enderchest).
Once the player rightlicks the chests cancell the event and run async task which fetches data from your database. once all the data are loaded run synchronous callback and create & open inventory for the player.
your implication is fairly vague to me. Iām not saying he has to use it or that he canāt use mysql, just that he may want to consider it.
I realize he asked for help with SQL serialization but it canāt hurt to mention alternatives if heās not completely tied to mysql.
ābecause I have to update the mysql contentā is him talking about events updating the database, not him saying āI must use mysqlā. sure, mysql is a possible backing store but mongo can just as well be, if he has the infrastructure to run it and the will to try.
never said his host locked him in to mysql, though itās a possibility; in which case my suggestion is moot and we can move along.
The only way to really keep consistency with minecrafts save files would be to either sync the contents when the file itself saves, or not use the real enderchest contents at all and somehow substitute the enderchest inventory for your own SQL backed inventory. Iām actually kind of interested in saving out player.datās (/ changing UUID ) and reloading them as being in the API in some form. Would allow for proper multiworld inventory handling, and having multiple characters per gameprofile for role play servers, and switching between player and moderator roles by literally saving everything about the player before turning them into their staff persona.