Skip to content

Commit

Permalink
New ver with new examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Mqzn committed Oct 16, 2024
1 parent 1369b99 commit 9a5cb5a
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 117 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
}

group = "io.github.mqzen"
version = "1.1.8d"
version = "1.1.9"

repositories {
gradlePluginPortal()
Expand Down
136 changes: 68 additions & 68 deletions src/test/java/io/github/mqzen/menus/ExampleMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,78 +19,78 @@

public final class ExampleMenu implements Menu {

/**
* @return The unique name for this menu
*/
@Override
public String getName() {
return "example menu";
}
/**
* @return The unique name for this menu
*/
@Override
public String getName() {
return "example menu";
}

/**
* @param extraData the data container for this menu for extra data
* @param opener the player who is opening this menu
* @return the title for this menu
*/
@Override
public @NotNull MenuTitle getTitle(DataRegistry extraData, Player opener) {
return MenuTitles.createLegacy("&cExample Menu");
}
/**
* @param extraData the data container for this menu for extra data
* @param opener the player who is opening this menu
* @return the title for this menu
*/
@Override
public @NotNull MenuTitle getTitle(DataRegistry extraData, Player opener) {
return MenuTitles.createLegacy("&cExample Menu");
}

/**
* @param extraData the data container for this menu for extra data
* @param opener the player who is opening this menu
* @return the capacity/size for this menu
*/
@Override
public @NotNull Capacity getCapacity(DataRegistry extraData, Player opener) {
return Capacity.ofRows(3);//Alternative approach: Capacity.ofRows(3)
}
/**
* @param extraData the data container for this menu for extra data
* @param opener the player who is opening this menu
* @return the capacity/size for this menu
*/
@Override
public @NotNull Capacity getCapacity(DataRegistry extraData, Player opener) {
return Capacity.ofRows(3);//Alternative approach: Capacity.ofRows(3)
}

/**
* Creates the content for the menu
*
* @param extraData the data container for this menu for extra data
* @param opener the player opening this menu
* @param capacity the capacity set by the user above
* @return the content of the menu to add (this includes items)
*/
@Override
public @NotNull Content getContent(DataRegistry extraData,
Player opener, Capacity capacity) {
/**
* Creates the content for the menu
*
* @param extraData the data container for this menu for extra data
* @param opener the player opening this menu
* @param capacity the capacity set by the user above
* @return the content of the menu to add (this includes items)
*/
@Override
public @NotNull Content getContent(DataRegistry extraData,
Player opener, Capacity capacity) {

Button borderPane = Button.clickable(
ItemBuilder.legacy(Material.STAINED_GLASS_PANE, 1, (short) 5)
.setDisplay("&r").build(),
ButtonClickAction.plain((menuView, event) -> {
event.setCancelled(true);
//we want nothing to happen here
menuView.updateButton(event.getSlot(), (button)-> {
assert button.getItem() != null;
var item = button.getItem();
short buttonData = button.getNamedData("data");
buttonData++;
if(buttonData > 12) {
buttonData = 0;
}
button.setNamedData("data", buttonData);
item.setDurability(buttonData);
button.setItem(item);
});
Button borderPane = Button.clickable(
ItemBuilder.legacy(Material.STAINED_GLASS_PANE, 1, (short) 5)
.setDisplay("&r").build(),
ButtonClickAction.plain((menuView, event) -> {
event.setCancelled(true);
//we want nothing to happen here
menuView.updateButton(event.getSlot(), (button) -> {
assert button.getItem() != null;
var item = button.getItem();
short buttonData = button.getNamedData("data");
buttonData++;
if (buttonData > 12) {
buttonData = 0;
}
button.setNamedData("data", buttonData);
item.setDurability(buttonData);
button.setItem(item);
});

})
).setNamedData("data", (short)5);
})
).setNamedData("data", (short) 5);

return Content.builder(capacity)
.iterate(Slot.of(10), Slot.of(16), Direction.RIGHT, ((content, slot) -> {
content.setButton(slot, borderPane);
}))
.build();
}
@Override
public void onClick(MenuView<?> playerMenuView, InventoryClickEvent event) {
//happens after button click is executed
event.setCancelled(true);
}
return Content.builder(capacity)
.iterate(Slot.of(10), Slot.of(16), Direction.RIGHT, ((content, slot) -> {
content.setButton(slot, borderPane);
}))
.build();
}

@Override
public void onClick(MenuView<?> playerMenuView, InventoryClickEvent event) {
//happens after button click is executed
event.setCancelled(true);
}
}
97 changes: 49 additions & 48 deletions src/test/java/io/github/mqzen/menus/ExamplePlainPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,61 +16,62 @@

public final class ExamplePlainPage extends Page {

private final int amountOfItems;
public ExamplePlainPage(int amountOfItems) {
this.amountOfItems = amountOfItems;
}
private final int amountOfItems;

public ExamplePlainPage(int amountOfItems) {
this.amountOfItems = amountOfItems;
}

/**
* The number of buttons this pageView should have
*
* @param capacity the capacity for the page
* @param opener opener of this pagination
* @return The number of buttons this pageView should have
*/
@Override
public FillRange getFillRange(Capacity capacity, Player opener) {
return FillRange.start(capacity).end(Slot.of(amountOfItems));
}

@Override
public ItemStack nextPageItem(Player player) {
return ItemBuilder.legacy(Material.PAPER)
.setDisplay("&aNext page")
.build();
}
/**
* The number of buttons this pageView should have
*
* @param capacity the capacity for the page
* @param opener opener of this pagination
* @return The number of buttons this pageView should have
*/
@Override
public FillRange getFillRange(Capacity capacity, Player opener) {
return FillRange.start(capacity).end(Slot.of(amountOfItems));
}

@Override
public ItemStack previousPageItem(Player player) {
return ItemBuilder.legacy(Material.PAPER)
.setDisplay("&ePrevious page")
.build();
}
@Override
public ItemStack nextPageItem(Player player) {
return ItemBuilder.legacy(Material.PAPER)
.setDisplay("&aNext page")
.build();
}

@Override
public String getName() {
return "Example plain-pagination";
}
@Override
public ItemStack previousPageItem(Player player) {
return ItemBuilder.legacy(Material.PAPER)
.setDisplay("&ePrevious page")
.build();
}

@Override
public @NotNull MenuTitle getTitle(DataRegistry dataRegistry, Player player) {
int index = dataRegistry.getData("index");
return MenuTitles.createLegacy("&6Example Plain page #" + (index+1));
}
@Override
public String getName() {
return "Example plain-pagination";
}

@Override
public @NotNull Capacity getCapacity(DataRegistry dataRegistry, Player player) {
return Capacity.ofRows(3);
}
@Override
public @NotNull MenuTitle getTitle(DataRegistry dataRegistry, Player player) {
int index = dataRegistry.getData("index");
return MenuTitles.createLegacy("&6Example Plain page #" + (index + 1));
}

@Override
public @NotNull Capacity getCapacity(DataRegistry dataRegistry, Player player) {
return Capacity.ofRows(3);
}

@Override
public @NotNull Content getContent(DataRegistry extraData, Player opener, Capacity capacity) {
var builder = Content.builder(capacity);
for(int i = 0; i < amountOfItems; i++) {
builder.setButton(i, new ExampleMenuComponent("" + i).toButton());
}
return builder.build();
}

@Override
public @NotNull Content getContent(DataRegistry extraData, Player opener, Capacity capacity) {
var builder = Content.builder(capacity);
for (int i = 0; i < amountOfItems; i++) {
builder.setButton(i, new ExampleMenuComponent("" + i).toButton());
}
return builder.build();
}
}

0 comments on commit 9a5cb5a

Please sign in to comment.