Java Code Examples for org.bukkit.block.BlockState#getBlock()

The following examples show how to use org.bukkit.block.BlockState#getBlock() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FallingBlocksMatchModule.java    From PGM with GNU Affero General Public License v3.0 6 votes vote down vote up
private void disturb(long pos, BlockState blockState, @Nullable ParticipantState disturber) {
  FallingBlocksRule rule = this.ruleWithShortestDelay(blockState);
  if (rule != null) {
    long tick = match.getTick().tick + rule.delay;
    TLongObjectMap<ParticipantState> blockDisturbers = this.blockDisturbersByTick.get(tick);

    if (blockDisturbers == null) {
      blockDisturbers = new TLongObjectHashMap<>();
      this.blockDisturbersByTick.put(tick, blockDisturbers);
    }

    Block block = blockState.getBlock();
    if (!blockDisturbers.containsKey(pos)) {
      blockDisturbers.put(pos, disturber);
    }
  }
}
 
Example 2
Source File: FallingBlocksMatchModule.java    From PGM with GNU Affero General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockChange(BlockTransformEvent event) {
  BlockState newState = event.getNewState();
  Block block = newState.getBlock();
  long pos = encodePos(block);

  // Only breaks are credited. Making a bridge fall by updating a block
  // does not credit you with breaking the bridge.
  ParticipantState breaker =
      event.isBreak() ? ParticipantBlockTransformEvent.getPlayerState(event) : null;

  if (!(event.getCause() instanceof BlockFallEvent)) {
    this.disturb(pos, newState, breaker);
  }

  for (BlockFace face : NEIGHBORS) {
    this.disturb(neighborPos(pos, face), block.getRelative(face).getState(), breaker);
  }
}
 
Example 3
Source File: CraftEventFactory.java    From Kettle with GNU General Public License v3.0 6 votes vote down vote up
public static BlockPlaceEvent callBlockPlaceEvent(World world, EntityPlayer who, EnumHand hand, BlockState replacedBlockState, int clickedX, int clickedY, int clickedZ) {
    CraftWorld craftWorld = world.getWorld();
    CraftServer craftServer = world.getServer();

    Player player = (Player) who.getBukkitEntity();

    Block blockClicked = craftWorld.getBlockAt(clickedX, clickedY, clickedZ);
    Block placedBlock = replacedBlockState.getBlock();

    boolean canBuild = canBuild(craftWorld, player, placedBlock.getX(), placedBlock.getZ());

    org.bukkit.inventory.ItemStack item;
    EquipmentSlot equipmentSlot;
    if (hand == EnumHand.MAIN_HAND) {
        item = player.getInventory().getItemInMainHand();
        equipmentSlot = EquipmentSlot.HAND;
    } else {
        item = player.getInventory().getItemInOffHand();
        equipmentSlot = EquipmentSlot.OFF_HAND;
    }

    BlockPlaceEvent event = new BlockPlaceEvent(placedBlock, replacedBlockState, blockClicked, item, player, canBuild, equipmentSlot);
    craftServer.getPluginManager().callEvent(event);

    return event;
}
 
Example 4
Source File: FallingBlocksMatchModule.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
private void disturb(long pos, BlockState blockState, @Nullable ParticipantState disturber) {
    FallingBlocksRule rule = this.ruleWithShortestDelay(blockState);
    if(rule != null) {
        long tick = this.getMatch().getClock().now().tick + rule.delay;
        TLongObjectMap<ParticipantState> blockDisturbers = this.blockDisturbersByTick.get(tick);

        if(blockDisturbers == null) {
            blockDisturbers = new TLongObjectHashMap<>();
            this.blockDisturbersByTick.put(tick, blockDisturbers);
        }

        Block block = blockState.getBlock();
        if(!blockDisturbers.containsKey(pos)) {
            blockDisturbers.put(pos, disturber);
        }
    }
}
 
Example 5
Source File: FallingBlocksMatchModule.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockChange(BlockTransformEvent event) {
    BlockState newState = event.getNewState();
    Block block = newState.getBlock();
    long pos = encodePos(block);

    // Only breaks are credited. Making a bridge fall by updating a block
    // does not credit you with breaking the bridge.
    ParticipantState breaker = event.isBreak() ? ParticipantBlockTransformEvent.getPlayerState(event) : null;

    if(!(event.getCause() instanceof BlockFallEvent)) {
        this.disturb(pos, newState, breaker);
    }

    for(BlockFace face : NEIGHBORS) {
        this.disturb(neighborPos(pos, face), block.getRelative(face).getState(), breaker);
    }
}
 
