Hi, I'm making a plugin to save the enchantments of the weapons in an enchanted book after disenchanting them in the grindstone, for that I'm using a hopper. (I'm making this thread because I did not find any solution related to my problem in the forums) The problems start when I want to add this book (after creating it) inside a hopper. I can store it (the book) inside a chest, but not inside a hopper. I decided to go step by step, and try to add a diamond inside a hopper, using the BlockPlaceEvent event. Code (Java): package me.matsuneitor.grindstoneenchanter.Events; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.block.Hopper; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.block.BlockPlaceEvent; import org.bukkit.inventory.ItemStack; public class BlockPlace implements Listener { @EventHandler public void onBlocKPlace(BlockPlaceEvent event) { if(event.getBlockPlaced().getType().equals(Material.HOPPER)) { event.getPlayer().sendMessage(ChatColor.AQUA + "¡Diamonds!"); Hopper hopper = (Hopper) event.getBlockPlaced().getState(); ItemStack itemStack = new ItemStack(Material.DIAMOND); hopper.getInventory().addItem(itemStack); hopper.update(); } } } I've already registered the event, when I place a hopper somewhere, I receive the message "Diamonds!" but the hopper's still empty. ¿What am I doing wrong? I'm using 1.15.2.
yup, that's for chests. I found the solution, changed from getInventory() to getSnapshotInventory() and now it works. Thanks y'all for the help.