-
-
Notifications
You must be signed in to change notification settings - Fork 19
/
DetectionExecutor.java
66 lines (54 loc) · 2.83 KB
/
DetectionExecutor.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package com.vagdedes.spartan.abstraction;
import com.vagdedes.spartan.functionality.important.MultiVersion;
import com.vagdedes.spartan.handlers.stability.TPS;
import com.vagdedes.spartan.objects.replicates.SpartanLocation;
import com.vagdedes.spartan.objects.replicates.SpartanPlayer;
import com.vagdedes.spartan.objects.system.HackPrevention;
import com.vagdedes.spartan.system.SpartanBukkit;
import me.vagdedes.spartan.system.Enums;
public abstract class DetectionExecutor {
public final CheckExecutor executor;
public final Enums.HackType hackType;
public final SpartanPlayer player;
public DetectionExecutor(CheckExecutor executor, Enums.HackType hackType, SpartanPlayer player) {
this.executor = executor;
this.hackType = hackType;
this.player = player;
}
protected final void runAsync(Runnable runnable) {
if (!MultiVersion.folia
&& (hackType.getCheck().isSilent(player.getWorld().getName())
|| TPS.getMillisecondsPassed(player) <= 40L)) {
SpartanBukkit.detectionThread.executeIfFreeElseHere(runnable);
} else {
// If there are less than 10 milliseconds available and the check is not silent,
// we definitely run the detection on the main thread because we run into the
// danger of moving the possible prevention in the next tick
runnable.run();
}
}
protected final void forceAsync(Runnable runnable) {
SpartanBukkit.detectionThread.execute(runnable);
}
protected final void cancel(String verbose, SpartanLocation location, int cancelTicks,
boolean groundTeleport, double damage, int violation) {
new HackPrevention(player, hackType, verbose, location, cancelTicks, groundTeleport, damage, violation);
}
protected final void cancel(String verbose, SpartanLocation location, int cancelTicks,
boolean groundTeleport, double damage) {
new HackPrevention(player, hackType, verbose, location, cancelTicks, groundTeleport, damage, 1);
}
protected final void cancel(String verbose, SpartanLocation location, int cancelTicks,
boolean groundTeleport) {
new HackPrevention(player, hackType, verbose, location, cancelTicks, groundTeleport, 0.0, 1);
}
protected final void cancel(String verbose, SpartanLocation location, int teleportCooldown) {
new HackPrevention(player, hackType, verbose, location, teleportCooldown, false, 0.0, 1);
}
protected final void cancel(String verbose, SpartanLocation location) {
new HackPrevention(player, hackType, verbose, location, 0, false, 0.0, 1);
}
protected final void cancel(String verbose) {
new HackPrevention(player, hackType, verbose, null, 0, false, 0.0, 1);
}
}