Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
import org.bukkit.scheduler.BukkitTask;

import java.sql.SQLException;
import java.time.format.TextStyle;
import java.util.List;
import java.util.Locale;

@Credit(developers = {"iambibi_"})
public class WeeklyEventsManager extends Feature implements LoadAfterItemsAdder, DatabaseFeature {
Expand All @@ -44,8 +46,8 @@ public void init() {

WeeklyEventPhase currentPhase = getCurrentPhase();
if (data.isActive() && currentPhase != null && DateUtils.getCurrentDayOfWeek().equals(currentPhase.getStartDay())) {
Runnable action = currentPhase.runAction();
if (action != null) action.run();
runPhase(currentPhase);
return;
}

scheduleNextPhase();
Expand Down Expand Up @@ -149,6 +151,18 @@ public static void scheduleNextPhase() {
return;
}

OMCLogger.infoFormatted("Prochaine Phase ({}) de l'évenement weekly ({}) le"
+ nextPhase.getStartDay().getDisplayName(TextStyle.FULL_STANDALONE, Locale.FRENCH) + " "
+ nextPhase.getStartHour() + "h" + nextPhase.getStartMinutes() + "m "
+ " (dans " + DateUtils.convertSecondToTime(DateUtils.getSecondsUntilDayOfWeekTime(
nextPhase.getStartDay(),
nextPhase.getStartHour(),
nextPhase.getStartMinutes(),
0
)) + ")", PlainTextComponentSerializer.plainText().serialize(nextPhase.getName()),
PlainTextComponentSerializer.plainText().serialize(getCurrentEvent().getName()));


currentTask = Bukkit.getScheduler().runTaskLater(OMCPlugin.getInstance(), () -> {
if (findNextPhase() != nextPhase) {
scheduleNextPhase();
Expand All @@ -166,11 +180,16 @@ private static void runPhase(WeeklyEventPhase phase) {
data.setActive(true);
save(data);

Runnable action = phase.runAction();
if (action != null) action.run();

advancePhase();
scheduleNextPhase();

try {
Runnable action = phase.runAction();
if (action != null) action.run();
} catch (Exception e) {
OMCLogger.error("Erreur lors de l'exécution de la phase {}",
PlainTextComponentSerializer.plainText().serialize(phase.getName()), e);
}
}

/**
Expand Down Expand Up @@ -203,24 +222,11 @@ public static void forceEventAtPhase(WeeklyEvent event, WeeklyEventPhase phase)
return;
}

data.setCurrentEventIndex(eventIndex);
data.setCurrentPhaseIndex(phaseIndex);
data.setActive(true);
save(data);

Runnable action = phase.runAction();
if (action != null) action.run();

boolean isLastPhase = phaseIndex == event.getPhases().size() - 1;
if (isLastPhase) {
advanceToNextEvent();
}

scheduleNextPhase();

OMCLogger.info("[WeeklyEvents] Event forcé : {} à la phase {}",
PlainTextComponentSerializer.plainText().serialize(event.getName()),
PlainTextComponentSerializer.plainText().serialize(phase.getName()));

runPhase(phase);
}

/**
Expand Down
Loading