Esempio n. 1
0
 /**
  * Detecting factory, based on the position of the sign. The base must be one or two blocks above
  * and the rails an additional block above the base. Signs are guaranteed to be signs and rails
  * are guaranteed to be rails.
  *
  * @param sign the block containing the sign that gives additional configuration to the mechanism.
  */
 public static CartMechanismBlocks findBySign(Block sign) throws InvalidMechanismException {
   if (!SignUtil.isSign(sign))
     throw new InvalidMechanismException("sign argument must be a sign!");
   if (BlockType.isRailBlock(sign.getFace(BlockFace.UP, 2).getTypeId())) {
     return new CartMechanismBlocks(
         sign.getFace(BlockFace.UP, 2), sign.getFace(BlockFace.UP, 1), sign);
   } else if (BlockType.isRailBlock(sign.getFace(BlockFace.UP, 3).getTypeId())) {
     return new CartMechanismBlocks(
         sign.getFace(BlockFace.UP, 3), sign.getFace(BlockFace.UP, 2), sign);
   }
   throw new InvalidMechanismException("could not find rails.");
 }
  /**
   * Find a position for the player to stand that is not inside a block. Blocks above the player
   * will be iteratively tested until there is a series of two free blocks. The player will be
   * teleported to that free position.
   *
   * @param player
   */
  public void findFreePosition(Player player) {
    Location loc = player.getLocation();
    int x = loc.getBlockX();
    int y = Math.max(0, loc.getBlockY());
    int origY = y;
    int z = loc.getBlockZ();
    World world = player.getWorld();

    byte free = 0;

    while (y <= 129) {
      if (BlockType.canPassThrough(world.getBlockTypeIdAt(x, y, z))) {
        free++;
      } else {
        free = 0;
      }

      if (free == 2) {
        if (y - 1 != origY) {
          loc.setX(x + 0.5);
          loc.setY(y);
          loc.setZ(z + 0.5);
          player.teleportTo(loc);
        }

        return;
      }

      y++;
    }
  }
Esempio n. 3
0
  /**
   * Find a position for the player to stand that is not inside a block. Blocks above the player
   * will be iteratively tested until there is a series of two free blocks. The player will be
   * teleported to that free position.
   *
   * @param player
   */
  public static void findFreePosition(Player player) {
    Location loc = player.getLocation();
    int x = loc.getBlockX();
    int y = Math.max(0, loc.getBlockY());
    int origY = y;
    int z = loc.getBlockZ();
    World world = player.getWorld();

    byte free = 0;

    while (y <= world.getMaxHeight() + 1) {
      if (BlockType.canPassThrough(world.getBlockTypeIdAt(x, y, z))) {
        free++;
      } else {
        free = 0;
      }

      if (free == 2) {
        if (y - 1 != origY || y == 1) {
          loc.setX(x + 0.5);
          loc.setY(y);
          loc.setZ(z + 0.5);
          if (y <= 2 && world.getBlockAt(x, 0, z).getTypeId() == BlockID.AIR) {
            world.getBlockAt(x, 0, z).setTypeId(20);
            loc.setY(2);
          }
          player.setFallDistance(0F);
          player.teleport(loc);
        }
        return;
      }

      y++;
    }
  }
