mirror of
https://github.com/darksaid98/AntiCheatReloaded.git
synced 2026-12-01 14:38:56 +00:00
Added/Fixed Glide check
This commit is contained in:
1 parent
831b82ff30
commit
9b87ce92eb
7 files changed
+42
-19
No files matched your search
@@ -57,8 +57,7 @@ public enum CheckType {
|
||||
FAST_PROJECTILE(Permission.CHECK_FASTPROJECTILE),
|
||||
ITEM_SPAM(Permission.CHECK_ITEMSPAM),
|
||||
FAST_INVENTORY(Permission.CHECK_FASTINVENTORY),
|
||||
AUTOTOOL(Permission.CHECK_AUTOTOOL),
|
||||
GLIDE(Permission.CHECK_GLIDE);
|
||||
AUTOTOOL(Permission.CHECK_AUTOTOOL);
|
||||
|
||||
private final Permission permission;
|
||||
private final Map<String, Integer> level = new HashMap<String, Integer>();
|
||||
|
||||
@@ -4,6 +4,7 @@ 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;
|
||||
|
||||
@@ -25,26 +26,27 @@ public class GlideCheck {
|
||||
|
||||
public static CheckResult runCheck(Player player, Distance distance) {
|
||||
String name = player.getName();
|
||||
if(!glideBuffer.containsKey(name))
|
||||
{
|
||||
glideBuffer.put(name, 0);
|
||||
}
|
||||
if(!lastYDelta.containsKey(name))
|
||||
{
|
||||
lastYDelta.put(name, 0.0);
|
||||
}
|
||||
if(!YAxisCheck.lastYcoord.containsKey(name))
|
||||
YAxisCheck.lastYcoord.put(name, player.getLocation().getY());
|
||||
double currentY = player.getLocation().getY();
|
||||
double math = currentY - YAxisCheck.lastYcoord.get(name);
|
||||
if(math < 0 && !AntiCheat.getManager().getBackend().isMovingExempt(player))
|
||||
{
|
||||
if(math <= lastYDelta.get(name) && !(player.getEyeLocation().getBlock().getType() == Material.LADDER)
|
||||
&& !Utilities.isInWater(player) && !Utilities.isInWeb(player)
|
||||
&& Utilities.cantStandAt(player.getLocation().getBlock()))
|
||||
&& Utilities.cantStandAtSingle(player.getLocation().getBlock()))
|
||||
{
|
||||
if(!glideBuffer.containsKey(name))
|
||||
glideBuffer.put(name, 0);
|
||||
int currentBuffer = glideBuffer.get(name);
|
||||
glideBuffer.put(name, currentBuffer + 1);
|
||||
if((currentBuffer + 1) >= AntiCheat.getManager().getBackend().getMagic().FLIGHT_LIMIT())
|
||||
if((currentBuffer + 1) >= AntiCheat.getManager().getBackend().getMagic().GLIDE_LIMIT())
|
||||
{
|
||||
double fallDist = distanceToFall(player.getLocation());
|
||||
player.teleport(player.getLocation().add(0, -fallDist, 0));
|
||||
player.setFallDistance((float) fallDist);
|
||||
if(!AntiCheat.getManager().getBackend().silentMode())
|
||||
{
|
||||
player.sendMessage(ChatColor.RED + "[AntiCheat] Glide/Fly hacking detected.");
|
||||
@@ -55,7 +57,14 @@ public class GlideCheck {
|
||||
}
|
||||
}
|
||||
lastYDelta.put(name, math);
|
||||
return PASS;
|
||||
return PASS;
|
||||
}
|
||||
|
||||
private static double distanceToFall(Location location) {
|
||||
double firstY = location.getY();
|
||||
while (location.clone().add(0, -0.1, 0).getBlock().getType() == Material.AIR)
|
||||
location.add(0, -0.1, 0);
|
||||
return firstY - location.getY();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -157,6 +157,10 @@ public interface Magic {
|
||||
* Number of times a player can be caught in-flight before action is taken; Type=INTEGER, Leniency=INCREASE.
|
||||
*/
|
||||
public int FLIGHT_LIMIT();
|
||||
/**
|
||||
* Number of times a player can be caught in-glide before action is taken; Type=INTEGER, Leniency=INCREASE.
|
||||
*/
|
||||
public int GLIDE_LIMIT();
|
||||
/**
|
||||
* How many blocks you can travel before action is taken; Type=INTEGER, Leniency=INCREASE.
|
||||
*/
|
||||
|
||||
@@ -307,7 +307,7 @@ public class PlayerListener extends EventListener {
|
||||
AntiCheat.getManager().addEvent(event.getEventName(), event.getHandlers().getRegisteredListeners());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
||||
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
|
||||
public void onPlayerMove(PlayerMoveEvent event) {
|
||||
final Player player = event.getPlayer();
|
||||
if (getCheckManager().checkInWorld(player) && !getCheckManager().isOpExempt(player)) {
|
||||
@@ -328,7 +328,7 @@ public class PlayerListener extends EventListener {
|
||||
log(result.getMessage(), player, CheckType.SPRINT);
|
||||
}
|
||||
}
|
||||
if (getCheckManager().willCheckQuick(player, CheckType.FLY) && !player.isFlying() && (Bukkit.getVersion().contains("1.9") && !player.isGliding()) /*TODO: ElytraFly check, this is a quick workaround */) {
|
||||
if (getCheckManager().willCheckQuick(player, CheckType.FLY) && !player.isFlying()) /*TODO: ElytraFly fix */ {
|
||||
CheckResult result = FlightCheck.runCheck(player, distance);
|
||||
if (result.failed()) {
|
||||
if (!silentMode()) {
|
||||
@@ -337,13 +337,11 @@ 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 */) {
|
||||
if (getCheckManager().willCheckQuick(player, CheckType.FLY) && !player.isFlying())/*TODO: ElytraFly fix */ {
|
||||
CheckResult result = GlideCheck.runCheck(player, distance);
|
||||
if (result.failed()) {
|
||||
if (!silentMode()) {
|
||||
event.setTo(user.getGoodLocation(from.clone()));
|
||||
}
|
||||
log(result.getMessage(), player, CheckType.GLIDE);
|
||||
// NO TELEPORT NEEDED HERE, HANDLED BY CHECK ITSELF
|
||||
log(result.getMessage(), player, CheckType.FLY);
|
||||
}
|
||||
}
|
||||
if (getCheckManager().willCheckQuick(player, CheckType.VCLIP) && event.getFrom().getY() > event.getTo().getY()) {
|
||||
|
||||
@@ -48,7 +48,6 @@ public enum Permission {
|
||||
CHECK_VISUAL,
|
||||
CHECK_FASTINVENTORY,
|
||||
CHECK_AUTOTOOL,
|
||||
CHECK_GLIDE,
|
||||
|
||||
/* System Nodes */
|
||||
SYSTEM_LOG,
|
||||
|
||||
@@ -61,6 +61,19 @@ public final class Utilities {
|
||||
AntiCheat.getManager().log(msg);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if only the block beneath them is standable (includes water + lava)
|
||||
* @param block the block to check (under)
|
||||
* @return true if they cannot stand there
|
||||
*/
|
||||
public static boolean cantStandAtSingle(Block block)
|
||||
{
|
||||
// TODO: Implement Better to reduce false positives (done? lets test...)
|
||||
Block otherBlock = block.getLocation().add(0, -0.5, 0).getBlock();
|
||||
boolean center = otherBlock.getType() == Material.AIR;
|
||||
return center;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether a player cannot stand on or around the given block
|
||||
|
||||
Reference in new issue
Block a user