Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add trident pickup event #1679

Merged
merged 1 commit into from
Nov 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/main/java/cn/nukkit/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import cn.nukkit.event.inventory.InventoryCloseEvent;
import cn.nukkit.event.inventory.InventoryPickupArrowEvent;
import cn.nukkit.event.inventory.InventoryPickupItemEvent;
import cn.nukkit.event.inventory.InventoryPickupTridentEvent;
import cn.nukkit.event.player.*;
import cn.nukkit.event.player.PlayerAsyncPreLoginEvent.LoginResult;
import cn.nukkit.event.player.PlayerInteractEvent.Action;
Expand Down Expand Up @@ -4928,6 +4929,12 @@ public boolean pickupEntity(Entity entity, boolean near) {
return false;
}

InventoryPickupTridentEvent ev = new InventoryPickupTridentEvent(this.inventory, (EntityThrownTrident) entity);
this.server.getPluginManager().callEvent(ev);
if (ev.isCancelled()) {
return false;
}

TakeItemEntityPacket pk = new TakeItemEntityPacket();
pk.entityId = this.getId();
pk.target = entity.getId();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package cn.nukkit.event.inventory;

import cn.nukkit.entity.projectile.EntityThrownTrident;
import cn.nukkit.event.Cancellable;
import cn.nukkit.event.HandlerList;
import cn.nukkit.inventory.Inventory;

public class InventoryPickupTridentEvent extends InventoryEvent implements Cancellable {

private static final HandlerList handlers = new HandlerList();

public static HandlerList getHandlers() {
return handlers;
}

private final EntityThrownTrident trident;

public InventoryPickupTridentEvent(Inventory inventory, EntityThrownTrident trident) {
super(inventory);
this.trident = trident;
}

public EntityThrownTrident getTrident() {
return trident;
}
}