Beispiel #1
0
    @Override
    public Cauldron detect(BlockWorldVector pt) {

      Block block = BukkitUtil.toBlock(pt);
      // check if this looks at all like something we're interested in
      // first
      if (block.getTypeId() == BlockID.AIR) return null;
      return new Cauldron(this.recipes, pt, plugin);
    }
    @Override
    public LightSwitch detect(BlockWorldVector 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 null;
      String line = ((Sign) block.getState()).getLine(1);
      if (!line.equalsIgnoreCase("[|]") && !line.equalsIgnoreCase("[I]")) return null;

      // okay, now we can start doing exploration of surrounding blocks
      // and if something goes wrong in here then we throw fits.
      return new LightSwitch(pt, plugin);
    }
Beispiel #3
0
    /**
     * Explore around the trigger to find a functional elevator; throw if things look funny.
     *
     * @param pt the trigger (should be a signpost)
     * @return an Elevator if we could make a valid one, or null if this looked nothing like an
     *     elevator.
     * @throws InvalidMechanismException if the area looked like it was intended to be an elevator,
     *     but it failed.
     */
    @Override
    public Teleporter detect(BlockWorldVector pt) throws InvalidMechanismException {

      Block block = BukkitUtil.toBlock(pt);
      // check if this looks at all like something we're interested in first

      if (block.getState() instanceof Sign) {
        Sign s = (Sign) block.getState();
        if (!s.getLine(1).equalsIgnoreCase("[Teleport]")) return null;
        String[] pos = s.getLine(2).split(":");
        if (pos.length > 2) return new Teleporter(block, plugin);
      }

      return null;
    }
Beispiel #4
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);

    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;
  }