summaryrefslogtreecommitdiffstats
path: root/src/main/java
diff options
context:
space:
mode:
authorJerom van der Sar <jerom.sar@hotmail.com>2014-07-31 03:05:08 +0200
committerturt2live <travpc@gmail.com>2014-08-17 11:41:40 -0600
commit80e8f2ab8709dedc9fa491907f623d5e371f3d3f (patch)
tree4e1f0298fda52d939d7bdde832a495a985c7c0b4 /src/main/java
parent3626720d537371277e05891240835b67d46d617e (diff)
downloadcraftbukkit-80e8f2ab8709dedc9fa491907f623d5e371f3d3f.tar
craftbukkit-80e8f2ab8709dedc9fa491907f623d5e371f3d3f.tar.gz
craftbukkit-80e8f2ab8709dedc9fa491907f623d5e371f3d3f.tar.lz
craftbukkit-80e8f2ab8709dedc9fa491907f623d5e371f3d3f.tar.xz
craftbukkit-80e8f2ab8709dedc9fa491907f623d5e371f3d3f.zip
Implement ability to keep items on death via plugins. Adds BUKKIT-5724
When a player dies their inventory is normally scattered over the the area in which they died. Plugins should be able to modify this behaviour by defining whether or not the player's inventory will be dropped on the ground or waiting for the player when they eventually respawn. This commit implements the methods included in the Bukkit half for the new behaviour by acting upon the boolean flag. The boolean flag is tested prior to clearing the inventory as well as prior to dropping the items on the ground. If the flag is true (indicating "keep inventory"), the items are not removed from the player's inventory and are not dropped on the ground.
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/net/minecraft/server/EntityPlayer.java4
-rw-r--r--src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java7
2 files changed, 8 insertions, 3 deletions
diff --git a/src/main/java/net/minecraft/server/EntityPlayer.java b/src/main/java/net/minecraft/server/EntityPlayer.java
index adfaddf3..84673b46 100644
--- a/src/main/java/net/minecraft/server/EntityPlayer.java
+++ b/src/main/java/net/minecraft/server/EntityPlayer.java
@@ -366,7 +366,7 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
IChatBaseComponent chatmessage = this.aW().b();
String deathmessage = chatmessage.c();
- org.bukkit.event.entity.PlayerDeathEvent event = CraftEventFactory.callPlayerDeathEvent(this, loot, deathmessage);
+ org.bukkit.event.entity.PlayerDeathEvent event = CraftEventFactory.callPlayerDeathEvent(this, loot, deathmessage, keepInventory);
String deathMessage = event.getDeathMessage();
@@ -379,7 +379,7 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
}
// we clean the player's inventory after the EntityDeathEvent is called so plugins can get the exact state of the inventory.
- if (!keepInventory) {
+ if (!event.getKeepInventory()) {
for (int i = 0; i < this.inventory.items.length; ++i) {
this.inventory.items[i] = null;
}
diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
index 0fff227f..9b10c418 100644
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
@@ -372,9 +372,10 @@ public class CraftEventFactory {
return event;
}
- public static PlayerDeathEvent callPlayerDeathEvent(EntityPlayer victim, List<org.bukkit.inventory.ItemStack> drops, String deathMessage) {
+ public static PlayerDeathEvent callPlayerDeathEvent(EntityPlayer victim, List<org.bukkit.inventory.ItemStack> drops, String deathMessage, boolean keepInventory) {
CraftPlayer entity = victim.getBukkitEntity();
PlayerDeathEvent event = new PlayerDeathEvent(entity, drops, victim.getExpReward(), 0, deathMessage);
+ event.setKeepInventory(keepInventory);
org.bukkit.World world = entity.getWorld();
Bukkit.getServer().getPluginManager().callEvent(event);
@@ -384,6 +385,10 @@ public class CraftEventFactory {
victim.expToDrop = event.getDroppedExp();
victim.newExp = event.getNewExp();
+ if (event.getKeepInventory()) {
+ return event;
+ }
+
for (org.bukkit.inventory.ItemStack stack : event.getDrops()) {
if (stack == null || stack.getType() == Material.AIR) continue;