summaryrefslogtreecommitdiffstats
path: root/nms-patches/WorldData.patch
blob: 6c9b12c9e294b48bb0f2f591acc33823ddca11ba (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
--- a/net/minecraft/server/WorldData.java
+++ b/net/minecraft/server/WorldData.java
@@ -5,6 +5,11 @@
 import java.util.Map;
 import java.util.Map.Entry;
 import java.util.concurrent.Callable;
+// CraftBukkit start
+import org.bukkit.Bukkit;
+import org.bukkit.event.weather.ThunderChangeEvent;
+import org.bukkit.event.weather.WeatherChangeEvent;
+// CraftBukkit end
 
 public class WorldData {
 
@@ -49,6 +54,7 @@
     private int M;
     private final Map<DimensionManager, NBTTagCompound> N;
     private GameRules O;
+    public WorldServer world; // CraftBukkit
 
     protected WorldData() {
         this.f = WorldType.NORMAL;
@@ -441,6 +447,18 @@
     }
 
     public void setThundering(boolean flag) {
+        // CraftBukkit start
+        org.bukkit.World world = Bukkit.getWorld(getName());
+        if (world != null) {
+            ThunderChangeEvent thunder = new ThunderChangeEvent(world, flag);
+            Bukkit.getServer().getPluginManager().callEvent(thunder);
+            if (thunder.isCancelled()) {
+                return;
+            }
+
+            setThunderDuration(0); // Will force a time reset
+        }
+        // CraftBukkit end
         this.v = flag;
     }
 
@@ -457,6 +475,18 @@
     }
 
     public void setStorm(boolean flag) {
+        // CraftBukkit start
+        org.bukkit.World world = Bukkit.getWorld(getName());
+        if (world != null) {
+            WeatherChangeEvent weather = new WeatherChangeEvent(world, flag);
+            Bukkit.getServer().getPluginManager().callEvent(weather);
+            if (weather.isCancelled()) {
+                return;
+            }
+
+            setWeatherDuration(0); // Will force a time reset
+        }
+        // CraftBukkit end
         this.t = flag;
     }
 
@@ -602,6 +632,12 @@
 
     public void setDifficulty(EnumDifficulty enumdifficulty) {
         this.C = enumdifficulty;
+        // CraftBukkit start
+        PacketPlayOutServerDifficulty packet = new PacketPlayOutServerDifficulty(this.getDifficulty(), this.isDifficultyLocked());
+        for (EntityPlayer player : (java.util.List<EntityPlayer>) (java.util.List) world.players) {
+            player.playerConnection.sendPacket(packet);
+        }
+        // CraftBukkit end
     }
 
     public boolean isDifficultyLocked() {
@@ -720,4 +756,12 @@
     public void a(DimensionManager dimensionmanager, NBTTagCompound nbttagcompound) {
         this.N.put(dimensionmanager, nbttagcompound);
     }
+
+    // CraftBukkit start - Check if the name stored in NBT is the correct one
+    public void checkName( String name ) {
+        if ( !this.levelName.equals( name ) ) {
+            this.levelName = name;
+        }
+    }
+    // CraftBukkit end
 }