Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public abstract IFRenderContext createRenderContext(
@NotNull UUID id,
@NotNull RootView root,
@NotNull ViewConfig config,
@NotNull ViewContainer container,
ViewContainer container,
@NotNull Map<String, Viewer> viewers,
Viewer subject,
Object initialData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@
import me.devnatan.inventoryframework.Viewer;
import me.devnatan.inventoryframework.component.BukkitItemComponentBuilder;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public final class RenderContext extends PlatformRenderContext<BukkitItemComponentBuilder, Context> implements Context {
public final class RenderContext extends PlatformRenderContext<BukkitItemComponentBuilder, Context>
implements Context, InventoryHolder {

private final Player player;

Expand All @@ -31,7 +34,7 @@ public RenderContext(
@NotNull UUID id,
@NotNull View root,
@NotNull ViewConfig config,
@NotNull ViewContainer container,
ViewContainer container,
@NotNull Map<String, Viewer> viewers,
Viewer subject,
Object initialData) {
Expand Down Expand Up @@ -163,4 +166,9 @@ public int hashCode() {
public String toString() {
return "RenderContext{" + "player=" + player + "} " + super.toString();
}

@Override
public @NotNull Inventory getInventory() {
return ((BukkitViewContainer) getContainerOrThrow()).getInventory();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public class BukkitElementFactory extends ElementFactory {
return new View();
}

// TODO Test it
@Override
public @NotNull ViewContainer createContainer(@NotNull IFContext context) {
final ViewConfig config = context.getConfig();
Expand All @@ -49,8 +48,7 @@ public class BukkitElementFactory extends ElementFactory {
finalType.getMaxSize(),
context.getRoot().getClass().getName()));

final InventoryHolder holder =
context.getRoot() instanceof InventoryHolder ? (InventoryHolder) context.getRoot() : null;
final InventoryHolder holder = context instanceof InventoryHolder ? (InventoryHolder) context : null;
final Inventory inventory =
InventoryFactory.current().createInventory(holder, finalType, size, config.getTitle());

Expand Down Expand Up @@ -80,7 +78,7 @@ public IFRenderContext createRenderContext(
@NotNull UUID id,
@NotNull RootView root,
@NotNull ViewConfig config,
@NotNull ViewContainer container,
ViewContainer container,
@NotNull Map<String, Viewer> viewers,
Viewer subject,
Object initialData) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public abstract class PlatformRenderContext<T extends ItemComponentBuilder<T, C>
private final Viewer subject;

// --- Inherited ---
private final ViewContainer container;
private ViewContainer container;
private boolean rendered;

// --- Properties ---
Expand All @@ -49,7 +49,7 @@ public abstract class PlatformRenderContext<T extends ItemComponentBuilder<T, C>
@NotNull UUID id,
@NotNull PlatformView root,
@NotNull ViewConfig config,
@NotNull ViewContainer container,
ViewContainer container,
@NotNull Map<String, Viewer> viewers,
Viewer subject,
Object initialData) {
Expand Down Expand Up @@ -233,6 +233,11 @@ public final void layoutSlot(char character, @NotNull BiConsumer<Integer, T> fac
return container;
}

@ApiStatus.Internal
public void setContainer(ViewContainer container) {
this.container = container;
}

@Override
public final @NotNull ViewConfig getConfig() {
return config;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import me.devnatan.inventoryframework.*;
import me.devnatan.inventoryframework.context.IFOpenContext;
import me.devnatan.inventoryframework.context.IFRenderContext;
import me.devnatan.inventoryframework.context.PlatformRenderContext;
import me.devnatan.inventoryframework.exception.InvalidLayoutException;
import me.devnatan.inventoryframework.internal.ElementFactory;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -70,18 +71,19 @@ IFRenderContext createRenderContext(IFOpenContext openContext) {

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,
null,
new HashMap<>(),
openContext.isShared() ? null : openContext.getViewer(),
openContext.getInitialData());

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

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

Expand Down
Loading