Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lightweight #162

Merged
merged 19 commits into from
Aug 27, 2024
Merged

Lightweight #162

merged 19 commits into from
Aug 27, 2024

Conversation

ItsNature
Copy link
Collaborator

@ItsNature ItsNature commented Aug 12, 2024

Overview

Description:
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.

Further documentation for Lightweight can be found on this page.

Code Example:

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

// Create a TypeRegistry with the message types you are using.
TypeRegistry registry = TypeRegistry.newBuilder()
        .add(DisplayWaypointMessage.getDescriptor())
        .add(ConfigurableSettings.getDescriptor())
        .add(OverrideConfigurableSettingsMessage.getDescriptor())
        .build();

// Create the protobuf printer with the registry
JsonFormat.Printer printer = JsonFormat.printer().usingTypeRegistry(registry);

// 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();

// Pack the messages into Any 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);
}

Method 2: Manual JSON Object Construction

// Construct the enable module message
JsonObject configurableSetting = new JsonObject();
configurableSetting.addProperty("apolloModule", "waypoint");
configurableSetting.addProperty("enable", true);

JsonArray configurableSettingsArray = new JsonArray();
configurableSettingsArray.add(configurableSetting);

JsonObject settingsObject = new JsonObject();
settingsObject.addProperty("@type", "type.googleapis.com/lunarclient.apollo.configurable.v1.OverrideConfigurableSettingsMessage");
settingsObject.add("configurableSettings", configurableSettingsArray);

// Send data
player.sendPluginMessage(this, "apollo:json", settingsObject.toString().getBytes());

// Construct the display waypoint message
JsonObject location = new JsonObject();
location.addProperty("world", "world");
location.addProperty("x", 150);
location.addProperty("y", 100);
location.addProperty("z", -150);

JsonObject color = new JsonObject();
color.addProperty("color", 255);

JsonObject waypointObject = new JsonObject();
waypointObject.addProperty("@type", "type.googleapis.com/lunarclient.apollo.waypoint.v1.DisplayWaypointMessage");
waypointObject.addProperty("name", "KoTH");
waypointObject.add("location", location);
waypointObject.add("color", color);
waypointObject.addProperty("preventRemoval", true);

// Send data
player.sendPluginMessage(this, "apollo:json", waypointObject.toString().getBytes());

Method 3: Direct JSON String Serialization

// Construct the JSON strings
String enableModuleData = "{\"@type\":\"type.googleapis.com/lunarclient.apollo.configurable.v1.OverrideConfigurableSettingsMessage\",\"configurableSettings\":[{\"apolloModule\":\"waypoint\",\"enable\":true}]}";
String displayWaypointData = "{\"@type\":\"type.googleapis.com/lunarclient.apollo.waypoint.v1.DisplayWaypointMessage\",\"name\":\"KoTH\",\"location\":{\"world\":\"world\",\"x\":150,\"y\":100,\"z\":-150},\"color\":{\"color\":255},\"preventRemoval\":true}";

// Send data
player.sendPluginMessage(this, "apollo:json", enableModuleData.getBytes());
player.sendPluginMessage(this, "apollo:json", displayWaypointData.getBytes());

Review Request Checklist

  • Your code follows the style guidelines of this project.
  • I have performed a self-review of my code.
  • I have tested this change myself. (If applicable)
  • I have made corresponding changes to the documentation. (If applicable)
  • The branch name follows the projects naming conventions. (e.g. feature/add-module & bugfix/fix-issue)

@ItsNature ItsNature added type: Documentation Documentation improvement or issue type: Enhancement Feature improvement or addition labels Aug 12, 2024
@ItsNature ItsNature marked this pull request as ready for review August 13, 2024 17:12
@ItsNature ItsNature merged commit 6c63dc6 into version/1.1.5 Aug 27, 2024
2 checks passed
@ItsNature ItsNature deleted the lightweight branch August 27, 2024 08:39
ItsNature added a commit that referenced this pull request Aug 28, 2024
* WIP: lightweight docs

* Lightweight doc revamp

* Simple touch-ups

* Switch methods to tabs

* Attempt to fix tabs

* Close tabs

* again

* Revert tabs

* Attempt to add tabs once more

* Add tab import

* Fix tab import

* Add lightweight-wrapper & lightweight-example modules

* Register "lunar:apollo" for player detection

* Add protobuf repo section

* Remove lightweight-wrapper & lightweight-example

* Add the Apollo repository & protobuf-java-util as dependency to docs

