Merge pull request #3 from blakehamiltons/main

Refactor OreVein class for better functionality and readability
This commit is contained in:
blakehamiltons 2024-01-24 16:26:01 -05:00 committed by GitHub
commit cd2c90dc7a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
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