org.bukkit.block.BlockFace#values ( )源码实例Demo

下面列出了org.bukkit.block.BlockFace#values ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: UhcCore   文件: FastLeavesDecayListener.java
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;
}
 
源代码2 项目: UhcCore   文件: TimberListener.java
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);
            }
        }
    }
}
 
源代码3 项目: Slimefun4   文件: SlimefunBootsListener.java
private void stomp(EntityDamageEvent e) {
    Player p = (Player) e.getEntity();
    p.getWorld().playSound(p.getLocation(), Sound.ENTITY_ZOMBIE_BREAK_WOODEN_DOOR, 1F, 2F);
    p.setVelocity(new Vector(0.0, 0.7, 0.0));

    for (Entity n : p.getNearbyEntities(4, 4, 4)) {
        if (n instanceof LivingEntity && !n.getUniqueId().equals(p.getUniqueId())) {
            Vector velocity = n.getLocation().toVector().subtract(p.getLocation().toVector()).normalize().multiply(1.4);
            n.setVelocity(velocity);

            if (!(n instanceof Player) || (p.getWorld().getPVP() && SlimefunPlugin.getProtectionManager().hasPermission(p, n.getLocation(), ProtectableAction.PVP))) {
                EntityDamageByEntityEvent event = new EntityDamageByEntityEvent(p, n, DamageCause.ENTITY_ATTACK, e.getDamage() / 2);
                Bukkit.getPluginManager().callEvent(event);
                if (!event.isCancelled()) ((LivingEntity) n).damage(e.getDamage() / 2);
            }
        }
    }

    for (BlockFace face : BlockFace.values()) {
        Block b = p.getLocation().getBlock().getRelative(BlockFace.DOWN).getRelative(face);
        p.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, b.getType());
    }
}
 
源代码4 项目: ObsidianDestroyer   文件: Util.java
public static boolean isNearLiquid(Location location) {
    for (BlockFace face : BlockFace.values()) {
        switch (face) {
            case NORTH:
            case EAST:
            case SOUTH:
            case WEST:
            case UP:
            case DOWN:
            case SELF:
                if (location.getBlock().getRelative(face) != null && location.getBlock().getRelative(face).isLiquid()) {
                    return true;
                }
                break;
            default:
                break;
        }
    }
    return false;
}
 
源代码5 项目: Carbon-2   文件: Utils.java
/**
 * Returns all adjacent blocks to a specified block. Returns an empty list if none were found. Air is not included.
 *
 * @param source
 * @return
 */
public static List<Block> getAllAdjacentBlocks(Block source) {
    List<Block> list = new ArrayList<Block>();
    for (BlockFace f : BlockFace.values()) {
        Block rel = source.getRelative(f);
        if (rel.getType() != Material.AIR) {
            list.add(rel);
        }
    }
    return list;
}
 
源代码6 项目: Thermos   文件: CraftBlock.java
public BlockFace getFace(final Block block) {
    BlockFace[] values = BlockFace.values();

    for (BlockFace face : values) {
        if ((this.getX() + face.getModX() == block.getX()) &&
            (this.getY() + face.getModY() == block.getY()) &&
            (this.getZ() + face.getModZ() == block.getZ())
        ) {
            return face;
        }
    }

    return null;
}
 
源代码7 项目: FastAsyncWorldedit   文件: AsyncBlock.java
@Override
public BlockFace getFace(Block block) {
    BlockFace[] directions = BlockFace.values();
    for(int i = 0; i < directions.length; ++i) {
        BlockFace face = directions[i];
        if(this.getX() + face.getModX() == block.getX() && this.getY() + face.getModY() == block.getY() && this.getZ() + face.getModZ() == block.getZ()) {
            return face;
        }
    }
    return null;
}
 
源代码8 项目: Carbon-2   文件: Utils.java
/**
 * Returns all adjacent blocks to a specified block. Returns an empty list if none were found. Air is not included.
 *
 * @param source
 * @return
 */
public static List<Block> getAllAdjacentBlocks(Block source) {
    List<Block> list = new ArrayList<Block>();
    for (BlockFace f : BlockFace.values()) {
        Block rel = source.getRelative(f);
        if (rel.getType() != Material.AIR) {
            list.add(rel);
        }
    }
    return list;
}
 
源代码9 项目: Carbon   文件: Utilities.java
/**
 * Returns all adjacent blocks to a specified block.
 * Returns an empty list if none were found.
 * Air is not included.
 * @param source
 * @return
 */
public static List<Block> getAllAdjacentBlocks(Block source) {
    List<Block> list = new ArrayList<Block>();
    for (BlockFace f : BlockFace.values()) {
        Block rel = source.getRelative(f);
        if (rel.getType() != Material.AIR) {
        list.add(rel);
        }
    }
    return list;
}
 
源代码10 项目: BedWars   文件: RescuePlatform.java
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();
    }
}
 
源代码11 项目: BedWars   文件: RescuePlatform.java
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();
    }
}
 
源代码12 项目: BedwarsRel   文件: RescuePlatform.java
@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);
  }
}
 
源代码13 项目: Carbon   文件: BlockListener.java
public boolean isTouching(Block block, Material material) {
	for (BlockFace b : BlockFace.values())
		if (block.getRelative(b).getType() == material)
			return true;
	return false;
}