-
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create SelectEnvironmentGUI that allows to select and deselect differ…
…ent world environments.
- Loading branch information
Showing
1 changed file
with
134 additions
and
0 deletions.
There are no files selected for viewing
134 changes: 134 additions & 0 deletions
134
src/main/java/world/bentobox/challenges/panel/util/SelectEnvironmentGUI.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
package world.bentobox.challenges.panel.util; | ||
|
||
|
||
import org.bukkit.Material; | ||
import org.bukkit.World; | ||
import java.util.Collections; | ||
import java.util.Set; | ||
import java.util.function.BiConsumer; | ||
|
||
import world.bentobox.bentobox.api.panels.builders.PanelBuilder; | ||
import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder; | ||
import world.bentobox.bentobox.api.user.User; | ||
|
||
|
||
/** | ||
* This class creates panel that allows to select and deselect World Environments. On save it runs | ||
* input consumer with true and selected values. | ||
*/ | ||
public class SelectEnvironmentGUI | ||
{ | ||
public SelectEnvironmentGUI(User user, Set<World.Environment> values, BiConsumer<Boolean, Set<World.Environment>> consumer) | ||
{ | ||
this.user = user; | ||
this.values = values; | ||
this.consumer = consumer; | ||
|
||
this.build(); | ||
} | ||
|
||
|
||
/** | ||
* This method builds environment select panel. | ||
*/ | ||
private void build() | ||
{ | ||
PanelBuilder panelBuilder = new PanelBuilder().user(this.user).name(this.user.getTranslation("challenges.gui.admin.environment-title")); | ||
|
||
panelBuilder.item(3, new PanelItemBuilder(). | ||
name(this.user.getTranslation("challenges.gui.admin.buttons.save")). | ||
icon(Material.GREEN_STAINED_GLASS_PANE). | ||
clickHandler((panel, user1, clickType, index) -> { | ||
this.consumer.accept(true, this.values); | ||
return true; | ||
}). | ||
build()); | ||
|
||
panelBuilder.item(5, new PanelItemBuilder(). | ||
name(this.user.getTranslation("challenges.gui.admin.buttons.cancel")). | ||
icon(Material.RED_STAINED_GLASS_PANE). | ||
clickHandler((panel, user1, clickType, i) -> { | ||
this.consumer.accept(false, Collections.emptySet()); | ||
return true; | ||
}). | ||
build()); | ||
|
||
panelBuilder.item(12, new PanelItemBuilder(). | ||
name(this.user.getTranslation("challenges.gui.admin.buttons.nether")). | ||
icon(Material.NETHERRACK). | ||
clickHandler((panel, user1, clickType, i) -> { | ||
if (this.values.contains(World.Environment.NETHER)) | ||
{ | ||
this.values.remove(World.Environment.NETHER); | ||
} | ||
else | ||
{ | ||
this.values.add(World.Environment.NETHER); | ||
} | ||
|
||
this.build(); | ||
return true; | ||
}). | ||
glow(this.values.contains(World.Environment.NETHER)). | ||
build()); | ||
panelBuilder.item(13, new PanelItemBuilder(). | ||
name(this.user.getTranslation("challenges.gui.admin.buttons.normal")). | ||
icon(Material.DIRT). | ||
clickHandler((panel, user1, clickType, i) -> { | ||
if (this.values.contains(World.Environment.NORMAL)) | ||
{ | ||
this.values.remove(World.Environment.NORMAL); | ||
} | ||
else | ||
{ | ||
this.values.add(World.Environment.NORMAL); | ||
} | ||
|
||
this.build(); | ||
return true; | ||
}). | ||
glow(this.values.contains(World.Environment.NORMAL)). | ||
build()); | ||
panelBuilder.item(14, new PanelItemBuilder(). | ||
name(this.user.getTranslation("challenges.gui.admin.buttons.end")). | ||
icon(Material.END_STONE). | ||
clickHandler((panel, user1, clickType, i) -> { | ||
if (this.values.contains(World.Environment.THE_END)) | ||
{ | ||
this.values.remove(World.Environment.THE_END); | ||
} | ||
else | ||
{ | ||
this.values.add(World.Environment.THE_END); | ||
} | ||
|
||
this.build(); | ||
return true; | ||
}). | ||
glow(this.values.contains(World.Environment.THE_END)). | ||
build()); | ||
|
||
panelBuilder.build(); | ||
} | ||
|
||
|
||
// --------------------------------------------------------------------- | ||
// Section: Variables | ||
// --------------------------------------------------------------------- | ||
|
||
/** | ||
* User who wants to run command. | ||
*/ | ||
private User user; | ||
|
||
/** | ||
* List with selected environments. | ||
*/ | ||
private Set<World.Environment> values; | ||
|
||
/** | ||
* Stores current Consumer | ||
*/ | ||
private BiConsumer<Boolean, Set<World.Environment>> consumer; | ||
|
||
} |