Exemplo n.º 1
0
 public static Block GetLowestBlock(Location Loc) {
   Location loc = Loc.clone();
   Block Use = loc.getWorld().getBlockAt(loc);
   if (isBlockSolid(Use) || Use.isLiquid()) {
     return Use;
   } else {
     while (!isBlockSolid(Use) && !Use.isLiquid() && loc.getBlockY() > 0) {
       Use = loc.getWorld().getBlockAt(loc.add(0, -1, 0));
     }
     return loc.getWorld().getBlockAt(loc);
   }
 }
Exemplo n.º 2
0
 private void getFloor() {
   floorblock = null;
   for (int i = 0; i <= maxHeightFromGround; i++) {
     Block block = player.getEyeLocation().getBlock().getRelative(BlockFace.DOWN, i);
     if (GeneralMethods.isSolid(block) || block.isLiquid()) {
       floorblock = block;
       return;
     }
   }
 }
Exemplo n.º 3
0
  private void progress() {
    if (!hasEmptyWaterBottle()) {
      remove();
      return;
    }

    if (player.isDead() || !player.isOnline()) {
      remove();
      return;
    }

    if (player.getWorld() != location.getWorld()) {
      remove();
      return;
    }

    if (System.currentTimeMillis() < time + interval) return;

    time = System.currentTimeMillis();

    Vector direction = Methods.getDirection(location, player.getEyeLocation()).normalize();
    location = location.clone().add(direction);

    if (location == null || block == null) {
      remove();
      return;
    }

    if (location.getBlock().equals(block.getLocation().getBlock())) return;

    if (Methods.isRegionProtectedFromBuild(player, "WaterManipulation", location)) {
      remove();
      return;
    }

    if (location.distance(player.getEyeLocation())
        > Methods.waterbendingNightAugment(range, player.getWorld())) {
      remove();
      return;
    }

    if (location.distance(player.getEyeLocation()) <= 1.5) {
      fillBottle();
      return;
    }

    Block newblock = location.getBlock();
    if (Methods.isTransparentToEarthbending(player, newblock) && !newblock.isLiquid()) {
      block.revertBlock();
      block = new TempBlock(newblock, Material.WATER, full);
    } else {
      remove();
      return;
    }
  }
Exemplo n.º 4
0
 public WaterReturn(Player player, Block block) {
   if (instances.containsKey(player)) return;
   this.player = player;
   location = block.getLocation();
   if (Methods.canBend(player.getName(), "WaterManipulation")) {
     if (!Methods.isRegionProtectedFromBuild(player, "WaterManipulation", location)
         && Methods.canBend(player.getName(), "WaterManipulation")) {
       if (Methods.isTransparentToEarthbending(player, block) && !block.isLiquid())
         this.block = new TempBlock(block, Material.WATER, full);
     }
   }
   // if (ID >= Integer.MAX_VALUE) {
   // ID = Integer.MIN_VALUE;
   // }
   // id = ID++;
   instances.put(player, this);
 }
  /**
   * Find a suitable location for a player to teleport to in the given world. This method uses
   * WorldBorder as the configuration source.
   *
   * @param world World to teleport to
   * @return Location to teleport to
   */
  private Location findSuitableLocationWB(World world) {
    BorderData borderData = WorldBorder.plugin.GetWorldBorder(world.getName());

    if (borderData == null) {
      // throw new IllegalStateException(String.format("World %1$s isn't configured in
      // WorldBorder.", world.getName()));
      return null;
    }

    for (int i = 0; i < 100; i++) {
      Vector position = new Vector(borderData.getX(), 0.0, borderData.getZ());

      // Get a uniform-area random position within the world border's geometry
      boolean isRound = (borderData.getShape() == null) ? true : borderData.getShape();
      if (isRound) {
        position.add(
            getRandomPointInEllipse(random, borderData.getRadiusX(), borderData.getRadiusZ()));
      } else {
        position.add(
            getRandomPointInRectangle(random, borderData.getRadiusX(), borderData.getRadiusZ()));
      }

      // Ensure there's a solid block to stand on
      Block highestBlock = world.getHighestBlockAt(position.getBlockX(), position.getBlockZ());
      if (highestBlock == null) continue;
      highestBlock = highestBlock.getRelative(0, -1, 0); // Because the javadocs are wrong.
      if (highestBlock == null) continue;
      if (highestBlock.getY() < 1 || highestBlock.getY() >= world.getMaxHeight() - 2) continue;
      if (highestBlock.isLiquid()) continue;

      position.setX((double) position.getBlockX() + 0.5);
      position.setY(highestBlock.getY() + 2);
      position.setZ((double) position.getBlockZ() + 0.5);

      return position.toLocation(world, getRandomYaw(), 0.0f);
    }

    return null;
  }
