Apollo
Internals
Lightweight

Lightweight

Our lightweight integration allows for Apollo features to be used, without the need for running the entire Apollo plugin. We will introduce you to three different methods that all achieve the same goal, while utilizing separate approaches. At the end of the day, all the methods displayed send the JSON message through the plugin messaging channel apollo:json. Each method offers different trade-offs between complexity, flexibility, and performance. Choose the method that best fits your use case and environment.

Message format

The message format used to communicate, follows a loosely structured JSON schema. The schema is defined using Protocol Buffers (protobuf) and includes various fields to achieve the end result, in this example-case displaying a waypoint. While the fields will change depending on the feature you're trying to implement, the @type will also remain. It should always be at the top, as shown. You can locate all the @type protos from this page: https://buf.build/lunarclient/apollo (opens in a new tab).

{
  "@type": "type.googleapis.com/lunarclient.apollo.waypoint.v1.DisplayWaypointMessage", // The protobuf message type
  "name": "KoTH",
  "location": {
    "world": "world",
    "x": 150,
    "y": 100,
    "z": -150
  },
  "color": {
    "color": 255
  },
  "preventRemoval": true
}

Usage Methods

Explore each method by cycling through each tab, to find the best fit for your requirements and needs.

Method 1: Using the apollo-protos & protobuf-java-util libraries

This method leverages the apollo-protos library and protobuf's native serialization mechanism, which offers efficient serialization and maintains strong typing and schema validation. It involves creating a type registry, serializing messages into protobuf format, and then converting them into JSON for transmission.

Steps

  1. Create a TypeRegistry: Register the message types you are using.

    TypeRegistry registry = TypeRegistry.newBuilder()
        .add(DisplayWaypointMessage.getDescriptor())
        .add(ConfigurableSettings.getDescriptor())
        .add(OverrideConfigurableSettingsMessage.getDescriptor())
        .build();
  2. Create the protobuf printer with the registry:

    JsonFormat.Printer printer = JsonFormat.printer().usingTypeRegistry(registry);
  3. Construct the messages:

    • Enable Module Message:

      OverrideConfigurableSettingsMessage enableModuleMessage = OverrideConfigurableSettingsMessage.newBuilder()
          .addConfigurableSettings(
              ConfigurableSettings.newBuilder()
                  .setApolloModule("waypoint")
                  .setEnable(true)
                  .build()
          ).build();
    • Display Waypoint Message:

      DisplayWaypointMessage waypointMessage = DisplayWaypointMessage.newBuilder()
          .setName("KoTH")
          .setLocation(
              BlockLocation.newBuilder()
                  .setWorld("world")
                  .setX(150)
                  .setY(100)
                  .setZ(-150)
                  .build())
          .setColor(
              Color.newBuilder()
                  .setColor(255)
                  .build())
          .setPreventRemoval(true)
          .build();
  4. Pack the messages into Any type and serialize:

    Any enableModuleAny = Any.pack(enableModuleMessage);
    Any displayWaypointAny = Any.pack(waypointMessage);
     
    try {
        byte[] enableModuleBytes = printer.print(enableModuleAny).getBytes();
        byte[] displayWaypointBytes = printer.print(displayWaypointAny).getBytes();
     
        player.sendPluginMessage(this, "apollo:json", enableModuleBytes);
        player.sendPluginMessage(this, "apollo:json", displayWaypointBytes);
    } catch (InvalidProtocolBufferException e) {
        throw new RuntimeException(e);
    }

Adding the repository and dependencies

pom.xml
<repositories>
    <repository>
        <id>lunarclient</id>
        <url>https://repo.lunarclient.dev</url>
    </repository>
</repositories>
 
<dependencies>
    <dependency>
        <groupId>com.lunarclient</groupId>
        <artifactId>apollo-protos</artifactId>
        <version>1.0-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>com.google.protobuf</groupId>
        <artifactId>protobuf-java-util</artifactId>
        <version>3.25.0</version>
    </dependency>
</dependencies>