@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
  public void onStructureGrow(final StructureGrowEvent event) {
    List<BlockState> blocks = event.getBlocks();
    boolean found = false;

    for (int i = 0; i < blocks.size(); i++) {
      if (found || PlotManager.isPlotWorld(blocks.get(i))) {
        found = true;
        String id = PlotManager.getPlotId(blocks.get(i).getLocation());

        if (id.equalsIgnoreCase("")) {
          event.getBlocks().remove(i);
          i--;
        }
      }
    }
  }
Esempio n. 2
0
  // lightstone - added bonemeal, player and itemstack
  public boolean b(
      World world,
      int i,
      int j,
      int k,
      Random random,
      boolean bonemeal,
      Player player,
      ItemStack itemstack) {
    int l = world.getData(i, j, k);

    world.setRawTypeId(i, j, k, 0);
    // lightstone start
    boolean grown = false;
    StructureGrowEvent event = null;
    Location location = new Location(world.getWorld(), i, j, k);
    WorldGenHugeMushroom worldgenhugemushroom = null;

    if (this.id == Block.BROWN_MUSHROOM.id) {
      event =
          new StructureGrowEvent(
              location, TreeType.BROWN_MUSHROOM, bonemeal, player, new ArrayList<BlockState>());
      worldgenhugemushroom = new WorldGenHugeMushroom(0);
    } else if (this.id == Block.RED_MUSHROOM.id) {
      event =
          new StructureGrowEvent(
              location, TreeType.RED_MUSHROOM, bonemeal, player, new ArrayList<BlockState>());
      worldgenhugemushroom = new WorldGenHugeMushroom(1);
    }
    if (worldgenhugemushroom != null && event != null) {
      grown = worldgenhugemushroom.grow(world, random, i, j, k, event, itemstack, world.getWorld());
    }
    if (!grown || event.isCancelled()) {
      world.setRawTypeIdAndData(i, j, k, this.id, l);
      return false;
    }
    return true;
    // lightstone end
  }
Esempio n. 3
0
  public boolean placeItem(
      EntityHuman entityhuman,
      World world,
      BlockPosition blockposition,
      EnumDirection enumdirection,
      float f,
      float f1,
      float f2) {
    // CraftBukkit start - handle all block place event logic here
    int data = this.getData();
    int count = this.count;

    if (!(this.getItem() instanceof ItemBucket)) { // if not bucket
      world.captureBlockStates = true;
      // special case bonemeal
      if (this.getItem() instanceof ItemDye && this.getData() == 15) {
        Block block = world.getType(blockposition).getBlock();
        if (block == Blocks.SAPLING || block instanceof BlockMushroom) {
          world.captureTreeGeneration = true;
        }
      }
    }
    boolean flag =
        this.getItem()
            .interactWith(this, entityhuman, world, blockposition, enumdirection, f, f1, f2);
    int newData = this.getData();
    int newCount = this.count;
    this.count = count;
    this.setData(data);
    world.captureBlockStates = false;
    if (flag && world.captureTreeGeneration && world.capturedBlockStates.size() > 0) {
      world.captureTreeGeneration = false;
      Location location =
          new Location(
              world.getWorld(), blockposition.getX(), blockposition.getY(), blockposition.getZ());
      TreeType treeType = BlockSapling.treeType;
      BlockSapling.treeType = null;
      List<BlockState> blocks = (List<BlockState>) world.capturedBlockStates.clone();
      world.capturedBlockStates.clear();
      StructureGrowEvent event = null;
      if (treeType != null) {
        event =
            new StructureGrowEvent(
                location, treeType, false, (Player) entityhuman.getBukkitEntity(), blocks);
        org.bukkit.Bukkit.getPluginManager().callEvent(event);
      }
      if (event == null || !event.isCancelled()) {
        // Change the stack to its new contents if it hasn't been tampered with.
        if (this.count == count && this.getData() == data) {
          this.setData(newData);
          this.count = newCount;
        }
        for (BlockState blockstate : blocks) {
          blockstate.update(true);
        }
      }

      return flag;
    }
    world.captureTreeGeneration = false;

    if (flag) {
      org.bukkit.event.block.BlockPlaceEvent placeEvent = null;
      List<BlockState> blocks = (List<BlockState>) world.capturedBlockStates.clone();
      world.capturedBlockStates.clear();
      if (blocks.size() > 1) {
        placeEvent =
            org.bukkit.craftbukkit.event.CraftEventFactory.callBlockMultiPlaceEvent(
                world,
                entityhuman,
                blocks,
                blockposition.getX(),
                blockposition.getY(),
                blockposition.getZ());
      } else if (blocks.size() == 1) {
        placeEvent =
            org.bukkit.craftbukkit.event.CraftEventFactory.callBlockPlaceEvent(
                world,
                entityhuman,
                blocks.get(0),
                blockposition.getX(),
                blockposition.getY(),
                blockposition.getZ());
      }

      if (placeEvent != null && (placeEvent.isCancelled() || !placeEvent.canBuild())) {
        flag = false; // cancel placement
        // revert back all captured blocks
        for (BlockState blockstate : blocks) {
          blockstate.update(true, false);
        }
      } else {
        // Change the stack to its new contents if it hasn't been tampered with.
        if (this.count == count && this.getData() == data) {
          this.setData(newData);
          this.count = newCount;
        }
        for (BlockState blockstate : blocks) {
          int x = blockstate.getX();
          int y = blockstate.getY();
          int z = blockstate.getZ();
          int updateFlag = ((CraftBlockState) blockstate).getFlag();
          org.bukkit.Material mat = blockstate.getType();
          Block oldBlock = CraftMagicNumbers.getBlock(mat);
          BlockPosition newblockposition = new BlockPosition(x, y, z);
          IBlockData block = world.getType(newblockposition);

          if (!(block instanceof BlockContainer)) { // Containers get placed automatically
            block.getBlock().onPlace(world, newblockposition, block);
          }

          world.notifyAndUpdatePhysics(
              newblockposition,
              null,
              oldBlock,
              block.getBlock(),
              updateFlag); // send null chunk as chunk.k() returns false by this point
        }
        entityhuman.b(StatisticList.USE_ITEM_COUNT[Item.getId(this.item)]);
      }
    }
    world.capturedBlockStates.clear();
    // CraftBukkit end

    return flag;
  }