Exemplo n.º 6
0
  private void initializeLocations() {
    Location location = origin.clone();
    locations.add(location);

    while (location.distance(origin) < RADIUS) {
      location = location.clone().add(direction);
      for (int i : new int[] {1, 2, 3, 0, -1}) {
        Location loc;
        loc = location.clone().add(0, i, 0);
        Block topBlock = loc.getBlock();
        Block botBlock = loc.clone().add(0, -1, 0).getBlock();
        if (BlockTools.isTransparentToEarthbending(player, topBlock)
            && !topBlock.isLiquid()
            && BlockTools.isEarthbendable(player, botBlock)) {
          location = loc.clone().add(0, -1, 0);
          locations.add(location);
          break;
        } else if (i == -1) {
          return;
        }
      }
    }
  }
Exemplo n.º 7
0
  private void progress() {
    BendingPlayer bPlayer = GeneralMethods.getBendingPlayer(player.getName());
    if (player.isDead()
        || !player.isOnline()
        || !GeneralMethods.canBend(player.getName(), "IceBlast")
        || bPlayer.isOnCooldown("IceBlast")) {
      cancel();
      return;
    }

    if (!player.getWorld().equals(location.getWorld())) {
      cancel();
      return;
    }

    if (player.getEyeLocation().distance(location) >= range) {
      if (progressing) {
        breakParticles(20);
        cancel();
        returnWater();
      } else {
        breakParticles(20);
        cancel();
      }
      return;
    }

    if ((GeneralMethods.getBoundAbility(player) == null
            || !GeneralMethods.getBoundAbility(player).equalsIgnoreCase("IceBlast"))
        && prepared) {
      cancel();
      return;
    }

    if (System.currentTimeMillis() < time + interval) return;

    time = System.currentTimeMillis();

    if (progressing) {

      Vector direction;

      if (location.getBlockY() == firstdestination.getBlockY()) settingup = false;

      if (location.distance(destination) <= 2) {
        cancel();
        returnWater();
        return;
      }

      if (settingup) {
        direction = GeneralMethods.getDirection(location, firstdestination).normalize();
      } else {
        direction = GeneralMethods.getDirection(location, destination).normalize();
      }

      location.add(direction);

      Block block = location.getBlock();

      if (block.equals(sourceblock)) return;

      source.revertBlock();
      source = null;

      if (EarthMethods.isTransparentToEarthbending(player, block) && !block.isLiquid()) {
        GeneralMethods.breakBlock(block);
      } else if (!WaterMethods.isWater(block)) {
        breakParticles(20);
        cancel();
        returnWater();
        return;
      }

      if (GeneralMethods.isRegionProtectedFromBuild(player, "IceBlast", location)) {
        cancel();
        returnWater();
        return;
      }

      for (Entity entity : GeneralMethods.getEntitiesAroundPoint(location, affectingradius)) {
        if (entity.getEntityId() != player.getEntityId() && entity instanceof LivingEntity) {
          affect((LivingEntity) entity);
          progressing = false;
          returnWater();
        }
      }

      if (!progressing) {
        cancel();
        return;
      }

      sourceblock = block;
      source = new TempBlock(sourceblock, Material.PACKED_ICE, data);

      for (int x = 0; x < 10; x++) {
        ParticleEffect.ITEM_CRACK.display(
            new ParticleEffect.ItemData(Material.ICE, (byte) 0),
            new Vector(
                ((Math.random() - 0.5) * .5),
                ((Math.random() - 0.5) * .5),
                ((Math.random() - 0.5) * .5)),
            .5f,
            location,
            257.0D);
        ParticleEffect.SNOW_SHOVEL.display(
            location,
            (float) (Math.random() - 0.5),
            (float) (Math.random() - 0.5),
            (float) (Math.random() - 0.5),
            0,
            5);
      }
      if (GeneralMethods.rand.nextInt(4) == 0) {
        WaterMethods.playIcebendingSound(location);
      }
      location = location.add(direction.clone());

    } else if (prepared) {
      WaterMethods.playFocusWaterEffect(sourceblock);
    }
  }
