Java Code Examples for org.bukkit.util.Vector#distanceSquared()

The following examples show how to use org.bukkit.util.Vector#distanceSquared() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MovePattern.java    From AACAdditionPro with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void cancelAction(User user, PacketEvent packetEvent)
{
    final IWrapperPlayPosition positionWrapper = packetEvent::getPacket;

    final Vector moveTo = new Vector(positionWrapper.getX(),
                                     positionWrapper.getY(),
                                     positionWrapper.getZ());

    final Location knownPosition = user.getPlayer().getLocation();

    // Not many blocks moved to prevent exploits and world change problems.
    if (moveTo.distanceSquared(knownPosition.toVector()) < 4) {
        // Teleport back the next tick.
        Bukkit.getScheduler().runTask(AACAdditionPro.getInstance(), () -> user.getPlayer().teleport(knownPosition, PlayerTeleportEvent.TeleportCause.UNKNOWN));
    }
}
 
Example 2
Source File: AimbotConvergence.java    From Hawk with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void check(Event event) {
    if(event instanceof MoveEvent) {
        MoveEvent e = (MoveEvent) event;
        HawkPlayer pp = e.getHawkPlayer();
        if(!e.hasDeltaPos())
            return;
        UUID uuid = pp.getUuid();
        Vector prePos = e.getFrom().toVector().clone().subtract(pp.getVelocity()).add(new Vector(0, 1.62, 0));
        Vector postPos = e.getFrom().toVector().add(new Vector(0, 1.62, 0));
        Vector preDir = e.getFrom().getDirection();
        Vector postDir = e.getTo().getDirection();
        Pair<Vector, Vector> points = new Ray(prePos, preDir).closestPointsBetweenLines(new Ray(postPos, postDir));

        Vector lastConvergence = lastConvergencePointMap.get(uuid);
        Vector convergence = points.getKey().add(points.getValue()).multiply(0.5);

        if(lastConvergence != null &&
                //make sure TPs don't false this check
                pp.getCurrentTick() - pp.getLastTeleportAcceptTick() > ServerUtils.getPing(e.getPlayer()) / 50 + 10 &&
                pp.getCurrentTick() > 100) {

            double distance = lastConvergence.distanceSquared(convergence);
            if(!Double.isNaN(distance)) {

                if(distance < 0.00000001)
                    punish(pp, false, e);
                else
                    reward(pp);

            }
        }

        lastConvergencePointMap.put(uuid, convergence);
    }
}
 
Example 3
Source File: EventRuleContext.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
public EventRule getNearest(Vector pos) {
    EventRule nearest = null;
    double distance = Double.POSITIVE_INFINITY;

    for(EventRule rule : byPriority) {
        double d = pos.distanceSquared(rule.region().getBounds().center());
        if(d < distance) {
            nearest = rule;
            distance = d;
        }
    }

    return nearest;
}
 
Example 4
Source File: LineSegment.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
public double distanceSquared(Vector point) {
    if(delta.isZero()) {
        return point.distanceSquared(start);
    } else {
        final double t = perpendicularProjectionParameter(point);
        if(t <= 0) {
            return point.distanceSquared(start);
        } else if(t >= 1) {
            return point.distanceSquared(finish);
        } else {
            return point.distanceSquared(parametricPoint(t));
        }
    }
}
 
Example 5
Source File: SentinelTargetingHelper.java    From Sentinel with MIT License 5 votes vote down vote up
/**
 * Returns a direction to run in, avoiding threatening entities as best as possible.
 * Returns a location of the spot to run to.
 * Returns null if nowhere to run.
 */
public Location runDirection(Location center) {
    for (int i = 0; i < 36; i++) {
        threatDists[i] = 1000 * 1000;
    }
    double range = sentinel.avoidRange;
    Vector centerVec = center.toVector();
    for (LivingEntity entity : avoidanceList) {
        Vector relative = entity.getLocation().toVector().subtract(centerVec);
        for (int i = 0; i < 36; i++) {
            double dist = relative.distanceSquared(directionReferenceVectors[i].clone().multiply(range));
            if (dist < threatDists[i]) {
                threatDists[i] = dist;
            }
        }
    }
    double longestDistance = 0;
    Location runTo = null;
    for (int i = 0; i < 36; i++) {
        if (threatDists[i] > longestDistance) {
            Location newRunTo = findSpotForRunDirection(center, range, directionReferenceVectors[i].clone());
            if (newRunTo != null) {
                runTo = newRunTo;
                longestDistance = threatDists[i];
            }
        }
    }
    if (SentinelPlugin.debugMe) {
        SentinelPlugin.instance.getLogger().info("(TEMP) Run to get threat distance: " + longestDistance + " to " + runTo + " from " + center.toVector());
    }
    return runTo;
}
 
Example 6
Source File: NetherPortals.java    From askyblock with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Function to check proximity to nether spawn location
 * 
 * @param player
 * @return true if in the spawn area, false if not
 */
private boolean awayFromSpawn(Player player) {
    Vector p = player.getLocation().toVector().multiply(new Vector(1, 0, 1));
    Vector spawn = player.getWorld().getSpawnLocation().toVector().multiply(new Vector(1, 0, 1));
    return !(spawn.distanceSquared(p) < (Settings.netherSpawnRadius
        * Settings.netherSpawnRadius));
}