1010import com .github .retrooper .packetevents .protocol .entity .type .EntityTypes ;
1111import com .github .retrooper .packetevents .protocol .packettype .PacketType ;
1212import com .github .retrooper .packetevents .protocol .player .ClientVersion ;
13+ import com .github .retrooper .packetevents .util .Vector3d ;
1314import com .github .retrooper .packetevents .wrapper .play .client .WrapperPlayClientInteractEntity ;
1415
1516@ CheckData (name = "BadPacketsT" )
@@ -35,37 +36,39 @@ public void onPacketReceive(final PacketReceiveEvent event) {
3536 if (event .getPacketType ().equals (PacketType .Play .Client .INTERACT_ENTITY )) {
3637 final WrapperPlayClientInteractEntity wrapper = new WrapperPlayClientInteractEntity (event );
3738 // Only INTERACT_AT actually has an interaction vector
38- wrapper .getTarget ().ifPresent (targetVector -> {
39- final PacketEntity packetEntity = player .compensatedEntities .getEntity (wrapper .getEntityId ());
40- // Don't continue if the compensated entity hasn't been resolved
41- if (packetEntity == null ) {
42- return ;
43- }
39+ if (wrapper .getAction () != WrapperPlayClientInteractEntity .InteractAction .INTERACT_AT ) return ;
40+ Vector3d targetVector = wrapper .getLocation ();
41+ if (targetVector == null ) return ; // shouldn't ever happen, but whatever
4442
45- // Make sure our target entity is actually a player (Player NPCs work too)
46- if (! EntityTypes . PLAYER . equals ( packetEntity . type )) {
47- // We can't check for any entity that is not a player
48- return ;
49- }
43+ final PacketEntity packetEntity = player . compensatedEntities . getEntity ( wrapper . getEntityId ());
44+ // Don't continue if the compensated entity hasn't been resolved
45+ if ( packetEntity == null ) {
46+ return ;
47+ }
5048
51- // Perform the interaction vector check
52- // TODO:
53- // 27/12/2023 - Dynamic values for more than just one entity type?
54- // 28/12/2023 - Player-only is fine
55- // 30/12/2023 - Expansions differ in 1.9+
56- final float scale = (float ) packetEntity .getAttributeValue (Attributes .SCALE );
57- if (targetVector .y > (minVerticalDisplacement * scale ) && targetVector .y < (maxVerticalDisplacement * scale )
58- && Math .abs (targetVector .x ) < (maxHorizontalDisplacement * scale )
59- && Math .abs (targetVector .z ) < (maxHorizontalDisplacement * scale )) {
60- return ;
61- }
49+ // Make sure our target entity is actually a player (Player NPCs work too)
50+ if (!EntityTypes .PLAYER .equals (packetEntity .type )) {
51+ // We can't check for any entity that is not a player
52+ return ;
53+ }
6254
63- // Log the vector
64- final String verbose = String .format ("%.5f/%.5f/%.5f" ,
65- targetVector .x , targetVector .y , targetVector .z );
66- // We could pretty much ban the player at this point
67- flagAndAlert (verbose );
68- });
55+ // Perform the interaction vector check
56+ // TODO:
57+ // 27/12/2023 - Dynamic values for more than just one entity type?
58+ // 28/12/2023 - Player-only is fine
59+ // 30/12/2023 - Expansions differ in 1.9+
60+ final float scale = (float ) packetEntity .getAttributeValue (Attributes .SCALE );
61+ if (targetVector .y > (minVerticalDisplacement * scale ) && targetVector .y < (maxVerticalDisplacement * scale )
62+ && Math .abs (targetVector .x ) < (maxHorizontalDisplacement * scale )
63+ && Math .abs (targetVector .z ) < (maxHorizontalDisplacement * scale )) {
64+ return ;
65+ }
66+
67+ // Log the vector
68+ final String verbose = String .format ("%.5f/%.5f/%.5f" ,
69+ targetVector .x , targetVector .y , targetVector .z );
70+ // We could pretty much ban the player at this point
71+ flagAndAlert (verbose );
6972 }
7073 }
7174}
0 commit comments