Exemplo n.º 8
0
  @Override
  public void populate(World world, Random rand, Chunk chunk) {
    // 30% chance of ever even happening (make it rare)
    if (rand.nextInt(100) > 70) return;
    // Get the first block in the operation
    Block first = getHighestSolidBlock(chunk, 0, 0);
    // No liquids pl0x
    if (first.isLiquid()) return;
    int f = first.getY();
    int nf = 0;
    // iterate through the heightmap and see how many blocks are on the same level
    Block test = null;
    for (int x = 0; x < 16; x++)
      for (int z = 0; z < 16; z++) {
        if ((test = getHighestSolidBlock(chunk, x, z)).getY() != f) {
          nf++;
        }
        // But no water!
        if (test.isLiquid()
            || test.getType().name().toLowerCase().contains("water")
            || test.getY() < 66) {
          return;
        }
      }
    // If there's more than this not level, cancel the operation
    if (nf > 2) return;

    int center = 8;
    int width = 5;

    int wsqr = width * width;
    int wmsqr = (width - 1) * (width - 1);

    int levels = 1 + rand.nextInt(2);
    int height = 5;

    int f0 = f;
    // Then build the pillar
    for (int x = 0; x < 16; x++)
      for (int z = 0; z < 16; z++) {
        // use distance squared for speed
        for (int i = 0; i < levels; i++) {
          f = f0 + height * i;
          int dsqr =
              Math.abs(center - x) * Math.abs(center - x)
                  + Math.abs(center - z) * Math.abs(center - z);
          if (dsqr <= wsqr && dsqr >= wmsqr) {
            for (int y = f; y < height + f && y < 128; y++) {
              if (y == height + f - 1 && i == levels - 1) {
                chunk.getBlock(x, y, z).setType(Material.FENCE);
              } else {
                chunk.getBlock(x, y, z).setType(Material.WOOD);
              }
            }
          } else if (dsqr <= wsqr) {
            // Floor/Hole
            if (i > 0 && x == 8 && z == 11) chunk.getBlock(x, f, z).setType(Material.AIR);
            else chunk.getBlock(x, f, z).setType(Material.WOOD);
            // Ceil/Hole
            if (x == 8 && z == 11) chunk.getBlock(x, f + height - 1, z).setType(Material.AIR);
            else chunk.getBlock(x, f + height - 1, z).setType(Material.WOOD);
          }
        }
      }
  }
Exemplo n.º 9
0
 @Override
 public boolean canSpawn(World world, int x, int z) {
   Block block = world.getHighestBlockAt(x, z).getRelative(BlockFace.DOWN);
   return !block.isLiquid() && !block.isEmpty() && !noSpawnFloors.contains(block.getType());
 }
