EverNifeCore icon indicating copy to clipboard operation
EverNifeCore copied to clipboard

Adding Mysql Components

Open ailanlana opened this issue 2 years ago • 5 comments

Right now it looks like the only storage method is YAML, will you consider adding Mysql support?

ailanlana avatar May 30 '24 11:05 ailanlana

Until today i have had no comission that required the PlayerData to be on a MySQL database.

Adding support for other types of storage is possible, but is not something easy to be done, mainly because most of my plugins does not have a relational-only strucutre.

If i had to create a support for mysql it would be necessary to store the PlayerData (mainly its PDSections) on a table as JSON.


More important, what are you trying to do? Why do you need another type of storage here?

EverNife avatar May 30 '24 14:05 EverNife

Since Minecraft can't be multithreaded and my server has a lot of mods, I had to resort to multiple zones to host more players. Doing this requires me to synchronize data between zones, which requires a database such as mysql.

EverNifeCore is a great plugin, I rely on it for some of my current plugins, and it would be great to have database support.

ailanlana avatar May 30 '24 15:05 ailanlana

I have started the implementation of this feature. To be honest it's not easy and will take some time.

The PDSections must allow a few customizations, with scenarios like:

  • Main PlayerData: Store on MySQL
  • PDSection1 Store on MySQL
  • PDSection2 Store on LocalOnly
  • PDSection3 Store on MySQL
  • PDSection4... etc

This will require PDSections to be registered individually with custom configurations to make them hotloaded as soon as EverNifeCore loads/reloads.

PlayerController.registerAutoLoadPDSection(
    instance,
    FEPlayerData.class
);

Also keep PDSections being able to store their data still using YamlSyntax, so, if we end up with a MySQL database it will be in tables of json values and with other NoSQL databases would still be easy to implement.


The idea is still abstract in my mind on how to implement that, but it will eventually arrive.

EverNife avatar Jul 15 '24 21:07 EverNife

After some centuries...

With https://github.com/EverNife/EveryDatabase we will finally be able to do the desired approach for this issue.

The idea will be:

EverNifeCore persists player data through a pluggable storage layer. Your plugin declares what it wants to store; the server admin decides where it lives (local files, H2, MySQL/MariaDB, PostgreSQL or MongoDB) in storage.yml. You write plain Java objects and call an async API - no SQL, no YAML, no manual save logic.

Two things are persisted:

  • PlayerData - the base per-player entity (name, first/last seen, cooldowns). EverNifeCore owns it.
  • PDSection - your plugin's per-player data. Each section is an independent entity, keyed by the player UUID, that can live on its own backend. You can literray have one PDSection on Mysql, another on Mongo, other on Postgree. etc.

Example of PDSection:

@Data
public class StorageTestPDSection extends PDSection {

    public int level;
    public long exp;
    public String rank = "none"; //def values works
    
    @Indexed 
    public String region = "default";  // create a 'table' on the backend for faster look-up
    
    public SomeComplexObject complexObject; // Inner serializable objects must be POJO as well
    
    @JsonIgnore
    public SomeObjectThatShouldNotBeSavedOnTheDatabase temporaryObject; // Can be anything

}
flowchart TB
    subgraph ADMIN["Admin"]
        YML[("storage.yml<br/>backends + playerdata + pdsections")]
    end

    subgraph DEV["Your plugin"]
        REG["registerPDSectionCfg(...)<br/>defaultBackend / suggestedBackends /<br/>cachePolicy / onConflict"]
    end

    subgraph CORE["EverNifeCore"]
        PC["PlayerController<br/>(async-only facade)"]
        BIND["PlayerDataBinding +<br/>PDSectionBinding(s)"]
        ECS["ECStorage<br/>(your own entities)"]
    end

    subgraph EDB["Embedded storage engine"]
        STO["Storage / Repository<br/>EntityDescriptor / Codec"]
        ANN["@OptimisticLock + @Indexed"]
    end

    subgraph BACKENDS["Physical backends (admin-named)"]
        S1[("localfile")]
        S2[("h2")]
        S3[("mysql / postgresql")]
        S4[("mongo")]
    end

    YML -. resolves .-> BIND
    REG --> BIND
    PC --> BIND
    ECS --> STO
    BIND --> STO
    STO --> ANN
    STO --> S1 & S2 & S3 & S4

    classDef admin fill:#FFE0B2,stroke:#E65100,color:#000
    classDef dev fill:#C8E6C9,stroke:#1B5E20,color:#000
    classDef core fill:#BBDEFB,stroke:#0D47A1,color:#000
    classDef edb fill:#B2DFDB,stroke:#004D40,color:#000
    classDef backend fill:#D1C4E9,stroke:#311B92,color:#000

    class YML admin
    class REG dev
    class PC,BIND,ECS core
    class STO,ANN edb
    class S1,S2,S3,S4 backend

I am still working on the Cache system right now, but will be done for the next major release soon. The new major release will have lots of breaking changes, will require a full rewrite of some logics.

EverNife avatar Jun 15 '26 19:06 EverNife

The new behaviors are documented here:

  • https://github.com/EverNife/EverNifeCore/wiki/PlayerData-and-PDSections
  • https://github.com/EverNife/EverNifeCore/wiki/Storage-Backends

They are already implemented and will be released with version 3.0.1.

The idea is what I had planned before: we register a PDSection POJO at startup and define its own behavior, migrations, imports, caching, etc. It is also possible to migrate existing plain YAML files to the new pattern.

PlayerController.registerPDSectionCfg(PDSectionConfiguration
        .builder(ecPluginData, LegacyFCApiSection.class, "legacy_fcapi")
        .legacyYaml("FCApi", LegacyFCApiSection::fromLegacy) // If you are migrating from EverNifeCore 2.x
        .build());

It is possible to have multiple migrations for a PDSection, allowing data to be incrementally updated between versions. The storage layer is completely database-agnostic.

The developer implements the PDSection, while the server administrator decides where the data should be stored: MongoDB, PostgreSQL, MySQL, local files, etc.

By default, all data is cached when a player joins the server and released when they leave after a grace period. If some data needs to remain resident in memory, that can also be configured.

I will be updating my other plugins soon, so i wll have more real exemples on the next months, mainly with FinalEconomy i will be updating it and making it compat with Hytale on the same buildscript.

EverNife avatar Aug 11 '26 03:08 EverNife