Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- THESE MUST BE IN SEPARATE CLASSES UNLESS YOU EDIT IT TO BE IN ONE
- import org.bukkit.Bukkit;
- import org.bukkit.Location;
- import org.bukkit.World;
- import org.bukkit.block.Block;
- public class Vector {
- private String worldName;
- private Location loc;
- //Instances
- public Vector(String world, int x, int y, int z, float yaw, float pitch) {
- this.loc = new Location(Bukkit.getWorld(world), x, y, z, yaw, pitch);
- this.worldName = world;
- }
- public Vector(String world, int x, int y, int z) {
- this(world, x, y, z, (float)0, (float)0);
- }
- public Vector(String world, double x, double y, double z, float yaw, float pitch) {
- this.loc = new Location(Bukkit.getWorld(world), x, y, z, yaw, pitch);
- this.worldName = world;
- }
- public Vector(String world, double x, double y, double z) {
- this(world, x, y, z, (float)0, (float)0);
- }
- public Vector(Location loc) {
- this.loc = loc;
- this.worldName = loc.getWorld().getName();
- }
- public void updateLocation() {
- this.loc = new Location(Bukkit.getWorld(this.getWorldName()), this.loc.getX(), this.loc.getY()
- , this.loc.getZ(), this.loc.getYaw(), this.loc.getPitch());
- }
- //Methods
- public Location getLocation() {
- return this.loc;
- }
- public double getX() {
- return this.loc.getX();
- }
- public double getY() {
- return this.loc.getY();
- }
- public double getZ() {
- return this.loc.getZ();
- }
- public float getYaw() {
- return this.loc.getYaw();
- }
- public float getPitch() {
- return this.loc.getPitch();
- }
- public int getBlockX() {
- return this.loc.getBlockX();
- }
- public int getBlockY() {
- return this.loc.getBlockY();
- }
- public int getBlockZ() {
- return this.loc.getBlockZ();
- }
- public Block getBlock() {
- return this.loc.getBlock();
- }
- public String getWorldName() {
- return this.worldName;
- }
- public World getWorld() {
- return this.loc.getWorld();
- }
- public static boolean compareBlock(Vector a, Vector b) {
- return a.getBlockX() == b.getBlockX() && a.getBlockY() == b.getBlockY()
- && a.getBlockZ() == b.getBlockZ() && a.getWorld().getName().equalsIgnoreCase(b.getWorld().getName());
- }
- public static boolean compareExact(Vector a, Vector b) {
- return a.getX() == b.getX() && a.getY() == b.getY()
- && a.getZ() == b.getZ() && a.getWorld().getName().equalsIgnoreCase(b.getWorld().getName());
- }
- public static Vector getStringToVector(String a) {
- if(!a.isEmpty()) {
- String[] b = a.split(",");
- if(b.length == 6) {
- return new Vector(b[0], Double.parseDouble(b[1]), Double.parseDouble(b[2])
- , Double.parseDouble(b[3]), Float.parseFloat(b[4]), Float.parseFloat(b[5]));
- }
- if(b.length == 4) {
- return new Vector(b[0], Double.parseDouble(b[1]), Double.parseDouble(b[2])
- , Double.parseDouble(b[3]));
- }
- return null;
- }else{
- return null;
- }
- }
- public static String getVectorToString(Vector a) {
- return a.getWorldName() + "," + a.getX() + "," + a.getY() + "," + a.getZ() + "," + a.getYaw() + "," + a.getPitch();
- }
- }
- import org.bukkit.Bukkit;
- import org.bukkit.Location;
- public class Cuboid {
- private Location loc1;
- private Location loc2;
- private String worldName;
- public Cuboid(Vector a, Vector b) {
- int x1 = Math.min(a.getLocation().getBlockX(), b.getLocation().getBlockX());
- int y1 = Math.min(a.getLocation().getBlockY(), b.getLocation().getBlockY());
- int z1 = Math.min(a.getLocation().getBlockZ(), b.getLocation().getBlockZ());
- int x2 = Math.max(a.getLocation().getBlockX(), b.getLocation().getBlockX());
- int y2 = Math.max(a.getLocation().getBlockY(), b.getLocation().getBlockY());
- int z2 = Math.max(a.getLocation().getBlockZ(), b.getLocation().getBlockZ());
- this.worldName = a.getWorldName();
- this.loc1 = new Location(Bukkit.getWorld(this.worldName), x1, y1, z1);
- this.loc2 = new Location(Bukkit.getWorld(this.worldName), x2, y2, z2);
- }
- public Location getMinimumPoint() {
- return this.loc1;
- }
- public Location getMaximumPoint() {
- return this.loc2;
- }
- public void updateLocations() {
- this.loc1 = new Location(Bukkit.getWorld(this.worldName), this.loc1.getBlockX(), this.loc1.getBlockY(), this.loc1.getBlockZ());
- this.loc2 = new Location(Bukkit.getWorld(this.worldName), this.loc2.getBlockX(), this.loc2.getBlockY(), this.loc2.getBlockZ());
- }
- public boolean contains(Location loc) {
- return loc.getBlockX() >= this.loc1.getBlockX() && loc.getBlockX() <= this.loc2.getBlockX()
- && loc.getBlockY() >= this.loc1.getBlockY() && loc.getBlockY() <= this.loc2.getBlockY()
- && loc.getBlockZ() >= this.loc1.getBlockZ() && loc.getBlockZ() <= this.loc2.getBlockZ();
- }
- public static String getCuboidToString(Cuboid cuboid) {
- Location min = cuboid.getMinimumPoint(), max = cuboid.getMaximumPoint();
- return Vector.getVectorToString(new Vector(cuboid.worldName, min.getBlockX(), min.getBlockY(), min.getBlockZ()))
- + ";" + Vector.getVectorToString(new Vector(cuboid.worldName, max.getBlockX(), max.getBlockY(), max.getBlockZ()));
- }
- public static Cuboid getStringToCuboid(String cube) {
- String[] split = cube.split(";");
- if(split.length == 2) {
- return new Cuboid(Vector.getStringToVector(split[0]), Vector.getStringToVector(split[1]));
- }else{
- return null;
- }
- }
- }
- /*
- public void setWalls(World world, Material mat) {
- for(int x = loc1.getBlockX(); x <= loc2.getBlockX(); ++x) {
- for(int y = loc1.getBlockY(); y <= loc2.getBlockY(); ++y) {
- new Location(world, x, y, loc1.getBlockZ()).getBlock().setType(mat);
- new Location(world, x, y, loc2.getBlockZ()).getBlock().setType(mat);
- }
- }
- for(int y = loc1.getBlockY(); y <= loc2.getBlockY(); ++y) {
- for(int z = loc1.getBlockZ(); z <= loc2.getBlockZ(); ++z) {
- new Location(world, loc1.getBlockX(), y, z).getBlock().setType(mat);
- new Location(world, loc2.getBlockX(), y, z).getBlock().setType(mat);
- }
- }
- }
- public void setOutline(World world, Material mat) {
- setWalls(world, mat);
- for(int x = loc1.getBlockX(); x <= loc2.getBlockX(); x++)
- for(int z = loc1.getBlockZ(); z <= loc2.getBlockZ(); z++) {
- new Location(world, x, loc1.getBlockY(), z).getBlock().setType(mat);
- new Location(world, x, loc2.getBlockY(), z).getBlock().setType(mat);
- }
- }
- public void setWhole(World world, Material mat) {
- for(int x = loc1.getBlockX(); x <= loc2.getBlockX(); x++)
- for(int y = loc1.getBlockY(); y <= loc2.getBlockY(); y++)
- for(int z = loc1.getBlockZ(); z <= loc2.getBlockZ(); z++)
- new Location(world,x,y,z).getBlock().setType(mat);
- }
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement