Add the ability to hide blocks from the GUI #324

This commit is contained in:
tastybento 2024-08-01 14:00:49 -07:00
parent 61719cdf3a
commit b9b5668fb9
3 changed files with 644 additions and 597 deletions

View File

@ -2,9 +2,12 @@ package world.bentobox.level.config;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
@ -26,6 +29,7 @@ public class BlockConfig {
private Map<Material, Integer> blockLimits = new EnumMap<>(Material.class);
private Map<Material, Integer> blockValues = new EnumMap<>(Material.class);
private final Map<World, Map<Material, Integer>> worldBlockValues = new HashMap<>();
private final List<Material> hiddenBlocks;
private Level addon;
/**
@ -49,6 +53,16 @@ public class BlockConfig {
if (blockValues.isConfigurationSection("worlds")) {
loadWorlds(blockValues);
}
// Hidden
hiddenBlocks = blockValues.getStringList("hidden-blocks").stream().map(name -> {
try {
return Material.valueOf(name.toUpperCase(Locale.ENGLISH));
} catch (Exception e) {
return null;
}
}).filter(Objects::nonNull).toList();
// All done
blockValues.save(file);
}
@ -159,5 +173,22 @@ public class BlockConfig {
return null;
}
/**
* Return true if the block should be hidden
* @param m block material
* @return true if hidden
*/
public boolean isHiddenBlock(Material m) {
return hiddenBlocks.contains(m);
}
/**
* Return true if the block should not be hidden
* @param m block material
* @return false if hidden
*/
public boolean isNotHiddenBlock(Material m) {
return !hiddenBlocks.contains(m);
}
}

File diff suppressed because it is too large Load Diff

View File

@ -10,6 +10,10 @@
limits:
COBBLESTONE: 10000
NETHERRACK: 1000
# These blocks will never be shown in the GUI even if they have value
hidden-blocks:
- BEDROCK
- AIR
blocks:
ACACIA_BUTTON: 1
ACACIA_DOOR: 2