Search in sources :

Example 1 with ActionList

use of fr.neatmonster.nocheatplus.actions.ActionList in project NoCheatPlus by NoCheatPlus.

the class MovingListener method checkExtremeMove.

/**
 * Check for extremely large moves. Initial intention is to prevent cheaters
 * from creating extreme load. SurvivalFly or CreativeFly is needed.
 *
 * @param player
 * @param from
 * @param to
 * @param data
 * @param cc
 * @return
 */
@SuppressWarnings("unused")
private Location checkExtremeMove(final Player player, final PlayerLocation from, final PlayerLocation to, final MovingData data, final MovingConfig cc) {
    final PlayerMoveData thisMove = data.playerMoves.getCurrentMove();
    final PlayerMoveData lastMove = data.playerMoves.getFirstPastMove();
    // TODO: Latency effects.
    // h + v violation (full move).
    double violation = 0.0;
    // Vertical move.
    // TODO: Configurable
    final boolean allowVerticalVelocity = false;
    if (Math.abs(thisMove.yDistance) > Magic.EXTREME_MOVE_DIST_VERTICAL) {
        // About -1.85 seems to be the negative maximum for velocity use in survival mode. Falling can result in slightly less than -3.
        if (lastMove.toIsValid && Math.abs(thisMove.yDistance) < Math.abs(lastMove.yDistance) && (thisMove.yDistance > 0.0 && lastMove.yDistance > 0.0 || thisMove.yDistance < 0.0 && lastMove.yDistance < 0.0) || allowVerticalVelocity && data.getOrUseVerticalVelocity(thisMove.yDistance) != null) {
        // Speed decreased or velocity is present.
        } else {
            // Violation.
            // Could subtract lastMove.yDistance.
            violation += thisMove.yDistance;
        }
    }
    // Horizontal move.
    if (thisMove.hDistance > Magic.EXTREME_MOVE_DIST_HORIZONTAL) {
        // Exclude valid moves first.
        // TODO: Attributes might allow unhealthy moves as well.
        // Observed maximum use so far: 5.515
        // TODO: Velocity flag too (if combined with configurable distances)?
        // Will change with model change.
        final double amount = thisMove.hDistance - data.getHorizontalFreedom();
        if (amount < 0.0 || lastMove.toIsValid && thisMove.hDistance - lastMove.hDistance <= 0.0 || data.useHorizontalVelocity(amount) >= amount) {
        // Speed decreased or velocity is present.
        } else {
            // Violation.
            // Could subtract lastMove.yDistance.
            violation += thisMove.hDistance;
        }
    }
    if (violation > 0.0) {
        // Ensure a set back location is present.
        if (!data.hasSetBack()) {
            data.setSetBack(from);
        }
        // Process violation as sub check of the appropriate fly check.
        violation *= 100.0;
        final Check check;
        final ActionList actions;
        final double vL;
        if (thisMove.flyCheck == CheckType.MOVING_SURVIVALFLY) {
            check = survivalFly;
            actions = cc.survivalFlyActions;
            data.survivalFlyVL += violation;
            vL = data.survivalFlyVL;
        } else {
            check = creativeFly;
            actions = cc.creativeFlyActions;
            data.creativeFlyVL += violation;
            vL = data.creativeFlyVL;
        }
        final ViolationData vd = new ViolationData(check, player, vL, violation, actions);
        // TODO: Reduce copy and paste (method to fill in locations, once using exact coords and latering default actions).
        if (vd.needsParameters()) {
            vd.setParameter(ParameterName.LOCATION_FROM, String.format(Locale.US, "%.2f, %.2f, %.2f", from.getX(), from.getY(), from.getZ()));
            vd.setParameter(ParameterName.LOCATION_TO, String.format(Locale.US, "%.2f, %.2f, %.2f", to.getX(), to.getY(), to.getZ()));
            vd.setParameter(ParameterName.DISTANCE, String.format(Locale.US, "%.2f", TrigUtil.distance(from, to)));
            vd.setParameter(ParameterName.TAGS, "EXTREME_MOVE");
        }
        // Some resetting is done in MovingListener.
        if (check.executeActions(vd).willCancel()) {
            // Set back + view direction of to (more smooth).
            return MovingUtil.getApplicableSetBackLocation(player, to.getYaw(), to.getPitch(), from, data, cc);
        }
    }
    // No cancel intended.
    return null;
}
Also used : PlayerMoveData(fr.neatmonster.nocheatplus.checks.moving.model.PlayerMoveData) Check(fr.neatmonster.nocheatplus.checks.Check) ActionList(fr.neatmonster.nocheatplus.actions.ActionList) ViolationData(fr.neatmonster.nocheatplus.checks.ViolationData)

Example 2 with ActionList

use of fr.neatmonster.nocheatplus.actions.ActionList in project NoCheatPlus by NoCheatPlus.

the class TestActions method testOptimizedLogActionEmpty.

@Test
public void testOptimizedLogActionEmpty() {
    PluginTests.setUnitTestNoCheatPlusAPI(false);
    PermissionRegistry pReg = NCPAPIProvider.getNoCheatPlusAPI().getPermissionRegistry();
    final ConfigFile config = new DefaultConfig();
    config.set("actions", "log:dummy:0:0:icf");
    config.set("strings.dummy", "dummy");
    config.set(ConfPaths.LOGGING_ACTIVE, false);
    ActionList actionList = config.getOptimizedActionList("actions", pReg.getOrRegisterPermission("dummy"));
    Action<ViolationData, ActionList>[] actions = actionList.getActions(0.0);
    if (actions.length != 0) {
        fail("Wrong number of actions.");
    }
}
Also used : Action(fr.neatmonster.nocheatplus.actions.Action) ConfigFile(fr.neatmonster.nocheatplus.config.ConfigFile) DefaultConfig(fr.neatmonster.nocheatplus.config.DefaultConfig) ActionList(fr.neatmonster.nocheatplus.actions.ActionList) PermissionRegistry(fr.neatmonster.nocheatplus.permissions.PermissionRegistry) Test(org.junit.Test)

Aggregations

ActionList (fr.neatmonster.nocheatplus.actions.ActionList)2 Action (fr.neatmonster.nocheatplus.actions.Action)1 Check (fr.neatmonster.nocheatplus.checks.Check)1 ViolationData (fr.neatmonster.nocheatplus.checks.ViolationData)1 PlayerMoveData (fr.neatmonster.nocheatplus.checks.moving.model.PlayerMoveData)1 ConfigFile (fr.neatmonster.nocheatplus.config.ConfigFile)1 DefaultConfig (fr.neatmonster.nocheatplus.config.DefaultConfig)1 PermissionRegistry (fr.neatmonster.nocheatplus.permissions.PermissionRegistry)1 Test (org.junit.Test)1