Skip to content

General notes on multi-platform Jars and supporting more server types in a manageable way #170

@p0t4t0sandwich

Description

@p0t4t0sandwich

My general use case here is that the majority of my plugins/mods support all modding/plugin APIs in one Jar, so it's a bit of a pain to include metrics for 4 different implementations in a reasonable manner (my current implementation works, but is a bit sketchy imo).

If bStats ever expands to more server types, it should have a generalized implementation available at bStats-Metrics, allowing for it to be easily expanded upon, probably using something similar to this:

public class Metrics {
    private static Supplier<Integer> playerCountFunc = () -> 0
    
    public static setPlayerCountFunc(Supplier<Integer> playerCountFunc) {
        this.playerCountFunc = playerCountFunc
    }
    
    // ... The rest of the Metrics class
}

Or alternatively, bStats could ship all the logic in one dependancy that can be shaded, that checks the server type/version and applies the right methods automagically.
The jump to multi-platform is a bit much tbh, but after the initial setup it's a lot nicer to maintain, given that everything except for platform-dependent methods is common code.

If bStats ever goes that route, the server type could be another field in the API, allowing for developers to just set up any multi-platform plugin with the same pluginId.

Edit:
Wrote up a generalized example here:
https://github.com/p0t4t0sandwich/TaterLib/blob/dev/common/src/main/java/dev/neuralnexus/taterlib/bstats/MetricsAdapter.java
Main idea is to check what platform the server is running on, then use whatever helper class to safely get the proper platform methods.

The main future maintainability concern here will obviously be Forge, as you can't leverage intermediaries like you can with Fabric to get multi-version support from one artifact, though if multi-platform support were to be implemented, I'd be willing to take on Forge and create some decent abstractions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions