DevNatan / inventory-framework

Minecraft Inventory API framework
MIT License
127 stars 22 forks source link

Needs a more detailed error message #579

Open github-actions[bot] opened 11 months ago

github-actions[bot] commented 11 months ago

https://github.com/DevNatan/inventory-framework/blob/ea9b4baa26e76b7f413bd316b97af2b0b34e6b3b/inventory-framework-platform/src/main/java/me/devnatan/inventoryframework/pipeline/PlatformOpenInterceptor.java#L66


        if (skipOpen) return;

        final PlatformView root = (PlatformView) openContext.getRoot();
        final IFRenderContext render = createRenderContext(openContext);
        root.addContext(render);
        root.renderContext(render);
    }

    @SuppressWarnings("unchecked")
    IFRenderContext createRenderContext(IFOpenContext openContext) {
        @SuppressWarnings("rawtypes")
        final PlatformView root = (PlatformView) openContext.getRoot();

        final ViewConfig contextConfig = openContext.getConfig();
        final String[] layout = contextConfig.getLayout();
        if (layout != null) {
            if (contextConfig.getSize() != 0 && contextConfig.getSize() != layout.length) {
                // TODO Needs a more detailed error message
                throw new InvalidLayoutException("The layout length differs from the set inventory size.");
            }
            openContext.modifyConfig().size(layout.length);
        }

        final ElementFactory elementFactory = root.getElementFactory();

        ViewContainer createdContainer = openContext.getContainer();
        if (createdContainer == null) createdContainer = elementFactory.createContainer(openContext);

        final IFRenderContext renderContext = elementFactory.createRenderContext(
                openContext.getId(),
                root,
                openContext.getConfig(),
                createdContainer,
                new HashMap<>(),
                openContext.isShared() ? null : openContext.getViewer(),
                openContext.getInitialData());

        renderContext.setEndless(openContext.isEndless());
        openContext.getStateValues().forEach(renderContext::initializeState);

        for (final Viewer viewer : openContext.getIndexedViewers().values()) {
            if (!viewer.isTransitioning()) viewer.setActiveContext(renderContext);
            // TODO Pass viewer object as parameter instead
            root.onViewerAdded(renderContext, viewer.getPlatformInstance(), renderContext.getInitialData());
            renderContext.addViewer(viewer);
        }

        renderContext.setActive(true);
        return renderContext;
    }
}