예제 #1
0
  private void surroundingSignChecks(String player, Block block) {
    int x = block.getX();
    int y = block.getY();
    int z = block.getZ();

    Block top = block.getWorld().getBlockAt(x, y + 1, z);
    if (top.getTypeId() == 63) {
      bystanders.add(new BrokenBlock(player, top, world));
    }
    Block north = block.getWorld().getBlockAt(x + 1, y, z);
    if (north.getTypeId() == 68 && north.getData() == 5) {
      bystanders.add(new BrokenBlock(player, north, world));
    }
    Block south = block.getWorld().getBlockAt(x - 1, y, z);
    if (south.getTypeId() == 68 && south.getData() == 4) {
      bystanders.add(new BrokenBlock(player, south, world));
    }
    Block east = block.getWorld().getBlockAt(x, y, z + 1);
    if (east.getTypeId() == 68 && east.getData() == 3) {
      bystanders.add(new BrokenBlock(player, east, world));
    }
    Block west = block.getWorld().getBlockAt(x, y, z - 1);
    if (west.getTypeId() == 68 && west.getData() == 2) {
      bystanders.add(new BrokenBlock(player, west, world));
    }
  }
  /*
   * Called when redstone changes.
   */
  @EventHandler(priority = EventPriority.HIGH)
  public void onBlockRedstoneChange(BlockRedstoneEvent event) {
    Block blockTo = event.getBlock();
    World world = blockTo.getWorld();

    ConfigurationManager cfg = plugin.getGlobalStateManager();
    WorldConfiguration wcfg = cfg.get(world);

    if (wcfg.simulateSponge && wcfg.redstoneSponges) {
      int ox = blockTo.getX();
      int oy = blockTo.getY();
      int oz = blockTo.getZ();

      for (int cx = -1; cx <= 1; cx++) {
        for (int cy = -1; cy <= 1; cy++) {
          for (int cz = -1; cz <= 1; cz++) {
            Block sponge = world.getBlockAt(ox + cx, oy + cy, oz + cz);
            if (sponge.getTypeId() == 19 && sponge.isBlockIndirectlyPowered()) {
              SpongeUtil.clearSpongeWater(plugin, world, ox + cx, oy + cy, oz + cz);
            } else if (sponge.getTypeId() == 19 && !sponge.isBlockIndirectlyPowered()) {
              SpongeUtil.addSpongeWater(plugin, world, ox + cx, oy + cy, oz + cz);
            }
          }
        }
      }

      return;
    }
  }
예제 #3
0
  /**
   * Places Blocks of a predetermined type just above the highest Block at each corner of the given
   * Chunk
   *
   * @param chunk The given Chunk
   */
  public static void markCorners(Chunk chunk) {
    // Get the highest Block (should be empty) at the South-West corner
    Block block = chunk.getBlock(0, 127, 0);
    // Move down until a non-empty Block is found
    while (block.getTypeId() == 0) block = block.getRelative(BlockFace.DOWN);
    // Change the empty Block just above the Block found
    block.getRelative(BlockFace.UP).setTypeId(cornerID);

    // Get the highest Block (should be empty) at the South-East corner
    block = chunk.getBlock(0, 127, 15);
    // Move down until a non-empty Block is found
    while (block.getTypeId() == 0) block = block.getRelative(BlockFace.DOWN);
    // Change the empty Block just above the Block found
    block.getRelative(BlockFace.UP).setTypeId(cornerID);

    // Get the highest Block (should be empty) at the North-West corner
    block = chunk.getBlock(15, 127, 0);
    // Move down until a non-empty Block is found
    while (block.getTypeId() == 0) block = block.getRelative(BlockFace.DOWN);
    // Change the empty Block just above the Block found
    block.getRelative(BlockFace.UP).setTypeId(cornerID);

    // Get the highest Block (should be empty) at the North-East corner
    block = chunk.getBlock(15, 127, 15);
    // Move down until a non-empty Block is found
    while (block.getTypeId() == 0) block = block.getRelative(BlockFace.DOWN);
    // Change the empty Block just above the Block found
    block.getRelative(BlockFace.UP).setTypeId(cornerID);
  }
