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 @@ -53,6 +53,7 @@ class SampleServer {
val viewFrame =
ViewFrame
.create(handler)
.enableDebug()
.with(Failing(), SimplePagination(), ScheduledView())
.register()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,18 @@ public class SamplePlugin extends JavaPlugin {
public void onEnable() {
ViewFrame viewFrame = ViewFrame.create(this)
.install(AnvilInputFeature.AnvilInput)
.enableDebug()
.with(
new AnvilInputSample(),
new Failing(),
new SimplePagination(),
new AutoUpdate(),
new PaginationOrientation(),
new TimerSample(),
new RowColumnSample())
new RowColumnSample(),
new NavigatingBetweenViewsA(),
new NavigatingBetweenViewsB()
)
.register();

IFExampleCommandExecutor command = new IFExampleCommandExecutor(viewFrame);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,7 @@
import java.util.Map;
import me.devnatan.inventoryframework.View;
import me.devnatan.inventoryframework.ViewFrame;
import me.devnatan.inventoryframework.runtime.view.AnvilInputSample;
import me.devnatan.inventoryframework.runtime.view.AutoUpdate;
import me.devnatan.inventoryframework.runtime.view.Failing;
import me.devnatan.inventoryframework.runtime.view.PaginationOrientation;
import me.devnatan.inventoryframework.runtime.view.RowColumnSample;
import me.devnatan.inventoryframework.runtime.view.SimplePagination;
import me.devnatan.inventoryframework.runtime.view.TimerSample;
import me.devnatan.inventoryframework.runtime.view.*;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
Expand All @@ -34,6 +28,7 @@ public class IFExampleCommandExecutor implements CommandExecutor, TabCompleter {
views.put("pagination", PaginationOrientation.class);
views.put("timer", TimerSample.class);
views.put("row-column", RowColumnSample.class);
views.put("navigation", NavigatingBetweenViewsA.class);
}

private final ViewFrame viewFrame;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package me.devnatan.inventoryframework.runtime.view;

import me.devnatan.inventoryframework.View;
import me.devnatan.inventoryframework.ViewConfigBuilder;
import me.devnatan.inventoryframework.context.RenderContext;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;

public class NavigatingBetweenViewsA extends View {

@Override
public void onInit(ViewConfigBuilder config) {
config.title("A").size(3);
}

@Override
public void onFirstRender(RenderContext render) {
// Moves player to "B" view on click
render.firstSlot(new ItemStack(Material.DIAMOND))
.onClick(click -> click.openForPlayer(NavigatingBetweenViewsB.class));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package me.devnatan.inventoryframework.runtime.view;

import me.devnatan.inventoryframework.View;
import me.devnatan.inventoryframework.ViewConfigBuilder;
import me.devnatan.inventoryframework.context.RenderContext;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;

public class NavigatingBetweenViewsB extends View {

@Override
public void onInit(ViewConfigBuilder config) {
config.title("B").size(3);
}

@Override
public void onFirstRender(RenderContext render) {
// Moves player to back to "A" view on click
render.firstSlot(new ItemStack(Material.REDSTONE))
.onClick(click -> click.openForPlayer(NavigatingBetweenViewsA.class));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ public int hashCode() {

@Override
public String toString() {
return "ItemComponent{" + ", position="
return "ItemComponent{position="
+ position + ", stack="
+ stack + ", cancelOnClick="
+ cancelOnClick + ", closeOnClick="
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.util.List;
import java.util.Optional;
import java.util.function.BiFunction;

import me.devnatan.inventoryframework.VirtualView;
import me.devnatan.inventoryframework.component.ComponentFactory;
import me.devnatan.inventoryframework.component.ItemComponentBuilder;
Expand Down Expand Up @@ -46,7 +47,7 @@ List<ComponentFactory> resolveFromInitialSlot(IFRenderContext context) {

int slot = 0;
for (int i = 0; i < context.getContainer().getSize(); i++) {
while (isSlotNotAvailableForAutoFilling(context, slot)) slot++;
while (!isSlotAvailableForAutoFilling(context, slot)) slot++;

try {
final BiFunction<Integer, Integer, ComponentFactory> factory = availableSlotFactories.get(i);
Expand Down Expand Up @@ -97,7 +98,7 @@ List<ComponentFactory> resolveFromLayoutSlot(IFRenderContext context) {

// if the selected slot is not available for autofill, move it until
// we find the next an available position
while (isSlotNotAvailableForAutoFilling(context, slot)) {
while (!isSlotAvailableForAutoFilling(context, slot)) {
try {
slot = fillablePositions[i + (++offset)];
} catch (final IndexOutOfBoundsException exception) {
Expand All @@ -117,17 +118,17 @@ List<ComponentFactory> resolveFromLayoutSlot(IFRenderContext context) {
return result;
}

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

// fast path -- check for already rendered items
if (context.getContainer().hasItem(slot)) return true;
if (context.getContainer().hasItem(slot)) return false;

// we need to check component factories since components don't have been yet rendered
return context.getComponentFactories().stream()
.filter(componentFactory -> componentFactory instanceof ItemComponentBuilder)
.map(componentFactory -> (ItemComponentBuilder<?, ?>) componentFactory)
.anyMatch(itemBuilder -> itemBuilder.isContainedWithin(slot));
.noneMatch(itemBuilder -> itemBuilder.isContainedWithin(slot));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private void resolveBounded(
int cursor = 0;
for (int i = 0; i < factories.size(); i++) {
while (cursor < candidateSlots.size()
&& AvailableSlotInterceptor.isSlotNotAvailableForAutoFilling(context, candidateSlots.get(cursor)))
&& !AvailableSlotInterceptor.isSlotAvailableForAutoFilling(context, candidateSlots.get(cursor)))
cursor++;

if (cursor >= candidateSlots.size())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ class ViewFrame private constructor(
override fun register(): ViewFrame {
check(!isRegistered) { "This view frame is already registered" }

// TODO Missing Minestom specific Inventory Framework logger impl
// Check `debugEnabled` here then set up just like we do on Bukkit side

isRegistered = true
PlatformUtils.setFactory(MinestomElementFactory())
pipeline.execute(FRAME_REGISTERED, this)
Expand Down
Loading