Added access to dropped item to CustomPlayerFishEvent

This commit is contained in:
Jules 2025-03-06 19:35:18 +01:00
parent 703f1f9610
commit 7ef35007fd
2 changed files with 14 additions and 4 deletions

View File

@ -1,6 +1,7 @@
package net.Indyuce.mmocore.api.event;
import net.Indyuce.mmocore.api.player.PlayerData;
import org.bukkit.entity.Item;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.bukkit.inventory.ItemStack;
@ -9,13 +10,19 @@ public class CustomPlayerFishEvent extends PlayerDataEvent implements Cancellabl
private static final HandlerList handlers = new HandlerList();
private ItemStack caught;
private final Item droppedItem;
private boolean cancelled = false;
public CustomPlayerFishEvent(PlayerData player, ItemStack caught) {
public CustomPlayerFishEvent(PlayerData player, ItemStack caught, Item droppedItem) {
super(player);
this.caught = caught;
this.droppedItem = droppedItem;
}
public Item getDroppedItem() {
return droppedItem;
}
public ItemStack getCaught() {

View File

@ -176,17 +176,20 @@ public class FishingListener implements Listener {
return;
}
Item item = hook.getWorld().dropItemNaturally(hook.getLocation(), collect);
// Call Bukkit event
CustomPlayerFishEvent called = new CustomPlayerFishEvent(playerData, collect);
CustomPlayerFishEvent called = new CustomPlayerFishEvent(playerData, collect, item);
Bukkit.getPluginManager().callEvent(called);
if (called.isCancelled())
if (called.isCancelled()) {
item.remove();
return;
}
// Increase player statistic
player.incrementStatistic(Statistic.FISH_CAUGHT);
// Calculate yeet velocity
Item item = hook.getWorld().dropItemNaturally(hook.getLocation(), collect);
MMOCoreUtils.displayIndicator(location.add(0, 1.25, 0),
ConfigMessage.fromKey("fish-out-water" + (isCriticalFish() ? "-crit" : "")).asLine());
Vector vec = player.getLocation().subtract(hook.getLocation()).toVector();