예제 #4
0
  private void torchCheck(String player, Block block) {
    ArrayList<Integer> torchTypes = new ArrayList<Integer>();
    torchTypes.add(50); // Torch
    torchTypes.add(75); // Redstone torch (on)
    torchTypes.add(76); // Redstone torch (off)

    int x = block.getX();
    int y = block.getY();
    int z = block.getZ();

    Block torchTop = block.getWorld().getBlockAt(x, y + 1, z);

    if (torchTypes.contains(torchTop.getTypeId()) && torchTop.getData() == 5) {
      bystanders.add(new BrokenBlock(player, torchTop, world));
    }
    Block torchNorth = block.getWorld().getBlockAt(x + 1, y, z);
    if (torchTypes.contains(torchNorth.getTypeId()) && torchNorth.getData() == 1) {
      bystanders.add(new BrokenBlock(player, torchNorth, world));
    }
    Block torchSouth = block.getWorld().getBlockAt(x - 1, y, z);
    if (torchTypes.contains(torchSouth.getTypeId()) && torchSouth.getData() == 2) {
      bystanders.add(new BrokenBlock(player, torchSouth, world));
    }
    Block torchEast = block.getWorld().getBlockAt(x, y, z + 1);
    if (torchTypes.contains(torchEast.getTypeId()) && torchEast.getData() == 3) {
      bystanders.add(new BrokenBlock(player, torchEast, world));
    }
    Block torchWest = block.getWorld().getBlockAt(x, y, z - 1);
    if (torchTypes.contains(torchWest.getTypeId()) && torchWest.getData() == 4) {
      bystanders.add(new BrokenBlock(player, torchWest, world));
    }
  }
 private void destroyBelow(final Block b, final Block wire) {
   if (b.getTypeId() != PitfallSettings.redstonePitItem) return;
   final int wireId = wire.getTypeId();
   wire.setTypeId(0);
   b.setTypeId(0);
   plugin
       .getServer()
       .getScheduler()
       .scheduleSyncDelayedTask(
           plugin,
           new Runnable() {
             public void run() {
               try {
                 wire.setTypeId(wireId);
                 b.setTypeId(PitfallSettings.redstonePitItem);
               } catch (Exception e) {
               }
             }
           },
           PitfallSettings.returnDelay);
   if (PitfallSettings.redstoneTriggerCorner) {
     destroyBelow(b.getRelative(BlockFace.NORTH_EAST), wire.getRelative(BlockFace.NORTH_EAST));
     destroyBelow(b.getRelative(BlockFace.NORTH_WEST), wire.getRelative(BlockFace.NORTH_WEST));
     destroyBelow(b.getRelative(BlockFace.SOUTH_EAST), wire.getRelative(BlockFace.SOUTH_EAST));
     destroyBelow(b.getRelative(BlockFace.SOUTH_WEST), wire.getRelative(BlockFace.SOUTH_WEST));
   }
   destroyBelow(b.getRelative(BlockFace.NORTH), wire.getRelative(BlockFace.NORTH));
   destroyBelow(b.getRelative(BlockFace.EAST), wire.getRelative(BlockFace.EAST));
   destroyBelow(b.getRelative(BlockFace.WEST), wire.getRelative(BlockFace.WEST));
   destroyBelow(b.getRelative(BlockFace.SOUTH), wire.getRelative(BlockFace.SOUTH));
 }
