mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-28 23:38:25 +01:00
Add cause to Weather/ThunderChangeEvents
This commit is contained in:
parent
c2b061d759
commit
f61b2947ad
3 changed files with 63 additions and 29 deletions
|
@ -61,7 +61,7 @@
|
|||
private int lastSpawnChunkRadius;
|
||||
final EntityTickList entityTickList = new EntityTickList();
|
||||
public final PersistentEntitySectionManager<Entity> entityManager;
|
||||
@@ -214,54 +226,204 @@
|
||||
@@ -214,53 +226,203 @@
|
||||
private final boolean tickTime;
|
||||
private final RandomSequences randomSequences;
|
||||
|
||||
|
@ -80,7 +80,7 @@
|
|||
+ public final UUID uuid;
|
||||
+ public boolean hasPhysicsEvent = true; // Paper - BlockPhysicsEvent
|
||||
+ public boolean hasEntityMoveEvent; // Paper - Add EntityMoveEvent
|
||||
|
||||
+
|
||||
+ public LevelChunk getChunkIfLoaded(int x, int z) {
|
||||
+ return this.chunkSource.getChunk(x, z, false);
|
||||
+ }
|
||||
|
@ -133,7 +133,7 @@
|
|||
+
|
||||
+ int maxBlockX = Mth.floor(axisalignedbb.maxX + 1.0E-7D) + 3;
|
||||
+ int maxBlockZ = Mth.floor(axisalignedbb.maxZ + 1.0E-7D) + 3;
|
||||
+
|
||||
|
||||
+ int minChunkX = minBlockX >> 4;
|
||||
+ int minChunkZ = minBlockZ >> 4;
|
||||
+
|
||||
|
@ -278,18 +278,28 @@
|
|||
return (RandomSequences) this.getDataStorage().computeIfAbsent(RandomSequences.factory(l), "random_sequences");
|
||||
});
|
||||
+ this.getCraftServer().addWorld(this.getWorld()); // CraftBukkit
|
||||
}
|
||||
|
||||
+ }
|
||||
+
|
||||
+ // Paper start
|
||||
+ @Override
|
||||
+ public boolean hasChunk(int chunkX, int chunkZ) {
|
||||
+ return this.getChunkSource().getChunkAtIfLoadedImmediately(chunkX, chunkZ) != null;
|
||||
+ }
|
||||
}
|
||||
+ // Paper end
|
||||
+
|
||||
|
||||
/** @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 @@
|
||||
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 @@
|
||||
this.rainLevel = Mth.clamp(this.rainLevel, 0.0F, 1.0F);
|
||||
}
|
||||
|
@ -464,16 +485,18 @@
|
|||
@VisibleForTesting
|
||||
public void resetWeatherCycle() {
|
||||
- this.serverLevelData.setRainTime(0);
|
||||
+ // CraftBukkit start
|
||||
this.serverLevelData.setRaining(false);
|
||||
- this.serverLevelData.setRaining(false);
|
||||
- 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.
|
||||
+ // Not that everyone ever manages to get the whole server to sleep at the same time....
|
||||
+ if (!this.serverLevelData.isRaining()) {
|
||||
+ this.serverLevelData.setRainTime(0);
|
||||
+ }
|
||||
+ // 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
|
||||
+ // 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....
|
||||
|
@ -783,15 +806,14 @@
|
|||
case NONE:
|
||||
explosion_effect = Explosion.BlockInteraction.KEEP;
|
||||
break;
|
||||
@@ -1143,17 +1480,28 @@
|
||||
break;
|
||||
@@ -1144,16 +1481,27 @@
|
||||
case TRIGGER:
|
||||
explosion_effect = Explosion.BlockInteraction.TRIGGER_BLOCK;
|
||||
+ break;
|
||||
break;
|
||||
+ // CraftBukkit start - handle custom explosion type
|
||||
+ case STANDARD:
|
||||
+ explosion_effect = Explosion.BlockInteraction.DESTROY;
|
||||
break;
|
||||
+ break;
|
||||
+ // CraftBukkit end
|
||||
default:
|
||||
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) {
|
||||
- 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
|
||||
+ }
|
||||
+
|
||||
|
||||
- for (int k = 0; k < this.players.size(); ++k) {
|
||||
- ServerPlayer entityplayer = (ServerPlayer) this.players.get(k);
|
||||
+ // 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) {
|
||||
+ // Paper start - Particle API
|
||||
|
@ -850,15 +875,13 @@
|
|||
+ // Paper end - Particle API
|
||||
+ // CraftBukkit end
|
||||
+ 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) {
|
||||
- ServerPlayer entityplayer = (ServerPlayer) this.players.get(k);
|
||||
- if (this.sendParticles(entityplayer, force, x, y, z, packetplayoutworldparticles)) {
|
||||
+ for (Player entityhuman : receivers) { // Paper - Particle API
|
||||
+ ServerPlayer entityplayer = (ServerPlayer) entityhuman; // Paper - Particle API
|
||||
+ 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)) {
|
||||
++j;
|
||||
}
|
||||
|
|
|
@ -120,10 +120,15 @@
|
|||
|
||||
Objects.requireNonNull(nbttaglist);
|
||||
stream.forEach(nbttaglist::add);
|
||||
@@ -310,6 +337,20 @@
|
||||
@@ -310,6 +337,25 @@
|
||||
|
||||
@Override
|
||||
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
|
||||
+ if (this.thundering == thundering) {
|
||||
+ return;
|
||||
|
@ -131,7 +136,7 @@
|
|||
+
|
||||
+ org.bukkit.World world = Bukkit.getWorld(this.getLevelName());
|
||||
+ 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);
|
||||
+ if (thunder.isCancelled()) {
|
||||
+ return;
|
||||
|
@ -141,10 +146,16 @@
|
|||
this.thundering = thundering;
|
||||
}
|
||||
|
||||
@@ -330,6 +371,20 @@
|
||||
@@ -330,6 +376,26 @@
|
||||
|
||||
@Override
|
||||
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
|
||||
+ if (this.raining == raining) {
|
||||
+ return;
|
||||
|
@ -152,7 +163,7 @@
|
|||
+
|
||||
+ org.bukkit.World world = Bukkit.getWorld(this.getLevelName());
|
||||
+ 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);
|
||||
+ if (weather.isCancelled()) {
|
||||
+ return;
|
||||
|
@ -162,7 +173,7 @@
|
|||
this.raining = raining;
|
||||
}
|
||||
|
||||
@@ -396,6 +451,12 @@
|
||||
@@ -396,6 +462,12 @@
|
||||
@Override
|
||||
public void setDifficulty(Difficulty difficulty) {
|
||||
this.settings = this.settings.withDifficulty(difficulty);
|
||||
|
@ -175,7 +186,7 @@
|
|||
}
|
||||
|
||||
@Override
|
||||
@@ -532,6 +593,14 @@
|
||||
@@ -532,6 +604,14 @@
|
||||
return this.settings.copy();
|
||||
}
|
||||
|
||||
|
|
|
@ -1201,7 +1201,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
|||
|
||||
@Override
|
||||
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.setClearWeatherDuration(0); // Reset clear weather duration (reset "/weather clear" commands)
|
||||
}
|
||||
|
@ -1223,7 +1223,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {
|
|||
|
||||
@Override
|
||||
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.setClearWeatherDuration(0); // Reset clear weather duration (reset "/weather clear" commands)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue