diff --git a/bukkit-example/src/main/java/com/lunarclient/apollo/example/api/examples/ChatApiExample.java b/bukkit-example/src/main/java/com/lunarclient/apollo/example/api/examples/ChatApiExample.java index 25e4a776..317d2826 100644 --- a/bukkit-example/src/main/java/com/lunarclient/apollo/example/api/examples/ChatApiExample.java +++ b/bukkit-example/src/main/java/com/lunarclient/apollo/example/api/examples/ChatApiExample.java @@ -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 diff --git a/bukkit-example/src/main/java/com/lunarclient/apollo/example/json/examples/ChatJsonExample.java b/bukkit-example/src/main/java/com/lunarclient/apollo/example/json/examples/ChatJsonExample.java index 092285e6..cb6ae53f 100644 --- a/bukkit-example/src/main/java/com/lunarclient/apollo/example/json/examples/ChatJsonExample.java +++ b/bukkit-example/src/main/java/com/lunarclient/apollo/example/json/examples/ChatJsonExample.java @@ -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 diff --git a/bukkit-example/src/main/java/com/lunarclient/apollo/example/proto/examples/ChatProtoExample.java b/bukkit-example/src/main/java/com/lunarclient/apollo/example/proto/examples/ChatProtoExample.java index adda6d26..1ca24849 100644 --- a/bukkit-example/src/main/java/com/lunarclient/apollo/example/proto/examples/ChatProtoExample.java +++ b/bukkit-example/src/main/java/com/lunarclient/apollo/example/proto/examples/ChatProtoExample.java @@ -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 diff --git a/docs/developers/modules/chat.mdx b/docs/developers/modules/chat.mdx index b73d70c4..084243ef 100644 --- a/docs/developers/modules/chat.mdx +++ b/docs/developers/modules/chat.mdx @@ -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); } ``` @@ -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); } ``` @@ -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); } ``` diff --git a/docs/developers/modules/team.mdx b/docs/developers/modules/team.mdx index bd856ce1..431a6afc 100644 --- a/docs/developers/modules/team.mdx +++ b/docs/developers/modules/team.mdx @@ -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() diff --git a/docs/developers/modules/waypoint.mdx b/docs/developers/modules/waypoint.mdx index 560cd1ac..6369ead2 100644 --- a/docs/developers/modules/waypoint.mdx +++ b/docs/developers/modules/waypoint.mdx @@ -190,7 +190,7 @@ public void resetWaypointsExample(Player viewer) { - 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. ### Displaying a Waypoint