mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-22 18:45:54 +01:00
1e76d09fad
This also fixes that the nether/end portals would be created even if the event was cancelled as well as that the EntityPortalEvent would be called for player portal usage which is not according to its API specification
82 lines
4.1 KiB
Diff
82 lines
4.1 KiB
Diff
--- a/net/minecraft/server/BlockPortalShape.java
|
|
+++ b/net/minecraft/server/BlockPortalShape.java
|
|
@@ -4,6 +4,13 @@
|
|
import java.util.function.Predicate;
|
|
import javax.annotation.Nullable;
|
|
|
|
+// CraftBukkit start
|
|
+import org.bukkit.craftbukkit.block.CraftBlock;
|
|
+import org.bukkit.craftbukkit.block.CraftBlockState;
|
|
+import org.bukkit.craftbukkit.event.CraftPortalEvent;
|
|
+import org.bukkit.event.world.PortalCreateEvent;
|
|
+// CraftBukkit end
|
|
+
|
|
public class BlockPortalShape {
|
|
|
|
private static final BlockBase.e a = (iblockdata, iblockaccess, blockposition) -> {
|
|
@@ -17,6 +24,7 @@
|
|
private BlockPosition position;
|
|
private int height;
|
|
private int width;
|
|
+ java.util.List<org.bukkit.block.BlockState> blocks = new java.util.ArrayList<org.bukkit.block.BlockState>(); // CraftBukkit - add field
|
|
|
|
public static Optional<BlockPortalShape> a(GeneratorAccess generatoraccess, BlockPosition blockposition, EnumDirection.EnumAxis enumdirection_enumaxis) {
|
|
return a(generatoraccess, blockposition, (blockportalshape) -> {
|
|
@@ -81,6 +89,7 @@
|
|
|
|
if (!a(iblockdata)) {
|
|
if (BlockPortalShape.a.test(iblockdata, this.b, blockposition_mutableblockposition)) {
|
|
+ blocks.add(CraftBlock.at(this.b, blockposition_mutableblockposition).getState()); // CraftBukkit
|
|
return i;
|
|
}
|
|
break;
|
|
@@ -152,12 +161,30 @@
|
|
return this.position != null && this.width >= 2 && this.width <= 21 && this.height >= 3 && this.height <= 21;
|
|
}
|
|
|
|
- public void createPortal() {
|
|
+ // CraftBukkit start - return boolean
|
|
+ public boolean createPortal() {
|
|
+ org.bukkit.World bworld = this.b.getMinecraftWorld().getWorld();
|
|
+
|
|
+ // Copy below for loop
|
|
IBlockData iblockdata = (IBlockData) Blocks.NETHER_PORTAL.getBlockData().set(BlockPortal.AXIS, this.c);
|
|
|
|
BlockPosition.a(this.position, this.position.shift(EnumDirection.UP, this.height - 1).shift(this.d, this.width - 1)).forEach((blockposition) -> {
|
|
+ CraftBlockState state = CraftBlockState.getBlockState(this.b.getMinecraftWorld(), blockposition, 18);
|
|
+ state.setData(iblockdata);
|
|
+ blocks.add(state);
|
|
+ });
|
|
+
|
|
+ PortalCreateEvent event = new PortalCreateEvent(blocks, bworld, null, PortalCreateEvent.CreateReason.FIRE);
|
|
+ this.b.getMinecraftWorld().getMinecraftServer().server.getPluginManager().callEvent(event);
|
|
+
|
|
+ if (event.isCancelled()) {
|
|
+ return false;
|
|
+ }
|
|
+ // CraftBukkit end
|
|
+ BlockPosition.a(this.position, this.position.shift(EnumDirection.UP, this.height - 1).shift(this.d, this.width - 1)).forEach((blockposition) -> {
|
|
this.b.setTypeAndData(blockposition, iblockdata, 18);
|
|
});
|
|
+ return true; // CraftBukkit
|
|
}
|
|
|
|
public boolean c() {
|
|
@@ -194,7 +221,7 @@
|
|
return new Vec3D(d2, d3, d4);
|
|
}
|
|
|
|
- public static ShapeDetectorShape a(WorldServer worldserver, BlockUtil.Rectangle blockutil_rectangle, EnumDirection.EnumAxis enumdirection_enumaxis, Vec3D vec3d, EntitySize entitysize, Vec3D vec3d1, float f, float f1) {
|
|
+ public static ShapeDetectorShape a(WorldServer worldserver, BlockUtil.Rectangle blockutil_rectangle, EnumDirection.EnumAxis enumdirection_enumaxis, Vec3D vec3d, EntitySize entitysize, Vec3D vec3d1, float f, float f1, CraftPortalEvent portalEventInfo) { // CraftBukkit // PAIL rename toDetectorShape
|
|
BlockPosition blockposition = blockutil_rectangle.origin;
|
|
IBlockData iblockdata = worldserver.getType(blockposition);
|
|
EnumDirection.EnumAxis enumdirection_enumaxis1 = (EnumDirection.EnumAxis) iblockdata.get(BlockProperties.E);
|
|
@@ -208,6 +235,6 @@
|
|
boolean flag = enumdirection_enumaxis1 == EnumDirection.EnumAxis.X;
|
|
Vec3D vec3d3 = new Vec3D((double) blockposition.getX() + (flag ? d2 : d4), (double) blockposition.getY() + d3, (double) blockposition.getZ() + (flag ? d4 : d2));
|
|
|
|
- return new ShapeDetectorShape(vec3d3, vec3d2, f + (float) i, f1);
|
|
+ return new ShapeDetectorShape(vec3d3, vec3d2, f + (float) i, f1, worldserver, portalEventInfo); // CraftBukkit
|
|
}
|
|
}
|