Merge pull request #418 from emortaldev/master

Add getPlayer() to PickupExperienceEvent
This commit is contained in:
TheMode 2021-08-19 07:25:15 +02:00 committed by GitHub
commit 7d752cc323
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 3 deletions

View File

@ -318,7 +318,7 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
if (expandedBoundingBox.intersect(itemBoundingBox)) { if (expandedBoundingBox.intersect(itemBoundingBox)) {
if (experienceOrb.shouldRemove() || experienceOrb.isRemoveScheduled()) if (experienceOrb.shouldRemove() || experienceOrb.isRemoveScheduled())
continue; continue;
PickupExperienceEvent pickupExperienceEvent = new PickupExperienceEvent(experienceOrb); PickupExperienceEvent pickupExperienceEvent = new PickupExperienceEvent(this, experienceOrb);
EventDispatcher.callCancellable(pickupExperienceEvent, () -> { EventDispatcher.callCancellable(pickupExperienceEvent, () -> {
short experienceCount = pickupExperienceEvent.getExperienceCount(); // TODO give to player short experienceCount = pickupExperienceEvent.getExperienceCount(); // TODO give to player
entity.remove(); entity.remove();

View File

@ -1,21 +1,30 @@
package net.minestom.server.event.item; package net.minestom.server.event.item;
import net.minestom.server.entity.ExperienceOrb; import net.minestom.server.entity.ExperienceOrb;
import net.minestom.server.entity.Player;
import net.minestom.server.event.trait.CancellableEvent; import net.minestom.server.event.trait.CancellableEvent;
import net.minestom.server.event.trait.PlayerEvent;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
public class PickupExperienceEvent implements CancellableEvent { public class PickupExperienceEvent implements CancellableEvent, PlayerEvent {
private final Player player;
private final ExperienceOrb experienceOrb; private final ExperienceOrb experienceOrb;
private short experienceCount; private short experienceCount;
private boolean cancelled; private boolean cancelled;
public PickupExperienceEvent(@NotNull ExperienceOrb experienceOrb) { public PickupExperienceEvent(@NotNull Player player, @NotNull ExperienceOrb experienceOrb) {
this.player = player;
this.experienceOrb = experienceOrb; this.experienceOrb = experienceOrb;
this.experienceCount = experienceOrb.getExperienceCount(); this.experienceCount = experienceOrb.getExperienceCount();
} }
@Override
public @NotNull Player getPlayer() {
return player;
}
@NotNull @NotNull
public ExperienceOrb getExperienceOrb() { public ExperienceOrb getExperienceOrb() {
return experienceOrb; return experienceOrb;