9
0
mirror of https://github.com/Xiao-MoMi/Custom-Fishing.git synced 2025-12-19 15:09:24 +00:00

new api event

This commit is contained in:
XiaoMoMi
2023-12-29 21:11:12 +08:00
parent 7fc673e6a3
commit 06162ccb4c
4 changed files with 80 additions and 7 deletions

View File

@@ -0,0 +1,68 @@
/*
* Copyright (C) <2022> <XiaoMoMi>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.momirealms.customfishing.api.event;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import org.bukkit.event.player.PlayerEvent;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
public class FishingLootSpawnEvent extends PlayerEvent implements Cancellable {
private static final HandlerList handlerList = new HandlerList();
private final Location location;
private final ItemStack itemStack;
private boolean isCancelled;
public FishingLootSpawnEvent(@NotNull Player who, Location location, ItemStack itemStack) {
super(who);
this.itemStack = itemStack;
this.location = location;
this.isCancelled = false;
}
@Override
public boolean isCancelled() {
return isCancelled;
}
@Override
public void setCancelled(boolean cancel) {
isCancelled = cancel;
}
public Location getLocation() {
return location;
}
public ItemStack getItemStack() {
return itemStack;
}
@Override
public @NotNull HandlerList getHandlers() {
return handlerList;
}
public static HandlerList getHandlerList() {
return handlerList;
}
}

View File

@@ -7,7 +7,7 @@ plugins {
allprojects {
version = "2.0.6"
version = "2.0.7"
apply<JavaPlugin>()
apply(plugin = "java")

View File

@@ -657,12 +657,8 @@ public class FishingManagerImpl implements Listener, FishingManager {
}
return;
}
case ENTITY -> {
plugin.getEntityManager().summonEntity(hook.getLocation(), player.getLocation(), loot);
}
case BLOCK -> {
plugin.getBlockManager().summonBlock(player, hook.getLocation(), player.getLocation(), loot);
}
case ENTITY -> plugin.getEntityManager().summonEntity(hook.getLocation(), player.getLocation(), loot);
case BLOCK -> plugin.getBlockManager().summonBlock(player, hook.getLocation(), player.getLocation(), loot);
}
doSuccessActions(loot, effect, fishingPreparation, player);
}

View File

@@ -23,6 +23,7 @@ import net.momirealms.customfishing.api.CustomFishingPlugin;
import net.momirealms.customfishing.api.common.Key;
import net.momirealms.customfishing.api.common.Pair;
import net.momirealms.customfishing.api.common.Tuple;
import net.momirealms.customfishing.api.event.FishingLootSpawnEvent;
import net.momirealms.customfishing.api.manager.ItemManager;
import net.momirealms.customfishing.api.manager.RequirementManager;
import net.momirealms.customfishing.api.mechanic.GlobalSettings;
@@ -424,6 +425,7 @@ public class ItemManagerImpl implements ItemManager, Listener {
/**
* Drops an item based on the provided loot, applying velocity from a hook location to a player location.
* This method would also trigger FishingLootSpawnEvent
*
* @param player The player for whom the item is intended.
* @param hookLocation The location where the item will initially drop.
@@ -441,6 +443,13 @@ public class ItemManagerImpl implements ItemManager, Listener {
if (item.getType() == Material.AIR) {
return;
}
FishingLootSpawnEvent spawnEvent = new FishingLootSpawnEvent(player, hookLocation, item);
Bukkit.getPluginManager().callEvent(spawnEvent);
if (spawnEvent.isCancelled()) {
return;
}
Entity itemEntity = hookLocation.getWorld().dropItem(hookLocation, item);
Vector vector = playerLocation.subtract(hookLocation).toVector().multiply(0.105);
vector = vector.setY((vector.getY() + 0.22) * 1.18);