Package ch.njol.skript.util

Examples of ch.njol.skript.util.Direction


  @Nullable
  protected Block[] get(final Event e) {
    final Expression<Direction> direction = this.direction;
    if (direction != null && !from.isSingle()) {
      final Location[] ls = (Location[]) from.getArray(e);
      final Direction d = direction.getSingle(e);
      if (ls.length == 0 || d == null)
        return new Block[0];
      final Block[] bs = new Block[ls.length];
      for (int i = 0; i < ls.length; i++) {
        bs[i] = d.getRelative(ls[i]).getBlock();
      }
      return bs;
    }
    final ArrayList<Block> r = new ArrayList<Block>();
    final Iterator<Block> iter = iterator(e);
View Full Code Here


        }
        final Object o = from.getSingle(e);
        if (o == null)
          return null;
        final Location l = o instanceof Location ? (Location) o : ((Block) o).getLocation().add(0.5, 0.5, 0.5);
        final Direction d = direction.getSingle(e);
        if (d == null)
          return null;
        if (l.getBlock() == null)
          return null;
        return new BlockLineIterator(l, o != l ? d.getDirection((Block) o) : d.getDirection(l), SkriptConfig.maxTargetBlockDistance.value());
      } else {
        final Block b = (Block) from.getSingle(e);
        if (b == null)
          return null;
        assert end != null;
View Full Code Here

  protected void execute(final Event e) {
    lastSpawned = null;
    final Number v = velocity != null ? velocity.getSingle(e) : DEFAULT_SPEED;
    if (v == null)
      return;
    final Direction dir = direction != null ? direction.getSingle(e) : Direction.IDENTITY;
    if (dir == null)
      return;
    for (final Object shooter : shooters.getArray(e)) {
      for (final EntityData<?> d : types.getArray(e)) {
        if (shooter instanceof LivingEntity) {
          final Vector vel = dir.getDirection(((LivingEntity) shooter).getLocation()).multiply(v.doubleValue());
          if (Fireball.class.isAssignableFrom(d.getType())) {// fireballs explode in the shooter's face by default
            final Fireball projectile = (Fireball) ((LivingEntity) shooter).getWorld().spawn(((LivingEntity) shooter).getEyeLocation().add(vel.clone().normalize().multiply(0.5)), d.getType());
            ProjectileUtils.setShooter(projectile, shooter);
            projectile.setVelocity(vel);
            lastSpawned = projectile;
          } else if (Projectile.class.isAssignableFrom(d.getType())) {
            final Projectile projectile = ((LivingEntity) shooter).launchProjectile((Class<? extends Projectile>) d.getType());
            set(projectile, d);
            projectile.setVelocity(vel);
            lastSpawned = projectile;
          } else {
            final Location loc = ((LivingEntity) shooter).getLocation();
            loc.setY(loc.getY() + ((LivingEntity) shooter).getEyeHeight() / 2);
            final Entity projectile = d.spawn(loc);
            if (projectile != null)
              projectile.setVelocity(vel);
            lastSpawned = projectile;
          }
        } else {
          final Vector vel = dir.getDirection((Location) shooter).multiply(v.doubleValue());
          final Entity projectile = d.spawn((Location) shooter);
          if (projectile != null)
            projectile.setVelocity(vel);
          lastSpawned = projectile;
        }
View Full Code Here

  @Nullable
  public Direction convert(final Object o) {
    if (o instanceof Block) {
      final MaterialData d = ((Block) o).getType().getNewData(((Block) o).getData());
      if (d instanceof Directional)
        return new Direction(((Directional) d).getFacing(), 1);
      return null;
    } else if (o instanceof LivingEntity) {
      return new Direction(Direction.getFacing(((LivingEntity) o).getLocation(), horizontal), 1);
    }
    assert false;
    return null;
  }
View Full Code Here

        "String",
       
        // Skript
        Color.BLACK, StructureType.RED_MUSHROOM, WeatherType.THUNDER,
        new Date(System.currentTimeMillis()), new Timespan(1337), new Time(12000), new Timeperiod(1000, 23000),
        new Experience(15), new Direction(0, Math.PI, 10), new Direction(new double[] {0, 1, 0}),
        new EntityType(new SimpleEntityData(HumanEntity.class), 300), new CreeperData(), new SimpleEntityData(Snowball.class), new HorseData(Variant.SKELETON_HORSE), new WolfData(), new XpOrbData(50),
       
        // Bukkit - simple classes only
        GameMode.ADVENTURE, Biome.EXTREME_HILLS, DamageCause.FALL,
       
View Full Code Here

        assert d.direction != null; // checked in init()
        v.add(d.direction.clone().multiply(n2.doubleValue()));
        d = d.next;
      }
      assert v != null;
      return new Direction[] {new Direction(v)};
    } else if (relativeTo != null) {
      final Object o = relativeTo.getSingle(e);
      if (o == null)
        return new Direction[0];
      if (o instanceof Block) {
        final BlockFace f = Direction.getFacing((Block) o);
        if (f == BlockFace.SELF || horizontal && (f == BlockFace.UP || f == BlockFace.DOWN))
          return new Direction[] {Direction.ZERO};
        return new Direction[] {new Direction(f, ln)};
      } else {
        final Location l = ((Entity) o).getLocation();
        if (!horizontal) {
          if (!facing) {
            final Vector v = l.getDirection().normalize().multiply(ln);
            assert v != null;
            return new Direction[] {new Direction(v)};
          }
          final double pitch = Direction.pitchToRadians(l.getPitch());
          assert pitch >= -Math.PI / 2 && pitch <= Math.PI / 2;
          if (pitch > Math.PI / 4)
            return new Direction[] {new Direction(new double[] {0, ln, 0})};
          if (pitch < -Math.PI / 4)
            return new Direction[] {new Direction(new double[] {0, -ln, 0})};
        }
        double yaw = Direction.yawToRadians(l.getYaw());
        if (horizontal && !facing) {
          return new Direction[] {new Direction(new double[] {Math.cos(yaw) * ln, 0, Math.sin(yaw) * ln})};
        }
        yaw = Math2.mod(yaw, 2 * Math.PI);
        if (yaw >= Math.PI / 4 && yaw < 3 * Math.PI / 4)
          return new Direction[] {new Direction(new double[] {0, 0, ln})};
        if (yaw >= 3 * Math.PI / 4 && yaw < 5 * Math.PI / 4)
          return new Direction[] {new Direction(new double[] {-ln, 0, 0})};
        if (yaw >= 5 * Math.PI / 4 && yaw < 7 * Math.PI / 4)
          return new Direction[] {new Direction(new double[] {0, 0, -ln})};
        assert yaw >= 0 && yaw < Math.PI / 4 || yaw >= 7 * Math.PI / 4 && yaw < 2 * Math.PI;
        return new Direction[] {new Direction(new double[] {ln, 0, 0})};
      }
    } else {
      return new Direction[] {new Direction(horizontal ? Direction.IGNORE_PITCH : 0, yaw, ln)};
    }
  }
View Full Code Here

    return true;
  }
 
  @Override
  protected void execute(final Event e) {
    final Direction d = direction.getSingle(e);
    if (d == null)
      return;
    final Number v = speed != null ? speed.getSingle(e) : null;
    if (speed != null && v == null)
      return;
    final Entity[] ents = entities.getArray(e);
    for (final Entity en : ents) {
      assert en != null;
      final Vector mod = d.getDirection(en);
      if (v != null)
        mod.normalize().multiply(v.doubleValue());
      en.setVelocity(en.getVelocity().add(mod)); // REMIND add NoCheatPlus exception to players
    }
  }
View Full Code Here

TOP

Related Classes of ch.njol.skript.util.Direction

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.