Skip to content

Commit f75ec91

Browse files
authored
Title Module - Add a option to clear the title on server switch (#223)
* Add `CLEAR_TITLE_ON_SERVER_SWITCH` option to the Title Module * Add example docs * Add `clearOnServerSwitch` parameter to the Title example command * Update format
1 parent 78eb61a commit f75ec91

File tree

11 files changed

+110
-2
lines changed

11 files changed

+110
-2
lines changed

api/src/main/java/com/lunarclient/apollo/module/title/TitleModule.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@
2525

2626
import com.lunarclient.apollo.module.ApolloModule;
2727
import com.lunarclient.apollo.module.ModuleDefinition;
28+
import com.lunarclient.apollo.option.Option;
29+
import com.lunarclient.apollo.option.SimpleOption;
2830
import com.lunarclient.apollo.recipients.Recipients;
31+
import io.leangen.geantyref.TypeToken;
2932
import org.jetbrains.annotations.ApiStatus;
3033

3134
/**
@@ -40,6 +43,27 @@
4043
@ModuleDefinition(id = "title", name = "Title")
4144
public abstract class TitleModule extends ApolloModule {
4245

46+
/**
47+
* Determines whether the players displayed title should clear when switching servers.
48+
*
49+
* @since 1.1.9
50+
*/
51+
public static final SimpleOption<Boolean> CLEAR_TITLE_ON_SERVER_SWITCH = Option.<Boolean>builder()
52+
.comment("Set to 'true' to clear the shown title when changing servers, otherwise 'false'.")
53+
.node("clear-title-on-server-switch").type(TypeToken.get(Boolean.class))
54+
.defaultValue(false).notifyClient().build();
55+
56+
TitleModule() {
57+
this.registerOptions(
58+
TitleModule.CLEAR_TITLE_ON_SERVER_SWITCH
59+
);
60+
}
61+
62+
@Override
63+
public boolean isClientNotify() {
64+
return true;
65+
}
66+
4367
/**
4468
* Sends the {@link Title} to the {@link Recipients}.
4569
*

bukkit-example-api/src/main/java/com/lunarclient/apollo/example/api/module/TitleApiExample.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,9 @@ public void resetTitlesExample(Player viewer) {
8282
apolloPlayerOpt.ifPresent(this.titleModule::resetTitles);
8383
}
8484

85+
@Override
86+
public void setClearTitleOnServerSwitch(boolean value) {
87+
this.titleModule.getOptions().set(TitleModule.CLEAR_TITLE_ON_SERVER_SWITCH, value);
88+
}
89+
8590
}

bukkit-example-common/src/main/java/com/lunarclient/apollo/example/command/TitleCommand.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,22 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
4141
}
4242

4343
Player player = (Player) sender;
44+
TitleExample titleExample = ApolloExamplePlugin.getInstance().getTitleExample();
45+
46+
if (args.length == 2 && args[0].equalsIgnoreCase("clearOnServerSwitch")) {
47+
boolean value = Boolean.parseBoolean(args[1]);
48+
titleExample.setClearTitleOnServerSwitch(value);
49+
50+
player.sendMessage("Clear title on server switch has been set to " + value);
51+
return true;
52+
}
4453

4554
if (args.length != 1) {
4655
player.sendMessage("Usage: /title <display|displayInterpolated|reset>");
56+
player.sendMessage("Usage: /title <clearOnServerSwitch> <value>");
4757
return true;
4858
}
4959

50-
TitleExample titleExample = ApolloExamplePlugin.getInstance().getTitleExample();
51-
5260
switch (args[0].toLowerCase()) {
5361
case "display": {
5462
titleExample.displayTitleExample(player);
@@ -70,6 +78,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
7078

7179
default: {
7280
player.sendMessage("Usage: /title <display|displayInterpolated|reset>");
81+
player.sendMessage("Usage: /title <clearOnServerSwitch> <value>");
7382
break;
7483
}
7584
}

bukkit-example-common/src/main/java/com/lunarclient/apollo/example/module/impl/TitleExample.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,6 @@ public abstract class TitleExample extends ApolloModuleExample {
3434

3535
public abstract void resetTitlesExample(Player viewer);
3636

37+
public abstract void setClearTitleOnServerSwitch(boolean value);
38+
3739
}

bukkit-example-json/src/main/java/com/lunarclient/apollo/example/json/module/TitleJsonExample.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
import com.lunarclient.apollo.example.json.util.JsonUtil;
3030
import com.lunarclient.apollo.example.module.impl.TitleExample;
3131
import java.time.Duration;
32+
import java.util.HashMap;
33+
import java.util.Map;
3234
import net.kyori.adventure.text.Component;
3335
import net.kyori.adventure.text.format.NamedTextColor;
3436
import net.kyori.adventure.text.format.TextDecoration;
@@ -86,4 +88,13 @@ public void resetTitlesExample(Player viewer) {
8688
JsonPacketUtil.sendPacket(viewer, message);
8789
}
8890

91+
@Override
92+
public void setClearTitleOnServerSwitch(boolean value) {
93+
Map<String, Object> properties = new HashMap<>();
94+
properties.put("clear-title-on-server-switch", value);
95+
96+
JsonObject message = JsonUtil.createEnableModuleObjectWithType("title", properties);
97+
JsonPacketUtil.broadcastPacket(message);
98+
}
99+
89100
}

bukkit-example-json/src/main/java/com/lunarclient/apollo/example/json/util/JsonPacketUtil.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public final class JsonPacketUtil {
6565
CONFIG_MODULE_PROPERTIES.put("server_rule", "override-max-chat-length", false);
6666
CONFIG_MODULE_PROPERTIES.put("server_rule", "max-chat-length", 256);
6767
CONFIG_MODULE_PROPERTIES.put("tnt_countdown", "tnt-ticks", 80);
68+
CONFIG_MODULE_PROPERTIES.put("title", "clear-title-on-server-switch", false);
6869
CONFIG_MODULE_PROPERTIES.put("waypoint", "server-handles-waypoints", false);
6970
}
7071

bukkit-example-proto/src/main/java/com/lunarclient/apollo/example/proto/module/TitleProtoExample.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
*/
2424
package com.lunarclient.apollo.example.proto.module;
2525

26+
import com.google.protobuf.Value;
27+
import com.lunarclient.apollo.configurable.v1.ConfigurableSettings;
2628
import com.lunarclient.apollo.example.module.impl.TitleExample;
2729
import com.lunarclient.apollo.example.proto.util.AdventureUtil;
2830
import com.lunarclient.apollo.example.proto.util.ProtobufPacketUtil;
@@ -31,6 +33,8 @@
3133
import com.lunarclient.apollo.title.v1.ResetTitlesMessage;
3234
import com.lunarclient.apollo.title.v1.TitleType;
3335
import java.time.Duration;
36+
import java.util.HashMap;
37+
import java.util.Map;
3438
import net.kyori.adventure.text.Component;
3539
import net.kyori.adventure.text.format.NamedTextColor;
3640
import net.kyori.adventure.text.format.TextDecoration;
@@ -86,4 +90,13 @@ public void resetTitlesExample(Player viewer) {
8690
ProtobufPacketUtil.sendPacket(viewer, message);
8791
}
8892

93+
@Override
94+
public void setClearTitleOnServerSwitch(boolean value) {
95+
Map<String, Value> properties = new HashMap<>();
96+
properties.put("clear-title-on-server-switch", Value.newBuilder().setBoolValue(value).build());
97+
98+
ConfigurableSettings settings = ProtobufPacketUtil.createModuleMessage("title", properties);
99+
ProtobufPacketUtil.broadcastPacket(settings);
100+
}
101+
89102
}

