summaryrefslogtreecommitdiffstats
path: root/nms-patches/DragonControllerManager.patch
blob: f33447d3307456d20569e6e93219ef907bb0bbf0 (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
--- a/net/minecraft/server/DragonControllerManager.java
+++ b/net/minecraft/server/DragonControllerManager.java
@@ -2,32 +2,44 @@
 
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
+import org.bukkit.craftbukkit.entity.CraftEnderDragon;
+import org.bukkit.entity.EnderDragon;
+import org.bukkit.event.entity.EnderDragonChangePhaseEvent;
 
 public class DragonControllerManager {
 
     private static final Logger a = LogManager.getLogger();
-    private final EntityEnderDragon b;
-    private final IDragonController[] c = new IDragonController[DragonControllerPhase.c()];
-    private IDragonController d;
+    private final EntityEnderDragon b; // PAIL: Rename enderDragon
+    private final IDragonController[] c = new IDragonController[DragonControllerPhase.c()]; // PAIL: Rename dragonControllers 
+    private IDragonController d; // PAIL: Rename currentDragonController
 
     public DragonControllerManager(EntityEnderDragon entityenderdragon) {
         this.b = entityenderdragon;
         this.a(DragonControllerPhase.k);
     }
 
-    public void a(DragonControllerPhase<?> dragoncontrollerphase) {
-        if (this.d == null || dragoncontrollerphase != this.d.i()) {
+    public void a(DragonControllerPhase<?> dragoncontrollerphase) { // PAIL: Rename setControllerPhase
+        if (this.d == null || dragoncontrollerphase != this.d.i()) { // PAIL: Rename getControllerPhase
             if (this.d != null) {
-                this.d.e();
+                this.d.e(); // PAIL: Rename
             }
 
-            this.d = this.b(dragoncontrollerphase);
+            // CraftBukkit start - Call EnderDragonChangePhaseEvent
+            EnderDragonChangePhaseEvent event = new EnderDragonChangePhaseEvent((CraftEnderDragon) this.b.getBukkitEntity(), this.d == null ? null : CraftEnderDragon.getBukkitPhase(this.d.i()), CraftEnderDragon.getBukkitPhase(dragoncontrollerphase));
+            this.b.world.getServer().getPluginManager().callEvent(event);
+            if (event.isCancelled()) {
+                return;
+            }
+            dragoncontrollerphase = CraftEnderDragon.getMinecraftPhase(event.getNewPhase());
+            // CraftBukkit end
+            
+            this.d = this.b(dragoncontrollerphase); // PAIL: Rename getDragonController
             if (!this.b.world.isClientSide) {
-                this.b.getDataWatcher().set(EntityEnderDragon.a, Integer.valueOf(dragoncontrollerphase.b()));
+                this.b.getDataWatcher().set(EntityEnderDragon.a, Integer.valueOf(dragoncontrollerphase.b())); // PAIL: Rename getId
             }
 
             DragonControllerManager.a.debug("Dragon is now in phase {} on the {}", new Object[] { dragoncontrollerphase, this.b.world.isClientSide ? "client" : "server"});
-            this.d.d();
+            this.d.d(); // PAIL: Rename reset
         }
     }
 
@@ -42,6 +54,6 @@
             this.c[i] = dragoncontrollerphase.a(this.b);
         }
 
-        return this.c[i];
+        return (T) this.c[i];
     }
 }