Hi, i'm trying to make a plugin, but there were complications When you destroy a block (for example obsidian) that gives the drop (the obsidian block), and that in the location of the block appears lava of imediate. I tried it as follows: Code (Java): public void onBreak(BlockBreakEvent e) { if (e.getBlock().getType().equals(Material.OBSIDIAN)) { e.getBlock().setType(Material.LAVA); } } Not works. Any can help me with any idea? Also I tryed to cancel the event. In that case the block changes the material, but don't drop anything. any response can help
The event is called prior to the block breaking, so if you set the block in the event handler itself, you will actually be breaking the block you set it to in-game. It looks like this: Start breaking block -> BlockBreakEvent called at the end -> Your listener runs, setting the new block type -> the server breaks the block, which you just set to LAVA To make sure you set the block AFTER the server actually breaks it, you need to use the Bukkit scheduler or schedule a BukkitRunnable to delay setting the block itself 1 tick.
Show your full code please. Also, for ENUMs you should use == Material. From what I understand you're trying to replace any broken obsidian to lava, right?
Code (Java): package com.SolitaSolaa.SkyBlock.Events; import org.bukkit.Material; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.block.BlockBreakEvent; public class Events implements Listener { @EventHandler public void onBreak(BlockBreakEvent e) { if (e.getBlock().getType().equals(Material.OBSIDIAN)) { e.getBlock().setType(Material.LAVA); } } }
Code (Text): @EventHandler public void onBreak(BlockBreakEvent e) { if (e.getBlock().getType() == Material.OBSIDIAN) { // Setup a bukkit runnable that will run e.getBlock().setType(Material.LAVA); about 10 ticks later } }
Code (Text): new BukkitRunnable() { @Override public void run() { // What you want to schedule goes here } }.runTaskLater(yourplugininstance, timeinticks);