Java Code Examples for org.bukkit.block.BlockFace#equals()

The following examples show how to use org.bukkit.block.BlockFace#equals() . 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: FastLeavesDecayListener.java    From UhcCore with GNU General Public License v3.0 6 votes vote down vote up
private boolean findLog(Block block, int i) {
    if (UniversalMaterial.isLog(block.getType())){
        return true;
    }else if (UniversalMaterial.isLeaves(block.getType())){
        i--;
    }else {
        return false;
    }
    if (i > 0){
        boolean result = false;
        for (BlockFace face : BlockFace.values()) {
            if (face.equals(BlockFace.DOWN) || face.equals(BlockFace.UP) || face.equals(BlockFace.NORTH) ||
                    face.equals(BlockFace.EAST) || face.equals(BlockFace.SOUTH) || face.equals(BlockFace.WEST)) {
                boolean b = findLog(block.getRelative(face), i);
                if (b) result = b;
            }
        }
        return result;
    }
    return false;
}
 
Example 2
Source File: TimberListener.java    From UhcCore with GNU General Public License v3.0 6 votes vote down vote up
private void breakTree(Block block, int i) {
    if (UniversalMaterial.isLog(block.getType())){
        block.breakNaturally();
        i = 2;
    }else {
        i--;
    }
    if (i > 0){
        for (BlockFace face : BlockFace.values()) {
            if (face.equals(BlockFace.DOWN) || face.equals(BlockFace.UP) || face.equals(BlockFace.NORTH) ||
                    face.equals(BlockFace.EAST) || face.equals(BlockFace.SOUTH) || face.equals(BlockFace.WEST)) {
                breakTree(block.getRelative(face), i);
            }
        }
    }
}
 
Example 3
Source File: FallingBlocksModule.java    From CardinalPGM with MIT License 6 votes vote down vote up
private boolean isBlockAttached(List<Block> scan, Rule rule, List<Vector> alreadyScanned) {
    if (scan.size() == 0) return false;
    List<Block> nextScan = Lists.newArrayList();
    for (Block scanning : scan) {
        if (alreadyScanned.size() > 4096) {
            Bukkit.getConsoleSender().sendMessage("Maximim scan area (4096 blocks) was reached.");
            return true;
        }
        for (BlockFace face : FACES) {
            Block block = scanning.getRelative(face);
            if (alreadyScanned.contains(block.getLocation().toVector())) continue;
            if (rule.getSticky().evaluate(block).equals(FilterState.ALLOW) || (face.equals(BlockFace.DOWN) && !block.getType().equals(Material.AIR))) {
                if (rule.getFilter().evaluate(block).equals(FilterState.ALLOW)) {
                    nextScan.add(block);
                    alreadyScanned.add(block.getLocation().toVector());
                } else return true;
            }
        }
    }
    return isBlockAttached(nextScan, rule, alreadyScanned);
}
 
Example 4
Source File: VeinGenerator.java    From UhcCore with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Get a set of adjacent blocks starting from a block
 * @param startBlock : the block where to start the search
 * @param nbrBlocks : number of adjacent blocks
 * @return
 */
private List<Block> getAdjacentsBlocks(Block startBlock, int nbrBlocks){
	int failedAttempts = 0;
	List<Block> adjacentBlocks = new ArrayList<Block>();
	adjacentBlocks.add(startBlock);
	while(adjacentBlocks.size() < nbrBlocks && failedAttempts < 25){
		// Get random block in the growing list of chosen blocks
		Block block = adjacentBlocks.get(RandomUtils.randomInteger(0, adjacentBlocks.size()-1));
		
		// RandomFace
		BlockFace face = RandomUtils.randomAdjacentFace();
		Location blockLocation = block.getLocation();
		if( (blockLocation.getBlockY() <= 1 && face.equals(BlockFace.DOWN)) || (blockLocation.getBlockY() >= 255 && face.equals(BlockFace.UP))){
			failedAttempts++;
		}else{
			// Find random adjacent block to this block
			Block adjacent = block.getRelative(face);
			if(adjacentBlocks.contains(adjacent) || !adjacent.getType().equals(Material.STONE)){
				// We only want to find new discovered block inside stone to avoid placing ores in mid-air in the caves.
				failedAttempts++;
			}else{
				adjacentBlocks.add(adjacent);
			}
		}
		
		
	}
	return adjacentBlocks;
}
 
