Java Code Examples for ch.njol.skript.Skript#EPSILON

The following examples show how to use ch.njol.skript.Skript#EPSILON . 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 File: DefaultComparators.java    From Skript with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Relation compare(final Number n1, final Number n2) {
	if (n1 instanceof Long && n2 instanceof Long)
		return Relation.get(n1.longValue() - n2.longValue());
	Double d1 = n1.doubleValue(),
		   d2 = n2.doubleValue();
	if (d1.isNaN() || d2.isNaN()) {
		return Relation.SMALLER;
	} else if (d1.isInfinite() || d2.isInfinite()) {
		return d1 > d2 ? Relation.GREATER : d1 < d2 ? Relation.SMALLER : Relation.EQUAL;
	} else {
		final double diff = d1 - d2;
		if (Math.abs(diff) < Skript.EPSILON)
			return Relation.EQUAL;
		return Relation.get(diff);
	}
}
 
Example 2
Source File: Money.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Money difference(final Money first, final Money second) {
	final double d = Math.abs(first.getAmount() - second.getAmount());
	if (d < Skript.EPSILON)
		return new Money(0);
	return new Money(d);
}
 
Example 3
Source File: EvtMoveOn.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Nullable
final static Block getOnBlock(final Location l) {
	Block block = l.getWorld().getBlockAt(l.getBlockX(), (int) (Math.ceil(l.getY()) - 1), l.getBlockZ());
	if (block.getType() == Material.AIR && Math.abs((l.getY() - l.getBlockY()) - 0.5) < Skript.EPSILON) { // Fences
		block = l.getWorld().getBlockAt(l.getBlockX(), l.getBlockY() - 1, l.getBlockZ());
		if (!fencePart.isOfType(block))
			return null;
	}
	return block;
}
 
Example 4
Source File: EffTeleport.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void execute(final Event e) {
	Location to = location.getSingle(e);
	if (to == null)
		return;
	if (Math.abs(to.getX() - to.getBlockX() - 0.5) < Skript.EPSILON && Math.abs(to.getZ() - to.getBlockZ() - 0.5) < Skript.EPSILON) {
		final Block on = to.getBlock().getRelative(BlockFace.DOWN);
		if (on.getType() != Material.AIR) {
			to = to.clone();
			// TODO 1.13 block height stuff
			//to.setY(on.getY() + Utils.getBlockHeight(on.getTypeId(), on.getData()));
		}
	}
	for (final Entity entity : entities.getArray(e)) {
		final Location loc;
		if (ignoreDirection(to.getYaw(), to.getPitch())) {
			loc = to.clone();
			loc.setPitch(entity.getLocation().getPitch());
			loc.setYaw(entity.getLocation().getYaw());
		} else {
			loc = to;
		}
		loc.getChunk().load();
		if (e instanceof PlayerRespawnEvent && entity.equals(((PlayerRespawnEvent) e).getPlayer()) && !Delay.isDelayed(e)) {
			((PlayerRespawnEvent) e).setRespawnLocation(loc);
		} else {
			entity.teleport(loc);
		}
	}
}
 
Example 5
Source File: AABB.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
public boolean contains(final Location l) {
	if (l.getWorld() != world)
		return false;
	return lowerBound.getX() - Skript.EPSILON < l.getX() && l.getX() < upperBound.getX() + Skript.EPSILON
			&& lowerBound.getY() - Skript.EPSILON < l.getY() && l.getY() < upperBound.getY() + Skript.EPSILON
			&& lowerBound.getZ() - Skript.EPSILON < l.getZ() && l.getZ() < upperBound.getZ() + Skript.EPSILON;
}
 
Example 6
Source File: BlockLineIterator.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("null")
private static Vector fitInWorld(final Location l, final Vector dir) {
	if (0 <= l.getBlockY() && l.getBlockY() < l.getWorld().getMaxHeight())
		return l.toVector();
	final double y = Math2.fit(0, l.getY(), l.getWorld().getMaxHeight());
	if (Math.abs(dir.getY()) < Skript.EPSILON)
		return new Vector(l.getX(), y, l.getZ());
	final double dy = y - l.getY();
	final double n = dy / dir.getY();
	return l.toVector().add(dir.clone().multiply(n));
}
 
Example 7
Source File: EvtMoveOn.java    From Skript with GNU General Public License v3.0 4 votes vote down vote up
final static int getBlockY(final double y, final Material id) {
	if (fencePart.isOfType(id) && Math.abs((y - Math.floor(y)) - 0.5) < Skript.EPSILON)
		return (int) Math.floor(y) - 1;
	return (int) Math.ceil(y) - 1;
}
 
Example 8
Source File: EffTeleport.java    From Skript with GNU General Public License v3.0 2 votes vote down vote up
/**
 * @param yaw Notch-yaw
 * @param pitch Notch-pitch
 * @return Whether the given pitch and yaw represent a cartesian coordinate direction
 */
private static boolean ignoreDirection(final float yaw, final float pitch) {
	return (pitch == 0 || Math.abs(pitch - 90) < Skript.EPSILON || Math.abs(pitch + 90) < Skript.EPSILON)
			&& (yaw == 0 || Math.abs(Math.sin(Math.toRadians(yaw))) < Skript.EPSILON || Math.abs(Math.cos(Math.toRadians(yaw))) < Skript.EPSILON);
}