Major improvements to movement related checks, including Waterwalk and Fly specifically. Improved because they're teleported back to their recorded good location, not the getFrom() from the event.

This commit is contained in:
SuPaH sPii committed 2012-11-21 14:52:18 -06:00
1 parent e0a12cb0ef
commit 994e2be704
6 files changed
+206 -55

No files matched your search

@@ -66,7 +66,7 @@ public class PlayerListener extends EventListener
@EventHandler
public void onPlayerToggleFlight(PlayerToggleFlightEvent event)
{
if(!event.isFlying())
if (!event.isFlying())
{
backend.logEnterExit(event.getPlayer());
}
@@ -75,7 +75,7 @@ public class PlayerListener extends EventListener
@EventHandler
public void onPlayerGameModeChange(PlayerGameModeChangeEvent event)
{
if(event.getNewGameMode() != GameMode.CREATIVE)
if (event.getNewGameMode() != GameMode.CREATIVE)
{
backend.logEnterExit(event.getPlayer());
}
@@ -153,7 +153,7 @@ public class PlayerListener extends EventListener
event.setCancelled(b);
if (b)
{
player.sendMessage(ChatColor.RED+config.getLang().getChatWarning());
player.sendMessage(ChatColor.RED + config.getLang().getChatWarning());
}
}
}
@@ -271,9 +271,9 @@ public class PlayerListener extends EventListener
{
getUserManager().addUserFromFile(player.getName());
}
if(player.hasMetadata(Anticheat.SPY_METADATA))
if (player.hasMetadata(Anticheat.SPY_METADATA))
{
for(Player p : player.getServer().getOnlinePlayers())
for (Player p : player.getServer().getOnlinePlayers())
{
if (!Permission.SYSTEM_SPY.get(p))
{
@@ -292,11 +292,12 @@ public class PlayerListener extends EventListener
Distance distance = new Distance(from, to);
double y = distance.getYDifference();
backend.logAscension(player, from.getY(), to.getY());
if (checkManager.willCheck(player, CheckType.FLY) && !player.isFlying() && checkManager.willCheck(player, CheckType.ZOMBE_FLY) && backend.checkFlight(player, distance))
{
if (!config.silentMode())
{
event.setTo(from.clone());
event.setTo(Anticheat.getManager().getUserManager().getUser(player.getName()).getGoodLocation(from.clone()));
}
log("tried to fly.", player, CheckType.FLY);
}
@@ -304,7 +305,7 @@ public class PlayerListener extends EventListener
{
if (!config.silentMode())
{
event.setTo(from.clone());
event.setTo(Anticheat.getManager().getUserManager().getUser(player.getName()).getGoodLocation(from.clone()));
}
log("tried to fly on y-axis", player, CheckType.FLY);
}
@@ -318,13 +319,17 @@ public class PlayerListener extends EventListener
{
// You come back up, and you suddenly feel sick from trying to stick yourself through the blocks..
Location newloc = new Location(player.getWorld(), event.getFrom().getX(), event.getFrom().getY() + result, event.getFrom().getZ());
if (result > 3)
{
result = 3; // prevents players from using AC as a way to teleport to sky islands.
}
if (newloc.getBlock().getTypeId() == 0)
{
event.setTo(newloc);
}
else
{
event.setTo(event.getFrom());
event.setTo(Anticheat.getManager().getUserManager().getUser(player.getName()).getGoodLocation(from.clone()));
}
player.damage(3);
}
@@ -335,7 +340,7 @@ public class PlayerListener extends EventListener
{
if (!config.silentMode())
{
event.setTo(from);
event.setTo(Anticheat.getManager().getUserManager().getUser(player.getName()).getGoodLocation(from.clone()));
player.damage(2); // I added this in here so the player(s) would still receive damage.
}
log("tried to avoid fall damage.", player, CheckType.NOFALL);
@@ -348,6 +353,8 @@ public class PlayerListener extends EventListener
Player player = event.getPlayer();
Location from = event.getFrom();
Location to = event.getTo();
boolean changed = false;
if (event.getTo() != event.getFrom())
{
Distance distance = new Distance(from, to);
@@ -360,51 +367,62 @@ public class PlayerListener extends EventListener
{
if (!config.silentMode())
{
event.setTo(from);
event.setTo(Anticheat.getManager().getUserManager().getUser(player.getName()).getGoodLocation(from.clone()));
}
log("tried to ascend too fast.", player, CheckType.SPEED);
changed = true;
}
if (backend.checkXZSpeed(player, x, z))
{
if (!config.silentMode())
{
event.setTo(from);
event.setTo(Anticheat.getManager().getUserManager().getUser(player.getName()).getGoodLocation(from.clone()));
}
log("tried to move too fast.", player, CheckType.SPEED);
changed = true;
}
if((event.getFrom().getX() != event.getTo().getX() || event.getFrom().getZ() != event.getTo().getZ()) && backend.checkTimer(player))
if ((event.getFrom().getX() != event.getTo().getX() || event.getFrom().getZ() != event.getTo().getZ()) && backend.checkTimer(player))
{
if (!config.silentMode())
{
event.setTo(from);
event.setTo(Anticheat.getManager().getUserManager().getUser(player.getName()).getGoodLocation(from.clone()));
}
log("tried to move too fast.", player, CheckType.SPEED);
changed = true;
}
}
if (checkManager.willCheck(player, CheckType.WATER_WALK) && backend.checkWaterWalk(player, x, z))
if (checkManager.willCheck(player, CheckType.WATER_WALK) && backend.checkWaterWalk(player, x, y, z))
{
if (!config.silentMode())
{
player.teleport(player.getLocation().add(0, -1, 0));
player.teleport(Anticheat.getManager().getUserManager().getUser(player.getName()).getGoodLocation(player.getLocation().add(0, -1, 0)));
}
log("tried to walk on water.", player, CheckType.WATER_WALK);
changed = true;
}
if (checkManager.willCheck(player, CheckType.SNEAK) && backend.checkSneak(player, x, z))
{
if (!config.silentMode())
{
event.setTo(from);
event.setTo(Anticheat.getManager().getUserManager().getUser(player.getName()).getGoodLocation(from.clone()));
player.setSneaking(false);
}
log("tried to sneak too fast.", player, CheckType.SNEAK);
changed = true;
}
if (checkManager.willCheck(player, CheckType.SPIDER) && backend.checkSpider(player, y))
{
if (!config.silentMode())
{
event.setTo(from);
event.setTo(Anticheat.getManager().getUserManager().getUser(player.getName()).getGoodLocation(from.clone()));
}
log("tried to climb a wall.", player, CheckType.SPIDER);
changed = true;
}
if (!changed)
{
Anticheat.getManager().getUserManager().getUser(player.getName()).setGoodLocation(event.getFrom());
}
}
}
@@ -49,7 +49,7 @@ public class Backend
private Map<String, Integer> ascensionCount = new HashMap<String, Integer>();
private Map<String, String> oldMessage = new HashMap<String, String>();
private Map<String, String> lastMessage = new HashMap<String, String>();
private Map<String, Integer> flightViolation = 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> chatKicks = new HashMap<String, Integer>();
private Map<String, Integer> nofallViolation = new HashMap<String, Integer>();
@@ -123,7 +123,7 @@ public class Backend
ascensionCount.remove(pN);
oldMessage.remove(pN);
lastMessage.remove(pN);
flightViolation.remove(pN);
blocksOverFlight.remove(pN);
chatLevel.remove(pN);
nofallViolation.remove(pN);
fastBreakViolation.remove(pN);
@@ -341,9 +341,10 @@ public class Backend
}
}
public boolean checkWaterWalk(Player player, double x, double z)
public boolean checkWaterWalk(Player player, double x, double y, double z)
{
Block block = player.getLocation().getBlock();
if (player.getVehicle() == null && !player.isFlying())
{
if (block.isLiquid())
@@ -363,6 +364,10 @@ public class Backend
{
b = true;
}
else if (!Utilities.isFullyInWater(player.getLocation()) && Utilities.isHoveringOverWater(player.getLocation(), 1) && y == 0D && !block.getType().equals(Material.WATER_LILY))
{
b = true;
}
if (b)
{
if (waterSpeedViolation.containsKey(player.getName()))
@@ -410,6 +415,7 @@ public class Backend
else
{
waterAscensionViolation.put(player.getName(), v + 1);
return true;
}
}
else
@@ -593,38 +599,61 @@ public class Backend
String name = player.getName();
double y1 = distance.fromY();
double y2 = distance.toY();
if (!isMovingExempt(player) && !Utilities.isInWater(player) && !Utilities.canStand(player.getLocation().getBlock()) && Utilities.cantStandAt(player.getLocation().add(0, -1, 0).getBlock()) && Utilities.cantStandAt(player.getLocation().add(0, -2, 0).getBlock()))
//Check if the player is climbing up water.
/* if (block.getRelative(BlockFace.NORTH).isLiquid() || block.getRelative(BlockFace.SOUTH).isLiquid() || block.getRelative(BlockFace.EAST).isLiquid() || block.getRelative(BlockFace.WEST).isLiquid())
{
if (y1 < y2)
{
//Even if they are using a hacked client and flying next to water to abuse this, they can't be go past the speed limit so they might as well swim
return distance.getYDifference() > magic.WATER_CLIMB_MAX;
}
} */
if (!isMovingExempt(player) && !Utilities.isHoveringOverWater(player.getLocation(), 1) && Utilities.cantStandAtExp(player.getLocation()))
{
Block block = player.getLocation().getBlock();
//Check if the player is climbing up water.
if (block.getRelative(BlockFace.NORTH).isLiquid() || block.getRelative(BlockFace.SOUTH).isLiquid() || block.getRelative(BlockFace.EAST).isLiquid() || block.getRelative(BlockFace.WEST).isLiquid())
/* if (y1 == y2 || y1 < y2)
{
if (y1 == y2)
{
//Check if the player is on slabs or crouching on stairs
if (Utilities.isSlab(block.getRelative(BlockFace.NORTH)) || Utilities.isSlab(block.getRelative(BlockFace.SOUTH)) || Utilities.isSlab(block.getRelative(BlockFace.EAST)) || Utilities.isSlab(block.getRelative(BlockFace.WEST)) || Utilities.isSlab(block.getRelative(BlockFace.NORTH_EAST)) || Utilities.isSlab(block.getRelative(BlockFace.SOUTH_EAST)) || Utilities.isSlab(block.getRelative(BlockFace.SOUTH_WEST)) || Utilities.isSlab(block.getRelative(BlockFace.NORTH_WEST)))
{
return false;
}
else if (player.isSneaking() && (Utilities.isStair(block.getRelative(BlockFace.NORTH)) || Utilities.isStair(block.getRelative(BlockFace.SOUTH)) || Utilities.isStair(block.getRelative(BlockFace.EAST)) || Utilities.isStair(block.getRelative(BlockFace.WEST)) || Utilities.isStair(block.getRelative(BlockFace.NORTH_EAST)) || Utilities.isStair(block.getRelative(BlockFace.SOUTH_EAST)) || Utilities.isStair(block.getRelative(BlockFace.SOUTH_WEST)) || Utilities.isStair(block.getRelative(BlockFace.NORTH_WEST))))
{
return false;
}
int violation = flightViolation.containsKey(name) ? flightViolation.get(name) + 1 : 1;
increment(player, flightViolation, violation);
return violation > magic.FLIGHT_LIMIT;
} */
if (!blocksOverFlight.containsKey(name))
{
if (y1 < y2)
{
//Even if they are using a hacked client and flying next to water to abuse this, they can't be go past the speed limit so they might as well swim
return distance.getYDifference() > magic.WATER_CLIMB_MAX;
}
blocksOverFlight.put(name, 0D);
}
else if (y1 == y2 || y1 < y2)
blocksOverFlight.put(name, (blocksOverFlight.get(name) + distance.getXDifference() + distance.getYDifference() + distance.getZDifference()));
if (y1 > y2)
{
if (y1 == y2)
{
//Check if the player is on slabs or crouching on stairs
if (Utilities.isSlab(block.getRelative(BlockFace.NORTH)) || Utilities.isSlab(block.getRelative(BlockFace.SOUTH)) || Utilities.isSlab(block.getRelative(BlockFace.EAST)) || Utilities.isSlab(block.getRelative(BlockFace.WEST)) || Utilities.isSlab(block.getRelative(BlockFace.NORTH_EAST)) || Utilities.isSlab(block.getRelative(BlockFace.SOUTH_EAST)) || Utilities.isSlab(block.getRelative(BlockFace.SOUTH_WEST)) || Utilities.isSlab(block.getRelative(BlockFace.NORTH_WEST)))
{
return false;
}
else if (player.isSneaking() && (Utilities.isStair(block.getRelative(BlockFace.NORTH)) || Utilities.isStair(block.getRelative(BlockFace.SOUTH)) || Utilities.isStair(block.getRelative(BlockFace.EAST)) || Utilities.isStair(block.getRelative(BlockFace.WEST)) || Utilities.isStair(block.getRelative(BlockFace.NORTH_EAST)) || Utilities.isStair(block.getRelative(BlockFace.SOUTH_EAST)) || Utilities.isStair(block.getRelative(BlockFace.SOUTH_WEST)) || Utilities.isStair(block.getRelative(BlockFace.NORTH_WEST))))
{
return false;
}
}
int violation = flightViolation.containsKey(name) ? flightViolation.get(name) + 1 : 1;
increment(player, flightViolation, violation);
return violation > magic.FLIGHT_LIMIT;
blocksOverFlight.put(name, (blocksOverFlight.get(name) - distance.getYDifference()));
}
if (blocksOverFlight.get(name) > magic.FLIGHT_BLOCK_LIMIT && (y1 <= y2))
{
return true;
}
}
flightViolation.put(name, 0);
else
{
blocksOverFlight.put(name, 0D);
}
return false;
}
@@ -749,7 +778,7 @@ public class Backend
}
else if (fastBreaks.get(name) >= magic.FASTBREAK_LIMIT)
{
if(!blockBreakHolder.containsKey(name) || !blockBreakHolder.get(name))
if (!blockBreakHolder.containsKey(name) || !blockBreakHolder.get(name))
{
blockBreakHolder.put(name, true);
}
@@ -760,9 +789,6 @@ public class Backend
}
}
}
System.out.println(System.currentTimeMillis() - lastBlockBroken.get(name));
System.out.println(fastBreaks.get(name));
lastBlockBroken.put(name, System.currentTimeMillis()); // always keep a log going.
}
@@ -980,6 +1006,18 @@ public class Backend
return isDoing(player, sprinted, magic.SPRINT_MIN);
}
public boolean isHoveringOverWaterAfterViolation(Player player)
{
if (waterSpeedViolation.containsKey(player.getName()))
{
if (waterSpeedViolation.get(player.getName()) >= magic.WATER_SPEED_VIOLATION_MAX && Utilities.isHoveringOverWater(player.getLocation()))
{
return true;
}
}
return false;
}
public void logBlockBreak(final Player player)
{
brokenBlock.put(player.getName(), System.currentTimeMillis());
@@ -1104,7 +1142,7 @@ public class Backend
/* Data for fly/speed should be reset */
nofallViolation.remove(player.getName());
flightViolation.remove(player.getName());
blocksOverFlight.remove(player.getName());
yAxisViolations.remove(player.getName());
yAxisLastViolation.remove(player.getName());
lastYcoord.remove(player.getName());
@@ -20,7 +20,10 @@ package net.h31ix.anticheat.manage;
import net.h31ix.anticheat.Anticheat;
import net.h31ix.anticheat.util.Configuration;
import net.h31ix.anticheat.util.Utilities;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
public class User
@@ -29,6 +32,7 @@ public class User
private int level = 0;
private int high;
private int med;
private Location goodLocation;
private boolean silentMode;
public User(String name)
@@ -69,7 +73,7 @@ public class User
public boolean increaseLevel(CheckType type)
{
if(getPlayer().isOnline())
if(getPlayer() != null || getPlayer().isOnline())
{
if(silentMode && type.getUses(name) % 4 != 0)
{
@@ -119,5 +123,35 @@ public class User
type.clearUse(name);
}
}
public Location getGoodLocation(Location e)
{
if(goodLocation == null)
{
return e;
}
return goodLocation;
}
public boolean hasGoodLocation()
{
return goodLocation != null;
}
public void setGoodLocation(Location e)
{
if(Utilities.cantStandAtExp(e))
{
return;
}
if(e.getBlock().isLiquid() && !Utilities.isFullyInWater(e))
{
return;
}
goodLocation = e;
}
}
@@ -160,6 +160,10 @@ public class Magic
* Number of times a player can be caught in-flight before action is taken; Type=integer, +Leniency=Increase.
*/
public final int FLIGHT_LIMIT;
/**
* How many blocks you can travel before action is taken; Type=integer, +Leniency=Increase.
*/
public final double FLIGHT_BLOCK_LIMIT;
/**
* Maximum speed that a player can climb a waterfall; Type=double, +Leniency=Increase.
*/
@@ -362,6 +366,7 @@ public class Magic
CHAT_KICK_LEVEL = getInt("CHAT_KICK_LEVEL");
CHAT_BAN_LEVEL = getInt("CHAT_BAN_LEVEL");
FLIGHT_LIMIT = getInt("FLIGHT_LIMIT");
FLIGHT_BLOCK_LIMIT = getDouble("FLIGHT_BLOCK_LIMIT");
WATER_CLIMB_MAX = getDouble("WATER_CLIMB_MAX");
Y_MAXVIOLATIONS = getInt("Y_MAXVIOLATIONS");
Y_MAXVIOTIME = getInt("Y_MAXVIOTIME");
@@ -22,10 +22,12 @@ import java.util.ArrayList;
import java.util.List;
import net.h31ix.anticheat.Anticheat;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Player;
import org.bukkit.util.NumberConversions;
public final class Utilities
{
@@ -65,6 +67,13 @@ public final class Utilities
{
return !canStand(block) && cantStandClose(block) && cantStandFar(block);
}
public static boolean cantStandAtExp(Location block)
{
// This is a experimental check for checking whether you can't stand at or whatever.
Block nblock = new Location(block.getWorld(), fixXAxis(block.getX()), block.getY() - 0.01D, block.getBlockZ()).getBlock();
return cantStandAt(nblock);
}
public static boolean cantStandClose(Block block)
{
@@ -80,6 +89,52 @@ public final class Utilities
{
return !(block.isLiquid() || block.getType() == Material.AIR);
}
public static boolean isFullyInWater(Location player)
{
double touchedX = fixXAxis(player.getX());
// Yes, this doesn't make sense, but it's supposed to fix some false positives in water walk.
// Think of it as 2 negatives = a positive :)
if(!(new Location(player.getWorld(), touchedX, player.getY(), player.getBlockZ()).getBlock()).isLiquid() && !(new Location(player.getWorld(), touchedX, Math.round(player.getY()), player.getBlockZ()).getBlock()).isLiquid())
{
return true;
}
return (new Location(player.getWorld(), touchedX, player.getY(), player.getBlockZ()).getBlock()).isLiquid() && (new Location(player.getWorld(), touchedX, Math.round(player.getY()), player.getBlockZ()).getBlock()).isLiquid();
}
public static double fixXAxis(double x)
{
/* Really really really useful function for those who are on the edges of blocks */
/* For Z axis, just use Math.round(xaxis); */
double touchedX = x;
double rem = touchedX - Math.round(touchedX) + 0.01D;
if (rem < 0.30D)
{
touchedX = NumberConversions.floor(x) - 1;
}
return touchedX;
}
public static boolean isHoveringOverWater(Location player, int blocks)
{
for(int i = player.getBlockY(); i > player.getBlockY() - blocks; i--)
{
Block newloc = (new Location(player.getWorld(), player.getBlockX(), i, player.getBlockZ())).getBlock();
if(newloc.getTypeId() != 0 && newloc.isLiquid())
return true;
else if (newloc.getTypeId() != 0)
return false;
}
return false;
}
public static boolean isHoveringOverWater(Location player)
{
return isHoveringOverWater(player, 25);
}
public static boolean isInstantBreak(Material m)
{