summaryrefslogtreecommitdiffstats
path: root/nms-patches/EntityBat.patch
blob: 44295d9e7e4e6dc3c1a13a065f1f2eb693b56c80 (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
--- a/net/minecraft/server/EntityBat.java
+++ b/net/minecraft/server/EntityBat.java
@@ -3,6 +3,7 @@
 import java.time.LocalDate;
 import java.time.temporal.ChronoField;
 import javax.annotation.Nullable;
+import org.bukkit.craftbukkit.event.CraftEventFactory; // CraftBukkit
 
 public class EntityBat extends EntityAmbient {
 
@@ -94,12 +95,20 @@
                 }
 
                 if (this.world.b(this, 4.0D) != null) {
+                    // CraftBukkit Start - Call BatToggleSleepEvent
+                    if (CraftEventFactory.handleBatToggleSleepEvent(this, true)) {
+                        this.setAsleep(false);
+                        this.world.a((EntityHuman) null, 1025, blockposition, 0);
+                    }
+                    // CraftBukkit End
+                }
+            } else {
+                // CraftBukkit Start - Call BatToggleSleepEvent
+                if (CraftEventFactory.handleBatToggleSleepEvent(this, true)) {
                     this.setAsleep(false);
                     this.world.a((EntityHuman) null, 1025, blockposition, 0);
                 }
-            } else {
-                this.setAsleep(false);
-                this.world.a((EntityHuman) null, 1025, blockposition, 0);
+                // CraftBukkit End - Call BatToggleSleepEvent
             }
         } else {
             if (this.b != null && (!this.world.isEmpty(this.b) || this.b.getY() < 1)) {
@@ -123,7 +132,11 @@
             this.bj = 0.5F;
             this.yaw += f1;
             if (this.random.nextInt(100) == 0 && this.world.getType(blockposition1).isOccluding()) {
-                this.setAsleep(true);
+                // CraftBukkit Start - Call BatToggleSleepEvent
+                if (CraftEventFactory.handleBatToggleSleepEvent(this, false)) {
+                    this.setAsleep(true);
+                }
+                // CraftBukkit End
             }
         }
 
@@ -146,7 +159,11 @@
             return false;
         } else {
             if (!this.world.isClientSide && this.isAsleep()) {
-                this.setAsleep(false);
+                // CraftBukkit Start - Call BatToggleSleepEvent
+                if (CraftEventFactory.handleBatToggleSleepEvent(this, true)) {
+                    this.setAsleep(false);
+                }
+                // CraftBukkit End - Call BatToggleSleepEvent
             }
 
             return super.damageEntity(damagesource, f);