Files
Project-CrankedPvP/Voyages/src/main/java/net/crankedpvp/voyages/tasks/VoyageRoomTimeLeftTask.java
T
2026-10-12 13:57:05 -03:00

38 lines
1.1 KiB
Java

package net.crankedpvp.voyages.tasks;
import net.crankedpvp.crankedutils.utils.TimeUtils;
import net.crankedpvp.voyages.struct.room.VoyageRoom;
import org.bukkit.scheduler.BukkitRunnable;
import java.util.Arrays;
import java.util.List;
public class VoyageRoomTimeLeftTask extends BukkitRunnable {
private static final List<Integer> WHEN_TO_DISPLAY_TITLE = Arrays.asList(300, 120, 60, 30, 15, 10, 5, 4, 3, 2, 1);
private final VoyageRoom<?> voyageRoom;
private int timeLeft;
public VoyageRoomTimeLeftTask(VoyageRoom<?> voyageRoom) {
this.timeLeft = voyageRoom.getDurationOfRoomInSeconds();
this.voyageRoom = voyageRoom;
}
@Override
public void run() {
if (timeLeft == 0) {
this.voyageRoom.stopVoyageRoom();
this.voyageRoom.nextRoom();
return;
}
if (WHEN_TO_DISPLAY_TITLE.contains(timeLeft))
this.voyageRoom.sendMessageToAllParticipants("&a&lVoyages &8➥ &7" + TimeUtils.formatSeconds(this.timeLeft) + " left before the end of this room.");
this.decrementTimeLeft();
}
public void decrementTimeLeft() {
this.timeLeft--;
}
}