Exemplo n.º 10
0
  private static void buildTree(World world, XYZ[] snakeBlocks) {
    // cut the snake into slices, this is my lab report
    HashMap<Integer, ArrayList<Block>> slices = new HashMap<Integer, ArrayList<Block>>();
    // System.out.println(snakeBlocks.length);
    for (XYZ loc : snakeBlocks) {
      Block block = world.getBlockAt(loc.x, loc.y, loc.z);
      if (block.isEmpty() && !block.isLiquid() && block.getType() != Material.BEDROCK) {
        if (slices.containsKey(Integer.valueOf(loc.y))) {
          slices.get(Integer.valueOf(loc.y)).add(block);
        } else {
          slices.put(Integer.valueOf(loc.y), new ArrayList<Block>());
          slices.get(Integer.valueOf(loc.y)).add(block);
        }
      }
    }

    ArrayList<Integer> sortedKeys = new ArrayList<Integer>(slices.keySet());
    Collections.sort(sortedKeys);
    int low = sortedKeys.get(0);
    int high = sortedKeys.get(sortedKeys.size() - 1);
    // boolean buildLayer1 = false;
    boolean buildLayer2 = false;
    boolean buildLayer3 = false;
    boolean buildLayer4 = false;
    for (Integer key : sortedKeys) {
      ArrayList<Block> slice = slices.get(key);
      for (Block b : slice) {
        b.setTypeIdAndData(17, (byte) 1, false);
      }
      //			if (!buildLayer1) {
      //				ArrayList<Block> toBranches = new ArrayList<Block>();
      //				for (Block b : slice) {
      //					if (b.getY()-low >= (high-low)-12 && checkBlockIsOnBorderOfSlice(b, slice)) {
      //						toBranches.add(b);
      //						buildLayer1 = true;
      //					}
      //				}
      //				buildTreeLayer1(toBranches);
      //			}
      if (!buildLayer2) {
        ArrayList<Block> toBranches = new ArrayList<Block>();
        for (Block b : slice) {
          if (b.getY() - low >= (high - low) - 8 && checkBlockIsOnBorderOfSlice(b, slice)) {
            toBranches.add(b);
            buildLayer2 = true;
          }
        }
        buildTreeLayer2(toBranches);
      }
      if (!buildLayer3) {
        ArrayList<Block> toBranches = new ArrayList<Block>();
        for (Block b : slice) {
          if (b.getY() - low >= (high - low) - 4 && checkBlockIsOnBorderOfSlice(b, slice)) {
            toBranches.add(b);
            buildLayer3 = true;
          }
        }
        buildTreeLayer3(toBranches);
      }
      if (!buildLayer4) {
        ArrayList<Block> toBranches = new ArrayList<Block>();
        for (Block b : slice) {
          if (b.getY() - low >= (high - low) && checkBlockIsOnBorderOfSlice(b, slice)) {
            toBranches.add(b);
            buildLayer4 = true;
          }
        }
        buildTreeLayer4(toBranches);
      }
    }
  }
