Example #1
0
 @SuppressWarnings("deprecation")
 @Override
 protected void execute(Event e) {
   Location pos1 = location1.getSingle(e);
   Location pos2 = location2.getSingle(e);
   EditSession session = editSession.getSingle(e);
   ItemStack[] blocks = blockList.getAll(e);
   RandomPattern random = new RandomPattern();
   if (session == null) return;
   for (ItemStack b : blocks) {
     if (b.getType().isBlock()) {
       random.add(new BlockPattern(new BaseBlock(b.getTypeId(), b.getDurability())), 50);
     }
   }
   try {
     session.makeWalls(
         new CuboidRegion(
             (World) BukkitUtil.getLocalWorld(pos1.getWorld()),
             BukkitUtil.toVector(pos1),
             BukkitUtil.toVector(pos2)),
         Patterns.wrap(random));
     session.flushQueue();
   } catch (WorldEditException ex) {
     if (ex instanceof MaxChangedBlocksException) return;
     else ex.printStackTrace();
   }
 }
Example #2
0
    @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;
    }
 @Override
 public void onRightClick(PlayerInteractEvent event) {
   if (!plugin.getLocalConfiguration().lightSwitchSettings.enable) return;
   if (!BukkitUtil.toWorldVector(event.getClickedBlock()).equals(pt))
     return; // wth? our manager is insane
   toggleLights(pt);
 }
Example #4
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);
    }
Example #5
0
  @Override
  public void onRightClick(PlayerInteractEvent event) {

    if (!plugin.getLocalConfiguration().teleporterSettings.enable) return;

    if (!BukkitUtil.toWorldVector(event.getClickedBlock())
        .equals(BukkitUtil.toWorldVector(trigger))) return; // wth? our manager is insane. ikr.

    LocalPlayer localPlayer = plugin.wrap(event.getPlayer());

    if (!localPlayer.hasPermission("craftbook.mech.teleporter.use")) {
      localPlayer.printError("mech.use-permission");
      return;
    }

    makeItSo(event.getPlayer());

    event.setCancelled(true);
  }
Example #6
0
  /**
   * Notify mechanics about a changed block that they are watching.
   *
   * @param event
   */
  public void notify(BlockEvent event) {

    Set<PersistentMechanic> pms = watchBlocks.get(BukkitUtil.toWorldVector(event.getBlock()));

    if (pms == null) return;

    for (PersistentMechanic m : pms) {
      m.onWatchBlockNotification(event);
    }
  }
  /**
   * 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);
        }
      }
    }
  }
    @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);
    }
Example #9
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;
    }
Example #10
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;
  }
Example #11
0
  @Override
  public void onRightClick(PlayerInteractEvent event) {

    LocalPlayer localPlayer = plugin.wrap(event.getPlayer());

    if (!plugin.getLocalConfiguration().cauldronSettings.enable) return;

    if (!localPlayer.hasPermission("craftbook.mech.cauldron")) return;

    if (!BukkitUtil.toWorldVector(event.getClickedBlock()).equals(pt)) return;
    if (event.getPlayer().getItemInHand().getTypeId() >= 255
        || event.getPlayer().getItemInHand().getType() == Material.AIR) {
      if (preCauldron(event.getPlayer(), event.getPlayer().getWorld(), pt)) {
        event.setUseInteractedBlock(Result.DENY);
        event.setUseItemInHand(Result.DENY);
        event.setCancelled(true);
      }
    }
  }
Example #12
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;
  }