1+ package com .justdoom .flappyanticheat .checks .movement .boatfly ;
2+
3+ import com .justdoom .flappyanticheat .checks .Check ;
4+ import com .justdoom .flappyanticheat .utils .PlayerUtil ;
5+ import com .justdoom .flappyanticheat .utils .ServerUtil ;
6+ import io .github .retrooper .packetevents .PacketEvents ;
7+ import io .github .retrooper .packetevents .event .impl .PacketPlayReceiveEvent ;
8+ import io .github .retrooper .packetevents .packettype .PacketType ;
9+ import io .github .retrooper .packetevents .packetwrappers .play .in .flying .WrappedPacketInFlying ;
10+ import org .bukkit .Location ;
11+ import org .bukkit .Material ;
12+ import org .bukkit .block .Block ;
13+ import org .bukkit .entity .EntityType ;
14+ import org .bukkit .entity .Player ;
15+
16+ import java .util .HashMap ;
17+ import java .util .Map ;
18+ import java .util .UUID ;
19+
20+ public class BoatFlyA extends Check {
21+
22+ private Map <UUID , Double > airTicks = new HashMap <>();
23+
24+ private Map <UUID , Boolean > inAir = new HashMap <>();
25+
26+ private Map <UUID , Double > y = new HashMap <>();
27+
28+ private Map <UUID , Double > lastY = new HashMap <>();
29+
30+ public BoatFlyA (){
31+ super ("BoatFly" , "A" , false );
32+ }
33+
34+ @ Override
35+ public void onPacketPlayReceive (PacketPlayReceiveEvent event ) {
36+
37+ Player player = event .getPlayer ();
38+ UUID uuid = player .getUniqueId ();
39+
40+ double airTicks = this .airTicks .getOrDefault (uuid , 0.0 );
41+ boolean inAir = this .inAir .getOrDefault (uuid , false );
42+
43+ //measuring how many ticks the player has an air block below them for
44+ airTicks = inAir ? airTicks + 1 : 0 ;
45+
46+ this .airTicks .put (uuid , airTicks );
47+
48+ if (event .getPacketId () == PacketType .Play .Client .VEHICLE_MOVE ) {
49+
50+ lastY .put (uuid , y .getOrDefault (uuid , 0.0 ));
51+ y .put (uuid , player .getLocation ().getY ());
52+
53+ //dont run the check if they have /fly on or are creative flying
54+ if (player .isFlying () || player .isGliding ()) return ;
55+
56+ if (ServerUtil .lowTPS (("checks." + check + "." + checkType ).toLowerCase ()))
57+ return ;
58+
59+ //check if the blocks below the player are air blocks. not entirely accurate.
60+ for (Block block : PlayerUtil .getNearbyBlocksHorizontally (new Location (player .getWorld (),
61+ player .getLocation ().getX (), player .getLocation ().getY () - 1 , player .getLocation ().getZ ()), 1 )) {
62+ if (block .getType () != Material .AIR ) {
63+ this .inAir .put (uuid , false );
64+ break ;
65+ } else {
66+ this .inAir .put (uuid , true );
67+ }
68+ }
69+
70+ player .sendMessage (String .valueOf (y .getOrDefault (uuid , 0.0 )));
71+ player .sendMessage (String .valueOf (lastY .getOrDefault (uuid , 0.0 )));
72+ if (player .isInsideVehicle () && airTicks > 10
73+ && y .getOrDefault (uuid , 0.0 ) > 1 + lastY .getOrDefault (uuid , 0.0 )
74+ && player .getVehicle ().getType () == EntityType .BOAT ) {
75+ fail ("" , player );
76+ }
77+ }
78+ }
79+ }
0 commit comments