From 2ab160e484fb064eed4c423ca8363a475a2da868 Mon Sep 17 00:00:00 2001 From: Nathan Adams Date: Sat, 14 Jan 2012 18:08:27 +0000 Subject: [PATCH] Implemented new PlayerDeathEvent methods for exp setting --- .../net/minecraft/server/EntityPlayer.java | 22 ++++++++++++++++--- .../craftbukkit/event/CraftEventFactory.java | 4 ++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/minecraft/server/EntityPlayer.java b/src/main/java/net/minecraft/server/EntityPlayer.java index 64821a6e75..b9ca7d3703 100644 --- a/src/main/java/net/minecraft/server/EntityPlayer.java +++ b/src/main/java/net/minecraft/server/EntityPlayer.java @@ -65,6 +65,9 @@ public class EntityPlayer extends EntityHuman implements ICrafting { public String listName; public org.bukkit.Location compassTarget; public int newExp = 0; + public int newLevel = 0; + public int newTotalExp = 0; + public boolean keepLevel = false; // CraftBukkit end public void a(NBTTagCompound nbttagcompound) { @@ -553,6 +556,7 @@ public class EntityPlayer extends EntityHuman implements ICrafting { public void t_() { this.cf = -99999999; + this.lastSentExp = -1; // CraftBukkit - Added to reset } public void a(String s) { @@ -627,18 +631,30 @@ public class EntityPlayer extends EntityHuman implements ICrafting { } public void reset() { + float exp = 0; + if(this.keepLevel) { + exp = this.exp; + this.newTotalExp = this.expTotal; + this.newLevel = this.expLevel; + } + this.health = 20; this.fireTicks = 0; this.fallDistance = 0; this.foodData = new FoodMetaData(); - this.expLevel = 0; - this.expTotal = 0; + this.expLevel = this.newLevel; + this.expTotal = this.newTotalExp; this.exp = 0; this.deathTicks = 0; effects.clear(); this.activeContainer = this.defaultContainer; this.lastSentExp = -1; // lastSentExp. Find line: "if (this.expTotal != this.XXXX) {" - this.giveExp(this.newExp); + if(this.keepLevel) { + this.exp = exp; + } else { + this.giveExp(this.newExp); + } + this.keepLevel = false; } public CraftPlayer getPlayer() { diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java index a5f834280d..887bbe4b91 100644 --- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java +++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java @@ -330,6 +330,10 @@ public class CraftEventFactory { org.bukkit.World world = entity.getWorld(); Bukkit.getServer().getPluginManager().callEvent(event); + // TODO: Possibly a way to persist this incase of disconnect + victim.keepLevel = event.getKeepLevel(); + victim.newLevel = event.getNewLevel(); + victim.newTotalExp = event.getNewTotalExp(); victim.expToDrop = event.getDroppedExp(); victim.newExp = event.getNewExp();