Add cause to Weather/ThunderChangeEvents

This commit is contained in:
Jake Potrebic 2020-12-02 18:23:26 -08:00
parent c2b061d759
commit f61b2947ad
3 changed files with 63 additions and 29 deletions

View file

@ -61,7 +61,7 @@
private int lastSpawnChunkRadius; private int lastSpawnChunkRadius;
final EntityTickList entityTickList = new EntityTickList(); final EntityTickList entityTickList = new EntityTickList();
public final PersistentEntitySectionManager<Entity> entityManager; public final PersistentEntitySectionManager<Entity> entityManager;
@@ -214,54 +226,204 @@ @@ -214,53 +226,203 @@
private final boolean tickTime; private final boolean tickTime;
private final RandomSequences randomSequences; private final RandomSequences randomSequences;
@ -80,7 +80,7 @@
+ public final UUID uuid; + public final UUID uuid;
+ public boolean hasPhysicsEvent = true; // Paper - BlockPhysicsEvent + public boolean hasPhysicsEvent = true; // Paper - BlockPhysicsEvent
+ public boolean hasEntityMoveEvent; // Paper - Add EntityMoveEvent + public boolean hasEntityMoveEvent; // Paper - Add EntityMoveEvent
+
+ public LevelChunk getChunkIfLoaded(int x, int z) { + public LevelChunk getChunkIfLoaded(int x, int z) {
+ return this.chunkSource.getChunk(x, z, false); + return this.chunkSource.getChunk(x, z, false);
+ } + }
@ -133,7 +133,7 @@
+ +
+ int maxBlockX = Mth.floor(axisalignedbb.maxX + 1.0E-7D) + 3; + int maxBlockX = Mth.floor(axisalignedbb.maxX + 1.0E-7D) + 3;
+ int maxBlockZ = Mth.floor(axisalignedbb.maxZ + 1.0E-7D) + 3; + int maxBlockZ = Mth.floor(axisalignedbb.maxZ + 1.0E-7D) + 3;
+
+ int minChunkX = minBlockX >> 4; + int minChunkX = minBlockX >> 4;
+ int minChunkZ = minBlockZ >> 4; + int minChunkZ = minBlockZ >> 4;
+ +
@ -278,18 +278,28 @@
return (RandomSequences) this.getDataStorage().computeIfAbsent(RandomSequences.factory(l), "random_sequences"); return (RandomSequences) this.getDataStorage().computeIfAbsent(RandomSequences.factory(l), "random_sequences");
}); });
+ this.getCraftServer().addWorld(this.getWorld()); // CraftBukkit + this.getCraftServer().addWorld(this.getWorld()); // CraftBukkit
} + }
+
+ // Paper start + // Paper start
+ @Override + @Override
+ public boolean hasChunk(int chunkX, int chunkZ) { + public boolean hasChunk(int chunkX, int chunkZ) {
+ return this.getChunkSource().getChunkAtIfLoadedImmediately(chunkX, chunkZ) != null; + return this.getChunkSource().getChunkAtIfLoadedImmediately(chunkX, chunkZ) != null;
+ } }
+ // Paper end + // Paper end
+
/** @deprecated */ /** @deprecated */
@Deprecated @Deprecated
@VisibleForTesting @@ -273,8 +435,8 @@
this.serverLevelData.setClearWeatherTime(clearDuration);
this.serverLevelData.setRainTime(rainDuration);
this.serverLevelData.setThunderTime(rainDuration);
- this.serverLevelData.setRaining(raining);
- this.serverLevelData.setThundering(thundering);
+ this.serverLevelData.setRaining(raining, org.bukkit.event.weather.WeatherChangeEvent.Cause.COMMAND); // Paper - Add cause to Weather/ThunderChangeEvents
+ this.serverLevelData.setThundering(thundering, org.bukkit.event.weather.ThunderChangeEvent.Cause.COMMAND); // Paper - Add cause to Weather/ThunderChangeEvents
}
@Override
@@ -305,12 +467,20 @@ @@ -305,12 +467,20 @@
long j; long j;
@ -408,6 +418,17 @@
} }
} }
@@ -679,8 +852,8 @@
this.serverLevelData.setThunderTime(j);
this.serverLevelData.setRainTime(k);
this.serverLevelData.setClearWeatherTime(i);
- this.serverLevelData.setThundering(flag1);
- this.serverLevelData.setRaining(flag2);
+ this.serverLevelData.setThundering(flag1, org.bukkit.event.weather.ThunderChangeEvent.Cause.NATURAL); // Paper - Add cause to Weather/ThunderChangeEvents
+ this.serverLevelData.setRaining(flag2, org.bukkit.event.weather.WeatherChangeEvent.Cause.NATURAL); // Paper - Add cause to Weather/ThunderChangeEvents
}
this.oThunderLevel = this.thunderLevel;
@@ -701,33 +874,67 @@ @@ -701,33 +874,67 @@
this.rainLevel = Mth.clamp(this.rainLevel, 0.0F, 1.0F); this.rainLevel = Mth.clamp(this.rainLevel, 0.0F, 1.0F);
} }
@ -464,16 +485,18 @@
@VisibleForTesting @VisibleForTesting
public void resetWeatherCycle() { public void resetWeatherCycle() {
- this.serverLevelData.setRainTime(0); - this.serverLevelData.setRainTime(0);
+ // CraftBukkit start - this.serverLevelData.setRaining(false);
this.serverLevelData.setRaining(false);
- this.serverLevelData.setThunderTime(0); - this.serverLevelData.setThunderTime(0);
- this.serverLevelData.setThundering(false);
+ // CraftBukkit start
+ this.serverLevelData.setRaining(false, org.bukkit.event.weather.WeatherChangeEvent.Cause.SLEEP); // Paper - Add cause to Weather/ThunderChangeEvents
+ // If we stop due to everyone sleeping we should reset the weather duration to some other random value. + // 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.... + // Not that everyone ever manages to get the whole server to sleep at the same time....
+ if (!this.serverLevelData.isRaining()) { + if (!this.serverLevelData.isRaining()) {
+ this.serverLevelData.setRainTime(0); + this.serverLevelData.setRainTime(0);
+ } + }
+ // CraftBukkit end + // CraftBukkit end
this.serverLevelData.setThundering(false); + this.serverLevelData.setThundering(false, org.bukkit.event.weather.ThunderChangeEvent.Cause.SLEEP); // Paper - Add cause to Weather/ThunderChangeEvents
+ // CraftBukkit start + // CraftBukkit start
+ // If we stop due to everyone sleeping we should reset the weather duration to some other random value. + // 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.... + // Not that everyone ever manages to get the whole server to sleep at the same time....
@ -783,15 +806,14 @@
case NONE: case NONE:
explosion_effect = Explosion.BlockInteraction.KEEP; explosion_effect = Explosion.BlockInteraction.KEEP;
break; break;
@@ -1143,17 +1480,28 @@ @@ -1144,16 +1481,27 @@
break;
case TRIGGER: case TRIGGER:
explosion_effect = Explosion.BlockInteraction.TRIGGER_BLOCK; explosion_effect = Explosion.BlockInteraction.TRIGGER_BLOCK;
+ break; break;
+ // CraftBukkit start - handle custom explosion type + // CraftBukkit start - handle custom explosion type
+ case STANDARD: + case STANDARD:
+ explosion_effect = Explosion.BlockInteraction.DESTROY; + explosion_effect = Explosion.BlockInteraction.DESTROY;
break; + break;
+ // CraftBukkit end + // CraftBukkit end
default: default:
throw new MatchException((String) null, (Throwable) null); throw new MatchException((String) null, (Throwable) null);
@ -838,9 +860,12 @@
public <T extends ParticleOptions> int sendParticles(T parameters, boolean force, boolean important, double x, double y, double z, int count, double offsetX, double offsetY, double offsetZ, double speed) { public <T extends ParticleOptions> int sendParticles(T parameters, boolean force, boolean important, double x, double y, double z, int count, double offsetX, double offsetY, double offsetZ, double speed) {
- ClientboundLevelParticlesPacket packetplayoutworldparticles = new ClientboundLevelParticlesPacket(parameters, force, important, x, y, z, (float) offsetX, (float) offsetY, (float) offsetZ, (float) speed, count); - ClientboundLevelParticlesPacket packetplayoutworldparticles = new ClientboundLevelParticlesPacket(parameters, force, important, x, y, z, (float) offsetX, (float) offsetY, (float) offsetZ, (float) speed, count);
- int j = 0;
+ return this.sendParticlesSource(null, parameters, force, important, x, y, z, count, offsetX, offsetY, offsetZ, speed); // CraftBukkit - visibility api support + return this.sendParticlesSource(null, parameters, force, important, x, y, z, count, offsetX, offsetY, offsetZ, speed); // CraftBukkit - visibility api support
+ } + }
+
- for (int k = 0; k < this.players.size(); ++k) {
- ServerPlayer entityplayer = (ServerPlayer) this.players.get(k);
+ // CraftBukkit start - visibility api support + // CraftBukkit start - visibility api support
+ public <T extends ParticleOptions> int sendParticlesSource(ServerPlayer sender, T t0, boolean flag, boolean flag1, double d0, double d1, double d2, int i, double d3, double d4, double d5, double d6) { + public <T extends ParticleOptions> int sendParticlesSource(ServerPlayer sender, T t0, boolean flag, boolean flag1, double d0, double d1, double d2, int i, double d3, double d4, double d5, double d6) {
+ // Paper start - Particle API + // Paper start - Particle API
@ -850,15 +875,13 @@
+ // Paper end - Particle API + // Paper end - Particle API
+ // CraftBukkit end + // CraftBukkit end
+ ClientboundLevelParticlesPacket packetplayoutworldparticles = new ClientboundLevelParticlesPacket(t0, flag, flag1, d0, d1, d2, (float) d3, (float) d4, (float) d5, (float) d6, i); + ClientboundLevelParticlesPacket packetplayoutworldparticles = new ClientboundLevelParticlesPacket(t0, flag, flag1, d0, d1, d2, (float) d3, (float) d4, (float) d5, (float) d6, i);
int j = 0; + int j = 0;
- for (int k = 0; k < this.players.size(); ++k) { - if (this.sendParticles(entityplayer, force, x, y, z, packetplayoutworldparticles)) {
- ServerPlayer entityplayer = (ServerPlayer) this.players.get(k);
+ for (Player entityhuman : receivers) { // Paper - Particle API + for (Player entityhuman : receivers) { // Paper - Particle API
+ ServerPlayer entityplayer = (ServerPlayer) entityhuman; // Paper - Particle API + ServerPlayer entityplayer = (ServerPlayer) entityhuman; // Paper - Particle API
+ if (sender != null && !entityplayer.getBukkitEntity().canSee(sender.getBukkitEntity())) continue; // CraftBukkit + if (sender != null && !entityplayer.getBukkitEntity().canSee(sender.getBukkitEntity())) continue; // CraftBukkit
+
- if (this.sendParticles(entityplayer, force, x, y, z, packetplayoutworldparticles)) {
+ if (this.sendParticles(entityplayer, flag, d0, d1, d2, packetplayoutworldparticles)) { + if (this.sendParticles(entityplayer, flag, d0, d1, d2, packetplayoutworldparticles)) {
++j; ++j;
} }

View file

@ -120,10 +120,15 @@
Objects.requireNonNull(nbttaglist); Objects.requireNonNull(nbttaglist);
stream.forEach(nbttaglist::add); stream.forEach(nbttaglist::add);
@@ -310,6 +337,20 @@ @@ -310,6 +337,25 @@
@Override @Override
public void setThundering(boolean thundering) { public void setThundering(boolean thundering) {
+ // Paper start - Add cause to Weather/ThunderChangeEvents
+ this.setThundering(thundering, org.bukkit.event.weather.ThunderChangeEvent.Cause.UNKNOWN);
+ }
+ public void setThundering(boolean thundering, org.bukkit.event.weather.ThunderChangeEvent.Cause cause) {
+ // Paper end - Add cause to Weather/ThunderChangeEvents
+ // CraftBukkit start + // CraftBukkit start
+ if (this.thundering == thundering) { + if (this.thundering == thundering) {
+ return; + return;
@ -131,7 +136,7 @@
+ +
+ org.bukkit.World world = Bukkit.getWorld(this.getLevelName()); + org.bukkit.World world = Bukkit.getWorld(this.getLevelName());
+ if (world != null) { + if (world != null) {
+ ThunderChangeEvent thunder = new ThunderChangeEvent(world, thundering); + ThunderChangeEvent thunder = new ThunderChangeEvent(world, thundering, cause); // Paper - Add cause to Weather/ThunderChangeEvents
+ Bukkit.getServer().getPluginManager().callEvent(thunder); + Bukkit.getServer().getPluginManager().callEvent(thunder);
+ if (thunder.isCancelled()) { + if (thunder.isCancelled()) {
+ return; + return;
@ -141,10 +146,16 @@
this.thundering = thundering; this.thundering = thundering;
} }
@@ -330,6 +371,20 @@ @@ -330,6 +376,26 @@
@Override @Override
public void setRaining(boolean raining) { public void setRaining(boolean raining) {
+ // Paper start - Add cause to Weather/ThunderChangeEvents
+ this.setRaining(raining, org.bukkit.event.weather.WeatherChangeEvent.Cause.UNKNOWN);
+ }
+
+ public void setRaining(boolean raining, org.bukkit.event.weather.WeatherChangeEvent.Cause cause) {
+ // Paper end - Add cause to Weather/ThunderChangeEvents
+ // CraftBukkit start + // CraftBukkit start
+ if (this.raining == raining) { + if (this.raining == raining) {
+ return; + return;
@ -152,7 +163,7 @@
+ +
+ org.bukkit.World world = Bukkit.getWorld(this.getLevelName()); + org.bukkit.World world = Bukkit.getWorld(this.getLevelName());
+ if (world != null) { + if (world != null) {
+ WeatherChangeEvent weather = new WeatherChangeEvent(world, raining); + WeatherChangeEvent weather = new WeatherChangeEvent(world, raining, cause); // Paper - Add cause to Weather/ThunderChangeEvents
+ Bukkit.getServer().getPluginManager().callEvent(weather); + Bukkit.getServer().getPluginManager().callEvent(weather);
+ if (weather.isCancelled()) { + if (weather.isCancelled()) {
+ return; + return;
@ -162,7 +173,7 @@
this.raining = raining; this.raining = raining;
} }
@@ -396,6 +451,12 @@ @@ -396,6 +462,12 @@
@Override @Override
public void setDifficulty(Difficulty difficulty) { public void setDifficulty(Difficulty difficulty) {
this.settings = this.settings.withDifficulty(difficulty); this.settings = this.settings.withDifficulty(difficulty);
@ -175,7 +186,7 @@
} }
@Override @Override
@@ -532,6 +593,14 @@ @@ -532,6 +604,14 @@
return this.settings.copy(); return this.settings.copy();
} }

View file

@ -1201,7 +1201,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {
@Override @Override
public void setStorm(boolean hasStorm) { public void setStorm(boolean hasStorm) {
this.world.levelData.setRaining(hasStorm); this.world.serverLevelData.setRaining(hasStorm, org.bukkit.event.weather.WeatherChangeEvent.Cause.PLUGIN); // Paper - Add cause to Weather/ThunderChangeEvents
this.setWeatherDuration(0); // Reset weather duration (legacy behaviour) this.setWeatherDuration(0); // Reset weather duration (legacy behaviour)
this.setClearWeatherDuration(0); // Reset clear weather duration (reset "/weather clear" commands) this.setClearWeatherDuration(0); // Reset clear weather duration (reset "/weather clear" commands)
} }
@ -1223,7 +1223,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {
@Override @Override
public void setThundering(boolean thundering) { public void setThundering(boolean thundering) {
this.world.serverLevelData.setThundering(thundering); this.world.serverLevelData.setThundering(thundering, org.bukkit.event.weather.ThunderChangeEvent.Cause.PLUGIN); // Paper - Add cause to Weather/ThunderChangeEvents
this.setThunderDuration(0); // Reset weather duration (legacy behaviour) this.setThunderDuration(0); // Reset weather duration (legacy behaviour)
this.setClearWeatherDuration(0); // Reset clear weather duration (reset "/weather clear" commands) this.setClearWeatherDuration(0); // Reset clear weather duration (reset "/weather clear" commands)
} }