added snowball knockback
This commit is contained in:
parent
7a15984f19
commit
36fc89e915
@ -1,12 +1,19 @@
|
||||
package eu.mhsl.craftattack.spawn.appliances.snowballKnockback;
|
||||
|
||||
import eu.mhsl.craftattack.spawn.appliance.Appliance;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.util.Vector;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SnowballKnockback extends Appliance {
|
||||
public void dealKnockback(LivingEntity entity, Vector velocityVector, double strength, double damage) {
|
||||
entity.damage(damage);
|
||||
entity.knockback(strength, -velocityVector.getX(), -velocityVector.getZ());
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
protected List<Listener> listeners() {
|
||||
|
@ -8,12 +8,11 @@ import org.bukkit.event.entity.ProjectileHitEvent;
|
||||
public class SnowballKnockbackListener extends ApplianceListener<SnowballKnockback> {
|
||||
@EventHandler
|
||||
public void onSnowballHit(ProjectileHitEvent event) {
|
||||
if(!event.getEntityType().equals(EntityType.SNOWBALL)) return;
|
||||
if(event.getHitEntity() == null) return;
|
||||
if(!event.getEntityType().equals(EntityType.SNOWBALL)) return;
|
||||
if(!(event.getHitEntity() instanceof LivingEntity hitEntity)) return;
|
||||
|
||||
Entity snowball = event.getEntity();
|
||||
hitEntity.damage(0.1);
|
||||
hitEntity.knockback(0.4, -snowball.getVelocity().getX(), -snowball.getVelocity().getZ());
|
||||
getAppliance().dealKnockback(hitEntity, snowball.getVelocity(), 0.4, 0.1);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user