mirror of
https://github.com/BentoBoxWorld/Challenges.git
synced 2024-11-28 05:25:21 +01:00
Replace setValue method with BiConsumer.
This will provide ability to use setters directly in caller GUIs.
This commit is contained in:
parent
09f69bd46a
commit
25371fc6aa
@ -8,12 +8,12 @@ import org.bukkit.inventory.ItemStack;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.function.BiConsumer;
|
||||||
|
|
||||||
import world.bentobox.bentobox.api.panels.PanelItem;
|
import world.bentobox.bentobox.api.panels.PanelItem;
|
||||||
import world.bentobox.bentobox.api.panels.PanelListener;
|
import world.bentobox.bentobox.api.panels.PanelListener;
|
||||||
import world.bentobox.bentobox.api.panels.builders.PanelBuilder;
|
import world.bentobox.bentobox.api.panels.builders.PanelBuilder;
|
||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
import world.bentobox.challenges.panel.CommonGUI;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -21,9 +21,9 @@ import world.bentobox.challenges.panel.CommonGUI;
|
|||||||
*/
|
*/
|
||||||
public class ItemSwitchGUI
|
public class ItemSwitchGUI
|
||||||
{
|
{
|
||||||
public ItemSwitchGUI(CommonGUI parentGUI, User user, List<ItemStack> itemStacks)
|
public ItemSwitchGUI(User user, List<ItemStack> itemStacks, BiConsumer<Boolean, List<ItemStack>> consumer)
|
||||||
{
|
{
|
||||||
this.parentGUI = parentGUI;
|
this.consumer = consumer;
|
||||||
this.user = user;
|
this.user = user;
|
||||||
this.itemStacks = itemStacks;
|
this.itemStacks = itemStacks;
|
||||||
this.build();
|
this.build();
|
||||||
@ -35,7 +35,7 @@ public class ItemSwitchGUI
|
|||||||
*/
|
*/
|
||||||
private void build()
|
private void build()
|
||||||
{
|
{
|
||||||
PanelBuilder panelBuilder = new PanelBuilder().name(this.user.getTranslation("challenges.gui.change-items"));
|
PanelBuilder panelBuilder = new PanelBuilder().user(this.user).name(this.user.getTranslation("challenges.gui.change-items"));
|
||||||
|
|
||||||
// Size of inventory that user can set via GUI.
|
// Size of inventory that user can set via GUI.
|
||||||
panelBuilder.size(45);
|
panelBuilder.size(45);
|
||||||
@ -94,9 +94,7 @@ public class ItemSwitchGUI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.parentGUI.setValue(returnItems);
|
this.consumer.accept(true, returnItems);
|
||||||
this.user.closeInventory();
|
|
||||||
this.parentGUI.build();
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
@ -108,7 +106,7 @@ public class ItemSwitchGUI
|
|||||||
description = Collections.emptyList();
|
description = Collections.emptyList();
|
||||||
icon = new ItemStack(Material.IRON_DOOR);
|
icon = new ItemStack(Material.IRON_DOOR);
|
||||||
clickHandler = (panel, user, clickType, slot) -> {
|
clickHandler = (panel, user, clickType, slot) -> {
|
||||||
this.parentGUI.build();
|
this.consumer.accept(false, Collections.emptyList());
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
break;
|
break;
|
||||||
@ -219,10 +217,6 @@ public class ItemSwitchGUI
|
|||||||
// Section: Variables
|
// Section: Variables
|
||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
/**
|
|
||||||
* ParentGUI from which current gui is called.
|
|
||||||
*/
|
|
||||||
private CommonGUI parentGUI;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User who opens current gui.
|
* User who opens current gui.
|
||||||
@ -233,4 +227,9 @@ public class ItemSwitchGUI
|
|||||||
* List with original items.
|
* List with original items.
|
||||||
*/
|
*/
|
||||||
private List<ItemStack> itemStacks;
|
private List<ItemStack> itemStacks;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Consumer that returns item stacks on save action.
|
||||||
|
*/
|
||||||
|
private BiConsumer<Boolean, List<ItemStack>> consumer;
|
||||||
}
|
}
|
||||||
|
@ -5,12 +5,12 @@ import org.bukkit.Material;
|
|||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.function.BiConsumer;
|
||||||
|
|
||||||
import world.bentobox.bentobox.api.panels.PanelItem;
|
import world.bentobox.bentobox.api.panels.PanelItem;
|
||||||
import world.bentobox.bentobox.api.panels.builders.PanelBuilder;
|
import world.bentobox.bentobox.api.panels.builders.PanelBuilder;
|
||||||
import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder;
|
import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder;
|
||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
import world.bentobox.challenges.panel.CommonGUI;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -18,11 +18,11 @@ import world.bentobox.challenges.panel.CommonGUI;
|
|||||||
*/
|
*/
|
||||||
public class NumberGUI
|
public class NumberGUI
|
||||||
{
|
{
|
||||||
public NumberGUI(CommonGUI parentGUI, User user, int value)
|
public NumberGUI(User user, int value, BiConsumer<Boolean, Integer> consumer)
|
||||||
{
|
{
|
||||||
this.parentGUI = parentGUI;
|
|
||||||
this.user = user;
|
this.user = user;
|
||||||
this.value = value;
|
this.value = value;
|
||||||
|
this.consumer = consumer;
|
||||||
|
|
||||||
this.currentOperation = Button.SET;
|
this.currentOperation = Button.SET;
|
||||||
|
|
||||||
@ -35,7 +35,7 @@ public class NumberGUI
|
|||||||
*/
|
*/
|
||||||
private void build()
|
private void build()
|
||||||
{
|
{
|
||||||
PanelBuilder panelBuilder = new PanelBuilder().name(this.user.getTranslation("challenges.gui.edit-number-title"));
|
PanelBuilder panelBuilder = new PanelBuilder().user(this.user).name(this.user.getTranslation("challenges.gui.edit-number-title"));
|
||||||
|
|
||||||
// Others
|
// Others
|
||||||
panelBuilder.item(0, this.getButton(Button.SAVE));
|
panelBuilder.item(0, this.getButton(Button.SAVE));
|
||||||
@ -93,10 +93,7 @@ public class NumberGUI
|
|||||||
description = Collections.emptyList();
|
description = Collections.emptyList();
|
||||||
icon = new ItemStack(Material.COMMAND_BLOCK);
|
icon = new ItemStack(Material.COMMAND_BLOCK);
|
||||||
clickHandler = (panel, user, clickType, slot) -> {
|
clickHandler = (panel, user, clickType, slot) -> {
|
||||||
this.parentGUI.setValue(this.value);
|
this.consumer.accept(true, this.value);
|
||||||
this.user.closeInventory();
|
|
||||||
this.parentGUI.build();
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
glow = false;
|
glow = false;
|
||||||
@ -108,7 +105,7 @@ public class NumberGUI
|
|||||||
description = Collections.emptyList();
|
description = Collections.emptyList();
|
||||||
icon = new ItemStack(Material.IRON_DOOR);
|
icon = new ItemStack(Material.IRON_DOOR);
|
||||||
clickHandler = (panel, user, clickType, slot) -> {
|
clickHandler = (panel, user, clickType, slot) -> {
|
||||||
this.parentGUI.build();
|
this.consumer.accept(false, this.value);
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
glow = false;
|
glow = false;
|
||||||
@ -290,9 +287,9 @@ public class NumberGUI
|
|||||||
// ---------------------------------------------------------------------
|
// ---------------------------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This variable stores return GUI.
|
* This variable stores current GUI consumer.
|
||||||
*/
|
*/
|
||||||
private CommonGUI parentGUI;
|
private BiConsumer<Boolean, Integer> consumer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User who runs GUI.
|
* User who runs GUI.
|
||||||
|
@ -5,12 +5,12 @@ import org.bukkit.Material;
|
|||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.function.BiConsumer;
|
||||||
|
|
||||||
import world.bentobox.bentobox.api.panels.PanelItem;
|
import world.bentobox.bentobox.api.panels.PanelItem;
|
||||||
import world.bentobox.bentobox.api.panels.builders.PanelBuilder;
|
import world.bentobox.bentobox.api.panels.builders.PanelBuilder;
|
||||||
import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder;
|
import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder;
|
||||||
import world.bentobox.bentobox.api.user.User;
|
import world.bentobox.bentobox.api.user.User;
|
||||||
import world.bentobox.challenges.panel.CommonGUI;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -19,16 +19,16 @@ import world.bentobox.challenges.panel.CommonGUI;
|
|||||||
*/
|
*/
|
||||||
public class StringListGUI
|
public class StringListGUI
|
||||||
{
|
{
|
||||||
public StringListGUI(CommonGUI parentGUI, User user, List<String> value)
|
public StringListGUI(User user, List<String> value, BiConsumer<Boolean, List<String>> consumer)
|
||||||
{
|
{
|
||||||
this.parentGUI = parentGUI;
|
this.consumer = consumer;
|
||||||
this.user = user;
|
this.user = user;
|
||||||
this.value = value;
|
this.value = value;
|
||||||
|
|
||||||
if (this.value.size() > 18)
|
if (this.value.size() > 18)
|
||||||
{
|
{
|
||||||
// TODO: throw error that so large list cannot be edited.
|
// TODO: throw error that so large list cannot be edited.
|
||||||
this.parentGUI.build();
|
this.consumer.accept(false, this.value);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -42,7 +42,7 @@ public class StringListGUI
|
|||||||
*/
|
*/
|
||||||
private void build()
|
private void build()
|
||||||
{
|
{
|
||||||
PanelBuilder panelBuilder = new PanelBuilder().name(this.user.getTranslation("challenges.gui.text-edit-title"));
|
PanelBuilder panelBuilder = new PanelBuilder().user(this.user).name(this.user.getTranslation("challenges.gui.text-edit-title"));
|
||||||
|
|
||||||
panelBuilder.item(0, this.getButton(Button.SAVE));
|
panelBuilder.item(0, this.getButton(Button.SAVE));
|
||||||
panelBuilder.item(1, this.getButton(Button.VALUE));
|
panelBuilder.item(1, this.getButton(Button.VALUE));
|
||||||
@ -82,9 +82,7 @@ public class StringListGUI
|
|||||||
description = Collections.emptyList();
|
description = Collections.emptyList();
|
||||||
icon = new ItemStack(Material.COMMAND_BLOCK);
|
icon = new ItemStack(Material.COMMAND_BLOCK);
|
||||||
clickHandler = (panel, user, clickType, slot) -> {
|
clickHandler = (panel, user, clickType, slot) -> {
|
||||||
this.parentGUI.setValue(this.value);
|
this.consumer.accept(true, this.value);
|
||||||
this.user.closeInventory();
|
|
||||||
this.parentGUI.build();
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
@ -96,7 +94,8 @@ public class StringListGUI
|
|||||||
description = Collections.emptyList();
|
description = Collections.emptyList();
|
||||||
icon = new ItemStack(Material.IRON_DOOR);
|
icon = new ItemStack(Material.IRON_DOOR);
|
||||||
clickHandler = (panel, user, clickType, slot) -> {
|
clickHandler = (panel, user, clickType, slot) -> {
|
||||||
this.parentGUI.build();
|
this.consumer.accept(false, this.value);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
break;
|
break;
|
||||||
@ -198,9 +197,9 @@ public class StringListGUI
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This variable stores return GUI.
|
* This variable stores consumer.
|
||||||
*/
|
*/
|
||||||
private CommonGUI parentGUI;
|
private BiConsumer<Boolean, List<String>> consumer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User who runs GUI.
|
* User who runs GUI.
|
||||||
|
Loading…
Reference in New Issue
Block a user