Rewrite storm / thunder event handling to catch all cases. Fixes SPIGOT-335.

This commit is contained in:
md_5 2015-01-05 09:50:48 +11:00
parent e5c51c790f
commit 07fcb493a9
3 changed files with 98 additions and 88 deletions

View file

@ -1,5 +1,5 @@
--- ../work/decompile-8eb82bde/net/minecraft/server/World.java 2014-12-10 19:16:20.916465384 +0000 --- ../work/decompile-8eb82bde/net/minecraft/server/World.java 2015-01-05 09:42:04.285856834 +1100
+++ src/main/java/net/minecraft/server/World.java 2014-12-10 19:11:37.648468459 +0000 +++ src/main/java/net/minecraft/server/World.java 2015-01-05 09:42:04.293856810 +1100
@@ -13,6 +13,22 @@ @@ -13,6 +13,22 @@
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
@ -412,38 +412,7 @@
entity.P = entity.locX; entity.P = entity.locX;
entity.Q = entity.locY; entity.Q = entity.locY;
entity.R = entity.locZ; entity.R = entity.locZ;
@@ -1615,7 +1834,13 @@ @@ -1651,12 +1870,18 @@
--j;
this.worldData.setThunderDuration(j);
if (j <= 0) {
- this.worldData.setThundering(!this.worldData.isThundering());
+ // CraftBukkit start
+ ThunderChangeEvent thunder = new ThunderChangeEvent(this.getWorld(), !this.worldData.isThundering());
+ this.getServer().getPluginManager().callEvent(thunder);
+ if (!thunder.isCancelled()) {
+ this.worldData.setThundering(!this.worldData.isThundering());
+ }
+ // CraftBukkit end
}
}
@@ -1639,7 +1864,14 @@
--k;
this.worldData.setWeatherDuration(k);
if (k <= 0) {
- this.worldData.setStorm(!this.worldData.hasStorm());
+ // CraftBukkit start
+ WeatherChangeEvent weather = new WeatherChangeEvent(this.getWorld(), !this.worldData.hasStorm());
+ this.getServer().getPluginManager().callEvent(weather);
+
+ if (!weather.isCancelled()) {
+ this.worldData.setStorm(!this.worldData.hasStorm());
+ }
+ // CraftBukkit end
}
}
@@ -1651,12 +1883,18 @@
} }
this.p = MathHelper.a(this.p, 0.0F, 1.0F); this.p = MathHelper.a(this.p, 0.0F, 1.0F);
@ -463,7 +432,7 @@
this.methodProfiler.a("buildList"); this.methodProfiler.a("buildList");
int i; int i;
@@ -1673,7 +1911,7 @@ @@ -1673,7 +1898,7 @@
for (int i1 = -l; i1 <= l; ++i1) { for (int i1 = -l; i1 <= l; ++i1) {
for (int j1 = -l; j1 <= l; ++j1) { for (int j1 = -l; j1 <= l; ++j1) {
@ -472,7 +441,7 @@
} }
} }
} }
@@ -1851,7 +2089,10 @@ @@ -1851,7 +2076,10 @@
} }
public boolean c(EnumSkyBlock enumskyblock, BlockPosition blockposition) { public boolean c(EnumSkyBlock enumskyblock, BlockPosition blockposition) {
@ -484,7 +453,7 @@
return false; return false;
} else { } else {
int i = 0; int i = 0;
@@ -2095,8 +2336,17 @@ @@ -2095,8 +2323,17 @@
while (iterator.hasNext()) { while (iterator.hasNext()) {
Entity entity = (Entity) iterator.next(); Entity entity = (Entity) iterator.next();
@ -503,7 +472,7 @@
++i; ++i;
} }
} }
@@ -2105,12 +2355,17 @@ @@ -2105,12 +2342,17 @@
} }
public void b(Collection collection) { public void b(Collection collection) {
@ -523,7 +492,7 @@
this.a(entity); this.a(entity);
} }
@@ -2124,7 +2379,13 @@ @@ -2124,7 +2366,13 @@
Block block1 = this.getType(blockposition).getBlock(); Block block1 = this.getType(blockposition).getBlock();
AxisAlignedBB axisalignedbb = flag ? null : block.a(this, blockposition, block.getBlockData()); AxisAlignedBB axisalignedbb = flag ? null : block.a(this, blockposition, block.getBlockData());
@ -538,7 +507,7 @@
} }
public int getBlockPower(BlockPosition blockposition, EnumDirection enumdirection) { public int getBlockPower(BlockPosition blockposition, EnumDirection enumdirection) {
@@ -2215,6 +2476,11 @@ @@ -2215,6 +2463,11 @@
for (int i = 0; i < this.players.size(); ++i) { for (int i = 0; i < this.players.size(); ++i) {
EntityHuman entityhuman1 = (EntityHuman) this.players.get(i); EntityHuman entityhuman1 = (EntityHuman) this.players.get(i);
@ -550,7 +519,7 @@
if (IEntitySelector.d.apply(entityhuman1)) { if (IEntitySelector.d.apply(entityhuman1)) {
double d5 = entityhuman1.e(d0, d1, d2); double d5 = entityhuman1.e(d0, d1, d2);
@@ -2269,7 +2535,7 @@ @@ -2269,7 +2522,7 @@
return null; return null;
} }
@ -559,7 +528,7 @@
this.dataManager.checkSession(); this.dataManager.checkSession();
} }
@@ -2331,6 +2597,16 @@ @@ -2331,6 +2584,16 @@
public void everyoneSleeping() {} public void everyoneSleeping() {}
@ -576,7 +545,7 @@
public float h(float f) { public float h(float f) {
return (this.q + (this.r - this.q) * f) * this.j(f); return (this.q + (this.r - this.q) * f) * this.j(f);
} }
@@ -2538,6 +2814,6 @@ @@ -2538,6 +2801,6 @@
int l = j * 16 + 8 - blockposition.getZ(); int l = j * 16 + 8 - blockposition.getZ();
short short0 = 128; short short0 = 128;

View file

@ -1,6 +1,50 @@
--- ../work/decompile-8eb82bde//net/minecraft/server/WorldData.java Sat Nov 29 19:36:33 2014 --- ../work/decompile-8eb82bde/net/minecraft/server/WorldData.java 2015-01-05 09:50:01.989188327 +1100
+++ src/main/java/net/minecraft/server/WorldData.java Sat Nov 29 19:35:56 2014 +++ src/main/java/net/minecraft/server/WorldData.java 2015-01-05 09:50:01.993188321 +1100
@@ -645,4 +645,12 @@ @@ -1,6 +1,9 @@
package net.minecraft.server;
import java.util.concurrent.Callable;
+import org.bukkit.Bukkit;
+import org.bukkit.event.weather.ThunderChangeEvent;
+import org.bukkit.event.weather.WeatherChangeEvent;
public class WorldData {
@@ -395,6 +398,16 @@
}
public void setThundering(boolean flag) {
+ // CraftBukkit start
+ org.bukkit.World world = Bukkit.getWorld(getName());
+ if (world != null) {
+ ThunderChangeEvent thunder = new ThunderChangeEvent(world, flag);
+ Bukkit.getServer().getPluginManager().callEvent(thunder);
+ if (thunder.isCancelled()) {
+ return;
+ }
+ }
+ // CraftBukkit end
this.s = flag;
}
@@ -411,6 +424,16 @@
}
public void setStorm(boolean flag) {
+ // CraftBukkit start
+ org.bukkit.World world = Bukkit.getWorld(getName());
+ if (world != null) {
+ WeatherChangeEvent weather = new WeatherChangeEvent(world, flag);
+ Bukkit.getServer().getPluginManager().callEvent(weather);
+ if (weather.isCancelled()) {
+ return;
+ }
+ }
+ // CraftBukkit end
this.q = flag;
}
@@ -645,4 +668,12 @@
static boolean q(WorldData worlddata) { static boolean q(WorldData worlddata) {
return worlddata.x; return worlddata.x;
} }

View file

@ -1,6 +1,6 @@
--- ../work/decompile-8eb82bde//net/minecraft/server/WorldServer.java 2015-01-04 19:54:26.537675427 +0000 --- ../work/decompile-8eb82bde/net/minecraft/server/WorldServer.java 2015-01-05 09:50:02.053188213 +1100
+++ src/main/java/net/minecraft/server/WorldServer.java 2015-01-04 19:54:26.541675427 +0000 +++ src/main/java/net/minecraft/server/WorldServer.java 2015-01-05 09:50:02.057188206 +1100
@@ -16,6 +16,20 @@ @@ -16,6 +16,18 @@
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
@ -14,14 +14,12 @@
+ +
+import org.bukkit.event.block.BlockFormEvent; +import org.bukkit.event.block.BlockFormEvent;
+import org.bukkit.event.weather.LightningStrikeEvent; +import org.bukkit.event.weather.LightningStrikeEvent;
+import org.bukkit.event.weather.ThunderChangeEvent;
+import org.bukkit.event.weather.WeatherChangeEvent;
+// CraftBukkit end +// CraftBukkit end
+ +
public class WorldServer extends World implements IAsyncTaskHandler { public class WorldServer extends World implements IAsyncTaskHandler {
private static final Logger a = LogManager.getLogger(); private static final Logger a = LogManager.getLogger();
@@ -37,14 +51,21 @@ @@ -37,14 +49,21 @@
private static final List U = Lists.newArrayList(new StructurePieceTreasure[] { new StructurePieceTreasure(Items.STICK, 0, 1, 3, 10), new StructurePieceTreasure(Item.getItemOf(Blocks.PLANKS), 0, 1, 3, 10), new StructurePieceTreasure(Item.getItemOf(Blocks.LOG), 0, 1, 3, 10), new StructurePieceTreasure(Items.STONE_AXE, 0, 1, 1, 3), new StructurePieceTreasure(Items.WOODEN_AXE, 0, 1, 1, 5), new StructurePieceTreasure(Items.STONE_PICKAXE, 0, 1, 1, 3), new StructurePieceTreasure(Items.WOODEN_PICKAXE, 0, 1, 1, 5), new StructurePieceTreasure(Items.APPLE, 0, 2, 3, 5), new StructurePieceTreasure(Items.BREAD, 0, 2, 3, 3), new StructurePieceTreasure(Item.getItemOf(Blocks.LOG2), 0, 1, 3, 10)}); private static final List U = Lists.newArrayList(new StructurePieceTreasure[] { new StructurePieceTreasure(Items.STICK, 0, 1, 3, 10), new StructurePieceTreasure(Item.getItemOf(Blocks.PLANKS), 0, 1, 3, 10), new StructurePieceTreasure(Item.getItemOf(Blocks.LOG), 0, 1, 3, 10), new StructurePieceTreasure(Items.STONE_AXE, 0, 1, 1, 3), new StructurePieceTreasure(Items.WOODEN_AXE, 0, 1, 1, 5), new StructurePieceTreasure(Items.STONE_PICKAXE, 0, 1, 1, 3), new StructurePieceTreasure(Items.WOODEN_PICKAXE, 0, 1, 1, 5), new StructurePieceTreasure(Items.APPLE, 0, 2, 3, 5), new StructurePieceTreasure(Items.BREAD, 0, 2, 3, 3), new StructurePieceTreasure(Item.getItemOf(Blocks.LOG2), 0, 1, 3, 10)});
private List V = Lists.newArrayList(); private List V = Lists.newArrayList();
@ -46,7 +44,7 @@
this.B(); this.B();
this.C(); this.C();
this.af().a(minecraftserver.aG()); this.af().a(minecraftserver.aG());
@@ -86,6 +107,89 @@ @@ -86,6 +105,89 @@
return this; return this;
} }
@ -136,7 +134,7 @@
public void doTick() { public void doTick() {
super.doTick(); super.doTick();
@@ -105,8 +209,11 @@ @@ -105,8 +207,11 @@
} }
this.methodProfiler.a("mobSpawner"); this.methodProfiler.a("mobSpawner");
@ -150,7 +148,7 @@
} }
this.methodProfiler.c("chunkSource"); this.methodProfiler.c("chunkSource");
@@ -135,6 +242,8 @@ @@ -135,6 +240,8 @@
this.Q.a(this.getTime()); this.Q.a(this.getTime());
this.methodProfiler.b(); this.methodProfiler.b();
this.ak(); this.ak();
@ -159,7 +157,7 @@
} }
public BiomeMeta a(EnumCreatureType enumcreaturetype, BlockPosition blockposition) { public BiomeMeta a(EnumCreatureType enumcreaturetype, BlockPosition blockposition) {
@@ -161,7 +270,7 @@ @@ -161,7 +268,7 @@
if (entityhuman.v()) { if (entityhuman.v()) {
++i; ++i;
@ -168,27 +166,26 @@
++j; ++j;
} }
} }
@@ -187,26 +296,45 @@ @@ -187,26 +294,46 @@
} }
private void ag() { private void ag() {
- this.worldData.setWeatherDuration(0); - this.worldData.setWeatherDuration(0);
- this.worldData.setStorm(false); this.worldData.setStorm(false);
- this.worldData.setThunderDuration(0); - this.worldData.setThunderDuration(0);
- this.worldData.setThundering(false);
+ // CraftBukkit start + // CraftBukkit start
+ WeatherChangeEvent weather = new WeatherChangeEvent(this.getWorld(), false); + // If we stop due to everyone sleeping we should reset the weather duration to some other random value.
+ this.getServer().getPluginManager().callEvent(weather); + // Not that everyone ever manages to get the whole server to sleep at the same time....
+ + if (!this.worldData.hasStorm()) {
+ ThunderChangeEvent thunder = new ThunderChangeEvent(this.getWorld(), false);
+ this.getServer().getPluginManager().callEvent(thunder);
+ if (!weather.isCancelled()) {
+ this.worldData.setWeatherDuration(0); + this.worldData.setWeatherDuration(0);
+ this.worldData.setStorm(false);
+ } + }
+ if (!thunder.isCancelled()) { + // CraftBukkit end
this.worldData.setThundering(false);
+ // 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....
+ if (!this.worldData.isThundering()) {
+ this.worldData.setThunderDuration(0); + this.worldData.setThunderDuration(0);
+ this.worldData.setThundering(false);
+ } + }
+ // CraftBukkit end + // CraftBukkit end
} }
@ -221,7 +218,7 @@
return false; return false;
} else { } else {
return false; return false;
@@ -227,15 +355,22 @@ @@ -227,15 +354,22 @@
} else { } else {
int i = 0; int i = 0;
int j = 0; int j = 0;
@ -252,7 +249,7 @@
this.a(k, l, chunk); this.a(k, l, chunk);
this.methodProfiler.c("tickChunk"); this.methodProfiler.c("tickChunk");
chunk.b(false); chunk.b(false);
@@ -260,11 +395,29 @@ @@ -260,11 +394,29 @@
BlockPosition blockposition1 = blockposition.down(); BlockPosition blockposition1 = blockposition.down();
if (this.w(blockposition1)) { if (this.w(blockposition1)) {
@ -284,7 +281,7 @@
} }
if (this.S() && this.getBiome(blockposition1).e()) { if (this.S() && this.getBiome(blockposition1).e()) {
@@ -376,7 +529,7 @@ @@ -376,7 +528,7 @@
} }
public void tickEntities() { public void tickEntities() {
@ -293,7 +290,7 @@
if (this.emptyTime++ >= 1200) { if (this.emptyTime++ >= 1200) {
return; return;
} }
@@ -401,7 +554,13 @@ @@ -401,7 +553,13 @@
throw new IllegalStateException("TickNextTick list out of synch"); throw new IllegalStateException("TickNextTick list out of synch");
} else { } else {
if (i > 1000) { if (i > 1000) {
@ -308,7 +305,7 @@
} }
this.methodProfiler.a("cleaning"); this.methodProfiler.a("cleaning");
@@ -501,6 +660,7 @@ @@ -501,6 +659,7 @@
return arraylist; return arraylist;
} }
@ -316,7 +313,7 @@
public void entityJoinedWorld(Entity entity, boolean flag) { public void entityJoinedWorld(Entity entity, boolean flag) {
if (!this.getSpawnAnimals() && (entity instanceof EntityAnimal || entity instanceof EntityWaterAnimal)) { if (!this.getSpawnAnimals() && (entity instanceof EntityAnimal || entity instanceof EntityWaterAnimal)) {
entity.die(); entity.die();
@@ -511,7 +671,9 @@ @@ -511,7 +670,9 @@
} }
super.entityJoinedWorld(entity, flag); super.entityJoinedWorld(entity, flag);
@ -326,7 +323,7 @@
private boolean getSpawnNPCs() { private boolean getSpawnNPCs() {
return this.server.getSpawnNPCs(); return this.server.getSpawnNPCs();
@@ -523,14 +685,44 @@ @@ -523,14 +684,44 @@
protected IChunkProvider k() { protected IChunkProvider k() {
IChunkLoader ichunkloader = this.dataManager.createChunkLoader(this.worldProvider); IChunkLoader ichunkloader = this.dataManager.createChunkLoader(this.worldProvider);
@ -373,7 +370,7 @@
for (int k1 = 0; k1 < this.h.size(); ++k1) { for (int k1 = 0; k1 < this.h.size(); ++k1) {
TileEntity tileentity = (TileEntity) this.h.get(k1); TileEntity tileentity = (TileEntity) this.h.get(k1);
BlockPosition blockposition = tileentity.getPosition(); BlockPosition blockposition = tileentity.getPosition();
@@ -539,6 +731,8 @@ @@ -539,6 +730,8 @@
arraylist.add(tileentity); arraylist.add(tileentity);
} }
} }
@ -382,7 +379,7 @@
return arraylist; return arraylist;
} }
@@ -601,6 +795,23 @@ @@ -601,6 +794,23 @@
int i = 0; int i = 0;
int j = this.worldProvider.getSeaLevel(); int j = this.worldProvider.getSeaLevel();
int k = 0; int k = 0;
@ -406,7 +403,7 @@
if (blockposition != null) { if (blockposition != null) {
i = blockposition.getX(); i = blockposition.getX();
@@ -611,7 +822,7 @@ @@ -611,7 +821,7 @@
int l = 0; int l = 0;
@ -415,7 +412,7 @@
i += random.nextInt(64) - random.nextInt(64); i += random.nextInt(64) - random.nextInt(64);
k += random.nextInt(64) - random.nextInt(64); k += random.nextInt(64) - random.nextInt(64);
++l; ++l;
@@ -648,8 +859,9 @@ @@ -648,8 +858,9 @@
return this.worldProvider.h(); return this.worldProvider.h();
} }
@ -426,7 +423,7 @@
if (iprogressupdate != null) { if (iprogressupdate != null) {
iprogressupdate.a("Saving level"); iprogressupdate.a("Saving level");
} }
@@ -660,7 +872,8 @@ @@ -660,7 +871,8 @@
} }
this.chunkProvider.saveChunks(flag, iprogressupdate); this.chunkProvider.saveChunks(flag, iprogressupdate);
@ -436,7 +433,7 @@
Iterator iterator = list.iterator(); Iterator iterator = list.iterator();
while (iterator.hasNext()) { while (iterator.hasNext()) {
@@ -680,7 +893,7 @@ @@ -680,7 +892,7 @@
} }
} }
@ -445,7 +442,7 @@
this.checkSession(); this.checkSession();
this.worldData.a(this.af().h()); this.worldData.a(this.af().h());
this.worldData.d(this.af().f()); this.worldData.d(this.af().f());
@@ -691,8 +904,12 @@ @@ -691,8 +903,12 @@
this.worldData.k(this.af().p()); this.worldData.k(this.af().p());
this.worldData.b(this.af().j()); this.worldData.b(this.af().j());
this.worldData.e(this.af().i()); this.worldData.e(this.af().i());
@ -459,7 +456,7 @@
} }
protected void a(Entity entity) { protected void a(Entity entity) {
@@ -724,8 +941,16 @@ @@ -724,8 +940,16 @@
} }
public boolean strikeLightning(Entity entity) { public boolean strikeLightning(Entity entity) {
@ -477,7 +474,7 @@
return true; return true;
} else { } else {
return false; return false;
@@ -737,10 +962,20 @@ @@ -737,10 +961,20 @@
} }
public Explosion createExplosion(Entity entity, double d0, double d1, double d2, float f, boolean flag, boolean flag1) { public Explosion createExplosion(Entity entity, double d0, double d1, double d2, float f, boolean flag, boolean flag1) {
@ -498,7 +495,7 @@
if (!flag1) { if (!flag1) {
explosion.clearBlocks(); explosion.clearBlocks();
} }
@@ -786,7 +1021,8 @@ @@ -786,7 +1020,8 @@
BlockActionData blockactiondata = (BlockActionData) iterator.next(); BlockActionData blockactiondata = (BlockActionData) iterator.next();
if (this.a(blockactiondata)) { if (this.a(blockactiondata)) {
@ -508,7 +505,7 @@
} }
} }
@@ -809,6 +1045,7 @@ @@ -809,6 +1044,7 @@
boolean flag = this.S(); boolean flag = this.S();
super.p(); super.p();
@ -516,7 +513,7 @@
if (this.o != this.p) { if (this.o != this.p) {
this.server.getPlayerList().a(new PacketPlayOutGameStateChange(7, this.p), this.worldProvider.getDimension()); this.server.getPlayerList().a(new PacketPlayOutGameStateChange(7, this.p), this.worldProvider.getDimension());
} }
@@ -827,7 +1064,21 @@ @@ -827,7 +1063,21 @@
this.server.getPlayerList().sendAll(new PacketPlayOutGameStateChange(7, this.p)); this.server.getPlayerList().sendAll(new PacketPlayOutGameStateChange(7, this.p));
this.server.getPlayerList().sendAll(new PacketPlayOutGameStateChange(8, this.r)); this.server.getPlayerList().sendAll(new PacketPlayOutGameStateChange(8, this.r));
} }
@ -539,7 +536,7 @@
} }
protected int q() { protected int q() {
@@ -855,10 +1106,17 @@ @@ -855,10 +1105,17 @@
} }
public void a(EnumParticle enumparticle, boolean flag, double d0, double d1, double d2, int i, double d3, double d4, double d5, double d6, int... aint) { public void a(EnumParticle enumparticle, boolean flag, double d0, double d1, double d2, int i, double d3, double d4, double d5, double d6, int... aint) {