From 004017028dfbe946963c07923b50f6952426928f Mon Sep 17 00:00:00 2001 From: Shevchik Date: Thu, 6 Mar 2014 17:31:05 +0400 Subject: [PATCH] Also pickup exp orbs --- .../cnaude/chairs/sitaddons/ChairEffects.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/com/cnaude/chairs/sitaddons/ChairEffects.java b/src/com/cnaude/chairs/sitaddons/ChairEffects.java index 5ba2dce..123ae79 100644 --- a/src/com/cnaude/chairs/sitaddons/ChairEffects.java +++ b/src/com/cnaude/chairs/sitaddons/ChairEffects.java @@ -9,6 +9,8 @@ import org.bukkit.entity.Entity; import org.bukkit.entity.ExperienceOrb; import org.bukkit.entity.Item; import org.bukkit.entity.Player; +import org.bukkit.event.player.PlayerExpChangeEvent; +import org.bukkit.event.player.PlayerLevelChangeEvent; import org.bukkit.event.player.PlayerPickupItemEvent; import com.cnaude.chairs.core.Chairs; @@ -101,6 +103,31 @@ public class ChairEffects { } } } + } else if (entity instanceof ExperienceOrb) { + ExperienceOrb eorb = (ExperienceOrb) entity; + int exptoadd = eorb.getExperience(); + while (exptoadd > 0) { + int localexptoadd = 0; + if (p.getExpToLevel() < exptoadd) { + localexptoadd = p.getExpToLevel(); + PlayerExpChangeEvent expchangeevent = new PlayerExpChangeEvent(p, localexptoadd); + Bukkit.getPluginManager().callEvent(expchangeevent); + p.giveExp(expchangeevent.getAmount()); + if (p.getExpToLevel() <= 0) { + PlayerLevelChangeEvent levelchangeevent = new PlayerLevelChangeEvent(p, p.getLevel(), p.getLevel()+1); + Bukkit.getPluginManager().callEvent(levelchangeevent); + p.setExp(0); + p.giveExpLevels(1); + } + } else { + localexptoadd = exptoadd; + PlayerExpChangeEvent expchangeevent = new PlayerExpChangeEvent(p, localexptoadd); + Bukkit.getPluginManager().callEvent(expchangeevent); + p.giveExp(expchangeevent.getAmount()); + } + exptoadd -= localexptoadd; + } + entity.remove(); } } }