summaryrefslogtreecommitdiffstats
path: root/nms-patches/BlockPortal.patch
blob: f9ccf2aa03f22c9705f77f8658c298e4645ed09d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
--- a/net/minecraft/server/BlockPortal.java
+++ b/net/minecraft/server/BlockPortal.java
@@ -4,6 +4,9 @@
 import java.util.Random;
 import javax.annotation.Nullable;
 
+import org.bukkit.event.entity.EntityPortalEnterEvent; // CraftBukkit
+import org.bukkit.event.world.PortalCreateEvent; // CraftBukkit
+
 public class BlockPortal extends BlockHalfTransparent {
 
     public static final BlockStateEnum<EnumDirection.EnumAxis> AXIS = BlockStateEnum.of("axis", EnumDirection.EnumAxis.class, new EnumDirection.EnumAxis[] { EnumDirection.EnumAxis.X, EnumDirection.EnumAxis.Z});
@@ -43,7 +46,8 @@
             }
 
             if (i > 0 && !world.getType(blockposition1.up()).l()) {
-                Entity entity = ItemMonsterEgg.a(world, EntityTypes.getName(EntityPigZombie.class), (double) blockposition1.getX() + 0.5D, (double) blockposition1.getY() + 1.1D, (double) blockposition1.getZ() + 0.5D);
+                // CraftBukkit - set spawn reason to NETHER_PORTAL
+                Entity entity = ItemMonsterEgg.spawnCreature(world, EntityTypes.getName(EntityPigZombie.class), (double) blockposition1.getX() + 0.5D, (double) blockposition1.getY() + 1.1D, (double) blockposition1.getZ() + 0.5D, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.NETHER_PORTAL);
 
                 if (entity != null) {
                     entity.portalCooldown = entity.aM();
@@ -70,14 +74,16 @@
         BlockPortal.Shape blockportal_shape = new BlockPortal.Shape(world, blockposition, EnumDirection.EnumAxis.X);
 
         if (blockportal_shape.d() && blockportal_shape.e == 0) {
-            blockportal_shape.createPortal();
-            return true;
+            // CraftBukkit start - return portalcreator
+            return blockportal_shape.createPortal();
+            // return true;
         } else {
             BlockPortal.Shape blockportal_shape1 = new BlockPortal.Shape(world, blockposition, EnumDirection.EnumAxis.Z);
 
             if (blockportal_shape1.d() && blockportal_shape1.e == 0) {
-                blockportal_shape1.createPortal();
-                return true;
+                return blockportal_shape1.createPortal();
+                // return true;
+                // CraftBukkit end
             } else {
                 return false;
             }
@@ -108,6 +114,10 @@
 
     public void a(World world, BlockPosition blockposition, IBlockData iblockdata, Entity entity) {
         if (!entity.isPassenger() && !entity.isVehicle() && entity.bf()) {
+            // CraftBukkit start - Entity in portal
+            EntityPortalEnterEvent event = new EntityPortalEnterEvent(entity.getBukkitEntity(), new org.bukkit.Location(world.getWorld(), blockposition.getX(), blockposition.getY(), blockposition.getZ()));
+            world.getServer().getPluginManager().callEvent(event);
+            // CraftBukkit end
             entity.e(blockposition);
         }
 
@@ -216,6 +226,7 @@
         private BlockPosition position;
         private int height;
         private int width;
+        java.util.Collection<org.bukkit.block.Block> blocks = new java.util.HashSet<org.bukkit.block.Block>(); // CraftBukkit - add field
 
         public Shape(World world, BlockPosition blockposition, EnumDirection.EnumAxis enumdirection_enumaxis) {
             this.a = world;
@@ -274,6 +285,10 @@
         }
 
         protected int c() {
+            // CraftBukkit start
+            this.blocks.clear();
+            org.bukkit.World bworld = this.a.getWorld();
+            // CraftBukkit end
             int i;
 
             label56:
@@ -294,11 +309,21 @@
                         block = this.a.getType(blockposition.shift(this.d)).getBlock();
                         if (block != Blocks.OBSIDIAN) {
                             break label56;
+                            // CraftBukkit start - add the block to our list
+                        } else {
+                            BlockPosition pos = blockposition.shift(this.d);
+                            blocks.add(bworld.getBlockAt(pos.getX(), pos.getY(), pos.getZ()));
+                            // CraftBukkit end
                         }
                     } else if (i == this.width - 1) {
                         block = this.a.getType(blockposition.shift(this.c)).getBlock();
                         if (block != Blocks.OBSIDIAN) {
                             break label56;
+                            // CraftBukkit start - add the block to our list
+                        } else {
+                            BlockPosition pos = blockposition.shift(this.c);
+                            blocks.add(bworld.getBlockAt(pos.getX(), pos.getY(), pos.getZ()));
+                            // CraftBukkit end
                         }
                     }
                 }
@@ -308,6 +333,11 @@
                 if (this.a.getType(this.position.shift(this.c, i).up(this.height)).getBlock() != Blocks.OBSIDIAN) {
                     this.height = 0;
                     break;
+                    // CraftBukkit start - add the block to our list
+                } else {
+                    BlockPosition pos = this.position.shift(this.c, i).up(this.height);
+                    blocks.add(bworld.getBlockAt(pos.getX(), pos.getY(), pos.getZ()));
+                    // CraftBukkit end
                 }
             }
 
@@ -329,7 +359,27 @@
             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.a.getWorld();
+
+            // Copy below for loop
+            for (int i = 0; i < this.width; ++i) {
+                BlockPosition blockposition = this.position.shift(this.c, i);
+
+                for (int j = 0; j < this.height; ++j) {
+                    BlockPosition pos = blockposition.up(j);
+                    blocks.add(bworld.getBlockAt(pos.getX(), pos.getY(), pos.getZ()));
+                }
+            }
+
+            PortalCreateEvent event = new PortalCreateEvent(blocks, bworld, PortalCreateEvent.CreateReason.FIRE);
+            this.a.getServer().getPluginManager().callEvent(event);
+
+            if (event.isCancelled()) {
+                return false;
+            }
+            // CraftBukkit end
             for (int i = 0; i < this.width; ++i) {
                 BlockPosition blockposition = this.position.shift(this.c, i);
 
@@ -338,6 +388,7 @@
                 }
             }
 
+            return true; // CraftBukkit
         }
     }
 }