herobrine99dan / NESS-Reloaded

NESS Reloaded is an anticheat that aims to support lots of minecraft versions (from 1.8 to 1.17.1) without losing the advantage of having powerful checks
GNU General Public License v3.0
47 stars 5 forks source link

Check framework improvements #68

Closed A248 closed 4 years ago

A248 commented 4 years ago

This PR deprecates AbstractCheck and allows checks to specify their own factories

Specifying checks

There are 2 non-deprecated ways, in this PR, to specify checks.

  1. The traditional way. This approach is the easiest to change existing checks to.

    • Extend Check or ListeningCheck depending on whether the check needs to listen to an event.
    • Declare a public static final CheckInfo checkInfo field. Use one of the static factory methods in CheckInfos.
      • The check info should match which base class was extended. ListeningCheckInfo corresponds to ListeningCheck, for example.
      • Also note CheckInfo may be written without the generic parameter as the parameter on CheckInfo is only kept for compatibility with existing checks (i.e., uses of AbstractCheck).
    • Declare a constructor with the same signature as the superconstructor. That is, Checks would declare XXX(CheckFactory, NessPlayer) whereas ListeningChecks would use XXX(ListeningCheckFactory, NessPlayer).
  2. With a specific check factory.

    • Create a factory class with the same name as the check, extending ListeningCheckFactory, CheckFactory, or BaseCheckFactory.
      • Note that `BaseCheckFactory should only be used in certain cases be used for "fake checks" - checks which are not related to any specific player. More on this below
    • Declare a constructor with 1 parameter, namely CheckManager. Other details about the check should be passed to the super constructor, including check instantiator and check name.
    • Here is an example using the AutoClick check:
public class AutoClickFactory extends ListeningCheckFactory<AutoClick> {

  public AutoClickFactory(CheckManager manager) {
    super(AutoClick::new, "AutoClick", manager,
      CheckInfos.forEventWithAsyncPeriodic(PlayerInteractEvent.class, Duration.ofSeconds(1L)));
  }

}

Using BaseCheckFactory

Use of BaseCheckFactory, BaseCheckInfo, and BaseCheck directly is for "fake checks" - those which are not maintained per-player. (If per-player checks are desired, CheckFactory or ListeningCheckFactory should be used)

When implementing BaseCheckFactory#newCheck(NessPlayer), the returned check is insignificant. It can be null or the same instance of an object. This method only exists to inform BaseCheckFactorys when a NessPlayer is added to the server. removeCheck(NessPlayer) is used to notify removal of a NessPlayer.