From d6d2d75fe6f8a248a7811b8c9762d2605b7d673b Mon Sep 17 00:00:00 2001 From: Shane Freeder <theboyetronic@gmail.com> Date: Sat, 9 Jun 2018 14:08:39 +0200 Subject: [PATCH] Add EntityTeleportEndGatewayEvent --- .../minecraft/world/entity/Entity.java.patch | 106 ++++++++++-------- 1 file changed, 59 insertions(+), 47 deletions(-) diff --git a/paper-server/patches/sources/net/minecraft/world/entity/Entity.java.patch b/paper-server/patches/sources/net/minecraft/world/entity/Entity.java.patch index 21667e6444..221d69af93 100644 --- a/paper-server/patches/sources/net/minecraft/world/entity/Entity.java.patch +++ b/paper-server/patches/sources/net/minecraft/world/entity/Entity.java.patch @@ -200,12 +200,12 @@ + private org.bukkit.util.Vector origin; + @javax.annotation.Nullable + private UUID originWorld; - ++ + public void setOrigin(@javax.annotation.Nonnull Location location) { + this.origin = location.toVector(); + this.originWorld = location.getWorld().getUID(); + } -+ + + @javax.annotation.Nullable + public org.bukkit.util.Vector getOriginVector() { + return this.origin != null ? this.origin.clone() : null; @@ -289,7 +289,7 @@ public SynchedEntityData getEntityData() { return this.entityData; -+ } + } + + // CraftBukkit start + public void refreshEntityData(ServerPlayer to) { @@ -298,7 +298,7 @@ + if (list != null) { + to.connection.send(new ClientboundSetEntityDataPacket(this.getId(), list)); + } - } ++ } + // CraftBukkit end public boolean equals(Object object) { @@ -470,15 +470,15 @@ } } -@@ -587,7 +871,23 @@ +@@ -587,9 +871,25 @@ } public final void igniteForSeconds(float seconds) { - this.igniteForTicks(Mth.floor(seconds * 20.0F)); + // CraftBukkit start + this.igniteForSeconds(seconds, true); -+ } -+ + } + + public final void igniteForSeconds(float f, boolean callEvent) { + if (callEvent) { + EntityCombustEvent event = new EntityCombustEvent(this.getBukkitEntity(), f); @@ -492,9 +492,11 @@ + } + // CraftBukkit end + this.igniteForTicks(Mth.floor(f * 20.0F)); - } - ++ } ++ public void igniteForTicks(int ticks) { + if (this.remainingFireTicks < ticks) { + this.setRemainingFireTicks(ticks); @@ -610,7 +910,7 @@ } @@ -533,10 +535,12 @@ if (!this.level().isClientSide() || this.isControlledByLocalInstance()) { Entity.MovementEmission entity_movementemission = this.getMovementEmission(); -@@ -1133,6 +1455,20 @@ - return SoundEvents.GENERIC_SPLASH; - } +@@ -1131,7 +1453,21 @@ + protected SoundEvent getSwimHighSpeedSplashSound() { + return SoundEvents.GENERIC_SPLASH; ++ } ++ + // CraftBukkit start - Add delegate methods + public SoundEvent getSwimSound0() { + return this.getSwimSound(); @@ -544,16 +548,15 @@ + + public SoundEvent getSwimSplashSound0() { + return this.getSwimSplashSound(); -+ } + } + + public SoundEvent getSwimHighSpeedSplashSound0() { + return this.getSwimHighSpeedSplashSound(); + } + // CraftBukkit end -+ + public void recordMovementThroughBlocks(Vec3 oldPos, Vec3 newPos) { this.movementThisTick.add(new Entity.Movement(oldPos, newPos)); - } @@ -1609,6 +1945,7 @@ this.yo = y; this.zo = d4; @@ -772,11 +775,10 @@ } catch (Throwable throwable) { CrashReport crashreport = CrashReport.forThrowable(throwable, "Saving entity NBT"); CrashReportCategory crashreportsystemdetails = crashreport.addCategory("Entity being saved"); -@@ -2079,7 +2490,67 @@ - } +@@ -2080,6 +2491,66 @@ } else { throw new IllegalStateException("Entity has invalid position"); -+ } + } + + // CraftBukkit start + // Spigot start @@ -832,7 +834,7 @@ + } + this.originWorld = originWorld; + origin = new org.bukkit.util.Vector(originTag.getDouble(0), originTag.getDouble(1), originTag.getDouble(2)); - } ++ } + + spawnedViaMobSpawner = nbt.getBoolean("Paper.FromMobSpawner"); // Restore entity's from mob spawner status + // Paper end @@ -1165,15 +1167,23 @@ return true; } -@@ -2852,6 +3457,18 @@ +@@ -2852,6 +3457,26 @@ if (world instanceof ServerLevel worldserver) { if (!this.isRemoved()) { + // CraftBukkit start + PositionMoveRotation absolutePosition = PositionMoveRotation.calculateAbsolute(PositionMoveRotation.of(this), PositionMoveRotation.of(teleportTarget), teleportTarget.relatives()); + Location to = CraftLocation.toBukkit(absolutePosition.position(), teleportTarget.newLevel().getWorld(), absolutePosition.yRot(), absolutePosition.xRot()); -+ EntityTeleportEvent teleEvent = CraftEventFactory.callEntityTeleportEvent(this, to); -+ if (teleEvent.isCancelled()) { ++ // Paper start - gateway-specific teleport event ++ final EntityTeleportEvent teleEvent; ++ if (this.portalProcess != null && this.portalProcess.isSamePortal(((net.minecraft.world.level.block.EndGatewayBlock) net.minecraft.world.level.block.Blocks.END_GATEWAY)) && this.level.getBlockEntity(this.portalProcess.getEntryPosition()) instanceof net.minecraft.world.level.block.entity.TheEndGatewayBlockEntity theEndGatewayBlockEntity) { ++ teleEvent = new com.destroystokyo.paper.event.entity.EntityTeleportEndGatewayEvent(this.getBukkitEntity(), this.getBukkitEntity().getLocation(), to, new org.bukkit.craftbukkit.block.CraftEndGateway(to.getWorld(), theEndGatewayBlockEntity)); ++ teleEvent.callEvent(); ++ } else { ++ teleEvent = CraftEventFactory.callEntityTeleportEvent(this, to); ++ } ++ // Paper end - gateway-specific teleport event ++ if (teleEvent.isCancelled() || teleEvent.getTo() == null) { + return null; + } + if (!to.equals(teleEvent.getTo())) { @@ -1184,7 +1194,7 @@ ServerLevel worldserver1 = teleportTarget.newLevel(); boolean flag = worldserver1.dimension() != worldserver.dimension(); -@@ -2920,8 +3537,12 @@ +@@ -2920,8 +3545,12 @@ } else { entity.restoreFrom(this); this.removeAfterChangingDimensions(); @@ -1198,7 +1208,7 @@ Iterator iterator1 = list1.iterator(); while (iterator1.hasNext()) { -@@ -2947,7 +3568,7 @@ +@@ -2947,7 +3576,7 @@ } private void sendTeleportTransitionToRidingPlayers(TeleportTransition teleportTarget) { @@ -1207,7 +1217,7 @@ Iterator iterator = this.getIndirectPassengers().iterator(); while (iterator.hasNext()) { -@@ -2995,8 +3616,9 @@ +@@ -2995,8 +3624,9 @@ } protected void removeAfterChangingDimensions() { @@ -1218,10 +1228,12 @@ leashable.removeLeash(); } -@@ -3006,6 +3628,20 @@ - return PortalShape.getRelativePosition(portalRect, portalAxis, this.position(), this.getDimensions(this.getPose())); - } +@@ -3004,7 +3634,21 @@ + public Vec3 getRelativePortalPosition(Direction.Axis portalAxis, BlockUtil.FoundRectangle portalRect) { + return PortalShape.getRelativePosition(portalRect, portalAxis, this.position(), this.getDimensions(this.getPose())); ++ } ++ + // CraftBukkit start + public CraftPortalEvent callPortalEvent(Entity entity, Location exit, PlayerTeleportEvent.TeleportCause cause, int searchRadius, int creationRadius) { + org.bukkit.entity.Entity bukkitEntity = entity.getBukkitEntity(); @@ -1233,13 +1245,12 @@ + return null; + } + return new CraftPortalEvent(event); -+ } + } + // CraftBukkit end -+ + public boolean canUsePortal(boolean allowVehicles) { return (allowVehicles || !this.isPassenger()) && this.isAlive(); - } -@@ -3134,9 +3770,15 @@ +@@ -3134,9 +3778,15 @@ return (Boolean) this.entityData.get(Entity.DATA_CUSTOM_NAME_VISIBLE); } @@ -1258,7 +1269,7 @@ return entity != null; } -@@ -3187,7 +3829,7 @@ +@@ -3187,7 +3837,7 @@ /** @deprecated */ @Deprecated protected void fixupDimensions() { @@ -1267,7 +1278,7 @@ EntityDimensions entitysize = this.getDimensions(entitypose); this.dimensions = entitysize; -@@ -3196,7 +3838,7 @@ +@@ -3196,7 +3846,7 @@ public void refreshDimensions() { EntityDimensions entitysize = this.dimensions; @@ -1276,7 +1287,7 @@ EntityDimensions entitysize1 = this.getDimensions(entitypose); this.dimensions = entitysize1; -@@ -3258,10 +3900,29 @@ +@@ -3258,10 +3908,29 @@ } public final void setBoundingBox(AABB boundingBox) { @@ -1308,7 +1319,7 @@ return this.getDimensions(pose).eyeHeight(); } -@@ -3335,7 +3996,7 @@ +@@ -3335,7 +4004,7 @@ } @Nullable @@ -1317,7 +1328,7 @@ return null; } -@@ -3435,7 +4096,7 @@ +@@ -3435,7 +4104,7 @@ } public boolean isControlledByLocalInstance() { @@ -1326,7 +1337,7 @@ if (entityliving instanceof Player entityhuman) { return entityhuman.isLocalPlayer(); -@@ -3445,7 +4106,7 @@ +@@ -3445,7 +4114,7 @@ } public boolean isControlledByClient() { @@ -1335,7 +1346,7 @@ return entityliving != null && entityliving.isControlledByClient(); } -@@ -3463,7 +4124,7 @@ +@@ -3463,7 +4132,7 @@ return new Vec3((double) f1 * d2 / (double) f3, 0.0D, (double) f2 * d2 / (double) f3); } @@ -1344,10 +1355,11 @@ return new Vec3(this.getX(), this.getBoundingBox().maxY, this.getZ()); } -@@ -3489,8 +4150,37 @@ +@@ -3488,9 +4157,38 @@ + public int getFireImmuneTicks() { return 1; } - ++ + // CraftBukkit start + private final CommandSource commandSource = new CommandSource() { + @@ -1376,14 +1388,14 @@ + } + }; + // CraftBukkit end -+ + public CommandSourceStack createCommandSourceStackForNameResolution(ServerLevel world) { - return new CommandSourceStack(CommandSource.NULL, this.position(), this.getRotationVector(), world, 0, this.getName().getString(), this.getDisplayName(), world.getServer(), this); + return new CommandSourceStack(this.commandSource, this.position(), this.getRotationVector(), world, 0, this.getName().getString(), this.getDisplayName(), world.getServer(), this); // CraftBukkit } public void lookAt(EntityAnchorArgument.Anchor anchorPoint, Vec3 target) { -@@ -3550,7 +4240,12 @@ +@@ -3550,7 +4248,12 @@ vec3d = vec3d.add(vec3d1); ++k1; @@ -1396,7 +1408,7 @@ } } } -@@ -3613,7 +4308,7 @@ +@@ -3613,7 +4316,7 @@ return new ClientboundAddEntityPacket(this, entityTrackerEntry); } @@ -1405,7 +1417,7 @@ return this.type.getDimensions(); } -@@ -3818,8 +4513,16 @@ +@@ -3818,8 +4521,16 @@ @Override public final void setRemoved(Entity.RemovalReason reason) { @@ -1423,7 +1435,7 @@ } if (this.removalReason.shouldDestroy()) { -@@ -3827,8 +4530,8 @@ +@@ -3827,8 +4538,8 @@ } this.getPassengers().forEach(Entity::stopRiding); @@ -1434,7 +1446,7 @@ } public void unsetRemoved() { -@@ -3887,7 +4590,7 @@ +@@ -3887,7 +4598,7 @@ } public Vec3 getKnownMovement() {