mirror of
https://github.com/SimplexDevelopment/FeelingLucky.git
synced 2024-11-13 22:13:32 +00:00
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:
parent
447e1ba391
commit
74cbcbcdb0
@ -11,11 +11,12 @@ import org.bukkit.block.Block;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.block.BlockBreakEvent;
|
import org.bukkit.event.block.BlockBreakEvent;
|
||||||
|
import org.jetbrains.annotations.ApiStatus;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
import org.jetbrains.annotations.ApiStatus;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class is currently unstable.
|
* This class is currently unstable.
|
||||||
@ -30,7 +31,7 @@ public class OreVein extends AbstractListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void playerMine(BlockBreakEvent event) {
|
public void playerMine(@NotNull BlockBreakEvent event) {
|
||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
Luck luck = plugin.getHandler().getLuckContainer(player);
|
Luck luck = plugin.getHandler().getLuckContainer(player);
|
||||||
if (luck.quickRNG(luck.getValue()) && doesQualify("ore_vein", luck.getValue()) && event.getBlock().isValidTool(player.getInventory().getItemInMainHand())) {
|
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();
|
Stream.Builder<Block> streamBuilder = Stream.builder();
|
||||||
Location start = block.getLocation();
|
Location start = block.getLocation();
|
||||||
World world = block.getWorld();
|
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 x = start.getBlockX() - 15; x <= start.getBlockX() + 15; x++) {
|
||||||
for (int y = start.getBlockY() - 15; y <= start.getBlockY() + 15; y++) {
|
for (int y = start.getBlockY() - 15; y <= start.getBlockY() + 15; y++) {
|
||||||
for (int z = start.getBlockZ() - 15; z <= start.getBlockZ() + 15; z++) {
|
for (int z = start.getBlockZ() - 15; z <= start.getBlockZ() + 15; z++) {
|
||||||
Location location = new Location(world, x, y, z);
|
Location location = new Location(world, x, y, z);
|
||||||
Material blockType = location.getBlock().getType();
|
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());
|
streamBuilder.add(location.getBlock());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return streamBuilder.build().filter(b -> b.getType().equals(block.getType())).toList();
|
return streamBuilder.build().collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,11 +11,11 @@ low_rarity_chance: 64.0
|
|||||||
# The following entries are for the rarity level of each event trigger.
|
# The following entries are for the rarity level of each event trigger.
|
||||||
# This will determine which rarity chance to use which ensures players
|
# This will determine which rarity chance to use which ensures players
|
||||||
# The following values are accepted: NONE, LOW, MED, HIGH
|
# 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.
|
# These entries are case-sensitive.
|
||||||
|
|
||||||
block_drops: LOW
|
block_drops: LOW
|
||||||
bonemeal: MED
|
bone_meal: MED
|
||||||
cheat_death: MED
|
cheat_death: MED
|
||||||
enchanting: HIGH
|
enchanting: HIGH
|
||||||
experience: HIGH
|
experience: HIGH
|
||||||
|
Loading…
Reference in New Issue
Block a user