24package com.dreamfirestudios.dreamcore.DreamActionBar;
26import com.dreamfirestudios.dreamcore.DreamJava.DreamClassID;
27import com.dreamfirestudios.dreamcore.DreamCore;
28import org.bukkit.entity.Player;
30import java.util.ArrayList;
37 private final List<DreamActionBarData> barFrames =
new ArrayList<>();
38 private final List<Player> viewers =
new ArrayList<>();
39 private int currentFrameIndex;
40 private boolean paused;
48 if (player ==
null)
throw new IllegalArgumentException(
"Player cannot be null");
49 return viewers.contains(player);
57 public void addViewer(Player player,
boolean multipleActionBars) {
58 if (player ==
null)
throw new IllegalArgumentException(
"Player cannot be null");
69 if (player ==
null)
throw new IllegalArgumentException(
"Player cannot be null");
71 viewers.remove(player);
78 viewers.forEach(this::removeViewer);
88 if (dreamActionBarData ==
null)
throw new IllegalArgumentException(
"DreamActionBarData cannot be null");
89 if (index >= 0 && index < barFrames.size()) barFrames.set(index, dreamActionBarData);
97 if (barFrames.isEmpty() || viewers.isEmpty())
return true;
98 if(paused)
return false;
100 if (dreamActionBarData ==
null)
throw new IllegalArgumentException(
"DreamActionBarData cannot be null");
101 viewers.parallelStream().forEach(dreamActionBarData::displayActionBar);
102 currentFrameIndex = (currentFrameIndex + 1) % barFrames.size();
138 private final List<DreamActionBarData> barFrames =
new ArrayList<>();
139 private final List<Player> viewers =
new ArrayList<>();
148 if (frame ==
null || repeatFrames <= 0)
return this;
149 for (
int i = 0; i < repeatFrames; i++) barFrames.add(frame);
159 if (player ==
null)
throw new IllegalArgumentException(
"Player cannot be null");
171 if (barFrames.isEmpty())
throw new IllegalArgumentException(
"At least one frame must be added.");
173 actionBar.barFrames.addAll(barFrames);
174 actionBar.viewers.addAll(viewers);
Provides utility methods for querying active DreamActionBar instances.
static boolean IsPlayerInActionBar(Player player)
Checks if a given player is currently viewing any DreamActionBar.
Event fired when a DreamActionBar is paused.
Event fired when a DreamActionBar resumes playing after being paused.
Event fired when a Player is added to a DreamActionBar.
Event fired when a Player is removed from a DreamActionBar.
Event fired when a DreamActionBar is stopped.
Builder class for creating DreamActionBar instances.
Builder addViewer(Player player)
Adds a viewer to the builder.
Builder addFrame(DreamActionBarData frame, int repeatFrames)
Adds a frame to the builder with optional repetition.
DreamActionBar build(boolean allowMultipleActionBars)
Builds a new DreamActionBar instance.
Represents an action bar instance that cycles through frames and displays them to viewers.
void pause()
Pauses this action bar, preventing further frame updates until resumed.
boolean displayNextFrame()
Displays the next frame in the sequence to all current viewers.
void updateFrame(int index, DreamActionBarData dreamActionBarData)
Updates a specific frame in the action bar sequence.
void addViewer(Player player, boolean multipleActionBars)
Adds a player as a viewer of this action bar.
void removeViewer(Player player)
Removes a player from the list of viewers.
boolean isPlayerViewing(Player player)
Determines whether a player is currently viewing this action bar.
void play()
Resumes this action bar if it was previously paused.
void clearViewers()
Clears all current viewers from this action bar.
void stop()
Stops this action bar, removing it from DreamCore and clearing all viewers.
static final LinkedHashMap< UUID, DreamActionBar > DreamActionBars
record DreamActionBarData(Function< Player, String > messageProvider, Function< Player, DreamMessageSettings > settingsProvider)
Represents a single frame of action bar data, including a message provider and a settings provider fo...