Skip to content

Commit

Permalink
add chat
Browse files Browse the repository at this point in the history
  • Loading branch information
iceBear67 committed Dec 9, 2024
1 parent ba66be0 commit 6498ac5
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/main/java/dev/tylerm/khs/game/listener/ChatHandler.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package dev.tylerm.khs.game.listener;

import dev.tylerm.khs.Main;
import dev.tylerm.khs.game.util.Status;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
Expand All @@ -11,9 +13,25 @@ public class ChatHandler implements Listener {

@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onChat(AsyncPlayerChatEvent event) {
if (Main.getInstance().getBoard().isSpectator(event.getPlayer())) {
event.setCancelled(true);
Main.getInstance().getBoard().getSpectators().forEach(spectator -> spectator.sendMessage(ChatColor.GRAY + "[SPECTATOR] " + event.getPlayer().getName() + ": " + event.getMessage()));
event.setCancelled(true);
//todo add config for chat configuration
var board = Main.getInstance().getBoard();
if (board.isSpectator(event.getPlayer())) {
board.getSpectators().forEach(spectator -> spectator.sendMessage(ChatColor.GRAY + "[SPECTATOR] " + event.getPlayer().getName() + ": " + event.getMessage()));
} else {
var status = Main.getInstance().getGame().getStatus();
if (status == Status.PLAYING) {
Bukkit.broadcastMessage(
ChatColor.BOLD +
(board.isHider(event.getPlayer()) ?
ChatColor.GOLD + "[BLOCK] "
: ChatColor.BLUE + "SEEKER ")
+ ChatColor.WHITE + event.getPlayer().getName() + ": " + ChatColor.GRAY + event.getMessage());
} else {
Bukkit.broadcastMessage(
event.getPlayer().getName() + ": " + ChatColor.GRAY + event.getMessage()
);
}
}
}

Expand Down

0 comments on commit 6498ac5

Please sign in to comment.