Skip to content

Commit

Permalink
MVP for new CheckManager; faster iteration; structure to support relo…
Browse files Browse the repository at this point in the history
…ading, adding/unloading checks
  • Loading branch information
Axionize committed Dec 19, 2024
1 parent b880f51 commit 4eada75
Show file tree
Hide file tree
Showing 14 changed files with 586 additions and 212 deletions.
5 changes: 3 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ dependencies {
implementation("com.zaxxer:HikariCP:4.0.3")

//implementation("com.github.grimanticheat:grimapi:1193c4fa41")
// Used for local testing: implementation("ac.grim.grimac:GRIMAPI:1.0")
implementation("com.github.grimanticheat:grimapi:fc5634e444")
// Used for local testing:
implementation("ac.grim.grimac:GrimAPI:1.0")
// implementation("com.github.grimanticheat:grimapi:fc5634e444")

implementation("org.jetbrains:annotations:24.1.0")
compileOnly("org.geysermc.floodgate:api:2.2.3-SNAPSHOT")
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/ac/grim/grimac/GrimExternalAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,12 @@ public ConfigManager getConfigManager() {
return configManager;
}

@Override
public boolean hasStarted() {
// TODO implement this
throw new UnsupportedOperationException("Not implemented yet");
}

private ConfigManager configManager = null;
private final ConfigManagerFileImpl configManagerFile = new ConfigManagerFileImpl();
private boolean started = false;
Expand Down
37 changes: 36 additions & 1 deletion src/main/java/ac/grim/grimac/checks/Check.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import ac.grim.grimac.GrimAPI;
import ac.grim.grimac.api.AbstractCheck;
import ac.grim.grimac.api.config.ConfigManager;
import ac.grim.grimac.api.dynamic.DefaultUnloadedBehavior;
import ac.grim.grimac.api.dynamic.UnloadedBehavior;
import ac.grim.grimac.api.events.FlagEvent;
import ac.grim.grimac.player.GrimPlayer;
import ac.grim.grimac.utils.common.ConfigReloadObserver;
Expand All @@ -15,6 +17,8 @@
import lombok.Setter;
import org.bukkit.Bukkit;

import java.lang.reflect.Method;

// Class from https://github.com/Tecnio/AntiCheatBase/blob/master/src/main/java/me/tecnio/anticheat/check/Check.java
@Getter
public class Check implements AbstractCheck, ConfigReloadObserver {
Expand All @@ -40,6 +44,16 @@ public boolean isExperimental() {
return experimental;
}

@Override
public UnloadedBehavior getUnloadedBehavior() {
return DefaultUnloadedBehavior.INSTANCE;
}

@Override
public int getCheckMask() {
throw new UnsupportedOperationException("Override this method to show which check types your check is!");
}

public Check(final GrimPlayer player) {
this.player = player;

Expand Down Expand Up @@ -112,7 +126,6 @@ public final void reward() {
violations = Math.max(0, violations - decay);
}

@Override
public void reload(ConfigManager configuration) {
decay = configuration.getDoubleElse(configName + ".decay", decay);
setbackVL = configuration.getDoubleElse(configName + ".setbackvl", setbackVL);
Expand Down Expand Up @@ -185,6 +198,28 @@ public boolean isTickPacketIncludingNonMovement(PacketTypeCommon packetType) {
return isFlying(packetType);
}

public interface UnloadedCheckHandler<T extends Check> {
// Return what the check's methods should return when unloaded
Object handleUnloadedCall(Method method, Object[] args);
}

// Default behavior - do nothing and return false/0/null
public static final UnloadedCheckHandler<?> DEFAULT_HANDLER = (method, args) -> {
// Return appropriate "no-op" value based on return type
Class<?> returnType = method.getReturnType();
if (returnType == boolean.class) return false;
if (returnType == int.class) return 0;
if (returnType == void.class) return null;
// etc...
return null;
};

private UnloadedCheckHandler<?> unloadedHandler = DEFAULT_HANDLER;

public void setUnloadedHandler(UnloadedCheckHandler<?> handler) {
this.unloadedHandler = handler;
}

@Override
public void reload() {
reload(GrimAPI.INSTANCE.getConfigManager().getConfig());
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/ac/grim/grimac/checks/type/BlockBreakCheck.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
package ac.grim.grimac.checks.type;

import ac.grim.grimac.api.CheckType;
import ac.grim.grimac.utils.anticheat.update.BlockBreak;

public interface BlockBreakCheck extends PostPredictionCheck {
default void onBlockBreak(final BlockBreak blockBreak) {}

@Override
default int getCheckMask() {
return CheckType.BLOCK_PLACE.getMask();
}
}
6 changes: 6 additions & 0 deletions src/main/java/ac/grim/grimac/checks/type/BlockPlaceCheck.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package ac.grim.grimac.checks.type;

import ac.grim.grimac.api.CheckType;
import ac.grim.grimac.api.config.ConfigManager;
import ac.grim.grimac.checks.Check;
import ac.grim.grimac.player.GrimPlayer;
Expand Down Expand Up @@ -97,4 +98,9 @@ protected SimpleCollisionBox getCombinedBox(final BlockPlace place) {

return combined;
}

@Override
public int getCheckMask() {
return CheckType.BLOCK_PLACE.getMask();
}
}
5 changes: 5 additions & 0 deletions src/main/java/ac/grim/grimac/checks/type/PacketCheck.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package ac.grim.grimac.checks.type;

import ac.grim.grimac.api.AbstractCheck;
import ac.grim.grimac.api.CheckType;
import com.github.retrooper.packetevents.event.PacketReceiveEvent;
import com.github.retrooper.packetevents.event.PacketSendEvent;

public interface PacketCheck extends AbstractCheck {
default void onPacketReceive(final PacketReceiveEvent event) {}
default void onPacketSend(final PacketSendEvent event) {}
@Override
default int getCheckMask() {
return CheckType.PACKET.getMask();
}
}
5 changes: 5 additions & 0 deletions src/main/java/ac/grim/grimac/checks/type/PositionCheck.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package ac.grim.grimac.checks.type;

import ac.grim.grimac.api.AbstractCheck;
import ac.grim.grimac.api.CheckType;
import ac.grim.grimac.utils.anticheat.update.PositionUpdate;

public interface PositionCheck extends AbstractCheck {

default void onPositionUpdate(final PositionUpdate positionUpdate) {
}
@Override
default int getCheckMask() {
return CheckType.POSITION.getMask();
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package ac.grim.grimac.checks.type;

import ac.grim.grimac.api.CheckType;
import ac.grim.grimac.utils.anticheat.update.PredictionComplete;

public interface PostPredictionCheck extends PacketCheck {

default void onPredictionComplete(final PredictionComplete predictionComplete) {
}
@Override
default int getCheckMask() {
return CheckType.POST_PREDICTION.getMask();
}
}
5 changes: 5 additions & 0 deletions src/main/java/ac/grim/grimac/checks/type/RotationCheck.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package ac.grim.grimac.checks.type;

import ac.grim.grimac.api.AbstractCheck;
import ac.grim.grimac.api.CheckType;
import ac.grim.grimac.utils.anticheat.update.RotationUpdate;

public interface RotationCheck extends AbstractCheck {

default void process(final RotationUpdate rotationUpdate) {
}
@Override
default int getCheckMask() {
return CheckType.ROTATION.getMask();
}
}
6 changes: 6 additions & 0 deletions src/main/java/ac/grim/grimac/checks/type/VehicleCheck.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
package ac.grim.grimac.checks.type;

import ac.grim.grimac.api.AbstractCheck;
import ac.grim.grimac.api.CheckType;
import ac.grim.grimac.utils.anticheat.update.VehiclePositionUpdate;

public interface VehicleCheck extends AbstractCheck {

void process(final VehiclePositionUpdate vehicleUpdate);

@Override
default int getCheckMask() {
return CheckType.VEHICLE.getMask();
}
}
Loading

0 comments on commit 4eada75

Please sign in to comment.