예제 #6
0
  @SuppressWarnings("deprecation")
  @Override
  public SpellResult onCast(ConfigurationSection parameters) {
    Target target = getTarget();
    if (target.hasEntity()) {
      SpellResult result = alterEntity(target.getEntity());
      if (result != SpellResult.NO_TARGET) {
        return result;
      }
    }
    Block targetBlock = target.getBlock();
    if (targetBlock == null) {
      return SpellResult.NO_TARGET;
    }

    int recurseDistance = parameters.getInt("depth", DEFAULT_RECURSE_DISTANCE);
    recurseDistance = (int) (mage.getRadiusMultiplier() * recurseDistance);

    List<Integer> adjustableMaterials = parseIntegers(DEFAULT_ADJUSTABLES);
    List<Integer> maxData = parseIntegers(DEFAULT_ADJUST_MAX);
    List<Integer> minData = parseIntegers(DEFAULT_ADJUST_MIN);

    if (adjustableMaterials.size() != maxData.size() || maxData.size() != minData.size()) {
      controller.getLogger().warning("Spells:Alter: Mis-match in adjustable material lists!");
    }

    if (!adjustableMaterials.contains(targetBlock.getTypeId())) {
      return SpellResult.FAIL;
    }
    if (!hasBuildPermission(targetBlock)) {
      return SpellResult.INSUFFICIENT_PERMISSION;
    }
    if (mage.isIndestructible(targetBlock)) {
      return SpellResult.NO_TARGET;
    }
    if (!isDestructible(targetBlock)) {
      return SpellResult.NO_TARGET;
    }

    int originalData = targetBlock.getData();

    int materialIndex = adjustableMaterials.indexOf(targetBlock.getTypeId());
    int minValue = minData.get(materialIndex);
    int maxValue = maxData.get(materialIndex);
    int dataSize = maxValue - minValue + 1;

    byte data = (byte) ((((originalData - minValue) + 1) % dataSize) + minValue);

    boolean recursive = recurseDistance > 0;
    adjust(targetBlock, data, recursive, recurseDistance, 0);
    registerForUndo();
    return SpellResult.CAST;
  }
  /*
   * Called when a player places a block.
   */
  @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
  public void onBlockPlace(BlockPlaceEvent event) {
    Block blockPlaced = event.getBlock();
    Player player = event.getPlayer();
    World world = blockPlaced.getWorld();

    ConfigurationManager cfg = plugin.getGlobalStateManager();
    WorldConfiguration wcfg = cfg.get(world);

    if (wcfg.useRegions) {
      final Location location = blockPlaced.getLocation();
      if (!plugin.getGlobalRegionManager().canBuild(player, location)
          || !plugin.getGlobalRegionManager().canConstruct(player, location)) {
        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 BlockPlaceBlacklistEvent(
                  plugin.wrapPlayer(player), toVector(blockPlaced), blockPlaced.getTypeId()),
              false,
              false)) {
        event.setCancelled(true);
        return;
      }
    }

    if (wcfg.signChestProtection && wcfg.getChestProtection().isChest(blockPlaced.getTypeId())) {
      if (wcfg.isAdjacentChestProtected(event.getBlock(), player)) {
        player.sendMessage(
            ChatColor.DARK_RED + "This spot is for a chest that you don't have permission for.");
        event.setCancelled(true);
        return;
      }
    }

    if (wcfg.simulateSponge && blockPlaced.getTypeId() == 19) {
      if (wcfg.redstoneSponges && blockPlaced.isBlockIndirectlyPowered()) {
        return;
      }

      int ox = blockPlaced.getX();
      int oy = blockPlaced.getY();
      int oz = blockPlaced.getZ();

      SpongeUtil.clearSpongeWater(plugin, world, ox, oy, oz);
    }
  }
