mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-28 23:38:25 +01:00
69ee95fa42
PaperMC believes that 1.16.2 is now ready for general release as we fixed the main issue plagueing the 1.16.x release, the MapLike data conversion issues. Until now, it was not safe for a server to convert a world to 1.16.2 without data conversion issues around villages and potentially other things. If you did, those MapLike errors meant something went wrong. This is now resolved. Big thanks to all those that helped, notably @BillyGalbreath and @Proximyst who did large parts of the update process with me. Please as always, backup your worlds and test before updating to 1.16.2! If you update to 1.16.2, there is no going back to an older build than this. --------------------------------- Co-authored-by: William Blake Galbreath <Blake.Galbreath@GMail.com> Co-authored-by: Mariell Hoversholm <proximyst@proximyst.com> Co-authored-by: krolik-exe <69214078+krolik-exe@users.noreply.github.com> Co-authored-by: BillyGalbreath <BillyGalbreath@users.noreply.github.com> Co-authored-by: stonar96 <minecraft.stonar96@gmail.com> Co-authored-by: Shane Freeder <theboyetronic@gmail.com> Co-authored-by: Jason Penilla <11360596+jpenilla@users.noreply.github.com> Co-authored-by: Riley Park <rileysebastianpark@gmail.com> Co-authored-by: Aurora <21148213+aurorasmiles@users.noreply.github.com> Co-authored-by: Nassim Jahnke <nassim@njahnke.dev> Co-authored-by: commandblockguy <commandblockguy1@gmail.com> Co-authored-by: DigitalRegent <misterwener@gmail.com> Co-authored-by: ishland <ishlandmc@yeah.net>
443 lines
22 KiB
Diff
443 lines
22 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Phoenix616 <mail@moep.tv>
|
|
Date: Tue, 21 Aug 2018 01:39:35 +0100
|
|
Subject: [PATCH] Improve death events
|
|
|
|
This adds the ability to cancel the death events and to modify the sound
|
|
an entity makes when dying. (In cases were no sound should it will be
|
|
called with shouldPlaySound set to false allowing unsilencing of silent
|
|
entities)
|
|
|
|
It makes handling of entity deaths a lot nicer as you no longer need
|
|
to listen on the damage event and calculate if the entity dies yourself
|
|
to cancel the death which has the benefit of also receiving the dropped
|
|
items and experience which is otherwise only properly possible by using
|
|
internal code.
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/CombatTracker.java b/src/main/java/net/minecraft/server/CombatTracker.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/net/minecraft/server/CombatTracker.java
|
|
+++ b/src/main/java/net/minecraft/server/CombatTracker.java
|
|
@@ -0,0 +0,0 @@ public class CombatTracker {
|
|
this.h = null;
|
|
}
|
|
|
|
+ public final void reset() { this.g(); } // Paper - OBFHELPER
|
|
public void g() {
|
|
int i = this.f ? 300 : 100;
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/net/minecraft/server/Entity.java
|
|
+++ b/src/main/java/net/minecraft/server/Entity.java
|
|
@@ -0,0 +0,0 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
|
|
}
|
|
// CraftBukkit end
|
|
|
|
+ public final void runKillTrigger(Entity entity, int kills, DamageSource damageSource) { this.a(entity, kills, damageSource); } // Paper - OBFHELPER
|
|
public void a(Entity entity, int i, DamageSource damagesource) {
|
|
if (entity instanceof EntityPlayer) {
|
|
CriterionTriggers.c.a((EntityPlayer) entity, this, damagesource);
|
|
@@ -0,0 +0,0 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, Ke
|
|
this.fallDistance = 0.0F;
|
|
}
|
|
|
|
+ public final void onKill(WorldServer worldserver, EntityLiving entityLiving) { this.a(worldserver, entityLiving); } // Paper - OBFHELPER
|
|
public void a(WorldServer worldserver, EntityLiving entityliving) {}
|
|
|
|
protected void l(double d0, double d1, double d2) {
|
|
diff --git a/src/main/java/net/minecraft/server/EntityArmorStand.java b/src/main/java/net/minecraft/server/EntityArmorStand.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/net/minecraft/server/EntityArmorStand.java
|
|
+++ b/src/main/java/net/minecraft/server/EntityArmorStand.java
|
|
@@ -0,0 +0,0 @@ public class EntityArmorStand extends EntityLiving {
|
|
|
|
@Override
|
|
public void killEntity() {
|
|
- org.bukkit.craftbukkit.event.CraftEventFactory.callEntityDeathEvent(this, drops); // CraftBukkit - call event
|
|
+ org.bukkit.event.entity.EntityDeathEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callEntityDeathEvent(this, drops); // CraftBukkit - call event // Paper - make cancellable
|
|
+ if (event.isCancelled()) return; // Paper - make cancellable
|
|
this.die();
|
|
}
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/EntityFox.java b/src/main/java/net/minecraft/server/EntityFox.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/net/minecraft/server/EntityFox.java
|
|
+++ b/src/main/java/net/minecraft/server/EntityFox.java
|
|
@@ -0,0 +0,0 @@ public class EntityFox extends EntityAnimal {
|
|
}
|
|
|
|
@Override
|
|
- protected void d(DamageSource damagesource) {
|
|
- ItemStack itemstack = this.getEquipment(EnumItemSlot.MAINHAND);
|
|
+ protected org.bukkit.event.entity.EntityDeathEvent d(DamageSource damagesource) { // Paper
|
|
+ ItemStack itemstack = this.getEquipment(EnumItemSlot.MAINHAND).cloneItemStack(); // Paper
|
|
+
|
|
+ // Paper start - Cancellable death event
|
|
+ org.bukkit.event.entity.EntityDeathEvent deathEvent = super.d(damagesource);
|
|
+
|
|
+ // Below is code to drop
|
|
+
|
|
+ if (deathEvent == null || deathEvent.isCancelled()) {
|
|
+ return deathEvent;
|
|
+ }
|
|
+ // Paper end
|
|
|
|
if (!itemstack.isEmpty()) {
|
|
this.a(itemstack);
|
|
this.setSlot(EnumItemSlot.MAINHAND, ItemStack.b);
|
|
}
|
|
|
|
- super.d(damagesource);
|
|
+ return deathEvent; // Paper
|
|
}
|
|
|
|
public static boolean a(EntityFox entityfox, EntityLiving entityliving) {
|
|
diff --git a/src/main/java/net/minecraft/server/EntityHorseChestedAbstract.java b/src/main/java/net/minecraft/server/EntityHorseChestedAbstract.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/net/minecraft/server/EntityHorseChestedAbstract.java
|
|
+++ b/src/main/java/net/minecraft/server/EntityHorseChestedAbstract.java
|
|
@@ -0,0 +0,0 @@ public abstract class EntityHorseChestedAbstract extends EntityHorseAbstract {
|
|
this.a((IMaterial) Blocks.CHEST);
|
|
}
|
|
|
|
- this.setCarryingChest(false);
|
|
+ //this.setCarryingChest(false); // Paper - moved to post death logic
|
|
}
|
|
|
|
}
|
|
|
|
+ // Paper start
|
|
+ protected void postDeathDropItems(org.bukkit.event.entity.EntityDeathEvent event) {
|
|
+ if (this.isCarryingChest() && (event == null || !event.isCancelled())) {
|
|
+ this.setCarryingChest(false);
|
|
+ }
|
|
+ }
|
|
+ // Paper end
|
|
+
|
|
@Override
|
|
public void saveData(NBTTagCompound nbttagcompound) {
|
|
super.saveData(nbttagcompound);
|
|
diff --git a/src/main/java/net/minecraft/server/EntityLiving.java b/src/main/java/net/minecraft/server/EntityLiving.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/net/minecraft/server/EntityLiving.java
|
|
+++ b/src/main/java/net/minecraft/server/EntityLiving.java
|
|
@@ -0,0 +0,0 @@ public abstract class EntityLiving extends Entity {
|
|
protected float aL;
|
|
protected float aM;
|
|
protected float aN;
|
|
- protected int aO;
|
|
+ protected int aO;protected int getKillCount() { return this.aO; } // Paper - OBFHELPER
|
|
public float lastDamage;
|
|
protected boolean jumping;
|
|
public float aR;
|
|
@@ -0,0 +0,0 @@ public abstract class EntityLiving extends Entity {
|
|
public Set<UUID> collidableExemptions = new HashSet<>();
|
|
public boolean canPickUpLoot;
|
|
public org.bukkit.craftbukkit.entity.CraftLivingEntity getBukkitLivingEntity() { return (org.bukkit.craftbukkit.entity.CraftLivingEntity) super.getBukkitEntity(); } // Paper
|
|
+ public boolean silentDeath = false; // Paper - mark entity as dying silently for cancellable death event
|
|
|
|
@Override
|
|
public float getBukkitYaw() {
|
|
@@ -0,0 +0,0 @@ public abstract class EntityLiving extends Entity {
|
|
if (knockbackCancelled) this.world.broadcastEntityEffect(this, (byte) 2); // Paper - Disable explosion knockback
|
|
if (this.dk()) {
|
|
if (!this.f(damagesource)) {
|
|
- SoundEffect soundeffect = this.getSoundDeath();
|
|
+ // Paper start - moved into CraftEventFactory event caller for cancellable death event
|
|
+ //SoundEffect soundeffect = this.getSoundDeath();
|
|
|
|
- if (flag1 && soundeffect != null) {
|
|
- this.playSound(soundeffect, this.getSoundVolume(), this.dG());
|
|
- }
|
|
+// if (flag1 && soundeffect != null) {
|
|
+// this.playSound(soundeffect, this.getSoundVolume(), this.dG());
|
|
+// }
|
|
+ this.silentDeath = !flag1; // mark entity as dying silently
|
|
+ // Paper end
|
|
|
|
this.die(damagesource);
|
|
+ this.silentDeath = false; // Paper - cancellable death event - reset to default
|
|
}
|
|
} else if (flag1) {
|
|
this.c(damagesource);
|
|
@@ -0,0 +0,0 @@ public abstract class EntityLiving extends Entity {
|
|
Entity entity = damagesource.getEntity();
|
|
EntityLiving entityliving = this.getKillingEntity();
|
|
|
|
+ /* // Paper - move down to make death event cancellable - this is the runKillTrigger below
|
|
if (this.aO >= 0 && entityliving != null) {
|
|
entityliving.a(this, this.aO, damagesource);
|
|
}
|
|
@@ -0,0 +0,0 @@ public abstract class EntityLiving extends Entity {
|
|
if (this.isSleeping()) {
|
|
this.entityWakeup();
|
|
}
|
|
+ */ // Paper
|
|
|
|
this.killed = true;
|
|
- this.getCombatTracker().g();
|
|
+ // this.getCombatTracker().g(); // Paper - moved into if below as .reset()
|
|
if (this.world instanceof WorldServer) {
|
|
if (entity != null) {
|
|
- entity.a((WorldServer) this.world, this);
|
|
+ // entity.a((WorldServer) this.world, this); // Paper - move below into if for onKill
|
|
}
|
|
|
|
- this.d(damagesource);
|
|
+ // Paper start
|
|
+ org.bukkit.event.entity.EntityDeathEvent deathEvent = this.d(damagesource);
|
|
+ if (deathEvent == null || !deathEvent.isCancelled()) {
|
|
+ if (this.getKillCount() >= 0 && entityliving != null) {
|
|
+ entityliving.runKillTrigger(this, this.getKillCount(), damagesource);
|
|
+ }
|
|
+ if (this.isSleeping()) {
|
|
+ this.entityWakeup();
|
|
+ }
|
|
+ this.getCombatTracker().reset();
|
|
+ if (entity != null) {
|
|
+ entity.onKill((WorldServer) this.world, this);
|
|
+ }
|
|
+ } else {
|
|
+ this.killed = false;
|
|
+ this.setHealth((float) deathEvent.getReviveHealth());
|
|
+ }
|
|
+ // Paper end
|
|
this.f(entityliving);
|
|
}
|
|
|
|
+ if (this.killed) { // Paper
|
|
this.world.broadcastEntityEffect(this, (byte) 3);
|
|
this.setPose(EntityPose.DYING);
|
|
+ } // Paper
|
|
}
|
|
}
|
|
|
|
@@ -0,0 +0,0 @@ public abstract class EntityLiving extends Entity {
|
|
if (!this.world.isClientSide) {
|
|
boolean flag = false;
|
|
|
|
- if (entityliving instanceof EntityWither) {
|
|
+ if (this.killed && entityliving instanceof EntityWither) { // Paper
|
|
if (this.world.getGameRules().getBoolean(GameRules.MOB_GRIEFING)) {
|
|
BlockPosition blockposition = this.getChunkCoordinates();
|
|
IBlockData iblockdata = Blocks.WITHER_ROSE.getBlockData();
|
|
@@ -0,0 +0,0 @@ public abstract class EntityLiving extends Entity {
|
|
}
|
|
}
|
|
|
|
- protected void d(DamageSource damagesource) {
|
|
+ protected org.bukkit.event.entity.EntityDeathEvent processDeath(DamageSource damagesource) { return d(damagesource); } // Paper - OBFHELPER
|
|
+ protected org.bukkit.event.entity.EntityDeathEvent d(DamageSource damagesource) { // Paper
|
|
Entity entity = damagesource.getEntity();
|
|
int i;
|
|
|
|
@@ -0,0 +0,0 @@ public abstract class EntityLiving extends Entity {
|
|
this.dropDeathLoot(damagesource, i, flag);
|
|
}
|
|
// CraftBukkit start - Call death event
|
|
- CraftEventFactory.callEntityDeathEvent(this, this.drops);
|
|
+ org.bukkit.event.entity.EntityDeathEvent deathEvent = CraftEventFactory.callEntityDeathEvent(this, this.drops); // Paper
|
|
+ this.postDeathDropItems(deathEvent); // Paper
|
|
this.drops = new ArrayList<>();
|
|
// CraftBukkit end
|
|
|
|
// this.dropInventory();// CraftBukkit - moved up
|
|
this.dropExperience();
|
|
+ return deathEvent; // Paper
|
|
}
|
|
|
|
protected void dropInventory() {}
|
|
+ protected void postDeathDropItems(org.bukkit.event.entity.EntityDeathEvent event) {} // Paper - method for post death logic that cannot be ran before the event is potentially cancelled
|
|
|
|
// CraftBukkit start
|
|
public int getExpReward() {
|
|
@@ -0,0 +0,0 @@ public abstract class EntityLiving extends Entity {
|
|
return SoundEffects.ENTITY_GENERIC_HURT;
|
|
}
|
|
|
|
+ public final SoundEffect getDeathSoundEffect() { return this.getSoundDeath(); } // Paper - OBFHELPER
|
|
@Nullable
|
|
protected SoundEffect getSoundDeath() {
|
|
return SoundEffects.ENTITY_GENERIC_DEATH;
|
|
@@ -0,0 +0,0 @@ public abstract class EntityLiving extends Entity {
|
|
|
|
}
|
|
|
|
+ public final float getDeathSoundVolume() { return this.getSoundVolume(); } // Paper - OBFHELPER
|
|
protected float getSoundVolume() {
|
|
return 1.0F;
|
|
}
|
|
|
|
+ public float getSoundPitch() { return dG();} // Paper - OBFHELPER
|
|
protected float dG() {
|
|
return this.isBaby() ? (this.random.nextFloat() - this.random.nextFloat()) * 0.2F + 1.5F : (this.random.nextFloat() - this.random.nextFloat()) * 0.2F + 1.0F;
|
|
}
|
|
diff --git a/src/main/java/net/minecraft/server/EntityPlayer.java b/src/main/java/net/minecraft/server/EntityPlayer.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/net/minecraft/server/EntityPlayer.java
|
|
+++ b/src/main/java/net/minecraft/server/EntityPlayer.java
|
|
@@ -0,0 +0,0 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
|
|
public int ping;
|
|
public boolean viewingCredits;
|
|
private int containerUpdateDelay; // Paper
|
|
+ // Paper start - cancellable death event
|
|
+ public boolean queueHealthUpdatePacket = false;
|
|
+ public net.minecraft.server.PacketPlayOutUpdateHealth queuedHealthUpdatePacket;
|
|
+ // Paper end
|
|
|
|
// CraftBukkit start
|
|
public String displayName;
|
|
@@ -0,0 +0,0 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
|
|
|
|
String deathmessage = defaultMessage.getString();
|
|
org.bukkit.event.entity.PlayerDeathEvent event = CraftEventFactory.callPlayerDeathEvent(this, loot, deathmessage, keepInventory);
|
|
+ // Paper start - cancellable death event
|
|
+ if (event.isCancelled()) {
|
|
+ // make compatible with plugins that might have already set the health in an event listener
|
|
+ if (this.getHealth() <= 0) {
|
|
+ this.setHealth((float) event.getReviveHealth());
|
|
+ }
|
|
+ return;
|
|
+ }
|
|
+ // Paper end
|
|
|
|
// SPIGOT-943 - only call if they have an inventory open
|
|
if (this.activeContainer != this.defaultContainer) {
|
|
@@ -0,0 +0,0 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
|
|
}
|
|
}
|
|
}
|
|
-
|
|
- return super.damageEntity(damagesource, f);
|
|
+ // Paper start - cancellable death events
|
|
+ //return super.damageEntity(damagesource, f);
|
|
+ this.queueHealthUpdatePacket = true;
|
|
+ boolean damaged = super.damageEntity(damagesource, f);
|
|
+ this.queueHealthUpdatePacket = false;
|
|
+ if (this.queuedHealthUpdatePacket != null) {
|
|
+ this.playerConnection.sendPacket(this.queuedHealthUpdatePacket);
|
|
+ this.queuedHealthUpdatePacket = null;
|
|
+ }
|
|
+ return damaged;
|
|
+ // Paper end
|
|
}
|
|
}
|
|
}
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftSound.java b/src/main/java/org/bukkit/craftbukkit/CraftSound.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/CraftSound.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/CraftSound.java
|
|
@@ -0,0 +0,0 @@ public enum CraftSound {
|
|
WEATHER_RAIN_ABOVE("weather.rain.above");
|
|
private final String minecraftKey;
|
|
|
|
+ // Paper start - cancellable death event
|
|
+ public static CraftSound getBySoundEffect(final SoundEffect effect) {
|
|
+ MinecraftKey key = IRegistry.SOUND_EVENT.getKey(effect);
|
|
+ Preconditions.checkArgument(key != null, "Key for sound effect %s not found?", effect.toString());
|
|
+
|
|
+ return valueOf(key.getKey().replace('.', '_').toUpperCase(java.util.Locale.ENGLISH));
|
|
+ }
|
|
+
|
|
+ public static Sound getSoundByEffect(final SoundEffect effect) {
|
|
+ return Sound.valueOf(getBySoundEffect(effect).name());
|
|
+ }
|
|
+
|
|
+ public static SoundEffect getSoundEffect(final Sound sound) {
|
|
+ return getSoundEffect(getSound(sound));
|
|
+ }
|
|
+ // Paper end
|
|
CraftSound(String minecraftKey) {
|
|
this.minecraftKey = minecraftKey;
|
|
}
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
@@ -0,0 +0,0 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
|
}
|
|
|
|
public void sendHealthUpdate() {
|
|
- getHandle().playerConnection.sendPacket(new PacketPlayOutUpdateHealth(getScaledHealth(), getHandle().getFoodData().getFoodLevel(), getHandle().getFoodData().getSaturationLevel()));
|
|
+ // Paper start - cancellable death event
|
|
+ //getHandle().playerConnection.sendPacket(new PacketPlayOutUpdateHealth(getScaledHealth(), getHandle().getFoodData().getFoodLevel(), getHandle().getFoodData().getSaturationLevel()));
|
|
+ PacketPlayOutUpdateHealth packet = new PacketPlayOutUpdateHealth(getScaledHealth(), getHandle().getFoodData().getFoodLevel(), getHandle().getFoodData().getSaturationLevel());
|
|
+ if (this.getHandle().queueHealthUpdatePacket) {
|
|
+ this.getHandle().queuedHealthUpdatePacket = packet;
|
|
+ } else {
|
|
+ this.getHandle().playerConnection.sendPacket(packet);
|
|
+ }
|
|
+ // Paper end
|
|
}
|
|
|
|
public void injectScaledMaxHealth(Collection<AttributeModifiable> collection, boolean force) {
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
|
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
|
@@ -0,0 +0,0 @@ public class CraftEventFactory {
|
|
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());
|
|
+ populateFields(victim, event); // Paper - make cancellable
|
|
CraftWorld world = (CraftWorld) entity.getWorld();
|
|
Bukkit.getServer().getPluginManager().callEvent(event);
|
|
|
|
+ // Paper start - make cancellable
|
|
+ if (event.isCancelled()) {
|
|
+ return event;
|
|
+ }
|
|
+ playDeathSound(victim, event);
|
|
+ // Paper end
|
|
victim.expToDrop = event.getDroppedExp();
|
|
|
|
for (org.bukkit.inventory.ItemStack stack : event.getDrops()) {
|
|
@@ -0,0 +0,0 @@ public class CraftEventFactory {
|
|
CraftPlayer entity = victim.getBukkitEntity();
|
|
PlayerDeathEvent event = new PlayerDeathEvent(entity, drops, victim.getExpReward(), 0, deathMessage);
|
|
event.setKeepInventory(keepInventory);
|
|
+ populateFields(victim, event); // Paper - make cancellable
|
|
org.bukkit.World world = entity.getWorld();
|
|
Bukkit.getServer().getPluginManager().callEvent(event);
|
|
+ // Paper start - make cancellable
|
|
+ if (event.isCancelled()) {
|
|
+ return event;
|
|
+ }
|
|
+ playDeathSound(victim, event);
|
|
+ // Paper end
|
|
|
|
victim.keepLevel = event.getKeepLevel();
|
|
victim.newLevel = event.getNewLevel();
|
|
@@ -0,0 +0,0 @@ public class CraftEventFactory {
|
|
return event;
|
|
}
|
|
|
|
+ // Paper start - helper methods for making death event cancellable
|
|
+ // Add information to death event
|
|
+ private static void populateFields(EntityLiving victim, EntityDeathEvent event) {
|
|
+ event.setReviveHealth(event.getEntity().getAttribute(org.bukkit.attribute.Attribute.GENERIC_MAX_HEALTH).getValue());
|
|
+ event.setShouldPlayDeathSound(!victim.silentDeath && !victim.isSilent());
|
|
+ net.minecraft.server.SoundEffect soundEffect = victim.getDeathSoundEffect();
|
|
+ event.setDeathSound(soundEffect != null ? org.bukkit.craftbukkit.CraftSound.getSoundByEffect(soundEffect) : null);
|
|
+ event.setDeathSoundCategory(org.bukkit.SoundCategory.valueOf(victim.getSoundCategory().name()));
|
|
+ event.setDeathSoundVolume(victim.getDeathSoundVolume());
|
|
+ event.setDeathSoundPitch(victim.getSoundPitch());
|
|
+ }
|
|
+
|
|
+ // Play death sound manually
|
|
+ private static void playDeathSound(EntityLiving victim, EntityDeathEvent event) {
|
|
+ if (event.shouldPlayDeathSound() && event.getDeathSound() != null && event.getDeathSoundCategory() != null) {
|
|
+ EntityHuman source = victim instanceof EntityHuman ? (EntityHuman) victim : null;
|
|
+ double x = event.getEntity().getLocation().getX();
|
|
+ double y = event.getEntity().getLocation().getY();
|
|
+ double z = event.getEntity().getLocation().getZ();
|
|
+ net.minecraft.server.SoundEffect soundEffect = org.bukkit.craftbukkit.CraftSound.getSoundEffect(event.getDeathSound());
|
|
+ net.minecraft.server.SoundCategory soundCategory = net.minecraft.server.SoundCategory.valueOf(event.getDeathSoundCategory().name());
|
|
+ victim.world.playSound(source, x, y, z, soundEffect, soundCategory, event.getDeathSoundVolume(), event.getDeathSoundPitch());
|
|
+ }
|
|
+ }
|
|
+ // Paper end
|
|
/**
|
|
* Server methods
|
|
*/
|