Esempio n. 4
0
  public boolean actSecondary(
      ServerInterface server,
      LocalConfiguration config,
      LocalPlayer player,
      LocalSession session,
      WorldVector clicked) {

    LocalWorld world = clicked.getWorld();
    EditSession editSession =
        WorldEdit.getInstance().getEditSessionFactory().getEditSession(world, -1, player);
    targetBlock = (editSession).getBlock(clicked);
    BlockType type = BlockType.fromID(targetBlock.getType());

    if (type != null) {
      player.print("Replacer tool switched to: " + type.getName());
    }

    return true;
  }
  /*
   * Called when a block is broken.
   */
  @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
  public void onBlockBreak(BlockBreakEvent event) {
    Player player = event.getPlayer();
    WorldConfiguration wcfg = getWorldConfig(player);

    if (!wcfg.itemDurability) {
      ItemStack held = player.getItemInHand();
      if (held.getTypeId() > 0
          && !(ItemType.usesDamageValue(held.getTypeId())
              || BlockType.usesData(held.getTypeId()))) {
        held.setDurability((short) 0);
        player.setItemInHand(held);
      }
    }

    if (!plugin.getGlobalRegionManager().canBuild(player, event.getBlock())
        || !plugin.getGlobalRegionManager().canConstruct(player, event.getBlock())) {
      player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");
      event.setCancelled(true);
      return;
    }

    if (wcfg.getBlacklist() != null) {
      if (!wcfg.getBlacklist()
          .check(
              new BlockBreakBlacklistEvent(
                  plugin.wrapPlayer(player),
                  toVector(event.getBlock()),
                  event.getBlock().getTypeId()),
              false,
              false)) {
        event.setCancelled(true);
        return;
      }

      if (!wcfg.getBlacklist()
          .check(
              new DestroyWithBlacklistEvent(
                  plugin.wrapPlayer(player),
                  toVector(event.getBlock()),
                  player.getItemInHand().getTypeId()),
              false,
              false)) {
        event.setCancelled(true);
        return;
      }
    }

    if (wcfg.isChestProtected(event.getBlock(), player)) {
      player.sendMessage(ChatColor.DARK_RED + "The chest is protected.");
      event.setCancelled(true);
      return;
    }
  }
Esempio n. 6
0
 /**
  * Detecting factory, based on the position of the base. The rails must be one block above and the
  * sign if it exists must be one or two blocks below. Signs are guaranteed to be signs (unless
  * they're null) and rails are guaranteed to be rails.
  *
  * @param base the block on which the rails sit; the type of this block is what determines the
  *     mechanism type.
  */
 public static CartMechanismBlocks findByBase(Block base) throws InvalidMechanismException {
   if (!BlockType.isRailBlock(base.getFace(BlockFace.UP, 1).getTypeId()))
     throw new InvalidMechanismException("could not find rails.");
   if (SignUtil.isSign(base.getFace(BlockFace.DOWN, 1).getTypeId())) {
     return new CartMechanismBlocks(
         base.getFace(BlockFace.UP, 1), base, base.getFace(BlockFace.DOWN, 1));
   } else if (SignUtil.isSign(base.getFace(BlockFace.DOWN, 2).getTypeId())) {
     return new CartMechanismBlocks(
         base.getFace(BlockFace.UP, 1), base, base.getFace(BlockFace.DOWN, 2));
   }
   return new CartMechanismBlocks(base.getFace(BlockFace.UP, 1), base, null);
 }
Esempio n. 7
0
 /**
  * Detecting factory, based on the position of the rails. The base must be one block below and the
  * sign if it exists must be two or three blocks below. Signs are guaranteed to be signs (unless
  * they're null) and rails are guaranteed to be rails.
  *
  * <p>This is the most important constructor, since it is the one invoked when processing cart
  * move events.
  *
  * @param rail the block containing the rails.
  */
 public static CartMechanismBlocks findByRail(Block rail) throws InvalidMechanismException {
   if (!BlockType.isRailBlock(rail.getTypeId()))
     throw new InvalidMechanismException("rail argument must be a rail!");
   if (SignUtil.isSign(rail.getFace(BlockFace.DOWN, 2).getTypeId())) {
     return new CartMechanismBlocks(
         rail, rail.getFace(BlockFace.DOWN, 1), rail.getFace(BlockFace.DOWN, 2));
   } else if (SignUtil.isSign(rail.getFace(BlockFace.DOWN, 3).getTypeId())) {
     return new CartMechanismBlocks(
         rail, rail.getFace(BlockFace.DOWN, 1), rail.getFace(BlockFace.DOWN, 3));
   }
   return new CartMechanismBlocks(rail, rail.getFace(BlockFace.DOWN, 1), null);
 }