Exemplo n.º 11
0
  public void attachRocketBoots(Player player, ItemStack boots) {

    if (gamemodeCheck.check(player, GameMode.CREATIVE, GameMode.SPECTATOR)) {
      commonString.messageSend(
          RocketInit.getPlugin(), player, true, RocketLanguage.RB_GAMEMODE_ERROR);
      disableRocketBoots(player, false, false, false, false, false);
      return;
    }

    UUID playerUUID = player.getUniqueId();

    ItemMeta rocketMeta = boots.getItemMeta();
    Block blockMiddle = player.getLocation().getBlock().getRelative(BlockFace.SELF);

    Boolean isWaterVariant = false;
    Boolean isRunnerVariant = false;

    String[] rocketMessage = new String[3];
    rocketMessage[0] = RocketLanguage.RB_ACTIVATE;

    switch (rocketMeta.getLore().size()) {
      case 1:
        rocketMessage[1] = RocketLanguage.RB_VARIANT + RocketLanguage.RB_NOT_FOUND;
        rocketMessage[2] = RocketLanguage.RB_ENHANCE + RocketLanguage.RB_NOT_FOUND;
        RocketInit.rocketVariant.put(playerUUID, Variant.ORIGINAL);
        RocketInit.rocketEnhancement.put(playerUUID, RocketEnhancement.Enhancement.NOTHING);
        break;

      case 2:
        String loreLine = ChatColor.stripColor(rocketMeta.getLore().get(1));

        if (Variant.isVariant(loreLine)) {
          Variant variantType = Variant.getEnum(loreLine);
          if (variantType != null) {
            rocketMessage[1] = RocketLanguage.RB_VARIANT + loreLine;
            rocketMessage[2] = RocketLanguage.RB_ENHANCE + RocketLanguage.RB_NOT_FOUND;

            RocketInit.rocketVariant.put(playerUUID, variantType);
            RocketInit.rocketEnhancement.put(playerUUID, RocketEnhancement.Enhancement.NOTHING);

            if (variantType.equals(Variant.WATER)) isWaterVariant = true;
            if (variantType.equals(Variant.RUNNER)) isRunnerVariant = true;
          }
        }

        if (RocketEnhancement.Enhancement.isEnhancement(loreLine)) {
          RocketEnhancement.Enhancement enhancementType =
              RocketEnhancement.Enhancement.getEnum(loreLine);
          if (enhancementType != null) {
            rocketMessage[1] = RocketLanguage.RB_VARIANT + RocketLanguage.RB_NOT_FOUND;
            rocketMessage[2] = RocketLanguage.RB_ENHANCE + loreLine;

            RocketInit.rocketVariant.put(playerUUID, Variant.ORIGINAL);
            RocketInit.rocketEnhancement.put(playerUUID, enhancementType);
          }
        }
        break;

      case 3:
        String variantLore = ChatColor.stripColor(rocketMeta.getLore().get(1));
        String enhancementLore = ChatColor.stripColor(rocketMeta.getLore().get(2));

        Variant variantType = Variant.getEnum(variantLore);
        RocketEnhancement.Enhancement enhancementType =
            RocketEnhancement.Enhancement.getEnum(enhancementLore);

        if (variantType != null && enhancementType != null) {
          rocketMessage[1] = RocketLanguage.RB_VARIANT + variantLore;
          RocketInit.rocketVariant.put(playerUUID, variantType);

          if (variantType.equals(Variant.WATER)) isWaterVariant = true;
          if (variantType.equals(Variant.RUNNER)) isRunnerVariant = true;

          rocketMessage[2] = RocketLanguage.RB_ENHANCE + enhancementLore;
          RocketInit.rocketEnhancement.put(playerUUID, enhancementType);
        }
        break;
    }

    if (!isWaterVariant && blockMiddle.isLiquid()) {
      RocketInit.rocketWater.add(playerUUID);
      commonString.messageSend(
          RocketInit.getPlugin(), player, true, RocketLanguage.RB_WATER_WARNING);
      return;
    }

    if (RocketInit.rocketVariant.get(playerUUID) == null
        || RocketInit.rocketEnhancement.get(playerUUID) == null) {
      commonString.messageSend(RocketInit.getPlugin(), player, true, RocketLanguage.RB_FAIL_ATTACH);
      disableRocketBoots(player, false, false, false, false, false);
      return;
    }

    if (RocketInit.rocketVariant.get(playerUUID) != Variant.ORIGINAL
        && player.getWorld().getName().equals("world_nether")) {
      commonString.messageSend(RocketInit.getPlugin(), player, true, RocketLanguage.RB_NETHER);
      disableRocketBoots(player, false, false, false, false, false);
      return;
    }

    if (player.getInventory().getBoots() == null)
      if (gamemodeCheck.check(player, GameMode.SURVIVAL, GameMode.ADVENTURE)) {

        commonString.messageSend(RocketInit.getPlugin(), player, true, rocketMessage);
        if (!isRunnerVariant) player.setAllowFlight(true);
        RocketInit.rocketPower.put(playerUUID, getBootPowerLevel(boots));
      }
  }
