Exemple #1
0
  /**
   * Checks a player.
   *
   * @param player the player
   * @return true, if successful
   */
  public boolean check(final Player player) {
    final InventoryConfig cc = InventoryConfig.getConfig(player);
    final InventoryData data = InventoryData.getData(player);

    boolean cancel = false;

    // Has the configured time passed? If so, reset the counter.
    if (data.dropLastTime + cc.dropTimeFrame <= System.currentTimeMillis()) {
      data.dropLastTime = System.currentTimeMillis();
      data.dropCount = 0;
      data.dropVL = 0D;
    }

    // Security check, if the system time changes.
    else if (data.dropLastTime > System.currentTimeMillis()) data.dropLastTime = Integer.MIN_VALUE;

    data.dropCount++;

    // The player dropped more than he should.
    if (data.dropCount > cc.dropLimit) {
      // Set his violation level.
      data.dropVL = data.dropCount - cc.dropLimit;

      // Dispatch a drop event (API).
      final DropEvent e = new DropEvent(player);
      Bukkit.getPluginManager().callEvent(e);

      // Execute whatever actions are associated with this check and the violation level and find
      // out if we should
      // cancel the event.
      cancel = !e.isCancelled() && executeActions(player, cc.dropActions, data.dropVL);
    }

    return cancel;
  }
Exemple #2
0
  /**
   * Checks a player.
   *
   * @param player the player
   * @param level the level
   * @return true, if successful
   */
  public boolean check(final Player player, final int level) {
    // Take time once.
    final long time = System.currentTimeMillis();

    final InventoryData data = InventoryData.getData(player);

    boolean cancel = false;

    // Hunger level change seems to not be the result of eating.
    if (data.instantEatFood == null || level <= player.getFoodLevel()) return false;

    // Rough estimation about how long it should take to eat
    final long expectedTimeWhenEatingFinished =
        Math.max(data.instantEatInteract, data.lastClickTime) + 700L;

    if (data.instantEatInteract > 0 && expectedTimeWhenEatingFinished < time) {
      // Acceptable, reduce VL to reward the player.
      data.instantEatVL *= 0.6D;
    } else if (data.instantEatInteract > time) {
      // Security test, if time ran backwards.
    } else {
      final double difference = (expectedTimeWhenEatingFinished - time) / 100D;

      // Player was too fast, increase their violation level.
      data.instantEatVL += difference;

      // Execute whatever actions are associated with this check and the violation level and find
      // out if we should
      // cancel the event.
      cancel =
          executeActions(
              player,
              data.instantEatVL,
              difference,
              InventoryConfig.getConfig(player).instantEatActions);
    }

    data.instantEatInteract = 0;
    data.instantEatFood = null;
    return cancel;
  }
  /**
   * Checks a player.
   *
   * @param player the player
   * @param force the force
   * @return true, if successful
   */
  public boolean check(final Player player, final float force, final long now) {

    final InventoryData data = InventoryData.getData(player);
    final InventoryConfig cc = InventoryConfig.getConfig(player);

    boolean cancel = false;

    // Rough estimation of how long pulling the string should've taken.
    final long expectedPullDuration =
        (long) (maxTime - maxTime * (1f - force) * (1f - force)) - cc.instantBowDelay;

    // Time taken to pull the string.
    final long pullDuration;
    final boolean valid;
    if (cc.instantBowStrict) {
      // The interact time is invalid, if set to 0.
      valid = data.instantBowInteract != 0;
      pullDuration = valid ? (now - data.instantBowInteract) : 0L;
    } else {
      valid = true;
      pullDuration = now - data.instantBowShoot;
    }

    if (valid
        && (!cc.instantBowStrict || data.instantBowInteract > 0L)
        && pullDuration >= expectedPullDuration) {
      // The player was slow enough, reward them by lowering their violation level.
      data.instantBowVL *= 0.9D;
    } else if (valid && data.instantBowInteract > now) {
      // Security check if time ran backwards.
      // TODO: Maybe this can be removed, though TickTask does not reset at the exact moment.
    } else {
      // Account for server side lag.
      // (Do not apply correction to invalid pulling.)
      final long correctedPullduration =
          valid
              ? (cc.lag
                  ? (long) (TickTask.getLag(expectedPullDuration, true) * pullDuration)
                  : pullDuration)
              : 0;
      if (correctedPullduration < expectedPullDuration) {
        // TODO: Consider: Allow one time but set yawrate penalty time ?
        final double difference = (expectedPullDuration - pullDuration) / 100D;

        // Player was too fast, increase their violation level.
        data.instantBowVL += difference;

        // Execute whatever actions are associated with this check and the
        // violation level and find out if we should cancel the event
        cancel =
            executeActions(player, data.instantBowVL, difference, cc.instantBowActions)
                .willCancel();
      }
    }

    if (data.debug && player.hasPermission(Permissions.ADMINISTRATION_DEBUG)) {
      player.sendMessage(
          ChatColor.YELLOW
              + "NCP: "
              + ChatColor.GRAY
              + "Bow shot - force: "
              + force
              + ", "
              + (cc.instantBowStrict || pullDuration < 2 * expectedPullDuration
                  ? ("pull time: " + pullDuration)
                  : "")
              + "("
              + expectedPullDuration
              + ")");
    }

    // Reset data here.
    data.instantBowInteract = 0;
    data.instantBowShoot = now;
    return cancel;
  }
Exemple #4
0
 /* (non-Javadoc)
  * @see fr.neatmonster.nocheatplus.checks.Check#isEnabled(org.bukkit.entity.Player)
  */
 @Override
 protected boolean isEnabled(final Player player) {
   return !player.hasPermission(Permissions.INVENTORY_DROP)
       && InventoryConfig.getConfig(player).dropCheck;
 }