Solved BlockBreak and residence

Discussion in 'Plugin Development' started by Sicka_gp, Apr 21, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    Sicka_gp

    Hi, I need help.
    I need to find out whether the block is destroyed to prevent the situation from someone destroys foreign residence and receives a bonus drops, while not destroy the block and did not damage the tool.
    anyone know how to do it?

    Code:
    @EventHandler
            public void breakblock(BlockBreakEvent event) {
                Block block = event.getBlock();
                Material block2 = event.getBlock().getType();
                World world = block.getWorld();
                Player p = event.getPlayer();
                Boolean breake_diamond = GameparkMessages.getPlugin().getConfig().getBoolean("BlockBreake.Diamond_ore", true);
                Boolean breake_emerald = GameparkMessages.getPlugin().getConfig().getBoolean("BlockBreake.Emerald_ore", false);
                Boolean breake_gold = GameparkMessages.getPlugin().getConfig().getBoolean("BlockBreake.Gold_ore", false);
                for (Player player : Bukkit.getServer().getOnlinePlayers()) {
                    if ((player.hasPermission(perm.breake)||player.hasPermission(perm.admin)) || (player.isOp())) {
                        if (breake_diamond)
                            if (block2 == Material.DIAMOND_ORE) {
                                player.sendMessage((p.getDisplayName() + ChatColor.RED  + " vytezil " + ChatColor.LIGHT_PURPLE + Material.getMaterial(block2.getId())));
                            }
                            else;
                        if (breake_gold)
                            if (block2 == Material.GOLD_ORE) {
                                player.sendMessage((p.getDisplayName() + ChatColor.RED + " vytezil " + ChatColor.LIGHT_PURPLE + Material.getMaterial(block2.getId())));
                            }
                            else;
                        if (breake_emerald)
                            if (block2 == Material.EMERALD_ORE) {
                                player.sendMessage((p.getDisplayName() + ChatColor.RED + " vytezil " + ChatColor.LIGHT_PURPLE + Material.getMaterial(block2.getId())));
                            }
                            else;
                    }
                }
                boolean bonusdrop = GameparkMessages.getPlugin().getConfig().getBoolean("DropBonus", false);
                boolean ench2 = p.getItemInHand().containsEnchantment(Enchantment.LOOT_BONUS_BLOCKS);
                Enchantment ench = Enchantment.LOOT_BONUS_BLOCKS;
                int enchlvl = p.getItemInHand().getEnchantmentLevel(ench);
                if(bonusdrop){
                    if (block.getType() == Material.DIRT || block.getType() == Material.STONE ||block.getType() == Material.GRASS || block.getType() == Material.SAND || block.getType() == Material.SANDSTONE || block.getType() == Material.LOG ||block.getType() == Material.GOLD_ORE || block.getType() == Material.REDSTONE_ORE || block.getType() == Material.IRON_ORE || block.getType() == Material.LAPIS_ORE || block.getType() == Material.COAL_ORE || block.getType() == Material.GLOWING_REDSTONE_ORE || block.getType() == Material.QUARTZ_ORE || block.getType() == Material.GLOWSTONE || block.getType() == Material.DIAMOND_ORE || block.getType() == Material.NETHERRACK  || block.getType() == Material.EMERALD_ORE) {
                        if(ench2){
                            if(enchlvl == 3){
                                ItemStack chosenItem = list4.get(new Random());
                                if(chosenItem.getType() != Material.AIR){
                                    world.dropItemNaturally(block.getLocation(), chosenItem);
                                }
                            }
                            if(enchlvl == 2){
                                ItemStack chosenItem = list3.get(new Random());
                                if(chosenItem.getType() != Material.AIR){
                                    world.dropItemNaturally(block.getLocation(), chosenItem);   
                                }
                            }
                            if(enchlvl == 1){
                                ItemStack chosenItem = list2.get(new Random());
                                if(chosenItem.getType() != Material.AIR){
                                    world.dropItemNaturally(block.getLocation(), chosenItem);   
                                }
                            }
                        }else{
                            ItemStack chosenItem = list.get(new Random());
                            if(chosenItem.getType() != Material.AIR){
                                world.dropItemNaturally(block.getLocation(), chosenItem);   
                            }
                        }
                    }
                }
            }
     
  2. Offline

    Nitnelave

    Set the listener with priority MONITOR and ignoreCancelled = true, and you will only be notified when the block really gets destroyed.
     
  3. Offline

    Sicka_gp

    OK, thanks :)
     
  4. Offline

    Nitnelave

    Just a reminder : if you do set the priority to MONITOR, do not alter the event. Don't change it, don't cancel it, or anything. You can just, as the title implies, monitor it (look, but don't touch).​

    If you have to modify it, use the priority HIGHEST.
     
Thread Status:
Not open for further replies.

Share This Page