Skip to content

Commit

Permalink
Add audience to broadcast action
Browse files Browse the repository at this point in the history
  • Loading branch information
Redned235 committed Jul 7, 2024
1 parent 141d785 commit 86514f2
Showing 1 changed file with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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<? extends Player> 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);
Expand All @@ -43,6 +59,11 @@ public void postProcess(Arena arena, Competition<?> competition) {
}
}

enum Audience {
SERVER,
GAME
}

enum MessageType {
CHAT,
ACTION_BAR,
Expand Down

0 comments on commit 86514f2

Please sign in to comment.