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 @@ -40,7 +40,7 @@ class AnvilInputNMS {
private static final MethodHandle SET_PLAYER_ACTIVE_CONTAINER;
private static final MethodHandle ADD_CONTAINER_SLOT_LISTENER;
private static final MethodHandle INIT_MENU;
private static final MethodHandle GET_TOP_INVENTORY;
private static final MethodHandle GET_TOP_INVENTORY;

// FIELDS
private static final MethodHandle CONTAINER_CHECK_REACHABLE;
Expand Down Expand Up @@ -75,7 +75,8 @@ class AnvilInputNMS {
CONTAINER, "a", MethodType.methodType(void.class, getNMSClass("world.inventory.ICrafting")));
INIT_MENU = getMethod(ENTITY_PLAYER, "a", MethodType.methodType(void.class, CONTAINER));

GET_TOP_INVENTORY = getMethod(InventoryView.class, "getTopInventory", MethodType.methodType(Inventory.class));
GET_TOP_INVENTORY =
getMethod(InventoryView.class, "getTopInventory", MethodType.methodType(Inventory.class));
} catch (Exception exception) {
throw new RuntimeException(
"Unsupported version for Anvil Input feature: " + ReflectionUtils.getVersionInformation(),
Expand All @@ -95,7 +96,8 @@ public static Inventory open(Player player, Object title, String initialInput) {
final Object anvilContainer = ANVIL_CONSTRUCTOR.invoke(windowId, GET_PLAYER_INVENTORY.invoke(entityPlayer));
CONTAINER_CHECK_REACHABLE.invoke(anvilContainer, false);

final AnvilInventory inventory = (AnvilInventory) GET_TOP_INVENTORY.invoke(InventoryUpdate.getBukkitView.invoke(anvilContainer));
final AnvilInventory inventory =
(AnvilInventory) GET_TOP_INVENTORY.invoke(InventoryUpdate.getBukkitView.invoke(anvilContainer));

inventory.setMaximumRepairCost(0);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ public interface IFCloseContext extends IFConfinedContext {
@NotNull
ViewContainer getContainer();

/**
* <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>
*/
@ApiStatus.Internal
Object getPlatformEvent();
/**
* <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>
*/
@ApiStatus.Internal
Object getPlatformEvent();
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ public abstract IFSlotRenderContext createSlotRenderContext(
* @param viewer The viewer that is currently the subject of the event of close.
* @return A new close context instance.
*/
public abstract IFCloseContext createCloseContext(@NotNull Viewer viewer, @NotNull IFRenderContext parent, @NotNull Object origin);
public abstract IFCloseContext createCloseContext(
@NotNull Viewer viewer, @NotNull IFRenderContext parent, @NotNull Object origin);

/**
* Creates a new platform builder instance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ List<ComponentFactory> resolveFromLayoutSlot(IFRenderContext context) {

private boolean isSlotNotAvailableForAutoFilling(IFRenderContext context, int slot) {
if (!context.getContainer().getType().canPlayerInteractOn(slot)) return true;
if (context.getContainer().getSize() >= slot) return false;

// fast path -- check for already rendered items
if (context.getContainer().hasItem(slot)) return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,23 @@ public class CloseContext extends PlatformConfinedContext implements IFCloseCont
private final Viewer subject;
private final Player player;
private final IFRenderContext parent;
private final InventoryCloseEvent closeOrigin;
private final InventoryCloseEvent closeOrigin;

private boolean cancelled;

@ApiStatus.Internal
public CloseContext(@NotNull Viewer subject, @NotNull IFRenderContext parent, @NotNull InventoryCloseEvent closeOrigin) {
public CloseContext(
@NotNull Viewer subject, @NotNull IFRenderContext parent, @NotNull InventoryCloseEvent closeOrigin) {
this.subject = subject;
this.player = ((BukkitViewer) subject).getPlayer();
this.parent = parent;
this.closeOrigin = closeOrigin;
this.closeOrigin = closeOrigin;
}

@Override
public Object getPlatformEvent() {
return closeOrigin;
}
@Override
public Object getPlatformEvent() {
return closeOrigin;
}

// TODO Needs documentation
public final @NotNull Player getPlayer() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ public IFSlotRenderContext createSlotRenderContext(
}

@Override
public IFCloseContext createCloseContext(@NotNull Viewer viewer, @NotNull IFRenderContext parent, @NotNull Object closeOrigin) {
public IFCloseContext createCloseContext(
@NotNull Viewer viewer, @NotNull IFRenderContext parent, @NotNull Object closeOrigin) {
return new CloseContext(viewer, parent, (InventoryCloseEvent) closeOrigin);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ internal class IFInventoryListener(

val context: IFRenderContext = viewer.activeContext
val root: RootView = context.getRoot()
val closeContext: IFCloseContext = root.elementFactory.createCloseContext(viewer, context, event)
val closeContext: IFCloseContext =
root.elementFactory.createCloseContext(viewer, context, event)

root.pipeline.execute(StandardPipelinePhases.CLOSE, closeContext)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class CloseContext
constructor(
subject: Viewer,
private val parent: IFRenderContext,
val origin: InventoryCloseEvent
val origin: InventoryCloseEvent,
) : PlatformConfinedContext(),
IFCloseContext,
Context {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,11 @@ class MinestomElementFactory : ElementFactory() {
viewer: Viewer?,
): IFSlotRenderContext = SlotRenderContext(slot, parent, viewer)

override fun createCloseContext(viewer: Viewer, parent: IFRenderContext, origin: Any): IFCloseContext = CloseContext(viewer, parent,origin as InventoryCloseEvent)
override fun createCloseContext(
viewer: Viewer,
parent: IFRenderContext,
origin: Any,
): IFCloseContext = CloseContext(viewer, parent, origin as InventoryCloseEvent)

override fun createComponentBuilder(root: VirtualView): ComponentBuilder<*, Context> = MinestomItemComponentBuilder(root)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,12 @@ public IFSlotRenderContext createSlotRenderContext(
}

@Override
public IFCloseContext createCloseContext(@NotNull Viewer viewer, @NotNull IFRenderContext parent, @NotNull Object origin) {
public IFCloseContext createCloseContext(
@NotNull Viewer viewer, @NotNull IFRenderContext parent, @NotNull Object origin) {
IFCloseContext mock = mock(IFCloseContext.class);
when(mock.getViewer()).thenReturn(viewer);
when(mock.getParent()).thenReturn(parent);
when(mock.getPlatformEvent()).thenReturn(origin);
when(mock.getPlatformEvent()).thenReturn(origin);
return mock;
}

Expand Down
Loading