3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-11-15 04:20:04 +01:00
Paper/patches/api/0113-Add-EntityKnockbackByEntityEvent-and-EntityPushedByE.patch

137 Zeilen
4.3 KiB
Diff

2021-06-11 14:02:28 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Brokkonaut <hannos17@gmx.de>
Date: Mon, 18 Jun 2018 15:40:39 +0200
2022-12-23 20:59:11 +01:00
Subject: [PATCH] Add EntityKnockbackByEntityEvent and
EntityPushedByEntityAttackEvent
2021-06-11 14:02:28 +02:00
2022-12-23 20:59:11 +01:00
Co-authored-by: aerulion <aerulion@gmail.com>
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/com/destroystokyo/paper/event/entity/EntityKnockbackByEntityEvent.java b/src/main/java/com/destroystokyo/paper/event/entity/EntityKnockbackByEntityEvent.java
new file mode 100644
2022-12-23 20:59:11 +01:00
index 0000000000000000000000000000000000000000..42fdf7a5bfab99a61ff2fbf562f2872ac360bef2
2021-06-11 14:02:28 +02:00
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/event/entity/EntityKnockbackByEntityEvent.java
2022-12-23 20:59:11 +01:00
@@ -0,0 +1,46 @@
2021-06-11 14:02:28 +02:00
+package com.destroystokyo.paper.event.entity;
+
2022-12-23 20:59:11 +01:00
+import io.papermc.paper.event.entity.EntityPushedByEntityAttackEvent;
2021-06-11 14:02:28 +02:00
+import org.bukkit.entity.Entity;
+import org.bukkit.entity.LivingEntity;
+import org.bukkit.util.Vector;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * Fired when an Entity is knocked back by the hit of another Entity. The acceleration
+ * vector can be modified. If this event is cancelled, the entity is not knocked back.
+ *
+ */
2022-12-23 20:59:11 +01:00
+public class EntityKnockbackByEntityEvent extends EntityPushedByEntityAttackEvent {
+ private final float knockbackStrength;
+
+ public EntityKnockbackByEntityEvent(@NotNull LivingEntity entity, @NotNull Entity hitBy, float knockbackStrength, @NotNull Vector acceleration) {
+ super(entity, hitBy, acceleration);
+ this.knockbackStrength = knockbackStrength;
+ }
+
+ /**
+ * @return the entity which was knocked back
+ */
+ @NotNull
+ @Override
+ public LivingEntity getEntity() {
+ return (LivingEntity) super.getEntity();
+ }
+
+ /**
+ * @return the original knockback strength.
+ */
+ public float getKnockbackStrength() {
+ return knockbackStrength;
+ }
+
+ /**
+ * @return the Entity which hit
+ */
+ @NotNull
+ public Entity getHitBy() {
+ return super.getPushedBy();
+ }
+
+}
diff --git a/src/main/java/io/papermc/paper/event/entity/EntityPushedByEntityAttackEvent.java b/src/main/java/io/papermc/paper/event/entity/EntityPushedByEntityAttackEvent.java
new file mode 100644
index 0000000000000000000000000000000000000000..c15401cd206eb9e1a7a8b7154aba0247e2da1e19
--- /dev/null
+++ b/src/main/java/io/papermc/paper/event/entity/EntityPushedByEntityAttackEvent.java
@@ -0,0 +1,70 @@
+package io.papermc.paper.event.entity;
+
+import org.bukkit.entity.Entity;
+import org.bukkit.event.Cancellable;
+import org.bukkit.event.HandlerList;
+import org.bukkit.event.entity.EntityEvent;
+import org.bukkit.util.Vector;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * Fired when an entity is pushed by another entity's attack. The acceleration vector can be
+ * modified. If this event is cancelled, the entity will not get pushed.
+ * <p>
+ * Note: Some entities might trigger this multiple times on the same entity
+ * as multiple acceleration calculations are done.
+ */
+public class EntityPushedByEntityAttackEvent extends EntityEvent implements Cancellable {
+
2021-06-11 14:02:28 +02:00
+ private static final HandlerList handlers = new HandlerList();
+
2022-12-23 20:59:11 +01:00
+ private final @NotNull Entity pushedBy;
+ private final @NotNull Vector acceleration;
2021-06-11 14:02:28 +02:00
+ private boolean cancelled = false;
+
2022-12-23 20:59:11 +01:00
+ public EntityPushedByEntityAttackEvent(@NotNull Entity entity, @NotNull Entity pushedBy, @NotNull Vector acceleration) {
2021-06-11 14:02:28 +02:00
+ super(entity);
2022-12-23 20:59:11 +01:00
+ this.pushedBy = pushedBy;
2021-06-11 14:02:28 +02:00
+ this.acceleration = acceleration;
+ }
+
+ @NotNull
+ public HandlerList getHandlers() {
+ return handlers;
+ }
+
+ @NotNull
+ public static HandlerList getHandlerList() {
+ return handlers;
+ }
+
+ @Override
+ public boolean isCancelled() {
+ return cancelled;
+ }
+
+ @Override
+ public void setCancelled(boolean cancel) {
+ cancelled = cancel;
+ }
+
+ /**
2022-12-23 20:59:11 +01:00
+ * Gets the entity which pushed the affected entity.
+ *
+ * @return the pushing entity
2021-06-11 14:02:28 +02:00
+ */
+ @NotNull
2022-12-23 20:59:11 +01:00
+ public Entity getPushedBy() {
+ return pushedBy;
2021-06-11 14:02:28 +02:00
+ }
+
+ /**
2022-12-23 20:59:11 +01:00
+ * Gets the acceleration that will be applied to the affected entity.
+ *
+ * @return the acceleration vector
2021-06-11 14:02:28 +02:00
+ */
+ @NotNull
+ public Vector getAcceleration() {
+ return acceleration;
+ }
+}