I'm trying to make a Minecraft spigot plugin using intellij. The bit that I'm struggling with is that I would like an event to be triggered when I place a certain item with a certain name and then that item be replaced with another.
For example, when a soul torch renamed "hello" in an anvil is placed it should be replaced with a barrel with a kit in it. I know how to cancel the original item and replace it with another, I just can't figure out or find anywhere about having the placed item only trigger the event if it has a certain name, and I don't know how to have the barrel have items in it (I've copied the nbt tag thing ingame with the /data command on a barrel that has the items I would like to use in it).
I've tried using the BlockData() stuff, it could be right because I have not idea how to use it or it could be just really incorrect.
This is my code so far:
@EventHandler(priority = EventPriority.LOW)
public void onTorchPlace_Low(BlockPlaceEvent event) {
if (event.getBlock().getType() == Material.TORCH) {
event.getBlock().setType(Material.DIAMOND_BLOCK.);
}
}
@EventHandler
public void onTorchPlace_Normal(BlockPlaceEvent event) {
Block block = event.getBlock();
if (block.getType() != Material.TORCH) {
return;
}
Bukkit.getLogger().info("A torch was placed");
}