mirror of
https://github.com/StarWishsama/Slimefun4.git
synced 2024-09-19 19:25:48 +00:00
fix taking damage on head collision while wearing elytra cap (#3760)
This commit is contained in:
parent
63414033a6
commit
4fbe2a0dcc
@ -1,9 +1,14 @@
|
||||
package io.github.thebusybiscuit.slimefun4.implementation.listeners;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
@ -18,20 +23,35 @@ import io.github.thebusybiscuit.slimefun4.core.services.sounds.SoundEffect;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.Slimefun;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.armor.ElytraCap;
|
||||
import io.github.thebusybiscuit.slimefun4.implementation.items.armor.SlimefunArmorPiece;
|
||||
import org.bukkit.event.entity.EntityToggleGlideEvent;
|
||||
|
||||
/**
|
||||
* The {@link Listener} for the {@link ElytraCap}.
|
||||
*
|
||||
* @author Seggan
|
||||
* @author J3fftw1
|
||||
*
|
||||
* @see ElytraCap
|
||||
*/
|
||||
public class ElytraImpactListener implements Listener {
|
||||
|
||||
private final Set<UUID> gliding = new HashSet<>();
|
||||
|
||||
public ElytraImpactListener(@Nonnull Slimefun plugin) {
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onGlideToggle(EntityToggleGlideEvent event) {
|
||||
Entity entity = event.getEntity();
|
||||
if (entity instanceof Player player && player.isGliding()) {
|
||||
UUID uuid = player.getUniqueId();
|
||||
gliding.add(uuid);
|
||||
}
|
||||
// We tick 1 tick later because the player is being toggled of at the same tick as it takes damage.
|
||||
Slimefun.instance().getServer().getScheduler().runTaskLater(Slimefun.instance(), gliding::clear, 1);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerCrash(EntityDamageEvent e) {
|
||||
if (!(e.getEntity() instanceof Player p)) {
|
||||
@ -39,7 +59,9 @@ public class ElytraImpactListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
if (e.getCause() == DamageCause.FALL || e.getCause() == DamageCause.FLY_INTO_WALL && p.isGliding()) {
|
||||
if ((e.getCause() == DamageCause.FALL || e.getCause() == DamageCause.FLY_INTO_WALL)
|
||||
&& (p.isGliding() || gliding.contains(p.getUniqueId()))
|
||||
) {
|
||||
Optional<PlayerProfile> optional = PlayerProfile.find(p);
|
||||
|
||||
if (optional.isEmpty()) {
|
||||
@ -48,7 +70,7 @@ public class ElytraImpactListener implements Listener {
|
||||
}
|
||||
|
||||
PlayerProfile profile = optional.get();
|
||||
Optional<SlimefunArmorPiece> helmet = profile.getArmor()[0].getItem();
|
||||
Optional<SlimefunArmorPiece> helmet = profile.getArmor()[3].getItem();
|
||||
|
||||
if (helmet.isPresent()) {
|
||||
SlimefunItem item = helmet.get();
|
||||
|
Loading…
Reference in New Issue
Block a user