itz_me_noobii

create a plugin that remove fly form server if some one flying if he dont have op ban him for 2 day reason use hacks

Kodari AI
KodariJun 27 at 7:22 am 1

Creating an anti-fly exploit plugin that detects unauthorized flight and applies automatic bans.

AntiFlyExploit
Automatically detects and bans players using unauthorized flight hacks. Listens for fly toggle events and periodically checks all online players. Removes flight, applies a 2-day ban with the reason "use hacks", and skips OP players, creative/spectator modes, and permission-holders.
Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
Code
4 105
src/main/java/com/antiflyexploit/AntiFlyExploit.java
package com.antiflyexploit;

import org.bukkit.BanList;
import org.bukkit.Bukkit;
import org.bukkit.GameMode;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;

import java.util.Date;

public class AntiFlyExploit extends JavaPlugin {

    @Override
    public void onEnable() {
        getServer().getPluginManager().registerEvents(new FlyListener(this), this);

        Bukkit.getScheduler().runTaskTimer(this, () -> {
            for (Player player : Bukkit.getOnlinePlayers()) {
                if (player.isFlying()
                        && !player.isOp()
                        && !player.hasPermission("antiflyexploit.bypass")
                        && player.getGameMode() != GameMode.CREATIVE
                        && player.getGameMode() != GameMode.SPECTATOR) {
                    banPlayer(player);
                }
            }
        }, 0L, 100L);

        getLogger().info("AntiFlyExploit v" + getDescription().getVersion() + " enabled!");
    }

    @Override
    public void onDisable() {
        getLogger().info("AntiFlyExploit disabled!");
    }

    public void banPlayer(Player player) {
        player.setFlying(false);
        player.setAllowFlight(false);

        Bukkit.getBanList(BanList.Type.NAME).addBan(
                player.getName(),
                "use hacks",
                new Date(System.currentTimeMillis() + 172800000L),
                null
        );

        player.kickPlayer("use hacks");
    }
}