예제 #8
0
  public static void smartLogFallables(Consumer consumer, String playerName, Block origin) {

    WorldConfig wcfg = getWorldConfig(origin.getWorld());
    if (wcfg == null) return;

    // Handle falling blocks
    Block checkBlock = origin.getRelative(BlockFace.UP);
    int up = 0;
    final int highestBlock = checkBlock.getWorld().getHighestBlockYAt(checkBlock.getLocation());
    while (BukkitUtils.getRelativeTopFallables().contains(checkBlock.getType())) {

      // Record this block as falling
      consumer.queueBlockBreak(playerName, checkBlock.getState());

      // Guess where the block is going (This could be thrown of by explosions, but it is better
      // than nothing)
      Location loc = origin.getLocation();
      int x = loc.getBlockX();
      int y = loc.getBlockY();
      int z = loc.getBlockZ();
      while (y > 0 && BukkitUtils.canFall(loc.getWorld(), x, (y - 1), z)) {
        y--;
      }
      // If y is 0 then the sand block fell out of the world :(
      if (y != 0) {
        Location finalLoc = new Location(loc.getWorld(), x, y, z);
        // Run this check to avoid false positives
        if (!BukkitUtils.getFallingEntityKillers().contains(finalLoc.getBlock().getType())) {
          finalLoc.add(0, up, 0); // Add this here after checking for block breakers
          if (finalLoc.getBlock().getType() == Material.AIR
              || BukkitUtils.getRelativeTopFallables().contains(finalLoc.getBlock().getType())) {
            consumer.queueBlockPlace(
                playerName, finalLoc, checkBlock.getTypeId(), checkBlock.getData());
          } else {
            consumer.queueBlockReplace(
                playerName,
                finalLoc,
                finalLoc.getBlock().getTypeId(),
                finalLoc.getBlock().getData(),
                checkBlock.getTypeId(),
                checkBlock.getData());
          }
          up++;
        }
      }
      if (checkBlock.getY() >= highestBlock) break;
      checkBlock = checkBlock.getRelative(BlockFace.UP);
    }
  }
 public static boolean protectBlock(Block block, String name) {
   boolean protect = false;
   if (lwc != null) {
     lwc.getPhysicalDatabase()
         .registerProtection(
             block.getTypeId(),
             ProtectionTypes.PRIVATE,
             block.getWorld().getName(),
             name,
             "",
             block.getX(),
             block.getY(),
             block.getZ());
     protect = true;
     TDebug.debug(
         DebugDetailLevel.EVERYTHING,
         block.getType().name()
             + " block protected for "
             + name
             + ". ("
             + block.getX()
             + ", "
             + block.getY()
             + ", "
             + block.getZ()
             + ")");
   }
   return protect;
 }
예제 #10
0
  public void storeClaimBackup(Claim claim, World world) {
    int baseX = getBase(claim.getX());
    long topX = claim.getX() >= 0 ? baseX + claimSize : baseX - claimSize;

    int baseZ = getBase(claim.getZ());
    long topZ = claim.getZ() >= 0 ? baseZ + claimSize : baseZ - claimSize;

    int maxY = world.getMaxHeight();

    Properties props = new Properties();

    for (int y = 0; y <= maxY; y++) {
      for (int z = baseZ; z <= topZ; z++) {
        for (int x = baseX; x <= topX; x++) {
          Block blockAt = world.getBlockAt(x, y, z);
          props.put(
              String.format("%d,%d,%d", x, y, z),
              String.format("%d:%d", blockAt.getTypeId(), blockAt.getData()));
        }
      }
    }

    File file = new File(backupFolder, String.format("claim-%d.xml"));

    try {
      props.storeToXML(
          new FileOutputStream(file), String.format("Claim backup for claim %d", claim.getId()));
    } catch (FileNotFoundException e) {
      logger.severe("Could not write backup to file" + file.getName());
    } catch (IOException e) {
      logger.severe("Could not write backup to file" + file.getName() + ": " + e.getMessage());
    }
  }
예제 #11
0
 /**
  * Sets the given block to fluid water. Used by addSpongeWater()
  *
  * @param world
  * @param ox
  * @param oy
  * @param oz
  */
 public static void setBlockToWater(World world, int ox, int oy, int oz) {
   Block block = world.getBlockAt(ox, oy, oz);
   int id = block.getTypeId();
   if (id == 0) {
     block.setTypeId(8);
   }
 }
예제 #12
0
 @Override
 public void perform(Block b) {
   if (b.getTypeId() == r) {
     h.put(b);
     b.setTypeId(i, false);
   }
 }
예제 #13
0
  @Override
  public void onBlockPlace(BlockPlaceEvent event) {
    if (event.isCancelled()) return;

    final Player player = event.getPlayer();
    final Block block = event.getBlock();

    // Check if block in an ExpensiveType
    if (!fieldManager.isExpensiveType(block.getTypeId())) return;
    // Check if block is known to PreciousStone (did stone get registered there)
    if (!stones.getForceFieldManager().isField(block)) return;
    System.out.println("Expst: stone is a Field block.");
    // Do nothing when player has bypass permissions
    if (permissionManager.bypassResult(player)) {
      player.sendMessage(
          ChatColor.YELLOW + "ExpensiveStones: Bypassed! Field handled by PreciousStones.");
      return;
    }

    // Add Field, will auto-dormant in creation of ExpensiveField
    ExpensiveField expField = new ExpensiveField(stones.getForceFieldManager().getField(block));
    fieldManager.addField(expField, true);
    player.sendMessage(ChatColor.YELLOW + "ExpensiveStones: stone detected! Stone is disabled.");
    player.sendMessage(ChatColor.YELLOW + "Place chest and sign to activate the field.");
  }
예제 #14
0
  /**
   * @param block
   * @param owner
   */
  public Unbreakable(Block block, String owner) {
    super(block.getX(), block.getY(), block.getZ(), block.getWorld().getName());

    this.owner = owner;
    this.type = new BlockTypeEntry(block.getTypeId(), block.getData());
    this.dirty = true;
  }
예제 #15
0
 public void setBlockCheck(World w, int x, int y, int z, int m, byte d, int id) {
   // List of blocks that a door cannot be placed on
   List<Integer> ids =
       Arrays.asList(
           0, 6, 8, 9, 10, 11, 18, 20, 26, 27, 28, 29, 30, 31, 32, 33, 34, 37, 38, 39, 40, 44, 46,
           50, 51, 53, 54, 55, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 75, 76,
           77, 78, 79, 81, 83, 85, 89, 92, 93, 94, 96, 101, 102, 104, 105, 106, 107, 108, 109, 111,
           113, 114, 115, 116, 117, 118, 119, 120, 122, 128, 130, 131, 132, 134, 135, 136);
   Block b = w.getBlockAt(x, y, z);
   Integer bId = Integer.valueOf(b.getTypeId());
   byte bData = b.getData();
   Statement statement = null;
   if (ids.contains(bId)) {
     b.setTypeIdAndData(m, d, true);
     // remember replaced block location, TypeId and Data so we can restore it later
     try {
       Connection connection = service.getConnection();
       statement = connection.createStatement();
       String replaced = w.getName() + ":" + x + ":" + y + ":" + z + ":" + bId + ":" + bData;
       String queryReplaced =
           "UPDATE tardis SET replaced = '" + replaced + "' WHERE tardis_id = " + id;
       statement.executeUpdate(queryReplaced);
       statement.close();
     } catch (SQLException e) {
       plugin.console.sendMessage(plugin.pluginName + "Set Replaced Block Error: " + e);
     } finally {
       try {
         statement.close();
       } catch (Exception e) {
       }
     }
   }
 }
예제 #16
0
  /*
   * (non-Javadoc)
   * @see com.nitnelave.CreeperHeal.block.Replaceable#replace(boolean)
   */
  @Override
  public boolean replace(boolean shouldDrop) {
    Block block = getBlock();
    int blockId = block.getTypeId();

    if (!CreeperConfig.overwriteBlocks && !isEmpty(blockId)) {
      if (CreeperConfig.dropDestroyedBlocks) drop();
      return true;
    } else if (CreeperConfig.overwriteBlocks
        && !isEmpty(blockId)
        && CreeperConfig.dropDestroyedBlocks) {
      CreeperBlock.newBlock(block.getState()).drop();
      block.setTypeIdAndData(0, (byte) 0, false);
    }

    if (!shouldDrop
        && isDependent(getTypeId())
        && isEmpty(getBlock().getRelative(getAttachingFace()).getTypeId())) {
      delay_replacement();
      return true;
    } else update();

    // TODO: Check the necessity, and move to CreeperRail if possible.
    checkForAscendingRails();

    return true;
  }
 @Override
 public void perform(Block b) {
   if (b.getTypeId() == ir) {
     h.put(b);
     b.setTypeIdAndData(i, d, true);
   }
 }
예제 #18
0
 @EventHandler(priority = EventPriority.HIGHEST)
 public void onPlayerInteractEventCand(PlayerInteractEvent event) {
   if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
     Block block = event.getClickedBlock();
     if ((block.getTypeId() == 63) || (block.getTypeId() == 68)) {
       Sign sign = (Sign) block.getState();
       String line0pc = sign.getLine(0);
       String line1pc = sign.getLine(1);
       if (line0pc.contains("[Warp]")) {
         Player p = event.getPlayer();
         String warp = line1pc.toString();
         p.performCommand("Warp " + warp);
       }
     }
   }
 }
