Java Code Examples for org.bukkit.Location#subtract()

The following examples show how to use org.bukkit.Location#subtract() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: EffectLib   File: HillEffect.java    License: MIT License 6 votes vote down vote up
@Override
public void onRun() {
    Location location = getLocation();
    Vector v = new Vector();
    for (int x = 0; x <= particles; x++) {
        double y1 = Math.sin(Math.PI * x / particles);
        for (int z = 0; z <= particles; z++) {
            double y2 = Math.sin(Math.PI * z / particles);
            v.setX(edgeLength * x / particles).setZ(edgeLength * z / particles);
            v.setY(height * y1 * y2);
            VectorUtils.rotateAroundAxisY(v, yRotation);

            display(particle, location.add(v));
            location.subtract(v);
        }
    }
}
 
Example 2
Source Project: EffectLib   File: WarpEffect.java    License: MIT License 6 votes vote down vote up
@Override
public void onRun() {
    Location location = getLocation();
    if (step > rings) {
        step = 0;
    }
    double x, y, z;
    y = step * grow;
    location.add(0, y, 0);
    for (int i = 0; i < particles; i++) {
        double angle = (double) 2 * Math.PI * i / particles;
        x = Math.cos(angle) * radius;
        z = Math.sin(angle) * radius;
        location.add(x, 0, z);
        display(particle, location);
        location.subtract(x, 0, z);
    }
    location.subtract(0, y, 0);
    step++;
}
 
