24package com.dreamfirestudios.dreamcore.DreamCam;
26import com.dreamfirestudios.dreamcore.DreamCore;
27import com.dreamfirestudios.dreamcore.DreamJava.DreamClassID;
28import org.bukkit.Bukkit;
29import org.bukkit.GameMode;
30import org.bukkit.Location;
31import org.bukkit.entity.Player;
32import org.bukkit.scheduler.BukkitRunnable;
55 private final List<UUID> players =
new ArrayList<>();
56 private List<DreamCamSet> camSets =
new ArrayList<>();
58 private final Map<UUID, GameMode> playersGamemodesBefore =
new HashMap<>();
59 private final Map<UUID, Location> playersLocationsBefore =
new HashMap<>();
60 private final Map<UUID, Boolean> playersFlyingBefore =
new HashMap<>();
61 private BukkitRunnable bukkitRunnable;
64 public List<DreamCamSet>
getCamSets() {
return camSets; }
74 for (var player : players)
addPlayer(player);
84 players.add(player.getUniqueId());
92 for (var playerUUID :
new ArrayList<>(players)) {
93 var player = Bukkit.getPlayer(playerUUID);
105 if (!players.contains(player.getUniqueId()))
return;
107 player.setGameMode(playersGamemodesBefore.getOrDefault(player.getUniqueId(), player.getGameMode()));
108 player.teleport(playersLocationsBefore.getOrDefault(player.getUniqueId(), player.getLocation()));
109 player.setFlying(playersFlyingBefore.getOrDefault(player.getUniqueId(), player.isFlying()));
110 players.remove(player.getUniqueId());
118 if (bukkitRunnable !=
null)
return;
119 for (var playerUUID : players) {
120 var player = Bukkit.getPlayer(playerUUID);
121 if (player ==
null)
continue;
122 playersGamemodesBefore.put(playerUUID, player.getGameMode());
123 playersLocationsBefore.put(playerUUID, player.getLocation());
124 playersFlyingBefore.put(playerUUID, player.isFlying());
125 player.setGameMode(GameMode.SPECTATOR);
138 for (var playerUUID :
new ArrayList<>(players)) {
139 var player = Bukkit.getPlayer(playerUUID);
143 if (bukkitRunnable !=
null) {
144 bukkitRunnable.cancel();
145 bukkitRunnable =
null;
170 private final List<DreamCamSet> camSets =
new ArrayList<>();
171 private final List<Player> players =
new ArrayList<>();
184 if (durationInTicks <= 0)
throw new IllegalArgumentException(
"durationInTicks must be > 0");
186 var pathLocations =
new ArrayList<Location>();
187 pathLocations.add(start.clone());
189 var stepX = (end.getX() - start.getX()) / durationInTicks;
190 var stepY = (end.getY() - start.getY()) / durationInTicks;
191 var stepZ = (end.getZ() - start.getZ()) / durationInTicks;
192 var stepYaw = (end.getYaw() - start.getYaw()) / durationInTicks;
193 var stepPitch = (end.getPitch() - start.getPitch()) / durationInTicks;
195 var step =
new Location(start.getWorld(), stepX, stepY, stepZ, (
float) stepYaw, (
float) stepPitch);
197 for (
int i = 1; i <= durationInTicks; i++) {
198 var prevLocation = pathLocations.get(i - 1).clone();
199 var next = prevLocation.add(step);
200 next.setYaw(next.getYaw() + stepYaw);
201 next.setPitch(next.getPitch() + stepPitch);
202 pathLocations.add(next);
205 camSets.add(
new DreamCamSet(pathLocations, lookAtType, data));
215 this.players.addAll(Arrays.asList(players));
229 path.camSets = camSets;
230 players.forEach(path::addPlayer);
Fired before a player is added to a DreamCamPath.
Fired when a player leaves a DreamCamPath (either manually or at the end).
Fired when a DreamCamPath starts running.
Fired when a DreamCamPath stops (after restoring player states).
Bukkit runnable that steps through a DreamCamPath point-by-point, teleporting players and dispatching...
Builder class for creating DreamCamPath instances.
CamPathBuilder players(Player... players)
Adds players to this path.
CamPathBuilder addTravelPath(Location start, Location end, LookAtType lookAtType, Object data, int durationInTicks)
Adds a linear travel path segment.
DreamCamPath create()
Builds or retrieves the path instance.
Represents a cinematic camera path composed of multiple camera sets (segments).
void onPlayerLeave(Player player)
Called when a player leaves unexpectedly.
List< DreamCamSet > getCamSets()
Gets all camera sets in this path.
void onDisable()
Called when the plugin is disabled to safely remove players.
List< UUID > getPlayers()
Gets the players currently on this path (by UUID).
void endCamPath(boolean hasFinished)
Stops the path and restores all player states.
void addPlayer(Player... players)
Adds multiple players to the camera path.
void startCamPath()
Starts playback of the camera path for all players.
void addPlayer(Player player)
Adds a single player to the camera path.
void removeAllPlayers(boolean hasFinished)
Removes all players from the path.
void removePlayerFromPath(Player player, boolean hasFinished)
Removes a single player from the path and restores their state.
static DreamCore DreamCore
static final LinkedHashMap< UUID, DreamCamPath > DreamCamPaths
Defines how the camera should orient itself during path playback.
record DreamCamSet(List< Location > points, LookAtType lookAtType, Object object)
Represents a segment of a camera path containing ordered points and rotation rules (look-at behavior)...