pdinklag / MinecraftStats

A Minecraft player statistics browser for the web - supports 1.13 and later!
https://discord.gg/brH5PGG8By
Other
226 stars 53 forks source link

MinecraftStats

Minecraft 1.13 to 1.12 License: CC BY-SA 4.0 Example Installation at DVGaming.com Discord

MinecraftStats is a web browser application for the statistics that Minecraft servers collect for players.

The presentation is done by giving awards to players for certain achievements. For example, the player who played on the server for the longest total time receives the Dedication award. Every award has a viewable ranking associated to it with medals - the award holder gets the gold medal, the second the silver medal and the third the bronze medal for the award. Each medal gives players a crown score (1 for every bronze medal, 2 for every silver, 4 for every gold medal), which is displayed in a server hall of fame.

A live demo of MinecraftStats in action is available here: DVG Snapshot Stats. Feel free to join the project's Discord for help – or just for fun!

Overview

This is to give a brief overview as to how MinecraftStats works.

Data Updates

The web frontend of MinecraftStats is initially empty and needs to be fed data from your Minecraft server. This is done via an update.

The updater (either the plugin or the CLI, see below) will look at your players' statistics, which are typically stored in JSON files under world/stats in your Minecraft server's directory. From this, using predefined awards and events, it will compute rankings as well as a Hall of Fame score. The data is contained in a data directory in the web frontend's directory.

Using the Configuration, you can change some behaviour like excluding certain players. It is possible to run Events that track certain statistics only for a fixed amount of time – for example, picture a Skeleton Hunt event over Halloween. The system is extensible and you can add Custom Awards.

Plugin vs. CLI

MinecraftStats comes in two flavors. You can use it as a Plugin or via the command-line interface (CLI). Briefly, if your server supports plugins (e.g., SpigotMC or PaperMC), using the plugin is the much easier way. If you are running a vanilla server or prefer to have data updates under more careful control, you will have to use the CLI.

This documentation is written for both variants. If anything special applies to one variant in particular, you will always find a corresponding subsection.

Plugin Exclusives

The Plugin has some exclusive features, making its use much easier than the CLI. Some features are for communication with other plugins, others are conveniences that are enabled by being run in the scope of a server application.

Setup

This section will guide you through getting MinecraftStats up and running.

Requirements

MinecraftStats supports Minecraft 1.13 or later. For the web frontend, a webserver is required.

Plugin

The plugin can be used in any server capable of running Spigot plugins, particularly Spigot or PaperMC. MinecraftStats automatically detects the following plugins that feature a webserver:

That said, if you have any of the above plugins installed, there is no need to setup a webserver yourself unless you desire to.

CLI

Java 8 or later is required to run the CLI. You will need to setup a webserver yourself.

Installation

Plugin

Simply place MinecraftStats.jar into your server's plugins directory.

If you intend to use your own webserver, follow the steps described for the web frontend setup below.

CLI

Unpack the MinecraftStatsCLI.zip from the release wherever you like. In the Configuration, you must set the data → documentRoot and server → sources settings to match your system.

Furthermore, follow the steps described for the web frontend setup below.

Combining Multiple Servers (BungeeCord)

The server → sources setting supports multiple entries, so you can combine multiple servers into a single statistics browser.

Web Frontend Setup

Extract the contents of MinecraftStatsWeb.zip to the place within your document root that you configured in the data → documentRoot setting.

Make sure that the updater has write permissions to that directory.

Migrating from Python

If you previously used the Python version, you can use MinecraftStats almost like before by using the CLI. Bascially, update.py is now MinecraftStatsCLI.jar that you run via java -jar rather than Python. Just like for Minecraft 1.13, Java 8 or later is required.

:warning: The former workflow of simply cloning this repository and updating away is now deprecated. The repository only contains the source code, the runnable jar and ready web frontend files must be built from source or can be downloaded from the releases. To migrate, keep your config and follow the steps described for the CLI and Web Frontend above, then do the following config updates.

In your config.json, you will now have to add the data → documentRoot setting that points to your webserver (see Configuration for details):

"data": {
    "documentRoot": "/var/www/html"
},

The server → customName setting has been renamed to client → serverName.

If you created custom awards, you will have to translate them to a JSON representation; the Python scripts will no longer work. Head to Custom Awards for details. If you used events, they are no longer stated in config.json but in separate files. See Events for details.

Configuration

Depending on whether you use the plugin or the CLI, the configuration is done in a YAML or JSON file, respectively. The following settings apply for both.

Plugin

The configuration is done in the plugin's config.yml. If it does not exist, the default configuration will be created.

The following settings are for the plugin only:

CLI

The configuration must be given in a JSON file. Edit the default config.json to reflect your server.

The following setting is required for the CLI:

Usage

This section describes the everyday use of MinecraftStats.

Plugin

By installing the plugin with the default configuration and if you have a plugin featuring a webserver (see Requirements), you're already set. The plugin will automatically update the data for the web frontend once started, and then regularly according to the data → updateInterval setting.

If you rely on MinecraftStats to find a webserver plugin, this is how you and your players access the web frontend using a browser:

CLI

When using the CLI, the data for the web frontend needs to be updated by executing MinecraftStatsCLI.jar like so:

