So basiclly what we are going to do is to check if both of the entities are players or not, then we are going to calculate the Distance between the two players using the Vector3 function called distance(), i've tested the maximum amount of Normal reach and it was 3.9, so we are going to cancel the Hits if the Distance between the two players is higher than 3.9! PHP: /*** @param EntityDamageEvent $event*/public function onDamage(EntityDamageEvent $event){ $entity = $event->getEntity(); if($event instanceof EntityDamageByEntityEvent and $entity instanceof Player){ $damager = $event->getDamager(); if($damager instanceof Player){ if($damager->getGamemode() == Player::CREATIVE or $damager->getGamemode() == Player::SPECTATOR) return; $distance = $damager->distance($entity); $max = 3.9; //The Maximum amount of reach that i got when i was legit. if($distance > $max){ $event->setCancelled(true); $this->getLogger()->debug(TextFormat::RED . $damager->getName() . " got " . $distance . " of reach!"); } } }}
please note that doing that is bad, especially for laggy players or servers suggest adding tolerance suggest adding suspicious tick to prevent false flag
actually i tested the reach with a Laggy connection and it didn't mess with the Reach distance, didn't try with a laggy server but this code just cancel the hits so it's okay
This will cause a bug with bows where they won't take damage if the distance is greater than your maximum reach. I'd add a cause check to prevent this from happening.
Could Set Items Example: Items of PvP, Swords, Axes, Hand, among other Items. It will be ? I'm a newbie !!
You can't actually make a 100% efficient anti reach, nor hacker free server. All this is doing is adding more limited factors, but can always affect legit players. What if Bobby combo BOB, hitting BOB multiple times and the last hit was from far away. Wouldn't this affect such matters? There's always a scene where it would also affect the real players. But anyhow, you guys can use the method for monitoring, but shouldn't be canceled.
that's why there should be more threshold and calculated, ex bobby always hit BOB at a far range for >90% of the time