shadows_xit

generate a minecraft plugin with /fly which helps the user to fly and add luckperms support

Kodari AI
KodariMay 26 at 4:28 am 10,258 (v2)

I’ll create a lightweight flight management plugin with LuckPerms integration.

FlyCommand
A lightweight flight management plugin that allows players to toggle flight mode with LuckPerms permission support. Features include self and other player flight toggling, configurable messages, and persistent flight states. Integrates seamlessly with LuckPerms for permission management. Includes admin commands to manage flight for other players with proper permission checks.

Created FlyCommand plugin with /fly command and full LuckPerms integration. Features include self and other player flight toggling, persistent flight states across disconnects, configurable messages, and proper permission checks through LuckPerms (falls back to default permissions if LuckPerms is not installed).

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
Code
5 249
src/main/java/com/flycommand/FlyPlugin.java
package com.flycommand;

import com.flycommand.commands.FlyCommand;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.plugin.java.JavaPlugin;

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

public class FlyPlugin extends JavaPlugin implements Listener {

    private Set<UUID> flyingPlayers;
    private boolean luckPermsAvailable;

    @Override
    public void onEnable() {
        saveDefaultConfig();
        
        flyingPlayers = new HashSet<>();
        luckPermsAvailable = getServer().getPluginManager().getPlugin("LuckPerms") != null;
        
        if (luckPermsAvailable) {
            getLogger().info("LuckPerms detected! Permission system integrated.");
        } else {
            getLogger().warning("LuckPerms not found. Using default permission system.");
        }
        
        getCommand("fly").setExecutor(new FlyCommand(this));
        getServer().getPluginManager().registerEvents(this, this);
        
        getLogger().info("FlyCommand has been enabled!");
    }

    @Override
    public void onDisable() {
        for (UUID uuid : flyingPlayers) {
            Player player = getServer().getPlayer(uuid);
            if (player != null && player.isOnline()) {
                player.setAllowFlight(false);
                player.setFlying(false);
            }
        }
        flyingPlayers.clear();
        
        getLogger().info("FlyCommand has been disabled!");
    }

    @EventHandler
    public void onPlayerJoin(PlayerJoinEvent event) {
        Player player = event.getPlayer();
        
        if (getConfig().getBoolean("persist-flight", true)) {
            if (flyingPlayers.contains(player.getUniqueId()) && player.hasPermission("fly.keep")) {
                player.setAllowFlight(true);
            }
        } else {
            flyingPlayers.remove(player.getUniqueId());
            player.setAllowFlight(false);
            player.setFlying(false);
        }
    }

    public void addFlyingPlayer(UUID uuid) {
        flyingPlayers.add(uuid);
    }

    public void removeFlyingPlayer(UUID uuid) {
        flyingPlayers.remove(uuid);
    }

    public boolean isLuckPermsAvailable() {
        return luckPermsAvailable;
    }

    public String getMessage(String key) {
        return colorize(getConfig().getString("messages." + key, "&cMessage not found: " + key));
    }

    public String getMessage(String key, String placeholder, String value) {
        return getMessage(key).replace("{" + placeholder + "}", value);
    }

    private String colorize(String message) {
        return message.replace("&", "§");
    }
}