mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-23 02:55:47 +01:00
119 lines
9.5 KiB
Diff
119 lines
9.5 KiB
Diff
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) {
|
|
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
|
|
index 3c410f22c92a64b50d77b22c4b3027d51bcd7e05..1c4ec9049d84adbeb26b7abda82836f8ce0ff0ba 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/Entity.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
|
|
@@ -3527,7 +3527,15 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
|
|
org.bukkit.entity.Entity bukkitEntity = entity.getBukkitEntity();
|
|
Location enter = bukkitEntity.getLocation();
|
|
|
|
- EntityPortalEvent event = new EntityPortalEvent(bukkitEntity, enter, exit, searchRadius, true, creationRadius);
|
|
+ // 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
|
|
+ default -> org.bukkit.PortalType.CUSTOM;
|
|
+ };
|
|
+ EntityPortalEvent event = new EntityPortalEvent(bukkitEntity, enter, exit, searchRadius, true, creationRadius, portalType);
|
|
+ // 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
|
|
index a530276b0123dee5680d7e09ad3d2f0414909c91..1722188fbfccd233625db540ddcaf646762fd023 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) -> {
|