mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2024-09-18 09:51:17 +02:00
Fight checks: Use data and config from arguments. Prepare new methods.
This commit is contained in:
parent
4dc6b58920
commit
a4aad90c82
@ -32,9 +32,7 @@ public class Angle extends Check {
|
|||||||
* @param worldChanged
|
* @param worldChanged
|
||||||
* @return true, if successful
|
* @return true, if successful
|
||||||
*/
|
*/
|
||||||
public boolean check(final Player player, final boolean worldChanged) {
|
public boolean check(final Player player, final boolean worldChanged, final FightData data, final FightConfig cc) {
|
||||||
final FightConfig cc = FightConfig.getConfig(player);
|
|
||||||
final FightData data = FightData.getData(player);
|
|
||||||
|
|
||||||
if (worldChanged){
|
if (worldChanged){
|
||||||
// TODO: clear some data.
|
// TODO: clear some data.
|
||||||
|
@ -38,10 +38,7 @@ public class Critical extends Check {
|
|||||||
* the player
|
* the player
|
||||||
* @return true, if successful
|
* @return true, if successful
|
||||||
*/
|
*/
|
||||||
public boolean check(final Player player, final Location loc) {
|
public boolean check(final Player player, final Location loc, final FightData data, final FightConfig cc) {
|
||||||
final FightConfig cc = FightConfig.getConfig(player);
|
|
||||||
final FightData data = FightData.getData(player);
|
|
||||||
|
|
||||||
boolean cancel = false;
|
boolean cancel = false;
|
||||||
|
|
||||||
final float mcFallDistance = player.getFallDistance();
|
final float mcFallDistance = player.getFallDistance();
|
||||||
|
@ -30,11 +30,8 @@ public class Direction extends Check {
|
|||||||
* the damaged
|
* the damaged
|
||||||
* @return true, if successful
|
* @return true, if successful
|
||||||
*/
|
*/
|
||||||
public boolean check(final Player player, final Location loc, final Entity damaged, final Location dLoc) {
|
public boolean check(final Player player, final Location loc, final Entity damaged, final Location dLoc, final FightData data, final FightConfig cc) {
|
||||||
final FightConfig cc = FightConfig.getConfig(player);
|
boolean cancel = false;
|
||||||
final FightData data = FightData.getData(player);
|
|
||||||
|
|
||||||
boolean cancel = false;
|
|
||||||
|
|
||||||
// Safeguard, if entity is complex, this check will fail due to giant and hard to define hitboxes.
|
// Safeguard, if entity is complex, this check will fail due to giant and hard to define hitboxes.
|
||||||
// if (damaged instanceof EntityComplex || damaged instanceof EntityComplexPart)
|
// if (damaged instanceof EntityComplex || damaged instanceof EntityComplexPart)
|
||||||
@ -84,4 +81,10 @@ public class Direction extends Check {
|
|||||||
|
|
||||||
return cancel;
|
return cancel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public DirectionContext getContext(final Player player, final Location loc, final Entity damaged, final Location damagedLoc, final FightData data, final FightConfig cc) {
|
||||||
|
final DirectionContext context = new DirectionContext();
|
||||||
|
// TODO: implement...
|
||||||
|
return context;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,10 @@
|
|||||||
|
package fr.neatmonster.nocheatplus.checks.fight;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Context data for the direction check, for repeated use within a loop.
|
||||||
|
* @author mc_dev
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class DirectionContext {
|
||||||
|
|
||||||
|
}
|
@ -195,15 +195,15 @@ public class FightListener extends CheckListener implements JoinLeaveListener{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!cancelled && critical.isEnabled(player) && critical.check(player, loc)) {
|
if (!cancelled && critical.isEnabled(player) && critical.check(player, loc, data, cc)) {
|
||||||
cancelled = true;
|
cancelled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!cancelled && knockback.isEnabled(player) && knockback.check(player)) {
|
if (!cancelled && knockback.isEnabled(player) && knockback.check(player, data, cc)) {
|
||||||
cancelled = true;
|
cancelled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!cancelled && noSwing.isEnabled(player) && noSwing.check(player)) {
|
if (!cancelled && noSwing.isEnabled(player) && noSwing.check(player, data, cc)) {
|
||||||
cancelled = true;
|
cancelled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -214,16 +214,33 @@ public class FightListener extends CheckListener implements JoinLeaveListener{
|
|||||||
// TODO: Order of all these checks ...
|
// TODO: Order of all these checks ...
|
||||||
// Checks that use LocationTrace.
|
// Checks that use LocationTrace.
|
||||||
|
|
||||||
// TODO: Each check a method to determine max. latency ?
|
/**
|
||||||
|
* Iterate trace for trigonometric checks.<br>
|
||||||
|
* Calculate shared data before checking.<br>
|
||||||
|
* Maintain a latency window.<br>
|
||||||
|
* Check all in one loop, with pre- and invalidation conditions.<br>
|
||||||
|
* If some checks are disabled, window estimation must still be done fro the remaining ones.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
if (!cancelled && reach.isEnabled(player) && reach.check(player, loc, damaged, damagedLoc)) {
|
// TODO: Later optimize (...)
|
||||||
|
|
||||||
|
// First loop through reach and direction, to determine a window.
|
||||||
|
final boolean reachEnabled = !cancelled && reach.isEnabled(player);
|
||||||
|
//final ReachContext reachContext = reachEnabled ? reach.getContext(player, loc, damaged, damagedLoc, data, cc) : null;
|
||||||
|
|
||||||
|
if (reachEnabled && reach.check(player, loc, damaged, damagedLoc, data, cc)) {
|
||||||
cancelled = true;
|
cancelled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!cancelled && direction.isEnabled(player) && direction.check(player, loc, damaged, damagedLoc)) {
|
final boolean directionEnabled = !cancelled && direction.isEnabled(player);
|
||||||
|
//final DirectionContext directionContext = directionEnabled ? direction.getContext(player, loc, damaged, damagedLoc, data, cc) : null;
|
||||||
|
|
||||||
|
if (directionEnabled && direction.check(player, loc, damaged, damagedLoc, data, cc)) {
|
||||||
cancelled = true;
|
cancelled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check angle with allowed window.
|
||||||
if (angle.isEnabled(player)) {
|
if (angle.isEnabled(player)) {
|
||||||
// The "fast turning" checks are checked in any case because they accumulate data.
|
// The "fast turning" checks are checked in any case because they accumulate data.
|
||||||
// Improbable yaw changing.
|
// Improbable yaw changing.
|
||||||
@ -233,7 +250,7 @@ public class FightListener extends CheckListener implements JoinLeaveListener{
|
|||||||
cancelled = true;
|
cancelled = true;
|
||||||
}
|
}
|
||||||
// Angle check.
|
// Angle check.
|
||||||
if (angle.check(player, worldChanged)) {
|
if (angle.check(player, worldChanged, data, cc)) {
|
||||||
cancelled = true;
|
cancelled = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,10 +26,7 @@ public class Knockback extends Check {
|
|||||||
* the player
|
* the player
|
||||||
* @return true, if successful
|
* @return true, if successful
|
||||||
*/
|
*/
|
||||||
public boolean check(final Player player) {
|
public boolean check(final Player player, final FightData data, final FightConfig cc) {
|
||||||
final FightConfig cc = FightConfig.getConfig(player);
|
|
||||||
final FightData data = FightData.getData(player);
|
|
||||||
|
|
||||||
boolean cancel = false;
|
boolean cancel = false;
|
||||||
|
|
||||||
final long time = System.currentTimeMillis();
|
final long time = System.currentTimeMillis();
|
||||||
|
@ -24,9 +24,7 @@ public class NoSwing extends Check {
|
|||||||
* the player
|
* the player
|
||||||
* @return true, if successful
|
* @return true, if successful
|
||||||
*/
|
*/
|
||||||
public boolean check(final Player player) {
|
public boolean check(final Player player, final FightData data, final FightConfig cc) {
|
||||||
final FightData data = FightData.getData(player);
|
|
||||||
|
|
||||||
boolean cancel = false;
|
boolean cancel = false;
|
||||||
|
|
||||||
// Did they swing his arm before?
|
// Did they swing his arm before?
|
||||||
@ -40,9 +38,10 @@ public class NoSwing extends Check {
|
|||||||
|
|
||||||
// Execute whatever actions are associated with this check and the violation level and find out if we should
|
// Execute whatever actions are associated with this check and the violation level and find out if we should
|
||||||
// cancel the event.
|
// cancel the event.
|
||||||
cancel = executeActions(player, data.noSwingVL, 1D, FightConfig.getConfig(player).noSwingActions);
|
cancel = executeActions(player, data.noSwingVL, 1D, cc.noSwingActions);
|
||||||
}
|
}
|
||||||
|
|
||||||
return cancel;
|
return cancel;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -51,10 +51,7 @@ public class Reach extends Check {
|
|||||||
* the damaged
|
* the damaged
|
||||||
* @return true, if successful
|
* @return true, if successful
|
||||||
*/
|
*/
|
||||||
public boolean check(final Player player, final Location pLoc, final Entity damaged, final Location dRef) {
|
public boolean check(final Player player, final Location pLoc, final Entity damaged, final Location dRef, final FightData data, final FightConfig cc) {
|
||||||
final FightConfig cc = FightConfig.getConfig(player);
|
|
||||||
final FightData data = FightData.getData(player);
|
|
||||||
|
|
||||||
boolean cancel = false;
|
boolean cancel = false;
|
||||||
|
|
||||||
// The maximum distance allowed to interact with an entity in survival mode.
|
// The maximum distance allowed to interact with an entity in survival mode.
|
||||||
@ -135,4 +132,10 @@ public class Reach extends Check {
|
|||||||
|
|
||||||
return cancel;
|
return cancel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ReachContext getContext(final Player player, final Location loc, final Entity damaged, final Location damagedLoc, final FightData data, final FightConfig cc) {
|
||||||
|
final ReachContext context = new ReachContext();
|
||||||
|
// TODO: Implement
|
||||||
|
return context;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,10 @@
|
|||||||
|
package fr.neatmonster.nocheatplus.checks.fight;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Context data for the reach check, for repeated use within a loop.
|
||||||
|
* @author mc_dev
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public class ReachContext {
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user