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