1.15.2 What am i doing wrong here? (SOLVED)

Discussion in 'Spigot Plugin Development' 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.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 org.bukkit.event.entity.EntityDamageEvent.DamageCause;

    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);
        }

        @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 {
                    p.setFlying(false);
                    p.setAllowFlight(false);
                    p.sendMessage(Utils.chat(plugin.getConfig().getString("FlyCommand.flying_disabled_message")));
                    return true;
                }
            } else {
                p.sendMessage(Utils.chat(plugin.getConfig().getString("permission_error_message")));
            }

            return false;

        }
       
        @EventHandler
        public void onFallDamage(EntityDamageEvent e) {
            if (e.getEntity() instanceof Player) {
                Player p = (Player) e.getEntity();
                if (e.getCause() == DamageCause.FALL) {
                    if (hadFlight.contains(p.getUniqueId())) {
                        e.setCancelled(true);
                        hadFlight.remove(p.getUniqueId());
                    }
                }
            }
       
        }

    }
     
     
    #1 xFadedxShadow, Feb 8, 2020
    Last edited: Feb 8, 2020
Thread Status:
Not open for further replies.