Fix hook retrieval not working properly

This commit is contained in:
William278 committed 2023-03-22 15:58:50 +00:00
1 parent c316d290c5
commit 42adc13425
6 files changed
+66 -86

No files matched your search

@@ -166,38 +166,21 @@ public interface HuskHomes extends TaskRunner, EventDispatcher {
* @return the {@link Set} of active {@link Hook}s
*/
@NotNull
Set<Hook> getPluginHooks();
List<Hook> getHooks();
/**
* Finds the {@link Hook} of the given class instance from the set of active {@link Hook}s
*
* @param hookClass the class of the {@link Hook} to get
* @param <H> the type of the {@link Hook}
* @return the {@link Hook} instance, or an empty {@link Optional} if not found
*/
default <H extends Hook> Optional<H> getHook(@NotNull Class<H> hookClass) {
return getPluginHooks().stream()
.filter(hook -> hook.getClass() == hookClass)
.findFirst()
.map(hookClass::cast);
default <T extends Hook> Optional<T> getHook(@NotNull Class<T> hookClass) {
return getHooks().stream()
.filter(hook -> hookClass.isAssignableFrom(hook.getClass()))
.map(hookClass::cast)
.findFirst();
}
/**
* Gets the {@link MapHook} being used to display public homes and warps on a web map, if there is one, and it is enabled
*
* @return the {@link MapHook} optionally being used
*/
default Optional<MapHook> getMapHook() {
return getSettings().doMapHook() ? getHook(MapHook.class) : Optional.empty();
}
/**
* Gets the {@link EconomyHook} being used to charge players for commands, if there is one, and it is enabled
*
* @return the {@link EconomyHook} optionally being used
*/
default Optional<EconomyHook> getEconomyHook() {
return getSettings().doEconomy() ? getHook(EconomyHook.class) : Optional.empty();
return getHook(EconomyHook.class);
}
default Optional<MapHook> getMapHook() {
return getHook(MapHook.class);
}
/**