mirror of
https://github.com/darksaid98/AntiCheatReloaded.git
synced 2026-12-01 14:38:56 +00:00
A bit better fly protection, this allows us to relax some of the limits on walking/running etc.
This commit is contained in:
1 parent
b1d37ecdfd
commit
6188216f97
3 files changed
+59
-4
No files matched your search
@@ -22,6 +22,7 @@ public class Anticheat extends JavaPlugin {
|
||||
public BowManager bm = new BowManager(this);
|
||||
public HealthManager hm = new HealthManager();
|
||||
public LoginManager lm = new LoginManager(this);
|
||||
public FlyManager fm = new FlyManager();
|
||||
//End Managers
|
||||
|
||||
public Configuration config;
|
||||
|
||||
@@ -7,6 +7,7 @@ import net.h31ix.anticheat.checks.*;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
@@ -31,6 +32,7 @@ public class PlayerListener implements Listener {
|
||||
ItemManager im;
|
||||
HealthManager hm;
|
||||
LoginManager lm;
|
||||
FlyManager fm;
|
||||
|
||||
public PlayerListener(Anticheat plugin)
|
||||
{
|
||||
@@ -41,6 +43,7 @@ public class PlayerListener implements Listener {
|
||||
this.tracker = plugin.tracker;
|
||||
this.hm = plugin.hm;
|
||||
this.lm = plugin.lm;
|
||||
this.fm = plugin.fm;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@@ -200,7 +203,7 @@ public class PlayerListener implements Listener {
|
||||
else if(player.isSneaking())
|
||||
{
|
||||
//Make sure they are at normal sneak speeds. (not using sneak hacks)
|
||||
if(xd > 0.17D || zd > 0.17D)
|
||||
if(xd > 0.2D || zd > 0.2D)
|
||||
{
|
||||
tracker.increaseLevel(player);
|
||||
plugin.log(player.getName()+" is sneaking too fast! XSpeed="+xd+" ZSpeed="+zd);
|
||||
@@ -210,7 +213,7 @@ public class PlayerListener implements Listener {
|
||||
}
|
||||
}
|
||||
//Otherwise set a hardcoded limit to any other traveling
|
||||
else if(xd > 0.32D || zd > 0.32D)
|
||||
else if(xd > 0.4D || zd > 0.4D)
|
||||
{
|
||||
if(!player.isFlying() && !player.hasPotionEffect(PotionEffectType.SPEED))
|
||||
{
|
||||
@@ -223,7 +226,7 @@ public class PlayerListener implements Listener {
|
||||
else
|
||||
{
|
||||
//If they are sprinting or flying give slack
|
||||
if(xd > 0.62D || zd > 0.62D)
|
||||
if(xd > 0.7D || zd > 0.7D)
|
||||
{
|
||||
tracker.increaseLevel(player);
|
||||
plugin.log(player.getName()+" is sprinting too fast! XSpeed="+xd+" ZSpeed="+zd);
|
||||
@@ -277,7 +280,20 @@ public class PlayerListener implements Listener {
|
||||
//No change in Y
|
||||
else
|
||||
{
|
||||
|
||||
Block block = player.getLocation().getBlock().getRelative(BlockFace.DOWN);
|
||||
if(block.getType() == Material.AIR && block.getRelative(BlockFace.NORTH).getType() == Material.AIR && block.getRelative(BlockFace.EAST).getType() == Material.AIR && block.getRelative(BlockFace.SOUTH).getType() == Material.AIR && block.getRelative(BlockFace.WEST).getType() == Material.AIR)
|
||||
{
|
||||
if (fm.checkFly(player))
|
||||
{
|
||||
event.setTo(event.getFrom().clone());
|
||||
plugin.log(player.getName()+" tried to fly!");
|
||||
tracker.increaseLevel(player);
|
||||
}
|
||||
else
|
||||
{
|
||||
tracker.decreaseLevel(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
package net.h31ix.anticheat.manage;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class FlyManager {
|
||||
public Map<Player,Integer> y = new HashMap<Player,Integer>();
|
||||
public Map<Player,Integer> yvl = new HashMap<Player,Integer>();
|
||||
|
||||
public FlyManager()
|
||||
{
|
||||
}
|
||||
|
||||
public boolean checkFly(Player player)
|
||||
{
|
||||
//Sometimes a player's y drop is 0 when they reach the peak of their jump
|
||||
//To combat false positives, the player must have 4 y values of 0 in a row to trigger.
|
||||
if(yvl.get(player) == null)
|
||||
{
|
||||
yvl.put(player,1);
|
||||
}
|
||||
else
|
||||
{
|
||||
yvl.put(player,yvl.get(player)+1);
|
||||
}
|
||||
if(yvl.get(player) >= 4)
|
||||
{
|
||||
yvl.put(player,1);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user