mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2024-09-03 19:00:30 +02:00
Corrections for knockback: Ignore vehicles, method naming.
This commit is contained in:
parent
3c8b255817
commit
3739e2a3f5
|
@ -503,6 +503,7 @@ public class FightListener extends CheckListener implements JoinLeaveListener{
|
|||
|
||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
|
||||
public void onEntityDamageMonitor(final EntityDamageEvent event) {
|
||||
// TODO: Do rule out events that don't count (ndt) !
|
||||
final Entity damaged = event.getEntity();
|
||||
if (damaged instanceof Player){
|
||||
final Player damagedPlayer = (Player) damaged;
|
||||
|
@ -517,8 +518,8 @@ public class FightListener extends CheckListener implements JoinLeaveListener{
|
|||
case ENTITY_ATTACK:
|
||||
if (event instanceof EntityDamageByEntityEvent) {
|
||||
final Entity entity = ((EntityDamageByEntityEvent) event).getDamager();
|
||||
if ((entity instanceof Player) && FightConfig.getConfig(damagedPlayer).knockBackVelocityPvP) {
|
||||
checkKnockBack((Player) entity, damagedPlayer, damagedData);
|
||||
if ((entity instanceof Player) && !entity.isInsideVehicle() && FightConfig.getConfig(damagedPlayer).knockBackVelocityPvP) {
|
||||
applyKnockBack((Player) entity, damagedPlayer, damagedData);
|
||||
}
|
||||
}
|
||||
default:
|
||||
|
@ -528,12 +529,12 @@ public class FightListener extends CheckListener implements JoinLeaveListener{
|
|||
}
|
||||
|
||||
/**
|
||||
* Knockback accounting: Add velocity.
|
||||
* Knock-back accounting: Add velocity.
|
||||
* @param attacker
|
||||
* @param damagedPlayer
|
||||
* @param damagedData
|
||||
*/
|
||||
private void checkKnockBack(final Player attacker, final Player damagedPlayer, final FightData damagedData) {
|
||||
private void applyKnockBack(final Player attacker, final Player damagedPlayer, final FightData damagedData) {
|
||||
double level = 1.0; // Assume "some knock-back" always.
|
||||
if (attacker.isSprinting()) {
|
||||
level += 1.0;
|
||||
|
@ -542,7 +543,6 @@ public class FightListener extends CheckListener implements JoinLeaveListener{
|
|||
if (stack != null && stack.getType() != Material.AIR) {
|
||||
level += (double) stack.getEnchantmentLevel(Enchantment.KNOCKBACK);
|
||||
}
|
||||
if (level > 0.0) {
|
||||
final MovingData mdata = MovingData.getData(damagedPlayer);
|
||||
final MovingConfig mcc = MovingConfig.getConfig(damagedPlayer);
|
||||
// Cap the level to something reasonable. TODO: Config.
|
||||
|
@ -562,8 +562,6 @@ public class FightListener extends CheckListener implements JoinLeaveListener{
|
|||
MovingListener.addVelocity(damagedPlayer, mdata, mcc, dir.getX(), vy, dir.getZ());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* We listen to death events to prevent a very specific method of doing godmode.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue
Block a user