diff --git a/src/main/java/net/minestom/server/entity/Player.java b/src/main/java/net/minestom/server/entity/Player.java index 0517c1504..d74c6eedf 100644 --- a/src/main/java/net/minestom/server/entity/Player.java +++ b/src/main/java/net/minestom/server/entity/Player.java @@ -318,9 +318,10 @@ public class Player extends LivingEntity implements CommandSender, Localizable, if (expandedBoundingBox.intersect(itemBoundingBox)) { if (experienceOrb.shouldRemove() || experienceOrb.isRemoveScheduled()) continue; - PickupExperienceEvent pickupExperienceEvent = new PickupExperienceEvent(experienceOrb); + PickupExperienceEvent pickupExperienceEvent = new PickupExperienceEvent(experienceOrb, this); EventDispatcher.callCancellable(pickupExperienceEvent, () -> { - short experienceCount = pickupExperienceEvent.getExperienceCount(); // TODO give to player + short experienceCount = pickupExperienceEvent.getExperienceCount(); + this.setExp(this.getExp() + experienceCount); entity.remove(); }); } diff --git a/src/main/java/net/minestom/server/event/item/PickupExperienceEvent.java b/src/main/java/net/minestom/server/event/item/PickupExperienceEvent.java index 832ee6f52..e85e053c1 100644 --- a/src/main/java/net/minestom/server/event/item/PickupExperienceEvent.java +++ b/src/main/java/net/minestom/server/event/item/PickupExperienceEvent.java @@ -1,18 +1,21 @@ package net.minestom.server.event.item; import net.minestom.server.entity.ExperienceOrb; +import net.minestom.server.entity.Player; import net.minestom.server.event.trait.CancellableEvent; import org.jetbrains.annotations.NotNull; public class PickupExperienceEvent implements CancellableEvent { private final ExperienceOrb experienceOrb; + private final Player player; private short experienceCount; private boolean cancelled; - public PickupExperienceEvent(@NotNull ExperienceOrb experienceOrb) { + public PickupExperienceEvent(@NotNull ExperienceOrb experienceOrb, @NotNull Player player) { this.experienceOrb = experienceOrb; + this.player = player; this.experienceCount = experienceOrb.getExperienceCount(); } @@ -21,6 +24,11 @@ public class PickupExperienceEvent implements CancellableEvent { return experienceOrb; } + @NotNull + public Player getPlayer() { + return player; + } + public short getExperienceCount() { return experienceCount; }