-
-
Save SocraticPhoenix/c7be9f432683270fc3c79aa55f35d3a5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class GridFinalizer implements Finalizer<InventoryButtonPage, GridTarget> { | |
@Override | |
public void display(Player player, GridTarget target, InventoryButtonPage page, PluginContainer owner) { | |
CustomInventoryBuilder builder = new CustomInventoryBuilder(); | |
builder.of(InventoryArchetypes.CHEST).property(new InventoryDimension(9, target.height())) | |
.property(new InventoryTitle(page.title())); | |
int offset = (9 - target.length()) / 2; | |
offset = offset < 0 ? 0 : offset; | |
Inventory inventory = builder.build(owner.getInstance().get()); | |
for (int x = 0; x < target.length(); x++) { | |
for (int y = 0; y < target.height(); y++) { | |
Inventory slot = inventory.query(new SlotPos(x + offset, y)).query(Slot.class); | |
if(slot instanceof Slot) { | |
target.get(x, y).ifPresent(stack -> ((Slot) slot).set(stack)); | |
} | |
} | |
} | |
player.closeInventory(Cause.of(NamedCause.source(MenuPlugin.container()), NamedCause.of("reason", InventoryReason.NEW_MENU))); | |
player.openInventory(inventory, Cause.of(NamedCause.source(MenuPlugin.container()), NamedCause.of("reason", InventoryReason.OPEN_MENU))); | |
} | |
@Override | |
public Class<InventoryButtonPage> page() { | |
return InventoryButtonPage.class; | |
} | |
@Override | |
public Class<GridTarget> target() { | |
return GridTarget.class; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment