Get exploded blocks

Discussion in 'Plugin Development' started by Jncwhite01, Mar 12, 2017.

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

    Jncwhite01

    Hello, I am making a plugin which allows a pickaxe to create an explosion on block break and have got that working but have a problem using world guard regions

    Blocks inside the regions listed in config should be broken, while blocks outside that region, even if affected by the explosion, will have the event cancelled

    My current code:

    BlockBreakEvent

    Code:
    if(item.getItemMeta().getDisplayName().equals(plugin.getConfig().getString("Explosive.Name").replaceAll("&", "ยง")))
            {
                Bukkit.getServer().getLogger().info("A");
                if(item.getType().toString().equals(plugin.getConfig().getString("Explosive.Item")))
                {
                    Bukkit.getServer().getLogger().info("B");
                    for(ProtectedRegion r : set)
                    {
                        for(String name : plugin.getConfig().getStringList("Explosive.Regions"))
                        {
                            if(r.getId().equals(name.toLowerCase()))
                            {
                                Bukkit.getServer().getLogger().info("C");
                                world.createExplosion(loc, 4.0f);
                                return;
                            }
                            return;
                        }
                    }
                }
                return;   
            }
    BlockExplodeEvent

    Code:
    @EventHandler
        public void onBlockExplode(BlockExplodeEvent event)
        {
            Bukkit.getServer().getLogger().info("D");
            for(Block exploded : event.blockList())
            {
                Location loc = exploded.getLocation();
                World world = exploded.getWorld();
               
                RegionManager rm = plugin.getWorldGuard().getRegionManager(world);
                ApplicableRegionSet set = rm.getApplicableRegions(loc);
               
                for(ProtectedRegion r : set)
                {
                    if(!r.contains(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()))
                    {
                        Bukkit.getServer().getLogger().info("E");
                        event.setCancelled(true);
                    }
                }
            }
        }
    First time using the WorldGuard API so may have something wrong using that!
     
  2. Offline

    Caderape2

    @Jncwhite01 don't cancel the event
    Use event.blockList().remove(block) for remove a block from the list of explosed block
     
  3. Offline

    N00BHUN73R

    @Jncwhite01
    The guy above me, Cade, is correct, use event.blockList().remove(block);, buttt, there's a chance for a concurrent modification exception to be thrown
    What I've been told to do, is this:
    PHP:
    for(Block b : new ArrayList<>(event.blockList())) {
    and then just use the good ol, event.blocklist.remove stuff and it won't error out at all..
     
  4. Offline

    Jncwhite01

    Thank you both of you, will try that in abit when I can get on my PC and will try it out!
     
  5. Online

    timtower Administrator Administrator Moderator

    @Jncwhite01 Please check your quotes. Thing you quoted from me is unrelated to this.
     
  6. Offline

    Jncwhite01

    Sorry, didnt realise that was in my multi quote
     
Thread Status:
Not open for further replies.

Share This Page