mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2025-01-06 15:58:12 +01:00
Adjust fight.reach to use optimal reference y.
This commit is contained in:
parent
660182f351
commit
308117054a
@ -3,6 +3,7 @@ package fr.neatmonster.nocheatplus.checks.fight;
|
|||||||
|
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.craftbukkit.entity.CraftEntity;
|
||||||
import org.bukkit.entity.EnderDragon;
|
import org.bukkit.entity.EnderDragon;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.LivingEntity;
|
import org.bukkit.entity.LivingEntity;
|
||||||
@ -74,34 +75,42 @@ public class Reach extends Check {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Reference locations to check distance for.
|
// Reference locations to check distance for.
|
||||||
// TODO: improve reference location: depending on height difference choose min(foot/hitbox, attacker)
|
final Location dRef = damaged.getLocation();
|
||||||
final Location dRef;
|
final double height;
|
||||||
if (damaged instanceof LivingEntity){
|
if (damaged instanceof LivingEntity){
|
||||||
dRef = ((LivingEntity) damaged).getEyeLocation();
|
height = Math.max(((LivingEntity) damaged).getEyeHeight(), ((CraftEntity)damaged).getHandle().height);
|
||||||
}
|
}
|
||||||
else dRef = damaged.getLocation();
|
else height = ((CraftEntity)damaged).getHandle().height;
|
||||||
final Location pRef = player.getEyeLocation();
|
final Location pRef = player.getEyeLocation();
|
||||||
|
|
||||||
|
// Refine y position.
|
||||||
|
// TODO: Make a little more accurate by counting in the actual bounding box.
|
||||||
|
final double pY = pRef.getY();
|
||||||
|
final double dY = dRef.getY();
|
||||||
|
if (pY <= dY); // Keep the foot level y.
|
||||||
|
else if (pY >= dY + height) dRef.setY(dY + height); // Highest ref y.
|
||||||
|
else dRef.setY(0); // Level with damaged.
|
||||||
|
|
||||||
final Vector pRel = dRef.toVector().subtract(pRef.toVector());
|
final Vector pRel = dRef.toVector().subtract(pRef.toVector());
|
||||||
|
|
||||||
// Distance is calculated from eye location to center of targeted. If the player is further away from his target
|
// Distance is calculated from eye location to center of targeted. If the player is further away from his target
|
||||||
// than allowed, the difference will be assigned to "distance".
|
// than allowed, the difference will be assigned to "distance".
|
||||||
final double lenpRel = pRel.length();
|
final double lenpRel = pRel.length();
|
||||||
double distance = lenpRel - distanceLimit;
|
double violation = lenpRel - distanceLimit;
|
||||||
|
|
||||||
// Handle the EnderDragon differently.
|
// Handle the EnderDragon differently.
|
||||||
if (damaged instanceof EnderDragon)
|
if (damaged instanceof EnderDragon)
|
||||||
distance -= 6.5D;
|
violation -= 6.5D;
|
||||||
|
|
||||||
if (distance > 0) {
|
if (violation > 0) {
|
||||||
// He failed, increment violation level. This is influenced by lag, so don't do it if there was lag.
|
// He failed, increment violation level. This is influenced by lag, so don't do it if there was lag.
|
||||||
if (!LagMeasureTask.skipCheck())
|
if (!LagMeasureTask.skipCheck())
|
||||||
data.reachVL += distance;
|
data.reachVL += violation;
|
||||||
|
|
||||||
// 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.reachVL, distance, cc.reachActions);
|
cancel = executeActions(player, data.reachVL, violation, cc.reachActions);
|
||||||
if (Improbable.check(player, (float) distance, System.currentTimeMillis()))
|
if (Improbable.check(player, (float) violation, System.currentTimeMillis()))
|
||||||
cancel = true;
|
cancel = true;
|
||||||
if (cancel)
|
if (cancel)
|
||||||
// If we should cancel, remember the current time too.
|
// If we should cancel, remember the current time too.
|
||||||
@ -110,7 +119,7 @@ public class Reach extends Check {
|
|||||||
else if (lenpRel - distanceLimit * data.reachMod > 0){
|
else if (lenpRel - distanceLimit * data.reachMod > 0){
|
||||||
data.reachLastViolationTime = Math.max(data.reachLastViolationTime, System.currentTimeMillis() - cc.reachPenalty / 2);
|
data.reachLastViolationTime = Math.max(data.reachLastViolationTime, System.currentTimeMillis() - cc.reachPenalty / 2);
|
||||||
cancel = true;
|
cancel = true;
|
||||||
Improbable.check(player, (float) distance / 2f, System.currentTimeMillis());
|
Improbable.check(player, (float) violation / 2f, System.currentTimeMillis());
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
// Player passed the check, reward him.
|
// Player passed the check, reward him.
|
||||||
|
Loading…
Reference in New Issue
Block a user