From 52a466f7ead50dcce2459621a55c51cf115fe663 Mon Sep 17 00:00:00 2001 From: Video Date: Tue, 11 Apr 2023 19:34:49 -0600 Subject: [PATCH] Bugfixes and rewrites of how notifications are registered --- .../hotbarsplus/api/config/Configuration.java | 10 ----- .../provider/INotificationRouteProvider.java | 32 +++++++++++++++ .../hotbarsplus/core/HBPCore.java | 5 --- .../provider/NotificationRouteProvider.java | 39 +++++++++++++++++++ .../core/universal/ConfigurationManager.java | 6 +++ .../core/universal/NotificationManager.java | 9 ++++- src/main/resources/fabric.mod.json | 3 ++ 7 files changed, 87 insertions(+), 17 deletions(-) create mode 100644 src/main/java/me/videogamesm12/hotbarsplus/api/provider/INotificationRouteProvider.java create mode 100644 src/main/java/me/videogamesm12/hotbarsplus/core/provider/NotificationRouteProvider.java diff --git a/src/main/java/me/videogamesm12/hotbarsplus/api/config/Configuration.java b/src/main/java/me/videogamesm12/hotbarsplus/api/config/Configuration.java index 1861314..a413524 100644 --- a/src/main/java/me/videogamesm12/hotbarsplus/api/config/Configuration.java +++ b/src/main/java/me/videogamesm12/hotbarsplus/api/config/Configuration.java @@ -50,11 +50,6 @@ public class Configuration @Getter public static class Notifications implements NotificationTypeRegistered { - public Notifications() - { - NotificationTypeRegistered.EVENT.register(this); - } - @Setter private boolean enabled = true; @@ -81,11 +76,6 @@ public static class LastHotbarPage implements HotbarNavigateEvent private BigInteger page = HBPCore.UPL.getCurrentPage(); - public LastHotbarPage() - { - HotbarNavigateEvent.EVENT.register(this); - } - @Override public ActionResult onNavigate(BigInteger page) { diff --git a/src/main/java/me/videogamesm12/hotbarsplus/api/provider/INotificationRouteProvider.java b/src/main/java/me/videogamesm12/hotbarsplus/api/provider/INotificationRouteProvider.java new file mode 100644 index 0000000..c57328c --- /dev/null +++ b/src/main/java/me/videogamesm12/hotbarsplus/api/provider/INotificationRouteProvider.java @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2023 Video + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE + * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package me.videogamesm12.hotbarsplus.api.provider; + +import me.videogamesm12.hotbarsplus.core.universal.NotificationManager; + +import java.util.List; + +/** + *

INotificationRouteProvider

+ *

Hotbars+'s new way of registering notification routes as of v2.0-pre10.

+ *

To use this, implement this interface in your project as a provider and have it return a list of route classes. Then, add a path to the class in your fabric.mod.json file as an entrypoint for "hotbarsplus".

+ */ +public interface INotificationRouteProvider +{ + List> getNotificationRoutes(); +} diff --git a/src/main/java/me/videogamesm12/hotbarsplus/core/HBPCore.java b/src/main/java/me/videogamesm12/hotbarsplus/core/HBPCore.java index 1caeff2..16eebec 100644 --- a/src/main/java/me/videogamesm12/hotbarsplus/core/HBPCore.java +++ b/src/main/java/me/videogamesm12/hotbarsplus/core/HBPCore.java @@ -55,11 +55,6 @@ public class HBPCore implements ClientModInitializer @Override public void onInitializeClient() { - // NOTIFICATION TYPES - //------------------------------------------------------------------------ - UNL.register(ActionBarNotification.class); // Action bar notification - UNL.register(ToastNotification.class); // Toast notification - // LAST HOTBAR PAGE TRACKING //------------------------------------------------------------------------ if (UCL.getConfig().getLastHotbarPage().isEnabled()) diff --git a/src/main/java/me/videogamesm12/hotbarsplus/core/provider/NotificationRouteProvider.java b/src/main/java/me/videogamesm12/hotbarsplus/core/provider/NotificationRouteProvider.java new file mode 100644 index 0000000..3a83bb7 --- /dev/null +++ b/src/main/java/me/videogamesm12/hotbarsplus/core/provider/NotificationRouteProvider.java @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2023 Video + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE + * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package me.videogamesm12.hotbarsplus.core.provider; + +import me.videogamesm12.hotbarsplus.api.provider.INotificationRouteProvider; +import me.videogamesm12.hotbarsplus.core.notifications.ActionBarNotification; +import me.videogamesm12.hotbarsplus.core.notifications.ToastNotification; +import me.videogamesm12.hotbarsplus.core.universal.NotificationManager; + +import java.util.Arrays; +import java.util.List; + +/** + *

NotificationRouteProvider

+ *

Registers Hotbars+'s built-in notification routes (action bar and toast notifications)

+ */ +public class NotificationRouteProvider implements INotificationRouteProvider +{ + @Override + public List> getNotificationRoutes() + { + return Arrays.asList(ActionBarNotification.class, ToastNotification.class); + } +} diff --git a/src/main/java/me/videogamesm12/hotbarsplus/core/universal/ConfigurationManager.java b/src/main/java/me/videogamesm12/hotbarsplus/core/universal/ConfigurationManager.java index c75fbff..7a598d8 100644 --- a/src/main/java/me/videogamesm12/hotbarsplus/core/universal/ConfigurationManager.java +++ b/src/main/java/me/videogamesm12/hotbarsplus/core/universal/ConfigurationManager.java @@ -22,6 +22,8 @@ import lombok.Getter; import me.videogamesm12.hotbarsplus.api.config.Configuration; +import me.videogamesm12.hotbarsplus.api.event.navigation.HotbarNavigateEvent; +import me.videogamesm12.hotbarsplus.api.event.notification.NotificationTypeRegistered; import me.videogamesm12.hotbarsplus.core.HBPCore; import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents; import net.minecraft.client.MinecraftClient; @@ -74,6 +76,10 @@ public void load() } ClientLifecycleEvents.CLIENT_STOPPING.register(this); + + // This is a hack to get both of these things working. + HotbarNavigateEvent.EVENT.register(config.getLastHotbarPage()); + NotificationTypeRegistered.EVENT.register(config.getNotificationConfig()); } public void save() diff --git a/src/main/java/me/videogamesm12/hotbarsplus/core/universal/NotificationManager.java b/src/main/java/me/videogamesm12/hotbarsplus/core/universal/NotificationManager.java index e96c318..0aadd79 100644 --- a/src/main/java/me/videogamesm12/hotbarsplus/core/universal/NotificationManager.java +++ b/src/main/java/me/videogamesm12/hotbarsplus/core/universal/NotificationManager.java @@ -25,9 +25,11 @@ import me.videogamesm12.hotbarsplus.api.event.navigation.HotbarNavigateEvent; import me.videogamesm12.hotbarsplus.api.event.notification.NotificationTypeRegistered; import me.videogamesm12.hotbarsplus.api.event.success.BackupSuccessEvent; +import me.videogamesm12.hotbarsplus.api.provider.INotificationRouteProvider; import me.videogamesm12.hotbarsplus.api.util.Util; import me.videogamesm12.hotbarsplus.core.HBPCore; import me.videogamesm12.hotbarsplus.core.notifications.ActionBarNotification; +import net.fabricmc.loader.api.FabricLoader; import net.kyori.adventure.text.Component; import net.minecraft.text.Text; import net.minecraft.util.ActionResult; @@ -49,7 +51,9 @@ public class NotificationManager public NotificationManager() { - register(ActionBarNotification.class); + // Routes are now registered in this fashion. + FabricLoader.getInstance().getEntrypointContainers("hotbarsplus", INotificationRouteProvider.class) + .forEach(container -> container.getEntrypoint().getNotificationRoutes().forEach(this::register)); } /** @@ -69,9 +73,10 @@ public void showNotification(Component title, Component description, Component m } /** - * Registers a NotificationType. + * Registers a NotificationType. As of Hotbars+ v2.0-pre10 this method is considered internal and should not be used. * @param typeClass A class that implements NotificationType. */ + @Deprecated public void register(Class typeClass) { try diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index e84330e..3d2de21 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -16,6 +16,9 @@ "entrypoints": { "client": [ "me.videogamesm12.hotbarsplus.core.HBPCore" + ], + "hotbarsplus": [ + "me.videogamesm12.hotbarsplus.core.provider.NotificationRouteProvider" ] }, "mixins": [