Skip to content

Commit

Permalink
Fix campfire
Browse files Browse the repository at this point in the history
  • Loading branch information
Norbit4 committed Oct 11, 2024
1 parent 3f5895f commit 7ccfc3c
Showing 1 changed file with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -22,11 +24,11 @@ protected static void applyEffect(Player p, List<Block> 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));
}
}
Expand All @@ -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<Block> blocks) {
return blocks
private static boolean containsLitMaterial(Material mat, List<Block> blocks) {
List<Block> 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);
}
}

0 comments on commit 7ccfc3c

Please sign in to comment.