Add restart API events

This commit is contained in:
Alessandro Proto 2024-10-28 19:39:11 +01:00
parent fc00b80c05
commit 82f4e24404
3 changed files with 36 additions and 1 deletions

View file

@ -9,7 +9,7 @@ yarn_mappings=1.20.1+build.10
loader_version=0.16.7
# Mod Properties
mod_version=1.16.0
mod_version=1.16.1
maven_group=cc.reconnected
archives_base_name=rcc-server

View file

@ -0,0 +1,31 @@
package cc.reconnected.server.api.events;
import cc.reconnected.server.core.BossBarManager;
import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.EventFactory;
public class RestartEvents {
public static final Event<Schedule> SCHEDULED = EventFactory.createArrayBacked(Schedule.class, callbacks ->
(timeBar) -> {
for (Schedule callback : callbacks) {
callback.onSchedule(timeBar);
}
});
public static final Event<Cancel> CANCELED = EventFactory.createArrayBacked(Cancel.class, callbacks ->
(timeBar) -> {
for (Cancel callback : callbacks) {
callback.onCancel(timeBar);
}
});
@FunctionalInterface
public interface Schedule {
void onSchedule(BossBarManager.TimeBar timeBar);
}
@FunctionalInterface
public interface Cancel {
void onCancel(BossBarManager.TimeBar timeBar);
}
}

View file

@ -3,6 +3,7 @@ package cc.reconnected.server.core;
import cc.reconnected.server.RccServer;
import cc.reconnected.server.api.events.BossBarEvents;
import cc.reconnected.server.api.events.RccEvents;
import cc.reconnected.server.api.events.RestartEvents;
import cc.reconnected.server.util.Components;
import net.kyori.adventure.key.InvalidKeyException;
import net.kyori.adventure.key.Key;
@ -90,6 +91,8 @@ public class AutoRestart {
BossBar.Style.NOTCHED_20,
true
);
RestartEvents.SCHEDULED.invoker().onSchedule(restartBar);
}
public static boolean isScheduled() {
@ -99,6 +102,7 @@ public class AutoRestart {
public static void cancel() {
if (restartBar != null) {
BossBarManager.getInstance().cancelTimeBar(restartBar);
RestartEvents.CANCELED.invoker().onCancel(restartBar);
restartBar = null;
}