From e7659255fee490154f2bfd4e8f12dd17fed20668 Mon Sep 17 00:00:00 2001 From: Stampede Date: Sun, 14 Jul 2024 11:09:26 -0500 Subject: [PATCH] feat: add ModLoaded callback event on Fabric (#346) Co-authored-by: William --- .../william278/husksync/FabricHuskSync.java | 3 ++ .../husksync/event/ModLoadedCallback.java | 39 +++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 fabric/src/main/java/net/william278/husksync/event/ModLoadedCallback.java diff --git a/fabric/src/main/java/net/william278/husksync/FabricHuskSync.java b/fabric/src/main/java/net/william278/husksync/FabricHuskSync.java index 8906f916..10600494 100644 --- a/fabric/src/main/java/net/william278/husksync/FabricHuskSync.java +++ b/fabric/src/main/java/net/william278/husksync/FabricHuskSync.java @@ -49,6 +49,7 @@ import net.william278.husksync.database.MongoDbDatabase; import net.william278.husksync.database.MySqlDatabase; import net.william278.husksync.database.PostgresDatabase; import net.william278.husksync.event.FabricEventDispatcher; +import net.william278.husksync.event.ModLoadedCallback; import net.william278.husksync.hook.PlanHook; import net.william278.husksync.listener.EventListener; import net.william278.husksync.listener.FabricEventListener; @@ -206,6 +207,8 @@ public class FabricHuskSync implements DedicatedServerModInitializer, HuskSync, // Check for updates this.checkForUpdates(); + + ModLoadedCallback.EVENT.invoker().post(FabricHuskSyncAPI.getInstance()); } private void onDisable() { diff --git a/fabric/src/main/java/net/william278/husksync/event/ModLoadedCallback.java b/fabric/src/main/java/net/william278/husksync/event/ModLoadedCallback.java new file mode 100644 index 00000000..fff90015 --- /dev/null +++ b/fabric/src/main/java/net/william278/husksync/event/ModLoadedCallback.java @@ -0,0 +1,39 @@ +/* + * This file is part of HuskSync, licensed under the Apache License 2.0. + * + * Copyright (c) William278 + * Copyright (c) contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package net.william278.husksync.event; + +import net.fabricmc.fabric.api.event.Event; +import net.fabricmc.fabric.api.event.EventFactory; +import net.william278.husksync.api.HuskSyncAPI; +import org.jetbrains.annotations.NotNull; + +import java.util.Arrays; + +public interface ModLoadedCallback { + + @NotNull + Event EVENT = EventFactory.createArrayBacked( + ModLoadedCallback.class, + (listeners) -> (api) -> Arrays.stream(listeners).forEach(listener -> listener.post(api)) + ); + + void post(@NotNull HuskSyncAPI api); + +}