summaryrefslogtreecommitdiffstats
path: root/src/main/java/net
diff options
context:
space:
mode:
authorDinnerbone <dinnerbone@dinnerbone.com>2011-09-21 15:41:24 +0100
committerDinnerbone <dinnerbone@dinnerbone.com>2011-09-21 15:41:24 +0100
commit20ddc944bb38b96ac5deb742126c53b9989b5c31 (patch)
treecf8cef5a55f609417a756d34a7b09034d48b69e9 /src/main/java/net
parent751ab82be07aec65151d7a0a76b90d8fc12974f6 (diff)
downloadcraftbukkit-20ddc944bb38b96ac5deb742126c53b9989b5c31.tar
craftbukkit-20ddc944bb38b96ac5deb742126c53b9989b5c31.tar.gz
craftbukkit-20ddc944bb38b96ac5deb742126c53b9989b5c31.tar.lz
craftbukkit-20ddc944bb38b96ac5deb742126c53b9989b5c31.tar.xz
craftbukkit-20ddc944bb38b96ac5deb742126c53b9989b5c31.zip
Refactored a bunch of death code into the event factory
Diffstat (limited to 'src/main/java/net')
-rw-r--r--src/main/java/net/minecraft/server/EntityChicken.java14
-rw-r--r--src/main/java/net/minecraft/server/EntityCow.java9
-rw-r--r--src/main/java/net/minecraft/server/EntityEnderman.java12
-rw-r--r--src/main/java/net/minecraft/server/EntityLiving.java31
-rw-r--r--src/main/java/net/minecraft/server/EntityPlayer.java13
-rw-r--r--src/main/java/net/minecraft/server/EntitySheep.java11
-rw-r--r--src/main/java/net/minecraft/server/EntitySquid.java12
-rw-r--r--src/main/java/net/minecraft/server/ServerConfigurationManager.java4
8 files changed, 35 insertions, 71 deletions
diff --git a/src/main/java/net/minecraft/server/EntityChicken.java b/src/main/java/net/minecraft/server/EntityChicken.java
index e8797157..2cd58802 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 84cc8e59..41e67767 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 75417bae..85a7a609 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 23d81935..533638d8 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 b5c90270..799aae64 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 f619288e..f32ecb2a 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 d9eed62b..f4396701 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 8272595d..1a78fa3b 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());
}