From 52b942fe4306d39ac068f88898825e2f0743aa46 Mon Sep 17 00:00:00 2001 From: Genny Date: Sun, 14 Jun 2020 03:41:55 -0500 Subject: Reimplement black glass safety but correctly --- src/main/java/dev/genbyte/sunfright/Damager.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src') diff --git a/src/main/java/dev/genbyte/sunfright/Damager.java b/src/main/java/dev/genbyte/sunfright/Damager.java index 83c57e7..093dbb6 100644 --- a/src/main/java/dev/genbyte/sunfright/Damager.java +++ b/src/main/java/dev/genbyte/sunfright/Damager.java @@ -4,14 +4,18 @@ import java.util.Collection; import java.util.Random; import java.util.logging.Level; +import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.World; +import org.bukkit.block.Block; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.Damageable; import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.scheduler.BukkitRunnable; +import org.bukkit.util.RayTraceResult; +import org.bukkit.util.Vector; public class Damager extends BukkitRunnable { private final Sunfright sf; @@ -72,6 +76,19 @@ public class Damager extends BukkitRunnable { } public void run() { + Location loc = player.getLocation(); + World world = loc.getWorld(); + Block topBlock = player.getWorld().rayTraceBlocks( + loc, + new Vector(0, 1, 0), + world.getMaxHeight()-loc.getY() + ).getHitBlock(); + + if (topBlock.getLocation().getY() > player.getLocation().getY() + && topBlock.getType().equals(Material.BLACK_STAINED_GLASS)) { + return; + } + ItemStack helmet = player.getInventory().getHelmet(); if (helmet != null) { -- cgit 1.4.1-3-g733a5