diff --git a/inventory-framework-platform/src/main/java/me/devnatan/inventoryframework/IFViewFrame.java b/inventory-framework-platform/src/main/java/me/devnatan/inventoryframework/IFViewFrame.java index ca24ddc8..ef3b2629 100644 --- a/inventory-framework-platform/src/main/java/me/devnatan/inventoryframework/IFViewFrame.java +++ b/inventory-framework-platform/src/main/java/me/devnatan/inventoryframework/IFViewFrame.java @@ -1,6 +1,12 @@ package me.devnatan.inventoryframework; -import java.util.*; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; +import java.util.function.Consumer; import java.util.stream.Collectors; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Contract; @@ -12,6 +18,7 @@ abstract class IFViewFrame, V extends PlatformView registeredViews = new HashMap<>(); protected final Map viewerById = new HashMap<>(); + protected Consumer defaultConfig; protected IFViewFrame() {} @@ -140,4 +147,29 @@ void removeViewer(@NotNull Viewer viewer) { viewerById.remove(viewer.getId()); } } + + /** + * Sets the default configuration that will be used for all views registered from this framework. + *

+ * This API is experimental and is not subject to the general compatibility guarantees + * such API may be changed or may be removed completely in any further release. + * + * @return This framework instance. + * @see Default Configuration on Wiki + */ + @SuppressWarnings("unchecked") + @ApiStatus.Experimental + public final S defaultConfig(@NotNull Consumer defaultConfig) { + this.defaultConfig = defaultConfig; + return (S) this; + } + + /** + * The default configuration applier of this framework. + * + * @return The default configuration applier of this framework. + */ + final Consumer getDefaultConfig() { + return defaultConfig; + } } diff --git a/inventory-framework-platform/src/main/java/me/devnatan/inventoryframework/PlatformView.java b/inventory-framework-platform/src/main/java/me/devnatan/inventoryframework/PlatformView.java index 708a9255..83bf416a 100644 --- a/inventory-framework-platform/src/main/java/me/devnatan/inventoryframework/PlatformView.java +++ b/inventory-framework-platform/src/main/java/me/devnatan/inventoryframework/PlatformView.java @@ -158,8 +158,17 @@ public final void navigateTo( getFramework().getRegisteredViewByType(target).open(Collections.singletonList(viewer), initialData); } + /** + * Creates a new ViewConfigBuilder instance with the default platform configuration. + * Configuration is inherited from the {@link #getFramework() framework} if available. + * + * @return A new ViewConfigBuilder instance. + */ public final @NotNull ViewConfigBuilder createConfig() { - return new ViewConfigBuilder().type(ViewType.CHEST); + final ViewConfigBuilder configBuilder = new ViewConfigBuilder().type(ViewType.CHEST); + if (getFramework().getDefaultConfig() != null) + getFramework().getDefaultConfig().accept(configBuilder); + return configBuilder; } /**