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,
+9 -10
View File
@@ -1,14 +1,13 @@
# AntiCheat configuration file
# Please report any bugs: https://github.com/gravitylow/AntiCheat/issues
# AntiCheatReloaded configuration file
spam:
chat:
# Should AntiCheat block players spamming messages in chat?
# Should AntiCheatReloaded block players spamming messages in chat?
block-speed: true
block-repetition: true
# Valid actions = NONE,KICK,BAN,COMMAND[command]
action-one: KICK
action-two: BAN
# Should AntiCheat block players spamming commands in chat?
# Should AntiCheatReloaded block players spamming commands in chat?
command:
block-speed: true
block-repetition: true
@@ -18,22 +17,22 @@ spam:
system:
# Turning auto-update off is a _BAD_ idea. You will no longer be protected by the latest hacks/cheats if you do so, and will have to update manually.
auto-update: true
# Should AntiCheat log ALL failed checks to console?
# Should AntiCheatReloaded log ALL failed checks to console?
log-to-console: false
# Should AntiCheat log to file?
# Should AntiCheatReloaded log to file?
log-to-file: true
# Should AntiCheat display extra debug information when starting?
# Should AntiCheatReloaded display extra debug information when starting?
verbose-startup: false
# If silent mode is on, players will not be stopped when they try to hack, and AntiCheat will do everything possible to keep them unaware of their rising hack level.
# If silent mode is on, players will not be stopped when they try to hack, and AntiCheatReloaded will do everything possible to keep them unaware of their rising hack level.
# However, alerts will still be sent to console and to admins online, and events will still take place.
silent-mode: false
# Should ops be exempt from all checks?
exempt-op: false
# Should AntiCheat track plugins in its own registered events?
# Should AntiCheatReloaded track plugins in its own registered events?
event-chains: true
# Should Enterprise options be enabled? Only set this to true if you're an advanced user.
enterprise: false
# Use /anticheat check for a list of valid checks
# Use /AntiCheatReloaded check for a list of valid checks
disabled-checks:
- EXAMPLE_CHECK
disable-in:
+1 -2
View File
@@ -1,5 +1,4 @@
# AntiCheat configuration file
# Please report any bugs: https://github.com/gravitylow/AntiCheat/issues
# AntiCheatReloaded configuration file
groups:
- 'Medium : 20 : YELLOW : WARN'
- 'High : 50 : RED : KICK'
+5 -6
View File
@@ -1,15 +1,14 @@
# AntiCheat language file
# Please report any bugs: https://github.com/gravitylow/AntiCheat/issues
# AntiCheatReloaded language file
ALERT:
- '&player has just entered the &group hack group.'
- '&player''s last failed check was: &check.'
- 'Type ''/anticheat report &player'' for more information.'
WARNING:
- '[AntiCheat] Hacking is not permitted.'
- '[AntiCheat] If you continue to hack, action will be taken.'
BAN_REASON: 'Banned by AntiCheat'
- '[AntiCheatReloaded] Hacking is not permitted.'
- '[AntiCheatReloaded] If you continue to hack, action will be taken.'
BAN_REASON: 'Banned by AntiCheatReloaded'
BAN_BROADCAST: '&player was banned for hacking.'
KICK_REASON: 'Kicked by AntiCheat'
KICK_REASON: 'Kicked by AntiCheatReloaded'
KICK_BROADCAST: '&player was kicked for hacking.'
SPAM_WARNING: 'Stop spamming the server or you will be kicked!'
SPAM_KICK_REASON: 'Kicked for spamming'
+1 -3
View File
@@ -1,6 +1,4 @@
# AntiCheat configuration file
# Please report any bugs: http://dev.bukkit.org/server-mods/anticheat/
# Documentation for these values is available at http://gravitydevelopment.net/docs/anticheat/net/gravitydevelopment/anticheat/config/providers/Magic.html
# AntiCheatReloaded configuration file
ANIMATION_INTERACT_MAX: 3
ANIMATION_MIN: 200
ASCENSION_COUNT_MAX: 8
+3 -3
View File
@@ -1,7 +1,7 @@
author: Gravity
description: AntiCheat helps easily identify and block malicious users on your server.
name: AntiCheatReloaded
author: Rammelkast
description: AntiCheatReloaded helps easily identify and block malicious users on your server.
main: net.gravitydevelopment.anticheat.AntiCheat
name: AntiCheat
softdepend: [ProtocolLib]
startup: postworld
url: http://gravitydevelopment.net
+1 -2
View File
@@ -1,5 +1,4 @@
# AntiCheat configuration file
# Please report any bugs: https://github.com/gravitylow/AntiCheat/issues
# AntiCheatReloaded rules file
rules:
# if spider check is less than 0, set group to 20. otherwise, do nothing
- 'Check_SPIDER < 0 ? Player.KICK : null'