mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2025-01-20 06:21:23 +01:00
[Development] Direction? Done.
This commit is contained in:
parent
6a5c4923a0
commit
64743af238
@ -58,7 +58,7 @@ public class Direction extends Check {
|
||||
|
||||
boolean cancel = false;
|
||||
|
||||
if (!CheckUtils.intersects(player, location, OFFSET)) {
|
||||
if (!CheckUtils.intersects(player, location, location.add(1D, 1D, 1D), OFFSET)) {
|
||||
// Player failed the check. Let's try to guess how far he was from looking directly to the block...
|
||||
final Vector direction = player.getEyeLocation().getDirection();
|
||||
final Vector blockEyes = location.add(0.5D, 0.5D, 0.5D).subtract(player.getEyeLocation()).toVector();
|
||||
@ -73,8 +73,7 @@ public class Direction extends Check {
|
||||
|
||||
// Execute whatever actions are associated with this check and the violation level and find out if we should
|
||||
// cancel the event.
|
||||
if (!e.isCancelled() && executeActions(player, cc.directionActions, data.directionVL))
|
||||
cancel = true;
|
||||
cancel = !e.isCancelled() && executeActions(player, cc.directionActions, data.directionVL);
|
||||
} else
|
||||
// Player did likely nothing wrong, reduce violation counter to reward him.
|
||||
data.directionVL *= 0.9D;
|
||||
|
@ -58,7 +58,7 @@ public class Direction extends Check {
|
||||
|
||||
boolean cancel = false;
|
||||
|
||||
if (!CheckUtils.intersects(player, location, OFFSET)) {
|
||||
if (!CheckUtils.intersects(player, location, location.add(1D, 1D, 1D), OFFSET)) {
|
||||
// Player failed the check. Let's try to guess how far he was from looking directly to the block...
|
||||
final Vector direction = player.getEyeLocation().getDirection();
|
||||
final Vector blockEyes = location.add(0.5D, 0.5D, 0.5D).subtract(player.getEyeLocation()).toVector();
|
||||
@ -73,8 +73,7 @@ public class Direction extends Check {
|
||||
|
||||
// Execute whatever actions are associated with this check and the violation level and find out if we should
|
||||
// cancel the event.
|
||||
if (!e.isCancelled() && executeActions(player, cc.directionActions, data.directionVL))
|
||||
cancel = true;
|
||||
cancel = !e.isCancelled() && executeActions(player, cc.directionActions, data.directionVL);
|
||||
} else
|
||||
// Player did likely nothing wrong, reduce violation counter to reward him.
|
||||
data.directionVL *= 0.9D;
|
||||
|
@ -25,13 +25,29 @@ import fr.neatmonster.nocheatplus.utilities.PlayerLocation;
|
||||
*/
|
||||
public class Critical extends Check {
|
||||
|
||||
/**
|
||||
* The event triggered by this check.
|
||||
*/
|
||||
public class CriticalEvent extends CheckEvent {
|
||||
|
||||
/**
|
||||
* Instantiates a new critical event.
|
||||
*
|
||||
* @param player
|
||||
* the player
|
||||
*/
|
||||
public CriticalEvent(final Player player) {
|
||||
super(player);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks a player.
|
||||
*
|
||||
* @param player
|
||||
* the player
|
||||
* @return true, if successful
|
||||
*/
|
||||
public boolean check(final Player player) {
|
||||
final FightConfig cc = FightConfig.getConfig(player);
|
||||
final FightData data = FightData.getData(player);
|
||||
@ -73,6 +89,9 @@ public class Critical extends Check {
|
||||
return cancel;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see fr.neatmonster.nocheatplus.checks.Check#getParameter(fr.neatmonster.nocheatplus.actions.ParameterName, org.bukkit.entity.Player)
|
||||
*/
|
||||
@Override
|
||||
public String getParameter(final ParameterName wildcard, final Player player) {
|
||||
if (wildcard == ParameterName.VIOLATIONS)
|
||||
@ -81,6 +100,9 @@ public class Critical extends Check {
|
||||
return super.getParameter(wildcard, player);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see fr.neatmonster.nocheatplus.checks.Check#isEnabled(org.bukkit.entity.Player)
|
||||
*/
|
||||
@Override
|
||||
protected boolean isEnabled(final Player player) {
|
||||
return !player.hasPermission(Permissions.FIGHT_CRITICAL) && FightConfig.getConfig(player).criticalCheck;
|
||||
|
124
src/fr/neatmonster/nocheatplus/checks/fight/Direction.java
Normal file
124
src/fr/neatmonster/nocheatplus/checks/fight/Direction.java
Normal file
@ -0,0 +1,124 @@
|
||||
package fr.neatmonster.nocheatplus.checks.fight;
|
||||
|
||||
import net.minecraft.server.Entity;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import fr.neatmonster.nocheatplus.actions.ParameterName;
|
||||
import fr.neatmonster.nocheatplus.checks.Check;
|
||||
import fr.neatmonster.nocheatplus.checks.CheckEvent;
|
||||
import fr.neatmonster.nocheatplus.players.Permissions;
|
||||
import fr.neatmonster.nocheatplus.utilities.CheckUtils;
|
||||
|
||||
/*
|
||||
* M""""""'YMM oo dP oo
|
||||
* M mmmm. `M 88
|
||||
* M MMMMM M dP 88d888b. .d8888b. .d8888b. d8888P dP .d8888b. 88d888b.
|
||||
* M MMMMM M 88 88' `88 88ooood8 88' `"" 88 88 88' `88 88' `88
|
||||
* M MMMM' .M 88 88 88. ... 88. ... 88 88 88. .88 88 88
|
||||
* M .MM dP dP `88888P' `88888P' dP dP `88888P' dP dP
|
||||
* MMMMMMMMMMM
|
||||
*/
|
||||
/**
|
||||
* The Direction check will find out if a player tried to interact with something that's not in his field of view.
|
||||
*/
|
||||
public class Direction extends Check {
|
||||
|
||||
/**
|
||||
* The event triggered by this check.
|
||||
*/
|
||||
public class DirectionEvent extends CheckEvent {
|
||||
|
||||
/**
|
||||
* Instantiates a new direction event.
|
||||
*
|
||||
* @param player
|
||||
* the player
|
||||
*/
|
||||
public DirectionEvent(final Player player) {
|
||||
super(player);
|
||||
}
|
||||
}
|
||||
|
||||
private final double OFFSET = 0.5D;
|
||||
|
||||
/**
|
||||
* Checks a player.
|
||||
*
|
||||
* @param player
|
||||
* the player
|
||||
* @param damaged
|
||||
* the damaged
|
||||
* @return true, if successful
|
||||
*/
|
||||
public boolean check(final Player player, final Entity damaged) {
|
||||
final FightConfig cc = FightConfig.getConfig(player);
|
||||
final FightData data = FightData.getData(player);
|
||||
|
||||
boolean cancel = false;
|
||||
|
||||
final Location minimum = new Location(player.getWorld(), damaged.boundingBox.a, damaged.boundingBox.b,
|
||||
damaged.boundingBox.c);
|
||||
final Location maximum = new Location(player.getWorld(), damaged.boundingBox.d, damaged.boundingBox.e,
|
||||
damaged.boundingBox.f);
|
||||
if (!CheckUtils.intersects(player, minimum, maximum, OFFSET)) {
|
||||
|
||||
// Player failed the check. Let's try to guess how far he was from looking directly to the entity...
|
||||
final Vector direction = player.getEyeLocation().getDirection();
|
||||
final Vector blockEyes = minimum.add(maximum).multiply(0.5D).subtract(player.getEyeLocation()).toVector();
|
||||
final double distance = blockEyes.crossProduct(direction).length() / direction.length();
|
||||
|
||||
// Add the overall violation level of the check.
|
||||
data.directionVL += distance;
|
||||
|
||||
// Dispatch a direction event (API)
|
||||
final DirectionEvent e = new DirectionEvent(player);
|
||||
Bukkit.getPluginManager().callEvent(e);
|
||||
|
||||
// Execute whatever actions are associated with this check and the violation level and find out if we should
|
||||
// cancel the event.
|
||||
cancel = !e.isCancelled() && executeActions(player, cc.directionActions, data.directionVL);
|
||||
|
||||
if (cancel)
|
||||
// If we should cancel, remember the current time too.
|
||||
data.directionLastViolationTime = System.currentTimeMillis();
|
||||
} else
|
||||
// Reward the player by lowering his violation level.
|
||||
data.directionVL *= 0.8D;
|
||||
|
||||
// If the player is still in penalty time, cancel the event anyway.
|
||||
if (data.directionLastViolationTime + cc.directionPenalty > System.currentTimeMillis()) {
|
||||
// A safeguard to avoid people getting stuck in penalty time indefinitely in case the system time of the
|
||||
// server gets changed.
|
||||
if (data.directionLastViolationTime > System.currentTimeMillis())
|
||||
data.directionLastViolationTime = 0;
|
||||
|
||||
// He is in penalty time, therefore request cancelling of the event.
|
||||
return true;
|
||||
}
|
||||
|
||||
return cancel;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see fr.neatmonster.nocheatplus.checks.Check#getParameter(fr.neatmonster.nocheatplus.actions.ParameterName, org.bukkit.entity.Player)
|
||||
*/
|
||||
@Override
|
||||
public String getParameter(final ParameterName wildcard, final Player player) {
|
||||
if (wildcard == ParameterName.VIOLATIONS)
|
||||
return String.valueOf(Math.round(FightData.getData(player).directionVL));
|
||||
else
|
||||
return super.getParameter(wildcard, player);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see fr.neatmonster.nocheatplus.checks.Check#isEnabled(org.bukkit.entity.Player)
|
||||
*/
|
||||
@Override
|
||||
protected boolean isEnabled(final Player player) {
|
||||
return !player.hasPermission(Permissions.FIGHT_DIRECTION) && FightConfig.getConfig(player).directionCheck;
|
||||
}
|
||||
}
|
@ -60,6 +60,10 @@ public class FightConfig {
|
||||
public final double criticalVelocity;
|
||||
public final ActionList criticalActions;
|
||||
|
||||
public final boolean directionCheck;
|
||||
public final long directionPenalty;
|
||||
public final ActionList directionActions;
|
||||
|
||||
/**
|
||||
* Instantiates a new fight configuration.
|
||||
*
|
||||
@ -75,5 +79,9 @@ public class FightConfig {
|
||||
criticalFallDistance = data.getDouble(ConfPaths.FIGHT_CRITICAL_FALLDISTANCE);
|
||||
criticalVelocity = data.getDouble(ConfPaths.FIGHT_CRITICAL_VELOCITY);
|
||||
criticalActions = data.getActionList(ConfPaths.FIGHT_CRITICAL_ACTIONS, Permissions.FIGHT_CRITICAL);
|
||||
|
||||
directionCheck = data.getBoolean(ConfPaths.FIGHT_DIRECTION_CHECK);
|
||||
directionPenalty = data.getLong(ConfPaths.FIGHT_DIRECTION_PENALTY);
|
||||
directionActions = data.getActionList(ConfPaths.FIGHT_DIRECTION_ACTIONS, Permissions.FIGHT_DIRECTION);
|
||||
}
|
||||
}
|
||||
|
@ -41,7 +41,11 @@ public class FightData {
|
||||
// Violation levels.
|
||||
public double angleVL;
|
||||
public double criticalVL;
|
||||
public double directionVL;
|
||||
|
||||
// Data of the angle check.
|
||||
public TreeMap<Long, Location> angleHits = new TreeMap<Long, Location>();
|
||||
|
||||
// Data of the direction check.
|
||||
public long directionLastViolationTime;
|
||||
}
|
||||
|
@ -208,6 +208,11 @@ public abstract class ConfPaths {
|
||||
public static final String FIGHT_CRITICAL_VELOCITY = FIGHT_CRITICAL + "velocity";
|
||||
public static final String FIGHT_CRITICAL_ACTIONS = FIGHT_CRITICAL + "actions";
|
||||
|
||||
private static final String FIGHT_DIRECTION = FIGHT + "direction.";
|
||||
public static final String FIGHT_DIRECTION_CHECK = FIGHT_DIRECTION + "active";
|
||||
public static final String FIGHT_DIRECTION_PENALTY = FIGHT_DIRECTION + "penalty";
|
||||
public static final String FIGHT_DIRECTION_ACTIONS = FIGHT_DIRECTION + "actions";
|
||||
|
||||
/*
|
||||
* e e ,e,
|
||||
* d8b d8b e88 88e Y8b Y888P " 888 8e e88 888
|
||||
|
@ -186,6 +186,11 @@ public class DefaultConfig extends ConfigFile {
|
||||
set(ConfPaths.FIGHT_CRITICAL_VELOCITY, 0.1D);
|
||||
set(ConfPaths.FIGHT_CRITICAL_ACTIONS, "cancel vl>50 log:critical:0:5:cif cancel");
|
||||
|
||||
set(ConfPaths.FIGHT_DIRECTION_CHECK, true);
|
||||
set(ConfPaths.FIGHT_DIRECTION_PENALTY, 500L);
|
||||
set(ConfPaths.FIGHT_DIRECTION_ACTIONS,
|
||||
"cancel vl>5 log:fdirection:3:5:f cancel vl>20 log:fdirection:0:5:if cancel vl>50 log:fdirection:0:5:cif cancel");
|
||||
|
||||
/*
|
||||
* e e ,e,
|
||||
* d8b d8b e88 88e Y8b Y888P " 888 8e e88 888
|
||||
@ -251,6 +256,7 @@ public class DefaultConfig extends ConfigFile {
|
||||
set(ConfPaths.STRINGS + ".critical", start + "tried to do a critical hit but wasn't technically jumping" + end);
|
||||
set(ConfPaths.STRINGS + ".fastbreak", start + "tried to break too much blocks" + end);
|
||||
set(ConfPaths.STRINGS + ".fastplace", start + "tried to place too much blocks" + end);
|
||||
set(ConfPaths.STRINGS + ".fdirection", start + "tried to hit an entity out of line of sight" + end);
|
||||
set(ConfPaths.STRINGS + ".flyshort", start + "tried to move unexpectedly" + end);
|
||||
set(ConfPaths.STRINGS + ".flylong", start
|
||||
+ "tried to move from [locationfrom] to [locationto] over a distance of [distance] block(s)" + end);
|
||||
|
@ -115,6 +115,7 @@ public class Permissions {
|
||||
private static final String FIGHT = CHECKS + ".fight";
|
||||
public static final String FIGHT_ANGLE = FIGHT + ".angle";
|
||||
public static final String FIGHT_CRITICAL = FIGHT + ".critical";
|
||||
public static final String FIGHT_DIRECTION = FIGHT + ".direction";
|
||||
|
||||
/*
|
||||
* e e ,e,
|
||||
|
@ -41,19 +41,22 @@ public class CheckUtils {
|
||||
*
|
||||
* @param player
|
||||
* the player
|
||||
* @param location
|
||||
* the location
|
||||
* @param minimum
|
||||
* the minimum location
|
||||
* @param maximum
|
||||
* the maximum location
|
||||
* @param offset
|
||||
* the offset
|
||||
* @return true, if successful
|
||||
*/
|
||||
public static boolean intersects(final Player player, final Location location, final double offset) {
|
||||
final double x1 = location.getX() - offset;
|
||||
final double y1 = location.getY() - offset;
|
||||
final double z1 = location.getZ() - offset;
|
||||
final double xH = location.getX() + 1D + offset;
|
||||
final double yH = location.getY() + 1D + offset;
|
||||
final double zH = location.getZ() + 1D + offset;
|
||||
public static boolean intersects(final Player player, final Location minimum, final Location maximum,
|
||||
final double offset) {
|
||||
final double x1 = minimum.getX() - offset;
|
||||
final double y1 = minimum.getY() - offset;
|
||||
final double z1 = minimum.getZ() - offset;
|
||||
final double xH = maximum.getX() + offset;
|
||||
final double yH = maximum.getY() + offset;
|
||||
final double zH = maximum.getZ() + offset;
|
||||
final double x0 = player.getEyeLocation().getX();
|
||||
final double y0 = player.getEyeLocation().getY();
|
||||
final double z0 = player.getEyeLocation().getZ();
|
||||
|
Loading…
Reference in New Issue
Block a user