Added events related to weather in 1.5. Thanks wizjany!

This commit is contained in:
EvilSeph 2011-04-25 19:47:25 -04:00
parent 1d0a6d56b7
commit d2a4c510b3
7 changed files with 206 additions and 32 deletions

View File

@ -4,6 +4,7 @@ package net.minecraft.server;
import org.bukkit.craftbukkit.CraftServer; import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.entity.CraftEntity; import org.bukkit.craftbukkit.entity.CraftEntity;
import org.bukkit.event.entity.ExplosionPrimeEvent; import org.bukkit.event.entity.ExplosionPrimeEvent;
import org.bukkit.event.entity.CreeperPowerEvent;
// CraftBukkit end // CraftBukkit end
public class EntityCreeper extends EntityMonster { public class EntityCreeper extends EntityMonster {
@ -125,6 +126,16 @@ public class EntityCreeper extends EntityMonster {
public void a(EntityWeatherStorm entityweatherstorm) { public void a(EntityWeatherStorm entityweatherstorm) {
super.a(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
} }
} }

View File

@ -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);
}
}
}

View File

@ -9,11 +9,14 @@ import java.util.Set;
import java.util.TreeSet; import java.util.TreeSet;
// CraftBukkit start // CraftBukkit start
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.CraftWorld; import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.craftbukkit.event.CraftEventFactory; import org.bukkit.craftbukkit.event.CraftEventFactory;
import org.bukkit.event.block.BlockCanBuildEvent; import org.bukkit.event.block.BlockCanBuildEvent;
import org.bukkit.event.block.BlockPhysicsEvent; import org.bukkit.event.block.BlockPhysicsEvent;
import org.bukkit.event.entity.CreatureSpawnEvent; import org.bukkit.event.entity.CreatureSpawnEvent;
import org.bukkit.event.weather.WeatherChangeEvent;
import org.bukkit.event.weather.ThunderChangeEvent;
// CraftBukkit end // CraftBukkit end
public class World implements IBlockAccess { public class World implements IBlockAccess {
@ -1490,7 +1493,13 @@ public class World implements IBlockAccess {
--i; --i;
this.worldData.b(i); this.worldData.b(i);
if (i <= 0) { 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; --j;
this.worldData.c(j); this.worldData.c(j);
if (j <= 0) { 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() { private void y() {
this.worldData.c(0); // CraftBukkit start
this.worldData.b(false); CraftServer server = ((WorldServer) this).getServer();
this.worldData.b(0);
this.worldData.a(false); 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() { protected void j() {

View File

@ -7,6 +7,7 @@ import java.util.List;
import org.bukkit.BlockChangeDelegate; import org.bukkit.BlockChangeDelegate;
import org.bukkit.craftbukkit.CraftServer; import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.CraftWorld; import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.event.weather.LightningStrikeEvent;
public class WorldServer extends World implements BlockChangeDelegate { public class WorldServer extends World implements BlockChangeDelegate {
// CraftBukkit end // CraftBukkit end
@ -105,8 +106,15 @@ public class WorldServer extends World implements BlockChangeDelegate {
public boolean a(Entity entity) { public boolean a(Entity entity) {
if (super.a(entity)) { if (super.a(entity)) {
this.server.serverConfigurationManager.a(entity.locX, entity.locY, entity.locZ, 512.0D, new Packet71Weather(entity)); CraftServer server = cserver;
return true;
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 { } else {
return false; return false;
} }

View File

@ -11,6 +11,8 @@ import java.util.Random;
import net.minecraft.server.*; import net.minecraft.server.*;
import org.bukkit.entity.Arrow; 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.event.world.SpawnChangeEvent;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.entity.Boat; import org.bukkit.entity.Boat;
@ -121,16 +123,16 @@ public class CraftWorld implements World {
public boolean unloadChunk(int x, int z, boolean save) { public boolean unloadChunk(int x, int z, boolean save) {
return unloadChunk(x, z, save, false); return unloadChunk(x, z, save, false);
} }
public boolean unloadChunkRequest(int x, int z) { public boolean unloadChunkRequest(int x, int z) {
return unloadChunkRequest(x, z, true); return unloadChunkRequest(x, z, true);
} }
public boolean unloadChunkRequest(int x, int z, boolean safe) { public boolean unloadChunkRequest(int x, int z, boolean safe) {
if (safe && isChunkInUse(x, z)) { if (safe && isChunkInUse(x, z)) {
return false; return false;
} }
provider.queueUnload(x, z); provider.queueUnload(x, z);
return true; return true;
@ -554,13 +556,19 @@ public class CraftWorld implements World {
} }
public void setStorm(boolean hasStorm) { public void setStorm(boolean hasStorm) {
world.worldData.b(hasStorm); CraftServer server = world.getServer();
// These numbers are from Minecraft WeatherChangeEvent weather = new WeatherChangeEvent((org.bukkit.World) this, hasStorm);
if (hasStorm) { server.getPluginManager().callEvent(weather);
setWeatherDuration(rand.nextInt(12000) + 12000); if (!weather.isCancelled()) {
} else { world.worldData.b(hasStorm);
setWeatherDuration(rand.nextInt(168000) + 12000);
// 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) { public void setThundering(boolean thundering) {
world.worldData.a(thundering); CraftServer server = world.getServer();
// These numbers are from Minecraft ThunderChangeEvent thunder = new ThunderChangeEvent((org.bukkit.World) this, thundering);
if (thundering) { server.getPluginManager().callEvent(thunder);
setThunderDuration(rand.nextInt(12000) + 3600); if (!thunder.isCancelled()) {
} else { world.worldData.a(thundering);
setThunderDuration(rand.nextInt(168000) + 12000);
// These numbers are from Minecraft
if (thundering) {
setThunderDuration(rand.nextInt(12000) + 3600);
} else {
setThunderDuration(rand.nextInt(168000) + 12000);
}
} }
} }
public int getThunderDuration() { public int getThunderDuration() {
return world.worldData.k(); return world.worldData.k();
} }
public void setThunderDuration(int duration) { public void setThunderDuration(int duration) {
world.worldData.b(duration); world.worldData.b(duration);
} }
public long getSeed() { public long getSeed() {

View File

@ -1,8 +1,11 @@
package org.bukkit.craftbukkit.entity; package org.bukkit.craftbukkit.entity;
import net.minecraft.server.EntityCreeper; import net.minecraft.server.EntityCreeper;
import net.minecraft.server.WorldServer;
import org.bukkit.craftbukkit.CraftServer; import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.entity.Creeper; import org.bukkit.entity.Creeper;
import org.bukkit.event.entity.CreeperPowerEvent;
public class CraftCreeper extends CraftMonster implements Creeper { public class CraftCreeper extends CraftMonster implements Creeper {
@ -20,11 +23,28 @@ public class CraftCreeper extends CraftMonster implements Creeper {
} }
public void setPowered(boolean powered) { public void setPowered(boolean powered) {
// CraftBukkit start
CraftServer server = this.server;
org.bukkit.entity.Entity entity = this.getHandle().getBukkitEntity();
if (powered) { 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 { } 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
} }
} }

View File

@ -1,9 +1,7 @@
package org.bukkit.craftbukkit.entity; package org.bukkit.craftbukkit.entity;
import net.minecraft.server.EntityPig; import net.minecraft.server.EntityPig;
import org.bukkit.craftbukkit.CraftServer; import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.entity.CraftAnimals;
import org.bukkit.entity.Pig; import org.bukkit.entity.Pig;
public class CraftPig extends CraftAnimals implements Pig { public class CraftPig extends CraftAnimals implements Pig {