Skip to content

Commit

Permalink
Bugfixes and rewrites of how notifications are registered
Browse files Browse the repository at this point in the history
  • Loading branch information
VideoGameSmash12 committed Apr 12, 2023
1 parent 0ec2567 commit 52a466f
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

/**
* <h1>INotificationRouteProvider</h1>
* <p>Hotbars+'s new way of registering notification routes as of v2.0-pre10.</p>
* <p>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".</p>
*/
public interface INotificationRouteProvider
{
List<Class<? extends NotificationManager.NotificationRoute>> getNotificationRoutes();
}
5 changes: 0 additions & 5 deletions src/main/java/me/videogamesm12/hotbarsplus/core/HBPCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

/**
* <h1>NotificationRouteProvider</h1>
* <p>Registers Hotbars+'s built-in notification routes (action bar and toast notifications)</p>
*/
public class NotificationRouteProvider implements INotificationRouteProvider
{
@Override
public List<Class<? extends NotificationManager.NotificationRoute>> getNotificationRoutes()
{
return Arrays.asList(ActionBarNotification.class, ToastNotification.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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));
}

/**
Expand All @@ -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<? extends NotificationRoute> typeClass)
{
try
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
"entrypoints": {
"client": [
"me.videogamesm12.hotbarsplus.core.HBPCore"
],
"hotbarsplus": [
"me.videogamesm12.hotbarsplus.core.provider.NotificationRouteProvider"
]
},
"mixins": [
Expand Down

0 comments on commit 52a466f

Please sign in to comment.