diff --git a/plugin/src/main/java/org/battleplugins/arena/event/action/types/BroadcastAction.java b/plugin/src/main/java/org/battleplugins/arena/event/action/types/BroadcastAction.java index 539066a6..9fb22ce0 100644 --- a/plugin/src/main/java/org/battleplugins/arena/event/action/types/BroadcastAction.java +++ b/plugin/src/main/java/org/battleplugins/arena/event/action/types/BroadcastAction.java @@ -6,14 +6,17 @@ import org.battleplugins.arena.Arena; import org.battleplugins.arena.ArenaPlayer; import org.battleplugins.arena.competition.Competition; +import org.battleplugins.arena.competition.LiveCompetition; import org.battleplugins.arena.event.action.EventAction; import org.bukkit.Bukkit; import org.bukkit.entity.Player; +import java.util.Collection; import java.util.Locale; import java.util.Map; public class BroadcastAction extends EventAction { + private static final String AUDIENCE_KEY = "audience"; private static final String MESSAGE_KEY = "message"; private static final String TYPE_KEY = "type"; @@ -27,12 +30,25 @@ public void call(ArenaPlayer arenaPlayer) { @Override public void postProcess(Arena arena, Competition competition) { + if (!(competition instanceof LiveCompetition liveCompetition)) { + return; + } + String message = this.get(MESSAGE_KEY); MessageType messageType = MessageType.valueOf(this.getOrDefault(TYPE_KEY, MessageType.CHAT.name()) .toUpperCase(Locale.ROOT) ); - for (Player player : Bukkit.getOnlinePlayers()) { + Audience audience = Audience.valueOf(this.getOrDefault(AUDIENCE_KEY, Audience.GAME.name()) + .toUpperCase(Locale.ROOT) + ); + + Collection players = switch (audience) { + case GAME -> liveCompetition.getPlayers().stream().map(ArenaPlayer::getPlayer).toList(); + case SERVER -> Bukkit.getOnlinePlayers(); + }; + + for (Player player : players) { Component component = MiniMessage.miniMessage().deserialize(message); switch (messageType) { case CHAT -> player.sendMessage(component); @@ -43,6 +59,11 @@ public void postProcess(Arena arena, Competition competition) { } } + enum Audience { + SERVER, + GAME + } + enum MessageType { CHAT, ACTION_BAR,