From 7ccfc3c72a48b7e22ad4d184e6245d9353472b03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Norbert=20=C5=9Aleziak?= Date: Fri, 11 Oct 2024 22:46:07 +0200 Subject: [PATCH] Fix campfire --- .../mechanics/CampfireMechanic.java | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/main/java/pl/norbit/survivaltweaks/mechanics/CampfireMechanic.java b/src/main/java/pl/norbit/survivaltweaks/mechanics/CampfireMechanic.java index ae4bf29..a113821 100644 --- a/src/main/java/pl/norbit/survivaltweaks/mechanics/CampfireMechanic.java +++ b/src/main/java/pl/norbit/survivaltweaks/mechanics/CampfireMechanic.java @@ -2,6 +2,8 @@ import org.bukkit.Material; import org.bukkit.block.Block; +import org.bukkit.block.data.Lightable; +import org.bukkit.block.data.type.Campfire; import org.bukkit.entity.Player; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; @@ -22,11 +24,11 @@ protected static void applyEffect(Player p, List blocks) { return; } - if(containsMaterial(Material.CAMPFIRE, blocks)){ + if(containsLitMaterial(Material.CAMPFIRE, blocks)){ sync(() -> applyEffect(p, PotionEffectType.REGENERATION)); } - if(containsMaterial(Material.SOUL_CAMPFIRE, blocks)){ + if(containsLitMaterial(Material.SOUL_CAMPFIRE, blocks)){ sync(() -> applyEffect(p, PotionEffectType.FIRE_RESISTANCE)); } } @@ -35,9 +37,18 @@ private static void applyEffect(Player player, PotionEffectType potionEffectType player.addPotionEffect(new PotionEffect(potionEffectType, 50, 0)); } - private static boolean containsMaterial(Material mat, List blocks) { - return blocks + private static boolean containsLitMaterial(Material mat, List blocks) { + List campfires = blocks .stream() - .anyMatch(b -> b.getType() == mat); + .filter(b -> b.getType() == mat) + .toList(); + + if(campfires.isEmpty()){ + return false; + } + + return campfires.stream() + .map(b -> (Campfire) b.getBlockData()) + .anyMatch(Lightable::isLit); } }