Started with moving checks to their own classes, started with flight

This commit is contained in:
Rammelkast committed 2016-05-26 16:47:08 +02:00
1 parent 9af31633ea
commit 98a3a34b5d
4 files changed
+147 -72

No files matched your search

@@ -18,14 +18,12 @@
package net.gravitydevelopment.anticheat.check;
import net.gravitydevelopment.anticheat.AntiCheat;
import net.gravitydevelopment.anticheat.config.Configuration;
import net.gravitydevelopment.anticheat.config.providers.Lang;
import net.gravitydevelopment.anticheat.config.providers.Magic;
import net.gravitydevelopment.anticheat.manage.AntiCheatManager;
import net.gravitydevelopment.anticheat.util.User;
import net.gravitydevelopment.anticheat.util.Distance;
import net.gravitydevelopment.anticheat.util.Utilities;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.Location;
@@ -38,7 +36,15 @@ import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerToggleSprintEvent;
import org.bukkit.potion.PotionEffectType;
import java.util.*;
import net.gravitydevelopment.anticheat.AntiCheat;
import net.gravitydevelopment.anticheat.check.movement.FlightCheck;
import net.gravitydevelopment.anticheat.config.Configuration;
import net.gravitydevelopment.anticheat.config.providers.Lang;
import net.gravitydevelopment.anticheat.config.providers.Magic;
import net.gravitydevelopment.anticheat.manage.AntiCheatManager;
import net.gravitydevelopment.anticheat.util.Distance;
import net.gravitydevelopment.anticheat.util.User;
import net.gravitydevelopment.anticheat.util.Utilities;
public class Backend {
private List<String> isInWater = new ArrayList<String>();
@@ -46,7 +52,6 @@ public class Backend {
private List<String> isAscending = new ArrayList<String>();
private Map<String, Integer> interactionCount = new HashMap<String, Integer>();
private Map<String, Integer> ascensionCount = new HashMap<String, Integer>();
private Map<String, Double> blocksOverFlight = new HashMap<String, Double>();
private Map<String, Integer> chatLevel = new HashMap<String, Integer>();
private Map<String, Integer> commandLevel = new HashMap<String, Integer>();
private Map<String, Integer> nofallViolation = new HashMap<String, Integer>();
@@ -77,7 +82,6 @@ public class Backend {
private Map<String, Long> sprinted = new HashMap<String, Long>();
private Map<String, Long> brokenBlock = new HashMap<String, Long>();
private Map<String, Long> placedBlock = new HashMap<String, Long>();
private Map<String, Long> movingExempt = new HashMap<String, Long>();
private Map<String, Long> blockTime = new HashMap<String, Long>();
private Map<String, Integer> blocksDropped = new HashMap<String, Integer>();
private Map<String, Long> lastInventoryTime = new HashMap<String, Long>();
@@ -100,6 +104,10 @@ public class Backend {
lang = manager.getConfiguration().getLang();
transparent.add((byte) -1);
}
public Magic getMagic() {
return magic;
}
public void updateConfig(Configuration config) {
magic = config.getMagic();
@@ -115,7 +123,7 @@ public class Backend {
blocksDropped.remove(pN);
blockTime.remove(pN);
movingExempt.remove(pN);
FlightCheck.movingExempt.remove(pN);
brokenBlock.remove(pN);
placedBlock.remove(pN);
bowWindUp.remove(pN);
@@ -127,7 +135,7 @@ public class Backend {
instantBreakExempt.remove(pN);
isAscending.remove(pN);
ascensionCount.remove(pN);
blocksOverFlight.remove(pN);
FlightCheck.blocksOverFlight.remove(pN);
nofallViolation.remove(pN);
fastBreakViolation.remove(pN);
yAxisViolations.remove(pN);
@@ -155,7 +163,7 @@ public class Backend {
sprinted.remove(pN);
brokenBlock.remove(pN);
placedBlock.remove(pN);
movingExempt.remove(pN);
FlightCheck.movingExempt.remove(pN);
blockTime.remove(pN);
blocksDropped.remove(pN);
lastInventoryTime.remove(pN);
@@ -557,36 +565,6 @@ public class Backend {
return PASS;
}
public CheckResult checkFlight(Player player, Distance distance) {
if (distance.getYDifference() > magic.TELEPORT_MIN()) {
// This was a teleport, so we don't care about it.
return PASS;
}
final String name = player.getName();
final double y1 = distance.fromY();
final double y2 = distance.toY();
if (!isMovingExempt(player) && !Utilities.isHoveringOverWater(player.getLocation(), 1) && Utilities.cantStandAtExp(player.getLocation()) && Utilities.blockIsnt(player.getLocation().getBlock().getRelative(BlockFace.DOWN), new Material[]{Material.FENCE, Material.FENCE_GATE, Material.COBBLE_WALL})) {
if (!blocksOverFlight.containsKey(name)) {
blocksOverFlight.put(name, 0D);
}
blocksOverFlight.put(name, (blocksOverFlight.get(name) + distance.getXDifference() + distance.getYDifference() + distance.getZDifference()));
if (y1 > y2) {
blocksOverFlight.put(name, (blocksOverFlight.get(name) - distance.getYDifference()));
}
if (blocksOverFlight.get(name) > magic.FLIGHT_BLOCK_LIMIT() && (y1 <= y2)) {
return new CheckResult(CheckResult.Result.FAILED, player.getName() + " flew over " + blocksOverFlight.get(name) + " blocks (max=" + magic.FLIGHT_BLOCK_LIMIT() + ")");
}
} else {
blocksOverFlight.put(name, 0D);
}
return PASS;
}
public void logAscension(Player player, double y1, double y2) {
String name = player.getName();
if (y1 < y2 && !isAscending.contains(name)) {
@@ -991,24 +969,24 @@ public class Backend {
break;
}
movingExempt.put(player.getName(), System.currentTimeMillis() + time);
FlightCheck.movingExempt.put(player.getName(), System.currentTimeMillis() + time);
// Only map in which termination time is calculated beforehand.
}
public void logEnterExit(final Player player) {
movingExempt.put(player.getName(), System.currentTimeMillis() + magic.ENTERED_EXITED_TIME());
FlightCheck.movingExempt.put(player.getName(), System.currentTimeMillis() + magic.ENTERED_EXITED_TIME());
}
public void logToggleSneak(final Player player) {
movingExempt.put(player.getName(), System.currentTimeMillis() + magic.SNEAK_TIME());
FlightCheck.movingExempt.put(player.getName(), System.currentTimeMillis() + magic.SNEAK_TIME());
}
public void logTeleport(final Player player) {
movingExempt.put(player.getName(), System.currentTimeMillis() + magic.TELEPORT_TIME());
FlightCheck.movingExempt.put(player.getName(), System.currentTimeMillis() + magic.TELEPORT_TIME());
/* Data for fly/speed should be reset */
nofallViolation.remove(player.getName());
blocksOverFlight.remove(player.getName());
FlightCheck.blocksOverFlight.remove(player.getName());
yAxisViolations.remove(player.getName());
yAxisLastViolation.remove(player.getName());
lastYcoord.remove(player.getName());
@@ -1016,15 +994,15 @@ public class Backend {
}
public void logExitFly(final Player player) {
movingExempt.put(player.getName(), System.currentTimeMillis() + magic.EXIT_FLY_TIME());
FlightCheck.movingExempt.put(player.getName(), System.currentTimeMillis() + magic.EXIT_FLY_TIME());
}
public void logJoin(final Player player) {
movingExempt.put(player.getName(), System.currentTimeMillis() + magic.JOIN_TIME());
FlightCheck.movingExempt.put(player.getName(), System.currentTimeMillis() + magic.JOIN_TIME());
}
public boolean isMovingExempt(Player player) {
return isDoing(player, movingExempt, -1);
return isDoing(player, FlightCheck.movingExempt, -1);
}
public boolean isAscending(Player player) {
@@ -0,0 +1,79 @@
package net.gravitydevelopment.anticheat.check.movement;
import java.util.HashMap;
import java.util.Map;
import org.bukkit.Material;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
import net.gravitydevelopment.anticheat.AntiCheat;
import net.gravitydevelopment.anticheat.check.CheckResult;
import net.gravitydevelopment.anticheat.util.Distance;
import net.gravitydevelopment.anticheat.util.Utilities;
public class FlightCheck {
private static final CheckResult PASS = new CheckResult(CheckResult.Result.PASSED);
public static Map<String, Double> blocksOverFlight = new HashMap<String, Double>();
public static Map<String, Long> movingExempt = new HashMap<String, Long>();
public static CheckResult runCheck(Player player, Distance distance) {
if (distance.getYDifference() > AntiCheat.getManager().getBackend().getMagic().TELEPORT_MIN()) {
// This was a teleport, so we don't care about it.
return PASS;
}
final String name = player.getName();
final double y1 = distance.fromY();
final double y2 = distance.toY();
if (!isMovingExempt(player) && !Utilities.isHoveringOverWater(player.getLocation(), 1) && Utilities.cantStandAtExp(player.getLocation()) && Utilities.blockIsnt(player.getLocation().getBlock().getRelative(BlockFace.DOWN), new Material[]{Material.FENCE, Material.FENCE_GATE, Material.COBBLE_WALL})) {
if (!blocksOverFlight.containsKey(name)) {
blocksOverFlight.put(name, 0D);
}
blocksOverFlight.put(name, (blocksOverFlight.get(name) + distance.getXDifference() + distance.getYDifference() + distance.getZDifference()));
if (y1 > y2) {
blocksOverFlight.put(name, (blocksOverFlight.get(name) - distance.getYDifference()));
}
if (blocksOverFlight.get(name) > AntiCheat.getManager().getBackend().getMagic().FLIGHT_BLOCK_LIMIT() && (y1 <= y2)) {
return new CheckResult(CheckResult.Result.FAILED, player.getName() + " flew over " + blocksOverFlight.get(name) + " blocks (max=" + AntiCheat.getManager().getBackend().getMagic().FLIGHT_BLOCK_LIMIT() + ")");
}
} else {
blocksOverFlight.put(name, 0D);
}
return PASS;
}
private static boolean isMovingExempt(Player player) {
return isDoing(player, movingExempt, -1);
}
private static boolean isDoing(Player player, Map<String, Long> map, double max) {
if (map.containsKey(player.getName())) {
if (max != -1) {
if (((System.currentTimeMillis() - map.get(player.getName())) / 1000) > max) {
map.remove(player.getName());
return false;
} else {
return true;
}
} else {
// Termination time has already been calculated
if (map.get(player.getName()) < System.currentTimeMillis()) {
map.remove(player.getName());
return false;
} else {
return true;
}
}
} else {
return false;
}
}
}
@@ -24,20 +24,20 @@ import org.bukkit.command.CommandSender;
public class CommandHelp extends CommandBase {
private static final String NAME = "AntiCheat Help";
private static final String NAME = "AntiCheatReloaded Help";
private static final String COMMAND = "help";
private static final String USAGE = "anticheat help";
private static final Permission PERMISSION = Permission.SYSTEM_HELP;
private static final String[] HELP = {
GRAY + "/anti " + AQUA + "help",
GRAY + "/anti " + AQUA + "reload",
GRAY + "/anti " + AQUA + "update",
GRAY + "/anti " + AQUA + "debug " + AQUA + "<user>",
GRAY + "/anti " + AQUA + "check " + GOLD + "[check] [on/off]",
GRAY + "/anti " + AQUA + "log " + GOLD + "[file/console] [on/off]",
GRAY + "/anti " + AQUA + "report " + GOLD + "[group/user]",
GRAY + "/anti " + AQUA + "reset " + GOLD + "[user]",
GRAY + "/anti " + AQUA + "spy " + GOLD + "[user]",
RED + "/anti " + GRAY + "help",
RED + "/anti " + GRAY + "reload",
RED + "/anti " + GRAY + "update",
RED + "/anti " + GRAY + "debug " + WHITE + "<user>",
RED + "/anti " + GRAY + "check " + WHITE + "[check] [on/off]",
RED + "/anti " + GRAY + "log " + WHITE + "[file/console] [on/off]",
RED + "/anti " + GRAY + "report " + WHITE + "[group/user]",
RED + "/anti " + GRAY + "reset " + WHITE + "[user]",
RED + "/anti " + GRAY + "spy " + WHITE + "[user]",
};
public CommandHelp() {
@@ -18,14 +18,6 @@
package net.gravitydevelopment.anticheat.event;
import net.gravitydevelopment.anticheat.AntiCheat;
import net.gravitydevelopment.anticheat.check.CheckType;
import net.gravitydevelopment.anticheat.util.User;
import net.gravitydevelopment.anticheat.check.CheckResult;
import net.gravitydevelopment.anticheat.util.Distance;
import net.gravitydevelopment.anticheat.util.Permission;
import net.gravitydevelopment.anticheat.util.Utilities;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
@@ -38,10 +30,36 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.block.Action;
import org.bukkit.event.entity.ProjectileLaunchEvent;
import org.bukkit.event.player.*;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerAnimationEvent;
import org.bukkit.event.player.PlayerBedEnterEvent;
import org.bukkit.event.player.PlayerBedLeaveEvent;
import org.bukkit.event.player.PlayerChangedWorldEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerDropItemEvent;
import org.bukkit.event.player.PlayerGameModeChangeEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerKickEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import org.bukkit.event.player.PlayerToggleFlightEvent;
import org.bukkit.event.player.PlayerToggleSneakEvent;
import org.bukkit.event.player.PlayerToggleSprintEvent;
import org.bukkit.event.player.PlayerVelocityEvent;
import org.bukkit.inventory.PlayerInventory;
import net.gravitydevelopment.anticheat.AntiCheat;
import net.gravitydevelopment.anticheat.check.CheckResult;
import net.gravitydevelopment.anticheat.check.CheckType;
import net.gravitydevelopment.anticheat.check.movement.FlightCheck;
import net.gravitydevelopment.anticheat.util.Distance;
import net.gravitydevelopment.anticheat.util.Permission;
import net.gravitydevelopment.anticheat.util.User;
import net.gravitydevelopment.anticheat.util.Utilities;
public class PlayerListener extends EventListener {
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
@@ -317,7 +335,7 @@ public class PlayerListener extends EventListener {
}
}
if (getCheckManager().willCheckQuick(player, CheckType.FLY) && !player.isFlying() && (Bukkit.getVersion().contains("1.9") && !player.isGliding()) /*TODO: ElytraFly check, this is a quick workaround */) {
CheckResult result = getBackend().checkFlight(player, distance);
CheckResult result = FlightCheck.runCheck(player, distance);
if (result.failed()) {
if (!silentMode()) {
event.setTo(user.getGoodLocation(from.clone()));