Example 6
Source File: CraftEventFactory.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
public static boolean handleBlockFormEvent(World world, BlockPos pos, IBlockState block, @Nullable Entity entity) {
    BlockState blockState = world.getWorld().getBlockAt(pos.getX(), pos.getY(), pos.getZ()).getState();
    blockState.setType(CraftMagicNumbers.getMaterial(block.getBlock()));
    blockState.setRawData((byte) block.getBlock().getMetaFromState(block));

    BlockFormEvent event = (entity == null) ? new BlockFormEvent(blockState.getBlock(), blockState) : new EntityBlockFormEvent(entity.getBukkitEntity(), blockState.getBlock(), blockState);
    world.getServer().getPluginManager().callEvent(event);

    if (!event.isCancelled()) {
        blockState.update(true);
    }

    return !event.isCancelled();
}
 
Example 7
Source File: ShopItemListener.java    From ShopChest with MIT License 5 votes vote down vote up
@EventHandler(priority = EventPriority.HIGH)
public void onStructureGrow(StructureGrowEvent e) {
    for (BlockState state : e.getBlocks()) {
        Block newBlock = state.getBlock();
        if (shopUtils.isShop(newBlock.getLocation()) || shopUtils.isShop(newBlock.getRelative(BlockFace.DOWN).getLocation())) {
            e.setCancelled(true);
        }
    }
}
 
Example 8
Source File: DoorMatcher.java    From Modern-LWC with MIT License 4 votes vote down vote up
public boolean matches(ProtectionFinder finder) {
    BlockState baseBlockState = finder.getBaseBlock();
    Block block = baseBlockState.getBlock();
    // Get the block above the base block
    Block aboveBaseBlock = block.getRelative(BlockFace.UP);

    // Get the block above the block above the base block
    Block aboveAboveBaseBlock = aboveBaseBlock.getRelative(BlockFace.UP);

    // look for door if they're clicking a pressure plate
    if (PRESSURE_PLATES.contains(baseBlockState.getType()) || PRESSURE_PLATES.contains(aboveBaseBlock.getType())) {
        Block pressurePlate = PRESSURE_PLATES.contains(baseBlockState.getType()) ? block : aboveBaseBlock;

        for (BlockFace face : faces) {
            Block relative = pressurePlate.getRelative(face);

            // only check if it's a door
            if (!PROTECTABLES_DOORS.contains(relative.getType())) {
                continue;
            }

            // create a protection finder
            ProtectionFinder doorFinder = new ProtectionFinder(LWC.getInstance());

            // attempt to match the door
            if (doorFinder.matchBlocks(relative)) {
                // add the blocks it matched
                for (BlockState found : doorFinder.getBlocks()) {
                    finder.addBlock(found);
                }

                // add the pressure plate
                finder.addBlock(pressurePlate);
                return true;
            }
        }
    }

    // Match the block UNDER the door
    if (PROTECTABLES_DOORS.contains(aboveAboveBaseBlock.getType())
            && PROTECTABLES_DOORS.contains(aboveBaseBlock.getType())) {
        finder.addBlock(aboveAboveBaseBlock);
        finder.addBlock(aboveBaseBlock);
        findPressurePlate(finder, aboveBaseBlock);
        return true;
    }

    // Match the bottom half of the door
    else if (PROTECTABLES_DOORS.contains(aboveBaseBlock.getType())) {
        finder.addBlock(aboveBaseBlock);
        finder.addBlock(block.getRelative(BlockFace.DOWN));
        findPressurePlate(finder, block);
        return true;
    }

    // Match the top half of the door
    else if (PROTECTABLES_DOORS.contains(baseBlockState.getType())) {
        Block bottomHalf = block.getRelative(BlockFace.DOWN);

        finder.addBlock(bottomHalf);
        finder.addBlock(bottomHalf.getRelative(BlockFace.DOWN));
        findPressurePlate(finder, bottomHalf);
        return true;
    }

    return false;
}
 
