81 lines
2.6 KiB
Java
81 lines
2.6 KiB
Java
package dev.viper.eventengine.model;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import java.util.*;
|
|
|
|
/**
|
|
* Repräsentiert eine aktuell laufende Event-Instanz.
|
|
*/
|
|
public class ActiveEvent {
|
|
|
|
public enum State { WAITING, RUNNING, ENDED }
|
|
|
|
private final EventDefinition definition;
|
|
private State state;
|
|
private final long startTime;
|
|
private final Set<UUID> participants;
|
|
private final Map<UUID, Integer> scores;
|
|
private int taskId = -1;
|
|
private UUID winner;
|
|
|
|
public ActiveEvent(EventDefinition definition) {
|
|
this.definition = definition;
|
|
this.state = State.WAITING;
|
|
this.startTime = System.currentTimeMillis();
|
|
this.participants = new LinkedHashSet<>();
|
|
this.scores = new HashMap<>();
|
|
this.winner = null;
|
|
}
|
|
|
|
public void addParticipant(Player player) {
|
|
participants.add(player.getUniqueId());
|
|
scores.putIfAbsent(player.getUniqueId(), 0);
|
|
}
|
|
|
|
public void removeParticipant(Player player) {
|
|
participants.remove(player.getUniqueId());
|
|
}
|
|
|
|
public boolean isParticipant(Player player) {
|
|
return participants.contains(player.getUniqueId());
|
|
}
|
|
|
|
public void addScore(UUID uuid, int points) {
|
|
scores.merge(uuid, points, Integer::sum);
|
|
}
|
|
|
|
public int getScore(UUID uuid) {
|
|
return scores.getOrDefault(uuid, 0);
|
|
}
|
|
|
|
/** Gibt Spieler sortiert nach Score zurück */
|
|
public List<Map.Entry<UUID, Integer>> getLeaderboard() {
|
|
List<Map.Entry<UUID, Integer>> entries = new ArrayList<>(scores.entrySet());
|
|
entries.sort((a, b) -> b.getValue() - a.getValue());
|
|
return entries;
|
|
}
|
|
|
|
public long getElapsedSeconds() {
|
|
return (System.currentTimeMillis() - startTime) / 1000;
|
|
}
|
|
|
|
public long getRemainingSeconds() {
|
|
if (definition.getDurationSeconds() == 0) return -1;
|
|
long remaining = definition.getDurationSeconds() - getElapsedSeconds();
|
|
return Math.max(0, remaining);
|
|
}
|
|
|
|
public EventDefinition getDefinition() { return definition; }
|
|
public State getState() { return state; }
|
|
public void setState(State state) { this.state = state; }
|
|
public Set<UUID> getParticipants() { return Collections.unmodifiableSet(participants); }
|
|
public Map<UUID, Integer> getScores() { return scores; }
|
|
public int getTaskId() { return taskId; }
|
|
public void setTaskId(int taskId) { this.taskId = taskId; }
|
|
public int getParticipantCount() { return participants.size(); }
|
|
public UUID getWinner() { return winner; }
|
|
public void setWinner(UUID winner) { this.winner = winner; }
|
|
public boolean hasWinner() { return winner != null; }
|
|
}
|