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 @@ -7,10 +7,7 @@
import java.util.function.Predicate;
import me.devnatan.inventoryframework.InventoryFrameworkException;
import me.devnatan.inventoryframework.VirtualView;
import me.devnatan.inventoryframework.context.IFContext;
import me.devnatan.inventoryframework.context.IFSlotClickContext;
import me.devnatan.inventoryframework.context.IFSlotContext;
import me.devnatan.inventoryframework.context.IFSlotRenderContext;
import me.devnatan.inventoryframework.context.*;
import me.devnatan.inventoryframework.state.State;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.UnmodifiableView;
Expand Down Expand Up @@ -178,7 +175,8 @@ public void updated(@NotNull IFSlotRenderContext context) {

@Override
public void clear(@NotNull IFContext context) {
context.getContainer().removeItem(getPosition());
((IFRenderContext) context).getContainer().removeItem(getPosition());

setVisible(false);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package me.devnatan.inventoryframework.context;

import me.devnatan.inventoryframework.ViewContainer;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;

public interface IFCloseContext extends IFConfinedContext {

Expand Down Expand Up @@ -28,4 +30,12 @@ public interface IFCloseContext extends IFConfinedContext {
* @param cancelled If this context should be cancelled.
*/
void setCancelled(boolean cancelled);

/**
* The container of this context.
*
* @return The container of this context.
*/
@NotNull
ViewContainer getContainer();
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import java.util.UUID;
import me.devnatan.inventoryframework.RootView;
import me.devnatan.inventoryframework.ViewConfig;
import me.devnatan.inventoryframework.ViewContainer;
import me.devnatan.inventoryframework.Viewer;
import me.devnatan.inventoryframework.VirtualView;
import me.devnatan.inventoryframework.component.Component;
Expand Down Expand Up @@ -81,20 +80,6 @@ public interface IFContext extends VirtualView, StateValueHost {
@ApiStatus.Internal
void removeViewer(@NotNull Viewer viewer);

/**
* The container of this context.
* <p>
* The container is where all the changes that are displayed to the user are applied.
* <p>
* Direct modifications to the container must launch an inventory modification error, which
* signals that that function will change the container for whoever is seeing what, which, if it
* is not possible at that moment or if the container is not sufficiently prepared for this,
* it must fail.
*
* @return The container of this context.
*/
ViewContainer getContainer();

/**
* View root from which this context originated.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.List;
import java.util.function.BiFunction;
import me.devnatan.inventoryframework.ViewContainer;
import me.devnatan.inventoryframework.component.ComponentFactory;
import me.devnatan.inventoryframework.internal.LayoutSlot;
import org.jetbrains.annotations.ApiStatus;
Expand Down Expand Up @@ -38,4 +39,19 @@ public interface IFRenderContext extends IFConfinedContext {
*/
@ApiStatus.Internal
BiFunction<Integer, Integer, ComponentFactory> getAvailableSlotFactory();

/**
* The container of this context.
* <p>
* The container is where all the changes that are displayed to the user are applied.
* <p>
* Direct modifications to the container must launch an inventory modification error, which
* signals that that function will change the container for whoever is seeing what, which, if it
* is not possible at that moment or if the container is not sufficiently prepared for this,
* it must fail.
*
* @return The container of this context.
*/
@NotNull
ViewContainer getContainer();
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package me.devnatan.inventoryframework.context;

import me.devnatan.inventoryframework.ViewContainer;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;

/**
* Represents a context in which there is a specific slot related to it, the main context
Expand All @@ -25,18 +27,6 @@ public interface IFSlotContext extends IFContext {
@ApiStatus.Internal
IFRenderContext getParent();

/**
* Clears this slot from the current context.
* <p>
* The slot will only be cleaned on the next update, so if you want it cleaned immediately
* update the slot using {@link #update()}.
*
* <p><b><i> 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. </i></b>
*/
@ApiStatus.Experimental
void clear();

/**
* Returns the slot position of this context in the current container.
*
Expand All @@ -48,42 +38,25 @@ public interface IFSlotContext extends IFContext {
void setSlot(int slot);

/**
* Returns the wrapper containing the item related to this context.
*
* <p><b><i>This is an internal inventory-framework API that should not be used from outside of
* this library. No compatibility guarantees are provided.</i></b>
* Whether this context originated from an interaction coming from the actor's container and not
* from the view's container.
*
* @return The current item wrapper.
* @return If this context originated from the actor's container
*/
// @ApiStatus.Internal
// @NotNull
// ItemWrapper getItemWrapper();
boolean isOnEntityContainer();

/**
* Returns the current item of this context.
* The container of this context.
* <p>
* The item returned is not necessarily the item positioned in the slot, there are cases, for
* example in {@link IFSlotMoveContext}, in which the current item may be the item the entity
* is interacting with and not a positioned item.
*
* @return The current item.
*/
// @NotNull
// ItemWrapper getCurrentItem();

/**
* Sets the new item for this slot for this context.
*
* @param item The new item that'll be set.
* @throws InventoryModificationException When the container is changed.
*/
// void setItem(@Nullable Object item) throws InventoryModificationException;

/**
* Whether this context originated from an interaction coming from the actor's container and not
* from the view's container.
* The container is where all the changes that are displayed to the user are applied.
* <p>
* Direct modifications to the container must launch an inventory modification error, which
* signals that that function will change the container for whoever is seeing what, which, if it
* is not possible at that moment or if the container is not sufficiently prepared for this,
* it must fail.
*
* @return If this context originated from the actor's container
* @return The container of this context.
*/
boolean isOnEntityContainer();
@NotNull
ViewContainer getContainer();
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,18 @@ public interface IFSlotRenderContext extends IFSlotContext, IFConfinedContext {

void setCancelled(boolean cancelled);

/**
* Clears this slot from the current context.
* <p>
* The slot will only be cleaned on the next update, so if you want it cleaned immediately
* update the slot using {@link #update()}.
*
* <p><b><i> 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. </i></b>
*/
@ApiStatus.Experimental
void clear();

/**
* Checks if the item in this context has been changed.
*
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,7 @@ final void tryThrowDoNotWorkWithSharedContext(String replacement) {
@Override
public String toString() {
return "AbstractIFContext{" + "id="
+ getId() + ", container="
+ getContainer() + ", viewers="
+ getId() + ", viewers="
+ getIndexedViewers() + ", config="
+ getConfig() + ", initialData="
+ getInitialData() + "} "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,7 @@
import java.util.function.Supplier;
import me.devnatan.inventoryframework.ViewContainer;
import me.devnatan.inventoryframework.VirtualView;
import me.devnatan.inventoryframework.context.Context;
import me.devnatan.inventoryframework.context.IFContext;
import me.devnatan.inventoryframework.context.IFSlotClickContext;
import me.devnatan.inventoryframework.context.IFSlotContext;
import me.devnatan.inventoryframework.context.IFSlotRenderContext;
import me.devnatan.inventoryframework.context.SlotClickContext;
import me.devnatan.inventoryframework.context.SlotContext;
import me.devnatan.inventoryframework.context.SlotRenderContext;
import me.devnatan.inventoryframework.context.*;
import me.devnatan.inventoryframework.state.State;
import me.devnatan.inventoryframework.utils.SlotConverter;
import org.bukkit.inventory.ItemStack;
Expand Down Expand Up @@ -110,7 +103,7 @@ public BukkitItemComponentBuilder withSlot(int slot) {

@Override
public BukkitItemComponentBuilder withSlot(int row, int column) {
final ViewContainer container = ((IFContext) root).getContainer();
final ViewContainer container = ((IFRenderContext) root).getContainer();
return withSlot(SlotConverter.convertSlot(row, column, container.getRowsCount(), container.getColumnsCount()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public final RenderContext getParent() {
}

@Override
public final ViewContainer getContainer() {
public final @NotNull ViewContainer getContainer() {
return getParent().getContainer();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import me.devnatan.inventoryframework.BukkitViewer;
import me.devnatan.inventoryframework.InventoryFrameworkException;
import me.devnatan.inventoryframework.UnsupportedOperationInSharedContextException;
import me.devnatan.inventoryframework.View;
import me.devnatan.inventoryframework.ViewConfig;
import me.devnatan.inventoryframework.ViewConfigBuilder;
import me.devnatan.inventoryframework.ViewContainer;
import me.devnatan.inventoryframework.Viewer;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.ApiStatus;
Expand Down Expand Up @@ -109,11 +107,6 @@ public final Viewer getSubject() {
return subject;
}

@Override
public final ViewContainer getContainer() {
throw new InventoryFrameworkException("Container is not available in open phase");
}

@Override
public final void waitUntil(@NotNull CompletableFuture<Void> task) {
this.waitTask = task;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,6 @@ public final void setSlot(int slot) {
this.slot = slot;
}

@Override
public final void clear() {
// TODO do something
throw new UnsupportedOperationException();
}

@Override
public final @NotNull Map<String, Viewer> getIndexedViewers() {
return getParent().getIndexedViewers();
Expand Down Expand Up @@ -128,7 +122,7 @@ public final void watchState(long id, StateWatcher listener) {
}

@Override
public final ViewContainer getContainer() {
public final @NotNull ViewContainer getContainer() {
return getParent().getContainer();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public final ItemStack getItem() {

public final void setItem(ItemStack item) {
this.item = item;
setChanged(true);
}

@Override
Expand All @@ -45,6 +46,11 @@ public final void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}

@Override
public void clear() {
setItem(null);
}

@Override
public final boolean hasChanged() {
return changed;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ public void removeContext(@NotNull TContext context) {
* @param context The context to render.
*/
@ApiStatus.Internal
public void renderContext(@NotNull TContext context) {
public void renderContext(@NotNull TRenderContext context) {
getPipeline().execute(context);

@SuppressWarnings("rawtypes")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ abstract class PlatformConfinedContext extends PlatformContext implements IFConf

@Override
public void closeForPlayer() {
getContainer().close(getViewer());
getContainerOrThrow().close(getViewer());
}

@Override
Expand All @@ -27,11 +27,11 @@ public void openForPlayer(@NotNull Class<? extends RootView> other, Object initi

@Override
public void updateTitleForPlayer(@NotNull String title) {
getContainer().changeTitle(title, getViewer());
getContainerOrThrow().changeTitle(title, getViewer());
}

@Override
public void resetTitleForPlayer() {
getContainer().changeTitle(null, getViewer());
getContainerOrThrow().changeTitle(null, getViewer());
}
}
Loading