Skip to content

Commit 67e6f0d

Browse files
committed
Move NoFall check out of backend
1 parent 83d9705 commit 67e6f0d

File tree

7 files changed

+103
-112
lines changed

7 files changed

+103
-112
lines changed

src/main/java/com/rammelkast/anticheatreloaded/AntiCheatReloaded.java

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ public final class AntiCheatReloaded extends JavaPlugin {
7575
private static boolean verbose;
7676

7777
private double tps = -1;
78-
private String symbiosisMetric = "None";
7978

8079
@Override
8180
public void onLoad() {
@@ -165,7 +164,6 @@ public void run() {
165164
getServer().getScheduler().runTaskLater(this, new Runnable() {
166165
@Override
167166
public void run() {
168-
checkForSymbiosis();
169167
try {
170168
final Metrics metrics = new Metrics(AntiCheatReloaded.this, 202);
171169
metrics.addCustomChart(new SingleLineChart("cheaters_kicked", new Callable<Integer>() {
@@ -189,12 +187,6 @@ public String call() throws Exception {
189187
return VersionUtil.getVersion();
190188
}
191189
}));
192-
metrics.addCustomChart(new SimplePie("symbiosis", new Callable<String>() {
193-
@Override
194-
public String call() throws Exception {
195-
return symbiosisMetric;
196-
}
197-
}));
198190
metrics.addCustomChart(new SimplePie("floodgate_enabled", new Callable<String>() {
199191
@Override
200192
public String call() throws Exception {
@@ -312,56 +304,6 @@ public void onPlayerKicked() {
312304
this.playersKicked++;
313305
}
314306

315-
/**
316-
* Creates metric that checks for anti-cheat symbiosis I use this to see if
317-
* AntiCheatReloaded is actively being used together with other anti-cheats, so
318-
* I can account for that.
319-
*/
320-
protected void checkForSymbiosis() {
321-
if (Bukkit.getPluginManager().getPlugin("NoCheatPlus") != null) {
322-
if (this.symbiosisMetric.equals("None")) {
323-
this.symbiosisMetric = "NoCheatPlus";
324-
} else {
325-
this.symbiosisMetric += ", NoCheatPlus";
326-
}
327-
}
328-
if (Bukkit.getPluginManager().getPlugin("Matrix") != null) {
329-
if (this.symbiosisMetric.equals("None")) {
330-
this.symbiosisMetric = "Matrix";
331-
} else {
332-
this.symbiosisMetric += ", Matrix";
333-
}
334-
}
335-
if (Bukkit.getPluginManager().getPlugin("AAC") != null) {
336-
if (this.symbiosisMetric.equals("None")) {
337-
this.symbiosisMetric = "AAC";
338-
} else {
339-
this.symbiosisMetric += ", AAC";
340-
}
341-
}
342-
if (Bukkit.getPluginManager().getPlugin("Spartan") != null) {
343-
if (this.symbiosisMetric.equals("None")) {
344-
this.symbiosisMetric = "Spartan";
345-
} else {
346-
this.symbiosisMetric += ", Spartan";
347-
}
348-
}
349-
if (Bukkit.getPluginManager().getPlugin("Negativity") != null) {
350-
if (this.symbiosisMetric.equals("None")) {
351-
this.symbiosisMetric = "Negativity";
352-
} else {
353-
this.symbiosisMetric += ", Negativity";
354-
}
355-
}
356-
if (Bukkit.getPluginManager().getPlugin("SoaromaSAC") != null) {
357-
if (this.symbiosisMetric.equals("None")) {
358-
this.symbiosisMetric = "SoaromaSAC";
359-
} else {
360-
this.symbiosisMetric += ", SoaromaSAC";
361-
}
362-
}
363-
}
364-
365307
public static void sendToMainThread(final Runnable runnable) {
366308
Bukkit.getScheduler().runTask(AntiCheatReloaded.getPlugin(), runnable);
367309
}

src/main/java/com/rammelkast/anticheatreloaded/check/Backend.java

Lines changed: 3 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import org.bukkit.Location;
2727
import org.bukkit.Material;
2828
import org.bukkit.block.Block;
29-
import org.bukkit.block.BlockFace;
3029
import org.bukkit.entity.Player;
3130
import org.bukkit.event.player.PlayerToggleSprintEvent;
3231
import org.bukkit.potion.PotionEffectType;
@@ -39,6 +38,7 @@
3938
import com.rammelkast.anticheatreloaded.check.movement.FlightCheck;
4039
import com.rammelkast.anticheatreloaded.check.movement.NoSlowCheck;
4140
import com.rammelkast.anticheatreloaded.check.packet.MorePacketsCheck;
41+
import com.rammelkast.anticheatreloaded.check.player.NoFallCheck;
4242
import com.rammelkast.anticheatreloaded.config.Configuration;
4343
import com.rammelkast.anticheatreloaded.config.providers.Checks;
4444
import com.rammelkast.anticheatreloaded.config.providers.Lang;
@@ -47,7 +47,6 @@
4747
import com.rammelkast.anticheatreloaded.util.Distance;
4848
import com.rammelkast.anticheatreloaded.util.User;
4949
import com.rammelkast.anticheatreloaded.util.Utilities;
50-
import com.rammelkast.anticheatreloaded.util.VersionUtil;
5150

5251
public class Backend {
5352
private static final CheckResult PASS = new CheckResult(CheckResult.Result.PASSED);
@@ -57,7 +56,6 @@ public class Backend {
5756
private final Map<UUID, Long> levitatingEnd = new HashMap<UUID, Long>();
5857
private final Map<UUID, Integer> chatLevel = new HashMap<UUID, Integer>();
5958
private final Map<UUID, Integer> commandLevel = new HashMap<UUID, Integer>();
60-
private final Map<UUID, Integer> nofallViolation = new HashMap<UUID, Integer>();
6159
private final Map<UUID, Integer> fastPlaceViolation = new HashMap<UUID, Integer>();
6260
private final Map<UUID, Long> lastBlockPlaced = new HashMap<UUID, Long>();
6361
private final Map<UUID, Long> lastBlockPlaceTime = new HashMap<UUID, Long>();
@@ -105,7 +103,6 @@ public void cleanup(final Player player) {
105103
startEat.remove(uuid);
106104
lastHeal.remove(uuid);
107105
sprinted.remove(uuid);
108-
nofallViolation.remove(uuid);
109106
fastPlaceViolation.remove(uuid);
110107
lastBlockPlaced.remove(uuid);
111108
lastBlockPlaceTime.remove(uuid);
@@ -124,6 +121,7 @@ public void cleanup(final Player player) {
124121
fastSneakViolations.remove(uuid);
125122
lastSneak.remove(uuid);
126123
levitatingEnd.remove(uuid);
124+
NoFallCheck.VIOLATIONS.remove(uuid);
127125
VelocityCheck.VIOLATIONS.remove(uuid);
128126
MorePacketsCheck.LAST_PACKET_TIME.remove(uuid);
129127
MorePacketsCheck.PACKET_BALANCE.remove(uuid);
@@ -211,40 +209,6 @@ public CheckResult checkSpider(final Player player, final double y) {
211209
}
212210
}
213211

214-
public CheckResult checkNoFall(final Player player, final double y) {
215-
final UUID uuid = player.getUniqueId();
216-
if (player.getGameMode() != GameMode.CREATIVE && !player.isInsideVehicle() && !player.isSleeping()
217-
&& !isMovingExempt(player) && !justPlaced(player) && !Utilities.isNearWater(player)
218-
&& !Utilities.isInWeb(player) && !player.getLocation().getBlock().getType().name().endsWith("TRAPDOOR")
219-
&& !VersionUtil.isSlowFalling(player)
220-
&& !Utilities
221-
.isNearShulkerBox(player.getLocation().getBlock().getRelative(BlockFace.DOWN).getLocation())
222-
&& !Utilities.isNearClimbable(player)
223-
&& !Utilities.isNearWater(player.getLocation().clone().subtract(0, 1.5, 0))) {
224-
if (player.getFallDistance() == 0) {
225-
if (nofallViolation.get(uuid) == null) {
226-
nofallViolation.put(uuid, 1);
227-
} else {
228-
nofallViolation.put(uuid, nofallViolation.get(player.getUniqueId()) + 1);
229-
}
230-
231-
int i = nofallViolation.get(uuid);
232-
int vlBeforeFlag = checksConfig.getInteger(CheckType.NOFALL, "vlBeforeFlag");
233-
if (i >= vlBeforeFlag) {
234-
nofallViolation.put(player.getUniqueId(), 1);
235-
return new CheckResult(CheckResult.Result.FAILED,
236-
"tried to avoid fall damage (" + i + " times in a row, max=" + vlBeforeFlag + ")");
237-
} else {
238-
return PASS;
239-
}
240-
} else {
241-
nofallViolation.put(uuid, 0);
242-
return PASS;
243-
}
244-
}
245-
return PASS;
246-
}
247-
248212
public CheckResult checkSneakToggle(final Player player) {
249213
final User user = AntiCheatReloaded.getManager().getUserManager().getUser(player.getUniqueId());
250214
final long lastSneak = this.lastSneak.getOrDefault(player.getUniqueId(), (long) 0);
@@ -534,7 +498,7 @@ public void logTeleport(final Player player) {
534498
manager.getUserManager().getUser(player.getUniqueId()).getMovementManager().lastTeleport = System
535499
.currentTimeMillis();
536500
/* Data for fly/speed should be reset */
537-
nofallViolation.remove(player.getUniqueId());
501+
NoFallCheck.VIOLATIONS.remove(player.getUniqueId());
538502
ElytraCheck.JUMP_Y_VALUE.remove(player.getUniqueId());
539503
}
540504

src/main/java/com/rammelkast/anticheatreloaded/check/movement/AimbotCheck.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@
3131
import com.rammelkast.anticheatreloaded.util.Utilities;
3232

3333
/*
34-
* In development - expect issues
34+
* TODO redo (again)
35+
* Just go for a basic GCD check and implement optifine detection
3536
*/
3637
public final class AimbotCheck {
3738

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* AntiCheatReloaded for Bukkit and Spigot.
3+
* Copyright (c) 2012-2015 AntiCheat Team
4+
* Copyright (c) 2016-2022 Rammelkast
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
package com.rammelkast.anticheatreloaded.check.player;
20+
21+
import java.util.HashMap;
22+
import java.util.Map;
23+
import java.util.UUID;
24+
25+
import org.bukkit.GameMode;
26+
import org.bukkit.block.BlockFace;
27+
import org.bukkit.entity.Player;
28+
29+
import com.rammelkast.anticheatreloaded.AntiCheatReloaded;
30+
import com.rammelkast.anticheatreloaded.check.Backend;
31+
import com.rammelkast.anticheatreloaded.check.CheckResult;
32+
import com.rammelkast.anticheatreloaded.check.CheckType;
33+
import com.rammelkast.anticheatreloaded.config.providers.Checks;
34+
import com.rammelkast.anticheatreloaded.util.Utilities;
35+
import com.rammelkast.anticheatreloaded.util.VersionUtil;
36+
37+
public final class NoFallCheck {
38+
39+
public static final Map<UUID, Integer> VIOLATIONS = new HashMap<>();
40+
41+
private static final CheckResult PASS = new CheckResult(CheckResult.Result.PASSED);
42+
43+
public static CheckResult performCheck(final Player player, final double motionY) {
44+
final UUID uuid = player.getUniqueId();
45+
final Backend backend = AntiCheatReloaded.getManager().getBackend();
46+
final Checks checksConfig = AntiCheatReloaded.getManager().getConfiguration().getChecks();
47+
if (player.getGameMode() != GameMode.CREATIVE && !player.isInsideVehicle() && !player.isSleeping()
48+
&& !backend.isMovingExempt(player) && !backend.justPlaced(player) && !Utilities.isNearWater(player)
49+
&& !Utilities.isInWeb(player) && !player.getLocation().getBlock().getType().name().endsWith("TRAPDOOR")
50+
&& !VersionUtil.isSlowFalling(player)
51+
&& !Utilities
52+
.isNearShulkerBox(player.getLocation().getBlock().getRelative(BlockFace.DOWN).getLocation())
53+
&& !Utilities.isNearClimbable(player)
54+
&& !Utilities.isNearWater(player.getLocation().clone().subtract(0, 1.5, 0))) {
55+
if (player.getFallDistance() == 0.0) {
56+
if (VIOLATIONS.get(uuid) == null) {
57+
VIOLATIONS.put(uuid, 1);
58+
} else {
59+
VIOLATIONS.put(uuid, VIOLATIONS.get(player.getUniqueId()) + 1);
60+
}
61+
62+
final int violations = VIOLATIONS.get(uuid);
63+
final int vlBeforeFlag = checksConfig.getInteger(CheckType.NOFALL, "vlBeforeFlag");
64+
if (violations >= vlBeforeFlag) {
65+
VIOLATIONS.put(player.getUniqueId(), 1);
66+
return new CheckResult(CheckResult.Result.FAILED,
67+
"tried to avoid fall damage (" + violations + " times in a row, max=" + vlBeforeFlag + ")");
68+
} else {
69+
return PASS;
70+
}
71+
} else {
72+
VIOLATIONS.put(uuid, 0);
73+
return PASS;
74+
}
75+
}
76+
return PASS;
77+
}
78+
79+
}

src/main/java/com/rammelkast/anticheatreloaded/command/executors/CommandReload.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public CommandReload() {
4242
@Override
4343
protected void execute(CommandSender cs, String[] args) {
4444
CONFIG.load();
45-
cs.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "ACR " + ChatColor.DARK_GRAY + "> " + ChatColor.GRAY + "The configuration was reloaded");
45+
cs.sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "ACR " + ChatColor.DARK_GRAY + "> "
46+
+ ChatColor.GRAY + "The configuration was reloaded");
4647
}
4748
}

src/main/java/com/rammelkast/anticheatreloaded/event/PlayerListener.java

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
import com.rammelkast.anticheatreloaded.check.movement.StrafeCheck;
7373
import com.rammelkast.anticheatreloaded.check.movement.WaterWalkCheck;
7474
import com.rammelkast.anticheatreloaded.check.player.IllegalInteract;
75+
import com.rammelkast.anticheatreloaded.check.player.NoFallCheck;
7576
import com.rammelkast.anticheatreloaded.manage.AntiCheatManager;
7677
import com.rammelkast.anticheatreloaded.util.Distance;
7778
import com.rammelkast.anticheatreloaded.util.Permission;
@@ -82,7 +83,7 @@
8283
public final class PlayerListener extends EventListener {
8384

8485
private static final AntiCheatManager MANAGER = AntiCheatReloaded.getManager();
85-
86+
8687
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
8788
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
8889
final Player player = event.getPlayer();
@@ -184,18 +185,18 @@ public void onPlayerVelocity(final PlayerVelocityEvent event) {
184185
if (!user.getMovementManager().onGround) {
185186
return;
186187
}
187-
188+
188189
final double motionY = velocity.getY();
189190
user.getMovementManager().velocityExpectedMotionY = motionY;
190191
// End part of Velocity check
191-
192+
192193
MANAGER.addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
193194
}
194195

195196
@EventHandler(priority = EventPriority.HIGHEST)
196197
public void onPlayerChat(final AsyncPlayerChatEvent event) {
197198
final Player player = event.getPlayer();
198-
199+
199200
if (getCheckManager().willCheck(player, CheckType.CHAT_SPAM)) {
200201
final CheckResult result = getBackend().checkChatSpam(player, event.getMessage());
201202
if (result.failed()) {
@@ -252,7 +253,8 @@ public User call() throws Exception {
252253
}).get();
253254
getUserManager().removeUser(user);
254255
} catch (final InterruptedException | ExecutionException exception) {
255-
AntiCheatReloaded.getPlugin().getLogger().log(Level.SEVERE, "Failed to destroy user object async", exception);
256+
AntiCheatReloaded.getPlugin().getLogger().log(Level.SEVERE, "Failed to destroy user object async",
257+
exception);
256258
return;
257259
}
258260

@@ -290,7 +292,8 @@ public void onPlayerInteract(final PlayerInteractEvent event) {
290292
final Player player = event.getPlayer();
291293
final PlayerInventory inv = player.getInventory();
292294
if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) {
293-
final ItemStack itemInHand = ((event.getHand() == EquipmentSlot.HAND) ? inv.getItemInMainHand() : inv.getItemInOffHand());
295+
final ItemStack itemInHand = ((event.getHand() == EquipmentSlot.HAND) ? inv.getItemInMainHand()
296+
: inv.getItemInOffHand());
294297

295298
if (itemInHand.getType() == Material.BOW) {
296299
getBackend().logBowWindUp(player);
@@ -372,10 +375,11 @@ public User call() throws Exception {
372375
}).get();
373376
getUserManager().addUser(user);
374377
} catch (final InterruptedException | ExecutionException exception) {
375-
AntiCheatReloaded.getPlugin().getLogger().log(Level.SEVERE, "Failed to create user object async", exception);
378+
AntiCheatReloaded.getPlugin().getLogger().log(Level.SEVERE, "Failed to create user object async",
379+
exception);
376380
return;
377381
}
378-
382+
379383
MANAGER.addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
380384

381385
if (player.hasPermission("anticheat.admin") && !AntiCheatReloaded.getUpdateManager().isLatest()) {
@@ -427,7 +431,8 @@ public void onPlayerMove(final PlayerMoveEvent event) {
427431
}
428432
if (getCheckManager().willCheckQuick(player, CheckType.VCLIP)
429433
&& event.getFrom().getY() > event.getTo().getY()) {
430-
final CheckResult result = getBackend().checkVClip(player, new Distance(event.getFrom(), event.getTo()));
434+
final CheckResult result = getBackend().checkVClip(player,
435+
new Distance(event.getFrom(), event.getTo()));
431436
if (result.failed()) {
432437
if (!silentMode()) {
433438
int data = result.getData() > 3 ? 3 : result.getData();
@@ -447,7 +452,7 @@ public void onPlayerMove(final PlayerMoveEvent event) {
447452
&& getCheckManager().willCheck(player, CheckType.FLIGHT)
448453
&& !Utilities.isClimbableBlock(player.getLocation().getBlock())
449454
&& event.getFrom().getY() > event.getTo().getY()) {
450-
final CheckResult result = getBackend().checkNoFall(player, y);
455+
final CheckResult result = NoFallCheck.performCheck(player, y);
451456
if (result.failed()) {
452457
if (!silentMode()) {
453458
event.setTo(user.getGoodLocation(from.clone()));

src/main/java/com/rammelkast/anticheatreloaded/manage/CheckManager.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,9 @@
3636
import com.rammelkast.anticheatreloaded.util.VersionUtil;
3737

3838
/**
39-
* <p/>
40-
* The manager that AntiCheat will check with to see if it should watch certain checks and certain players.
39+
* The manager that AntiCheatReloaded will check with to see if it should watch
40+
* certain checks and certain players.
4141
*/
42-
4342
public final class CheckManager {
4443

4544
private final AntiCheatManager manager;

0 commit comments

Comments
 (0)