Solved Replacing broken block into a new block

Discussion in 'Plugin Development' started by Ducyooo, Oct 1, 2020.

  1. Offline

    Ducyooo

    Hi, im trying to set the broken block to bedrock before replacing it again to the broken block type, I cant figure out a way to get it working..

    Code:
    public class BlockBreakEvent implements Listener {
    
        private Main main;
        private HashMap<Location, Block> brokenBlock = new HashMap<Location, Block>();
    
        public BlockBreakEvent(Main main) {
            this.main = main;
        }
    
        @EventHandler
        public void blockBreak(org.bukkit.event.block.BlockBreakEvent event) {
            Player player = event.getPlayer();
            PlayerLevelManager playerLevelManager = main.levelManagerHashMap.get(player.getUniqueId());
            Location location = event.getBlock().getLocation();
            Block block = event.getBlock();
            brokenBlock.put(location, block);
            if (block.getType() == Material.COBBLESTONE) {
                event.getBlock().setType(Material.BEDROCK);
                player.getInventory().addItem(new ItemStack(Material.COBBLESTONE,1 ));
                Bukkit.getScheduler().runTaskLater(main, new Runnable() {
                    @Override
                    public void run() {
                        event.getBlock().setType(Material.COBBLESTONE);
                        brokenBlock.clear();
                    }
                }, 200);
            }
            //SCOREBOARD
            playerLevelManager.setXp(playerLevelManager.getXp() + 100);
            player.sendMessage("┬ža[!] +100 esperienza");
            main.xpCheck(player, playerLevelManager);
            ScoreboardManager scoreboardManager = new ScoreboardManager(main);
            scoreboardManager.setScore(player, playerLevelManager.getLevel(), playerLevelManager.getXp());
        }
    }
     
  2. Online

    timtower Moderator Moderator

    @Ducyooo What part do you need help with then?

    brokenBlock.clear();
    You should remove that line regardless.
     
  3. Offline

    Ducyooo

    Oh im sorry it all works fine but it doesn't replace the broken block with bedrock... anyways thanks for replying and the advice!
     
  4. Online

    timtower Moderator Moderator

    @Ducyooo Cancel the event, then set the block.
     
  5. Offline

    Ducyooo

    @timtower thank you............................
     

Share This Page