(SOLVED

Discussion in 'Spigot Plugin Help' started by xFadedxShadow, Feb 8, 2020.

Thread Status:
Not open for further replies.
  1. Code (Java):
    package xFadedxShadow.Essentials.Commands;

    import java.util.HashSet;
    import java.util.Set;
    import java.util.UUID;

    import org.bukkit.Bukkit;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.EntityDamageEvent;

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

    public class FlyCommand implements CommandExecutor, Listener {
       
        private Main plugin;
        private Set<UUID> hadFlight;
       
        public FlyCommand(Main plugin) {
            this.plugin = plugin;
            hadFlight = new HashSet<>();
            plugin.getCommand("fly").setExecutor(this);
           
            Bukkit.getPluginManager().registerEvents(this, plugin);
        }

        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if (!(sender instanceof Player)) {
                sender.sendMessage(Utils.chat(plugin.getConfig().getString("permission_error_message")));
                return true;
            }
           
            Player p = (Player) sender;
           
            if (p.hasPermission("faded-essentials.fly")) {
                if (!p.getAllowFlight()) {
                    hadFlight.add(p.getUniqueId());
                    p.setAllowFlight(true);
                    p.sendMessage(Utils.chat(plugin.getConfig().getString("FlyCommand.flying_enabled_message")));
                    return true;
                } else {
                    if (p.getAllowFlight()) {
                        if (p.getFallDistance() <= 4) {
                            hadFlight.remove(p.getUniqueId());
                            p.setFlying(false);
                            p.setAllowFlight(false);
                            p.sendMessage(Utils.chat(plugin.getConfig().getString("FlyCommand.flying_disabled_message")));
                            return true;
                        } else {
                            p.setFlying(false);
                            p.setAllowFlight(false);
                            p.sendMessage(Utils.chat(plugin.getConfig().getString("FlyCommand.flying_disabled_message")));
                        }
                    }
                }
            } else {
                p.sendMessage(Utils.chat(plugin.getConfig().getString("permission_error_message")));
                return true;
            }
           
            return false;
        }
       
        @EventHandler
        public void onFallDamage(EntityDamageEvent e) {
            if (e.getEntity() instanceof Player) {
                Player p = (Player) e.getEntity();
                if (hadFlight.contains(p.getUniqueId())){
                    e.setCancelled(true);
                    hadFlight.remove(p.getUniqueId());
                }
            }
        }

    }
     
     
  2. Just Figured out that p.getFallDistance(); Doesn't actually get the distance from Player to the ground. Seems misleading and it p's me off seriously.
     
  3. How do i get the actual distance from the player to the ground?
     
  4. I mean if you want help describing your issue rather than saying "What is wrong with this seriously!" is beneficial. The method name does actually what it describes, it gets the distance that the entity fell.

    Anyway, from reading through your code I'm assuming you want to check if the player is 4 blocks above a solid block (or perhaps a certain coordinate :shrug:). Through a quick google search I found this thread: https://www.spigotmc.org/threads/tu...distance-from-the-ground.164701/#post-1748619.
     
Thread Status:
Not open for further replies.