diff --git a/src/main/java/net/minecraft/server/EntityExperienceOrb.java b/src/main/java/net/minecraft/server/EntityExperienceOrb.java index 8a7476b00d..26e2204bf8 100644 --- a/src/main/java/net/minecraft/server/EntityExperienceOrb.java +++ b/src/main/java/net/minecraft/server/EntityExperienceOrb.java @@ -1,5 +1,7 @@ package net.minecraft.server; +import org.bukkit.craftbukkit.event.CraftEventFactory; // CraftBukkit + public class EntityExperienceOrb extends Entity { public int a; @@ -130,7 +132,7 @@ public class EntityExperienceOrb extends Entity { entityhuman.x = 2; this.world.makeSound(this, "random.orb", 0.1F, 0.5F * ((this.random.nextFloat() - this.random.nextFloat()) * 0.7F + 1.8F)); entityhuman.receive(this, 1); - entityhuman.giveExp(this.value); + entityhuman.giveExp(CraftEventFactory.callPlayerExpChangeEvent(entityhuman, this.value).getAmount()); // CraftBukkit - this.value to event.getAmount() this.die(); } } diff --git a/src/main/java/net/minecraft/server/EntityHuman.java b/src/main/java/net/minecraft/server/EntityHuman.java index d7156aeb26..69f6e62130 100644 --- a/src/main/java/net/minecraft/server/EntityHuman.java +++ b/src/main/java/net/minecraft/server/EntityHuman.java @@ -57,6 +57,7 @@ public abstract class EntityHuman extends EntityLiving { protected boolean J = false; public float K; public PlayerAbilities abilities = new PlayerAbilities(); + public int oldLevel = -1; // CraftBukkit public int expLevel; public int expTotal; public float exp; diff --git a/src/main/java/net/minecraft/server/EntityPlayer.java b/src/main/java/net/minecraft/server/EntityPlayer.java index dd0e90a4b7..a3a13f2dab 100644 --- a/src/main/java/net/minecraft/server/EntityPlayer.java +++ b/src/main/java/net/minecraft/server/EntityPlayer.java @@ -319,6 +319,17 @@ public class EntityPlayer extends EntityHuman implements ICrafting { this.lastSentExp = this.expTotal; this.netServerHandler.sendPacket(new Packet43SetExperience(this.exp, this.expTotal, this.expLevel)); } + + // CraftBukkit start + if (this.oldLevel == -1) { + this.oldLevel = this.expLevel; + } + + if (this.oldLevel != this.expLevel) { + CraftEventFactory.callPlayerLevelChangeEvent(this.world.getServer().getPlayer((EntityPlayer) this), this.oldLevel, this.expLevel); + this.oldLevel = this.expLevel; + } + // CraftBukkit end } public void e(int i) { diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java index 955d1a904d..d37ce1ad84 100644 --- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java +++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java @@ -391,4 +391,17 @@ public class CraftEventFactory { return event; } + + public static PlayerLevelChangeEvent callPlayerLevelChangeEvent(Player player, int oldLevel, int newLevel) { + PlayerLevelChangeEvent event = new PlayerLevelChangeEvent(player, oldLevel, newLevel); + Bukkit.getPluginManager().callEvent(event); + return event; + } + + public static PlayerExpChangeEvent callPlayerExpChangeEvent(EntityHuman entity, int expAmount) { + Player player = (Player) entity.getBukkitEntity(); + PlayerExpChangeEvent event = new PlayerExpChangeEvent(player, expAmount); + Bukkit.getPluginManager().callEvent(event); + return event; + } }