From 8d942e0cf670def71f34ff7bd8bf4bb1f3904062 Mon Sep 17 00:00:00 2001 From: ItsNature Date: Mon, 11 Aug 2025 19:29:07 +0200 Subject: [PATCH 1/4] Add `CLEAR_TITLE_ON_SERVER_SWITCH` option to the Title Module --- .../apollo/module/title/TitleModule.java | 24 +++++++++++++++++++ .../example/json/util/JsonPacketUtil.java | 1 + .../proto/util/ProtobufPacketUtil.java | 1 + .../lightweight/json/packet-util.mdx | 1 + .../lightweight/protobuf/packet-util.mdx | 1 + docs/developers/modules/title.mdx | 8 +++++++ 6 files changed, 36 insertions(+) diff --git a/api/src/main/java/com/lunarclient/apollo/module/title/TitleModule.java b/api/src/main/java/com/lunarclient/apollo/module/title/TitleModule.java index 792ddc98..f75cddd1 100644 --- a/api/src/main/java/com/lunarclient/apollo/module/title/TitleModule.java +++ b/api/src/main/java/com/lunarclient/apollo/module/title/TitleModule.java @@ -25,7 +25,10 @@ import com.lunarclient.apollo.module.ApolloModule; import com.lunarclient.apollo.module.ModuleDefinition; +import com.lunarclient.apollo.option.Option; +import com.lunarclient.apollo.option.SimpleOption; import com.lunarclient.apollo.recipients.Recipients; +import io.leangen.geantyref.TypeToken; import org.jetbrains.annotations.ApiStatus; /** @@ -40,6 +43,27 @@ @ModuleDefinition(id = "title", name = "Title") public abstract class TitleModule extends ApolloModule { + /** + * Determines whether the players displayed title should clear when switching servers. + * + * @since 1.1.9 + */ + public static final SimpleOption CLEAR_TITLE_ON_SERVER_SWITCH = Option.builder() + .comment("Set to 'true' to clear the shown title when changing servers, otherwise 'false'.") + .node("clear-title-on-server-switch").type(TypeToken.get(Boolean.class)) + .defaultValue(false).notifyClient().build(); + + TitleModule() { + this.registerOptions( + TitleModule.CLEAR_TITLE_ON_SERVER_SWITCH + ); + } + + @Override + public boolean isClientNotify() { + return true; + } + /** * Sends the {@link Title} to the {@link Recipients}. * diff --git a/bukkit-example-json/src/main/java/com/lunarclient/apollo/example/json/util/JsonPacketUtil.java b/bukkit-example-json/src/main/java/com/lunarclient/apollo/example/json/util/JsonPacketUtil.java index 1ac6bd83..57b94561 100644 --- a/bukkit-example-json/src/main/java/com/lunarclient/apollo/example/json/util/JsonPacketUtil.java +++ b/bukkit-example-json/src/main/java/com/lunarclient/apollo/example/json/util/JsonPacketUtil.java @@ -65,6 +65,7 @@ public final class JsonPacketUtil { CONFIG_MODULE_PROPERTIES.put("server_rule", "override-max-chat-length", false); CONFIG_MODULE_PROPERTIES.put("server_rule", "max-chat-length", 256); CONFIG_MODULE_PROPERTIES.put("tnt_countdown", "tnt-ticks", 80); + CONFIG_MODULE_PROPERTIES.put("title", "clear-title-on-server-switch", false); CONFIG_MODULE_PROPERTIES.put("waypoint", "server-handles-waypoints", false); } diff --git a/bukkit-example-proto/src/main/java/com/lunarclient/apollo/example/proto/util/ProtobufPacketUtil.java b/bukkit-example-proto/src/main/java/com/lunarclient/apollo/example/proto/util/ProtobufPacketUtil.java index 97590deb..423d6214 100644 --- a/bukkit-example-proto/src/main/java/com/lunarclient/apollo/example/proto/util/ProtobufPacketUtil.java +++ b/bukkit-example-proto/src/main/java/com/lunarclient/apollo/example/proto/util/ProtobufPacketUtil.java @@ -72,6 +72,7 @@ public final class ProtobufPacketUtil { 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("title", "clear-title-on-server-switch", Value.newBuilder().setBoolValue(false).build()); CONFIG_MODULE_PROPERTIES.put("waypoint", "server-handles-waypoints", Value.newBuilder().setBoolValue(false).build()); } diff --git a/docs/developers/lightweight/json/packet-util.mdx b/docs/developers/lightweight/json/packet-util.mdx index 0a740d1e..b7263a48 100644 --- a/docs/developers/lightweight/json/packet-util.mdx +++ b/docs/developers/lightweight/json/packet-util.mdx @@ -47,6 +47,7 @@ static { CONFIG_MODULE_PROPERTIES.put("server_rule", "override-max-chat-length", false); CONFIG_MODULE_PROPERTIES.put("server_rule", "max-chat-length", 256); CONFIG_MODULE_PROPERTIES.put("tnt_countdown", "tnt-ticks", 80); + CONFIG_MODULE_PROPERTIES.put("title", "clear-title-on-server-switch", false); CONFIG_MODULE_PROPERTIES.put("waypoint", "server-handles-waypoints", false); } ``` diff --git a/docs/developers/lightweight/protobuf/packet-util.mdx b/docs/developers/lightweight/protobuf/packet-util.mdx index 3ea0b429..b74f9b56 100644 --- a/docs/developers/lightweight/protobuf/packet-util.mdx +++ b/docs/developers/lightweight/protobuf/packet-util.mdx @@ -51,6 +51,7 @@ static { 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("title", "clear-title-on-server-switch", Value.newBuilder().setBoolValue(false).build()); CONFIG_MODULE_PROPERTIES.put("waypoint", "server-handles-waypoints", Value.newBuilder().setBoolValue(false).build()); } ``` diff --git a/docs/developers/modules/title.mdx b/docs/developers/modules/title.mdx index 78649ac8..106406cb 100644 --- a/docs/developers/modules/title.mdx +++ b/docs/developers/modules/title.mdx @@ -256,3 +256,11 @@ public void resetTitlesExample(Player viewer) { + +## Available options + +- __`CLEAR_TITLE_ON_SERVER_SWITCH`__ + - Determines whether the players displayed title should clear when switching servers. + - Values + - Type: `Boolean` + - Default: `false` From 3b90d554153c1643290077a863ef7b48d10c0705 Mon Sep 17 00:00:00 2001 From: ItsNature Date: Mon, 11 Aug 2025 19:41:11 +0200 Subject: [PATCH 2/4] Add example docs --- .../example/api/module/TitleApiExample.java | 5 +++ .../example/module/impl/TitleExample.java | 2 ++ .../example/json/module/TitleJsonExample.java | 11 +++++++ .../proto/module/TitleProtoExample.java | 13 ++++++++ docs/developers/modules/title.mdx | 32 +++++++++++++++++++ 5 files changed, 63 insertions(+) diff --git a/bukkit-example-api/src/main/java/com/lunarclient/apollo/example/api/module/TitleApiExample.java b/bukkit-example-api/src/main/java/com/lunarclient/apollo/example/api/module/TitleApiExample.java index 78e884c0..e3843c8f 100644 --- a/bukkit-example-api/src/main/java/com/lunarclient/apollo/example/api/module/TitleApiExample.java +++ b/bukkit-example-api/src/main/java/com/lunarclient/apollo/example/api/module/TitleApiExample.java @@ -82,4 +82,9 @@ public void resetTitlesExample(Player viewer) { apolloPlayerOpt.ifPresent(this.titleModule::resetTitles); } + @Override + public void setClearTitleOnServerSwitch(boolean value) { + this.titleModule.getOptions().set(TitleModule.CLEAR_TITLE_ON_SERVER_SWITCH, value); + } + } diff --git a/bukkit-example-common/src/main/java/com/lunarclient/apollo/example/module/impl/TitleExample.java b/bukkit-example-common/src/main/java/com/lunarclient/apollo/example/module/impl/TitleExample.java index 48fdc134..87075107 100644 --- a/bukkit-example-common/src/main/java/com/lunarclient/apollo/example/module/impl/TitleExample.java +++ b/bukkit-example-common/src/main/java/com/lunarclient/apollo/example/module/impl/TitleExample.java @@ -34,4 +34,6 @@ public abstract class TitleExample extends ApolloModuleExample { public abstract void resetTitlesExample(Player viewer); + public abstract void setClearTitleOnServerSwitch(boolean value); + } diff --git a/bukkit-example-json/src/main/java/com/lunarclient/apollo/example/json/module/TitleJsonExample.java b/bukkit-example-json/src/main/java/com/lunarclient/apollo/example/json/module/TitleJsonExample.java index 31d4de8e..a7d138d4 100644 --- a/bukkit-example-json/src/main/java/com/lunarclient/apollo/example/json/module/TitleJsonExample.java +++ b/bukkit-example-json/src/main/java/com/lunarclient/apollo/example/json/module/TitleJsonExample.java @@ -29,6 +29,8 @@ import com.lunarclient.apollo.example.json.util.JsonUtil; import com.lunarclient.apollo.example.module.impl.TitleExample; import java.time.Duration; +import java.util.HashMap; +import java.util.Map; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.TextDecoration; @@ -86,4 +88,13 @@ public void resetTitlesExample(Player viewer) { JsonPacketUtil.sendPacket(viewer, message); } + @Override + public void setClearTitleOnServerSwitch(boolean value) { + Map properties = new HashMap<>(); + properties.put("clear-title-on-server-switch", value); + + JsonObject message = JsonUtil.createEnableModuleObjectWithType("title", properties); + JsonPacketUtil.broadcastPacket(message); + } + } diff --git a/bukkit-example-proto/src/main/java/com/lunarclient/apollo/example/proto/module/TitleProtoExample.java b/bukkit-example-proto/src/main/java/com/lunarclient/apollo/example/proto/module/TitleProtoExample.java index 786e2c71..6488314d 100644 --- a/bukkit-example-proto/src/main/java/com/lunarclient/apollo/example/proto/module/TitleProtoExample.java +++ b/bukkit-example-proto/src/main/java/com/lunarclient/apollo/example/proto/module/TitleProtoExample.java @@ -23,6 +23,8 @@ */ package com.lunarclient.apollo.example.proto.module; +import com.google.protobuf.Value; +import com.lunarclient.apollo.configurable.v1.ConfigurableSettings; import com.lunarclient.apollo.example.module.impl.TitleExample; import com.lunarclient.apollo.example.proto.util.AdventureUtil; import com.lunarclient.apollo.example.proto.util.ProtobufPacketUtil; @@ -31,6 +33,8 @@ import com.lunarclient.apollo.title.v1.ResetTitlesMessage; import com.lunarclient.apollo.title.v1.TitleType; import java.time.Duration; +import java.util.HashMap; +import java.util.Map; import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.TextDecoration; @@ -86,4 +90,13 @@ public void resetTitlesExample(Player viewer) { ProtobufPacketUtil.sendPacket(viewer, message); } + @Override + public void setClearTitleOnServerSwitch(boolean value) { + Map properties = new HashMap<>(); + properties.put("clear-title-on-server-switch", Value.newBuilder().setBoolValue(value).build()); + + ConfigurableSettings settings = ProtobufPacketUtil.createModuleMessage("title", properties); + ProtobufPacketUtil.broadcastPacket(settings); + } + } diff --git a/docs/developers/modules/title.mdx b/docs/developers/modules/title.mdx index 106406cb..4a698c89 100644 --- a/docs/developers/modules/title.mdx +++ b/docs/developers/modules/title.mdx @@ -70,6 +70,14 @@ public void resetTitlesExample(Player viewer) { } ``` +### Clear Title On Server Switch + +```java +public void setClearTitleOnServerSwitch(boolean value) { + this.titleModule.getOptions().set(TitleModule.CLEAR_TITLE_ON_SERVER_SWITCH, value); +} +``` + #### `Title` Options `.type(TitleType)` is the type of title you want to display. See the [TitleType](#titletype-types) types section for more. @@ -190,6 +198,18 @@ public void resetTitlesExample(Player viewer) { } ``` +### Clear Title On Server Switch + +```java +public void setClearTitleOnServerSwitch(boolean value) { + Map properties = new HashMap<>(); + properties.put("clear-title-on-server-switch", Value.newBuilder().setBoolValue(value).build()); + + ConfigurableSettings settings = ProtobufPacketUtil.createModuleMessage("title", properties); + ProtobufPacketUtil.broadcastPacket(settings); +} +``` + @@ -253,6 +273,18 @@ public void resetTitlesExample(Player viewer) { } ``` +### Clear Title On Server Switch + +```java +public void setClearTitleOnServerSwitch(boolean value) { + Map properties = new HashMap<>(); + properties.put("clear-title-on-server-switch", value); + + JsonObject message = JsonUtil.createEnableModuleObjectWithType("title", properties); + JsonPacketUtil.broadcastPacket(message); +} +``` + From ce5d4ce55449d2415e9407d54e8658a58e9ac9a3 Mon Sep 17 00:00:00 2001 From: ItsNature Date: Mon, 11 Aug 2025 22:22:10 +0200 Subject: [PATCH 3/4] Add `clearOnServerSwitch` parameter to the Title example command --- .../apollo/example/command/TitleCommand.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/bukkit-example-common/src/main/java/com/lunarclient/apollo/example/command/TitleCommand.java b/bukkit-example-common/src/main/java/com/lunarclient/apollo/example/command/TitleCommand.java index fa6d2423..cf7ad4cf 100644 --- a/bukkit-example-common/src/main/java/com/lunarclient/apollo/example/command/TitleCommand.java +++ b/bukkit-example-common/src/main/java/com/lunarclient/apollo/example/command/TitleCommand.java @@ -41,14 +41,22 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command } Player player = (Player) sender; + TitleExample titleExample = ApolloExamplePlugin.getInstance().getTitleExample(); + + if (args.length == 2 && args[0].equalsIgnoreCase("clearOnServerSwitch")) { + boolean value = Boolean.parseBoolean(args[1]); + titleExample.setClearTitleOnServerSwitch(value); + + player.sendMessage("Clear title on server switch has been set to " + value); + return true; + } if (args.length != 1) { player.sendMessage("Usage: /title "); + player.sendMessage("Usage: /title "); return true; } - TitleExample titleExample = ApolloExamplePlugin.getInstance().getTitleExample(); - switch (args[0].toLowerCase()) { case "display": { titleExample.displayTitleExample(player); @@ -70,6 +78,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command default: { player.sendMessage("Usage: /title "); + player.sendMessage("Usage: /title "); break; } } From 2ef9233b5f5b26ac87b13ebae2a404a1a0f35290 Mon Sep 17 00:00:00 2001 From: ItsNature Date: Mon, 11 Aug 2025 22:28:47 +0200 Subject: [PATCH 4/4] Update format --- docs/developers/modules/title.mdx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/developers/modules/title.mdx b/docs/developers/modules/title.mdx index 4a698c89..f8b71cff 100644 --- a/docs/developers/modules/title.mdx +++ b/docs/developers/modules/title.mdx @@ -198,7 +198,7 @@ public void resetTitlesExample(Player viewer) { } ``` -### Clear Title On Server Switch +**Clear Title On Server Switch** ```java public void setClearTitleOnServerSwitch(boolean value) { @@ -273,7 +273,7 @@ public void resetTitlesExample(Player viewer) { } ``` -### Clear Title On Server Switch +**Clear Title On Server Switch** ```java public void setClearTitleOnServerSwitch(boolean value) {