1.15.2 Take no fall damage when turning off /fly

Discussion in 'Spigot Plugin Development' started by xFadedxShadow, Feb 7, 2020.

  1. Code (Text):
    package xFadedxShadow.Essentials.Commands;

    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;

    import xFadedxShadow.Essentials.Main;
    import xFadedxShadow.Essentials.Utils.Utils;

    public class FlyCommand implements CommandExecutor {

        private Main plugin;

        public FlyCommand(Main plugin) {
            this.plugin = plugin;

        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if (!(sender instanceof Player)) {
                return true;

            Player p = (Player) sender;

            if (p.hasPermission("faded-essentials.fly")) {
                if (!(p.getAllowFlight() == true)) {
                    return true;
                } else {
                    return true;
            } else {

            return false;

  2. I want the player not to take fall damage after they disable /fly but only one time
  3. Store player's UUID in Set(or some other way, like metadata or persistentdata). When a player takes fall damage - check if(set.remove(uuid)), then just cancel event.
    • Agree Agree x 1
  4. I recomend you changing
    Code (Java):
    if (!(p.getAllowFlight() == true)) {
    Code (Java):
    if (!p.getAllowFlight()) {
  5. Could you show me an example possibly I'm pretty new to Plugin Development
  6. Something Like this? Then use a Hasmap or something?

    Code (Text):
    if(p.getUniqueId().equals(uuid) {
        return p;
  7. Declare Set variable(near your private Main plugin;), like private Set<UUID> hadFlight;
    Initialize it in constructor - hadFlight = new HashSet<>();.
    When player turns fly on, add its UUID to set - hadFlight.add(p.getUniqueId());
    Finally, on EntityDamageEvent with player and fall checks, check for player's UUID in set and cancel event if player was flying.
    Code (Java):
  8. In the class that extends JavaPlugin create a
    Code (Java):
    Set<UUID> flyingPlayers= LinkedHashSet<>();
    Then make a getter for that variable
    Code (Java):
    public Set<UUID> getFlyingPlayers(){
      return name;
    Now when a player activates the fly use
    Code (Java):
    Now create a EntityDamageEvent and check if the damage type is DamageCause.FALL and if the damaged is a player
    Then, use
    Code (Java):
    if(YourMainClassInstance.getFlyingPlayers().contains(Player.getUniqueID()) && !p.getAllowFlight()){
    Now when a player that has stoped flying will not recive fall damage the first time they deactivate the flying mode
  9. Set.remove returns the object removed or null if the set didn't had the object
    Code (Text):
    hadFlight.remove(p.getUniqueId()) == null
    will be true if the set contained the player UUID and false if it didn't
  10. Pretty sure it's about Maps, not Sets. For Sets it has no sense just because you already have the object which you want to remove from set.
  11. Strahan


    Just remember if you do /restart any players in flight will no longer be protected unless you log the collection to config and reload when it comes back up.