Package fr.neatmonster.nocheatplus.checks.moving

Examples of fr.neatmonster.nocheatplus.checks.moving.LocationTrace


        }
        // TODO: calculate factor for dists: ticks * 50 * lag
       
        // TODO: dist < width => skip some checks (direction, ..)
     
        final LocationTrace damagedTrace;
        final Player damagedPlayer;
        if (damaged instanceof Player){
          damagedPlayer = (Player) damaged;
//          // Bad pitch/yaw, just in case.
//         if (LocUtil.needsDirectionCorrection(useLoc2.getYaw(), useLoc2.getPitch())) {
//           mcAccess.correctDirection(damagedPlayer);
//           damagedPlayer.getLocation(useLoc2);
//         }
         // Log.
          if (cc.debug && damagedPlayer.hasPermission(Permissions.ADMINISTRATION_DEBUG)){
            damagedPlayer.sendMessage("Attacked by " + player.getName() + ": inv=" + mcAccess.getInvulnerableTicks(damagedPlayer) + " ndt=" + damagedPlayer.getNoDamageTicks());
          }
          // Check for self hit exploits (mind that projectiles are excluded from this.)
          if (selfHit.isEnabled(player) && selfHit.check(player, damagedPlayer, data, cc)) {
            cancelled = true;
          }
          // Get+update the damaged players.
          // TODO: Problem with NPCs: data stays (not a big problem).
          // (This is done even if the event has already been cancelled, to keep track, if the player is on a horse.)
          damagedTrace = MovingData.getData(damagedPlayer).updateTrace(damagedPlayer, damagedLoc, tick);
        } else {
          damagedPlayer = null; // TODO: This is a temporary workaround.
          // Use a fake trace.
          // TODO: Provide for entities too? E.g. one per player, or a fully fledged bookkeeping thing (EntityData).
          //final MovingConfig mcc = MovingConfig.getConfig(damagedLoc.getWorld().getName());
          damagedTrace = null; //new LocationTrace(mcc.traceSize, mcc.traceMergeDist);
          //damagedTrace.addEntry(tick, damagedLoc.getX(), damagedLoc.getY(), damagedLoc.getZ());
        }
       
        if (cc.cancelDead){
          if (damaged.isDead()) {
            cancelled = true;
          }
          // Only allow damaging others if taken damage this tick.
            if (player.isDead() && data.damageTakenByEntityTick != TickTask.getTick()){
              cancelled = true;
            }
        }
       
        if (damage <= 4.0 && tick == data.damageTakenByEntityTick && data.thornsId != Integer.MIN_VALUE && data.thornsId == damaged.getEntityId()){
          // Don't handle further, but do respect selfhit/canceldead.
          // TODO: Remove soon.
          data.thornsId = Integer.MIN_VALUE;
          return cancelled;
        }
        else {
          data.thornsId = Integer.MIN_VALUE;
        }

        // Run through the main checks.
        if (!cancelled && speed.isEnabled(player)){
          if (speed.check(player, now)){
            cancelled = true;
            // Still feed the improbable.
            if (data.speedVL > 50){
              Improbable.check(player, 2f, now, "fight.speed");
            }
            else{
              Improbable.feed(player, 2f, now);
            }
          }
          else if (normalizedMove > 2.0 && Improbable.check(player, 1f, now, "fight.speed")){
            // Feed improbable in case of ok-moves too.
            // TODO: consider only feeding if attacking with higher average speed (!)
            cancelled = true;
          }
        }

        if (!cancelled && critical.isEnabled(player) && critical.check(player, loc, data, cc)) {
          cancelled = true;
        }
       
        if (!cancelled && knockback.isEnabled(player) && knockback.check(player, data, cc)) {
          cancelled = true;
        }
       
        if (!cancelled && noSwing.isEnabled(player) && noSwing.check(player, data, cc)) {
          cancelled = true;
        }
       
        if (!cancelled && player.isBlocking() && !player.hasPermission(Permissions.MOVING_SURVIVALFLY_BLOCKING)) {
          cancelled = true;
        }
       
        // TODO: Order of all these checks ...
        // Checks that use LocationTrace.

        // TODO: Later optimize (...), should reverse check window ?
       
        // First loop through reach and direction, to determine a window.
        final boolean reachEnabled = !cancelled && reach.isEnabled(player);
        final boolean directionEnabled = !cancelled && direction.isEnabled(player);
       
        if (reachEnabled || directionEnabled) {
          if (damagedPlayer != null) {
            // TODO: Move to a method (trigonometric checks).
                final ReachContext reachContext = reachEnabled ? reach.getContext(player, loc, damaged, damagedLoc, data, cc) : null;
                final DirectionContext directionContext = directionEnabled ? direction.getContext(player, loc, damaged, damagedLoc, data, cc) : null;
               
                final long traceOldest = tick; // - damagedTrace.getMaxSize(); // TODO: Set by window.
                // TODO: Iterating direction: could also start from latest, be it on occasion.
                Iterator<TraceEntry> traceIt = damagedTrace.maxAgeIterator(traceOldest);
               
                boolean violation = true; // No tick with all checks passed.
                boolean reachPassed = !reachEnabled; // Passed individually for some tick.
                boolean directionPassed = !directionEnabled; // Passed individually for some tick.
                // TODO: Maintain a latency estimate + max diff and invalidate completely (i.e. iterate from latest NEXT time)], or just max latency.
View Full Code Here


  @Test
  public void testEmptyIterator() {
    // Expected to fail.
    int size = 80;
    double mergeDist = -0.1;
    LocationTrace trace = new LocationTrace(size, mergeDist);
    try {
      trace.oldestIterator();
      fail("Expect an exception on trying to get an empty iterator (oldest).");
    } catch (IllegalArgumentException ex) {
     
    }
    try {
      trace.latestIterator();
      fail("Expect an exception on trying to get an empty iterator (latest).");
    } catch (IllegalArgumentException ex) {
     
    }
    try {
      trace.maxAgeIterator(0);
      fail("Expect an exception on trying to get an empty iterator (maxAge).");
    } catch (IllegalArgumentException ex) {
     
    }
  }
View Full Code Here

 
  @Test
  public void testIteratorSizeAndOrder() {
    int size = 80;
    double mergeDist = -0.1; // Never merge.
    LocationTrace trace = new LocationTrace(size, mergeDist);
    // Adding up to size elements.
    for (int i = 0; i < size; i++) {
      trace.addEntry(i, i, i, i);
    }
    // Test size with one time filled up.
    testIteratorSizeAndOrder(trace);
    // Add size / 2 elements, to test cross-boundary iteration.
    for (int i = 0; i < size / 2; i++) {
      trace.addEntry(i + size, i, i, i);
    }
    // Test size again.
    testIteratorSizeAndOrder(trace);
  }
View Full Code Here

 
  @Test
  public void testMaxAgeIterator() {
    int size = 80;
    double mergeDist = -0.1; // Never merge.
    LocationTrace trace = new LocationTrace(size, mergeDist);
    // Adding up to size elements.
    for (int i = 0; i < size; i++) {
      trace.addEntry(i, i, i, i);
    }
    for (int i = 0; i < size; i++) {
      Iterator<TraceEntry> it = trace.maxAgeIterator(i);
      long got = it.next().time;
      if (got != i) {
        fail("Bad entry point for iterator (maxAge), expected " + i + ", got instead: " + got);
      }
      int n = 1;
View Full Code Here

 
  @Test
  public void testMaxAgeFirstElementAnyway() {
    int size = 80;
    double mergeDist = -0.1; // Never merge.
    LocationTrace trace = new LocationTrace(size, mergeDist);
    trace.addEntry(0, 0, 0, 0);
    if (!trace.maxAgeIterator(1000).hasNext()) {
      fail("Expect iterator (maxAge) to always contain the latest element.");
    }
    trace.addEntry(1, 0, 0, 0);
    final Iterator<TraceEntry> it = trace.maxAgeIterator(2);
    if (!it.hasNext()) {
      fail("Expect iterator (maxAge) to always contain the latest element.");
    }
    it.next();
    if (it.hasNext()) {
View Full Code Here

 
  @Test
  public void testSize() {
    int size = 80;
    double mergeDist = -0.1;
    LocationTrace trace = new LocationTrace(size, mergeDist);
    // Empty
    if (!trace.isEmpty()) {
      fail("Trace must be empty on start.");
    }
    if (trace.size() != 0) {
      fail("Size must be 0 at start.");
    }
    // Adding up to size elements.
    for (int i = 0; i < size ; i++) {
      trace.addEntry(i, i, i, i);
      if (trace.size() != i + 1) {
        fail("Wrong size, expect " + (i + 1) + ", got instead: " + trace.size());
      }
    }
    // Adding a lot of elements.
    for (int i = 0; i < 1000; i ++) {
      trace.addEntry(i + size, i, i, i);
      if (trace.size() != size) {
        fail("Wrong size, expect " + size + ", got instead: " + trace.size());
      }
    }
  }
View Full Code Here

 
  @Test
  public void testMergeZeroDist() {
    int size = 80;
    double mergeDist = 0.0;
    LocationTrace trace = new LocationTrace(size, mergeDist);
    for (int i = 0; i < 1000; i ++) {
      trace.addEntry(i + size, 0 , 0, 0);
      if (trace.size() != 1) {
        fail("Wrong size, expect 1, got instead: " + trace.size());
      }
    }
  }
View Full Code Here

  @Test
  public void testMergeUpdateAlwaysDist() {
    // Extreme merge dist.
    int size = 80;
    double mergeDist = 1000.0;
    LocationTrace trace = new LocationTrace(size, mergeDist);
    double x = 0;
    double y = 0;
    double z = 0;
    trace.addEntry(0 , x, y, z);
    // Note that entries might get split, if the distance to the second last gets too big, so the maximum number of steps must be limited.
    for (int i = 0; i < 1000; i ++) {
      x = randStep(x, 0.5);
      y = randStep(y, 0.5);
      z = randStep(z, 0.5);
      trace.addEntry(i + 1, x, y, z);
      if (trace.size() != 2) {
        fail("Wrong size, expect 2, got instead: " + trace.size());
      }
    }
  }
View Full Code Here

  @Test
  public void testMergeDist() {
    // Deterministic steps => calculatable size.
    int size = 80;
    double mergeDist = 0.5;
    LocationTrace trace = new LocationTrace(size, mergeDist);
    double x = 0;
    double y = 0;
    double z = 0;
    trace.addEntry(0 , x, y, z);
    for (int i = 0; i < size * 2; i ++) {
      x += 0.5;
      trace.addEntry(i + 1, x, y, z);
      if (Math.abs(trace.size() - (1 + i / 2)) > 1 ) {
        fail("Wrong size, expect roughly half of " + (i + 1) + ", got instead: " + trace.size());
      }
    }
    Iterator<TraceEntry> it = trace.oldestIterator();
    while (it.hasNext()) {
      if (it.next().lastDistSq > 1.0) {
        fail("Spacing should be smaller than 1.0 (sq / actual).");
      }
    }
View Full Code Here

TOP

Related Classes of fr.neatmonster.nocheatplus.checks.moving.LocationTrace

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.