Example 3
Source Project: Crazy-Crates   File: NMS_v1_9_R2.java    License: MIT License 6 votes vote down vote up
@Override
public List<Location> getLocations(File f, Location loc) {
    loc = loc.subtract(2, 1, 2);
    List<Location> locations = new ArrayList<>();
    try {
        FileInputStream fis = new FileInputStream(f);
        NBTTagCompound nbt = NBTCompressedStreamTools.a(fis);
        short width = nbt.getShort("Width");
        short height = nbt.getShort("Height");
        short length = nbt.getShort("Length");
        fis.close();
        //paste
        for (int x = 0; x < width; ++x) {
            for (int y = 0; y < height; ++y) {
                for (int z = 0; z < length; ++z) {
                    final Location l = new Location(loc.getWorld(), x + loc.getX(), y + loc.getY(), z + loc.getZ());
                    locations.add(l);
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return locations;
}
 
Example 4
Source Project: EffectLib   File: VortexEffect.java    License: MIT License 6 votes vote down vote up
@Override
public void onRun() {
    Location location = getLocation();
    for (int x = 0; x < circles; x++) {
        for (int i = 0; i < helixes; i++) {
            double angle = step * radials + (2 * Math.PI * i / helixes);
            Vector v = new Vector(Math.cos(angle) * radius, step * grow, Math.sin(angle) * radius);
            VectorUtils.rotateAroundAxisX(v, (location.getPitch() + 90) * MathUtils.degreesToRadians);
            VectorUtils.rotateAroundAxisY(v, -location.getYaw() * MathUtils.degreesToRadians);

            location.add(v);
            display(particle, location);
            location.subtract(v);
        }
        step++;
    }
}
 
Example 5
Source Project: Crazy-Crates   File: NMS_v1_10_R1.java    License: MIT License 6 votes vote down vote up
@Override
public List<Location> getLocations(File f, Location loc) {
    loc = loc.subtract(2, 1, 2);
    List<Location> locations = new ArrayList<>();
    try {
        FileInputStream fis = new FileInputStream(f);
        NBTTagCompound nbt = NBTCompressedStreamTools.a(fis);
        short width = nbt.getShort("Width");
        short height = nbt.getShort("Height");
        short length = nbt.getShort("Length");
        fis.close();
        //paste
        for (int x = 0; x < width; ++x) {
            for (int y = 0; y < height; ++y) {
                for (int z = 0; z < length; ++z) {
                    final Location l = new Location(loc.getWorld(), x + loc.getX(), y + loc.getY(), z + loc.getZ());
                    locations.add(l);
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return locations;
}
 
Example 6
Source Project: EffectLib   File: DonutEffect.java    License: MIT License 6 votes vote down vote up
@Override
public void onRun() {
    Location location = getLocation();
    Vector v = new Vector();
    for (int i = 0; i < circles; i++) {
        double theta = 2 * Math.PI * i / circles;
        for (int j = 0; j < particlesCircle; j++) {
            double phi = 2 * Math.PI * j / particlesCircle;
            double cosPhi = Math.cos(phi);
            v.setX((radiusDonut + radiusTube * cosPhi) * Math.cos(theta));
            v.setY((radiusDonut + radiusTube * cosPhi) * Math.sin(theta));
            v.setZ(radiusTube * Math.sin(phi));

            VectorUtils.rotateVector(v, xRotation, yRotation, zRotation);

            display(particle, location.add(v));
            location.subtract(v);
        }
    }
}
 
Example 7
Source Project: Crazy-Crates   File: NMS_v1_12_R1.java    License: MIT License 6 votes vote down vote up
@Override
public List<Location> getLocations(File f, Location loc) {
    loc = loc.subtract(2, 1, 2);
    List<Location> locations = new ArrayList<>();
    try {
        FileInputStream fis = new FileInputStream(f);
        NBTTagCompound nbt = NBTCompressedStreamTools.a(fis);
        short width = nbt.getShort("Width");
        short height = nbt.getShort("Height");
        short length = nbt.getShort("Length");
        fis.close();
        //paste
        for (int x = 0; x < width; ++x) {
            for (int y = 0; y < height; ++y) {
                for (int z = 0; z < length; ++z) {
                    final Location l = new Location(loc.getWorld(), x + loc.getX(), y + loc.getY(), z + loc.getZ());
                    locations.add(l);
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return locations;
}
 
Example 8
Source Project: EffectLib   File: FountainEffect.java    License: MIT License 6 votes vote down vote up
@Override
public void onRun() {
    Location location = getLocation();
    for (int i = 1; i <= strands; i++) {
        double angle = 2 * i * Math.PI / strands + rotation;
        for (int j = 1; j <= particlesStrand; j++) {
            float ratio = (float) j / particlesStrand;
            double x, y, z;
            x = Math.cos(angle) * radius * ratio;
            y = Math.sin(Math.PI * j / particlesStrand) * height;
            z = Math.sin(angle) * radius * ratio;
            location.add(x, y, z);
            display(particle, location);
            location.subtract(x, y, z);
        }
    }
    for (int i = 0; i < particlesSpout; i++) {
        Vector v = RandomUtils.getRandomCircleVector().multiply(RandomUtils.random.nextFloat() * radius * radiusSpout);
        v.setY(RandomUtils.random.nextFloat() * heightSpout);
        location.add(v);
        display(particle, location);
        location.subtract(v);
    }
}
 
Example 9
Source Project: ArmorStandTools   File: Utils.java    License: MIT License 6 votes vote down vote up
static Location getLocationFacing(Location loc) {
    Location l = loc.clone();
    Vector v = l.getDirection();
    v.setY(0);
    v.multiply(3);
    l.add(v);
    l.setYaw(l.getYaw() + 180);
    int n;
    boolean ok = false;
    for (n = 0; n < 5; n++) {
        if (l.getBlock().getType().isSolid()) {
            l.add(0, 1, 0);
        } else {
            ok = true;
            break;
        }
    }
    if (!ok) {
        l.subtract(0, 5, 0);
    }
    return l;
}
 
Example 10
Source Project: EffectLib   File: CircleEffect.java    License: MIT License 6 votes vote down vote up
@Override
public void onRun() {
    Location location = getLocation();
    location.subtract(xSubtract, ySubtract, zSubtract);
    double inc = (2 * Math.PI) / particles;
    int steps = wholeCircle ? particles : 1;
    for (int i = 0; i < steps; i++) {
        double angle = step * inc;
        Vector v = new Vector();
        v.setX(Math.cos(angle) * radius);
        v.setZ(Math.sin(angle) * radius);
        VectorUtils.rotateVector(v, xRotation, yRotation, zRotation);
        if (enableRotation) {
            VectorUtils.rotateVector(v, angularVelocityX * step, angularVelocityY * step, angularVelocityZ * step);
        }
        display(particle, location.clone().add(v), 0, 30);
        step++;
    }
}
 
Example 11
Source Project: Crazy-Crates   File: NMS_v1_9_R2.java    License: MIT License 5 votes vote down vote up
@Override
public void pasteSchematic(File f, Location loc) {
    loc = loc.subtract(2, 1, 2);
    try {
        FileInputStream fis = new FileInputStream(f);
        NBTTagCompound nbt = NBTCompressedStreamTools.a(fis);
        short width = nbt.getShort("Width");
        short height = nbt.getShort("Height");
        short length = nbt.getShort("Length");
        byte[] blocks = nbt.getByteArray("Blocks");
        byte[] data = nbt.getByteArray("Data");
        fis.close();
        //paste
        for (int x = 0; x < width; ++x) {
            for (int y = 0; y < height; ++y) {
                for (int z = 0; z < length; ++z) {
                    int index = y * width * length + z * width + x;
                    final Location l = new Location(loc.getWorld(), x + loc.getX(), y + loc.getY(), z + loc.getZ());
                    int b = blocks[index] & 0xFF;//make the block unsigned, so that blocks with an id over 127, like quartz and emerald, can be pasted
                    final Block block = l.getBlock();
                    block.setType(Material.getMaterial(b));
                    block.setData(data[index]);
                    //you can check what type the block is here, like if(m.equals(Material.BEACON)) to check if it's a beacon
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 12
Source Project: Crazy-Crates   File: NMS_v1_11_R1.java    License: MIT License 5 votes vote down vote up
@Override
public void pasteSchematic(File f, Location loc) {
    loc = loc.subtract(2, 1, 2);
    try {
        FileInputStream fis = new FileInputStream(f);
        NBTTagCompound nbt = NBTCompressedStreamTools.a(fis);
        short width = nbt.getShort("Width");
        short height = nbt.getShort("Height");
        short length = nbt.getShort("Length");
        byte[] blocks = nbt.getByteArray("Blocks");
        byte[] data = nbt.getByteArray("Data");
        fis.close();
        //paste
        for (int x = 0; x < width; ++x) {
            for (int y = 0; y < height; ++y) {
                for (int z = 0; z < length; ++z) {
                    int index = y * width * length + z * width + x;
                    final Location l = new Location(loc.getWorld(), x + loc.getX(), y + loc.getY(), z + loc.getZ());
                    int b = blocks[index] & 0xFF;//make the block unsigned, so that blocks with an id over 127, like quartz and emerald, can be pasted
                    final Block block = l.getBlock();
                    block.setType(Material.getMaterial(b));
                    block.setData(data[index]);
                    //you can check what type the block is here, like if(m.equals(Material.BEACON)) to check if it's a beacon
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 13
Source Project: EffectLib   File: DiscoBallEffect.java    License: MIT License 5 votes vote down vote up
public void onRun() {
    Location location = getLocation();
    //Lines
    int mL = RandomUtils.random.nextInt(maxLines - 2) + 2;
    for (int m = 0; m < mL * 2; m++) {
        double x = RandomUtils.random.nextInt(max - max * (-1)) + max * (-1);
        double y = RandomUtils.random.nextInt(max - max * (-1)) + max * (-1);
        double z = RandomUtils.random.nextInt(max - max * (-1)) + max * (-1);
        if (direction == Direction.DOWN) {
            y = RandomUtils.random.nextInt(max * 2 - max) + max;
        } else if (direction == Direction.UP) {
            y = RandomUtils.random.nextInt(max * (-1) - max * (-2)) + max * (-2);
        }
        Location target = location.clone().subtract(x, y, z);
        if (target == null) {
            cancel();
            return;
        }
        Vector link = target.toVector().subtract(location.toVector());
        float length = (float) link.length();
        link.normalize();

        float ratio = length / lineParticles;
        Vector v = link.multiply(ratio);
        Location loc = location.clone().subtract(v);
        for (int i = 0; i < lineParticles; i++) {
            loc.add(v);
            display(lineParticle, loc, lineColor);
        }
    }

    //Sphere
    for (int i = 0; i < sphereParticles; i++) {
        Vector vector = RandomUtils.getRandomVector().multiply(sphereRadius);
        location.add(vector);
        display(sphereParticle, location, sphereColor);
        location.subtract(vector);
    }
}
 
Example 14
Source Project: EffectLib   File: ShieldEffect.java    License: MIT License 5 votes vote down vote up
@Override
public void onRun() {
    Location location = getLocation();
    for (int i = 0; i < particles; i++) {
        Vector vector = RandomUtils.getRandomVector().multiply(radius);
        if (!sphere) {
            vector.setY(Math.abs(vector.getY()));
        }
        location.add(vector);
        display(particle, location);
        location.subtract(vector);
    }
}
 
Example 15
Source Project: EffectLib   File: FlameEffect.java    License: MIT License 5 votes vote down vote up
@Override
public void onRun() {
    Location location = getLocation();
    for (int i = 0; i < 10; i++) {
        Vector v = RandomUtils.getRandomCircleVector().multiply(RandomUtils.random.nextDouble() * 0.6d);
        v.setY(RandomUtils.random.nextFloat() * 1.8);
        location.add(v);
        display(particle, location);
        location.subtract(v);
    }
}
 
Example 16
@EventHandler
@SuppressWarnings("unused")
public void onPlayerMove(PlayerMoveEvent e) {
    if (e.getTo() == null || !plugin.getWorldManager().isSkyAssociatedWorld(e.getTo().getWorld())) {
        return;
    }
    String islandNameAt = WorldGuardHandler.getIslandNameAt(e.getTo());
    if (islandNameAt == null) {
        return;
    }
    IslandInfo islandInfo = plugin.getIslandInfo(islandNameAt);
    if (islandInfo == null || islandInfo.getBans().isEmpty()) {
        return;
    }
    Player player = e.getPlayer();
    if (!player.isOp() && !player.hasPermission("usb.mod.bypassprotection") && isBlockedFromEntry(player, islandInfo)) {
        e.setCancelled(true);
        Location l = e.getTo().clone();
        l.subtract(islandInfo.getIslandLocation());
        Vector v = new Vector(l.getX(), l.getY(), l.getZ());
        v.normalize();
        v.multiply(1.5); // Bounce
        player.setVelocity(v);
        if (islandInfo.isBanned(player)) {
            plugin.notifyPlayer(player, tr("\u00a7cBanned:\u00a7e You are banned from this island."));
        } else {
            plugin.notifyPlayer(player, tr("\u00a7cLocked:\u00a7e That island is locked! No entry allowed."));
        }
    }
}
 
Example 17
@Override
public void onRun() {
    Location location = getLocation();
    if (oldT == 0) {
        oldT = heightScale + Math.PI / 16;
    } else {
        oldT = oldT + Math.PI / 16;
    }
    double xposition = radius * Math.cos(oldT);
    double yposition = radius * Math.sin(oldT);
    double zposition = radius * Math.sin(oldT);
    location.add(xposition, yposition, zposition);
    display(particle, location, particleColor);
    location.subtract(xposition, yposition, zposition);
}
 
Example 18
Source Project: EffectLib   File: CubeEffect.java    License: MIT License 4 votes vote down vote up
private void drawCubeOutline(Location location) {
    double xRotation = 0, yRotation = 0, zRotation = 0;
    if (enableRotation) {
        xRotation = step * angularVelocityX;
        yRotation = step * angularVelocityY;
        zRotation = step * angularVelocityZ;
    }
    float a = edgeLength / 2;
    // top and bottom
    double angleX, angleY;
    Vector v = new Vector();
    for (int i = 0; i < 4; i++) {
        angleY = i * Math.PI / 2;
        for (int j = 0; j < 2; j++) {
            angleX = j * Math.PI;
            for (int p = 0; p <= particles; p++) {
                v.setX(a).setY(a);
                v.setZ(edgeLength * p / particles - a);
                VectorUtils.rotateAroundAxisX(v, angleX);
                VectorUtils.rotateAroundAxisY(v, angleY);

                if (enableRotation) {
                    VectorUtils.rotateVector(v, xRotation, yRotation, zRotation);
                }
                display(particle, location.add(v));
                location.subtract(v);
            }
        }
        // pillars
        for (int p = 0; p <= particles; p++) {
            v.setX(a).setZ(a);
            v.setY(edgeLength * p / particles - a);
            VectorUtils.rotateAroundAxisY(v, angleY);

            if (enableRotation) {
                VectorUtils.rotateVector(v, xRotation, yRotation, zRotation);
            }
            display(particle, location.add(v));
            location.subtract(v);
        }
    }
}
 
Example 19
@Override
public void execute(CommandSender sender, String[] args) throws Exception {
	NovaPlayer nPlayer = PlayerManager.getPlayer(sender);

	if(nPlayer.getActiveSelection() != null) {
		nPlayer.getActiveSelection().reset();
	}

	NovaRegion region;
	if(args.length == 0) {
		region = nPlayer.getAtRegion();
	}
	else {
		String indexString = args[0];

		if(!NumberUtils.isNumeric(indexString)) {
			Message.CHAT_ENTERINTEGER.send(sender);
			return;
		}

		int index = Integer.parseInt(indexString);

		region = nPlayer.getGuild().getRegion(index);
	}

	if(region == null) {
		Message.CHAT_REGION_NOTFOUND.send(sender);
		return;
	}

	RegionSelection selection = new RegionSelectionImpl(nPlayer, RegionSelection.Type.ENLARGE, region);
	Location corner0 = selection.getCorner(0);
	Location corner1 = selection.getCorner(1);
	int diff = GroupManager.getGroup(sender).get(NovaGroupImpl.Key.REGION_ENLARGE_BLOCKS);

	if(corner0.getBlockX() < corner1.getBlockX()
			&& corner0.getBlockZ() < corner1.getBlockZ()) {
		corner0.add(-diff, 0, -diff);
		corner1.subtract(-diff, 0, -diff);
	}

	if(corner0.getBlockX() < corner1.getBlockX()
			&& corner0.getBlockZ() > corner1.getBlockZ()) {
		corner0.add(-diff, 0, diff);
		corner1.subtract(-diff, 0, diff);
	}

	if(corner0.getBlockX() > corner1.getBlockX()
			&& corner0.getBlockZ() > corner1.getBlockZ()) {
		corner0.add(diff, 0, diff);
		corner1.subtract(diff, 0, diff);
	}

	if(corner0.getBlockX() > corner1.getBlockX()
			&& corner0.getBlockZ() < corner1.getBlockZ()) {
		corner0.add(diff, 0, -diff);
		corner1.subtract(diff, 0, -diff);
	}

	Command.REGION_BUY.execute(sender, new String[0]);
}
 
Example 20
Source Project: EffectLib   File: CylinderEffect.java    License: MIT License 4 votes vote down vote up
@Override
public void onRun() {
    Location location = getLocation();
    if (sideRatio == 0) {
        calculateSideRatio();
    }
    Random r = RandomUtils.random;
    double xRotation = rotationX, yRotation = rotationY, zRotation = rotationZ;
    if (orient) {
        xRotation = Math.toRadians(90 - location.getPitch()) + rotationX;
        yRotation = Math.toRadians(180 - location.getYaw()) + rotationY;
    }
    if (enableRotation) {
        xRotation += step * angularVelocityX;
        yRotation += step * angularVelocityY;
        zRotation += step * angularVelocityZ;
    }
    for (int i = 0; i < particles; i++) {
        float multi = (solid) ? r.nextFloat() : 1;
        Vector v = RandomUtils.getRandomCircleVector().multiply(radius);
        if (r.nextFloat() <= sideRatio) {
            // SIDE PARTICLE
            v.multiply(multi);
            v.setY((r.nextFloat() * 2 - 1) * (height / 2));
        } else {
            // GROUND PARTICLE
            v.multiply(r.nextFloat());
            if (r.nextFloat() < 0.5) {
                // TOP
                v.setY(multi * (height / 2));
            } else {
                // BOTTOM
                v.setY(-multi * (height / 2));
            }
        }
        if (enableRotation || orient) {
            VectorUtils.rotateVector(v, xRotation, yRotation, zRotation);
        }
        display(particle, location.add(v));
        location.subtract(v);
    }
    display(particle, location);
    step++;
}