Removing drops in region

Discussion in 'Plugin Development' started by slater96, Sep 30, 2012.

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

    slater96

    Hi, if I have points like
    startx: 87.0
    starty: 71.0
    startz: 187.0
    endx: 92.0
    endy: 72.0
    endz: 192.0
    How would I make it clear the drops in that area only, I know how to do it for a whole world but not a region. Thanks
     
  2. Offline

    HouseMD

    generate an array of the blocks in the region first.

    Code:
    public static ArrayList<Location> gameArea = new ArrayList<>();
     
    public static void addBlocks(Player p, Location l1, Location l2) {
            int mix, max, miy, miz, may, maz;
     
            // //
            if (l1.getBlockX() < l2.getBlockX()) {
                mix = l1.getBlockX();
                max = l2.getBlockX();
            } else {
                mix = l2.getBlockX();
                max = l1.getBlockX();
            }
     
            // //
     
            if (l1.getBlockY() < l2.getBlockY()) {
                miy = l1.getBlockY();
                may = l2.getBlockY();
            } else {
                miy = l2.getBlockY();
                may = l1.getBlockY();
            }
            // //
     
            if (l1.getBlockZ() < l2.getBlockZ()) {
                miz = l1.getBlockZ();
                maz = l2.getBlockZ();
            } else {
                miz = l2.getBlockZ();
                maz = l1.getBlockZ();
            }
            // //
     
            for (int x = mix; x <= max; x++) {
                for (int y = miy; y <= may; y++) {
                    for (int z = miz; z <= maz; z++) {
                        Location loc = new Location(p.getWorld(), x, y, z);
                        gameArea.add(loc);
                        blockCounter++;
                    }
                }
            }
     
        }
    Then just check for items on the ground and if they are on any block inside that area, remove them.
     
  3. Offline

    gregthegeek

    Code:
    for(Item i : <world>.getEntitiesByClass(Item.class)) {
        Location l = i.getLocation();
        double x = l.getX();
        double y = l.getY();
        double z = l.getZ();
        if(x > startX && x < endX && y > startY && y < endY && z > startZ && z < startZ) {
            i.remove();
        }
    }
    
     
Thread Status:
Not open for further replies.

Share This Page