Skip to content

Commit fa2a906

Browse files
authored
Lightweight Documentation Fixes & Improvements (#186)
* Fix waypoint warning hyperlink redirecting to the wrong page * Remove @type from Team json example * better live chat message example
1 parent 4f152f5 commit fa2a906

File tree

6 files changed

+173
-80
lines changed

6 files changed

+173
-80
lines changed

bukkit-example/src/main/java/com/lunarclient/apollo/example/api/examples/ChatApiExample.java

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,29 +24,46 @@
2424
package com.lunarclient.apollo.example.api.examples;
2525

2626
import com.lunarclient.apollo.Apollo;
27+
import com.lunarclient.apollo.example.ApolloExamplePlugin;
2728
import com.lunarclient.apollo.example.common.modules.impl.ChatExample;
2829
import com.lunarclient.apollo.module.chat.ChatModule;
2930
import com.lunarclient.apollo.recipients.Recipients;
3031
import net.kyori.adventure.text.Component;
3132
import net.kyori.adventure.text.format.NamedTextColor;
33+
import org.bukkit.scheduler.BukkitRunnable;
3234

3335
public class ChatApiExample extends ChatExample {
3436

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

37-
private int countdown = 5;
38-
3939
@Override
4040
public void displayLiveChatMessageExample() {
41-
this.chatModule.displayLiveChatMessage(Recipients.ofEveryone(),
42-
Component.text("Game starting in ", NamedTextColor.GREEN)
43-
.append(Component.text(this.countdown, NamedTextColor.BLUE)),
44-
13
45-
);
46-
47-
if (--this.countdown == 0) {
48-
this.countdown = 5;
49-
}
41+
BukkitRunnable runnable = new BukkitRunnable() {
42+
43+
private int countdown = 5;
44+
45+
@Override
46+
public void run() {
47+
if (this.countdown > 0) {
48+
ChatApiExample.this.chatModule.displayLiveChatMessage(Recipients.ofEveryone(),
49+
Component.text("Game starting in ", NamedTextColor.GREEN)
50+
.append(Component.text(this.countdown, NamedTextColor.BLUE)),
51+
13
52+
);
53+
54+
this.countdown--;
55+
} else {
56+
ChatApiExample.this.chatModule.displayLiveChatMessage(Recipients.ofEveryone(),
57+
Component.text("Game started! ", NamedTextColor.GREEN),
58+
13
59+
);
60+
61+
this.cancel();
62+
}
63+
}
64+
};
65+
66+
runnable.runTaskTimer(ApolloExamplePlugin.getPlugin(), 0L, 20L);
5067
}
5168

5269
@Override

bukkit-example/src/main/java/com/lunarclient/apollo/example/json/examples/ChatJsonExample.java

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,31 +24,48 @@
2424
package com.lunarclient.apollo.example.json.examples;
2525

2626
import com.google.gson.JsonObject;
27+
import com.lunarclient.apollo.example.ApolloExamplePlugin;
2728
import com.lunarclient.apollo.example.common.modules.impl.ChatExample;
2829
import com.lunarclient.apollo.example.json.AdventureUtil;
2930
import com.lunarclient.apollo.example.json.JsonPacketUtil;
3031
import net.kyori.adventure.text.Component;
3132
import net.kyori.adventure.text.format.NamedTextColor;
33+
import org.bukkit.scheduler.BukkitRunnable;
3234

3335
public class ChatJsonExample extends ChatExample {
3436

35-
private int countdown = 5;
36-
3737
@Override
3838
public void displayLiveChatMessageExample() {
39-
JsonObject message = new JsonObject();
40-
message.addProperty("@type", "type.googleapis.com/lunarclient.apollo.chat.v1.DisplayLiveChatMessageMessage");
41-
message.addProperty("message_id", 13);
42-
message.addProperty("adventure_json_lines", AdventureUtil.toJson(
43-
Component.text("Game starting in ", NamedTextColor.GREEN)
44-
.append(Component.text(this.countdown, NamedTextColor.BLUE))
45-
));
39+
BukkitRunnable runnable = new BukkitRunnable() {
4640

47-
if (--this.countdown == 0) {
48-
this.countdown = 5;
49-
}
41+
private int countdown = 5;
5042

51-
JsonPacketUtil.broadcastPacket(message);
43+
@Override
44+
public void run() {
45+
JsonObject message = new JsonObject();
46+
message.addProperty("@type", "type.googleapis.com/lunarclient.apollo.chat.v1.DisplayLiveChatMessageMessage");
47+
message.addProperty("message_id", 13);
48+
49+
if (this.countdown > 0) {
50+
message.addProperty("adventure_json_lines", AdventureUtil.toJson(
51+
Component.text("Game starting in ", NamedTextColor.GREEN)
52+
.append(Component.text(this.countdown, NamedTextColor.BLUE))
53+
));
54+
55+
JsonPacketUtil.broadcastPacket(message);
56+
this.countdown--;
57+
} else {
58+
message.addProperty("adventure_json_lines", AdventureUtil.toJson(
59+
Component.text("Game started! ", NamedTextColor.GREEN)
60+
));
61+
62+
JsonPacketUtil.broadcastPacket(message);
63+
this.cancel();
64+
}
65+
}
66+
};
67+
68+
runnable.runTaskTimer(ApolloExamplePlugin.getPlugin(), 0L, 20L);
5269
}
5370

5471
@Override

bukkit-example/src/main/java/com/lunarclient/apollo/example/proto/examples/ChatProtoExample.java

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,31 +25,47 @@
2525

2626
import com.lunarclient.apollo.chat.v1.DisplayLiveChatMessageMessage;
2727
import com.lunarclient.apollo.chat.v1.RemoveLiveChatMessageMessage;
28+
import com.lunarclient.apollo.example.ApolloExamplePlugin;
2829
import com.lunarclient.apollo.example.common.modules.impl.ChatExample;
2930
import com.lunarclient.apollo.example.proto.AdventureUtil;
3031
import com.lunarclient.apollo.example.proto.ProtobufPacketUtil;
3132
import net.kyori.adventure.text.Component;
3233
import net.kyori.adventure.text.format.NamedTextColor;
34+
import org.bukkit.scheduler.BukkitRunnable;
3335

3436
public class ChatProtoExample extends ChatExample {
3537

36-
private int countdown = 5;
37-
3838
@Override
3939
public void displayLiveChatMessageExample() {
40-
DisplayLiveChatMessageMessage message = DisplayLiveChatMessageMessage.newBuilder()
41-
.setAdventureJsonLines(AdventureUtil.toJson(
42-
Component.text("Game starting in ", NamedTextColor.GREEN)
43-
.append(Component.text(this.countdown, NamedTextColor.BLUE)))
44-
)
45-
.setMessageId(13)
46-
.build();
40+
BukkitRunnable runnable = new BukkitRunnable() {
4741

48-
if (--this.countdown == 0) {
49-
this.countdown = 5;
50-
}
42+
private int countdown = 5;
5143

52-
ProtobufPacketUtil.broadcastPacket(message);
44+
@Override
45+
public void run() {
46+
DisplayLiveChatMessageMessage.Builder builder = DisplayLiveChatMessageMessage.newBuilder()
47+
.setMessageId(13);
48+
49+
if (this.countdown > 0) {
50+
builder.setAdventureJsonLines(AdventureUtil.toJson(
51+
Component.text("Game starting in ", NamedTextColor.GREEN)
52+
.append(Component.text(this.countdown, NamedTextColor.BLUE)))
53+
);
54+
55+
ProtobufPacketUtil.broadcastPacket(builder.build());
56+
this.countdown--;
57+
} else {
58+
builder.setAdventureJsonLines(AdventureUtil.toJson(
59+
Component.text("Game started! ", NamedTextColor.GREEN))
60+
);
61+
62+
ProtobufPacketUtil.broadcastPacket(builder.build());
63+
this.cancel();
64+
}
65+
}
66+
};
67+
68+
runnable.runTaskTimer(ApolloExamplePlugin.getPlugin(), 0L, 20L);
5369
}
5470

5571
@Override

docs/developers/modules/chat.mdx

Lines changed: 85 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,31 @@ Explore each integration by cycling through each tab, to find the best fit for y
2727
### Displaying a Live Chat Message
2828

2929
```java
30-
private int countdown = 5;
31-
3230
public void displayLiveChatMessageExample() {
33-
this.chatModule.displayLiveChatMessage(Recipients.ofEveryone(),
34-
Component.text("Game starting in ", NamedTextColor.GREEN)
35-
.append(Component.text(this.countdown, NamedTextColor.BLUE)),
36-
13
37-
);
38-
39-
if (--this.countdown == 0) {
40-
this.countdown = 5;
41-
}
31+
BukkitRunnable runnable = new BukkitRunnable() {
32+
33+
private int countdown = 5;
34+
35+
@Override
36+
public void run() {
37+
ChatApiExample.this.chatModule.displayLiveChatMessage(Recipients.ofEveryone(),
38+
Component.text("Game starting in ", NamedTextColor.GREEN)
39+
.append(Component.text(this.countdown, NamedTextColor.BLUE)),
40+
13
41+
);
42+
43+
if (--this.countdown == 0) {
44+
ChatApiExample.this.chatModule.displayLiveChatMessage(Recipients.ofEveryone(),
45+
Component.text("Game started! ", NamedTextColor.GREEN),
46+
13
47+
);
48+
49+
this.cancel();
50+
}
51+
}
52+
};
53+
54+
runnable.runTaskTimer(ApolloExamplePlugin.getPlugin(), 0L, 20L);
4255
}
4356
```
4457

@@ -57,22 +70,37 @@ public void removeLiveChatMessageExample() {
5770
**Displaying a Live Chat Message**
5871

5972
```java
60-
private int countdown = 5;
61-
73+
@Override
6274
public void displayLiveChatMessageExample() {
63-
DisplayLiveChatMessageMessage message = DisplayLiveChatMessageMessage.newBuilder()
64-
.setAdventureJsonLines(AdventureUtil.toJson(
65-
Component.text("Game starting in ", NamedTextColor.GREEN)
66-
.append(Component.text(this.countdown, NamedTextColor.BLUE)))
67-
)
68-
.setMessageId(13)
69-
.build();
70-
71-
if (--this.countdown == 0) {
72-
this.countdown = 5;
73-
}
74-
75-
ProtobufPacketUtil.broadcastPacket(message);
75+
BukkitRunnable runnable = new BukkitRunnable() {
76+
77+
private int countdown = 5;
78+
79+
@Override
80+
public void run() {
81+
DisplayLiveChatMessageMessage.Builder builder = DisplayLiveChatMessageMessage.newBuilder()
82+
.setMessageId(13);
83+
84+
if (this.countdown > 0) {
85+
builder.setAdventureJsonLines(AdventureUtil.toJson(
86+
Component.text("Game starting in ", NamedTextColor.GREEN)
87+
.append(Component.text(this.countdown, NamedTextColor.BLUE)))
88+
);
89+
90+
ProtobufPacketUtil.broadcastPacket(builder.build());
91+
this.countdown--;
92+
} else {
93+
builder.setAdventureJsonLines(AdventureUtil.toJson(
94+
Component.text("Game started! ", NamedTextColor.GREEN))
95+
);
96+
97+
ProtobufPacketUtil.broadcastPacket(builder.build());
98+
this.cancel();
99+
}
100+
}
101+
};
102+
103+
runnable.runTaskTimer(ApolloExamplePlugin.getPlugin(), 0L, 20L);
76104
}
77105
```
78106

@@ -95,22 +123,38 @@ public void removeLiveChatMessageExample() {
95123
**Displaying a Live Chat Message**
96124

97125
```java
98-
private int countdown = 5;
99-
126+
@Override
100127
public void displayLiveChatMessageExample() {
101-
JsonObject message = new JsonObject();
102-
message.addProperty("@type", "type.googleapis.com/lunarclient.apollo.chat.v1.DisplayLiveChatMessageMessage");
103-
message.addProperty("message_id", 13);
104-
message.addProperty("adventure_json_lines", AdventureUtil.toJson(
105-
Component.text("Game starting in ", NamedTextColor.GREEN)
106-
.append(Component.text(this.countdown, NamedTextColor.BLUE))
107-
));
108-
109-
if (--this.countdown == 0) {
110-
this.countdown = 5;
111-
}
112-
113-
JsonPacketUtil.broadcastPacket(message);
128+
BukkitRunnable runnable = new BukkitRunnable() {
129+
130+
private int countdown = 5;
131+
132+
@Override
133+
public void run() {
134+
JsonObject message = new JsonObject();
135+
message.addProperty("@type", "type.googleapis.com/lunarclient.apollo.chat.v1.DisplayLiveChatMessageMessage");
136+
message.addProperty("message_id", 13);
137+
138+
if (this.countdown > 0) {
139+
message.addProperty("adventure_json_lines", AdventureUtil.toJson(
140+
Component.text("Game starting in ", NamedTextColor.GREEN)
141+
.append(Component.text(this.countdown, NamedTextColor.BLUE))
142+
));
143+
144+
JsonPacketUtil.broadcastPacket(message);
145+
this.countdown--;
146+
} else {
147+
message.addProperty("adventure_json_lines", AdventureUtil.toJson(
148+
Component.text("Game started! ", NamedTextColor.GREEN)
149+
));
150+
151+
JsonPacketUtil.broadcastPacket(message);
152+
this.cancel();
153+
}
154+
}
155+
};
156+
157+
runnable.runTaskTimer(ApolloExamplePlugin.getPlugin(), 0L, 20L);
114158
}
115159
```
116160

docs/developers/modules/team.mdx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,6 @@ public class Team {
445445

446446
private JsonObject createTeamMember(Player member) {
447447
JsonObject message = new JsonObject();
448-
message.addProperty("@type", "type.googleapis.com/lunarclient.apollo.team.v1.TeamMember");
449448
message.add("player_uuid", JsonUtil.createUuidObject(member.getUniqueId()));
450449
message.addProperty("adventure_json_player_name", AdventureUtil.toJson(
451450
Component.text()

docs/developers/modules/waypoint.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ public void resetWaypointsExample(Player viewer) {
190190
<Tab>
191191

192192
<Callout type="warning">
193-
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.
193+
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.
194194
</Callout>
195195

196196
**Displaying a Waypoint**

0 commit comments

Comments
 (0)