Solved Adding loot for pickup when fishing

Discussion in 'Spigot Plugin Development' started by NeverFlame42, Jul 9, 2021.

  1. This may have a super simple solution, but how do you add items for pickup when fishing? For example, when fishing, the player will have a chance to obtain say diamonds along with the other normal fishing loot. I;ve done some research but haven't found much about this.
    Any ideas?
     
  2. #3 NeverFlame42, Jul 9, 2021
    Last edited: Jul 9, 2021
  3. Hey NeverFlame42,

    Through the event, you can get the item with event.getCaught(). This returns the entity that was caught. You should check if it has an instance of an Item. Then, you can cast it to an Item. Then, you can set the type by doing item.setItemStack(Item).

    You can read more about it in the doc -> https://hub.spigotmc.org/javadocs/spigot/org/bukkit/event/player/PlayerFishEvent.html

    Here is a code example, though make sure you don't just copy and understand everything.
    Code (Java):
    @EventHandler
    public void onFish(PlayerFishEvent event)  {
            if (event.getCaught() instanceof Item)   {
                Item stack = (Item) event.getCaught();
                stack.setItemStack(new ItemStack(Material.DIAMOND));
            }
        }
    If I helped you, it would help if you left a rating :D
     
    #4 Potatoes_Duck, Jul 9, 2021
    Last edited: Jul 9, 2021
    • Like Like x 1
    • Informative Informative x 1