java -jar MinecraftStatsCLI.jar config.json
Automatic Updates

The CLI does not include any means for automatic updates - you need to take care of this yourself. The following lists some possibilities you might have.

The most common way to do automatic updates (on Linux servers) is by creating a cronjob that starts the update script regularly, e.g., every 10 minutes. Typically, a cronjob for MinecraftStats will look like this:

# update MinecraftStats every 5 minutes
*/5 *  *  *  *  java -jar MinecraftStatsCLI.jar config.json

⚠️ Note that cronjobs run in the current working directory. It is therefore recommend to state an absolute path in the data → documentRoot setting.

FTP

In case you use FTP to transfer the player's statistics JSON files to another machine before updating, please note that MinecraftStats uses a JSON file's last modified date in order to determine a player's last play time. Therefore, in order for it to function correctly, the last modified timestamps of the files need to be retained.

Events

Events allow you to track a specific award for a limited amount of time. Events are defined in a JSON file each in the events directory either in the plugin's directory (or next to config.json for the CLI)..

The following information needs to be specified for an event:

Be sure to align your start and end times to your update interval in order to avoid inaccuracies.

:warning: Note that at least one update must happen before the event starts. Otherwise, there is no way for MinecraftStats to know the scores of each player before the event, and thus the scores will be counted from the beginning of the server rather than your start time.

Example

As an example, consider a Halloween-themed event called "Skeleton Hunt" that tracks how many skeletons people kill between October 30, 10 AM in the morning and midnight of November 1. We would create the file skeleton-hunt-2023.json in the events directory with the following contents:

{
    "name": "skeleton_hunt_2023",
    "title": "Skeleton Hunt",
    "stat": "kill_skeleton",
    "startTime": "2023-10-30 10:00",
    "endTime": "2023-11-01 00:00"
}

Custom Awards

The awards are defined in the stats directoy in a JSON file each. You can create additional awards simply by adding another JSON file. By convention, the name of the JSON file should match the ID of the award.

A JSON object defining an award consists of the following felds:

As a hint, if you wish to create a custom award, it is a good idea to find an already existing award that is similar to what you have in mind, and then copy its JSON file and edit it as needed. Especially regarding data readers, this is by far the most simple way that should work for almost all cases.

Data Readers

Readers define how an award score is determined from a player's statistics JSON. There are different types of readers that can be selected using the $type field. The other fields that are available depend on the selected type. The following is a listing of the available reader types, each with an example award (ID) for reference.

Advancements

MinecraftStats also loads players' advancements. These can be accessed by stating advancements as the first node. An example can be found in the biomes award, which counts the number of different biomes a player has visited.

Icon

Place your award's icon into the img/award-icons directory of the web frontend. It must be named after the award's ID.

Localization

You give your award a human-readable title and description by editing the localization. The localization files are found in the localization directory of the web frontend with one JSON file per language each.

Development

MinecraftStats is a Gradle project. By executing the release task, all release artifacts (Plugin, CLI and standalone web frontend) are generated from the source.

Troubleshooting

Here is some help troubleshooting common issues.

History

The project started as a hyper-casual idea to get player rankings for certain things. It was meant as a special attraction on our small snapshot survival server at DVGaming. Because we ran snapshot versions of Minecraft, vanilla servers had to be supported and thus a plugin for Bukkit was out of question. The project was a very simple command-line script in the beginning, and I chose Python to do that.

MinecraftStats was rewritten twice. The first rewrite happened in 2018 following the release of snapshot 17w47a for Minecraft 1.13, where Mojang change the structure of how Minecraft stores player statistics completely.

Throughout the years, MinecraftStats gained some popularity, much more than anticipated. With that, requests for a Bukkit (Spigot / PaperMC) plugin became more frequent. A first shot at a plugin that simply executed the Python script failed, because many hosters don't allow that. For that reason, and to reflect the fact that the project had become much more complex and the Python code became more and more of a mess, the project was rewritten in Java in a way that both plugin and vanilla servers are supported.

Only since the Java implementation, MinecraftStats officially has numbered versions that follow the Semantic Versioning scheme.

Changelog

3.31

This update uses a newer API of SkinsRestorer and fixes more MOTD issues.

3.3.0

This update adds automatic detection of squremap's webserver and fixes bugs in both the plugin and CLI.

3.2.1

This update fixes future events being displayed as "Finished" in the web frontend, as well as the "Invalid Date" display for event end times.

3.2.0

This update adds automatic detection of BlueMap's webserver and fixes bugs in the plugin.

3.1.0

This update adds SkinsRestorer for the plugin and avoids unnecessary Mojang API calls.

3.0.2

This patch release fixes issues that occurred for offline-mode servers.

3.0.1

In full 202X fashion, here's a release-day patch that fixes an issue in the plugin. The CLI and web frontend are not affected.

3.0.0

This was the initial release of the Java reimplementation.

License and Attribution

MinecraftStats is released under the Creative Commons BY-SA 4.0 license. This means you can pretty much use and modify it freely, with the only requirements being attribution and not putting it under restrictive licenses if modified.

The only requirement regarding attribution is that you provide a visible link to this original repository in your installment. The easiest way to do this is by not removing it from the footer in index.html where you will also find a reminder about this.