Esempio n. 8
0
  public void doEffect() {

    try {
      if (effectID == 0) return;
      if (effectID == 2001 && BlockType.fromID(effectData) == null) return;
      Block b = SignUtil.getBackBlock(BukkitUtil.toSign(getSign()).getBlock());
      for (int i = 0; i < times; i++) {
        b.getWorld()
            .playEffect(b.getLocation().add(offset), Effect.getById(effectID), effectData, 50);
      }
    } catch (Exception ignored) {
    }
  }
Esempio n. 9
0
  @Override
  public void simulateBlockMine(Vector pt) {
    BaseBlock block = getLazyBlock(pt);
    BaseItemStack stack = BlockType.getBlockDrop(block.getId(), (short) block.getData());

    if (stack != null) {
      final int amount = stack.getAmount();
      if (amount > 1) {
        dropItem(pt, new BaseItemStack(stack.getType(), 1, stack.getData()), amount);
      } else {
        dropItem(pt, stack, amount);
      }
    }

    try {
      setBlock(pt, new BaseBlock(BlockID.AIR));
    } catch (WorldEditException e) {
      throw new RuntimeException(e);
    }
  }
Esempio n. 10
0
  @EventHandler(ignoreCancelled = true)
  public void onRightClick(PlayerInteractEvent event) {

    if (!plugin.getConfiguration().chairEnabled) return;
    if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return;
    if (event.getClickedBlock() == null
        || !plugin.getConfiguration().chairBlocks.contains(event.getClickedBlock().getTypeId()))
      return;

    BukkitPlayer player = new BukkitPlayer(plugin, event.getPlayer());

    // Now everything looks good, continue;
    if (player.getPlayer().getItemInHand() == null
        || !player.getPlayer().getItemInHand().getType().isBlock()
        || player.getPlayer().getItemInHand().getTypeId() == 0) {
      if (plugin.getConfiguration().chairSneak != player.getPlayer().isSneaking()) return;
      if (!player.hasPermission("craftbook.mech.chair.use")) {
        player.printError("mech.use-permission");
        return;
      }
      if (hasChair(player.getPlayer())) { // Stand
        removeChair(player.getPlayer());
        event.getPlayer().teleport(event.getClickedBlock().getLocation().add(0.5, 1.5, 0.5));
      } else { // Sit
        if (hasChair(event.getClickedBlock())) {
          player.print("This seat is already occupied.");
          return;
        }
        if (BlockType.canPassThrough(event.getClickedBlock().getRelative(0, -1, 0).getTypeId())) {

          player.printError("This chair has nothing below it!");
          return;
        }
        player
            .getPlayer()
            .teleport(
                event.getClickedBlock().getLocation().add(0.5, 0, 0.5)); // Teleport to the seat
        addChair(player.getPlayer(), event.getClickedBlock());
      }
    }
  }
Esempio n. 11
0
  private static boolean occupiable(Block block) {

    return BlockType.canPassThrough(block.getTypeId());
  }
Esempio n. 12
0
 /**
  * Detecting factory; defers to one of the other three specific detecting factories based on
  * whether the given unknown block appears to be a sign, rail, or base.
  *
  * @param unknown the block to examine.
  */
 public static CartMechanismBlocks find(Block unknown) throws InvalidMechanismException {
   final int ti = unknown.getTypeId();
   if (SignUtil.isSign(ti)) return findBySign(unknown);
   else if (BlockType.isRailBlock(ti)) return findByRail(unknown);
   else return findByBase(unknown);
 }
Esempio n. 13
0
 @Override
 public boolean usesBlockData(int type) {
   // We future proof here by assuming all unknown blocks use data
   return BlockType.usesData(type) || BlockType.fromID(type) == null;
 }
Esempio n. 14
0
 @Override
 public boolean isValidBlockType(int type) {
   return BlockType.fromID(type) != null;
 }