Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lightweight Documentation Fixes & Improvements #186

Merged
merged 3 commits into from
Dec 19, 2024
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 @@ -24,29 +24,46 @@
package com.lunarclient.apollo.example.api.examples;

import com.lunarclient.apollo.Apollo;
import com.lunarclient.apollo.example.ApolloExamplePlugin;
import com.lunarclient.apollo.example.common.modules.impl.ChatExample;
import com.lunarclient.apollo.module.chat.ChatModule;
import com.lunarclient.apollo.recipients.Recipients;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.scheduler.BukkitRunnable;

public class ChatApiExample extends ChatExample {

private final ChatModule chatModule = Apollo.getModuleManager().getModule(ChatModule.class);

private int countdown = 5;

@Override
public void displayLiveChatMessageExample() {
this.chatModule.displayLiveChatMessage(Recipients.ofEveryone(),
Component.text("Game starting in ", NamedTextColor.GREEN)
.append(Component.text(this.countdown, NamedTextColor.BLUE)),
13
);

if (--this.countdown == 0) {
this.countdown = 5;
}
BukkitRunnable runnable = new BukkitRunnable() {

private int countdown = 5;

@Override
public void run() {
if (this.countdown > 0) {
ChatApiExample.this.chatModule.displayLiveChatMessage(Recipients.ofEveryone(),
Component.text("Game starting in ", NamedTextColor.GREEN)
.append(Component.text(this.countdown, NamedTextColor.BLUE)),
13
);

this.countdown--;
} else {
ChatApiExample.this.chatModule.displayLiveChatMessage(Recipients.ofEveryone(),
Component.text("Game started! ", NamedTextColor.GREEN),
13
);

this.cancel();
}
}
};

runnable.runTaskTimer(ApolloExamplePlugin.getPlugin(), 0L, 20L);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,48 @@
package com.lunarclient.apollo.example.json.examples;

import com.google.gson.JsonObject;
import com.lunarclient.apollo.example.ApolloExamplePlugin;
import com.lunarclient.apollo.example.common.modules.impl.ChatExample;
import com.lunarclient.apollo.example.json.AdventureUtil;
import com.lunarclient.apollo.example.json.JsonPacketUtil;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.scheduler.BukkitRunnable;

public class ChatJsonExample extends ChatExample {

private int countdown = 5;

@Override
public void displayLiveChatMessageExample() {
JsonObject message = new JsonObject();
message.addProperty("@type", "type.googleapis.com/lunarclient.apollo.chat.v1.DisplayLiveChatMessageMessage");
message.addProperty("message_id", 13);
message.addProperty("adventure_json_lines", AdventureUtil.toJson(
Component.text("Game starting in ", NamedTextColor.GREEN)
.append(Component.text(this.countdown, NamedTextColor.BLUE))
));
BukkitRunnable runnable = new BukkitRunnable() {

if (--this.countdown == 0) {
this.countdown = 5;
}
private int countdown = 5;

JsonPacketUtil.broadcastPacket(message);
@Override
public void run() {
JsonObject message = new JsonObject();
message.addProperty("@type", "type.googleapis.com/lunarclient.apollo.chat.v1.DisplayLiveChatMessageMessage");
message.addProperty("message_id", 13);

if (this.countdown > 0) {
message.addProperty("adventure_json_lines", AdventureUtil.toJson(
Component.text("Game starting in ", NamedTextColor.GREEN)
.append(Component.text(this.countdown, NamedTextColor.BLUE))
));

JsonPacketUtil.broadcastPacket(message);
this.countdown--;
} else {
message.addProperty("adventure_json_lines", AdventureUtil.toJson(
Component.text("Game started! ", NamedTextColor.GREEN)
));

JsonPacketUtil.broadcastPacket(message);
this.cancel();
}
}
};

runnable.runTaskTimer(ApolloExamplePlugin.getPlugin(), 0L, 20L);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,47 @@

import com.lunarclient.apollo.chat.v1.DisplayLiveChatMessageMessage;
import com.lunarclient.apollo.chat.v1.RemoveLiveChatMessageMessage;
import com.lunarclient.apollo.example.ApolloExamplePlugin;
import com.lunarclient.apollo.example.common.modules.impl.ChatExample;
import com.lunarclient.apollo.example.proto.AdventureUtil;
import com.lunarclient.apollo.example.proto.ProtobufPacketUtil;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.scheduler.BukkitRunnable;

public class ChatProtoExample extends ChatExample {

private int countdown = 5;

@Override
public void displayLiveChatMessageExample() {
DisplayLiveChatMessageMessage message = DisplayLiveChatMessageMessage.newBuilder()
.setAdventureJsonLines(AdventureUtil.toJson(
Component.text("Game starting in ", NamedTextColor.GREEN)
.append(Component.text(this.countdown, NamedTextColor.BLUE)))
)
.setMessageId(13)
.build();
BukkitRunnable runnable = new BukkitRunnable() {

if (--this.countdown == 0) {
this.countdown = 5;
}
private int countdown = 5;

ProtobufPacketUtil.broadcastPacket(message);
@Override
public void run() {
DisplayLiveChatMessageMessage.Builder builder = DisplayLiveChatMessageMessage.newBuilder()
.setMessageId(13);

if (this.countdown > 0) {
builder.setAdventureJsonLines(AdventureUtil.toJson(
Component.text("Game starting in ", NamedTextColor.GREEN)
.append(Component.text(this.countdown, NamedTextColor.BLUE)))
);

ProtobufPacketUtil.broadcastPacket(builder.build());
this.countdown--;
} else {
builder.setAdventureJsonLines(AdventureUtil.toJson(
Component.text("Game started! ", NamedTextColor.GREEN))
);

ProtobufPacketUtil.broadcastPacket(builder.build());
this.cancel();
}
}
};

runnable.runTaskTimer(ApolloExamplePlugin.getPlugin(), 0L, 20L);
}

@Override
Expand Down
126 changes: 85 additions & 41 deletions docs/developers/modules/chat.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,31 @@ Explore each integration by cycling through each tab, to find the best fit for y
### Displaying a Live Chat Message

```java
private int countdown = 5;

public void displayLiveChatMessageExample() {
this.chatModule.displayLiveChatMessage(Recipients.ofEveryone(),
Component.text("Game starting in ", NamedTextColor.GREEN)
.append(Component.text(this.countdown, NamedTextColor.BLUE)),
13
);

if (--this.countdown == 0) {
this.countdown = 5;
}
BukkitRunnable runnable = new BukkitRunnable() {

private int countdown = 5;

@Override
public void run() {
ChatApiExample.this.chatModule.displayLiveChatMessage(Recipients.ofEveryone(),
Component.text("Game starting in ", NamedTextColor.GREEN)
.append(Component.text(this.countdown, NamedTextColor.BLUE)),
13
);

if (--this.countdown == 0) {
ChatApiExample.this.chatModule.displayLiveChatMessage(Recipients.ofEveryone(),
Component.text("Game started! ", NamedTextColor.GREEN),
13
);

this.cancel();
}
}
};

runnable.runTaskTimer(ApolloExamplePlugin.getPlugin(), 0L, 20L);
}
```

Expand All @@ -57,22 +70,37 @@ public void removeLiveChatMessageExample() {
### Displaying a Live Chat Message

```java
private int countdown = 5;

@Override
public void displayLiveChatMessageExample() {
DisplayLiveChatMessageMessage message = DisplayLiveChatMessageMessage.newBuilder()
.setAdventureJsonLines(AdventureUtil.toJson(
Component.text("Game starting in ", NamedTextColor.GREEN)
.append(Component.text(this.countdown, NamedTextColor.BLUE)))
)
.setMessageId(13)
.build();

if (--this.countdown == 0) {
this.countdown = 5;
}

ProtobufPacketUtil.broadcastPacket(message);
BukkitRunnable runnable = new BukkitRunnable() {

private int countdown = 5;

@Override
public void run() {
DisplayLiveChatMessageMessage.Builder builder = DisplayLiveChatMessageMessage.newBuilder()
.setMessageId(13);

if (this.countdown > 0) {
builder.setAdventureJsonLines(AdventureUtil.toJson(
Component.text("Game starting in ", NamedTextColor.GREEN)
.append(Component.text(this.countdown, NamedTextColor.BLUE)))
);

ProtobufPacketUtil.broadcastPacket(builder.build());
this.countdown--;
} else {
builder.setAdventureJsonLines(AdventureUtil.toJson(
Component.text("Game started! ", NamedTextColor.GREEN))
);

ProtobufPacketUtil.broadcastPacket(builder.build());
this.cancel();
}
}
};

runnable.runTaskTimer(ApolloExamplePlugin.getPlugin(), 0L, 20L);
}
```

Expand All @@ -95,22 +123,38 @@ public void removeLiveChatMessageExample() {
### Displaying a Live Chat Message

```java
private int countdown = 5;

@Override
public void displayLiveChatMessageExample() {
JsonObject message = new JsonObject();
message.addProperty("@type", "type.googleapis.com/lunarclient.apollo.chat.v1.DisplayLiveChatMessageMessage");
message.addProperty("message_id", 13);
message.addProperty("adventure_json_lines", AdventureUtil.toJson(
Component.text("Game starting in ", NamedTextColor.GREEN)
.append(Component.text(this.countdown, NamedTextColor.BLUE))
));

if (--this.countdown == 0) {
this.countdown = 5;
}

JsonPacketUtil.broadcastPacket(message);
BukkitRunnable runnable = new BukkitRunnable() {

private int countdown = 5;

@Override
public void run() {
JsonObject message = new JsonObject();
message.addProperty("@type", "type.googleapis.com/lunarclient.apollo.chat.v1.DisplayLiveChatMessageMessage");
message.addProperty("message_id", 13);

if (this.countdown > 0) {
message.addProperty("adventure_json_lines", AdventureUtil.toJson(
Component.text("Game starting in ", NamedTextColor.GREEN)
.append(Component.text(this.countdown, NamedTextColor.BLUE))
));

JsonPacketUtil.broadcastPacket(message);
this.countdown--;
} else {
message.addProperty("adventure_json_lines", AdventureUtil.toJson(
Component.text("Game started! ", NamedTextColor.GREEN)
));

JsonPacketUtil.broadcastPacket(message);
this.cancel();
}
}
};

runnable.runTaskTimer(ApolloExamplePlugin.getPlugin(), 0L, 20L);
}
```

Expand Down
1 change: 0 additions & 1 deletion docs/developers/modules/team.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,6 @@ public class Team {

private JsonObject createTeamMember(Player member) {
JsonObject message = new JsonObject();
message.addProperty("@type", "type.googleapis.com/lunarclient.apollo.team.v1.TeamMember");
message.add("player_uuid", JsonUtil.createUuidObject(member.getUniqueId()));
message.addProperty("adventure_json_player_name", AdventureUtil.toJson(
Component.text()
Expand Down
2 changes: 1 addition & 1 deletion docs/developers/modules/waypoint.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public void resetWaypointsExample(Player viewer) {
<Tab>

<Callout type="warning">
Make sure the server is sending the world name to the client as show in the [Player Detection](/apollo/developers/lightweight/protobuf/player-detection) example.
Make sure the server is sending the world name to the client as show in the [Player Detection](/apollo/developers/lightweight/json/player-detection) example.
</Callout>

### Displaying a Waypoint
Expand Down