137 lines
7.0 KiB
Diff
137 lines
7.0 KiB
Diff
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||
|
From: Jake Potrebic <jake.m.potrebic@gmail.com>
|
||
|
Date: Wed, 2 Dec 2020 18:23:26 -0800
|
||
|
Subject: [PATCH] Add cause to Weather/ThunderChangeEvents
|
||
|
|
||
|
|
||
|
diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
|
||
|
index 511e6a941d441c55a4b38660f0f7f8c47fa689dd..85e62e3c52950a517c4dbae739d21d879cb467a4 100644
|
||
|
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
|
||
|
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
|
||
|
@@ -413,8 +413,8 @@ public class ServerLevel extends net.minecraft.world.level.Level implements Worl
|
||
|
this.worldDataServer.setClearWeatherTime(clearDuration);
|
||
|
this.worldDataServer.setRainTime(rainDuration);
|
||
|
this.worldDataServer.setThunderTime(rainDuration);
|
||
|
- this.worldDataServer.setRaining(raining);
|
||
|
- this.worldDataServer.setThundering(thundering);
|
||
|
+ this.worldDataServer.setRaining(raining, org.bukkit.event.weather.WeatherChangeEvent.Cause.COMMAND); // Paper
|
||
|
+ this.worldDataServer.setThundering(thundering, org.bukkit.event.weather.ThunderChangeEvent.Cause.COMMAND); // Paper
|
||
|
}
|
||
|
|
||
|
public Biome getBiomeBySeed(int i, int j, int k) { return getUncachedNoiseBiome(i, j, k); } // Paper - OBFHELPER
|
||
|
@@ -476,8 +476,8 @@ public class ServerLevel extends net.minecraft.world.level.Level implements Worl
|
||
|
this.worldDataServer.setThunderTime(j);
|
||
|
this.worldDataServer.setRainTime(k);
|
||
|
this.worldDataServer.setClearWeatherTime(i);
|
||
|
- this.worldDataServer.setThundering(flag1);
|
||
|
- this.worldDataServer.setRaining(flag2);
|
||
|
+ this.worldDataServer.setThundering(flag1, org.bukkit.event.weather.ThunderChangeEvent.Cause.NATURAL); // Paper
|
||
|
+ this.worldDataServer.setRaining(flag2, org.bukkit.event.weather.WeatherChangeEvent.Cause.NATURAL); // Paper
|
||
|
}
|
||
|
|
||
|
this.oThunderLevel = this.thunderLevel;
|
||
|
@@ -879,14 +879,14 @@ public class ServerLevel extends net.minecraft.world.level.Level implements Worl
|
||
|
|
||
|
private void stopWeather() {
|
||
|
// CraftBukkit start
|
||
|
- this.worldDataServer.setRaining(false);
|
||
|
+ this.worldDataServer.setRaining(false, org.bukkit.event.weather.WeatherChangeEvent.Cause.SLEEP); // Paper - when passing the night
|
||
|
// If we stop due to everyone sleeping we should reset the weather duration to some other random value.
|
||
|
// Not that everyone ever manages to get the whole server to sleep at the same time....
|
||
|
if (!this.worldDataServer.isRaining()) {
|
||
|
this.worldDataServer.setRainTime(0);
|
||
|
}
|
||
|
// CraftBukkit end
|
||
|
- this.worldDataServer.setThundering(false);
|
||
|
+ this.worldDataServer.setThundering(false, org.bukkit.event.weather.ThunderChangeEvent.Cause.SLEEP); // Paper - when passing the night
|
||
|
// CraftBukkit start
|
||
|
// If we stop due to everyone sleeping we should reset the weather duration to some other random value.
|
||
|
// Not that everyone ever manages to get the whole server to sleep at the same time....
|
||
|
diff --git a/src/main/java/net/minecraft/world/level/storage/PrimaryLevelData.java b/src/main/java/net/minecraft/world/level/storage/PrimaryLevelData.java
|
||
|
index 83f2fdfa1ac2435f5199b5c33bfc409d2e94f4ed..e902534fd64f72e46feefa04f526e0dacd612627 100644
|
||
|
--- a/src/main/java/net/minecraft/world/level/storage/PrimaryLevelData.java
|
||
|
+++ b/src/main/java/net/minecraft/world/level/storage/PrimaryLevelData.java
|
||
|
@@ -325,21 +325,26 @@ public class PrimaryLevelData implements ServerLevelData, WorldData {
|
||
|
|
||
|
@Override
|
||
|
public void setThundering(boolean thundering) {
|
||
|
+ // Paper start
|
||
|
+ this.setThundering(thundering, org.bukkit.event.weather.ThunderChangeEvent.Cause.UNKNOWN);
|
||
|
+ }
|
||
|
+ public void setThundering(boolean flag, org.bukkit.event.weather.ThunderChangeEvent.Cause cause) {
|
||
|
+ // Paper end
|
||
|
// CraftBukkit start
|
||
|
- if (this.thundering == thundering) {
|
||
|
+ if (this.thundering == flag) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
org.bukkit.World world = Bukkit.getWorld(getLevelName());
|
||
|
if (world != null) {
|
||
|
- ThunderChangeEvent thunder = new ThunderChangeEvent(world, thundering);
|
||
|
+ ThunderChangeEvent thunder = new ThunderChangeEvent(world, flag, cause); // Paper
|
||
|
Bukkit.getServer().getPluginManager().callEvent(thunder);
|
||
|
if (thunder.isCancelled()) {
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
|
// CraftBukkit end
|
||
|
- this.thundering = thundering;
|
||
|
+ this.thundering = flag;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
@@ -359,21 +364,27 @@ public class PrimaryLevelData implements ServerLevelData, WorldData {
|
||
|
|
||
|
@Override
|
||
|
public void setRaining(boolean raining) {
|
||
|
+ // Paper start
|
||
|
+ this.setRaining(raining, org.bukkit.event.weather.WeatherChangeEvent.Cause.UNKNOWN);
|
||
|
+ }
|
||
|
+
|
||
|
+ public void setStorm(boolean flag, org.bukkit.event.weather.WeatherChangeEvent.Cause cause) {
|
||
|
+ // Paper end
|
||
|
// CraftBukkit start
|
||
|
- if (this.raining == raining) {
|
||
|
+ if (this.raining == flag) {
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
org.bukkit.World world = Bukkit.getWorld(getLevelName());
|
||
|
if (world != null) {
|
||
|
- WeatherChangeEvent weather = new WeatherChangeEvent(world, raining);
|
||
|
+ WeatherChangeEvent weather = new WeatherChangeEvent(world, flag, cause); // Paper
|
||
|
Bukkit.getServer().getPluginManager().callEvent(weather);
|
||
|
if (weather.isCancelled()) {
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
|
// CraftBukkit end
|
||
|
- this.raining = raining;
|
||
|
+ this.raining = flag;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
||
|
index a1fa2d5e00bd125abd38a00e0bc3936f2fb8186f..1c9321cef1a05c5e8a22dd52bc63a5103eaf7311 100644
|
||
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
||
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
||
|
@@ -1452,7 +1452,7 @@ public class CraftWorld implements World {
|
||
|
|
||
|
@Override
|
||
|
public void setStorm(boolean hasStorm) {
|
||
|
- world.levelData.setRaining(hasStorm);
|
||
|
+ world.worldDataServer.setRaining(hasStorm, org.bukkit.event.weather.WeatherChangeEvent.Cause.PLUGIN); // Paper
|
||
|
setWeatherDuration(0); // Reset weather duration (legacy behaviour)
|
||
|
setClearWeatherDuration(0); // Reset clear weather duration (reset "/weather clear" commands)
|
||
|
}
|
||
|
@@ -1474,7 +1474,7 @@ public class CraftWorld implements World {
|
||
|
|
||
|
@Override
|
||
|
public void setThundering(boolean thundering) {
|
||
|
- world.worldDataServer.setThundering(thundering);
|
||
|
+ world.worldDataServer.setThundering(thundering, org.bukkit.event.weather.ThunderChangeEvent.Cause.PLUGIN); // Paper
|
||
|
setThunderDuration(0); // Reset weather duration (legacy behaviour)
|
||
|
setClearWeatherDuration(0); // Reset clear weather duration (reset "/weather clear" commands)
|
||
|
}
|