Exemplo n.º 12
0
 /**
  * Determine whether a given block is a either empty or liquid (but not lava)
  *
  * @param b the block to check
  * @return whether the block is suitable
  */
 public static boolean isSpaceForPlayer(Block b) {
   return (b.isEmpty() || b.isLiquid())
       && b.getType() != Material.LAVA
       && b.getType() != Material.STATIONARY_LAVA;
 }
  private boolean progress() {
    if (player.isDead()
        || !player.isOnline()
        || !GeneralMethods.canBend(player.getName(), "EarthBlast")) {
      breakBlock();
      return false;
    }
    if (System.currentTimeMillis() - time >= interval) {
      time = System.currentTimeMillis();

      if (falling) {
        breakBlock();
        return false;
      }

      if (!EarthMethods.isEarthbendable(player, sourceblock)
          && sourceblock.getType() != Material.COBBLESTONE) {
        instances.remove(id);
        return false;
      }

      if (!progressing && !falling) {

        if (GeneralMethods.getBoundAbility(player) == null) {
          unfocusBlock();
          return false;
        }

        if (!GeneralMethods.getBoundAbility(player).equalsIgnoreCase("EarthBlast")) {
          unfocusBlock();
          return false;
        }

        if (sourceblock == null) {
          instances.remove(id);
          return false;
        }
        if (!player.getWorld().equals(sourceblock.getWorld())) {
          unfocusBlock();
          return false;
        }
        if (sourceblock.getLocation().distance(player.getLocation()) > preparerange) {
          unfocusBlock();
          return false;
        }
      }

      if (falling) {
        breakBlock();

      } else {
        if (!progressing) {
          return false;
        }

        if (sourceblock.getY() == firstdestination.getBlockY()) {
          settingup = false;
        }

        Vector direction;
        if (settingup) {
          direction = GeneralMethods.getDirection(location, firstdestination).normalize();
        } else {
          direction = GeneralMethods.getDirection(location, destination).normalize();
        }

        location = location.clone().add(direction);

        WaterMethods.removeWaterSpouts(location, player);
        AirMethods.removeAirSpouts(location, player);

        Block block = location.getBlock();
        if (block.getLocation().equals(sourceblock.getLocation())) {
          location = location.clone().add(direction);
          block = location.getBlock();
        }

        if (EarthMethods.isTransparentToEarthbending(player, block) && !block.isLiquid()) {
          GeneralMethods.breakBlock(block);
        } else if (!settingup) {
          breakBlock();
          return false;
        } else {
          location = location.clone().subtract(direction);
          direction = GeneralMethods.getDirection(location, destination).normalize();
          location = location.clone().add(direction);

          WaterMethods.removeWaterSpouts(location, player);
          AirMethods.removeAirSpouts(location, player);
          double radius = FireBlast.AFFECTING_RADIUS;
          Player source = player;
          if (EarthBlast.annihilateBlasts(location, radius, source)
              || WaterManipulation.annihilateBlasts(location, radius, source)
              || FireBlast.annihilateBlasts(location, radius, source)) {
            breakBlock();
            return false;
          }

          Combustion.removeAroundPoint(location, radius);

          Block block2 = location.getBlock();
          if (block2.getLocation().equals(sourceblock.getLocation())) {
            location = location.clone().add(direction);
            block2 = location.getBlock();
          }

          if (EarthMethods.isTransparentToEarthbending(player, block) && !block.isLiquid()) {
            GeneralMethods.breakBlock(block);
          } else {
            breakBlock();
            return false;
          }
        }

        for (Entity entity :
            GeneralMethods.getEntitiesAroundPoint(location, FireBlast.AFFECTING_RADIUS)) {
          if (GeneralMethods.isRegionProtectedFromBuild(
              player, "EarthBlast", entity.getLocation())) {
            continue;
          }
          if (entity instanceof LivingEntity
              && (entity.getEntityId() != player.getEntityId() || hitself)) {

            AirMethods.breakBreathbendingHold(entity);

            Location location = player.getEyeLocation();
            Vector vector = location.getDirection();
            entity.setVelocity(vector.normalize().multiply(pushfactor));
            double damage = this.damage;
            if (EarthMethods.isMetal(sourceblock) && EarthMethods.canMetalbend(player)) {
              damage = EarthMethods.getMetalAugment(this.damage);
            }
            GeneralMethods.damageEntity(player, entity, damage);
            progressing = false;
          }
        }

        if (!progressing) {
          breakBlock();
          return false;
        }

        if (revert) {
          // Methods.addTempEarthBlock(sourceblock, block);
          if (sourceblock.getType() == Material.RED_SANDSTONE) {
            sourceblock.setType(sourcetype);
            if (sourcetype == Material.SAND) {
              sourceblock.setData((byte) 0x1);
            }
          } else {
            sourceblock.setType(sourcetype);
          }
          EarthMethods.moveEarthBlock(sourceblock, block);

          if (block.getType() == Material.SAND) {
            block.setType(Material.SANDSTONE);
          }
          if (block.getType() == Material.GRAVEL) {
            block.setType(Material.STONE);
          }
        } else {
          block.setType(sourceblock.getType());
          sourceblock.setType(Material.AIR);
        }

        sourceblock = block;

        if (location.distance(destination) < 1) {
          if (sourcetype == Material.SAND || sourcetype == Material.GRAVEL) {
            progressing = false;
            if (sourceblock.getType() == Material.RED_SANDSTONE) {
              sourcetype = Material.SAND;
              sourceblock.setType(sourcetype);
              sourceblock.setData((byte) 0x1);
            } else {
              sourceblock.setType(sourcetype);
            }
          }

          falling = true;
          progressing = false;
        }

        return true;
      }
    }

    return false;
  }