mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-29 12:27:59 +01:00
Add cause to Weather/ThunderChangeEvents (#4832)
This commit is contained in:
parent
84726837ab
commit
ebff0c4ed9
@ -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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/org/bukkit/event/weather/ThunderChangeEvent.java
|
||||
+++ b/src/main/java/org/bukkit/event/weather/ThunderChangeEvent.java
|
||||
@@ -0,0 +0,0 @@ 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
|
||||
@@ -0,0 +0,0 @@ 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/org/bukkit/event/weather/WeatherChangeEvent.java
|
||||
+++ b/src/main/java/org/bukkit/event/weather/WeatherChangeEvent.java
|
||||
@@ -0,0 +0,0 @@ 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
|
||||
@@ -0,0 +0,0 @@ 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
|
||||
}
|
@ -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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/net/minecraft/server/level/WorldServer.java
|
||||
+++ b/src/main/java/net/minecraft/server/level/WorldServer.java
|
||||
@@ -0,0 +0,0 @@ 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
|
||||
@@ -0,0 +0,0 @@ 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;
|
||||
@@ -0,0 +0,0 @@ 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/net/minecraft/world/level/storage/WorldDataServer.java
|
||||
+++ b/src/main/java/net/minecraft/world/level/storage/WorldDataServer.java
|
||||
@@ -0,0 +0,0 @@ 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;
|
||||
@@ -0,0 +0,0 @@ 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;
|
||||
@@ -0,0 +0,0 @@ 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;
|
||||
@@ -0,0 +0,0 @@ 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
|
||||
@@ -0,0 +0,0 @@ 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)
|
||||
}
|
||||
@@ -0,0 +0,0 @@ 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)
|
||||
}
|
Loading…
Reference in New Issue
Block a user