Skip to content

Instantly share code, notes, and snippets.

@whilb
Last active August 29, 2015 13:56
Show Gist options
  • Save whilb/8855245 to your computer and use it in GitHub Desktop.
Save whilb/8855245 to your computer and use it in GitHub Desktop.
Custom region and selection object example
//REGION CLASS
import org.bukkit.Location;
public class Region {
private Selection sel;
public Region(Selection sel) {
this.sel = sel;
}
public boolean locationIsInArea(Location l) {
int xmin = (sel.getFirst().getBlockX() < sel.getSecond().getBlockX()) ? sel.getFirst().getBlockX() : sel.getSecond().getBlockX();
int xmax = (sel.getFirst().getBlockX() > sel.getSecond().getBlockX()) ? sel.getFirst().getBlockX() : sel.getSecond().getBlockX();
int ymin = (sel.getFirst().getBlockY() < sel.getSecond().getBlockY()) ? sel.getFirst().getBlockY() : sel.getSecond().getBlockY();
int ymax = (sel.getFirst().getBlockY() > sel.getSecond().getBlockY()) ? sel
.getFirst().getBlockY() : sel.getSecond().getBlockY();
int zmin = (sel.getFirst().getBlockZ() < sel.getSecond().getBlockZ()) ? sel.getFirst().getBlockZ() : sel.getSecond().getBlockZ();
int zmax = (sel.getFirst().getBlockZ() > sel.getSecond().getBlockZ()) ? sel.getFirst().getBlockZ() : sel.getSecond().getBlockZ();
if ((l.getBlockX() <= xmax && l.getBlockX() >= xmin)&& (l.getBlockY() <= ymax && l.getBlockY() >= ymin) && (l.getBlockZ() <= zmax && l.getBlockZ() >= zmin)) {
return true;
}
return false;
}
public Selection getSelection(){
return sel;
}
}
//SELECTION CLASS
import org.bukkit.Location;
public class Selection {
private Location first;
private Location second;
public Selection() {
}
public void setFirst(Location first) {
this.first = first;
}
public void setSecond(Location second) {
this.second = second;
}
public Location getFirst() {
return this.first;
}
public Location getSecond() {
return this.second;
}
@Override
public String toString() {
return new String("FirstPoint: X:" + getFirst().getBlockX() + " Y:"
+ getFirst().getY() + " Z:" + getFirst().getZ()
+ "\nSecondPoint: X:" + getSecond().getX() + " Y:"
+ getSecond().getBlockY() + " Z:" + getSecond().getZ());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment