Skip to content

Commit

Permalink
Add an ability to reset bundle vie SelectBundlePanel.
Browse files Browse the repository at this point in the history
Create dummy bundle object that will be added to SelectBundlePanel and is a way how to select that island has no bundle.
  • Loading branch information
BONNe committed Dec 5, 2020
1 parent 9ea00f7 commit 77a754d
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,34 @@ public GeneratorBundleObject clone()
}


// ---------------------------------------------------------------------
// Section: Static dummy bundle.
// ---------------------------------------------------------------------


/**
* Dummy bundle is used to display a bundle that contains all generators.
*/
public final static GeneratorBundleObject dummyBundle;

/**
* Populate dummy bundle with some values.
*/
static
{
dummyBundle = new GeneratorBundleObject();
dummyBundle.setGeneratorIcon(new ItemStack(Material.STRUCTURE_VOID));
dummyBundle.setFriendlyName("&f&l No Bundle");
dummyBundle.setUniqueId(null);

List<String> description = new ArrayList<>();
description.add("&cThis is not an actual");
description.add("&cbundle.");

dummyBundle.setDescription(description);
}


// ---------------------------------------------------------------------
// Section: Variables
// ---------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -494,9 +494,12 @@ protected List<String> generateBundleDescription(GeneratorBundleObject bundle)
bundle.getDescription().forEach(line ->
description.add(ChatColor.translateAlternateColorCodes('&', line)));

description.add(this.user.getTranslation(Constants.DESCRIPTIONS + "bundle-permission",
Constants.ID, bundle.getUniqueId(),
Constants.GAMEMODE, Utils.getGameMode(this.world).toLowerCase()));
if (bundle != GeneratorBundleObject.dummyBundle)
{
description.add(this.user.getTranslation(Constants.DESCRIPTIONS + "bundle-permission",
Constants.ID, bundle.getUniqueId(),
Constants.GAMEMODE, Utils.getGameMode(this.world).toLowerCase()));
}

// Add missing permissions
if (!bundle.getGeneratorTiers().isEmpty())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ private PanelItem createButton(Button button)
clickHandler = (panel, user, clickType, slot) ->
{
SelectBundlePanel.open(this, islandBundle, bundle -> {
if (bundle == null)
if (bundle == null || bundle == GeneratorBundleObject.dummyBundle)
{
this.generatorData.setIslandBundle(null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
import java.util.stream.Collectors;

import world.bentobox.bentobox.api.panels.PanelItem;
import world.bentobox.bentobox.api.panels.builders.PanelBuilder;
import world.bentobox.bentobox.api.panels.builders.PanelItemBuilder;
import world.bentobox.magiccobblestonegenerator.database.objects.GeneratorBundleObject;
import world.bentobox.magiccobblestonegenerator.database.objects.GeneratorTierObject;
import world.bentobox.magiccobblestonegenerator.panels.CommonPanel;
import world.bentobox.magiccobblestonegenerator.panels.GuiUtils;
import world.bentobox.magiccobblestonegenerator.utils.Constants;
Expand All @@ -32,10 +34,18 @@ private SelectBundlePanel(CommonPanel panel, GeneratorBundleObject bundle, Consu
{
super(panel);
this.consumer = consumer;
this.selectedBundle = bundle;
this.selectedBundle = bundle == null ? GeneratorBundleObject.dummyBundle : bundle;

this.bundleList = this.addon.getAddonManager().getAllGeneratorBundles(this.world);

// Add dummy bundle that contains all generators from GameMode.
this.bundleList.add(0, GeneratorBundleObject.dummyBundle);
// Add all generators to the dummy bundle
GeneratorBundleObject.dummyBundle.setGeneratorTiers(
this.addon.getAddonManager().getAllGeneratorTiers(this.world).stream().
map(GeneratorTierObject::getUniqueId).
collect(Collectors.toSet()));

// Calculate max page count.
this.maxPageIndex = (int) Math.ceil(1.0 * this.bundleList.size() / 21) - 1;
// Set page index to 0
Expand Down Expand Up @@ -236,7 +246,10 @@ protected List<String> generateBundleDescription(GeneratorBundleObject bundle)
{
List<String> description = super.generateBundleDescription(bundle);

description.add(this.user.getTranslation(Constants.DESCRIPTIONS + "selected"));
if (this.selectedBundle == bundle)
{
description.add(this.user.getTranslation(Constants.DESCRIPTIONS + "selected"));
}

description.add("");
description.add(this.user.getTranslation(Constants.TIPS + "click-to-choose"));
Expand Down

0 comments on commit 77a754d

Please sign in to comment.