Skip to content

Commit

Permalink
richpresence, serverrule, staffmod, stopwatch, title, tntcountdown, t…
Browse files Browse the repository at this point in the history
…ranfser, vignette & waypoint markdown examples
  • Loading branch information
ItsNature committed Sep 18, 2024
1 parent 895be25 commit 1f35ca3
Show file tree
Hide file tree
Showing 16 changed files with 1,152 additions and 150 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,38 +40,40 @@ public class TitleApiExample extends TitleExample {

private final TitleModule titleModule = Apollo.getModuleManager().getModule(TitleModule.class);

private final Title helloTitle = Title.builder()
.type(TitleType.TITLE)
.message(Component.text()
.content("Hello, player!")
.color(NamedTextColor.GREEN)
.decorate(TextDecoration.BOLD)
.build())
.scale(1.0f)
.displayTime(Duration.ofMillis(1500L))
.fadeInTime(Duration.ofMillis(250))
.fadeOutTime(Duration.ofMillis(300))
.build();

private final Title interpolatedTitle = Title.builder()
.type(TitleType.TITLE)
.message(Component.text()
.content("This title expands!")
.color(NamedTextColor.GREEN)
.decorate(TextDecoration.BOLD)
.build())
.scale(0.1f)
.interpolationScale(1.0f)
.interpolationRate(0.01f)
.displayTime(Duration.ofMillis(5000L))
.fadeInTime(Duration.ofMillis(250))
.fadeOutTime(Duration.ofMillis(300))
.build();

@Override
public void displayTitleExample(Player viewer) {
Optional<ApolloPlayer> apolloPlayerOpt = Apollo.getPlayerManager().getPlayer(viewer.getUniqueId());
apolloPlayerOpt.ifPresent(apolloPlayer -> this.titleModule.displayTitle(apolloPlayer, this.helloTitle));
apolloPlayerOpt.ifPresent(apolloPlayer -> this.titleModule.displayTitle(apolloPlayer, Title.builder()
.type(TitleType.TITLE)
.message(Component.text()
.content("Hello, player!")
.color(NamedTextColor.GREEN)
.decorate(TextDecoration.BOLD)
.build())
.scale(1.0f)
.displayTime(Duration.ofMillis(1500L))
.fadeInTime(Duration.ofMillis(250))
.fadeOutTime(Duration.ofMillis(300))
.build()));
}

@Override
public void displayTitleInterpolatedExample(Player viewer) {
Optional<ApolloPlayer> apolloPlayerOpt = Apollo.getPlayerManager().getPlayer(viewer.getUniqueId());
apolloPlayerOpt.ifPresent(apolloPlayer -> this.titleModule.displayTitle(apolloPlayer, Title.builder()
.type(TitleType.TITLE)
.message(Component.text()
.content("This title expands!")
.color(NamedTextColor.GREEN)
.decorate(TextDecoration.BOLD)
.build())
.scale(0.1f)
.interpolationScale(1.0f)
.interpolationRate(0.01f)
.displayTime(Duration.ofMillis(5000L))
.fadeInTime(Duration.ofMillis(250))
.fadeOutTime(Duration.ofMillis(300))
.build()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void overrideTntCountdownExample(Player viewer) {

@Override
public void clearTntCountdownOptionExample() {
this.tntCountdownModule.getOptions().remove(TntCountdownModule.TNT_TICKS, 160);
this.tntCountdownModule.getOptions().remove(TntCountdownModule.TNT_TICKS, 80);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
Player player = (Player) sender;

if (args.length != 1) {
player.sendMessage("Usage: /title <display|reset>");
player.sendMessage("Usage: /title <display|displayinterpolation|reset>");
return true;
}

Expand All @@ -56,14 +56,20 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command
break;
}

case "displayinterpolation": {
titleExample.displayTitleInterpolatedExample(player);
player.sendMessage("Displaying interpolated title...");
break;
}

case "reset": {
titleExample.resetTitlesExample(player);
player.sendMessage("Resetting titles....");
break;
}

default: {
player.sendMessage("Usage: /title <display|reset>");
player.sendMessage("Usage: /title <display|displayinterpolation|reset>");
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public abstract class TitleExample extends ApolloExample {

public abstract void displayTitleExample(Player viewer);

public abstract void displayTitleInterpolatedExample(Player viewer);

public abstract void resetTitlesExample(Player viewer);

}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,26 @@ public void displayTitleExample(Player viewer) {
.decorate(TextDecoration.BOLD)
.build()
));
message.addProperty("scale", 1.0f);
message.addProperty("fade_in_time", JsonUtil.createDurationObject(Duration.ofMillis(1500)));
message.addProperty("display_time", JsonUtil.createDurationObject(Duration.ofMillis(250)));
message.addProperty("fade_out_time", JsonUtil.createDurationObject(Duration.ofMillis(300)));

JsonPacketUtil.sendPacket(viewer, message);
}

@Override
public void displayTitleInterpolatedExample(Player viewer) {
JsonObject message = new JsonObject();
message.addProperty("@type", "type.googleapis.com/lunarclient.apollo.title.v1.DisplayTitleMessage");
message.addProperty("title_type", 1); // 1 = title, 2 = subtitle
message.addProperty("adventure_json_message", AdventureUtil.toJson(
Component.text()
.content("This title expands!")
.color(NamedTextColor.GREEN)
.decorate(TextDecoration.BOLD)
.build()
));
message.addProperty("scale", 0.1f);
message.addProperty("interpolation_scale", 1.0f);
message.addProperty("interpolation_rate", 0.01f);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,41 +38,46 @@

public class TitleProtoExample extends TitleJsonExample {

private final DisplayTitleMessage helloTitle = DisplayTitleMessage.newBuilder()
.setTitleType(TitleType.TITLE_TYPE_TITLE)
.setAdventureJsonMessage(AdventureUtil.toJson(
Component.text()
.content("Hello, player!")
.color(NamedTextColor.GREEN)
.decorate(TextDecoration.BOLD)
.build()
))
.setScale(1.0f)
.setFadeInTime(ProtobufUtil.createDurationProto(Duration.ofMillis(1500)))
.setDisplayTime(ProtobufUtil.createDurationProto(Duration.ofMillis(250)))
.setFadeOutTime(ProtobufUtil.createDurationProto(Duration.ofMillis(300)))
.build();
@Override
public void displayTitleExample(Player viewer) {
DisplayTitleMessage message = DisplayTitleMessage.newBuilder()
.setTitleType(TitleType.TITLE_TYPE_TITLE)
.setAdventureJsonMessage(AdventureUtil.toJson(
Component.text()
.content("Hello, player!")
.color(NamedTextColor.GREEN)
.decorate(TextDecoration.BOLD)
.build()
))
.setScale(1.0f)
.setFadeInTime(ProtobufUtil.createDurationProto(Duration.ofMillis(1500)))
.setDisplayTime(ProtobufUtil.createDurationProto(Duration.ofMillis(250)))
.setFadeOutTime(ProtobufUtil.createDurationProto(Duration.ofMillis(300)))
.build();

private final DisplayTitleMessage interpolatedTitle = DisplayTitleMessage.newBuilder()
.setTitleType(TitleType.TITLE_TYPE_TITLE)
.setAdventureJsonMessage(AdventureUtil.toJson(
Component.text()
.content("This title expands!")
.color(NamedTextColor.GREEN)
.decorate(TextDecoration.BOLD)
.build()
))
.setScale(0.1f)
.setInterpolationScale(1.0f)
.setInterpolationRate(0.01f)
.setFadeInTime(ProtobufUtil.createDurationProto(Duration.ofMillis(5000)))
.setDisplayTime(ProtobufUtil.createDurationProto(Duration.ofMillis(250)))
.setFadeOutTime(ProtobufUtil.createDurationProto(Duration.ofMillis(300)))
.build();
ProtobufPacketUtil.sendPacket(viewer, message);
}

@Override
public void displayTitleExample(Player viewer) {
ProtobufPacketUtil.sendPacket(viewer, this.helloTitle);
public void displayTitleInterpolatedExample(Player viewer) {
DisplayTitleMessage message = DisplayTitleMessage.newBuilder()
.setTitleType(TitleType.TITLE_TYPE_TITLE)
.setAdventureJsonMessage(AdventureUtil.toJson(
Component.text()
.content("This title expands!")
.color(NamedTextColor.GREEN)
.decorate(TextDecoration.BOLD)
.build()
))
.setScale(0.1f)
.setInterpolationScale(1.0f)
.setInterpolationRate(0.01f)
.setFadeInTime(ProtobufUtil.createDurationProto(Duration.ofMillis(5000)))
.setDisplayTime(ProtobufUtil.createDurationProto(Duration.ofMillis(250)))
.setFadeOutTime(ProtobufUtil.createDurationProto(Duration.ofMillis(300)))
.build();

ProtobufPacketUtil.sendPacket(viewer, message);
}

@Override
Expand Down
83 changes: 80 additions & 3 deletions docs/developers/modules/richpresence.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ The rich presence module allows you to interact with Discord and Lunar Client's
## Integration

### Sample Code
Explore each integration by cycling through each tab, to find the best fit for your requirements and needs.

<Tabs items={['Apollo API', 'apollo-protos library', 'Manual JSON Object Construction']}>

<Tab>

### Override Rich Presence

```java
public void overrideServerRichPresenceExample(Player viewer) {
Expand All @@ -50,6 +57,15 @@ public void overrideServerRichPresenceExample(Player viewer) {
}
```

### Reset Rich Presence

```java
public void resetServerRichPresenceExample(Player viewer) {
Optional<ApolloPlayer> apolloPlayerOpt = Apollo.getPlayerManager().getPlayer(viewer.getUniqueId());
apolloPlayerOpt.ifPresent(this.richPresenceModule::resetServerRichPresence);
}
```

### `ServerRichPresence` Options

`.gameName(String)` the name of the game the player is playing on.
Expand Down Expand Up @@ -100,11 +116,72 @@ public void overrideServerRichPresenceExample(Player viewer) {
.teamMaxSize(4)
```

### Resetting the server rich presence for a player
</Tab>

<Tab>

### Override Rich Presence

```java
public void overrideServerRichPresenceExample(Player viewer) {
OverrideServerRichPresenceMessage message = OverrideServerRichPresenceMessage.newBuilder()
.setGameName("BedWars")
.setGameVariantName("Solo")
.setGameState("In Game")
.setPlayerState("Playing")
.setMapName("Winter")
.setSubServer("BW02")
.setTeamCurrentSize(3)
.setTeamMaxSize(4)
.build();

ProtobufPacketUtil.sendPacket(viewer, message);
}
```

### Reset Rich Presence

```java
public void resetServerRichPresenceExample(Player viewer) {
Optional<ApolloPlayer> apolloPlayerOpt = Apollo.getPlayerManager().getPlayer(viewer.getUniqueId());
apolloPlayerOpt.ifPresent(this.richPresenceModule::resetServerRichPresence);
ResetServerRichPresenceMessage message = ResetServerRichPresenceMessage.getDefaultInstance();
ProtobufPacketUtil.sendPacket(viewer, message);
}
```

</Tab>

<Tab>

### Override Rich Presence

```java
public void overrideServerRichPresenceExample(Player viewer) {
JsonObject message = new JsonObject();
message.addProperty("@type", "type.googleapis.com/lunarclient.apollo.richpresence.v1.OverrideServerRichPresenceMessage");
message.addProperty("game_name", "BedWars");
message.addProperty("game_variant_name", "Solo");
message.addProperty("game_state", "In Game");
message.addProperty("player_state", "Playing");
message.addProperty("map_name", "Winter");
message.addProperty("sub_server", "BW02");
message.addProperty("team_current_size", 3);
message.addProperty("team_max_size", 4);

JsonPacketUtil.sendPacket(viewer, message);
}
```

### Reset Rich Presence

```java
public void resetServerRichPresenceExample(Player viewer) {
JsonObject message = new JsonObject();
message.addProperty("@type", "type.googleapis.com/lunarclient.apollo.richpresence.v1.ResetServerRichPresenceMessage");

JsonPacketUtil.sendPacket(viewer, message);
}
```

</Tab>

</Tabs>
Loading

1 comment on commit 1f35ca3

@LunarClientBot
Copy link
Collaborator

@LunarClientBot LunarClientBot commented on 1f35ca3 Sep 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📄 Documentation Deployment

Status:✅ Completed
Environment:preview
URL:https://e2b1f468.lunarclient-dev.pages.dev

Please sign in to comment.