mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-28 05:25:42 +01:00
Refactored a bunch of death code into the event factory
This commit is contained in:
parent
751ab82be0
commit
20ddc944bb
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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());
|
||||
}
|
||||
|
@ -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<org.bukkit.inventory.ItemStack> 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<org.bukkit.inventory.ItemStack> 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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user