MySQL guide - rutgerkok/BetterEnderChest GitHub Wiki

BetterEnderChest has an option to save the chests in the database. This can be used to share chests between servers or a website.

Database format

The database format is very simple: each world group gets its own table, and each table has three columns: one is the numerical id of the chest, one is the name and one is a serialized blob of the NBT of the contents of the Ender Chest.

Switching from flatfile to MySQL

When you switch to MySQL, you will notice that BetterEnderChest no longer attempts to load chests from the old chest directory on disk. If you still want to have those chests, you need enable importing from flatfile.

First of all, set BetterEnderChest.manualWorldgroupManagement to true. Restart the server or reload the config file using /bec reload. Two new sections will appear in your config.yml: the Groups and the Imports section. We can leave the Groups section alone, we only need to change the Imports section.

In the imports section, you will see the importer that is used for each group. If you aren't using the multigroup feature, it will just look like this:

Imports:
  default: vanilla

For each group, change the importer to betterenderchest-flatfilenbt. Instead of trying to import from the vanilla Ender Chests, BetterEnderChest will now try to import from the old .dat files.

Sharing chests between servers

Ender Chests are automatically shared between servers when the group names are the same on both servers and both servers point to the same database. However, there's one caveat: BetterEnderChest keeps the Ender Chests in memory. This cache is needed, otherwise things will go horribly wrong when two people on the same server view the same Ender Chest: items will get lost or duplicated, depending on which person closes the inventory first.

Chests are unloaded from the cache if there are no unsaved changes, the owner is offline and no one is viewing the inventory. Chest unloading happens during the autosave tick. How often this tick happens, depends on the AutoSave.autoSaveIntervalSeconds setting. If you set this to three, it means that within three seconds of the last change to the chest, the chest will get saved to the database. If the player logs out, the chest will be unloaded within those three seconds, provided there are no unsaved changes.

Even if the player made a change to the Ender Chest just before he logged out on that server, the chest will get unloaded within six seconds (within three seconds the autosave will happen, exactly three seconds later the chest will get unloaded). Assuming he logs in two seconds later on another server, it means he has four seconds before he can open his Ender Chest on the other server. If he opens his chest within those four seconds, he will see an outdated chest. If you are worried about this, you can set the AutoSave.autoSaveIntervalSeconds to an even lower value, for example 1 second.

Don't worry: BetterEnderChest won't save the chest if there are no unsaved changes to the chest since the last autosave. This means that even with a very low AutoSave.autoSaveIntervalSeconds, only a small amount of chest will get saved.