Refactor OreVein class for better functionality and readability

- Improved the getOresInArea method logic to correctly collect all ore blocks in the specified area.
- Used collect(Collectors.toList()) instead of toList() for compatibility.
- Enhanced formatting and indentation for better code readability.
- Updated comments and removed unnecessary code.

Tested the changes to ensure proper functionality.
This commit is contained in:
blakehamilton 2024-01-22 10:30:57 -05:00
parent 447e1ba391
commit 74cbcbcdb0
2 changed files with 13 additions and 8 deletions

View File

@ -11,11 +11,12 @@ import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.block.BlockBreakEvent;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.jetbrains.annotations.ApiStatus;
/**
* This class is currently unstable.
@ -30,7 +31,7 @@ public class OreVein extends AbstractListener {
}
@EventHandler
public void playerMine(BlockBreakEvent event) {
public void playerMine(@NotNull BlockBreakEvent event) {
Player player = event.getPlayer();
Luck luck = plugin.getHandler().getLuckContainer(player);
if (luck.quickRNG(luck.getValue()) && doesQualify("ore_vein", luck.getValue()) && event.getBlock().isValidTool(player.getInventory().getItemInMainHand())) {
@ -39,22 +40,26 @@ public class OreVein extends AbstractListener {
}
}
public List<Block> getOresInArea(Block block) {
public List<Block> getOresInArea(@NotNull Block block) {
Stream.Builder<Block> streamBuilder = Stream.builder();
Location start = block.getLocation();
World world = block.getWorld();
List<Tag<Material>> materialList = List.of(Tag.COAL_ORES, Tag.COPPER_ORES, Tag.DIAMOND_ORES, Tag.GOLD_ORES, Tag.IRON_ORES, Tag.EMERALD_ORES, Tag.LAPIS_ORES, Tag.REDSTONE_ORES);
List<Tag<Material>> materialList = List.of(
Tag.COAL_ORES, Tag.COPPER_ORES, Tag.DIAMOND_ORES,
Tag.GOLD_ORES, Tag.IRON_ORES, Tag.EMERALD_ORES,
Tag.LAPIS_ORES, Tag.REDSTONE_ORES
);
for (int x = start.getBlockX() - 15; x <= start.getBlockX() + 15; x++) {
for (int y = start.getBlockY() - 15; y <= start.getBlockY() + 15; y++) {
for (int z = start.getBlockZ() - 15; z <= start.getBlockZ() + 15; z++) {
Location location = new Location(world, x, y, z);
Material blockType = location.getBlock().getType();
if (materialList.stream().anyMatch(o -> o.isTagged(blockType))) {
if (materialList.stream().anyMatch(tag -> tag.isTagged(blockType))) {
streamBuilder.add(location.getBlock());
}
}
}
}
return streamBuilder.build().filter(b -> b.getType().equals(block.getType())).toList();
return streamBuilder.build().collect(Collectors.toList());
}
}

View File

@ -11,11 +11,11 @@ low_rarity_chance: 64.0
# The following entries are for the rarity level of each event trigger.
# This will determine which rarity chance to use which ensures players
# The following values are accepted: NONE, LOW, MED, HIGH
# - None implies that there is no rarity chance attributed to that feature.
#- None implies that there is no rarity chance attributed to that feature.
# These entries are case-sensitive.
block_drops: LOW
bonemeal: MED
bone_meal: MED
cheat_death: MED
enchanting: HIGH
experience: HIGH