diff options
author | EvilSeph <evilseph@unaligned.org> | 2011-04-25 19:47:25 -0400 |
---|---|---|
committer | EvilSeph <evilseph@unaligned.org> | 2011-04-25 19:47:25 -0400 |
commit | d2a4c510b39bebfcaca328cb67ef6432bc9fd985 (patch) | |
tree | 8cc0aec1f0c9f79c2bd1260f31cee237c5122e6c | |
parent | 1d0a6d56b7169a2123256811fabe634fb43c58d8 (diff) | |
download | craftbukkit-d2a4c510b39bebfcaca328cb67ef6432bc9fd985.tar craftbukkit-d2a4c510b39bebfcaca328cb67ef6432bc9fd985.tar.gz craftbukkit-d2a4c510b39bebfcaca328cb67ef6432bc9fd985.tar.lz craftbukkit-d2a4c510b39bebfcaca328cb67ef6432bc9fd985.tar.xz craftbukkit-d2a4c510b39bebfcaca328cb67ef6432bc9fd985.zip |
Added events related to weather in 1.5. Thanks wizjany!
7 files changed, 206 insertions, 32 deletions
diff --git a/src/main/java/net/minecraft/server/EntityCreeper.java b/src/main/java/net/minecraft/server/EntityCreeper.java index e7c2bfe2..d42c4599 100644 --- a/src/main/java/net/minecraft/server/EntityCreeper.java +++ b/src/main/java/net/minecraft/server/EntityCreeper.java @@ -4,6 +4,7 @@ package net.minecraft.server; import org.bukkit.craftbukkit.CraftServer; import org.bukkit.craftbukkit.entity.CraftEntity; import org.bukkit.event.entity.ExplosionPrimeEvent; +import org.bukkit.event.entity.CreeperPowerEvent; // CraftBukkit end public class EntityCreeper extends EntityMonster { @@ -125,6 +126,16 @@ public class EntityCreeper extends EntityMonster { public void a(EntityWeatherStorm entityweatherstorm) { super.a(entityweatherstorm); - this.datawatcher.b(17, Byte.valueOf((byte) 1)); + // CraftBukkit start + CraftServer server = ((WorldServer) this.world).getServer(); + org.bukkit.entity.Entity entity = this.getBukkitEntity(); + + CreeperPowerEvent event = new CreeperPowerEvent(entity, entityweatherstorm.getBukkitEntity(), CreeperPowerEvent.PowerCause.LIGHTNING); + server.getPluginManager().callEvent(event); + + if (!event.isCancelled()) { + this.datawatcher.b(17, Byte.valueOf((byte) 1)); + } + // CraftBukkit end } } diff --git a/src/main/java/net/minecraft/server/EntityPig.java b/src/main/java/net/minecraft/server/EntityPig.java new file mode 100644 index 00000000..54d93869 --- /dev/null +++ b/src/main/java/net/minecraft/server/EntityPig.java @@ -0,0 +1,95 @@ +package net.minecraft.server; + +//CraftBukkit start +import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.craftbukkit.event.CraftEventFactory; +import org.bukkit.event.entity.EntityCombustEvent; +import org.bukkit.event.entity.PigZapEvent; +// CraftBukkit end + +public class EntityPig extends EntityAnimal { + + public EntityPig(World world) { + super(world); + this.texture = "/mob/pig.png"; + this.b(0.9F, 0.9F); + } + + protected void b() { + this.datawatcher.a(16, Byte.valueOf((byte) 0)); + } + + public void b(NBTTagCompound nbttagcompound) { + super.b(nbttagcompound); + nbttagcompound.a("Saddle", this.x()); + } + + public void a(NBTTagCompound nbttagcompound) { + super.a(nbttagcompound); + this.a(nbttagcompound.m("Saddle")); + } + + protected String g() { + return "mob.pig"; + } + + protected String h() { + return "mob.pig"; + } + + protected String i() { + return "mob.pigdeath"; + } + + public boolean a(EntityHuman entityhuman) { + if (this.x() && !this.world.isStatic + && (this.passenger == null || this.passenger == entityhuman)) { + entityhuman.mount(this); + return true; + } else { + return false; + } + } + + protected int j() { + return this.fireTicks > 0 ? Item.GRILLED_PORK.id : Item.PORK.id; + } + + public boolean x() { + return (this.datawatcher.a(16) & 1) != 0; + } + + public void a(boolean flag) { + if (flag) { + this.datawatcher.b(16, Byte.valueOf((byte) 1)); + } else { + this.datawatcher.b(16, Byte.valueOf((byte) 0)); + } + } + + public void a(EntityWeatherStorm entityweatherstorm) { + EntityPigZombie entitypigzombie = new EntityPigZombie(this.world); + entitypigzombie.setPositionRotation(this.locX, this.locY, this.locZ, + this.yaw, this.pitch); + + // CraftBukkit start + CraftServer server = ((WorldServer) this.world).getServer(); + org.bukkit.entity.Entity entity = this.getBukkitEntity(); + + PigZapEvent event = new PigZapEvent(entity, entityweatherstorm.getBukkitEntity(), entitypigzombie.getBukkitEntity()); + server.getPluginManager().callEvent(event); + + if (!event.isCancelled()) { + this.world.addEntity(entitypigzombie); + this.die(); + } + // CraftBukkit end + } + + protected void a(float f) { + super.a(f); + if (f > 5.0F && this.passenger instanceof EntityHuman) { + ((EntityHuman) this.passenger).a((Statistic) AchievementList.u); + } + } +} diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java index 598d5c2e..b5327cae 100644 --- a/src/main/java/net/minecraft/server/World.java +++ b/src/main/java/net/minecraft/server/World.java @@ -9,11 +9,14 @@ import java.util.Set; import java.util.TreeSet; // CraftBukkit start +import org.bukkit.craftbukkit.CraftServer; import org.bukkit.craftbukkit.CraftWorld; import org.bukkit.craftbukkit.event.CraftEventFactory; import org.bukkit.event.block.BlockCanBuildEvent; import org.bukkit.event.block.BlockPhysicsEvent; import org.bukkit.event.entity.CreatureSpawnEvent; +import org.bukkit.event.weather.WeatherChangeEvent; +import org.bukkit.event.weather.ThunderChangeEvent; // CraftBukkit end public class World implements IBlockAccess { @@ -1490,7 +1493,13 @@ public class World implements IBlockAccess { --i; this.worldData.b(i); if (i <= 0) { - this.worldData.a(!this.worldData.j()); + CraftServer server = ((WorldServer) this).getServer(); + + ThunderChangeEvent thunder = new ThunderChangeEvent(((WorldServer) this).getWorld(), !this.worldData.j()); + server.getPluginManager().callEvent(thunder); + if (!thunder.isCancelled()) { + this.worldData.a(!this.worldData.j()); + } } } @@ -1506,7 +1515,13 @@ public class World implements IBlockAccess { --j; this.worldData.c(j); if (j <= 0) { - this.worldData.b(!this.worldData.l()); + CraftServer server = ((WorldServer) this).getServer(); + + WeatherChangeEvent weather = new WeatherChangeEvent(((WorldServer) this).getWorld(), !this.worldData.l()); + server.getPluginManager().callEvent(weather); + if (!weather.isCancelled()) { + this.worldData.b(!this.worldData.l()); + } } } @@ -1543,10 +1558,23 @@ public class World implements IBlockAccess { } private void y() { - this.worldData.c(0); - this.worldData.b(false); - this.worldData.b(0); - this.worldData.a(false); + // CraftBukkit start + CraftServer server = ((WorldServer) this).getServer(); + + WeatherChangeEvent weather = new WeatherChangeEvent((org.bukkit.World) this, false); + server.getPluginManager().callEvent(weather); + + ThunderChangeEvent thunder = new ThunderChangeEvent((org.bukkit.World) this, false); + server.getPluginManager().callEvent(thunder); + if (!weather.isCancelled()) { + this.worldData.c(0); + this.worldData.b(false); + } + if (!thunder.isCancelled()) { + this.worldData.b(0); + this.worldData.a(false); + } + //CraftBukkit end } protected void j() { diff --git a/src/main/java/net/minecraft/server/WorldServer.java b/src/main/java/net/minecraft/server/WorldServer.java index 553108c5..e0c73c28 100644 --- a/src/main/java/net/minecraft/server/WorldServer.java +++ b/src/main/java/net/minecraft/server/WorldServer.java @@ -7,6 +7,7 @@ import java.util.List; import org.bukkit.BlockChangeDelegate; import org.bukkit.craftbukkit.CraftServer; import org.bukkit.craftbukkit.CraftWorld; +import org.bukkit.event.weather.LightningStrikeEvent; public class WorldServer extends World implements BlockChangeDelegate { // CraftBukkit end @@ -105,8 +106,15 @@ public class WorldServer extends World implements BlockChangeDelegate { public boolean a(Entity entity) { if (super.a(entity)) { - this.server.serverConfigurationManager.a(entity.locX, entity.locY, entity.locZ, 512.0D, new Packet71Weather(entity)); - return true; + CraftServer server = cserver; + + LightningStrikeEvent lightning = new LightningStrikeEvent((org.bukkit.World) world, entity.getBukkitEntity()); + server.getPluginManager().callEvent(lightning); + if (!lightning.isCancelled()) { + this.server.serverConfigurationManager.a(entity.locX, entity.locY, entity.locZ, 512.0D, new Packet71Weather(entity)); + return true; + } + return false; } else { return false; } diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java index 96895634..4c5fa33f 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java @@ -11,6 +11,8 @@ import java.util.Random; import net.minecraft.server.*; import org.bukkit.entity.Arrow; +import org.bukkit.event.weather.WeatherChangeEvent; +import org.bukkit.event.weather.ThunderChangeEvent; import org.bukkit.event.world.SpawnChangeEvent; import org.bukkit.block.Block; import org.bukkit.entity.Boat; @@ -121,16 +123,16 @@ public class CraftWorld implements World { public boolean unloadChunk(int x, int z, boolean save) { return unloadChunk(x, z, save, false); } - + public boolean unloadChunkRequest(int x, int z) { return unloadChunkRequest(x, z, true); } - + public boolean unloadChunkRequest(int x, int z, boolean safe) { if (safe && isChunkInUse(x, z)) { return false; } - + provider.queueUnload(x, z); return true; @@ -554,13 +556,19 @@ public class CraftWorld implements World { } public void setStorm(boolean hasStorm) { - world.worldData.b(hasStorm); - - // These numbers are from Minecraft - if (hasStorm) { - setWeatherDuration(rand.nextInt(12000) + 12000); - } else { - setWeatherDuration(rand.nextInt(168000) + 12000); + CraftServer server = world.getServer(); + + WeatherChangeEvent weather = new WeatherChangeEvent((org.bukkit.World) this, hasStorm); + server.getPluginManager().callEvent(weather); + if (!weather.isCancelled()) { + world.worldData.b(hasStorm); + + // These numbers are from Minecraft + if (hasStorm) { + setWeatherDuration(rand.nextInt(12000) + 12000); + } else { + setWeatherDuration(rand.nextInt(168000) + 12000); + } } } @@ -577,22 +585,28 @@ public class CraftWorld implements World { } public void setThundering(boolean thundering) { - world.worldData.a(thundering); - - // These numbers are from Minecraft - if (thundering) { - setThunderDuration(rand.nextInt(12000) + 3600); - } else { - setThunderDuration(rand.nextInt(168000) + 12000); + CraftServer server = world.getServer(); + + ThunderChangeEvent thunder = new ThunderChangeEvent((org.bukkit.World) this, thundering); + server.getPluginManager().callEvent(thunder); + if (!thunder.isCancelled()) { + world.worldData.a(thundering); + + // These numbers are from Minecraft + if (thundering) { + setThunderDuration(rand.nextInt(12000) + 3600); + } else { + setThunderDuration(rand.nextInt(168000) + 12000); + } } } - + public int getThunderDuration() { return world.worldData.k(); } public void setThunderDuration(int duration) { - world.worldData.b(duration); + world.worldData.b(duration); } public long getSeed() { diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftCreeper.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftCreeper.java index 2844723f..974bd859 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftCreeper.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftCreeper.java @@ -1,8 +1,11 @@ package org.bukkit.craftbukkit.entity; import net.minecraft.server.EntityCreeper; +import net.minecraft.server.WorldServer; + import org.bukkit.craftbukkit.CraftServer; import org.bukkit.entity.Creeper; +import org.bukkit.event.entity.CreeperPowerEvent; public class CraftCreeper extends CraftMonster implements Creeper { @@ -20,11 +23,28 @@ public class CraftCreeper extends CraftMonster implements Creeper { } public void setPowered(boolean powered) { + // CraftBukkit start + CraftServer server = this.server; + org.bukkit.entity.Entity entity = this.getHandle().getBukkitEntity(); + if (powered) { - getHandle().W().b(17, (byte)1); + CreeperPowerEvent event = new CreeperPowerEvent(entity, CreeperPowerEvent.PowerCause.SET_ON); + server.getPluginManager().callEvent(event); + + if (!event.isCancelled()) { + getHandle().W().b(17, (byte)1); + } } else { - getHandle().W().b(17, (byte)0); + CreeperPowerEvent event = new CreeperPowerEvent(entity, CreeperPowerEvent.PowerCause.SET_OFF); + server.getPluginManager().callEvent(event); + + if (!event.isCancelled()) { + getHandle().W().b(17, (byte)0); + } } + + // CraftBukkit end + } } diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPig.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPig.java index b92aa36c..a73d51f9 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPig.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPig.java @@ -1,9 +1,7 @@ package org.bukkit.craftbukkit.entity; import net.minecraft.server.EntityPig; - import org.bukkit.craftbukkit.CraftServer; -import org.bukkit.craftbukkit.entity.CraftAnimals; import org.bukkit.entity.Pig; public class CraftPig extends CraftAnimals implements Pig { |