SQL Enderchest

Hey :smile:
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).

  1. The location of the items in the enderchest doesn’t matter.
  2. 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 ?

  1. Enderchest block place / remove event
  2. Count blocks / items
  3. 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 :smile:
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

  1. get the content of the chest (how can I do this?)
  2. split it in columns → save items in my database

inventoryopenevent

  1. get item columns from the database and create a enderchestinventory
    object (how is the name of this, when there is one?)

  2. insert items inenderchest

getContent().

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.

btw inventory/item api is not finished yet.

events and implementations aside, have you considered translating the data into json and storing it in something like mongodb?

=> implying he has to/wants to use mysql

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.

1 Like

Regardless which storage system you use, only update the contents when a user disconnects from your server and load them once when he joins.

This would imply loosing any added content when the server instantly crashed, right?

A server shouldn’t instantly crash; the contents would still be saved in minecrafts default storage for ender chest (player.dat afaik).

If the server crash, it Will not be saved. The only the way the data could be saved, is the server make auto save.

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.

I’m thinking of a lockup due to malicious hardware or a power loss :wink: