extras/src/main/java/pw/kaboom/extras/modules/entity/EntityKnockback.java

36 lines
1.1 KiB
Java
Raw Normal View History

2019-12-17 12:37:59 +00:00
package pw.kaboom.extras.modules.entity;
2019-07-30 17:14:24 +00:00
2020-02-26 20:20:13 +00:00
import org.bukkit.entity.Arrow;
import org.bukkit.entity.EntityType;
2019-07-30 17:14:24 +00:00
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
2020-02-26 20:20:13 +00:00
import org.bukkit.event.entity.ProjectileHitEvent;
2019-07-30 17:14:24 +00:00
import com.destroystokyo.paper.event.entity.EntityKnockbackByEntityEvent;
2019-12-21 14:12:26 +00:00
public final class EntityKnockback implements Listener {
2022-05-20 02:35:48 +00:00
@EventHandler
void onEntityKnockbackByEntity(final EntityKnockbackByEntityEvent event) {
final int knockbackLimit = 60;
2019-07-30 18:18:16 +00:00
2022-05-20 02:35:48 +00:00
if (event.getKnockbackStrength() > knockbackLimit) {
event.getAcceleration().multiply(
knockbackLimit / event.getKnockbackStrength()
);
}
}
2020-02-27 15:08:10 +00:00
2022-05-20 02:35:48 +00:00
@EventHandler
void onProjectileHit(final ProjectileHitEvent event) {
if (event.getHitEntity() != null
&& EntityType.ARROW.equals(event.getEntityType())) {
final Arrow arrow = (Arrow) event.getEntity();
final int knockbackLimit = 60;
2020-02-27 15:08:10 +00:00
2022-05-20 02:35:48 +00:00
if (arrow.getKnockbackStrength() > knockbackLimit) {
arrow.setKnockbackStrength(knockbackLimit);
}
}
}
2019-07-30 17:14:24 +00:00
}