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.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);
// 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;
// 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,9 +1493,15 @@ public class World implements IBlockAccess {
--i;
this.worldData.b(i);
if (i <= 0) {
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());
}
}
}
int j = this.worldData.m();
@ -1506,9 +1515,15 @@ public class World implements IBlockAccess {
--j;
this.worldData.c(j);
if (j <= 0) {
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());
}
}
}
this.B = this.C;
if (this.worldData.l()) {
@ -1543,11 +1558,24 @@ public class World implements IBlockAccess {
}
private void y() {
// 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() {
this.M.clear();

View File

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

View File

@ -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;
@ -554,6 +556,11 @@ public class CraftWorld implements World {
}
public void setStorm(boolean hasStorm) {
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
@ -563,6 +570,7 @@ public class CraftWorld implements World {
setWeatherDuration(rand.nextInt(168000) + 12000);
}
}
}
public int getWeatherDuration() {
return world.worldData.m();
@ -577,6 +585,11 @@ public class CraftWorld implements World {
}
public void setThundering(boolean thundering) {
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
@ -586,6 +599,7 @@ public class CraftWorld implements World {
setThunderDuration(rand.nextInt(168000) + 12000);
}
}
}
public int getThunderDuration() {
return world.worldData.k();

View File

@ -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) {
CreeperPowerEvent event = new CreeperPowerEvent(entity, CreeperPowerEvent.PowerCause.SET_ON);
server.getPluginManager().callEvent(event);
if (!event.isCancelled()) {
getHandle().W().b(17, (byte)1);
}
} else {
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;
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 {