best way to make regions?

Discussion in 'Plugin Development' started by boardinggamer, Dec 3, 2012.

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

    boardinggamer

    I want to make a region between 2 points with a way of checking if a player breaks a block in that region. What is the best way to go about this that will cause the least amount of lag or hopefully no lag.
     
  2. Offline

    microgeek

    Make use of Object Oriented Programing. Create a new class that has the variables for a region.

    Code:
    public class Region {
     
    private int startX;
    private int startY;
    private int startZ;
     
    private int endX;
    private int endY;
    private int endZ;
     
    public Region(int startX) {
    this.startX = startX;
    //ect, ect
    }
    //Create getters and setters
    } 
    Create a Set<Region> (look into Java generics if you don't understand this).
    regionSet.add(new Region(1, 2, 3, 4, 5, 6));
     
  3. Offline

    Barinade

    PHP:
        @EventHandler
        
    public void blockBreak(BlockBreakEvent e) {
            
    //block 1
            
    int minX 0;
            
    int minY 0;
            
    int minZ 0;
           
            
    //block 2
            
    int maxX 0;
            
    int maxY 0;
            
    int maxZ 0;
            
    Location l e.getBlock().getLocation();
            if (
    l.getBlockX() >= minX && l.getBlockX() <= maxX) {
                if (
    l.getBlockY() >= minY && l.getBlockY() <= maxY) {
                    if (
    l.getBlockZ() >= minZ && l.getBlockZ() <= maxZ) {
                        
    //block is within region
                    
    }
                }
            }
            
    //extra:
            
    for (int x=minX;x<maxX;x++) {
                for(
    int y=minY;y<maxY;y++) {
                    for (
    int z=minZ;z<maxZ;z++) {
                        
    //do something for every block in the region
                    
    }
                }
            }
        }
    My crap way of doing regions :p
     
Thread Status:
Not open for further replies.

Share This Page