Compare commits

..

1 Commits

Author SHA1 Message Date
MrHua269
23fc8891ed Added missing NPE checks and make async teleport event position mutable 2025-01-31 22:26:43 +08:00
2 changed files with 43 additions and 13 deletions

View File

@@ -6,10 +6,10 @@ Subject: [PATCH] Add missing teleportation apis for folia
diff --git a/src/main/java/me/earthme/luminol/api/entity/EntityTeleportAsyncEvent.java b/src/main/java/me/earthme/luminol/api/entity/EntityTeleportAsyncEvent.java
new file mode 100644
index 0000000000000000000000000000000000000000..04e1d7b39e1c140d6c9910c371d2fc65468dfc38
index 0000000000000000000000000000000000000000..4635a56c60c836675150faca51755dbe09543840
--- /dev/null
+++ b/src/main/java/me/earthme/luminol/api/entity/EntityTeleportAsyncEvent.java
@@ -0,0 +1,80 @@
@@ -0,0 +1,90 @@
+package me.earthme.luminol.api.entity;
+
+import org.apache.commons.lang3.Validate;
@@ -34,7 +34,7 @@ index 0000000000000000000000000000000000000000..04e1d7b39e1c140d6c9910c371d2fc65
+
+ private final Entity entity;
+ private final PlayerTeleportEvent.TeleportCause teleportCause;
+ private final Location destination;
+ private Location destination;
+
+ public EntityTeleportAsyncEvent(Entity entity, PlayerTeleportEvent.TeleportCause teleportCause, Location destination) {
+ Validate.notNull(entity, "entity cannot be a null value!");
@@ -70,6 +70,16 @@ index 0000000000000000000000000000000000000000..04e1d7b39e1c140d6c9910c371d2fc65
+ return this.destination;
+ }
+
+ /**
+ * Set the destination of the teleport
+ * @param destination the destination
+ */
+ public void setDestination(Location destination) {
+ Validate.notNull(destination, "destination cannot be a null value!");
+
+ this.destination = destination;
+ }
+
+ @Override
+ public @NotNull HandlerList getHandlers() {
+ return HANDLERS;

View File

@@ -19,26 +19,46 @@ index 9fd3fe181df2ce6dbe695f6463d3940ac4c01167..822d401150d3764004b2570da828b4f6
);
});
diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java
index 406c382ae2fdaa7d8996d250487bbdfb7e4bb7f9..c742695ea24588826f50740ad442f3234953ba81 100644
index 406c382ae2fdaa7d8996d250487bbdfb7e4bb7f9..e41aef2b9e7204b35202d66eb17985e3731d9611 100644
--- a/net/minecraft/world/entity/Entity.java
+++ b/net/minecraft/world/entity/Entity.java
@@ -4164,6 +4164,15 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
@@ -4164,6 +4164,35 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
}
// TODO any events that can modify go HERE
+ // Luminol start - Add missing teleportation apis
+ if (!new me.earthme.luminol.api.entity.EntityTeleportAsyncEvent(
+ org.bukkit.Location destinationLoc;
+
+ if (pitch == null) {
+ if (yaw == null) {
+ destinationLoc = io.papermc.paper.util.MCUtil.toLocation(destination, pos, Float.NaN, Float.NaN);
+ } else {
+ destinationLoc = io.papermc.paper.util.MCUtil.toLocation(destination, pos, yaw, Float.NaN);
+ }
+ }else {
+ if (yaw == null) {
+ destinationLoc = io.papermc.paper.util.MCUtil.toLocation(destination, pos, Float.NaN, pitch);
+ }else {
+ destinationLoc = io.papermc.paper.util.MCUtil.toLocation(destination, pos, yaw, pitch);
+ }
+ }
+
+ final me.earthme.luminol.api.entity.EntityTeleportAsyncEvent wrapped = new me.earthme.luminol.api.entity.EntityTeleportAsyncEvent(
+ this.getBukkitEntity(),
+ cause,
+ io.papermc.paper.util.MCUtil.toLocation(destination, pos, yaw ,pitch)
+ ).callEvent()) {
+ destinationLoc
+ );
+ if (!wrapped.callEvent()) {
+ return false;
+ }
+
+ destination = ((org.bukkit.craftbukkit.CraftWorld) wrapped.getDestination().getWorld()).getHandle();
+ pos = io.papermc.paper.util.MCUtil.toVec3(wrapped.getDestination());
+ // Luminol end
// check for same region
if (destination == this.level()) {
@@ -4280,7 +4289,20 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
@@ -4280,7 +4309,20 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
// we just select the spawn position
case END: {
if (destination.getTypeKey() == net.minecraft.world.level.dimension.LevelStem.END) {
@@ -60,7 +80,7 @@ index 406c382ae2fdaa7d8996d250487bbdfb7e4bb7f9..c742695ea24588826f50740ad442f323
// need to load chunks so we can create the platform
destination.moonrise$loadChunksAsync(
targetPos, 16, // load 16 blocks to be safe from block physics
@@ -4305,7 +4327,20 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
@@ -4305,7 +4347,20 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
}
);
} else {
@@ -82,7 +102,7 @@ index 406c382ae2fdaa7d8996d250487bbdfb7e4bb7f9..c742695ea24588826f50740ad442f323
// need to load chunk for heightmap
destination.moonrise$loadChunksAsync(
spawnPos, 0,
@@ -4355,8 +4390,20 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
@@ -4355,8 +4410,20 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
WorldBorder destinationBorder = destination.getWorldBorder();
double dimensionScale = net.minecraft.world.level.dimension.DimensionType.getTeleportationScale(origin.dimensionType(), destination.dimensionType());
@@ -104,7 +124,7 @@ index 406c382ae2fdaa7d8996d250487bbdfb7e4bb7f9..c742695ea24588826f50740ad442f323
ca.spottedleaf.concurrentutil.completable.CallbackCompletable<BlockUtil.FoundRectangle> portalFound
= new ca.spottedleaf.concurrentutil.completable.CallbackCompletable<>();
@@ -4493,9 +4540,18 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
@@ -4493,9 +4560,18 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
if (!this.canPortalAsync(destination, takePassengers)) {
return false;
}
@@ -124,7 +144,7 @@ index 406c382ae2fdaa7d8996d250487bbdfb7e4bb7f9..c742695ea24588826f50740ad442f323
// Kaiiju end
Vec3 initialPosition = this.position();
@@ -4569,6 +4625,9 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
@@ -4569,6 +4645,9 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
tpComplete.accept(teleported);
}
// Kaiiju end