Example 5
Source File: RescuePlatform.java    From BedWars with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void createPlatform(boolean bre, int time, int dist, Material bMat) {
    canBreak = bre;
    breakingTime = time;
    buildingMaterial = bMat;
    platformBlocks = new ArrayList<>();

    Location center = player.getLocation().clone();
    center.setY(center.getY() - dist);

    for (BlockFace blockFace : BlockFace.values()) {
        if (blockFace.equals(BlockFace.DOWN) || blockFace.equals(BlockFace.UP)) {
            continue;
        }

        Block placedBlock = center.getBlock().getRelative(blockFace);
        if (placedBlock.getType() != Material.AIR) {
            continue;
        }

        ItemStack coloredStack = Main.applyColor(
                TeamColor.fromApiColor(team.getColor()), new ItemStack(buildingMaterial));
        if (Main.isLegacy()) {
            placedBlock.setType(coloredStack.getType());
            try {
                // The method is no longer in API, but in legacy versions exists
                Block.class.getMethod("setData", byte.class).invoke(placedBlock, (byte) coloredStack.getDurability());
            } catch (Exception e) {
            }
        } else {
            placedBlock.setType(coloredStack.getType());
        }
        addBlockToList(placedBlock);
    }

    if (breakingTime > 0) {
        game.registerSpecialItem(this);
        runTask();

        MiscUtils.sendActionBarMessage(player, i18nonly("specials_rescue_platform_created").replace("%time%", Integer.toString(breakingTime)));

        item.setAmount(item.getAmount() - 1);
        if (item.getAmount() > 1) {
    		item.setAmount(item.getAmount() - 1);
    	} else {
    		player.getInventory().remove(item);
    	}
        player.updateInventory();
    } else {
        game.registerSpecialItem(this);

        MiscUtils.sendActionBarMessage(player, i18nonly("specials_rescue_platform_created_unbreakable"));
        item.setAmount(item.getAmount() - 1);
        if (item.getAmount() > 1) {
    		item.setAmount(item.getAmount() - 1);
    	} else {
    		player.getInventory().remove(item);
    	}
        player.updateInventory();
    }
}
 
Example 6
Source File: RescuePlatform.java    From BedWars with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void createPlatform(boolean bre, int time, int dist, Material bMat) {
    canBreak = bre;
    breakingTime = time;
    buildingMaterial = bMat;
    platformBlocks = new ArrayList<>();

    Location center = player.getLocation().clone();
    center.setY(center.getY() - dist);

    for (BlockFace blockFace : BlockFace.values()) {
        if (blockFace.equals(BlockFace.DOWN) || blockFace.equals(BlockFace.UP)) {
            continue;
        }

        Block placedBlock = center.getBlock().getRelative(blockFace);
        if (placedBlock.getType() != Material.AIR) {
            continue;
        }

        ItemStack coloredStack = Main.applyColor(
                TeamColor.fromApiColor(team.getColor()), new ItemStack(buildingMaterial));
        if (Main.isLegacy()) {
            placedBlock.setType(coloredStack.getType());
            try {
                // The method is no longer in API, but in legacy versions exists
                Block.class.getMethod("setData", byte.class).invoke(placedBlock, (byte) coloredStack.getDurability());
            } catch (Exception e) {
            }
        } else {
            placedBlock.setType(coloredStack.getType());
        }
        addBlockToList(placedBlock);
    }

    if (breakingTime > 0) {
        game.registerSpecialItem(this);
        runTask();

        MiscUtils.sendActionBarMessage(player, i18nonly("specials_rescue_platform_created").replace("%time%", Integer.toString(breakingTime)));

        item.setAmount(item.getAmount() - 1);
        if (item.getAmount() > 1) {
    		item.setAmount(item.getAmount() - 1);
    	} else {
    		player.getInventory().remove(item);
    	}
        player.updateInventory();
    } else {
        game.registerSpecialItem(this);

        MiscUtils.sendActionBarMessage(player, i18nonly("specials_rescue_platform_created_unbreakable"));
        item.setAmount(item.getAmount() - 1);
        if (item.getAmount() > 1) {
    		item.setAmount(item.getAmount() - 1);
    	} else {
    		player.getInventory().remove(item);
    	}
        player.updateInventory();
    }
}
 
