Random drop on Player eat event

Discussion in 'Plugin Development' started by MatriZ, Feb 18, 2021.

  1. Offline

    MatriZ

    Hello,
    Im trying to make plugin that when player eats it will drop random item to that specific player.
    And btw im new in coding
    My current codes are:
    Listeners:
    Code:
    package idk.listeners;
    
    
    import javax.annotation.Nonnull;
    
    import org.bukkit.Bukkit;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerItemConsumeEvent;
    import org.bukkit.plugin.Plugin;
    
    import idk.Main.Main;
    
    
    public class listener implements Listener{
    
        private Main plugin;
     
        public listener(Main plugin) {
            this.plugin = plugin;
            Bukkit.getPluginManager().registerEvents(this, (@Nonnull Plugin) plugin);
         
       }
     
    @EventHandler
       public void eat(PlayerItemConsumeEvent e) {
           Player = e.getPlayer();
    
       }
    }
    
    Main:

    package idk.Main;


    import org.bukkit.plugin.java.JavaPlugin;

    import idk.listeners.listener;

    public class Main extends JavaPlugin{

    @Override
    public void onEnable() {
    new listener(this);
    }
    }
     
    Last edited: Feb 18, 2021
  2. Offline

    timtower Administrator Administrator Moderator

  3. Offline

    MatriZ

    I dont know how to make it to spawn item when player eats
     
  4. Offline

    Newdel

    https://hub.spigotmc.org/javadocs/spigot/org/bukkit/inventory/ItemStack.html#<init>(org.bukkit.Material)
    https://hub.spigotmc.org/javadocs/spigot/org/bukkit/material/package-summary.html
    https://hub.spigotmc.org/javadocs/spigot/org/bukkit/entity/HumanEntity.html#getInventory()
    https://hub.spigotmc.org/javadocs/s...ml#addItem(org.bukkit.inventory.ItemStack...)
    Try figuring it out on your own with exactly these links and come back if you still have questions.
    If you don't get the solution with those links, you should probably learn a bit more basic java before writing plugins

    Btw, rename your class to Listener pls because Java classes start with a capital letter
     

Share This Page