FishingControl is a small example plugin that demonstrates how to use the server's fishing-related events to control casting, reeling, and loot generation. This README documents the three events the plugin demonstrates and gives short code examples for plugin authors.
All event classes are under the pocketmine\event namespace.
-
PlayerFishCastEvent
- Fired when a player attempts to cast a fishing hook (i.e. uses a fishing rod while no hook is already present).
- Type:
pocketmine\event\player\PlayerFishCastEvent - Cancellable: yes. If cancelled, the cast will not happen and no hook projectile is spawned.
- Typical constructor:
new PlayerFishCastEvent(Player $player, FishingRod $rod) - Use case: prevent casting in certain worlds/regions, implement per-world fishing rules.
Example listener:
use pocketmine\event\player\PlayerFishCastEvent; public function onCast(PlayerFishCastEvent $e): void{ if($e->getPlayer()->getWorld()->getFolderName() === "no-fishing-world"){ $e->setCancelled(true); $e->getPlayer()->sendMessage("Fishing is disabled here."); } }
-
PlayerFishReelEvent
- Fired when a player reels in an existing hook that they own.
- Type:
pocketmine\event\player\PlayerFishReelEvent - Cancellable: yes. If cancelled, the reeling action will be aborted (the hook remains).
- Key methods:
getHook(): ?Entity— the FishHook entity being reeled, if present.getTargetEntity(): ?Entity— an entity that was hooked (if any).getLoot(): ?Item— the loot item the server intends to give (may be null).setLoot(?Item $item): void— modify the loot (set to a different item) or set to null to drop/skip loot.
- Use case: change what the player receives, prevent reeling in certain entities, add special behaviour based on player permissions.
Example listener (force every catch to a diamond):
use pocketmine\event\player\PlayerFishReelEvent; use pocketmine\item\VanillaItems; public function onReel(PlayerFishReelEvent $e): void{ $e->setLoot(VanillaItems::DIAMOND()); }
Notes:
- The server will use the loot returned from this event when spawning/delivering the item. If you set a loot item here, it should be an instance of
pocketmine\item\Item(for vanilla items useVanillaItems::...()).
-
FishHookLootEvent
- Fired right before the server spawns the
ItemEntityfor loot from a fish hook. - Type:
pocketmine\event\entity\FishHookLootEvent - Cancellable: yes. If cancelled, the item entity will not be spawned.
- Key methods:
getLoot(): Item— the item that will be spawned.setLoot(Item $item): void— replace the spawned item.
- Use case: final chance to transform or prevent the item from appearing, or to add special metadata to the spawned item.
Example listener:
use pocketmine\event\entity\FishHookLootEvent; use pocketmine\item\VanillaItems; public function onLoot(FishHookLootEvent $e): void{ // Log and change the loot $this->getLogger()->info("Hook loot about to spawn: " . $e->getLoot()->getName()); $e->setLoot(VanillaItems::DIAMOND()); }
- Fired right before the server spawns the
- Event priorities and cancellation: handlers may declare
@priorityand@handleCancelledin their docblocks if you need fine-grained control. Handlers that checkisCancelled()can decide whether to run or ignore. - Registration: register your listener in
onEnable()using$this->getServer()->getPluginManager()->registerEvents($listener, $this);. - Ordering:
PlayerFishReelEventis fired before the server spawns the loot.FishHookLootEventis fired immediately before the item entity is spawned — use whichever fits your needs. - Testing: Use a combination of server console logs and in-game testing (cast and reel). The example plugin provides fallback closure registrations for the events, and also logs when the server creates and calls the events.
The server now supports plugins providing multiple loot items when a player reels in a hook. There are two modes plugins can use:
-
Replace default loot (default): plugin calls
setLoot(...)orsetLoots([...]). The server will use exactly the items you provide instead of the vanilla loot. -
Append to default loot: plugin calls
addLoot(...)orsetLoots([...])and thensetAppendLoot(true)on thePlayerFishReelEvent. The server will keep the vanilla-generated loot as the first item and append your items after it.
Replace vanilla loot with a single diamond:
use pocketmine\event\player\PlayerFishReelEvent;
use pocketmine\item\VanillaItems;
public function onReel(PlayerFishReelEvent $e): void{
$e->setLoot(VanillaItems::DIAMOND());
}Provide multiple items and replace vanilla loot:
public function onReel(PlayerFishReelEvent $e): void{
$e->setLoots([VanillaItems::DIAMOND(), VanillaItems::GOLD_INGOT()]);
}Append items to vanilla loot (vanilla loot kept first):
public function onReel(PlayerFishReelEvent $e): void{
$e->addLoot(VanillaItems::DIAMOND());
$e->addLoot(VanillaItems::GOLD_INGOT());
$e->setAppendLoot(true);
}- For each loot item (vanilla or plugin-provided) the server fires a
FishHookLootEventimmediately before spawning theItemEntity. Handlers forFishHookLootEventmaysetLoot(...)orsetLoots(...)orsetCancelled(true)to modify or cancel individual spawns. - If you want to completely handle spawning yourself, you can call
setLoots([])orsetLoot(null)(orsetCancelled(true)on theFishHookLootEvent) and then spawn your ownItemEntityinstances at the desired location.
- Start the server from the repository root (PowerShell):
.\start.ps1
# or
.\start.cmd-
Confirm the plugin loads: look for
[FishingControl] FishingControl enabledin the console logs. -
Join the server with a Bedrock client and equip a fishing rod.
-
Cast and reel several times. Watch the server console:
- The server logs debug messages when it calls events (e.g.
FishingRod: calling PlayerFishReelEvent for <player>). - The plugin logs
FishingControl: onReel fired for <player> loot=...when your listener runs. FishHookLootEventlogs appear as--------FishHook spawning loot: <item>.
- The server logs debug messages when it calls events (e.g.
-
To test append behavior specifically:
- Modify your plugin listener to call
addLoot(...)andsetAppendLoot(true)as in the example above. - Reload/restart the server or re-enable the plugin, then cast and reel. You should see the vanilla loot plus your appended items spawn (and corresponding logs).
- Modify your plugin listener to call
If anything doesn't behave as expected, paste the relevant console lines (the debug lines and plugin logs) and I'll help trace it further.
This plugin is intended to run on BeeltyMine (stable v5.x) and is known to work with the APIs in this repository. API class names and method availability may differ in older or custom builds.
Bu eklenti BeeltyMine üzerinde çalışır (BeeltyMine v5.x uyumludur).
GitHub: https://github.com/BeeltyMine/BeeltyMine
FishingControl example plugin and this README are provided as examples; adapt and reuse them under the same license as the main project.