Chat Module
Overview
The chat module allows you to interact with and modify users chat feeds.
- Adds the ability to simulate live updating messages
- Grants the ability to remove specific messages for a player
Example of simulating live chat!
Integration
Sample Code
Explore each integration by cycling through each tab, to find the best fit for your requirements and needs.
Displaying a Live Chat Message
public void displayLiveChatMessageExample() {
if (ServerUtil.isFolia()) {
this.runFoliaChatMessageTask();
} else {
this.runBukkitChatMessageTask();
}
}
private void runBukkitChatMessageTask() {
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.getInstance(), 1L, 20L);
}
private void runFoliaChatMessageTask() {
AtomicInteger countdown = new AtomicInteger(5);
Bukkit.getGlobalRegionScheduler().runAtFixedRate(ApolloExamplePlugin.getInstance(), task -> {
int seconds = countdown.getAndDecrement();
if (seconds > 0) {
ChatApiExample.this.chatModule.displayLiveChatMessage(Recipients.ofEveryone(),
Component.text("Game starting in ", NamedTextColor.GREEN)
.append(Component.text(seconds, NamedTextColor.BLUE)),
13
);
} else {
ChatApiExample.this.chatModule.displayLiveChatMessage(Recipients.ofEveryone(),
Component.text("Game started! ", NamedTextColor.GREEN),
13
);
task.cancel();
}
}, 1L, 20L);
}
Removing a Live Chat Message
public void removeLiveChatMessageExample() {
this.chatModule.removeLiveChatMessage(Recipients.ofEveryone(), 13);
}