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)
|
@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,26 +543,23 @@ 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.
|
level = Math.min(20.0, level);
|
||||||
level = Math.min(20.0, level);
|
// TODO: How is the direction really calculated?
|
||||||
// TODO: How is the direction really calculated?
|
final Vector dir = attacker.getLocation(useLoc1).getDirection().multiply(0.5 * level);
|
||||||
final Vector dir = attacker.getLocation(useLoc1).getDirection().multiply(0.5 * level);
|
|
||||||
|
|
||||||
double vy = dir.getY();
|
double vy = dir.getY();
|
||||||
if (BlockProperties.isOnGround(damagedPlayer, damagedPlayer.getLocation(useLoc1), mcc.yOnGround)) {
|
if (BlockProperties.isOnGround(damagedPlayer, damagedPlayer.getLocation(useLoc1), mcc.yOnGround)) {
|
||||||
// (Re-used useLoc1 without need for cleanup.)
|
// (Re-used useLoc1 without need for cleanup.)
|
||||||
vy = 0.365;
|
vy = 0.365;
|
||||||
}
|
|
||||||
useLoc1.setWorld(null); // Cleanup.
|
|
||||||
if (damagedData.debug || mdata.debug) {
|
|
||||||
NCPAPIProvider.getNoCheatPlusAPI().getLogManager().debug(Streams.TRACE_FILE, damagedPlayer.getName() + " received knockback level: " + level);
|
|
||||||
}
|
|
||||||
MovingListener.addVelocity(damagedPlayer, mdata, mcc, dir.getX(), vy, dir.getZ());
|
|
||||||
}
|
}
|
||||||
|
useLoc1.setWorld(null); // Cleanup.
|
||||||
|
if (damagedData.debug || mdata.debug) {
|
||||||
|
NCPAPIProvider.getNoCheatPlusAPI().getLogManager().debug(Streams.TRACE_FILE, damagedPlayer.getName() + " received knockback level: " + level);
|
||||||
|
}
|
||||||
|
MovingListener.addVelocity(damagedPlayer, mdata, mcc, dir.getX(), vy, dir.getZ());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue
Block a user