mirror of
https://github.com/darksaid98/AntiCheatReloaded.git
synced 2026-12-01 14:38:56 +00:00
Fixed blocks incorrectly causing an increased hack level and added spider (wall climb) protection
This commit is contained in:
1 parent
bce769b40d
commit
0c7e4140bd
4 files changed
+56
-56
No files matched your search
@@ -1,13 +1,12 @@
|
||||
/*
|
||||
* To change this template, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package net.h31ix.anticheat.checks;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import net.minecraft.server.EntityComplex;
|
||||
import net.minecraft.server.EntityComplexPart;
|
||||
import net.minecraft.server.Entity;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.entity.CraftEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
@@ -21,42 +20,39 @@ public class EyeCheck {
|
||||
this.entity = entity;
|
||||
}
|
||||
|
||||
public double getOffset()
|
||||
public boolean isLooking()
|
||||
{
|
||||
//Thanks to Evenprime (NoCheat)
|
||||
if(entity instanceof EntityComplex || entity instanceof EntityComplexPart)
|
||||
{
|
||||
return -1;
|
||||
//TODO: Fix this mess!
|
||||
/**Location startLoc = player.getEyeLocation();
|
||||
int direction = (int)((-180)+startLoc.getYaw());
|
||||
int radius = 100;
|
||||
int degrees = 30;
|
||||
List<Entity> entitys = new ArrayList<Entity>();
|
||||
int[] startPos = new int[] { (int)startLoc.getX(), (int)startLoc.getZ() };
|
||||
int[] endA = new int[] { (int)(radius * Math.cos(direction - (degrees/2))), (int)(radius * Math.sin(direction - (degrees/2))) };
|
||||
int[] endB = new int[] { (int)(radius * Math.cos(direction + (degrees/2))), (int)(radius * Math.sin(direction + (degrees/2))) };
|
||||
|
||||
Location l = entity.getBukkitEntity().getLocation();
|
||||
if (!isPointInCircle(startPos[0], startPos[1], radius, l.getBlockX(), l.getBlockZ())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final float width = entity.length > entity.width ? entity.length : entity.width;
|
||||
final double height = entity.boundingBox.e - entity.boundingBox.b;
|
||||
final double off = directionCheck(player, entity.locX, entity.locY + (height / 2D), entity.locZ, width, height, 75);
|
||||
return off;
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}**/
|
||||
return true;
|
||||
}
|
||||
|
||||
public final double directionCheck(final Player player, final double targetX, final double targetY, final double targetZ, final double targetWidth, final double targetHeight, final double precision)
|
||||
{
|
||||
//Thanks to Evenprime (NoCheat)
|
||||
final Location eyes = player.getPlayer().getEyeLocation();
|
||||
final double factor = Math.sqrt(Math.pow(eyes.getX() - targetX, 2) + Math.pow(eyes.getY() - targetY, 2) + Math.pow(eyes.getZ() - targetZ, 2));
|
||||
final Vector direction = eyes.getDirection();
|
||||
final double x = ((double) targetX) - eyes.getX();
|
||||
final double y = ((double) targetY) - eyes.getY();
|
||||
final double z = ((double) targetZ) - eyes.getZ();
|
||||
final double xPrediction = factor * direction.getX();
|
||||
final double yPrediction = factor * direction.getY();
|
||||
final double zPrediction = factor * direction.getZ();
|
||||
double off = 0.0D;
|
||||
off += Math.max(Math.abs(x - xPrediction) - (targetWidth / 2 + precision), 0.0D);
|
||||
off += Math.max(Math.abs(z - zPrediction) - (targetWidth / 2 + precision), 0.0D);
|
||||
off += Math.max(Math.abs(y - yPrediction) - (targetHeight / 2 + precision), 0.0D);
|
||||
if(off > 1) {
|
||||
off = Math.sqrt(off);
|
||||
private static int[] getVectorForPoints(int x1, int y1, int x2, int y2) {
|
||||
return new int[] { Math.abs(x2-x1), Math.abs(y2-y1) };
|
||||
}
|
||||
return off;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private static boolean isPointInCircle(int cx, int cy, int radius, int px, int py) {
|
||||
double dist = (px-cx)^2 + (py-cy)^2;
|
||||
return dist < (radius^2);
|
||||
}
|
||||
|
||||
private static double getAngleBetweenVectors(int[] vector1, int[] vector2){
|
||||
return Math.atan2(vector2[1], vector2[0]) - Math.atan2(vector1[1], vector1[0]);
|
||||
}
|
||||
}
|
||||
@@ -60,26 +60,18 @@ public class BlockListener implements Listener {
|
||||
Player player = event.getPlayer();
|
||||
if(player != null)
|
||||
{
|
||||
if(!am.swungArm(player))
|
||||
//TODO: For some reason, animations are called after block place, so add an eye check here.
|
||||
LengthCheck c = new LengthCheck(event.getBlock().getLocation(),event.getPlayer().getLocation());
|
||||
if(c.getXDifference() > 6.0D || c.getZDifference() > 6.0D || c.getYDifference() > 6.0D)
|
||||
{
|
||||
tracker.increaseLevel(player);
|
||||
plugin.log(player.getName()+" didn't swing their arm on a block place!");
|
||||
plugin.log(player.getName()+" tried to place a block too far away!");
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LengthCheck c = new LengthCheck(event.getBlock().getLocation(),event.getPlayer().getLocation());
|
||||
if(c.getXDifference() > 6.0D || c.getZDifference() > 6.0D || c.getYDifference() > 6.0D)
|
||||
{
|
||||
tracker.increaseLevel(player);
|
||||
plugin.log(player.getName()+" tried to place a block too far away!");
|
||||
event.setCancelled(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
tracker.decreaseLevel(player);
|
||||
}
|
||||
}
|
||||
tracker.decreaseLevel(player);
|
||||
}
|
||||
}
|
||||
am.reset(player);
|
||||
}
|
||||
|
||||
@@ -60,9 +60,9 @@ public class EntityListener implements Listener {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
EyeCheck ec = new EyeCheck(p,((CraftEntity)event.getEntity()).getHandle());
|
||||
double off = ec.getOffset();
|
||||
if(off > 0.1D && off != -1)
|
||||
if(ec.isLooking())
|
||||
{
|
||||
plugin.log(p.getName()+" tried to hit an entity they were not looking at!");
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,9 +6,11 @@ import net.h31ix.anticheat.PlayerTracker;
|
||||
import net.h31ix.anticheat.manage.VehicleManager;
|
||||
import net.h31ix.anticheat.checks.LengthCheck;
|
||||
import net.h31ix.anticheat.manage.ItemManager;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerAnimationEvent;
|
||||
import org.bukkit.event.player.PlayerAnimationType;
|
||||
@@ -51,7 +53,7 @@ public class PlayerListener implements Listener {
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onPlayerAnimation(PlayerAnimationEvent event)
|
||||
{
|
||||
if(event.getAnimationType() == PlayerAnimationType.ARM_SWING)
|
||||
@@ -178,7 +180,17 @@ public class PlayerListener implements Listener {
|
||||
}
|
||||
if(event.getFrom().getY() < event.getTo().getY())
|
||||
{
|
||||
if(yd > 1D)
|
||||
//TODO: This is a little hacky. Any better way to figure this out?
|
||||
if(yd <= 0.11761 && yd >= 0.11759)
|
||||
{
|
||||
if(player.getLocation().getBlock().getType() != Material.VINE && player.getLocation().getBlock().getType() != Material.LADDER)
|
||||
{
|
||||
plugin.log(player.getName()+" tried to climb a wall!");
|
||||
tracker.increaseLevel(player);
|
||||
event.setTo(event.getFrom().clone());
|
||||
}
|
||||
}
|
||||
else if(yd > 1D)
|
||||
{
|
||||
tracker.increaseLevel(player);
|
||||
plugin.log(player.getName()+" is ascending too fast! YSpeed="+yd);
|
||||
|
||||
Reference in new issue
Block a user