bukkit-example-proto/src/main/java/com/lunarclient/apollo/example/proto/util/ProtobufPacketUtil.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ public final class ProtobufPacketUtil {
7272
CONFIG_MODULE_PROPERTIES.put("server_rule", "override-max-chat-length", Value.newBuilder().setBoolValue(false).build());
7373
CONFIG_MODULE_PROPERTIES.put("server_rule", "max-chat-length", Value.newBuilder().setNumberValue(256).build());
7474
CONFIG_MODULE_PROPERTIES.put("tnt_countdown", "tnt-ticks", Value.newBuilder().setNumberValue(80).build());
75+
CONFIG_MODULE_PROPERTIES.put("title", "clear-title-on-server-switch", Value.newBuilder().setBoolValue(false).build());
7576
CONFIG_MODULE_PROPERTIES.put("waypoint", "server-handles-waypoints", Value.newBuilder().setBoolValue(false).build());
7677
}
7778

docs/developers/lightweight/json/packet-util.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ static {
4747
CONFIG_MODULE_PROPERTIES.put("server_rule", "override-max-chat-length", false);
4848
CONFIG_MODULE_PROPERTIES.put("server_rule", "max-chat-length", 256);
4949
CONFIG_MODULE_PROPERTIES.put("tnt_countdown", "tnt-ticks", 80);
50+
CONFIG_MODULE_PROPERTIES.put("title", "clear-title-on-server-switch", false);
5051
CONFIG_MODULE_PROPERTIES.put("waypoint", "server-handles-waypoints", false);
5152
}
5253
```

docs/developers/lightweight/protobuf/packet-util.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ static {
5151
CONFIG_MODULE_PROPERTIES.put("server_rule", "override-max-chat-length", Value.newBuilder().setBoolValue(false).build());
5252
CONFIG_MODULE_PROPERTIES.put("server_rule", "max-chat-length", Value.newBuilder().setNumberValue(256).build());
5353
CONFIG_MODULE_PROPERTIES.put("tnt_countdown", "tnt-ticks", Value.newBuilder().setNumberValue(80).build());
54+
CONFIG_MODULE_PROPERTIES.put("title", "clear-title-on-server-switch", Value.newBuilder().setBoolValue(false).build());
5455
CONFIG_MODULE_PROPERTIES.put("waypoint", "server-handles-waypoints", Value.newBuilder().setBoolValue(false).build());
5556
}
5657
```

0 commit comments

Comments
 (0)