Moved YAxis check to seperate class, fixing it soon

This commit is contained in:
Rammelkast committed 2016-05-27 20:42:41 +02:00
1 parent 98a3a34b5d
commit b51ece796d
13 files changed
+160 -98

No files matched your search

@@ -38,6 +38,7 @@ import org.bukkit.potion.PotionEffectType;
import net.gravitydevelopment.anticheat.AntiCheat;
import net.gravitydevelopment.anticheat.check.movement.FlightCheck;
import net.gravitydevelopment.anticheat.check.movement.YAxisCheck;
import net.gravitydevelopment.anticheat.config.Configuration;
import net.gravitydevelopment.anticheat.config.providers.Lang;
import net.gravitydevelopment.anticheat.config.providers.Magic;
@@ -57,10 +58,6 @@ public class Backend {
private Map<String, Integer> nofallViolation = new HashMap<String, Integer>();
private Map<String, Integer> speedViolation = new HashMap<String, Integer>();
private Map<String, Integer> fastBreakViolation = new HashMap<String, Integer>();
private Map<String, Integer> yAxisViolations = new HashMap<String, Integer>();
private Map<String, Long> yAxisLastViolation = new HashMap<String, Long>();
private Map<String, Double> lastYcoord = new HashMap<String, Double>();
private Map<String, Long> lastYtime = new HashMap<String, Long>();
private Map<String, Integer> fastBreaks = new HashMap<String, Integer>();
private Map<String, Boolean> blockBreakHolder = new HashMap<String, Boolean>();
private Map<String, Long> lastBlockBroken = new HashMap<String, Long>();
@@ -138,10 +135,10 @@ public class Backend {
FlightCheck.blocksOverFlight.remove(pN);
nofallViolation.remove(pN);
fastBreakViolation.remove(pN);
yAxisViolations.remove(pN);
yAxisLastViolation.remove(pN);
lastYcoord.remove(pN);
lastYtime.remove(pN);
YAxisCheck.yAxisViolations.remove(pN);
YAxisCheck.yAxisLastViolation.remove(pN);
YAxisCheck.lastYcoord.remove(pN);
YAxisCheck.lastYtime.remove(pN);
fastBreaks.remove(pN);
blockBreakHolder.remove(pN);
lastBlockBroken.remove(pN);
@@ -452,63 +449,6 @@ public class Backend {
return PASS;
}
public CheckResult checkYAxis(Player player, Distance distance) {
if (distance.getYDifference() > magic.TELEPORT_MIN() || distance.getYDifference() < 0) {
return PASS;
}
if (!isMovingExempt(player) && !Utilities.isClimbableBlock(player.getLocation().getBlock()) && !Utilities.isClimbableBlock(player.getLocation().add(0, -1, 0).getBlock()) && !player.isInsideVehicle() && !Utilities.isInWater(player) && !hasJumpPotion(player)) {
double y1 = player.getLocation().getY();
String name = player.getName();
// Fix Y axis spam.
if (!lastYcoord.containsKey(name) || !lastYtime.containsKey(name) || !yAxisLastViolation.containsKey(name) || !yAxisLastViolation.containsKey(name)) {
lastYcoord.put(name, y1);
yAxisViolations.put(name, 0);
yAxisLastViolation.put(name, 0L);
lastYtime.put(name, System.currentTimeMillis());
} else {
if (y1 > lastYcoord.get(name) && yAxisViolations.get(name) > magic.Y_MAXVIOLATIONS() && (System.currentTimeMillis() - yAxisLastViolation.get(name)) < magic.Y_MAXVIOTIME()) {
Location g = player.getLocation();
yAxisViolations.put(name, yAxisViolations.get(name) + 1);
yAxisLastViolation.put(name, System.currentTimeMillis());
if (!silentMode()) {
g.setY(lastYcoord.get(name));
player.sendMessage(ChatColor.RED + "[AntiCheat] Fly hacking on the y-axis detected. Please wait 5 seconds to prevent getting damage.");
if (g.getBlock().getType() == Material.AIR) {
player.teleport(g);
}
}
return new CheckResult(CheckResult.Result.FAILED, player.getName() + " tried to fly on y-axis " + yAxisViolations.get(name) + " times (max =" + magic.Y_MAXVIOLATIONS() + ")");
} else {
if (yAxisViolations.get(name) > magic.Y_MAXVIOLATIONS() && (System.currentTimeMillis() - yAxisLastViolation.get(name)) > magic.Y_MAXVIOTIME()) {
yAxisViolations.put(name, 0);
yAxisLastViolation.put(name, 0L);
}
}
long i = System.currentTimeMillis() - lastYtime.get(name);
double diff = magic.Y_MAXDIFF() + (Utilities.isStair(player.getLocation().add(0, -1, 0).getBlock()) ? 0.5 : 0.0);
if ((y1 - lastYcoord.get(name)) > diff && i < magic.Y_TIME()) {
Location g = player.getLocation();
yAxisViolations.put(name, yAxisViolations.get(name) + 1);
yAxisLastViolation.put(name, System.currentTimeMillis());
if (!silentMode()) {
g.setY(lastYcoord.get(name));
if (g.getBlock().getType() == Material.AIR) {
player.teleport(g);
}
}
return new CheckResult(CheckResult.Result.FAILED, player.getName() + " tried to fly on y-axis in " + i + " ms (min =" + magic.Y_TIME() + ")");
} else {
if ((y1 - lastYcoord.get(name)) > magic.Y_MAXDIFF() + 1 || (System.currentTimeMillis() - lastYtime.get(name)) > magic.Y_TIME()) {
lastYtime.put(name, System.currentTimeMillis());
lastYcoord.put(name, y1);
}
}
}
}
// Fix Y axis spam
return PASS;
}
public CheckResult checkTimer(Player player) {
String name = player.getName();
int step = 1;
@@ -987,10 +927,10 @@ public class Backend {
/* Data for fly/speed should be reset */
nofallViolation.remove(player.getName());
FlightCheck.blocksOverFlight.remove(player.getName());
yAxisViolations.remove(player.getName());
yAxisLastViolation.remove(player.getName());
lastYcoord.remove(player.getName());
lastYtime.remove(player.getName());
YAxisCheck.yAxisViolations.remove(player.getName());
YAxisCheck.yAxisLastViolation.remove(player.getName());
YAxisCheck.lastYcoord.remove(player.getName());
YAxisCheck.lastYtime.remove(player.getName());
}
public void logExitFly(final Player player) {
@@ -57,7 +57,8 @@ public enum CheckType {
FAST_PROJECTILE(Permission.CHECK_FASTPROJECTILE),
ITEM_SPAM(Permission.CHECK_ITEMSPAM),
FAST_INVENTORY(Permission.CHECK_FASTINVENTORY),
AUTOTOOL(Permission.CHECK_AUTOTOOL);
AUTOTOOL(Permission.CHECK_AUTOTOOL),
GLIDE(Permission.CHECK_GLIDE);
private final Permission permission;
private final Map<String, Integer> level = new HashMap<String, Integer>();
@@ -49,7 +49,7 @@ public class FlightCheck {
return PASS;
}
private static boolean isMovingExempt(Player player) {
public static boolean isMovingExempt(Player player) {
return isDoing(player, movingExempt, -1);
}
@@ -0,0 +1,25 @@
package net.gravitydevelopment.anticheat.check.movement;
import java.util.HashMap;
import java.util.Map;
import org.bukkit.entity.Player;
import net.gravitydevelopment.anticheat.AntiCheat;
import net.gravitydevelopment.anticheat.check.CheckResult;
import net.gravitydevelopment.anticheat.util.Distance;
/**
*
* @author Marco STILL IN ALPHA TESTING!
*/
public class GlideCheck {
private static final CheckResult PASS = new CheckResult(CheckResult.Result.PASSED);
public static CheckResult runCheck(Player player, Distance distance) {
return PASS;
// TODO
}
}
@@ -0,0 +1,90 @@
package net.gravitydevelopment.anticheat.check.movement;
import java.util.HashMap;
import java.util.Map;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffectType;
import net.gravitydevelopment.anticheat.AntiCheat;
import net.gravitydevelopment.anticheat.check.CheckResult;
import net.gravitydevelopment.anticheat.util.Distance;
import net.gravitydevelopment.anticheat.util.Utilities;
/**
* The suckishness and false-positives of this check are killing me. TODO TODO TODO FIX THIS!!!1!
*/
public class YAxisCheck {
private static final CheckResult PASS = new CheckResult(CheckResult.Result.PASSED);
public static Map<String, Double> lastYcoord = new HashMap<String, Double>();
public static Map<String, Long> lastYtime = new HashMap<String, Long>();
public static Map<String, Integer> yAxisViolations = new HashMap<String, Integer>();
public static Map<String, Long> yAxisLastViolation = new HashMap<String, Long>();
private static boolean hasJumpPotion(Player player) {
return player.hasPotionEffect(PotionEffectType.JUMP);
}
public static CheckResult runCheck(Player player, Distance distance) {
if (distance.getYDifference() > AntiCheat.getManager().getBackend().getMagic().TELEPORT_MIN() || distance.getYDifference() < 0) {
return PASS;
}
if (!FlightCheck.isMovingExempt(player) && !Utilities.isClimbableBlock(player.getLocation().getBlock()) && !Utilities.isClimbableBlock(player.getLocation().add(0, -1, 0).getBlock()) && !player.isInsideVehicle() && !Utilities.isInWater(player) && !hasJumpPotion(player)) {
double y1 = player.getLocation().getY();
String name = player.getName();
// Fix Y axis spam.
if (!lastYcoord.containsKey(name) || !lastYtime.containsKey(name) || !yAxisLastViolation.containsKey(name) || !yAxisLastViolation.containsKey(name)) {
lastYcoord.put(name, y1);
yAxisViolations.put(name, 0);
yAxisLastViolation.put(name, 0L);
lastYtime.put(name, System.currentTimeMillis());
} else {
if (y1 > lastYcoord.get(name) && yAxisViolations.get(name) > AntiCheat.getManager().getBackend().getMagic().Y_MAXVIOLATIONS() && (System.currentTimeMillis() - yAxisLastViolation.get(name)) < AntiCheat.getManager().getBackend().getMagic().Y_MAXVIOTIME()) {
Location g = player.getLocation();
yAxisViolations.put(name, yAxisViolations.get(name) + 1);
yAxisLastViolation.put(name, System.currentTimeMillis());
if (!AntiCheat.getManager().getBackend().silentMode()) {
g.setY(lastYcoord.get(name));
player.sendMessage(ChatColor.RED + "[AntiCheat] Fly hacking on the y-axis detected. Please wait 5 seconds to prevent getting damage.");
if (g.getBlock().getType() == Material.AIR) {
player.teleport(g);
}
}
return new CheckResult(CheckResult.Result.FAILED, player.getName() + " tried to fly on y-axis " + yAxisViolations.get(name) + " times (max =" + AntiCheat.getManager().getBackend().getMagic().Y_MAXVIOLATIONS() + ")");
} else {
if (yAxisViolations.get(name) > AntiCheat.getManager().getBackend().getMagic().Y_MAXVIOLATIONS() && (System.currentTimeMillis() - yAxisLastViolation.get(name)) > AntiCheat.getManager().getBackend().getMagic().Y_MAXVIOTIME()) {
yAxisViolations.put(name, 0);
yAxisLastViolation.put(name, 0L);
}
}
long i = System.currentTimeMillis() - lastYtime.get(name);
double diff = AntiCheat.getManager().getBackend().getMagic().Y_MAXDIFF() + (Utilities.isStair(player.getLocation().add(0, -1, 0).getBlock()) ? 0.5 : 0.0);
if ((y1 - lastYcoord.get(name)) > diff && i < AntiCheat.getManager().getBackend().getMagic().Y_TIME()) {
Location g = player.getLocation();
yAxisViolations.put(name, yAxisViolations.get(name) + 1);
yAxisLastViolation.put(name, System.currentTimeMillis());
if (!AntiCheat.getManager().getBackend().silentMode()) {
g.setY(lastYcoord.get(name));
if (g.getBlock().getType() == Material.AIR) {
player.teleport(g);
}
}
return new CheckResult(CheckResult.Result.FAILED, player.getName() + " tried to fly on y-axis in " + i + " ms (min =" + AntiCheat.getManager().getBackend().getMagic().Y_TIME() + ")");
} else {
if ((y1 - lastYcoord.get(name)) > AntiCheat.getManager().getBackend().getMagic().Y_MAXDIFF() + 1 || (System.currentTimeMillis() - lastYtime.get(name)) > AntiCheat.getManager().getBackend().getMagic().Y_TIME()) {
lastYtime.put(name, System.currentTimeMillis());
lastYcoord.put(name, y1);
}
}
}
}
// Fix Y axis spam
return PASS;
}
}
@@ -55,6 +55,8 @@ 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.check.movement.GlideCheck;
import net.gravitydevelopment.anticheat.check.movement.YAxisCheck;
import net.gravitydevelopment.anticheat.util.Distance;
import net.gravitydevelopment.anticheat.util.Permission;
import net.gravitydevelopment.anticheat.util.User;
@@ -343,6 +345,15 @@ public class PlayerListener extends EventListener {
log(result.getMessage(), player, CheckType.FLY);
}
}
if (getCheckManager().willCheckQuick(player, CheckType.GLIDE) && !player.isFlying() && (Bukkit.getVersion().contains("1.9") && !player.isGliding()) /*TODO: ElytraFly check, this is a quick workaround */) {
CheckResult result = GlideCheck.runCheck(player, distance);
if (result.failed()) {
if (!silentMode()) {
event.setTo(user.getGoodLocation(from.clone()));
}
log(result.getMessage(), player, CheckType.GLIDE);
}
}
if (getCheckManager().willCheckQuick(player, CheckType.VCLIP) && event.getFrom().getY() > event.getTo().getY()) {
CheckResult result = getBackend().checkVClip(player, new Distance(event.getFrom(), event.getTo()));
if (result.failed()) {
@@ -459,7 +470,7 @@ public class PlayerListener extends EventListener {
}
if (getCheckManager().willCheck(player, CheckType.FLY) && !player.isFlying()) {
CheckResult result1 = getBackend().checkYAxis(player, new Distance(from, to));
CheckResult result1 = YAxisCheck.runCheck(player, new Distance(from, to));
CheckResult result2 = getBackend().checkAscension(player, from.getY(), to.getY());
String log = result1.failed() ? result1.getMessage() : result2.failed() ? result2.getMessage() : "";
if (!log.equals("")) {
@@ -48,6 +48,7 @@ public enum Permission {
CHECK_VISUAL,
CHECK_FASTINVENTORY,
CHECK_AUTOTOOL,
CHECK_GLIDE,
/* System Nodes */
SYSTEM_LOG,