diff --git a/src/main/java/net/minecraft/server/EntityChicken.java b/src/main/java/net/minecraft/server/EntityChicken.java index e8797157ea..2cd588026f 100644 --- a/src/main/java/net/minecraft/server/EntityChicken.java +++ b/src/main/java/net/minecraft/server/EntityChicken.java @@ -2,10 +2,7 @@ package net.minecraft.server; // CraftBukkit start import java.util.List; - -import org.bukkit.Location; -import org.bukkit.craftbukkit.entity.CraftEntity; -import org.bukkit.event.entity.EntityDeathEvent; +import org.bukkit.craftbukkit.event.CraftEventFactory; // CraftBukkit end public class EntityChicken extends EntityAnimal { @@ -92,14 +89,7 @@ public class EntityChicken extends EntityAnimal { loot.add(new org.bukkit.inventory.ItemStack(this.fireTicks > 0 ? Item.COOKED_CHICKEN.id : Item.RAW_CHICKEN.id, 1)); } - CraftEntity entity = (CraftEntity) this.getBukkitEntity(); - EntityDeathEvent event = new EntityDeathEvent(entity, loot); - org.bukkit.World bworld = this.world.getWorld(); - this.world.getServer().getPluginManager().callEvent(event); - - for (org.bukkit.inventory.ItemStack stack: event.getDrops()) { - bworld.dropItemNaturally(entity.getLocation(), stack); - } + CraftEventFactory.callEntityDeathEvent(this, loot); // CraftBukkit end } } diff --git a/src/main/java/net/minecraft/server/EntityCow.java b/src/main/java/net/minecraft/server/EntityCow.java index 84cc8e5909..41e67767c7 100644 --- a/src/main/java/net/minecraft/server/EntityCow.java +++ b/src/main/java/net/minecraft/server/EntityCow.java @@ -62,14 +62,7 @@ public class EntityCow extends EntityAnimal { loot.add(new org.bukkit.inventory.ItemStack(this.fireTicks > 0 ? Item.COOKED_BEEF.id : Item.RAW_BEEF.id, count)); } - CraftEntity entity = (CraftEntity) this.getBukkitEntity(); - EntityDeathEvent event = new EntityDeathEvent(entity, loot); - org.bukkit.World bworld = this.world.getWorld(); - this.world.getServer().getPluginManager().callEvent(event); - - for (org.bukkit.inventory.ItemStack stack: event.getDrops()) { - bworld.dropItemNaturally(entity.getLocation(), stack); - } + CraftEventFactory.callEntityDeathEvent(this, loot); // CraftBukkit end } diff --git a/src/main/java/net/minecraft/server/EntityEnderman.java b/src/main/java/net/minecraft/server/EntityEnderman.java index 75417bae3f..85a7a609c3 100644 --- a/src/main/java/net/minecraft/server/EntityEnderman.java +++ b/src/main/java/net/minecraft/server/EntityEnderman.java @@ -4,10 +4,9 @@ package net.minecraft.server; import java.util.List; import org.bukkit.Location; -import org.bukkit.craftbukkit.entity.CraftEntity; +import org.bukkit.craftbukkit.event.CraftEventFactory; import org.bukkit.event.entity.EndermanPickupEvent; import org.bukkit.event.entity.EndermanPlaceEvent; -import org.bukkit.event.entity.EntityDeathEvent; // CraftBukkit end public class EntityEnderman extends EntityMonster { @@ -276,14 +275,7 @@ public class EntityEnderman extends EntityMonster { loot.add(new org.bukkit.inventory.ItemStack(i, count)); } - CraftEntity entity = (CraftEntity) this.getBukkitEntity(); - EntityDeathEvent event = new EntityDeathEvent(entity, loot); - org.bukkit.World bworld = this.world.getWorld(); - this.world.getServer().getPluginManager().callEvent(event); - - for (org.bukkit.inventory.ItemStack stack: event.getDrops()) { - bworld.dropItemNaturally(entity.getLocation(), stack); - } + CraftEventFactory.callEntityDeathEvent(this, loot); // CraftBukkit end } diff --git a/src/main/java/net/minecraft/server/EntityLiving.java b/src/main/java/net/minecraft/server/EntityLiving.java index 23d8193539..533638d832 100644 --- a/src/main/java/net/minecraft/server/EntityLiving.java +++ b/src/main/java/net/minecraft/server/EntityLiving.java @@ -6,11 +6,10 @@ import java.util.Iterator; import java.util.List; // CraftBukkit start -import org.bukkit.craftbukkit.entity.CraftEntity; import org.bukkit.craftbukkit.TrigMath; +import org.bukkit.craftbukkit.event.CraftEventFactory; import org.bukkit.event.entity.EntityDamageByBlockEvent; import org.bukkit.event.entity.EntityDamageEvent; -import org.bukkit.event.entity.EntityDeathEvent; import org.bukkit.event.entity.EntityRegainHealthEvent; import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason; // CraftBukkit end @@ -78,6 +77,7 @@ public abstract class EntityLiving extends Entity { protected float aU = 0.7F; private Entity d; protected int aV = 0; + public int expToDrop = 0; // CraftBukkit added public EntityLiving(World world) { super(world); @@ -188,8 +188,9 @@ public abstract class EntityLiving extends Entity { if (this.health <= 0) { ++this.deathTicks; if (this.deathTicks > 20) { - if (this.c > 0 || this.X()) { - i = this.a(this.b); + // CraftBukkit start - update getExpReward() below if this changes! + if (expToDrop > 0) { + i = expToDrop; while (i > 0) { int j = EntityExperienceOrb.b(i); @@ -198,6 +199,7 @@ public abstract class EntityLiving extends Entity { this.world.addEntity(new EntityExperienceOrb(this.world, this.locX, this.locY, this.locZ, j)); } } + // CraftBukkit end this.ag(); this.die(); @@ -229,6 +231,18 @@ public abstract class EntityLiving extends Entity { return this.ax; } + // CraftBukkit start + public int getExpReward() { + int exp = a(this.b); + + if (this.c > 0 || this.X()) { + return exp; + } else { + return 0; + } + } + // CraftBukkit end + protected boolean X() { return false; } @@ -528,14 +542,7 @@ public abstract class EntityLiving extends Entity { loot.add(new org.bukkit.inventory.ItemStack(i, count)); } - CraftEntity entity = (CraftEntity) this.getBukkitEntity(); - EntityDeathEvent event = new EntityDeathEvent(entity, loot); - org.bukkit.World bworld = this.world.getWorld(); - this.world.getServer().getPluginManager().callEvent(event); - - for (org.bukkit.inventory.ItemStack stack: event.getDrops()) { - bworld.dropItemNaturally(entity.getLocation(), stack); - } + CraftEventFactory.callEntityDeathEvent(this, loot); // CraftBukkit end } diff --git a/src/main/java/net/minecraft/server/EntityPlayer.java b/src/main/java/net/minecraft/server/EntityPlayer.java index b5c902708d..799aae6484 100644 --- a/src/main/java/net/minecraft/server/EntityPlayer.java +++ b/src/main/java/net/minecraft/server/EntityPlayer.java @@ -9,8 +9,8 @@ import java.util.Set; import org.bukkit.Bukkit; import org.bukkit.craftbukkit.ChunkCompressionThread; import org.bukkit.craftbukkit.CraftWorld; +import org.bukkit.craftbukkit.event.CraftEventFactory; import org.bukkit.craftbukkit.inventory.CraftItemStack; -import org.bukkit.event.entity.EntityDeathEvent; import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason; // CraftBukkit end @@ -60,6 +60,7 @@ public class EntityPlayer extends EntityHuman implements ICrafting { public String displayName; public org.bukkit.Location compassTarget; + public int newExp = 0; // CraftBukkit end public void a(NBTTagCompound nbttagcompound) { @@ -154,11 +155,7 @@ public class EntityPlayer extends EntityHuman implements ICrafting { } } - org.bukkit.entity.Entity bukkitEntity = this.getBukkitEntity(); - CraftWorld bworld = this.world.getWorld(); - - EntityDeathEvent event = new EntityDeathEvent(bukkitEntity, loot); - this.world.getServer().getPluginManager().callEvent(event); + CraftEventFactory.callPlayerDeathEvent(this, loot); // CraftBukkit - we clean the player's inventory after the EntityDeathEvent is called so plugins can get the exact state of the inventory. for (int i = 0; i < this.inventory.items.length; ++i) { @@ -169,10 +166,6 @@ public class EntityPlayer extends EntityHuman implements ICrafting { this.inventory.armor[i] = null; } - for (org.bukkit.inventory.ItemStack stack: event.getDrops()) { - bworld.dropItemNaturally(bukkitEntity.getLocation(), stack); - } - this.x(); // CraftBukkit end } diff --git a/src/main/java/net/minecraft/server/EntitySheep.java b/src/main/java/net/minecraft/server/EntitySheep.java index f619288e24..f32ecb2ace 100644 --- a/src/main/java/net/minecraft/server/EntitySheep.java +++ b/src/main/java/net/minecraft/server/EntitySheep.java @@ -1,6 +1,7 @@ package net.minecraft.server; import java.util.Random; +import org.bukkit.craftbukkit.event.CraftEventFactory; public class EntitySheep extends EntityAnimal { @@ -25,15 +26,7 @@ public class EntitySheep extends EntityAnimal { loot.add(new org.bukkit.inventory.ItemStack(org.bukkit.Material.WOOL, 1, (short) 0, (byte) this.getColor())); } - org.bukkit.World bworld = this.world.getWorld(); - org.bukkit.entity.Entity entity = this.getBukkitEntity(); - - org.bukkit.event.entity.EntityDeathEvent event = new org.bukkit.event.entity.EntityDeathEvent(entity, loot); - this.world.getServer().getPluginManager().callEvent(event); - - for (org.bukkit.inventory.ItemStack stack: event.getDrops()) { - bworld.dropItemNaturally(entity.getLocation(), stack); - } + CraftEventFactory.callEntityDeathEvent(this, loot); // CraftBukkit end } diff --git a/src/main/java/net/minecraft/server/EntitySquid.java b/src/main/java/net/minecraft/server/EntitySquid.java index d9eed62b9f..f43967011c 100644 --- a/src/main/java/net/minecraft/server/EntitySquid.java +++ b/src/main/java/net/minecraft/server/EntitySquid.java @@ -1,6 +1,6 @@ package net.minecraft.server; -import org.bukkit.event.entity.EntityDeathEvent; // CraftBukkit +import org.bukkit.craftbukkit.event.CraftEventFactory; // CraftBukkit public class EntitySquid extends EntityWaterAnimal { @@ -63,15 +63,7 @@ public class EntitySquid extends EntityWaterAnimal { loot.add(new org.bukkit.inventory.ItemStack(org.bukkit.Material.INK_SACK, count)); } - org.bukkit.World bworld = this.world.getWorld(); - org.bukkit.entity.Entity entity = this.getBukkitEntity(); - - EntityDeathEvent event = new EntityDeathEvent(entity, loot); - this.world.getServer().getPluginManager().callEvent(event); - - for (org.bukkit.inventory.ItemStack stack : event.getDrops()) { - bworld.dropItemNaturally(entity.getLocation(), stack); - } + CraftEventFactory.callEntityDeathEvent(this, loot); // CraftBukkit end } diff --git a/src/main/java/net/minecraft/server/ServerConfigurationManager.java b/src/main/java/net/minecraft/server/ServerConfigurationManager.java index 8272595d5a..1a78fa3bf0 100644 --- a/src/main/java/net/minecraft/server/ServerConfigurationManager.java +++ b/src/main/java/net/minecraft/server/ServerConfigurationManager.java @@ -252,6 +252,10 @@ public class ServerConfigurationManager { entityplayer.fireTicks = 0; entityplayer.fallDistance = 0; entityplayer.foodData = new FoodMetaData(); + entityplayer.expTotal = 0; + entityplayer.exp = 0; + entityplayer.expLevel = 0; + entityplayer.d(entityplayer.newExp); } else { location.setWorld(this.server.getWorldServer(i).getWorld()); } diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java index 81d063cc2d..0082526cb5 100644 --- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java +++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java @@ -1,5 +1,6 @@ package org.bukkit.craftbukkit.event; +import java.util.List; import net.minecraft.server.ChunkCoordinates; import net.minecraft.server.EntityCaveSpider; import net.minecraft.server.EntityChicken; @@ -14,6 +15,7 @@ import net.minecraft.server.EntityLiving; import net.minecraft.server.EntityMonster; import net.minecraft.server.EntityPig; import net.minecraft.server.EntityPigZombie; +import net.minecraft.server.EntityPlayer; import net.minecraft.server.EntitySheep; import net.minecraft.server.EntitySilverfish; import net.minecraft.server.EntitySkeleton; @@ -35,6 +37,8 @@ import org.bukkit.block.BlockState; import org.bukkit.craftbukkit.CraftServer; import org.bukkit.craftbukkit.CraftWorld; import org.bukkit.craftbukkit.block.CraftBlock; +import org.bukkit.craftbukkit.entity.CraftLivingEntity; +import org.bukkit.craftbukkit.entity.CraftPlayer; import org.bukkit.craftbukkit.inventory.CraftItemStack; import org.bukkit.entity.AnimalTamer; import org.bukkit.entity.CreatureType; @@ -273,4 +277,35 @@ public class CraftEventFactory { Bukkit.getPluginManager().callEvent(event); return event; } + + public static EntityDeathEvent callEntityDeathEvent(EntityLiving victim, List drops) { + CraftLivingEntity entity = (CraftLivingEntity)victim.getBukkitEntity(); + EntityDeathEvent event = new EntityDeathEvent(entity, drops, victim.getExpReward()); + org.bukkit.World world = entity.getWorld(); + Bukkit.getServer().getPluginManager().callEvent(event); + + victim.expToDrop = event.getDroppedExp(); + + for (org.bukkit.inventory.ItemStack stack: event.getDrops()) { + world.dropItemNaturally(entity.getLocation(), stack); + } + + return event; + } + + public static PlayerDeathEvent callPlayerDeathEvent(EntityPlayer victim, List drops) { + CraftPlayer entity = (CraftPlayer)victim.getBukkitEntity(); + PlayerDeathEvent event = new PlayerDeathEvent(entity, drops, victim.getExpReward(), 0); + org.bukkit.World world = entity.getWorld(); + Bukkit.getServer().getPluginManager().callEvent(event); + + victim.expToDrop = event.getDroppedExp(); + victim.newExp = event.getNewExp(); + + for (org.bukkit.inventory.ItemStack stack: event.getDrops()) { + world.dropItemNaturally(entity.getLocation(), stack); + } + + return event; + } }