3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-15 02:50:09 +01:00

Add cause to Weather/ThunderChangeEvents (#4832)

Dieser Commit ist enthalten in:
Jake Potrebic 2021-05-24 09:45:23 -07:00 committet von GitHub
Ursprung 507cf19b3a
Commit 6f93dc95dc
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
2 geänderte Dateien mit 222 neuen und 0 gelöschten Zeilen

Datei anzeigen

@ -0,0 +1,104 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jake Potrebic <jake.m.potrebic@gmail.com>
Date: Wed, 2 Dec 2020 18:25:31 -0800
Subject: [PATCH] Add cause to Weather/ThunderChangeEvents
diff --git a/src/main/java/org/bukkit/event/weather/ThunderChangeEvent.java b/src/main/java/org/bukkit/event/weather/ThunderChangeEvent.java
index 6cdf83476b4e366bed79960e3706bea5ebe56788..032395c7114b6d757acf1918ce2b014870e85fcd 100644
--- a/src/main/java/org/bukkit/event/weather/ThunderChangeEvent.java
+++ b/src/main/java/org/bukkit/event/weather/ThunderChangeEvent.java
@@ -12,10 +12,20 @@ public class ThunderChangeEvent extends WeatherEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private boolean canceled;
private final boolean to;
+ // Paper start
+ private final Cause cause;
+ public ThunderChangeEvent(@NotNull final World world, final boolean to, @NotNull final Cause cause) {
+ super(world);
+ this.to = to;
+ this.cause = cause;
+ }
+
+ @Deprecated // Paper end
public ThunderChangeEvent(@NotNull final World world, final boolean to) {
super(world);
this.to = to;
+ this.cause = Cause.UNKNOWN; // Paper
}
@Override
@@ -47,4 +57,23 @@ public class ThunderChangeEvent extends WeatherEvent implements Cancellable {
public static HandlerList getHandlerList() {
return handlers;
}
+ // Paper start
+ /**
+ * Gets the cause of the weather change.
+ *
+ * @return the weather change cause
+ */
+ @NotNull
+ public Cause getCause() {
+ return this.cause;
+ }
+
+ public enum Cause {
+ COMMAND,
+ NATURAL,
+ SLEEP,
+ PLUGIN,
+ UNKNOWN
+ }
+ // Paper end
}
diff --git a/src/main/java/org/bukkit/event/weather/WeatherChangeEvent.java b/src/main/java/org/bukkit/event/weather/WeatherChangeEvent.java
index d562d87e7418641e52f4dae44f573eaa31add44a..dabd390b84354c14c269c03cbed2006014d004b2 100644
--- a/src/main/java/org/bukkit/event/weather/WeatherChangeEvent.java
+++ b/src/main/java/org/bukkit/event/weather/WeatherChangeEvent.java
@@ -12,10 +12,20 @@ public class WeatherChangeEvent extends WeatherEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private boolean canceled;
private final boolean to;
+ // Paper start
+ private final Cause cause;
+ public WeatherChangeEvent(@NotNull final World world, final boolean to, @NotNull Cause cause) {
+ super(world);
+ this.to = to;
+ this.cause = cause;
+ }
+
+ @Deprecated // Paper end
public WeatherChangeEvent(@NotNull final World world, final boolean to) {
super(world);
this.to = to;
+ this.cause = Cause.UNKNOWN; // Paper
}
@Override
@@ -47,4 +57,23 @@ public class WeatherChangeEvent extends WeatherEvent implements Cancellable {
public static HandlerList getHandlerList() {
return handlers;
}
+ // Paper start
+ /**
+ * Gets the cause of the weather change.
+ *
+ * @return the weather change cause
+ */
+ @NotNull
+ public Cause getCause() {
+ return cause;
+ }
+
+ public enum Cause {
+ COMMAND,
+ NATURAL,
+ SLEEP,
+ PLUGIN,
+ UNKNOWN
+ }
+ // Paper end
}

Datei anzeigen

@ -0,0 +1,118 @@
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)
}