Example 7
Source File: RescuePlatform.java    From BedwarsRel with GNU General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
public void create(Player player, Game game) {
  this.game = game;
  this.owner = player;

  int breakTime = BedwarsRel.getInstance()
      .getIntConfig("specials.rescue-platform.break-time", 10);
  int waitTime = BedwarsRel
      .getInstance().getIntConfig("specials.rescue-platform.using-wait-time", 20);
  boolean canBreak =
      BedwarsRel.getInstance().getBooleanConfig("specials.rescue-platform.can-break", false);
  Material configMaterial =
      Utils.getMaterialByConfig("specials.rescue-platform.block", Material.STAINED_GLASS);

  if (waitTime > 0) {
    ArrayList<RescuePlatform> livingPlatforms = this.getLivingPlatforms();
    if (!livingPlatforms.isEmpty()) {
      for (RescuePlatform livingPlatform : livingPlatforms) {
        int waitLeft = waitTime - livingPlatform.getLivingTime();
        if (waitLeft > 0) {
          player.sendMessage(
              ChatWriter.pluginMessage(
                  BedwarsRel._l(player, "ingame.specials.rescue-platform.left",
                      ImmutableMap.of("time", String.valueOf(waitLeft)))));
          return;
        }
      }
    }
  }

  if (player.getLocation().getBlock().getRelative(BlockFace.DOWN).getType() != Material.AIR) {
    player.sendMessage(
        ChatWriter.pluginMessage(ChatColor.RED + BedwarsRel._l(player, "errors.notinair")));
    return;
  }

  Location mid = player.getLocation().clone();
  mid.setY(mid.getY() - 1.0D);

  Team team = game.getPlayerTeam(player);

  ItemStack usedStack = null;

  if (BedwarsRel.getInstance().getCurrentVersion().startsWith("v1_8")) {
    usedStack = player.getInventory().getItemInHand();
    usedStack.setAmount(usedStack.getAmount() - 1);
    player.getInventory().setItem(player.getInventory().getHeldItemSlot(), usedStack);
  } else {
    if (player.getInventory().getItemInOffHand().getType() == this.getItemMaterial()) {
      usedStack = player.getInventory().getItemInOffHand();
      usedStack.setAmount(usedStack.getAmount() - 1);
      player.getInventory().setItemInOffHand(usedStack);
    } else if (player.getInventory().getItemInMainHand().getType() == this.getItemMaterial()) {
      usedStack = player.getInventory().getItemInMainHand();
      usedStack.setAmount(usedStack.getAmount() - 1);
      player.getInventory().setItemInMainHand(usedStack);
    }
  }
  player.updateInventory();

  for (BlockFace face : BlockFace.values()) {
    if (face.equals(BlockFace.DOWN) || face.equals(BlockFace.UP)) {
      continue;
    }

    Block placed = mid.getBlock().getRelative(face);
    if (placed.getType() != Material.AIR) {
      continue;
    }

    placed.setType(configMaterial);
    if (configMaterial.equals(Material.STAINED_GLASS) || configMaterial.equals(Material.WOOL)
        || configMaterial.equals(Material.STAINED_CLAY)) {
      placed.setData(team.getColor().getDyeColor().getWoolData());
    }

    if (!canBreak) {
      game.getRegion().addPlacedUnbreakableBlock(placed, null);
    } else {
      game.getRegion().addPlacedBlock(placed, null);
    }

    this.addPlatformBlock(placed);
  }
  if (breakTime > 0 || waitTime > 0) {
    this.runTask(breakTime, waitTime);
    game.addSpecialItem(this);
  }
}