Archiviert
13
0

Add new methods from PlayerMoveEvent to EntityMoveEvent (#5591)

Dieser Commit ist enthalten in:
TwoLeggedCat 2021-05-08 03:25:30 -05:00 committet von GitHub
Ursprung 29785297b5
Commit d7625d926d
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23

Datei anzeigen

@ -6,10 +6,10 @@ Subject: [PATCH] EntityMoveEvent
diff --git a/src/main/java/io/papermc/paper/event/entity/EntityMoveEvent.java b/src/main/java/io/papermc/paper/event/entity/EntityMoveEvent.java
new file mode 100644
index 0000000000000000000000000000000000000000..299ff57b3001b4be41cf2f0eea29ed82b8fb8ec7
index 0000000000000000000000000000000000000000..a5c017dc0392a4bbdccf33d9e963f96cbfbc0d9a
--- /dev/null
+++ b/src/main/java/io/papermc/paper/event/entity/EntityMoveEvent.java
@@ -0,0 +1,95 @@
@@ -0,0 +1,140 @@
+package io.papermc.paper.event.entity;
+
+import com.google.common.base.Preconditions;
@ -89,6 +89,51 @@ index 0000000000000000000000000000000000000000..299ff57b3001b4be41cf2f0eea29ed82
+ this.to = to;
+ }
+
+ /**
+ * Check if the entity has changed position (even within the same block) in the event
+ *
+ * @return whether the entity has changed position or not
+ */
+ public boolean hasChangedPosition() {
+ return hasExplicitlyChangedPosition() || !from.getWorld().equals(to.getWorld());
+ }
+
+ /**
+ * Check if the entity has changed position (even within the same block) in the event, disregarding a possible world change
+ *
+ * @return whether the entity has changed position or not
+ */
+ public boolean hasExplicitlyChangedPosition() {
+ return from.getX() != to.getX() || from.getY() != to.getY() || from.getZ() != to.getZ();
+ }
+
+ /**
+ * Check if the entity has moved to a new block in the event
+ *
+ * @return whether the entity has moved to a new block or not
+ */
+ public boolean hasChangedBlock() {
+ return hasExplicitlyChangedBlock() || !from.getWorld().equals(to.getWorld());
+ }
+
+ /**
+ * Check if the entity has moved to a new block in the event, disregarding a possible world change
+ *
+ * @return whether the entity has moved to a new block or not
+ */
+ public boolean hasExplicitlyChangedBlock() {
+ return from.getBlockX() != to.getBlockX() || from.getBlockY() != to.getBlockY() || from.getBlockZ() != to.getBlockZ();
+ }
+
+ /**
+ * Check if the entity has changed orientation in the event
+ *
+ * @return whether the entity has changed orientation or not
+ */
+ public boolean hasChangedOrientation() {
+ return from.getPitch() != to.getPitch() || from.getYaw() != to.getYaw();
+ }
+
+ private void validateLocation(@NotNull Location loc) {
+ Preconditions.checkArgument(loc != null, "Cannot use null location!");
+ Preconditions.checkArgument(loc.getWorld() != null, "Cannot use null location with null world!");