Advertisement
Guest User

Untitled

a guest
Jan 5th, 2014
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.52 KB | None | 0 0
  1. THESE MUST BE IN SEPARATE CLASSES UNLESS YOU EDIT IT TO BE IN ONE
  2.  
  3. import org.bukkit.Bukkit;
  4. import org.bukkit.Location;
  5. import org.bukkit.World;
  6. import org.bukkit.block.Block;
  7.  
  8. public class Vector {
  9.    
  10.     private String worldName;
  11.     private Location loc;
  12.    
  13.     //Instances
  14.     public Vector(String world, int x, int y, int z, float yaw, float pitch) {
  15.         this.loc = new Location(Bukkit.getWorld(world), x, y, z, yaw, pitch);
  16.         this.worldName = world;
  17.     }
  18.    
  19.     public Vector(String world, int x, int y, int z) {
  20.         this(world, x, y, z, (float)0, (float)0);
  21.     }
  22.    
  23.     public Vector(String world, double x, double y, double z, float yaw, float pitch) {
  24.         this.loc = new Location(Bukkit.getWorld(world), x, y, z, yaw, pitch);
  25.         this.worldName = world;
  26.     }
  27.    
  28.     public Vector(String world, double x, double y, double z) {
  29.         this(world, x, y, z, (float)0, (float)0);
  30.     }
  31.    
  32.     public Vector(Location loc) {
  33.         this.loc = loc;
  34.         this.worldName = loc.getWorld().getName();
  35.     }
  36.    
  37.     public void updateLocation() {
  38.         this.loc = new Location(Bukkit.getWorld(this.getWorldName()), this.loc.getX(), this.loc.getY()
  39.                 , this.loc.getZ(), this.loc.getYaw(), this.loc.getPitch());
  40.     }
  41.    
  42.     //Methods
  43.     public Location getLocation() {
  44.         return this.loc;
  45.     }
  46.    
  47.     public double getX() {
  48.         return this.loc.getX();
  49.     }
  50.    
  51.     public double getY() {
  52.         return this.loc.getY();
  53.     }
  54.    
  55.     public double getZ() {
  56.         return this.loc.getZ();
  57.     }
  58.    
  59.     public float getYaw() {
  60.         return this.loc.getYaw();
  61.     }
  62.    
  63.     public float getPitch() {
  64.         return this.loc.getPitch();
  65.     }
  66.    
  67.     public int getBlockX() {
  68.         return this.loc.getBlockX();
  69.     }
  70.    
  71.     public int getBlockY() {
  72.         return this.loc.getBlockY();
  73.     }
  74.    
  75.     public int getBlockZ() {
  76.         return this.loc.getBlockZ();
  77.     }
  78.    
  79.     public Block getBlock() {
  80.         return this.loc.getBlock();
  81.     }
  82.    
  83.     public String getWorldName() {
  84.         return this.worldName;
  85.     }
  86.    
  87.     public World getWorld() {
  88.         return this.loc.getWorld();
  89.     }
  90.    
  91.     public static boolean compareBlock(Vector a, Vector b) {
  92.         return a.getBlockX() == b.getBlockX() && a.getBlockY() == b.getBlockY()
  93.                 && a.getBlockZ() == b.getBlockZ() && a.getWorld().getName().equalsIgnoreCase(b.getWorld().getName());
  94.     }
  95.    
  96.     public static boolean compareExact(Vector a, Vector b) {
  97.         return a.getX() == b.getX() && a.getY() == b.getY()
  98.                 && a.getZ() == b.getZ() && a.getWorld().getName().equalsIgnoreCase(b.getWorld().getName());
  99.     }
  100.    
  101.     public static Vector getStringToVector(String a) {
  102.         if(!a.isEmpty()) {
  103.             String[] b = a.split(",");
  104.             if(b.length == 6) {
  105.                 return new Vector(b[0], Double.parseDouble(b[1]), Double.parseDouble(b[2])
  106.                         , Double.parseDouble(b[3]), Float.parseFloat(b[4]), Float.parseFloat(b[5]));
  107.             }
  108.             if(b.length == 4) {
  109.                 return new Vector(b[0], Double.parseDouble(b[1]), Double.parseDouble(b[2])
  110.                         , Double.parseDouble(b[3]));
  111.             }
  112.             return null;
  113.         }else{
  114.             return null;
  115.         }
  116.     }
  117.    
  118.     public static String getVectorToString(Vector a) {
  119.         return a.getWorldName() + "," + a.getX() + "," + a.getY() + "," + a.getZ() + "," + a.getYaw() + "," + a.getPitch();
  120.     }
  121. }
  122.  
  123.  
  124.  
  125.  
  126.  
  127. import org.bukkit.Bukkit;
  128. import org.bukkit.Location;
  129.  
  130. public class Cuboid {
  131.    
  132.     private Location loc1;
  133.     private Location loc2;
  134.     private String worldName;
  135.    
  136.     public Cuboid(Vector a, Vector b) {
  137.         int x1 = Math.min(a.getLocation().getBlockX(), b.getLocation().getBlockX());
  138.         int y1 = Math.min(a.getLocation().getBlockY(), b.getLocation().getBlockY());
  139.         int z1 = Math.min(a.getLocation().getBlockZ(), b.getLocation().getBlockZ());
  140.         int x2 = Math.max(a.getLocation().getBlockX(), b.getLocation().getBlockX());
  141.         int y2 = Math.max(a.getLocation().getBlockY(), b.getLocation().getBlockY());
  142.         int z2 = Math.max(a.getLocation().getBlockZ(), b.getLocation().getBlockZ());
  143.         this.worldName = a.getWorldName();
  144.         this.loc1 = new Location(Bukkit.getWorld(this.worldName), x1, y1, z1);
  145.         this.loc2 = new Location(Bukkit.getWorld(this.worldName), x2, y2, z2);
  146.     }
  147.    
  148.     public Location getMinimumPoint() {
  149.         return this.loc1;
  150.     }
  151.    
  152.     public Location getMaximumPoint() {
  153.         return this.loc2;
  154.     }
  155.    
  156.     public void updateLocations() {
  157.         this.loc1 = new Location(Bukkit.getWorld(this.worldName), this.loc1.getBlockX(), this.loc1.getBlockY(), this.loc1.getBlockZ());
  158.         this.loc2 = new Location(Bukkit.getWorld(this.worldName), this.loc2.getBlockX(), this.loc2.getBlockY(), this.loc2.getBlockZ());
  159.     }
  160.    
  161.     public boolean contains(Location loc) {
  162.           return loc.getBlockX() >= this.loc1.getBlockX() && loc.getBlockX() <= this.loc2.getBlockX()
  163.               && loc.getBlockY() >= this.loc1.getBlockY() && loc.getBlockY() <= this.loc2.getBlockY()
  164.               && loc.getBlockZ() >= this.loc1.getBlockZ() && loc.getBlockZ() <= this.loc2.getBlockZ();
  165.     }
  166.    
  167.     public static String getCuboidToString(Cuboid cuboid) {
  168.         Location min = cuboid.getMinimumPoint(), max = cuboid.getMaximumPoint();
  169.         return Vector.getVectorToString(new Vector(cuboid.worldName, min.getBlockX(), min.getBlockY(), min.getBlockZ()))
  170.                 + ";" + Vector.getVectorToString(new Vector(cuboid.worldName, max.getBlockX(), max.getBlockY(), max.getBlockZ()));
  171.     }
  172.    
  173.     public static Cuboid getStringToCuboid(String cube) {
  174.         String[] split = cube.split(";");
  175.         if(split.length == 2) {
  176.             return new Cuboid(Vector.getStringToVector(split[0]), Vector.getStringToVector(split[1]));
  177.         }else{
  178.             return null;
  179.         }
  180.     }
  181. }
  182.  
  183. /*
  184. public void setWalls(World world, Material mat) {
  185.     for(int x = loc1.getBlockX(); x <= loc2.getBlockX(); ++x) {
  186.         for(int y = loc1.getBlockY(); y <= loc2.getBlockY(); ++y) {
  187.             new Location(world, x, y, loc1.getBlockZ()).getBlock().setType(mat);
  188.             new Location(world, x, y, loc2.getBlockZ()).getBlock().setType(mat);
  189.         }
  190.     }
  191.  
  192.     for(int y = loc1.getBlockY(); y <= loc2.getBlockY(); ++y) {
  193.         for(int z = loc1.getBlockZ(); z <= loc2.getBlockZ(); ++z) {
  194.             new Location(world, loc1.getBlockX(), y, z).getBlock().setType(mat);
  195.             new Location(world, loc2.getBlockX(), y, z).getBlock().setType(mat);
  196.         }
  197.     }
  198. }
  199.  
  200. public void setOutline(World world, Material mat) {
  201.     setWalls(world, mat);
  202.    
  203.     for(int x = loc1.getBlockX(); x <= loc2.getBlockX(); x++)
  204.         for(int z = loc1.getBlockZ(); z <= loc2.getBlockZ(); z++) {
  205.             new Location(world, x, loc1.getBlockY(), z).getBlock().setType(mat);
  206.             new Location(world, x, loc2.getBlockY(), z).getBlock().setType(mat);
  207.         }
  208. }
  209.  
  210. public void setWhole(World world, Material mat) {
  211.     for(int x = loc1.getBlockX(); x <= loc2.getBlockX(); x++)
  212.         for(int y = loc1.getBlockY(); y <= loc2.getBlockY(); y++)
  213.             for(int z = loc1.getBlockZ(); z <= loc2.getBlockZ(); z++)
  214.                 new Location(world,x,y,z).getBlock().setType(mat);
  215. }
  216. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement