コード例 #1
0
  /**
   * Adds a position to be used a source.
   *
   * @return
   */
  @Override
  public void addSingleSourcePosition(WorldVector arg0) {

    int x = arg0.getBlockX();
    int y = arg0.getBlockY();
    int z = arg0.getBlockZ();

    if (BukkitUtil.toWorld(arg0.getWorld()).getBlockAt(BukkitUtil.toLocation(arg0)).getTypeId()
        == BlockType.CHEST.getID()) {
      BlockState complexBlock = BukkitUtil.toWorld(arg0.getWorld()).getBlockAt(x, y, z).getState();

      if (complexBlock instanceof Chest) {
        Chest chest = (Chest) complexBlock;

        if (!chests.contains(chest)) {
          chests.add((Chest) complexBlock);
        }
      }
    }
  }
コード例 #2
0
ファイル: LightStone.java プロジェクト: koryk/craftbook
    @Override
    public LightStone detect(BlockWorldVector pt, LocalPlayer player)
        throws InvalidMechanismException {

      Block block = BukkitUtil.toWorld(pt).getBlockAt(BukkitUtil.toLocation(pt));
      if (block != null
          && player.getHeldItemType() == CraftBookPlugin.inst().getConfiguration().lightstoneItem
          && player.hasPermission("craftbook.mech.lightstone.use")) return new LightStone();

      return null;
    }
コード例 #3
0
  /**
   * Toggle lights in the immediate area.
   *
   * @param pt
   * @return true if the block was recogized as a lightswitch; this may or may not mean that any
   *     lights were actually toggled.
   */
  private boolean toggleLights(BlockWorldVector pt) {
    World world = BukkitUtil.toWorld(pt);

    int wx = pt.getBlockX();
    int wy = pt.getBlockY();
    int wz = pt.getBlockZ();
    int aboveID = world.getBlockTypeIdAt(wx, wy + 1, wz);

    if (aboveID == BlockID.TORCH
        || aboveID == BlockID.REDSTONE_TORCH_OFF
        || aboveID == BlockID.REDSTONE_TORCH_ON) {
      // Check if block above is a redstone torch.
      // Used to get what to change torches to.
      boolean on = (aboveID != BlockID.TORCH);
      // Prevent spam
      Long lastUse = recentLightToggles.remove(pt);
      long currTime = System.currentTimeMillis();
      if (lastUse != null && currTime - lastUse < 500) {
        recentLightToggles.put(pt, lastUse);
        return true;
      }
      recentLightToggles.put(pt, currTime);
      int changed = 0;
      for (int x = -10 + wx; x <= 10 + wx; x++) {
        for (int y = -10 + wy; y <= 10 + wy; y++) {
          for (int z = -5 + wz; z <= 5 + wz; z++) {
            int id = world.getBlockTypeIdAt(x, y, z);
            if (id == BlockID.TORCH
                || id == BlockID.REDSTONE_TORCH_OFF
                || id == BlockID.REDSTONE_TORCH_ON) {
              // Limit the maximum number of changed lights
              if (changed >= 20) {
                return true;
              }
              if (on) {
                world.getBlockAt(x, y, z).setTypeId(BlockID.TORCH);
              } else {
                world.getBlockAt(x, y, z).setTypeId(BlockID.REDSTONE_TORCH_ON);
              }
              changed++;
            }
          }
        }
      }
      return true;
    }
    return false;
  }
コード例 #4
0
ファイル: LightSwitch.java プロジェクト: AfterKraft/craftbook
  /**
   * Toggle lights in the immediate area.
   *
   * @param pt
   * @return true if the block was recogized as a lightswitch; this may or may not mean that any
   *     lights were actually toggled.
   */
  private boolean toggleLights(BlockWorldVector pt) {

    World world = BukkitUtil.toWorld(pt);

    Block block = BukkitUtil.toBlock(pt);
    // check if this looks at all like something we're interested in first
    if (block.getTypeId() != BlockID.WALL_SIGN) return false;
    int radius = 10;
    int maximum = 20;
    try {
      radius = Integer.parseInt(((Sign) block.getState()).getLine(2));
    } catch (Exception ignored) {
    }
    try {
      maximum = Integer.parseInt(((Sign) block.getState()).getLine(3));
    } catch (Exception ignored) {
    }
    if (radius > plugin.getLocalConfiguration().lightSwitchSettings.maxRange) {
      radius = plugin.getLocalConfiguration().lightSwitchSettings.maxRange;
    }
    if (maximum > plugin.getLocalConfiguration().lightSwitchSettings.maxMaximum) {
      maximum = plugin.getLocalConfiguration().lightSwitchSettings.maxMaximum;
    }

    int wx = pt.getBlockX();
    int wy = pt.getBlockY();
    int wz = pt.getBlockZ();
    int aboveID = world.getBlockTypeIdAt(wx, wy + 1, wz);

    if (aboveID == BlockID.TORCH
        || aboveID == BlockID.REDSTONE_TORCH_OFF
        || aboveID == BlockID.REDSTONE_TORCH_ON) {
      // Check if block above is a redstone torch.
      // Used to get what to change torches to.
      boolean on = aboveID != BlockID.TORCH;
      // Prevent spam
      Long lastUse = recentLightToggles.remove(pt);
      long currTime = System.currentTimeMillis();

      if (lastUse != null && currTime - lastUse < 500) {
        recentLightToggles.put(pt, lastUse);
        return true;
      }

      recentLightToggles.put(pt, currTime);
      int changed = 0;
      for (int x = -radius + wx; x <= radius + wx; x++) {
        for (int y = -radius + wy; y <= radius + wy; y++) {
          for (int z = -radius + wz; z <= radius + wz; z++) {
            int id = world.getBlockTypeIdAt(x, y, z);
            if (id == BlockID.TORCH
                || id == BlockID.REDSTONE_TORCH_OFF
                || id == BlockID.REDSTONE_TORCH_ON) {
              // Limit the maximum number of changed lights
              if (changed >= maximum) return true;

              if (on) {
                world.getBlockAt(x, y, z).setTypeId(BlockID.TORCH);
              } else {
                world.getBlockAt(x, y, z).setTypeId(BlockID.REDSTONE_TORCH_ON);
              }
              changed++;
            }
          }
        }
      }
      return true;
    }
    return false;
  }