Merge pull request #321 from BentoBoxWorld/302_filter_on_value

Makes the default block tab show blocks with value only #302
This commit is contained in:
tastybento 2024-07-20 09:32:10 -07:00 committed by GitHub
commit 1d1623813c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 60 additions and 7 deletions

View File

@ -59,7 +59,7 @@ public class DetailsPanel {
}
// By default no-filters are active.
this.activeTab = Tab.ALL_BLOCKS;
this.activeTab = Tab.VALUE_BLOCKS;
this.activeFilter = Filter.NAME;
this.materialCountList = new ArrayList<>(Material.values().length);
@ -111,6 +111,28 @@ public class DetailsPanel {
this.materialCountList.clear();
switch (this.activeTab) {
case VALUE_BLOCKS -> {
Map<Material, Integer> materialCountMap = new EnumMap<>(Material.class);
materialCountMap.putAll(this.levelsData.getMdCount());
// Add underwater blocks.
this.levelsData.getUwCount().forEach((material, count) -> materialCountMap.put(material,
materialCountMap.computeIfAbsent(material, key -> 0) + count));
// Remove zero value blocks
materialCountMap.entrySet().removeIf(en -> {
Integer value = this.addon.getBlockConfig().getValue(world, en.getKey());
return value == null || value == 0;
});
materialCountMap.entrySet().stream().sorted((Map.Entry.comparingByKey())).forEachOrdered(entry -> {
if (entry.getValue() > 0) {
this.materialCountList.add(new Pair<>(entry.getKey(), entry.getValue()));
}
});
}
case ALL_BLOCKS -> {
Map<Material, Integer> materialCountMap = new EnumMap<>(Material.class);
@ -220,7 +242,7 @@ public class DetailsPanel {
builder.description(this.user.getTranslation(this.world, template.description()));
}
Tab tab = Enums.getIfPresent(Tab.class, String.valueOf(template.dataMap().get("tab"))).or(Tab.ALL_BLOCKS);
Tab tab = Enums.getIfPresent(Tab.class, String.valueOf(template.dataMap().get("tab"))).or(Tab.VALUE_BLOCKS);
// Get only possible actions, by removing all inactive ones.
List<ItemTemplateRecord.ActionRecords> activeActions = new ArrayList<>(template.actions());
@ -605,6 +627,10 @@ public class DetailsPanel {
*/
ALL_BLOCKS,
/**
* Blocks that have value
*/
VALUE_BLOCKS,
/**
* Above Sea level Tab.
*/
ABOVE_SEA_LEVEL,

View File

@ -112,6 +112,11 @@ level:
limit: "&7 Block limit: &e [number]"
count: "&7 Number of blocks: &e [number]"
calculated: "&7 Calculated value: &e [number]"
value_blocks:
name: "&f&l All Blocks With Value"
description: |-
&7 Display all blocks
&7 with value on island.
all_blocks:
name: "&f&l All Blocks"
description: |-

View File

@ -24,6 +24,28 @@ detail_panel:
1:
# Column number
2:
# Icon is a Bukkit Material.
icon: ICE
# Title of the button shown to the user. This is a reference and the reference will be translatable in the locale file
title: level.gui.buttons.value_blocks.name
# Description of the button shown to the user in the lore. This is a reference and the reference will be translatable in the locale file
description: level.gui.buttons.value_blocks.description
# The data section is a key-value list of data relavent for this button. It is interpreted by the code implemented the panel.
# The convention is to specify the type and the panel tab that will open if pressed. These are Enums in the code.
data:
# Type button will go to the ALL_BLOCKS tab when clicked.
type: TAB
tab: VALUE_BLOCKS
# Actions cover what happens if the button is clicked or the mouse is moved over it. There can be multiple actions possible for different
# click-types.
actions:
# Each action has an arbitrary descriptive name to define it.
view:
# The click-type is the same as the bukkit {@link org.bukkit.event.inventory.ClickType}. UNKNOWN is the default.
click-type: unknown
# tooltip is a locale reference that will be translated for the user and shown when they hover over the button.
tooltip: level.gui.tips.click-to-view
3:
# Icon is a Bukkit Material.
icon: STONE
# Title of the button shown to the user. This is a reference and the reference will be translatable in the locale file
@ -45,7 +67,7 @@ detail_panel:
click-type: unknown
# tooltip is a locale reference that will be translated for the user and shown when they hover over the button.
tooltip: level.gui.tips.click-to-view
3:
4:
icon: GRASS_BLOCK
title: level.gui.buttons.above_sea_level.name
description: level.gui.buttons.above_sea_level.description
@ -56,7 +78,7 @@ detail_panel:
view:
click-type: unknown
tooltip: level.gui.tips.click-to-view
4:
5:
icon: WATER_BUCKET
title: level.gui.buttons.underwater.name
description: level.gui.buttons.underwater.description
@ -67,7 +89,7 @@ detail_panel:
view:
click-type: unknown
tooltip: level.gui.tips.click-to-view
5:
6:
icon: SPAWNER
title: level.gui.buttons.spawner.name
description: level.gui.buttons.spawner.description