Offline Player Cache: Directors Cut - Player Data Caching
The Offline Player Cache: Directors Cut mod offers a completely redesigned solution for preserving player information on Minecraft servers even after they log out.
Main Features
Developers can register special records linked with identifiers and encoders for data serialization. When a player leaves the server, all their information is saved in the server's level data, allowing access through code or mod commands.
When a player reconnects to the server, their cached data is automatically deleted.
Available Commands
Retrieving Information
The /opc get <uuid>|<name> <key> command displays current player values. For online players, it shows real-time data; for offline players, it shows cached data.
Removing Data
The /opc remove <uuid>|<name> <key> command removes cached values of offline players based on the selected key. This command has no effect on online players.
Viewing List
The /opc list <uuid>|<name> command shows all keys and values stored for the specified player - current values for online players and cached values for offline players.
Developer Guide
Project Setup
To work with the API, add the following settings to your project:
gradle.properties file
opc_version=...
build.gradle file
repositories {
maven {
name = "Modrinth"
url = "https://api.modrinth.com/maven"
content {
includeGroup "maven.modrinth"
}
}
}
dependencies {
modImplementation "maven.modrinth:opc-directors-cut:${project.opc_version}"
// add this line if you don't want to require users to install the mod
include "maven.modrinth:opc-directors-cut:${project.opc_version}"
}
Creating a Record
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
public record Contract(String label, boolean signed) {
public static Codec<Contract> CODEC = RecordCodecBuilder.create((instance) ->
instance.group(
Codec.STRING.fieldOf("label").forGetter(Contract::label),
Codec.BOOL.fieldOf("signed").forGetter(Contract::signed)
).apply(instance, Contract::new)
);
}
Registering a Record
import maven_group.modid.concept.Contract; // Contract :)
// somewhere during static/mod initialization
private void init() {
OfflinePlayerCacheAPI.register(CONTRACT_RECORD_ID, Contract.class, Contract.CODEC, (Player player) -> {
// within this block, you decide how to translate a player's data to the Record you chose
return new Contract(player.getName() + ":contracted", true);
});
}
Retrieving Data
var cache = OfflinePlayerCacheAPI.getCache(server);
cache.getEntry(Contract.class, "bibi_reden").ifPresent(contract -> {
// we now know that there is a valid Contract entry for this player
// You can also use a UUID to fetch an entry as well
});
What's New in Version 2.*
In the new version, the concept of keys has been removed. Instead, you register an identifier, a record, and an encoder for working with data.