Fight checks: Use data and config from arguments. Prepare new methods.

This commit is contained in:
asofold 2014-03-23 18:49:30 +01:00
parent 4dc6b58920
commit a4aad90c82
9 changed files with 65 additions and 31 deletions

View File

@ -32,9 +32,7 @@ public class Angle extends Check {
* @param worldChanged
* @return true, if successful
*/
public boolean check(final Player player, final boolean worldChanged) {
final FightConfig cc = FightConfig.getConfig(player);
final FightData data = FightData.getData(player);
public boolean check(final Player player, final boolean worldChanged, final FightData data, final FightConfig cc) {
if (worldChanged){
// TODO: clear some data.

View File

@ -38,10 +38,7 @@ public class Critical extends Check {
* the player
* @return true, if successful
*/
public boolean check(final Player player, final Location loc) {
final FightConfig cc = FightConfig.getConfig(player);
final FightData data = FightData.getData(player);
public boolean check(final Player player, final Location loc, final FightData data, final FightConfig cc) {
boolean cancel = false;
final float mcFallDistance = player.getFallDistance();

View File

@ -30,11 +30,8 @@ public class Direction extends Check {
* the damaged
* @return true, if successful
*/
public boolean check(final Player player, final Location loc, final Entity damaged, final Location dLoc) {
final FightConfig cc = FightConfig.getConfig(player);
final FightData data = FightData.getData(player);
boolean cancel = false;
public boolean check(final Player player, final Location loc, final Entity damaged, final Location dLoc, final FightData data, final FightConfig cc) {
boolean cancel = false;
// Safeguard, if entity is complex, this check will fail due to giant and hard to define hitboxes.
// if (damaged instanceof EntityComplex || damaged instanceof EntityComplexPart)
@ -84,4 +81,10 @@ public class Direction extends Check {
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;
}
}

View File

@ -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 {
}

View File

@ -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;
}
if (!cancelled && knockback.isEnabled(player) && knockback.check(player)) {
if (!cancelled && knockback.isEnabled(player) && knockback.check(player, data, cc)) {
cancelled = true;
}
if (!cancelled && noSwing.isEnabled(player) && noSwing.check(player)) {
if (!cancelled && noSwing.isEnabled(player) && noSwing.check(player, data, cc)) {
cancelled = true;
}
@ -214,16 +214,33 @@ public class FightListener extends CheckListener implements JoinLeaveListener{
// TODO: Order of all these checks ...
// 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;
}
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;
}
// Check angle with allowed window.
if (angle.isEnabled(player)) {
// The "fast turning" checks are checked in any case because they accumulate data.
// Improbable yaw changing.
@ -233,7 +250,7 @@ public class FightListener extends CheckListener implements JoinLeaveListener{
cancelled = true;
}
// Angle check.
if (angle.check(player, worldChanged)) {
if (angle.check(player, worldChanged, data, cc)) {
cancelled = true;
}
}

View File

@ -26,10 +26,7 @@ public class Knockback extends Check {
* the player
* @return true, if successful
*/
public boolean check(final Player player) {
final FightConfig cc = FightConfig.getConfig(player);
final FightData data = FightData.getData(player);
public boolean check(final Player player, final FightData data, final FightConfig cc) {
boolean cancel = false;
final long time = System.currentTimeMillis();

View File

@ -24,9 +24,7 @@ public class NoSwing extends Check {
* the player
* @return true, if successful
*/
public boolean check(final Player player) {
final FightData data = FightData.getData(player);
public boolean check(final Player player, final FightData data, final FightConfig cc) {
boolean cancel = false;
// 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
// cancel the event.
cancel = executeActions(player, data.noSwingVL, 1D, FightConfig.getConfig(player).noSwingActions);
cancel = executeActions(player, data.noSwingVL, 1D, cc.noSwingActions);
}
return cancel;
}
}

View File

@ -51,10 +51,7 @@ public class Reach extends Check {
* the damaged
* @return true, if successful
*/
public boolean check(final Player player, final Location pLoc, final Entity damaged, final Location dRef) {
final FightConfig cc = FightConfig.getConfig(player);
final FightData data = FightData.getData(player);
public boolean check(final Player player, final Location pLoc, final Entity damaged, final Location dRef, final FightData data, final FightConfig cc) {
boolean cancel = false;
// The maximum distance allowed to interact with an entity in survival mode.
@ -135,4 +132,10 @@ public class Reach extends Check {
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;
}
}

View File

@ -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 {
}