Example 9
Source File: BlockTransformEvent.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
public BlockTransformEvent(Event cause, BlockState oldState, BlockState newState) {
    this(cause, oldState.getBlock(), oldState, newState);
}
 
Example 10
Source File: BlockFire.java    From Carbon with GNU Lesser General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
public void a(World world, int i, int j, int k, Random random) {
	if(world.getGameRules().getBoolean("doFireTick")) {
		boolean flag = world.getType(i, j - 1, k) == Blocks.NETHERRACK;
		if(((world.worldProvider instanceof WorldProviderTheEnd)) && (world.getType(i, j - 1, k) == Blocks.BEDROCK)) {
			flag = true;
		}
		if(!canPlace(world, i, j, k)) {
			fireExtinguished(world, i, j, k);
		}
		if((!flag) && (world.Q()) && ((world.isRainingAt(i, j, k)) || (world.isRainingAt(i - 1, j, k)) || (world.isRainingAt(i + 1, j, k)) || (world.isRainingAt(i, j, k - 1)) || (world.isRainingAt(i, j, k + 1)))) {
			fireExtinguished(world, i, j, k);
		}
		else {
			int l = world.getData(i, j, k);
			if(l < 15) {
				world.setData(i, j, k, l + random.nextInt(3) / 2, 4);
			}
			world.a(i, j, k, this, a(world) + random.nextInt(10));
			if((!flag) && (!e(world, i, j, k))) {
				if((!World.a(world, i, j - 1, k)) || (l > 3)) {
					fireExtinguished(world, i, j, k);
				}
			}
			else if((!flag) && (!e(world, i, j - 1, k)) && (l == 15) && (random.nextInt(4) == 0)) {
				fireExtinguished(world, i, j, k);
			}
			else {
				boolean flag1 = world.z(i, j, k);
				byte b0 = 0;
				if(flag1) {
					b0 = -50;
				}
				a(world, i + 1, j, k, 300 + b0, random, l);
				a(world, i - 1, j, k, 300 + b0, random, l);
				a(world, i, j - 1, k, 250 + b0, random, l);
				a(world, i, j + 1, k, 250 + b0, random, l);
				a(world, i, j, k - 1, 300 + b0, random, l);
				a(world, i, j, k + 1, 300 + b0, random, l);
				for(int i1 = i - 1; i1 <= i + 1; i1++) {
					for(int j1 = k - 1; j1 <= k + 1; j1++) {
						for(int k1 = j - 1; k1 <= j + 4; k1++) {
							if((i1 != i) || (k1 != j) || (j1 != k)) {
								int l1 = 100;
								if(k1 > j + 1) {
									l1 += (k1 - (j + 1)) * 100;
								}
								int i2 = m(world, i1, k1, j1);
								if(i2 > 0) {
									int j2 = (i2 + 40 + world.difficulty.a() * 7) / (l + 30);
									if(flag1) {
										j2 /= 2;
									}
									if((j2 > 0) && (random.nextInt(l1) <= j2) && ((!world.Q()) || (!world.isRainingAt(i1, k1, j1))) && (!world.isRainingAt(i1 - 1, k1, k)) && (!world.isRainingAt(i1 + 1, k1, j1)) && (!world.isRainingAt(i1, k1, j1 - 1)) && (!world.isRainingAt(i1, k1, j1 + 1))) {
										int k2 = l + random.nextInt(5) / 4;
										if(k2 > 15) {
											k2 = 15;
										}
										if((world.getType(i1, k1, j1) != this) && (!CraftEventFactory.callBlockIgniteEvent(world, i1, k1, j1, i, j, k).isCancelled())) {
											Server server = world.getServer();
											org.bukkit.World bworld = world.getWorld();
											BlockState blockState = bworld.getBlockAt(i1, k1, j1).getState();
											blockState.setTypeId(Block.getId(this));
											blockState.setData(new MaterialData(Block.getId(this), (byte) k2));

											BlockSpreadEvent spreadEvent = new BlockSpreadEvent(blockState.getBlock(), bworld.getBlockAt(i, j, k), blockState);
											server.getPluginManager().callEvent(spreadEvent);
											if(!spreadEvent.isCancelled()) {
												blockState.update(true);
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}
}