A library that extends the Minecraft Server Management Protocol (MSMP) by allowing for custom methods and notifications to be registered with the MSMP registry. Easy to use, customizable, and extensible.
Add the following to your build.gradle:
repositories {
maven { url = uri("https://jitpack.io") }
}
dependencies {
implementation("com.github.YOUR_USERNAME:msmp-lib:VERSION")
}And declare the dependency in your fabric.mod.json:
"depends": {
"msmp-lib": "*"
}Payloads are simple records that describe the data sent and received over MSMP.
Each payload needs a Codec for serialization and a Schema for MSMP discovery.
public record PingPayload(String message) {
public static final Codec<PingPayload> CODEC = RecordCodecBuilder.create(i -> i.group(
Codec.STRING.fieldOf("message").forGetter(PingPayload::message)
).apply(i, PingPayload::new));
public static final Schema<PingPayload> SCHEMA = Schema.record(CODEC)
.withField("message", Schema.STRING_SCHEMA);
}Create a MSMPServer instance in the SERVER_STARTED lifecycle event.
Use namespace() to register methods and notifications, and send() to broadcast notifications.
public class MyMod implements ModInitializer {
private static MSMPServer msmp;
private static MSMPNotification<PingPayload> ping;
@Override
public void onInitialize() {
ServerLifecycleEvents.SERVER_STARTED.register(server -> {
msmp = new MSMPServer(server);
ping = msmp.namespace("my_mod")
.notification("ping", PingPayload.SCHEMA, "A ping notification");
msmp.namespace("my_mod")
.method("echo",
EchoPayload.SCHEMA,
EchoPayload.SCHEMA,
"Echoes a message back to the client",
(server, params, client) -> {
System.out.println("Called by connection: " + client.connectionId());
return params;
}
);
});
ServerLifecycleEvents.SERVER_STOPPED.register(server -> {
msmp = null;
});
}
// Broadcast a notification to all connected clients
public static void sendPing() {
if (msmp != null) msmp.send(ping, new PingPayload("hello"));
}
}The method handler receives three parameters:
| Parameter | Type | Description |
|---|---|---|
server |
MinecraftServer |
The running Minecraft server instance |
params |
Param |
The payload received from the client |
client |
ClientInfo |
Info about the calling client, including connectionId() |
Calling a method (my_mod:echo):
{
"jsonrpc": "2.0",
"id": 1,
"method": "my_mod:echo",
"params": [{
"message": "hello"
}]
}Response:
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"message": "hello"
}
}Receiving a notification (my_mod:notification/ping):
{
"jsonrpc": "2.0",
"method": "my_mod:notification/ping",
"params": [{
"message": "hello"
}]
}- Minecraft with MSMP enabled (
management-server-enabled=trueinserver.properties) - The Management Server listens on
localhost:25576by default