Skip to content

Commit

Permalink
Added entity groups. Still a lot of bugs but it basically works.
Browse files Browse the repository at this point in the history
  • Loading branch information
tastybento committed Feb 5, 2025
1 parent a969008 commit 88a5cee
Show file tree
Hide file tree
Showing 6 changed files with 731 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@
import java.util.function.Consumer;
import java.util.stream.Collectors;

import org.bukkit.Fluid;
import org.bukkit.Material;
import org.bukkit.Tag;
import org.bukkit.World;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.inventory.ItemStack;

import lv.id.bonne.panelutils.PanelUtils;
import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.panels.PanelItem;
import world.bentobox.bentobox.api.panels.PanelListener;
import world.bentobox.bentobox.api.panels.builders.PanelBuilder;
Expand Down Expand Up @@ -172,7 +171,9 @@ private void buildMainPropertiesPanel(PanelBuilder panelBuilder) {
* @param panelBuilder PanelBuilder where icons must be added.
*/
private void buildIslandRequirementsPanel(PanelBuilder panelBuilder) {
BentoBox.getInstance().logDebug("build Island Req pan");
panelBuilder.item(19, this.createRequirementButton(RequirementButton.REQUIRED_ENTITIES));
panelBuilder.item(20, this.createRequirementButton(RequirementButton.REQUIRED_ENTITYTAGS));
panelBuilder.item(28, this.createRequirementButton(RequirementButton.REMOVE_ENTITIES));

panelBuilder.item(21, this.createRequirementButton(RequirementButton.REQUIRED_BLOCKS));
Expand Down Expand Up @@ -619,7 +620,7 @@ private PanelItem createRequirementButton(RequirementButton button) {
}
// Buttons for Island Requirements
case REQUIRED_ENTITIES, REMOVE_ENTITIES, REQUIRED_BLOCKS, REMOVE_BLOCKS, SEARCH_RADIUS,
REQUIRED_MATERIALTAGS -> {
REQUIRED_MATERIALTAGS, REQUIRED_ENTITYTAGS -> {
return this.createIslandRequirementButton(button);
}
// Buttons for Inventory Requirements
Expand Down Expand Up @@ -697,6 +698,7 @@ private PanelItem createIslandRequirementButton(RequirementButton button) {
description.add("");
description.add(this.user.getTranslation(Constants.TIPS + "click-to-toggle"));
}

case REQUIRED_MATERIALTAGS -> {
if (requirements.getRequiredMaterialTags().isEmpty()) {
description.add(this.user.getTranslation(reference + "none"));
Expand All @@ -705,12 +707,34 @@ private PanelItem createIslandRequirementButton(RequirementButton button) {
// Add Material Tags only
requirements.getRequiredMaterialTags()
.forEach((block, count) -> description.add(this.user.getTranslation(reference + "list",
"[block]", Utils.prettifyObject(block, this.user), "[number]", String.valueOf(count))));
"[tag]", Utils.prettifyObject(block, this.user), "[number]", String.valueOf(count))));
}

icon = new ItemStack(Material.STONE_BRICKS);
clickHandler = (panel, user, clickType, slot) -> {
ManageTagsPanel.open(this, requirements.getRequiredMaterialTags());
ManageBlockGroupsPanel.open(this, requirements.getRequiredMaterialTags());
return true;
};
glow = false;

description.add("");
description.add(this.user.getTranslation(Constants.TIPS + "click-to-change"));
}

case REQUIRED_ENTITYTAGS -> {
if (requirements.getRequiredEntityTypeTags().isEmpty()) {
description.add(this.user.getTranslation(reference + "none"));
} else {
description.add(this.user.getTranslation(reference + "title"));
// Add Material Tags only
requirements.getRequiredEntityTypeTags()
.forEach((block, count) -> description.add(this.user.getTranslation(reference + "list",
"[tag]", Utils.prettifyObject(block, this.user), "[number]", String.valueOf(count))));
}

icon = new ItemStack(Material.ZOMBIE_HEAD);
clickHandler = (panel, user, clickType, slot) -> {
ManageEntityGroupsPanel.open(this, requirements.getRequiredEntityTypeTags());
return true;
};
glow = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@


/**
* This class allows to edit material that are in required material map.
* This class allows to edit Block Groups that are in required.
*/
public class ManageTagsPanel extends CommonPagedPanel<Tag<Material>>
public class ManageBlockGroupsPanel extends CommonPagedPanel<Tag<Material>>
{

// ---------------------------------------------------------------------
Expand All @@ -43,7 +43,7 @@ public class ManageTagsPanel extends CommonPagedPanel<Tag<Material>>
* Functional buttons in current GUI.
*/
private enum Button {
ADD_BLOCK, REMOVE_BLOCK
ADD_BLOCK_GROUP, REMOVE_BLOCK_GROUP
}

// ---------------------------------------------------------------------
Expand All @@ -70,7 +70,7 @@ private enum Button {
*/
private List<Tag<Material>> filterElements;

private ManageTagsPanel(CommonPanel parentGUI, Map<Tag<Material>, Integer> map)
private ManageBlockGroupsPanel(CommonPanel parentGUI, Map<Tag<Material>, Integer> map)
{
super(parentGUI);
this.tagMap = map;
Expand All @@ -91,7 +91,7 @@ private ManageTagsPanel(CommonPanel parentGUI, Map<Tag<Material>, Integer> map)
*/
public static void open(CommonPanel parentGUI, Map<Tag<Material>, Integer> map)
{
new ManageTagsPanel(parentGUI, map).build();
new ManageBlockGroupsPanel(parentGUI, map).build();
}


Expand Down Expand Up @@ -131,13 +131,13 @@ protected void updateFilters()
protected void build()
{
PanelBuilder panelBuilder = new PanelBuilder().user(this.user).
name(this.user.getTranslation(Constants.TITLE + "manage-material-tags"));
name(this.user.getTranslation(Constants.TITLE + "manage-block-groups"));

// Create nice border.
PanelUtils.fillBorder(panelBuilder);

panelBuilder.item(3, this.createButton(Button.ADD_BLOCK));
panelBuilder.item(5, this.createButton(Button.REMOVE_BLOCK));
panelBuilder.item(3, this.createButton(Button.ADD_BLOCK_GROUP));
panelBuilder.item(5, this.createButton(Button.REMOVE_BLOCK_GROUP));
// Fill the box with what is selected
this.populateElements(panelBuilder, this.filterElements);

Expand Down Expand Up @@ -167,7 +167,7 @@ private PanelItem createButton(Button button)

switch (button)
{
case ADD_BLOCK -> {
case ADD_BLOCK_GROUP -> {
icon = new ItemStack(Material.BUCKET);
clickHandler = (panel, user1, clickType, slot) ->
{
Expand All @@ -193,7 +193,7 @@ private PanelItem createButton(Button button)
description.add("");
description.add(this.user.getTranslation(Constants.TIPS + "click-to-add"));
}
case REMOVE_BLOCK -> {
case REMOVE_BLOCK_GROUP -> {

if (!this.selectedTags.isEmpty())
{
Expand Down Expand Up @@ -248,7 +248,7 @@ private PanelItem createButton(Button button)
@Override
protected PanelItem createElementButton(Tag<Material> tag)
{
final String reference = Constants.BUTTON + "materialtag.";
final String reference = Constants.BUTTON + "block-group.";

List<String> description = new ArrayList<>();

Expand Down
Loading

0 comments on commit 88a5cee

Please sign in to comment.