Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 10th, 2012  |  syntax: Java  |  size: 5.45 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. package info.bytecraft.fill;
  2.  
  3. import info.bytecraft.chestbless.ChestBless;
  4.  
  5. import java.util.HashMap;
  6.  
  7. import org.bukkit.Location;
  8. import org.bukkit.Material;
  9. import org.bukkit.World;
  10. import org.bukkit.block.Block;
  11. import org.bukkit.entity.Player;
  12.  
  13. public class Fill {
  14.         private HashMap<Location, Material> undo = new HashMap<Location, Material>();
  15.  
  16.         private int x1, x2;
  17.         private int y1, y2;
  18.         private int z1, z2;
  19.  
  20.         private World world;
  21.  
  22.         private Player player;
  23.  
  24.         public Fill(){
  25.                 setX1(0);
  26.                 setX2(0);
  27.                 setY1(0);
  28.                 setY2(0);
  29.                 setZ1(0);
  30.                 setZ2(0);
  31.                 world = null;
  32.                 player = null;
  33.         }
  34.  
  35.         public Fill(int x1, int x2, int y1, int y2, int z1, int z2, final World world, Player player){
  36.                 this.setX1(x1); this.setX2(x2);
  37.                 this.setY1(y1); this.setY2(y2);
  38.                 this.setZ1(z1); this.setZ2(z2);
  39.                 this.world = world;
  40.                 this.player = player;
  41.         }
  42.  
  43.         public Fill(Location loc1, Location loc2, final World world, Player player){
  44.                 this.setX1(loc1.getBlockX()); this.setX2(loc2.getBlockX());
  45.                 this.setY1(loc1.getBlockY()); this.setY2(loc2.getBlockY());
  46.                 this.setZ1(loc1.getBlockZ()); this.setZ2(loc2.getBlockZ());
  47.                 this.world = world; this.player = player;
  48.         }
  49.  
  50.         public Player getPlayer() {
  51.                 return player;
  52.         }
  53.  
  54.         public int getX1() {
  55.                 return x1;
  56.         }
  57.  
  58.         public void setX1(int x1) {
  59.                 this.x1 = x1;
  60.         }
  61.  
  62.         public int getX2() {
  63.                 return x2;
  64.         }
  65.  
  66.         public void setX2(int x2) {
  67.                 this.x2 = x2;
  68.         }
  69.  
  70.         public int getY1() {
  71.                 return y1;
  72.         }
  73.  
  74.         public void setY1(int y1) {
  75.                 this.y1 = y1;
  76.         }
  77.  
  78.         public int getY2() {
  79.                 return y2;
  80.         }
  81.  
  82.         public void setY2(int y2) {
  83.                 this.y2 = y2;
  84.         }
  85.  
  86.         public int getZ1() {
  87.                 return z1;
  88.         }
  89.  
  90.         public void setZ1(int z1) {
  91.                 this.z1 = z1;
  92.         }
  93.  
  94.         public int getZ2() {
  95.                 return z2;
  96.         }
  97.  
  98.         public void setZ2(int z2) {
  99.                 this.z2 = z2;
  100.         }
  101.  
  102.         public World getWorld() {
  103.                 return world;
  104.         }
  105.  
  106.         public Location getLocation1(){
  107.                 return new Location(world, x1, y1, z1);
  108.         }
  109.  
  110.         public Location getLocation2(){
  111.                 return new Location(world, x2, y2, z2);
  112.         }
  113.  
  114.         public boolean contains(Location loc){
  115.                 BlockVector min = new BlockVector(Math.min(x1, x2), Math.min(y1, y2), Math.min(z1, z2));
  116.                 BlockVector max = new BlockVector(Math.max(x2, x2), Math.max(y1, y2), Math.max(z1, z2));
  117.                 BlockVector cur = new BlockVector(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
  118.                 return cur.isInAABB(min, max);
  119.         }
  120.  
  121.         public int setBlocks(Material mat){
  122.                 if(mat == null)return 0;
  123.                 int startX = Math.min(x1, x2);
  124.                 int endX = Math.max(x1, x2);
  125.  
  126.                 int startY = Math.min(y1, y2);
  127.                 int endY = Math.max(y1, y2);
  128.  
  129.                 int startZ = Math.min(z1, z2);
  130.                 int endZ = Math.max(z1, z2);
  131.                 undo.clear();
  132.                 for (int x = startX; x <= endX; x++) {
  133.                         for (int y = startY; y <= endY; y++) {
  134.                                 for (int z = startZ; z <= endZ; z++) {
  135.                                         Location loc = new Location(world, x,y,z);
  136.                                         Block block = loc.getBlock();
  137.                                         undo.put(loc, block.getType());
  138.                                         if(!ChestBless.isBless(block)){
  139.                                                 block.setType(mat);
  140.                                         }
  141.                                 }
  142.                         }
  143.                 }
  144.                 return this.getSize();
  145.         }
  146.  
  147.         public int replace(Material mat1, Material mat2){
  148.                 if(mat1 == null || mat2 == null){
  149.                         return 0;
  150.                 }
  151.                 int startX = Math.min(x1, x2);
  152.                 int endX = Math.max(x1, x2);
  153.  
  154.                 int startY = Math.min(y1, y2);
  155.                 int endY = Math.max(y1, y2);
  156.  
  157.                 int startZ = Math.min(z1, z2);
  158.                 int endZ = Math.max(z1, z2);
  159.  
  160.  
  161.                 undo.clear();
  162.                 for (int x = startX; x <= endX; x++) {
  163.                         for (int y = startY; y <= endY; y++) {
  164.                                 for (int z = startZ; z <= endZ; z++) {
  165.                                         Location loc = new Location(world, x, y ,z);
  166.                                         Block block = loc.getBlock();
  167.                                         undo.put(loc, block.getType());
  168.  
  169.                                         if(block.getType() == mat1){
  170.                                                 if(!ChestBless.isBless(block)){
  171.                                                         block.setType(mat2);
  172.                                                 }
  173.                                         }
  174.                                 }
  175.                         }
  176.                 }
  177.                 return this.getSize();
  178.         }
  179.  
  180.         public int replace(Material mat1, Material mat2, byte data){
  181.                 if(mat1 == null || mat2 == null){
  182.                         return 0;
  183.                 }
  184.  
  185.                 undo.clear();
  186.                 for(int x = Math.min(x2, x2); x <= Math.max(x1, x2); x++){
  187.                         for(int y = Math.min(y1, y2); y <= Math.max(y1, y2); y++){
  188.                                 for(int z = Math.min(z1, z2); z <= Math.max(z1, z2); z++){
  189.                                         Location loc = new Location(world, x, y ,z);
  190.                                         Block block = loc.getBlock();
  191.                                         undo.put(loc, block.getType());
  192.                                         if(block.getType() == mat1){
  193.                                                 if(!ChestBless.isBless(block)){
  194.                                                         block.setType(mat2);
  195.                                                         block.setData(data);
  196.                                                 }
  197.                                         }
  198.                                 }
  199.                         }
  200.                 }
  201.                 return getSize();
  202.         }
  203.  
  204.         public int undo(){
  205.                 Fill lastFill = FillPlugin.getLastFill(player);
  206.                 int startX = Math.min(lastFill.x1, lastFill.x2);
  207.                 int endX = Math.max(lastFill.x1, lastFill.x2);
  208.  
  209.                 int startY = Math.min(lastFill.y1, lastFill.y2);
  210.                 int endY = Math.max(y1, y2);
  211.  
  212.                 int startZ = Math.min(lastFill.z1, lastFill.z2);
  213.                 int endZ = Math.max(lastFill.z1, lastFill.z2);
  214.                 for (int x = startX; x <= endX; x++) {
  215.                         for (int y = startY; y <= endY; y++) {
  216.                                 for (int z = startZ; z <= endZ; z++) {
  217.                                         Location loc = new Location(world, x, y ,z);
  218.                                         if(undo.containsKey(loc)){
  219.                                                 if(!ChestBless.isBless(loc.getBlock())){
  220.                                                         loc.getBlock().setType(undo.get(loc));
  221.                                                 }
  222.                                         }
  223.                                 }
  224.                         }
  225.                 }
  226.                 return lastFill.getSize();
  227.         }
  228.  
  229.         public int getSize() {
  230.                 return (((Math.max(x1, x2) - Math.min(x1, x2)) + 1) *
  231.                                 ((Math.max(y1, y2) - Math.min(y1, y2)) + 1) *
  232.                                 ((Math.max(z1, z2) - Math.min(z1, z2)) + 1));
  233.         }
  234.  
  235.         public Fill copy(){
  236.                 return new Fill(this.getLocation1(), this.getLocation2(), this.world, this.player);
  237.         }
  238.        
  239.         public int paste(Location loc1, Location loc2){
  240.                 return 0;
  241.         }
  242.  
  243. }