Exemple #1
0
  private double calcHorizontalLength() {
    double length = 0.0;
    // Count the amount of horizontal tracks
    final BlockFace[] toCheck;
    if (this.instruction == BlockFace.SELF) {
      toCheck = FaceUtil.getFaces(this.railDirection);
    } else {
      toCheck = new BlockFace[] {this.instruction};
    }
    for (BlockFace face : toCheck) {
      int tlength = 0;
      // Get the type of rail required
      BlockFace checkface = face;
      if (checkface == BlockFace.NORTH) checkface = BlockFace.SOUTH;
      if (checkface == BlockFace.EAST) checkface = BlockFace.WEST;

      Block b = this.railsBlock;
      for (int i = 0; i < 20; i++) {
        // Next until invalid
        b = b.getRelative(face);
        Rails rr = BlockUtil.getRails(b);
        if (rr == null || rr.getDirection() != checkface) {
          break;
        }
        tlength++;
      }
      // Update the length
      if (tlength > length) {
        length = tlength;
      }
    }
    return length;
  }
Exemple #2
0
  private double calcDiagonalLength() {
    double length = 0.0;
    // Count the amount of zig-zagging curved tracks
    final BlockFace[] toCheck;
    if (this.instruction == BlockFace.SELF) {
      toCheck =
          new BlockFace[] {
            FaceUtil.rotate(this.railDirection, -2), FaceUtil.rotate(this.railDirection, 2)
          };
    } else {
      toCheck = new BlockFace[] {this.instruction};
    }
    for (BlockFace direction : toCheck) {
      double tlength = 0.0;
      // Find out the starting offset
      final BlockFace[] dirs = FaceUtil.getFaces(direction);
      BlockFace[] railDirs = FaceUtil.getFaces(this.railDirection);
      BlockFace railDirection = this.railDirection;

      Block b = this.railsBlock;
      for (int i = 0; i < 20; i++) {
        // Invert the direction
        railDirection = railDirection.getOppositeFace();
        railDirs[0] = railDirs[0].getOppositeFace();
        railDirs[1] = railDirs[1].getOppositeFace();
        // Obtain the new offset
        final BlockFace offset;
        if (LogicUtil.contains(railDirs[0], dirs)) {
          offset = railDirs[0];
        } else {
          offset = railDirs[1];
        }
        // Check if the new block is the expected curve direction
        b = b.getRelative(offset);
        Rails rr = BlockUtil.getRails(b);
        if (rr == null || rr.getDirection() != railDirection) {
          break;
        }
        tlength += MathUtil.HALFROOTOFTWO;
      }

      // Update the length
      if (tlength > length) {
        length = tlength;
      }
    }
    return length;
  }
Exemple #3
0
  public void main(Event e) {

    if (Util.config("bumpintherail", null).getBoolean("active")) {

      if (e.getEventName().equalsIgnoreCase("VehicleMoveEvent")) {
        VehicleMoveEvent event = (VehicleMoveEvent) e;

        if (event.getVehicle().getPassenger() instanceof Player) {
          Player player = (Player) event.getVehicle().getPassenger();

          if (!Util.config("bumpintherail", null)
              .getList("skipworld")
              .contains(player.getWorld().getName())) {
            if (event.getTo().getBlock().getType().equals(Material.RAILS)
                && event.getVehicle().getType().equals(EntityType.MINECART)) {
              if (!player.hasPermission("ijmh.immunity.rail")) {
                Rails rail = (Rails) event.getTo().getBlock().getState().getData();
                if (rail.isCurve()
                    && Util.pctChance(
                        Util.config("bumpintherail", null).getInt("chance"),
                        Util.config("bumpintherail", null).getInt("chancemod"))) {
                  event.getVehicle().eject();
                  Vector vector =
                      event.getTo().getDirection().midpoint(event.getFrom().getDirection());
                  player.setVelocity(
                      new Vector(
                          vector.getX() + Util.config("bumpintherail", null).getInt("distance"),
                          Util.config("bumpintherail", null).getInt("angle"),
                          vector.getZ() + Util.config("bumpintherail", null).getInt("distance")));
                  if (Util.config("bumpintherail", null).getBoolean("message"))
                    player.sendMessage(
                        ChatColor.GOLD + Util.chatColorText(Util.language.getString("lan_18")));
                }
              }
            }
          }
        }
      }
    }
  }