Add getPlayer() to PickupExperienceEvent

This commit is contained in:
emortal 2021-08-19 05:05:00 +01:00
parent 9750e1fe8b
commit a0696bc20b
2 changed files with 12 additions and 3 deletions

View File

@ -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();
});
}

View File

@ -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;
}