* Use correct `

* Fix typo

---------

Co-authored-by: TrentinTheKid <[email protected]>
@ItsNature ItsNature mentioned this pull request Sep 5, 2024
ItsNature added a commit that referenced this pull request Oct 28, 2024
* Deploy as 1.1.5-SNAPSHOT

* Lightweight (#162)

* WIP: lightweight docs

* Lightweight doc revamp

* Simple touch-ups

* Switch methods to tabs

* Attempt to fix tabs

* Close tabs

* again

* Revert tabs

* Attempt to add tabs once more

* Add tab import

* Fix tab import

* Add lightweight-wrapper & lightweight-example modules

* Register "lunar:apollo" for player detection

* Add protobuf repo section

* Remove lightweight-wrapper & lightweight-example

* Add the Apollo repository & protobuf-java-util as dependency to docs

* Use correct `

* Fix typo

---------

Co-authored-by: TrentinTheKid <[email protected]>

* fix: ClassCastException for Color conversion in newer Java versions (#161)

* fix: ClassCastException for Color conversion in newer Java versions

This commit corrects the issue by converting the Color object to its RGB hex string representation.

* fix: Restore HEX string compatibility while retaining Color object support

This commit addresses the regression introduced in the previous fix that enabled Color object usage but broke HEX string compatibility. The code has been adjusted to ensure that both HEX strings (e.g., "#FFFFAA00") and Color objects (e.g., Color.RED) can be used interchangeably when setting color values in options.set(). This fix ensures backward compatibility with the previous behavior while retaining the ability to use Color objects without causing a ClassCastException.

* Throw RuntimeException for invalid Color types

---------

Co-authored-by: ItsNature <[email protected]>

* make player an audience (#163)

* Deploy as 1.1.6-SNAPSHOT

* Feature - Tebex Module (#167)

* Implement Tebex module

* Rename TebexCheckoutSupportType to TebexEmbeddedCheckoutSupport & add basket id parameter to the tebex command

* basketId -> basketIdent

* Remove callout & doc page

---------

Co-authored-by: TrentinTheKid <[email protected]>

* Feature - Add Tebex locale field (#174)

* Add locale field to the tebex module

* Add seperate method to not break the API

* Use correct locale arg

* Lightweight: Documentation (#172)

* Add a bunch of lightweight examples

* Add more examples

* Even more examples...

* More examples & prepare for example plugin merge

* Fix adventure usages

* Testable state

* Add more notes

* Add switch implementation command

* Finish more examples, start working on markdown

* Spotless fixes

* Update beam.mdx with new examples

* Finish team examples

* More markdown work

* Add missing import to chat.mdx

* Move builders outside tabs again

* Fix remaining serialization issues

* Add more markdown examples

* Add hologram & limb examples

* move builders inside API tab, add nametag, nickhider & notification examples

* Finish proto examples

* Remove object utils

* add temp layout

* Finish all Json Examples

* Add Tebex module locale field to lightweight examples

* The merge!

* Start lightweight.mdx rewrite

* Close tab

* Import callout

* ADd modsettings examples

* richpresence, serverrule, staffmod, stopwatch, title, tntcountdown, tranfser, vignette & waypoint markdown examples

* Protobuf Lightweight Documentation

* Minor changes

* Updating player world code & markdown, packet enrichment & minor parameter fixups

* Fix links

* Fix the fixed links

* Spotless fixes

* Add lightweight callout to intro

* add intro to meta json

* Finish JSON lightweight docs

* Remove old lightweight.mdx

* Link usage methods, add module examples note

* resolve callout issue?

* Rebuild

* Team markdown examples

* update callout

* update callout

* remove placeholder text

* Remove build status

* Replace Component#appendNewLine with Component.append(Component.newline()) for backwards compatibility

* Default implementation type to API

* Remove protobuf-java-util dependency

* Final touch-ups

* fix typo

* Wording Change

* Lightning -> Lighting

* Use Futures for Roundtrip example & implement timeout

* Mark player data fields with `@Nullable`

---------

Co-authored-by: TrentinTheKid <[email protected]>

* Feature - Add packet spam debug command example (#177)

* add spam packet debug command

* decrease delay on packet spam

* improve spam packets command

---------

Co-authored-by: ItsNature <[email protected]>

* Sync LunarClient Mods & Options (#181)

* Sync LunarClient Mods & Options

* Update version tags to 1.1.6

---------

Co-authored-by: LunarClient Bot <[email protected]>

* Bump to 1.1.6 (#182)

---------

Co-authored-by: TrentinTheKid <[email protected]>
Co-authored-by: Hugo <[email protected]>
Co-authored-by: Connor <[email protected]>
Co-authored-by: LunarClient Bot <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: Documentation Documentation improvement or issue type: Enhancement Feature improvement or addition
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants