1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-21 04:05:48 +00:00

Changed some stuff in BeeWingListener, Should be more performance friendly now.

This commit is contained in:
beSnow 2020-05-15 23:50:41 +02:00
parent 84bce963b9
commit 733599691a

View File

@ -4,6 +4,7 @@ import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils;
import me.mrCookieSlime.Slimefun.Lists.SlimefunItems; import me.mrCookieSlime.Slimefun.Lists.SlimefunItems;
import me.mrCookieSlime.Slimefun.SlimefunPlugin; import me.mrCookieSlime.Slimefun.SlimefunPlugin;
import me.mrCookieSlime.Slimefun.api.Slimefun; import me.mrCookieSlime.Slimefun.api.Slimefun;
import org.bukkit.HeightMap;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; 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 * 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 * @author beSnow
*/ */
@ -27,16 +28,27 @@ public class BeeWingListener implements Listener {
plugin.getServer().getPluginManager().registerEvents(this, plugin); plugin.getServer().getPluginManager().registerEvents(this, plugin);
} }
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.LOWEST)
public void onApproachGround(PlayerMoveEvent e) { public void onApproachGround(PlayerMoveEvent e) {
Player player = e.getPlayer(); 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 (!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) double playerDistanceToHighestBlock = (player.getLocation().getY() - player.getWorld().getHighestBlockYAt(player.getLocation(), HeightMap.WORLD_SURFACE));
player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW_FALLING, 30, 0));
// 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) { private static int getDistanceToGround(Entity e) {
@ -50,5 +62,4 @@ public class BeeWingListener implements Listener {
} }
return distance; return distance;
} }
} }