diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/fight/Angle.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/fight/Angle.java
index 21c664ad..28ab00c0 100644
--- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/fight/Angle.java
+++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/fight/Angle.java
@@ -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.
diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/fight/Critical.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/fight/Critical.java
index b8f4ada2..2e5d7ca0 100644
--- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/fight/Critical.java
+++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/fight/Critical.java
@@ -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();
diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/fight/Direction.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/fight/Direction.java
index 5c0660f3..6c7ff759 100644
--- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/fight/Direction.java
+++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/fight/Direction.java
@@ -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;
+ }
}
diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/fight/DirectionContext.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/fight/DirectionContext.java
new file mode 100644
index 00000000..cd6b5b31
--- /dev/null
+++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/fight/DirectionContext.java
@@ -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 {
+
+}
diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/fight/FightListener.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/fight/FightListener.java
index 6a2f369b..9a601143 100644
--- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/fight/FightListener.java
+++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/fight/FightListener.java
@@ -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.
+ * Calculate shared data before checking.
+ * Maintain a latency window.
+ * Check all in one loop, with pre- and invalidation conditions.
+ * 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;
}
}
diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/fight/Knockback.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/fight/Knockback.java
index 30c7aa2a..c9405b1d 100644
--- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/fight/Knockback.java
+++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/fight/Knockback.java
@@ -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();
diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/fight/NoSwing.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/fight/NoSwing.java
index ba3f4e39..c54c8777 100644
--- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/fight/NoSwing.java
+++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/fight/NoSwing.java
@@ -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;
}
+
}
diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/fight/Reach.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/fight/Reach.java
index e4d307f5..67cb6238 100644
--- a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/fight/Reach.java
+++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/fight/Reach.java
@@ -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;
+ }
}
diff --git a/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/fight/ReachContext.java b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/fight/ReachContext.java
new file mode 100644
index 00000000..ab1a1930
--- /dev/null
+++ b/NCPCore/src/main/java/fr/neatmonster/nocheatplus/checks/fight/ReachContext.java
@@ -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 {
+
+}