Skip to content

Commit

Permalink
Implement AnvilGUI into StringListGui so users could edit text via An…
Browse files Browse the repository at this point in the history
…vil.
  • Loading branch information
BONNe committed Jan 19, 2019
1 parent faa237d commit be7435f
Showing 1 changed file with 21 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import java.util.List;
import java.util.function.BiConsumer;

import net.wesjd.anvilgui.AnvilGUI;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.panels.PanelItem;
import world.bentobox.bentobox.api.panels.builders.PanelBuilder;
import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder;
Expand Down Expand Up @@ -61,9 +63,9 @@ private void build()

panelBuilder.item(8, this.getButton(Button.CANCEL));

for (String element : this.value)
for (int i = 0; i < this.value.size(); i++)
{
panelBuilder.item(this.createStringElement(element));
panelBuilder.item(this.createStringElement(this.value.get(i), i));
}

panelBuilder.build();
Expand Down Expand Up @@ -122,10 +124,14 @@ private PanelItem getButton(Button button)
description = Collections.emptyList();
icon = new ItemStack(Material.WHITE_STAINED_GLASS_PANE);
clickHandler = (panel, user, clickType, slot) -> {

// TODO: Open Anvil GUI.

this.build();
new AnvilGUI(BentoBox.getInstance(),
this.user.getPlayer(),
" ",
(player, reply) -> {
this.value.add(reply);
this.build();
return reply;
});
return true;
};
break;
Expand Down Expand Up @@ -168,13 +174,20 @@ private PanelItem getButton(Button button)
* @param element Paper Icon name
* @return PanelItem.
*/
private PanelItem createStringElement(String element)
private PanelItem createStringElement(String element, int stringIndex)
{
return new PanelItemBuilder().
name(element).
icon(Material.PAPER).
clickHandler((panel, user1, clickType, i) -> {
// TODO: open anvil gui.
new AnvilGUI(BentoBox.getInstance(),
this.user.getPlayer(),
element,
(player, reply) -> {
this.value.set(stringIndex, reply);
this.build();
return reply;
});
return true;
}).build();
}
Expand Down

0 comments on commit be7435f

Please sign in to comment.