Solved Player flight check?

Discussion in 'Spigot Plugin Development' started by _diam, Apr 30, 2017.

Thread Status:
Not open for further replies.
  1. Hey, so I've been trying to do this for hours now, and I can't really find any helpful material on how to fix it. I'm trying to kick a player when they're flying with this code, but it doesn't kick them unless they get to y:99 (default Minecraft server kick height).

    Code (Text):
        @EventHandler
        public void onKick(PlayerKickEvent e) {
            if(e.getReason().toLowerCase().contains("flying is not enabled")) {
                Messaging.sendStaffAlert("&cConsole &7kicked &e" + e.getPlayer().getName() + " &7with reason: &c" + e.getReason(), null);
                Messaging.sendStaffAlert("&e" + e.getPlayer().getName() + " &7may be cheating [&e" + CheckType.getUserFriendlyString(CheckType.FLIGHT) + "&7][&e" + e.getPlayer().getLocation().getY() + "&7].", null);
            }
        }
       
        @EventHandler(priority = EventPriority.HIGHEST)
        public void onMove(PlayerMoveEvent e) {
            if(e.getPlayer().getAllowFlight() && e.getPlayer().getGameMode() != GameMode.CREATIVE) {
                if(e.getPlayer().getLocation().getY() >= 71) {
                    e.getPlayer().kickPlayer(ChatColor.translateAlternateColorCodes('&', "&7You were kicked from FrostPvP&7.\n\n&7Kicked by: &cConsole\n&7Reason: &fFlying is not enabled on this server."));
                    Messaging.sendStaffAlert("&cConsole &7kicked &e" + e.getPlayer().getName() + " &7with reason: &cFlying is not enabled on this server.", null);
                    Messaging.sendStaffAlert("&e" + e.getPlayer().getName() + " &7may be cheating [&e" + CheckType.getUserFriendlyString(CheckType.FLIGHT) + "&7][&e" + e.getPlayer().getLocation().getY() + "&7].", null);
                    return;
                }
                return;
            }
            return;
        }
    I've even tried this, but (as expected) to no avail:
    Code (Text):
        @EventHandler
        public void onToggleFlight(PlayerToggleFlightEvent e) {
            if(!e.getPlayer().isFlying() && !e.getPlayer().hasPermission("core.fly") && e.getPlayer().getGameMode() != GameMode.CREATIVE) {
                e.getPlayer().kickPlayer(ChatColor.translateAlternateColorCodes('&', "&7You were kicked from FrostPvP&7.\n\n&7Kicked by: &cConsole\n&7Reason: &fFlying is not enabled on this server."));
                Messaging.sendStaffAlert("&cConsole &7kicked &e" + e.getPlayer().getName() + " &7with reason: &cFlying is not enabled on this server.", null);
                Messaging.sendStaffAlert("&e" + e.getPlayer().getName() + " &7may be cheating [&e" + CheckType.getUserFriendlyString(CheckType.FLIGHT) + "&7][&e" + e.getPlayer().getLocation().getY() + "&7].", null);
            return;
            }
        return;
        }
       
    }
    Does anyone know how I can do this?
     
    • Optimistic Optimistic x 1
  2. Doesn't this need to be inverted? Not sure I may be wrong

    Code (Text):
    e.getPlayer().getAllowFlight()
     
  3. Yes, sorry, that was just a mistake with pasting. When I tested the code, it was inverted.
     
  4. Have you registered your event's?
     
  5. Hello,

    You try to check a fly like /fly or fly hack (Hacked Client) ?
     
  6. Thanks for trying to help out guys! I solved it this morning by changing this code:
    Code (Text):
    if(e.getPlayer().getAllowFlight() && e.getPlayer().getGameMode() != GameMode.CREATIVE) {
    to this:
    Code (Text):
    if(e.getPlayer().getAllowFlight() && e.getPlayer().getGameMode() != GameMode.CREATIVE && !e.getPlayer().hasPermission("core.fly")) {
    Not too sure why that even worked (seeing as all it does is make sure the play doesn't have permission to use /fly), but there arent any issues now. Thanks again everyone.

    // Locked and resolved
     
Thread Status:
Not open for further replies.