Paper/patches/server/0781-Improve-PortalEvents.patch

119 lines
9.5 KiB
Diff
Raw Normal View History

2022-12-17 18:36:02 +01:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jake Potrebic <jake.m.potrebic@gmail.com>
Date: Thu, 15 Dec 2022 10:33:39 -0800
Subject: [PATCH] Improve PortalEvents
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
index 96dff63230e8cda1f5e548d914c119bd64b5ac33..7270b6fa96bae937663c0fea77887e21fbd0eb57 100644
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
@@ -1340,7 +1340,7 @@ public class ServerPlayer extends net.minecraft.world.entity.player.Player {
}
// CraftBukkit start
Location enter = this.getBukkitEntity().getLocation();
- Location exit = (worldserver == null) ? null : CraftLocation.toBukkit(teleportTarget.pos(), worldserver.getWorld(), teleportTarget.yRot(), teleportTarget.xRot());
+ Location exit =/* (worldserver == null) ? null : // Paper - always non-null */CraftLocation.toBukkit(teleportTarget.pos(), worldserver.getWorld(), teleportTarget.yRot(), teleportTarget.xRot());
PlayerTeleportEvent tpEvent = new PlayerTeleportEvent(this.getBukkitEntity(), enter, exit, teleportTarget.cause());
Bukkit.getServer().getPluginManager().callEvent(tpEvent);
if (tpEvent.isCancelled() || tpEvent.getTo() == null) {
2022-12-17 18:36:02 +01:00
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index d5df4ddb33600479e6edb93a18db9400ffc6c699..9958be86d769b9fd17b6d24d0c4f1e96b65dfb08 100644
2022-12-17 18:36:02 +01:00
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -3529,7 +3529,15 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
2024-06-14 05:41:44 +02:00
org.bukkit.entity.Entity bukkitEntity = entity.getBukkitEntity();
2022-12-17 18:36:02 +01:00
Location enter = bukkitEntity.getLocation();
Updated Upstream (Bukkit/CraftBukkit/Spigot) (#11102) Upstream has released updates that appear to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Bukkit Changes: 3a3bea52 SPIGOT-7829: Increase maximum outgoing plugin message size to match Vanilla intention 5cd1c8cb SPIGOT-7831: Add CreatureSpawnEvent.SpawnReason#POTION_EFFECT a8e278f0 SPIGOT-7827: Sync EntityPortalEvent with PlayerPortalEvent since non-players can now create portals 53729d12 Remove spurious ApiStatus.Internal annotation b9f57486 SPIGOT-7799, PR-1039: Expose explosion world interaction in EntityExplodeEvent and BlockExplodeEvent 7983b966 PR-1029: Trial changing a small number of inner enums to classes/interfaces to better support custom values CraftBukkit Changes: 403accd56 SPIGOT-7831: Add CreatureSpawnEvent.SpawnReason#POTION_EFFECT 812761660 Increase outdated build delay bed1e3ff6 SPIGOT-7827: Sync EntityPortalEvent with PlayerPortalEvent since non-players can now create portals 2444c8b23 SPIGOT-7823: Suspicious sand and gravel material are not marked as having gravity correctly aceddcd0b SPIGOT-7820: Enum changes - duplicate method name a0d2d6a84 SPIGOT-7813: Material#isInteractable() always returns false 8fd64b091 SPIGOT-7806: Handle both loot and inventory item drop behaviour in PlayerDeathEvent a4ee40b74 SPIGOT-7799, PR-1436: Expose explosion world interaction in EntityExplodeEvent and BlockExplodeEvent 082aa51c5 PR-1424: Trial changing a small number of inner enums to classes/interfaces to better support custom values 66e78a96b SPIGOT-7815: Consider EntityDamageEvent status for Wolf armor damage Spigot Changes: 5bbef5ad SPIGOT-7834: Modify max value for generic.max_absorption
2024-07-18 10:13:20 +02:00
- EntityPortalEvent event = new EntityPortalEvent(bukkitEntity, enter, exit, searchRadius, true, creationRadius);
2022-12-17 18:36:02 +01:00
+ // Paper start
+ final org.bukkit.PortalType portalType = switch (cause) {
+ case END_PORTAL -> org.bukkit.PortalType.ENDER;
+ case NETHER_PORTAL -> org.bukkit.PortalType.NETHER;
+ case END_GATEWAY -> org.bukkit.PortalType.END_GATEWAY; // not actually used yet
2022-12-17 18:36:02 +01:00
+ default -> org.bukkit.PortalType.CUSTOM;
+ };
Updated Upstream (Bukkit/CraftBukkit/Spigot) (#11102) Upstream has released updates that appear to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Bukkit Changes: 3a3bea52 SPIGOT-7829: Increase maximum outgoing plugin message size to match Vanilla intention 5cd1c8cb SPIGOT-7831: Add CreatureSpawnEvent.SpawnReason#POTION_EFFECT a8e278f0 SPIGOT-7827: Sync EntityPortalEvent with PlayerPortalEvent since non-players can now create portals 53729d12 Remove spurious ApiStatus.Internal annotation b9f57486 SPIGOT-7799, PR-1039: Expose explosion world interaction in EntityExplodeEvent and BlockExplodeEvent 7983b966 PR-1029: Trial changing a small number of inner enums to classes/interfaces to better support custom values CraftBukkit Changes: 403accd56 SPIGOT-7831: Add CreatureSpawnEvent.SpawnReason#POTION_EFFECT 812761660 Increase outdated build delay bed1e3ff6 SPIGOT-7827: Sync EntityPortalEvent with PlayerPortalEvent since non-players can now create portals 2444c8b23 SPIGOT-7823: Suspicious sand and gravel material are not marked as having gravity correctly aceddcd0b SPIGOT-7820: Enum changes - duplicate method name a0d2d6a84 SPIGOT-7813: Material#isInteractable() always returns false 8fd64b091 SPIGOT-7806: Handle both loot and inventory item drop behaviour in PlayerDeathEvent a4ee40b74 SPIGOT-7799, PR-1436: Expose explosion world interaction in EntityExplodeEvent and BlockExplodeEvent 082aa51c5 PR-1424: Trial changing a small number of inner enums to classes/interfaces to better support custom values 66e78a96b SPIGOT-7815: Consider EntityDamageEvent status for Wolf armor damage Spigot Changes: 5bbef5ad SPIGOT-7834: Modify max value for generic.max_absorption
2024-07-18 10:13:20 +02:00
+ EntityPortalEvent event = new EntityPortalEvent(bukkitEntity, enter, exit, searchRadius, true, creationRadius, portalType);
2022-12-17 18:36:02 +01:00
+ // Paper end
event.getEntity().getServer().getPluginManager().callEvent(event);
if (event.isCancelled() || event.getTo() == null || event.getTo().getWorld() == null || !entity.isAlive()) {
return null;
diff --git a/src/main/java/net/minecraft/world/level/block/EndGatewayBlock.java b/src/main/java/net/minecraft/world/level/block/EndGatewayBlock.java
index 11486419dd98a013c7387d3d73f322a95a18c574..3f5bb5c9ceb5b31fcc9ef0a7a6157e1e1cb2a09f 100644
--- a/src/main/java/net/minecraft/world/level/block/EndGatewayBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/EndGatewayBlock.java
@@ -92,6 +92,10 @@ public class EndGatewayBlock extends BaseEntityBlock implements Portal {
protected void entityInside(BlockState state, Level world, BlockPos pos, Entity entity) {
if (!new io.papermc.paper.event.entity.EntityInsideBlockEvent(entity.getBukkitEntity(), org.bukkit.craftbukkit.block.CraftBlock.at(world, pos)).callEvent()) { return; } // Paper - Add EntityInsideBlockEvent
if (entity.canUsePortal(false)) {
+ // Paper start - call EntityPortalEnterEvent
+ org.bukkit.event.entity.EntityPortalEnterEvent event = new org.bukkit.event.entity.EntityPortalEnterEvent(entity.getBukkitEntity(), new org.bukkit.Location(world.getWorld(), pos.getX(), pos.getY(), pos.getZ()), org.bukkit.PortalType.END_GATEWAY); // Paper - add portal type
+ if (!event.callEvent()) return;
+ // Paper end - call EntityPortalEnterEvent
BlockEntity tileentity = world.getBlockEntity(pos);
if (!world.isClientSide && tileentity instanceof TheEndGatewayBlockEntity) {
diff --git a/src/main/java/net/minecraft/world/level/block/EndPortalBlock.java b/src/main/java/net/minecraft/world/level/block/EndPortalBlock.java
index 28fba1448309805fc3d687de6bc8454d2c85fcd3..a35a426cc7778a51523f26057b5d61b8a3e23d5d 100644
--- a/src/main/java/net/minecraft/world/level/block/EndPortalBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/EndPortalBlock.java
@@ -66,8 +66,9 @@ public class EndPortalBlock extends BaseEntityBlock implements Portal {
if (!new io.papermc.paper.event.entity.EntityInsideBlockEvent(entity.getBukkitEntity(), org.bukkit.craftbukkit.block.CraftBlock.at(world, pos)).callEvent()) { return; } // Paper - Add EntityInsideBlockEvent
if (entity.canUsePortal(false) && Shapes.joinIsNotEmpty(Shapes.create(entity.getBoundingBox().move((double) (-pos.getX()), (double) (-pos.getY()), (double) (-pos.getZ()))), state.getShape(world, pos), BooleanOp.AND)) {
// CraftBukkit start - Entity in portal
- EntityPortalEnterEvent event = new EntityPortalEnterEvent(entity.getBukkitEntity(), new org.bukkit.Location(world.getWorld(), pos.getX(), pos.getY(), pos.getZ()));
+ EntityPortalEnterEvent event = new EntityPortalEnterEvent(entity.getBukkitEntity(), new org.bukkit.Location(world.getWorld(), pos.getX(), pos.getY(), pos.getZ()), org.bukkit.PortalType.ENDER); // Paper - add portal type
world.getCraftServer().getPluginManager().callEvent(event);
+ if (event.isCancelled()) return; // Paper - make cancellable
// CraftBukkit end
if (!world.isClientSide && world.dimension() == Level.END && entity instanceof ServerPlayer) {
ServerPlayer entityplayer = (ServerPlayer) entity;
@@ -90,7 +91,7 @@ public class EndPortalBlock extends BaseEntityBlock implements Portal {
ServerLevel worldserver1 = world.getServer().getLevel(resourcekey);
if (worldserver1 == null) {
- return new DimensionTransition(PlayerTeleportEvent.TeleportCause.END_PORTAL); // CraftBukkit- always fire event in case plugins wish to change it
+ return null; // Paper - keep previous behavior of not firing PlayerTeleportEvent if the target world doesn't exist
} else {
boolean flag = resourcekey == Level.END;
BlockPos blockposition1 = flag ? ServerLevel.END_SPAWN_POINT : worldserver1.getSharedSpawnPos();
diff --git a/src/main/java/net/minecraft/world/level/block/NetherPortalBlock.java b/src/main/java/net/minecraft/world/level/block/NetherPortalBlock.java
2024-08-31 20:29:50 +02:00
index 417a9ab28d247d5fbb3f1097fdeccab7ad2a793b..0fdbcab175b51a8b77646e0e4a267d987b133a35 100644
--- a/src/main/java/net/minecraft/world/level/block/NetherPortalBlock.java
+++ b/src/main/java/net/minecraft/world/level/block/NetherPortalBlock.java
@@ -110,8 +110,9 @@ public class NetherPortalBlock extends Block implements Portal {
if (!new io.papermc.paper.event.entity.EntityInsideBlockEvent(entity.getBukkitEntity(), org.bukkit.craftbukkit.block.CraftBlock.at(world, pos)).callEvent()) { return; } // Paper - Add EntityInsideBlockEvent
if (entity.canUsePortal(false)) {
// CraftBukkit start - Entity in portal
- EntityPortalEnterEvent event = new EntityPortalEnterEvent(entity.getBukkitEntity(), new org.bukkit.Location(world.getWorld(), pos.getX(), pos.getY(), pos.getZ()));
+ EntityPortalEnterEvent event = new EntityPortalEnterEvent(entity.getBukkitEntity(), new org.bukkit.Location(world.getWorld(), pos.getX(), pos.getY(), pos.getZ()), org.bukkit.PortalType.NETHER); // Paper - add portal type
world.getCraftServer().getPluginManager().callEvent(event);
+ if (event.isCancelled()) return; // Paper - make cancellable
// CraftBukkit end
entity.setAsInsidePortal(this, pos);
}
@@ -143,7 +144,7 @@ public class NetherPortalBlock extends Block implements Portal {
// Paper end - Add EntityPortalReadyEvent
if (worldserver1 == null) {
- return new DimensionTransition(PlayerTeleportEvent.TeleportCause.NETHER_PORTAL); // always fire event in case plugins wish to change it
+ return null; // Paper - keep previous behavior of not firing PlayerTeleportEvent if the target world doesn't exist
} else {
boolean flag = worldserver1.getTypeKey() == LevelStem.NETHER;
// CraftBukkit end
diff --git a/src/main/java/net/minecraft/world/level/portal/DimensionTransition.java b/src/main/java/net/minecraft/world/level/portal/DimensionTransition.java
index 788f79dc38012595b385ee6a449daa0bccf0079a..36c8735312c885eb153f4ffdf0f2a5495e9c9f65 100644
--- a/src/main/java/net/minecraft/world/level/portal/DimensionTransition.java
+++ b/src/main/java/net/minecraft/world/level/portal/DimensionTransition.java
@@ -15,9 +15,7 @@ public record DimensionTransition(ServerLevel newLevel, Vec3 pos, Vec3 speed, fl
this(newLevel, pos, speed, yRot, xRot, missingRespawnBlock, postDimensionTransition, PlayerTeleportEvent.TeleportCause.UNKNOWN);
}
- public DimensionTransition(PlayerTeleportEvent.TeleportCause cause) {
- this(null, Vec3.ZERO, Vec3.ZERO, 0.0F, 0.0F, false, DO_NOTHING, cause);
- }
+ // Paper - remove unused constructor (for safety)
// CraftBukkit end
public static final DimensionTransition.PostDimensionTransition DO_NOTHING = (entity) -> {