From 74cbcbcdb0225e739b52ebe45b7f4dd4ef24ca8d Mon Sep 17 00:00:00 2001 From: blakehamilton <99293356+blakehamiltons@users.noreply.github.com> Date: Mon, 22 Jan 2024 10:30:57 -0500 Subject: [PATCH] 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. --- .../github/simplex/luck/listener/OreVein.java | 17 +++++++++++------ src/main/resources/config.yml | 4 ++-- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/main/java/io/github/simplex/luck/listener/OreVein.java b/src/main/java/io/github/simplex/luck/listener/OreVein.java index 1348493..4378504 100644 --- a/src/main/java/io/github/simplex/luck/listener/OreVein.java +++ b/src/main/java/io/github/simplex/luck/listener/OreVein.java @@ -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 getOresInArea(Block block) { + public List getOresInArea(@NotNull Block block) { Stream.Builder streamBuilder = Stream.builder(); Location start = block.getLocation(); World world = block.getWorld(); - List> 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> 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()); } } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index dcc5040..69c7524 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -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