From 17db1a2530fec078d98c99ea423c46dd2102921d Mon Sep 17 00:00:00 2001 From: ItsNature Date: Tue, 1 Oct 2024 17:29:57 +0200 Subject: [PATCH] Remove old lightweight.mdx --- docs/internals/lightweight.mdx | 271 --------------------------------- 1 file changed, 271 deletions(-) delete mode 100644 docs/internals/lightweight.mdx diff --git a/docs/internals/lightweight.mdx b/docs/internals/lightweight.mdx deleted file mode 100644 index 26f98321..00000000 --- a/docs/internals/lightweight.mdx +++ /dev/null @@ -1,271 +0,0 @@ -import { Tab, Tabs } from 'nextra-theme-docs' -import { Callout } from 'nextra-theme-docs' - -# 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 two different methods that achieve the same goal, while utilizing separate approaches. 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. -```JSON -{ - "@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: Protobuf - -This method leverages the apollo-protos library, which maintains strong typing and schema validation. - -**Steps** - -## Adding the repository and dependencies - - - - ```xml filename="pom.xml" - - - lunarclient - https://repo.lunarclient.dev - - - - - - com.lunarclient - apollo-protos - 1.0-SNAPSHOT - - - ``` - - - ```groovy filename="build.gradle" - repositories { - maven { - name = 'lunarclient' - url = 'https://repo.lunarclient.dev' - } - } - - dependencies { - api 'com.lunarclient:apollo-protos:1.0-SNAPSHOT' - } - ``` - - - ```kotlin filename="build.gradle.kts" - repositories { - maven { - name = "lunarclient" - url = uri("https://repo.lunarclient.dev") - } - } - - dependencies { - api("com.lunarclient:apollo-protos:1.0-SNAPSHOT") - } - ``` - - - -## Overview - -In order to start sending module-specific Apollo messages, the used module must be enabled for the player. -This is recommended to happen when the player sends the `REGISTER` packet to the server with the channel `lunar:apollo`. - -Available fields for each message, including their types, are available on the Buf Schema Registry at https://buf.build/lunarclient/apollo. - -## Detect if a player is using Lunar Client - -```java -public ApolloPlayerProtoListener(ApolloExamplePlugin plugin) { - Bukkit.getServer().getMessenger().registerOutgoingPluginChannel(plugin, "lunar:apollo"); - Bukkit.getPluginManager().registerEvents(this, plugin); -} - -@EventHandler -private void onRegisterChannel(PlayerRegisterChannelEvent event) { - if (!event.getChannel().equalsIgnoreCase("lunar:apollo")) { - return; - } - - player.sendMessage("You are using LunarClient!"); -} -``` - -## Sending packets - -Here are some util methods that will be used throughout shown examples, such as for sending or broadcasting packets, and a method that constructs the enable module messages. - -```java -public static void sendPacket(Player player, GeneratedMessageV3 message) { - byte[] bytes = Any.pack(message).toByteArray(); - player.sendPluginMessage(ApolloExamplePlugin.getPlugin(), "lunar:apollo", bytes); -} - -public static void broadcastPacket(GeneratedMessageV3 message) { - byte[] bytes = Any.pack(message).toByteArray(); - - Bukkit.getOnlinePlayers().forEach(player -> - player.sendPluginMessage(ApolloExamplePlugin.getPlugin(), "lunar:apollo", bytes)); -} - -public static void enableModules(Player player, List modules, Table properties) { - List settings = modules.stream() - .map(module -> createModuleMessage(module, properties.row(module))) - .collect(Collectors.toList()); - - OverrideConfigurableSettingsMessage message = OverrideConfigurableSettingsMessage - .newBuilder() - .addAllConfigurableSettings(settings) - .build(); - - ProtobufPacketUtil.sendPacket(player, message); -} - -public static ConfigurableSettings createModuleMessage(String module, Map properties) { - ConfigurableSettings.Builder moduleBuilder = ConfigurableSettings.newBuilder() - .setApolloModule(module) - .setEnable(true); - - if (properties != null) { - moduleBuilder.putAllProperties(properties); - } - - return moduleBuilder.build(); -} -``` - -## Enabling Apollo modules with their properties - -First we create a list of modules that we want to enable - -```java -private static final List APOLLO_MODULES = Arrays.asList("limb", "beam", "border", "chat", "colored_fire", "combat", "cooldown", - "entity", "glow", "hologram", "mod_setting", "nametag", "nick_hider", "notification", "packet_enrichment", "rich_presence", - "server_rule", "staff_mod", "stopwatch", "team", "title", "tnt_countdown", "transfer", "vignette", "waypoint" -); -``` - -Then we create a Table of properties for each module, these are the options that the client needs to be notified about. - -```java -private static final Table CONFIG_MODULE_PROPERTIES = HashBasedTable.create(); - -static { - CONFIG_MODULE_PROPERTIES.put("combat", "disable-miss-penalty", Value.newBuilder().setBoolValue(false).build()); - CONFIG_MODULE_PROPERTIES.put("server_rule", "competitive-game", Value.newBuilder().setBoolValue(false).build()); - CONFIG_MODULE_PROPERTIES.put("server_rule", "competitive-commands", Value.newBuilder().setListValue( - ListValue.newBuilder().addAllValues(Arrays.asList( - Value.newBuilder().setStringValue("/server").build(), - Value.newBuilder().setStringValue("/servers").build(), - Value.newBuilder().setStringValue("/hub").build())) - .build() - ).build()); - CONFIG_MODULE_PROPERTIES.put("server_rule", "disable-shaders", Value.newBuilder().setBoolValue(false).build()); - CONFIG_MODULE_PROPERTIES.put("server_rule", "disable-chunk-reloading", Value.newBuilder().setBoolValue(false).build()); - CONFIG_MODULE_PROPERTIES.put("server_rule", "disable-broadcasting", Value.newBuilder().setBoolValue(false).build()); - CONFIG_MODULE_PROPERTIES.put("server_rule", "anti-portal-traps", Value.newBuilder().setBoolValue(true).build()); - CONFIG_MODULE_PROPERTIES.put("server_rule", "override-brightness", Value.newBuilder().setBoolValue(false).build()); - CONFIG_MODULE_PROPERTIES.put("server_rule", "brightness", Value.newBuilder().setNumberValue(50).build()); - CONFIG_MODULE_PROPERTIES.put("server_rule", "override-nametag-render-distance", Value.newBuilder().setBoolValue(false).build()); - CONFIG_MODULE_PROPERTIES.put("server_rule", "nametag-render-distance", Value.newBuilder().setNumberValue(64).build()); - CONFIG_MODULE_PROPERTIES.put("server_rule", "override-max-chat-length", Value.newBuilder().setBoolValue(false).build()); - CONFIG_MODULE_PROPERTIES.put("server_rule", "max-chat-length", Value.newBuilder().setNumberValue(256).build()); - CONFIG_MODULE_PROPERTIES.put("tnt_countdown", "tnt-ticks", Value.newBuilder().setNumberValue(80).build()); - CONFIG_MODULE_PROPERTIES.put("waypoint", "server-handles-waypoints", Value.newBuilder().setBoolValue(false).build()); -} -``` - -Finally, send the enable packets if the player is using Lunar Client - -```java -@EventHandler -private void onRegisterChannel(PlayerRegisterChannelEvent event) { - if (!event.getChannel().equalsIgnoreCase("lunar:apollo")) { - return; - } - - ProtobufPacketUtil.enableModules(player, APOLLO_MODULES, CONFIG_MODULE_PROPERTIES); -} -``` - -## Apollo Module Example - -In this example it will be demonstrated how to display, remove & reset Waypoints. Examples for other modules can be found under the Developers -> Modules tab. - -```java -public void displayWaypointExample(Player viewer) { - DisplayWaypointMessage message = DisplayWaypointMessage.newBuilder() - .setName("KoTH") - .setLocation(ProtobufUtil.createBlockLocationProto(new Location(viewer.getWorld(), 500, 100, 500))) - .setColor(ProtobufUtil.createColorProto(Color.ORANGE)) - .setPreventRemoval(false) - .setHidden(false) - .build(); - - ProtobufPacketUtil.sendPacket(viewer, message); -} - -public void removeWaypointExample(Player viewer) { - RemoveWaypointMessage message = RemoveWaypointMessage.newBuilder() - .setName("KoTH") - .build(); - - ProtobufPacketUtil.sendPacket(viewer, message); -} - -public void resetWaypointsExample(Player viewer) { - ResetWaypointsMessage message = ResetWaypointsMessage.getDefaultInstance(); - ProtobufPacketUtil.sendPacket(viewer, message); -} -``` - -### Useful Links - -🔗 [Protobuf Packet Util](https://github.com/LunarClient/Apollo/blob/master/bukkit-example/src/main/java/com/lunarclient/apollo/example/proto/ProtobufPacketUtil.java) - Used for sending packets & creating the module messages
-🔗 [Protobuf Util](https://github.com/LunarClient/Apollo/blob/master/bukkit-example/src/main/java/com/lunarclient/apollo/example/proto/ProtobufUtil.java) - Used for creating messages used by most modules
-🔗 [Adventure Util](https://github.com/LunarClient/Apollo/blob/master/bukkit-example/src/main/java/com/lunarclient/apollo/example/proto/AdventureUtil.java) - Used for converting Adventure Components to JSON
-🔗 [Module Examples]((https://github.com/LunarClient/Apollo/tree/master/bukkit-example/src/main/java/com/lunarclient/apollo/example/proto)) - Code examples for all Apollo modules
-🔗 [Receive Apollo Packet Example]((https://github.com/LunarClient/Apollo/tree/master/bukkit-example/src/main/java/com/lunarclient/apollo/example/proto/listeners/ApolloPacketReceiveProtoListener.java)) - Used to handle packets sent from the client such as the `PlayerHandshakeMessage` & `PacketEnrichment Module` packets
-🔗 [Roundtrip Apollo Packet Example]((https://github.com/LunarClient/Apollo/tree/master/bukkit-example/src/main/java/com/lunarclient/apollo/example/proto/listeners/ApolloPacketReceiveProtoListener.java)) - Used to handle round-trip packets such as the ones sent by the `Transfer Module` - -
- - - -### Method 2: Manual JSON Object Construction - -This method involves manually constructing JSON objects using a JSON library (e.g., Gson) and then converting these objects into byte arrays for transmission. It allows for dynamic and programmatic construction of JSON objects, offering flexibility in modifying the JSON structure. Available fields for each message, including their types, are available on the Buf Schema Registry at https://buf.build/lunarclient/apollo. -While constructing messages, note that the `@type` field isn't required if the message is being sent within a message. - - - Note that this method uses a different plugin channel for sending packets, - which is `apollo:json`, while still using the `lunar:apollo` for player detection. - - -**Steps** - - -