Removing item drops from explosion

Discussion in 'Plugin Help/Development/Requests' started by HeyAwesomePeople, Mar 10, 2015.

Thread Status:
Not open for further replies.
  1. Hello. I am having some trouble removing the drops from the blocks in an explosion. It seems to be such a simple task but I cannot get it working.
    Code:
    Code:
        @SuppressWarnings("deprecation")
        @EventHandler
        public void explode(EntityExplodeEvent e) {
            if (!e.blockList().isEmpty() && (e.isCancelled() == false)) {
                final List<BlockState> blocks = new ArrayList<BlockState>();
                Iterator<Block> iter = e.blockList().iterator();
                while (iter.hasNext()) {
                    Block b = iter.next();
                    if (!plugin.manager.cMap.isPlayerInMap(b.getLocation()) || b.hasMetadata("nodestroy")) {
                        iter.remove();
                    }
                }
                for (Block b : e.blockList()) {
                    b.getDrops().clear(); // clearing drops here?
                    if (b.getType() != Material.AIR) {
                        if (!blocks.contains(b.getState())) {
                            blocks.add(b.getState());
                            FallingBlock fb = b.getWorld().spawnFallingBlock(b.getLocation(), b.getType(), b.getData());
                            fb.setVelocity(new Vector(getRandomVel(-0.8, 0.8), getRandomVel(0.1, 0.5), getRandomVel(-0.8, 0.8)));
                        }
                    }
                }
                new BukkitRunnable() {
                    public void run() {
                        regen(blocks, true, plugin.config.regenSpeed);
                        this.cancel();
                    }
                }.runTaskTimer(plugin, plugin.config.regenDelay * 20L, plugin.config.regenDelay * 20L);
            }
        }
    Most of this code is part of an explosion regeneration method, but I have placed "b.getDrops().clear();" inside the first line of a loop through the blocklist, and since that loop cannot be cancelled, it for sure is going through all blocks.

    What is going on here? Making an explosion still allows items to drop from it.

    Thanks,
    HeyAwesomePeople
     
  2. Offline

    Cycryl

    i think there is event.setYield(0.0);
     
  3. @Cycryl Tried that. Blocks still drop. Could this be a problem with Spigot itself? I'm away from the computer now but I will attempt to do this in another plugin on a server by itself to see if I can replicate the issue.
     
  4. Offline

    mine-care

    Don't compare booleans as:
    Boolean== true/false instead use if(boolean) for true and if(!boolean) for false.
    It is bizar indeed. Try a bit of debug yoself and ill try to get deep in spigot and find a way to completely remove drops via reflection.

    EDIT:
    In nms class "Explosion" if you scroll down, you can see clearly where the EntityExplodeEvent is fired. So with some reverse engineering you can find where this class is initialized to override it or use reflection to set this list to an empty list directly without the use of event (if and only if the event is somehow broken, else use it);
    =D
     
    Last edited: Mar 13, 2015
  5. Offline

    mrCookieSlime

    Moved to Alternatives Section.
     
Thread Status:
Not open for further replies.

Share This Page