I've got 2 problems!

Discussion in 'Plugin Development' started by TheSmallBones, Aug 27, 2013.

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

    TheSmallBones

    -snip-
    Okay problem solved. Now how do I get all blocks in an area? Like I have 2 coordinates and everything within that invisible rectaingle it makes I want gone!
     
  2. Offline

    LegoPal92

    This might help. It is for a minigame plugin that I am working on, Hope it helps.
    Code:
    import java.util.HashMap;
    import java.util.Map;
    import org.bukkit.Location;
    import org.bukkit.World;
    import org.bukkit.configuration.serialization.ConfigurationSerializable;
     
    public class Region
      implements ConfigurationSerializable
    {
      private int minX;
      private int minY;
      private int minZ;
      private int maxX;
      private int maxY;
      private int maxZ;
      private World world;
     
      public Region(Location loc1, Location loc2)
      {
        this.minX = Math.min(loc1.getBlockX(), loc2.getBlockX());
        this.minY = Math.min(loc1.getBlockY(), loc2.getBlockY());
        this.minZ = Math.min(loc1.getBlockZ(), loc2.getBlockZ());
        this.maxX = Math.max(loc1.getBlockX(), loc2.getBlockX());
        this.maxY = Math.max(loc1.getBlockY(), loc2.getBlockY());
        this.maxZ = Math.max(loc1.getBlockZ(), loc2.getBlockZ());
        this.world = loc2.getWorld();
      }
     
      public boolean isInside(Location loc)
      {
        if (loc.getWorld() != this.world) {
          return false;
        }
        if ((loc.getBlockX() >= this.minX) && (loc.getBlockX() <= this.maxX) &&
          (loc.getBlockY() >= this.minY) && (loc.getBlockY() <= this.maxY) &&
          (loc.getBlockZ() >= this.minZ) && (loc.getBlockZ() <= this.maxZ))
        {
          return true;
        }
        return false;
      }
     
      public Map<String, Object> serialize()
      {
        Map<String, Object> o = new HashMap<String, Object>();
        o.put("minX", Integer.valueOf(this.minX));
        o.put("minY", Integer.valueOf(this.minY));
        o.put("minZ", Integer.valueOf(this.minZ));
       
        o.put("maxX", Integer.valueOf(this.maxX));
        o.put("maxY", Integer.valueOf(this.maxY));
        o.put("maxZ", Integer.valueOf(this.maxZ));
     
        o.put("world", this.world.getName());
     
        return o;
      }
    }
    
     
  3. Offline

    AstramG

    Lets say you get all the locations and you have a variable for the list of locations called "locs"
    Code:java
    1. for (Location l : locs) {
    2. l.getBlock().setTypeId(0);
    3. }
     
Thread Status:
Not open for further replies.

Share This Page