From 733599691a29c5dab8bbb6bfff582d8099c05fe4 Mon Sep 17 00:00:00 2001 From: beSnow Date: Fri, 15 May 2020 23:50:41 +0200 Subject: [PATCH] Changed some stuff in BeeWingListener, Should be more performance friendly now. --- .../listeners/BeeWingListener.java | 29 +++++++++++++------ 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BeeWingListener.java b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BeeWingListener.java index e89165bf6..7f1e014ad 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BeeWingListener.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/implementation/listeners/BeeWingListener.java @@ -4,6 +4,7 @@ import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils; import me.mrCookieSlime.Slimefun.Lists.SlimefunItems; import me.mrCookieSlime.Slimefun.SlimefunPlugin; import me.mrCookieSlime.Slimefun.api.Slimefun; +import org.bukkit.HeightMap; import org.bukkit.Location; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; @@ -17,7 +18,7 @@ import org.bukkit.potion.PotionEffectType; /** * This {@link Listener} is responsible for the slow falling effect given to the player - * When Nearing the ground. + * When Nearing the ground when using the Bee Wings. * * @author beSnow */ @@ -27,16 +28,27 @@ public class BeeWingListener implements Listener { plugin.getServer().getPluginManager().registerEvents(this, plugin); } - @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + @EventHandler(priority = EventPriority.LOWEST) public void onApproachGround(PlayerMoveEvent e) { Player player = e.getPlayer(); - ItemStack helmet = e.getPlayer().getInventory().getChestplate(); - if (!SlimefunUtils.isItemSimilar(helmet, SlimefunItems.BEE_WINGS, true) && !Slimefun.hasUnlocked(e.getPlayer(), helmet, true)) return; if (!player.isGliding()) return; - if (getDistanceToGround(player) == 0) return; //More accurate than Entity#isOnGround() + if (player.isOnGround()) return; + ItemStack helmet = player.getInventory().getChestplate(); + if (!SlimefunUtils.isItemSimilar(helmet, SlimefunItems.BEE_WINGS, true) && !Slimefun.hasUnlocked(player, helmet, true)) + return; - if (getDistanceToGround(player) <= 6) - player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW_FALLING, 30, 0)); + double playerDistanceToHighestBlock = (player.getLocation().getY() - player.getWorld().getHighestBlockYAt(player.getLocation(), HeightMap.WORLD_SURFACE)); + + // getDistanceToGround will only fire when playerDistanceToHighestBlock is negative (which happens when a player is flying under an existing structure) + if (playerDistanceToHighestBlock < 0) { + if (getDistanceToGround(player) > 6) return; + player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW_FALLING, 40, 0)); + return; + } + + if (playerDistanceToHighestBlock <= 6) { + player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW_FALLING, 40, 0)); + } } private static int getDistanceToGround(Entity e) { @@ -50,5 +62,4 @@ public class BeeWingListener implements Listener { } return distance; } -} - +} \ No newline at end of file