예제 #19
0
  private void checkGnomesLivingOnTop(String player, Block block) {
    ArrayList<Integer> gnomes = new ArrayList<Integer>();
    gnomes.add(6); // Sapling
    gnomes.add(37); // Yellow Flower
    gnomes.add(38); // Red Flower
    gnomes.add(39); // Brown Mushroom
    gnomes.add(40); // Red Mushroom
    gnomes.add(55); // Redstone
    gnomes.add(59); // Crops
    gnomes.add(64); // Wood Door
    gnomes.add(66); // Tracks
    gnomes.add(69); // Lever
    gnomes.add(70); // Stone pressure plate
    gnomes.add(71); // Iron Door
    gnomes.add(72); // Wood pressure ePlate
    gnomes.add(78); // Snow
    gnomes.add(81); // Cactus
    gnomes.add(83); // Reeds

    int x = block.getX();
    int y = block.getY();
    int z = block.getZ();
    Block mrGnome = block.getWorld().getBlockAt(x, y + 1, z);

    if (gnomes.contains(mrGnome.getTypeId())) {
      bystanders.add(new BrokenBlock(player, mrGnome, world));
    }
  }
예제 #20
0
    public eBlock(final Block bl) {
      this.b = bl;
      this.i = bl.getTypeId();
      switch (bl.getType()) {
        case AIR:
          this.solid = false;
          break;

        case WATER:
          this.solid = false;
          break;

        case STATIONARY_WATER:
          this.solid = false;
          break;

        case STATIONARY_LAVA:
          this.solid = false;
          break;
        case LAVA:
          this.solid = false;
          break;

        default:
          this.solid = true;
      }
    }
예제 #21
0
 @Override
 public Cauldron detect(BlockWorldVector pt) {
   Block block = pt.toBlock();
   // 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);
 }
예제 #22
0
  public void loopThrough(Location loc1, Location loc2, World w) {

    File file = new File("plugins/NerdLocker/blocks.lock");
    if (!(file.exists())) {
      try {
        FileInputStream fstream = new FileInputStream("plugins/NerdLocker/blocks.lock");
        fstream.close();
      } catch (IOException e) {
        e.printStackTrace();
      }
    }

    int minx = Math.min(loc1.getBlockX(), loc2.getBlockX()),
        miny = Math.min(loc1.getBlockY(), loc2.getBlockY()),
        minz = Math.min(loc1.getBlockZ(), loc2.getBlockZ()),
        maxx = Math.max(loc1.getBlockX(), loc2.getBlockX()),
        maxy = Math.max(loc1.getBlockY(), loc2.getBlockY()),
        maxz = Math.max(loc1.getBlockZ(), loc2.getBlockZ());
    for (int x = minx; x <= maxx; x++) {
      for (int y = miny; y <= maxy; y++) {
        for (int z = minz; z <= maxz; z++) {
          Block b = w.getBlockAt(x, y, z);
          if (b.getTypeId() != 0) {
            addBlock(b);
          }
        }
      }
    }
  }
예제 #23
0
  /**
   * Applies a list of transformation on a block, if the block is not protected.
   *
   * @param toTransform the Bukkit block object to transform
   * @param transformations the list if transformations to apply
   */
  public static void transform(Block toTransform, List<List<String>> transformations) {
    if (isBlockProtected(toTransform)) {
      return;
    }

    for (List<String> toCheck : transformations) {
      ArrayList<String[]> stateIndex = new ArrayList<String[]>();

      for (int i = 0; i != 2; ++i) {
        String got = toCheck.get(i);

        if (got.contains(":")) { // Check for data _ appended.
          stateIndex.add(got.split(":"));
        } else {
          stateIndex.add(new String[] {got, "0"});
        }
      }

      String[] curState = stateIndex.get(0), toState = stateIndex.get(1);

      if (Integer.valueOf(curState[0]) == toTransform.getTypeId()
          && Integer.valueOf(curState[1]) == toTransform.getData()) {
        toTransform.setTypeIdAndData(Integer.valueOf(toState[0]), Byte.parseByte(toState[1]), true);
        return;
      }
    }
  }
