Skip to content

Commit

Permalink
Merge pull request #325 from BentoBoxWorld/324_hide_blocks
Browse files Browse the repository at this point in the history
Add the ability to hide blocks from the GUI #324
  • Loading branch information
tastybento authored Aug 6, 2024
2 parents 61719cd + b9b5668 commit 7c98b17
Show file tree
Hide file tree
Showing 3 changed files with 682 additions and 635 deletions.
31 changes: 31 additions & 0 deletions src/main/java/world/bentobox/level/config/BlockConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

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;

Expand All @@ -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;

/**
Expand All @@ -49,6 +53,16 @@ public BlockConfig(Level addon, YamlConfiguration blockValues, File file) throws
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);
}
Expand Down Expand Up @@ -159,5 +173,22 @@ public Integer getValue(World world, Material md) {
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);
}

}
Loading

0 comments on commit 7c98b17

Please sign in to comment.