3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-25 15:50:06 +01:00
Paper/patches/server-unmapped/0744-Add-cause-to-Weather-ThunderChangeEvents.patch

119 Zeilen
6.6 KiB
Diff

2021-06-11 14:02:28 +02:00
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/WorldServer.java b/src/main/java/net/minecraft/server/level/WorldServer.java
index 6aace2155258d8257d53ebfcb20c37ea7497c02c..f68a252378a94c8fcab622d2d89d738aceab45a4 100644
--- a/src/main/java/net/minecraft/server/level/WorldServer.java
+++ b/src/main/java/net/minecraft/server/level/WorldServer.java
@@ -419,8 +419,8 @@ public class WorldServer extends World implements GeneratorAccessSeed {
this.worldDataServer.setClearWeatherTime(i);
this.worldDataServer.setWeatherDuration(j);
this.worldDataServer.setThunderDuration(j);
- this.worldDataServer.setStorm(flag);
- this.worldDataServer.setThundering(flag1);
+ this.worldDataServer.setStorm(flag, org.bukkit.event.weather.WeatherChangeEvent.Cause.COMMAND); // Paper
+ this.worldDataServer.setThundering(flag1, org.bukkit.event.weather.ThunderChangeEvent.Cause.COMMAND); // Paper
}
public BiomeBase getBiomeBySeed(int i, int j, int k) { return a(i, j, k); } // Paper - OBFHELPER
@@ -482,8 +482,8 @@ public class WorldServer extends World implements GeneratorAccessSeed {
this.worldDataServer.setThunderDuration(j);
this.worldDataServer.setWeatherDuration(k);
this.worldDataServer.setClearWeatherTime(i);
- this.worldDataServer.setThundering(flag1);
- this.worldDataServer.setStorm(flag2);
+ this.worldDataServer.setThundering(flag1, org.bukkit.event.weather.ThunderChangeEvent.Cause.NATURAL); // Paper
+ this.worldDataServer.setStorm(flag2, org.bukkit.event.weather.WeatherChangeEvent.Cause.NATURAL); // Paper
}
this.lastThunderLevel = this.thunderLevel;
@@ -885,14 +885,14 @@ public class WorldServer extends World implements GeneratorAccessSeed {
private void clearWeather() {
// CraftBukkit start
- this.worldDataServer.setStorm(false);
+ this.worldDataServer.setStorm(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.hasStorm()) {
this.worldDataServer.setWeatherDuration(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/WorldDataServer.java b/src/main/java/net/minecraft/world/level/storage/WorldDataServer.java
index 202d0aea445003a6dc3355ff2f2663cc675d4504..16ebfe8d873ba05521e0a49156325f14e8bd6eb9 100644
--- a/src/main/java/net/minecraft/world/level/storage/WorldDataServer.java
+++ b/src/main/java/net/minecraft/world/level/storage/WorldDataServer.java
@@ -327,6 +327,11 @@ public class WorldDataServer implements IWorldDataServer, SaveData {
@Override
public void setThundering(boolean flag) {
+ // Paper start
+ this.setThundering(flag, 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 == flag) {
return;
@@ -334,7 +339,7 @@ public class WorldDataServer implements IWorldDataServer, SaveData {
org.bukkit.World world = Bukkit.getWorld(getName());
if (world != null) {
- ThunderChangeEvent thunder = new ThunderChangeEvent(world, flag);
+ ThunderChangeEvent thunder = new ThunderChangeEvent(world, flag, cause); // Paper
Bukkit.getServer().getPluginManager().callEvent(thunder);
if (thunder.isCancelled()) {
return;
@@ -361,6 +366,12 @@ public class WorldDataServer implements IWorldDataServer, SaveData {
@Override
public void setStorm(boolean flag) {
+ // Paper start
+ this.setStorm(flag, 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 == flag) {
return;
@@ -368,7 +379,7 @@ public class WorldDataServer implements IWorldDataServer, SaveData {
org.bukkit.World world = Bukkit.getWorld(getName());
if (world != null) {
- WeatherChangeEvent weather = new WeatherChangeEvent(world, flag);
+ WeatherChangeEvent weather = new WeatherChangeEvent(world, flag, cause); // Paper
Bukkit.getServer().getPluginManager().callEvent(weather);
if (weather.isCancelled()) {
return;
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
index 3b3eda95c0ff8b129adedbae6561bba2d01c2f3a..9d858f91828d6c2787ff1dc677a247bcab172701 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
@@ -1470,7 +1470,7 @@ public class CraftWorld implements World {
@Override
public void setStorm(boolean hasStorm) {
- world.worldData.setStorm(hasStorm);
+ world.worldDataServer.setStorm(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)
}
@@ -1492,7 +1492,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)
}