예제 #24
0
  /**
   * Called when a player places a block
   *
   * @param event Relevant event details
   */
  @Override
  public void onBlockPlace(BlockPlaceEvent event) {

    if (event.isCancelled()) {
      return;
    }

    Block blockPlaced = event.getBlock();
    Player player = event.getPlayer();
    World world = blockPlaced.getWorld();

    ConfigurationManager cfg = plugin.getGlobalConfiguration();
    WorldConfiguration wcfg = cfg.get(world);

    if (wcfg.useRegions) {
      if (!plugin.getGlobalRegionManager().canBuild(player, blockPlaced.getLocation())) {
        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 BlockPlaceBlacklistEvent(
                  plugin.wrapPlayer(player), toVector(blockPlaced), blockPlaced.getTypeId()),
              false,
              false)) {
        event.setCancelled(true);
        return;
      }
    }

    if (wcfg.simulateSponge && blockPlaced.getTypeId() == 19) {
      if (wcfg.redstoneSponges && blockPlaced.isBlockIndirectlyPowered()) {
        return;
      }

      int ox = blockPlaced.getX();
      int oy = blockPlaced.getY();
      int oz = blockPlaced.getZ();

      clearSpongeWater(world, ox, oy, oz);
    }
  }
예제 #25
0
  @Override
  public void changeBlock(Block block) {
    if (block.getTypeId() == match.getItemTypeId()
        && (match.getData() == 0 || block.getData() == match.getData())) {

      player.sendBlockChange(block.getLocation(), item.getItemType(), item.getData());
    }
  }
예제 #26
0
 /**
  * Iteratively determines the highest solid block
  *
  * @param chunk
  * @param x
  * @param z
  * @return Block highest solid
  */
 public Block getHighestSolidBlock(Chunk chunk, int x, int z) {
   Block block = null;
   // Return the highest block
   for (int i = 127; i >= 0; i--)
     if (!(block = chunk.getBlock(x, i, z)).isLiquid() && block.getTypeId() != 0) return block;
   // And as a matter of completeness, return the lowest point
   return block;
 }
예제 #27
0
 public void breakFoliage(Block b) {
   for (BlockFace bf : BlockFace.values()) {
     Block toTest = b.getRelative(bf, 1);
     if (toTest.getTypeId() == 18) {
       toTest.breakNaturally();
     }
   }
 }
예제 #28
0
 @SuppressWarnings("deprecation")
 private boolean isBlockBreakable(Block block) {
   Integer id = block.getTypeId();
   if (Arrays.asList(breakables).contains(id) && !Illumination.blocks.containsKey(block)) {
     return true;
   }
   return false;
 }
예제 #29
0
 public BlockType CheckBlock(Block block)
     throws InvocationTargetException, IllegalAccessException {
   if (block.getTypeId() < 4096 && block.getTypeId() != 0) {
     Object object = nmsResolver.getBlockList().get(block.getTypeId());
     ForgePermittor.log(object.getClass().toString(), true);
     // todo Test if this doesn't break something
     if (
     /*this.getInformationManager().HasContainerInterface(object) || */ nmsResolver
         .getCraftWorldHandler()
         .HasTileEntity(block))
       if (this.getInformationManager()
           .HasTradeBlockInterface(nmsResolver.getCraftWorldHandler().getTileEntityFrom(block)))
         return BlockType.Trade;
       else return BlockType.Container; // CheckConnectable(block);
     if (this.getInformationManager().HasBlockInterface(object)) return BlockType.Block;
   }
   return BlockType.Unknown;
 }
예제 #30
0
 private void gessThree(Block b) {
   for (BlockFace bf : BlockFace.values()) {
     Block toTest = b.getRelative(bf, 1);
     if (toTest.getTypeId() == 17 && !arbre.contains(toTest)) {
       arbre.add(toTest);
       gessThree(toTest);
     }
   }
 }