Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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<Boolean> CLEAR_TITLE_ON_SERVER_SWITCH = Option.<Boolean>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}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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 <display|displayInterpolated|reset>");
player.sendMessage("Usage: /title <clearOnServerSwitch> <value>");
return true;
}

TitleExample titleExample = ApolloExamplePlugin.getInstance().getTitleExample();

switch (args[0].toLowerCase()) {
case "display": {
titleExample.displayTitleExample(player);
Expand All @@ -70,6 +78,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command

default: {
player.sendMessage("Usage: /title <display|displayInterpolated|reset>");
player.sendMessage("Usage: /title <clearOnServerSwitch> <value>");
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,6 @@ public abstract class TitleExample extends ApolloModuleExample {

public abstract void resetTitlesExample(Player viewer);

public abstract void setClearTitleOnServerSwitch(boolean value);

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -86,4 +88,13 @@ public void resetTitlesExample(Player viewer) {
JsonPacketUtil.sendPacket(viewer, message);
}

@Override
public void setClearTitleOnServerSwitch(boolean value) {
Map<String, Object> properties = new HashMap<>();
properties.put("clear-title-on-server-switch", value);

JsonObject message = JsonUtil.createEnableModuleObjectWithType("title", properties);
JsonPacketUtil.broadcastPacket(message);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -86,4 +90,13 @@ public void resetTitlesExample(Player viewer) {
ProtobufPacketUtil.sendPacket(viewer, message);
}

@Override
public void setClearTitleOnServerSwitch(boolean value) {
Map<String, Value> properties = new HashMap<>();
properties.put("clear-title-on-server-switch", Value.newBuilder().setBoolValue(value).build());

ConfigurableSettings settings = ProtobufPacketUtil.createModuleMessage("title", properties);
ProtobufPacketUtil.broadcastPacket(settings);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down
1 change: 1 addition & 0 deletions docs/developers/lightweight/json/packet-util.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
```
Expand Down
1 change: 1 addition & 0 deletions docs/developers/lightweight/protobuf/packet-util.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
```
Expand Down
40 changes: 40 additions & 0 deletions docs/developers/modules/title.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -190,6 +198,18 @@ public void resetTitlesExample(Player viewer) {
}
```

**Clear Title On Server Switch**

```java
public void setClearTitleOnServerSwitch(boolean value) {
Map<String, Value> properties = new HashMap<>();
properties.put("clear-title-on-server-switch", Value.newBuilder().setBoolValue(value).build());

ConfigurableSettings settings = ProtobufPacketUtil.createModuleMessage("title", properties);
ProtobufPacketUtil.broadcastPacket(settings);
}
```

</Tab>

<Tab>
Expand Down Expand Up @@ -253,6 +273,26 @@ public void resetTitlesExample(Player viewer) {
}
```

**Clear Title On Server Switch**

```java
public void setClearTitleOnServerSwitch(boolean value) {
Map<String, Object> properties = new HashMap<>();
properties.put("clear-title-on-server-switch", value);

JsonObject message = JsonUtil.createEnableModuleObjectWithType("title", properties);
JsonPacketUtil.broadcastPacket(message);
}
```

</Tab>

</Tabs>

## Available options

- __`CLEAR_TITLE_ON_SERVER_SWITCH`__
- Determines whether the players displayed title should clear when switching servers.
- Values
- Type: `Boolean`
- Default: `false`