From 1da2d1f5b619706ae64f317fe9a822e4ab9efeaf Mon Sep 17 00:00:00 2001 From: Rigby Date: Wed, 21 Sep 2011 16:32:37 +0100 Subject: [PATCH] Implements the ability to customise and remove Player death messages. --- src/main/java/net/minecraft/server/EntityPlayer.java | 7 +++++-- .../org/bukkit/craftbukkit/event/CraftEventFactory.java | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/minecraft/server/EntityPlayer.java b/src/main/java/net/minecraft/server/EntityPlayer.java index 799aae6484..3c944a9baa 100644 --- a/src/main/java/net/minecraft/server/EntityPlayer.java +++ b/src/main/java/net/minecraft/server/EntityPlayer.java @@ -12,6 +12,7 @@ import org.bukkit.craftbukkit.CraftWorld; import org.bukkit.craftbukkit.event.CraftEventFactory; import org.bukkit.craftbukkit.inventory.CraftItemStack; import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason; +import org.bukkit.event.entity.PlayerDeathEvent; // CraftBukkit end public class EntityPlayer extends EntityHuman implements ICrafting { @@ -139,7 +140,6 @@ public class EntityPlayer extends EntityHuman implements ICrafting { } public void die(DamageSource damagesource) { - this.b.serverConfigurationManager.sendAll(new Packet3Chat(damagesource.a(this))); // CraftBukkit start java.util.List loot = new java.util.ArrayList(); @@ -155,7 +155,10 @@ public class EntityPlayer extends EntityHuman implements ICrafting { } } - CraftEventFactory.callPlayerDeathEvent(this, loot); + PlayerDeathEvent event = CraftEventFactory.callPlayerDeathEvent(this, loot, damagesource.a(this)); + if (!"".equals(event.getDeathMessage())) { + this.b.serverConfigurationManager.sendAll(new Packet3Chat(event.getDeathMessage())); + } // 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) { diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java index 0082526cb5..f86dded7e5 100644 --- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java +++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java @@ -293,9 +293,9 @@ public class CraftEventFactory { return event; } - public static PlayerDeathEvent callPlayerDeathEvent(EntityPlayer victim, List drops) { + public static PlayerDeathEvent callPlayerDeathEvent(EntityPlayer victim, List drops, String deathMessage) { CraftPlayer entity = (CraftPlayer)victim.getBukkitEntity(); - PlayerDeathEvent event = new PlayerDeathEvent(entity, drops, victim.getExpReward(), 0); + PlayerDeathEvent event = new PlayerDeathEvent(entity, drops, victim.getExpReward(), 0, deathMessage); org.bukkit.World world = entity.getWorld(); Bukkit.getServer().getPluginManager().callEvent(event);