Java Code Examples for org.bukkit.block.Block#getData()

The following examples show how to use org.bukkit.block.Block#getData() . 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: BlockImage.java    From PGM with GNU Affero General Public License v3.0 6 votes vote down vote up
/** Set every block in this image to its current state in the world */
@SuppressWarnings("deprecation")
public void save() {
  if (this.blockCounts != null) {
    this.blockCounts.clear();
  }

  int offset = 0;
  for (BlockVector v : this.bounds.getBlocks()) {
    Block block = this.world.getBlockAt(v.getBlockX(), v.getBlockY(), v.getBlockZ());
    this.blockIds[offset] = (short) block.getTypeId();
    this.blockData[offset] = block.getData();
    ++offset;

    if (this.blockCounts != null) {
      MaterialData md = block.getState().getData();
      this.blockCounts.put(md, this.blockCounts.get(md) + 1);
    }
  }
}
 
Example 2
Source File: WorldProblemListener.java    From PGM with GNU Affero General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void repairChunk(ChunkLoadEvent event) {
  if (this.repairedChunks.put(event.getWorld(), event.getChunk())) {
    // Replace formerly invisible half-iron-door blocks with barriers
    for (Block ironDoor : event.getChunk().getBlocks(Material.IRON_DOOR_BLOCK)) {
      BlockFace half = (ironDoor.getData() & 8) == 0 ? BlockFace.DOWN : BlockFace.UP;
      if (ironDoor.getRelative(half.getOppositeFace()).getType() != Material.IRON_DOOR_BLOCK) {
        ironDoor.setType(Material.BARRIER, false);
      }
    }

    // Remove all block 36 and remember the ones at y=0 so VoidFilter can check them
    for (Block block36 : event.getChunk().getBlocks(Material.PISTON_MOVING_PIECE)) {
      if (block36.getY() == 0) {
        block36Locations
            .get(event.getWorld())
            .add(block36.getX(), block36.getY(), block36.getZ());
      }
      block36.setType(Material.AIR, false);
    }
  }
}
 
Example 3
Source File: BlockListener.java    From Carbon with GNU Lesser General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void slabInteract(PlayerInteractEvent event) {
	if (event.getItem() == null || event.getAction() != Action.RIGHT_CLICK_BLOCK || event.getItem().getType() != Carbon.injector().redSandstoneSlabMat)
		return;
	Block clickedBlock = event.getClickedBlock();
	if (clickedBlock.getType() == Carbon.injector().redSandstoneSlabMat)
		if ((clickedBlock.getData() == 0 && event.getBlockFace() == BlockFace.UP) || (clickedBlock.getData() == 8 && event.getBlockFace() == BlockFace.DOWN)) {
			setDoubleSlab(event.getPlayer(), clickedBlock);
			event.setCancelled(true);
			return;
		}
	Block adjacent = clickedBlock.getRelative(event.getBlockFace());
	if (adjacent.getType() == Carbon.injector().redSandstoneSlabMat) {
		setDoubleSlab(event.getPlayer(), adjacent);
		event.setCancelled(true);
	}
}
 
Example 4
Source File: FaweAdapter_1_9.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
public BaseBlock getBlock(Location location)
{
    Preconditions.checkNotNull(location);

    CraftWorld craftWorld = (CraftWorld)location.getWorld();
    int x = location.getBlockX();
    int y = location.getBlockY();
    int z = location.getBlockZ();

    Block bukkitBlock = location.getBlock();
    BaseBlock block = new BaseBlock(bukkitBlock.getTypeId(), bukkitBlock.getData());

    TileEntity te = craftWorld.getHandle().getTileEntity(new BlockPosition(x, y, z));
    if (te != null)
    {
        NBTTagCompound tag = new NBTTagCompound();
        readTileEntityIntoTag(te, tag);
        block.setNbtData((CompoundTag)toNative(tag));
    }
    return block;
}
 
Example 5
Source File: FaweAdapter_1_10.java    From FastAsyncWorldedit with GNU General Public License v3.0 6 votes vote down vote up
public BaseBlock getBlock(Location location)
{
    Preconditions.checkNotNull(location);

    CraftWorld craftWorld = (CraftWorld)location.getWorld();
    int x = location.getBlockX();
    int y = location.getBlockY();
    int z = location.getBlockZ();

    Block bukkitBlock = location.getBlock();
    BaseBlock block = new BaseBlock(bukkitBlock.getTypeId(), bukkitBlock.getData());

    TileEntity te = craftWorld.getHandle().getTileEntity(new BlockPosition(x, y, z));
    if (te != null)
    {
        NBTTagCompound tag = new NBTTagCompound();
        readTileEntityIntoTag(te, tag);
        block.setNbtData((CompoundTag)toNative(tag));
    }
    return block;
}
 
Example 6
Source File: BukkitBlockConnectionProvider.java    From ViaVersion with MIT License 6 votes vote down vote up
@Override
public int getWorldBlockData(UserConnection user, int bx, int by, int bz) {
    UUID uuid = user.getProtocolInfo().getUuid();
    Player player = Bukkit.getPlayer(uuid);
    if (player != null) {
        World world = player.getWorld();
        int x = bx >> 4;
        int z = bz >> 4;
        if (world.isChunkLoaded(x, z)) {
            Chunk c = getChunk(world, x, z);
            Block b = c.getBlock(bx, by, bz);
            return b.getTypeId() << 4 | b.getData();
        }
    }
    return 0;
}
 
Example 7
Source File: BuildingCertainTaskType.java    From Quests with MIT License 6 votes vote down vote up
@SuppressWarnings("deprecation")
private boolean matchBlock(Task task, Block block) {
    Material material;
    Object configBlock = task.getConfigValue("block");
    Object configData = task.getConfigValue("data");
    Object configSimilarBlocks = task.getConfigValue("use-similar-blocks");

    material = Material.getMaterial(String.valueOf(configBlock));

    Material blockType = block.getType();
    short blockData = block.getData();

    if (blockType.equals(material)) {
        return configData == null || (((int) blockData) == ((int) configData));
    }
    return false;
}
 
Example 8
Source File: PlayerInteract.java    From AdditionsAPI with MIT License 5 votes vote down vote up
@EventHandler
public void onPlayerInteract(PlayerInteractEvent event) {
	Player player = event.getPlayer();
	PlayerInventory inv = player.getInventory();
	ItemStack item = inv.getItemInMainHand();
	if (event.getHand() != null)
		switch (event.getHand()) {
		case OFF_HAND:
			item = inv.getItemInOffHand();
			break;
		default:
			break;
		}

	if (AdditionsAPI.isCustomItem(item)) {
		CustomItemPlayerInteractEvent customEvent = new CustomItemPlayerInteractEvent(event,
				new CustomItemStack(item));
		Bukkit.getServer().getPluginManager().callEvent(customEvent);
	}
	if (event.getAction() != null && event.getAction() == Action.RIGHT_CLICK_BLOCK
			&& ToolType.getToolType(item.getType()) != null
			&& ToolType.getToolType(item.getType()).equals(ToolType.HOE)) {
		Block block = event.getClickedBlock();
		Material material = block.getType();
		Location blockLoc = block.getLocation();
		blockLoc.setY(blockLoc.getBlockY() + 1);
		Material materialUp = blockLoc.getBlock().getType();
		@SuppressWarnings("deprecation")
		byte data = block.getData();

		BlockFace face = event.getBlockFace();
		if (materialUp == Material.AIR && (face == BlockFace.UP || face == BlockFace.EAST || face == BlockFace.NORTH
				|| face == BlockFace.SOUTH || face == BlockFace.WEST))
			if (shouldPlaySound(material, item, data, player))
				player.playSound(block.getLocation(), "additionsapi.hoe.till", 1.0F, 1.0F);
	}
}
 
Example 9
Source File: FallingBlocksModule.java    From CardinalPGM with MIT License 5 votes vote down vote up
private void updateBlock(Block block, Rule rule) {
    if(rule.getFilter().evaluate(block).equals(FilterState.ALLOW)) {
        if (!isBlockAttached(block, rule)) {
            if (block.getRelative(BlockFace.DOWN).getType().equals(Material.AIR)) {
                Material material = block.getType();
                byte data = block.getData();
                block.setType(Material.AIR);
                Cardinal.getInstance().getGameHandler().getMatchWorld().spawnFallingBlock(block.getLocation(), material, data);
            } else {
                updateBlock(block.getRelative(BlockFace.DOWN), rule);
            }
        }
    }
}
 
Example 10
Source File: MiningCertainTaskType.java    From Quests with MIT License 5 votes vote down vote up
@SuppressWarnings("deprecation")
private boolean matchBlock(Task task, Block block) {
    Material material;


    Object configBlock = task.getConfigValues().containsKey("block") ? task.getConfigValue("block") : task.getConfigValue("blocks");
    Object configData = task.getConfigValue("data");
    Object configSimilarBlocks = task.getConfigValue("use-similar-blocks");

    List<String> checkBlocks = new ArrayList<>();
    if (configBlock instanceof List) {
        checkBlocks.addAll((List) configBlock);
    } else {
        checkBlocks.add(String.valueOf(configBlock));
    }

    for (String materialName : checkBlocks) {
        // LOG:1 LOG:2 LOG should all be supported with this
        String[] split = materialName.split(":");
        int comparableData = (int) configData;
        if (split.length > 1) {
            comparableData = Integer.parseInt(split[1]);
        }

        material = Material.getMaterial(String.valueOf(split[0]));
        Material blockType = block.getType();

        short blockData = block.getData();

        if (blockType.equals(material)) {
            return configData == null || ((int) blockData) == comparableData;
        }
    }
    return false;
}
 
Example 11
Source File: BukkitWorld.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public BaseBlock getBlock(Vector position) {
    BukkitImplAdapter adapter = BukkitQueue_0.getAdapter();
    if (adapter != null) {
        return adapter.getBlock(adapt(getWorld(), position));
    } else {
        Block bukkitBlock = getWorld().getBlockAt(position.getBlockX(), position.getBlockY(), position.getBlockZ());
        return new BaseBlock(bukkitBlock.getTypeId(), bukkitBlock.getData());
    }
}
 
Example 12
Source File: IslandGuard1_8.java    From askyblock with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Handle V1.8 blocks that need special treatment
 * Tilling of coarse dirt into dirt
 * Usually prevented because it could lead to an endless supply of dirt with gravel
 *
 * @param e - event
 */
@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.LOW, ignoreCancelled=true)
public void onPlayerInteract(final PlayerInteractEvent e) {
    if (DEBUG) {
        plugin.getLogger().info("1.8 " + e.getEventName());
    }
    if (!e.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
        return;
    }
    if (!IslandGuard.inWorld(e.getPlayer())) {
        return;
    }
    if (e.getPlayer().isOp()) {
        return;
    }
    // This permission bypasses protection
    if (VaultHelper.checkPerm(e.getPlayer(), Settings.PERMPREFIX + "mod.bypassprotect")
            || VaultHelper.checkPerm(e.getPlayer(), Settings.PERMPREFIX + "craft.dirt")) {
        return;
    }
    // Prevents tilling of coarse dirt into dirt
    ItemStack inHand = e.getPlayer().getItemInHand();
    if (inHand.getType() == Material.WOOD_HOE || inHand.getType() == Material.IRON_HOE || inHand.getType() == Material.GOLD_HOE
            || inHand.getType() == Material.DIAMOND_HOE || inHand.getType() == Material.STONE_HOE) {
        // plugin.getLogger().info("1.8 " + "DEBUG: hoe in hand");
        Block block = e.getClickedBlock();
        // plugin.getLogger().info("1.8 " + "DEBUG: block is " + block.getType() +
        // ":" + block.getData());
        // Check if coarse dirt
        if (block.getType() == Material.DIRT && block.getData() == (byte) 1) {
            // plugin.getLogger().info("1.8 " + "DEBUG: hitting coarse dirt!");
            e.setCancelled(true);
        }
    }
}
 
Example 13
Source File: IslandGuard1_9.java    From askyblock with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Handle blocks that need special treatment
 * Tilling of coarse dirt into dirt using off-hand (regular hand is in 1.8)
 * Usually prevented because it could lead to an endless supply of dirt with gravel
 * 
 * @param e - event
 */
@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.LOW, ignoreCancelled=true)
public void onPlayerInteract(final PlayerInteractEvent e) {
    if (!e.getAction().equals(Action.RIGHT_CLICK_BLOCK)) {
        return;
    }
    if (!IslandGuard.inWorld(e.getPlayer())) {
        return;
    }
    if (e.getPlayer().isOp()) {
        return;
    }
    // This permission bypasses protection
    if (VaultHelper.checkPerm(e.getPlayer(), Settings.PERMPREFIX + "mod.bypassprotect")
            || VaultHelper.checkPerm(e.getPlayer(), Settings.PERMPREFIX + "craft.dirt")) {
        return;
    }
    // Prevents tilling of coarse dirt into dirt
    ItemStack inHand = e.getPlayer().getInventory().getItemInOffHand();
    if (inHand.getType() == Material.WOOD_HOE || inHand.getType() == Material.IRON_HOE || inHand.getType() == Material.GOLD_HOE
            || inHand.getType() == Material.DIAMOND_HOE || inHand.getType() == Material.STONE_HOE) {
        // plugin.getLogger().info("1.8 " + "DEBUG: hoe in hand");
        Block block = e.getClickedBlock();
        // plugin.getLogger().info("1.8 " + "DEBUG: block is " + block.getType() +
        // ":" + block.getData());
        // Check if coarse dirt
        if (block.getType() == Material.DIRT && block.getData() == (byte) 1) {
            // plugin.getLogger().info("1.8 " + "DEBUG: hitting coarse dirt!");
            e.setCancelled(true);
        }
    }
}
 
Example 14
Source File: WallMatcher.java    From Modern-LWC with MIT License 5 votes vote down vote up
/**
 * Try and match a wall block
 *
 * @param block
 * @param matchingFace
 * @return
 */
private Block tryMatchBlock(Block block, BlockFace matchingFace) {
    byte direction = block.getData();
    BlockData blockData = block.getBlockData();

    // Blocks such as wall signs or banners
    if (PROTECTABLES_WALL.contains(block.getType()) && blockData instanceof Directional) {
        if (((Directional) block.getState().getBlockData()).getFacing() == matchingFace) {
            return block;
        }
    }

    // Levers, buttons
    else if (PROTECTABLES_LEVERS_ET_AL.contains(block.getType())) {
        byte EAST = 0x4;
        byte WEST = 0x3;
        byte SOUTH = 0x1;
        byte NORTH = 0x2;

        if (matchingFace == BlockFace.EAST && (direction & EAST) == EAST) {
            return block;
        } else if (matchingFace == BlockFace.WEST && (direction & WEST) == WEST) {
            return block;
        } else if (matchingFace == BlockFace.SOUTH && (direction & SOUTH) == SOUTH) {
            return block;
        } else if (matchingFace == BlockFace.NORTH && (direction & NORTH) == NORTH) {
            return block;
        }
    }

    return null;
}
 
Example 15
Source File: Core.java    From ProjectAres with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
@SuppressWarnings("deprecation")
public boolean isObjectiveMaterial(Block block) {
    return block.getType() == this.material.getItemType() && block.getData() == this.material.getData();
}
 
Example 16
Source File: BlockCollisionUtil.java    From QualityArmory with GNU General Public License v3.0 4 votes vote down vote up
public static boolean isSolid(Block b, Location l) {
	if(b.getType().name().equals("SNOW"))
		return false;
	if(b.getType().name().contains("SIGN"))
		return false;
	if (b.getType().name().endsWith("CARPET")) {
		return false;
	}
	if (b.getType() == Material.WATER) {
		if (QAMain.blockbullet_water)
			return true;
	}
	if (b.getType().name().contains("LEAVE")) {
		if (QAMain.blockbullet_leaves)
			return true;
	}
	if (b.getType().name().contains("SLAB") || b.getType().name().contains("STEP")) {
		if (!QAMain.blockbullet_halfslabs && ((l.getY() - l.getBlockY() > 0.5 && b.getData() == 0)
				|| (l.getY() - l.getBlockY() <= 0.5 && b.getData() == 1)))
			return false;
		return true;
	}
	if (b.getType().name().contains("BED_") || b.getType().name().contains("_BED")
			|| b.getType().name().contains("DAYLIGHT_DETECTOR")) {
		if (!QAMain.blockbullet_halfslabs && (l.getY() - l.getBlockY() > 0.5))
			return false;
		return true;
	}
	if (b.getType().name().contains("DOOR")) {
		if (QAMain.blockbullet_door)
			return true;
		return false;
	}
	if (b.getType().name().contains("GLASS")) {
		if (QAMain.blockbullet_glass)
			return true;
		return false;
	}

	if (b.getType().name().contains("STAIR")) {
		if (b.getData() < 4 && (l.getY() - l.getBlockY() < 0.5))
			return true;
		if (b.getData() >= 4 && (l.getY() - l.getBlockY() > 0.5))
			return true;
		switch (b.getData()) {
			case 0:
			case 4:
				return l.getX() - (0.5 + l.getBlockX()) > 0;
			case 1:
			case 5:
				return l.getX() - (0.5 + l.getBlockX()) < 0;
			case 2:
			case 6:
				return l.getZ() - (0.5 + l.getBlockZ()) > 0;
			case 3:
			case 7:
				return l.getZ() - (0.5 + l.getBlockZ()) < 0;

		}
	}

	if (b.getType().name().endsWith("FERN")) {
		return false;
	}
	if (b.getType().isOccluding()) {
		return true;
	}
	return false;
}
 
Example 17
Source File: RegionVisualizer.java    From HeavySpleef with GNU General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
public void run() {
	boolean finish = !player.isOnline();
	
	if (player.isOnline()) {
		Player bukkitPlayer = player.getBukkitPlayer();
		
		// Stores the current wool data
		byte data;
		
		if (currentRepetitions % 2 == 0) {
			data = LIME_WOOL_DATA;
		} else {
			data = RED_WOOL_DATA;
		}
		
		finish = currentRepetitions > REPETITIONS;
		Iterator<BlockVector> iterator = region.iterator();
		
		while (iterator.hasNext()) {
			BlockVector vec = iterator.next();
			
			int x = vec.getBlockX();
			int y = vec.getBlockY();
			int z = vec.getBlockZ();
			
			Location location = new Location(world, x, y, z);
			
			if (!finish) {
				bukkitPlayer.sendBlockChange(location, Material.WOOL, data);
			} else {
				Block block = world.getBlockAt(location);
				
				Material material = block.getType();
				data = block.getData();
				
				bukkitPlayer.sendBlockChange(location, material, data);
			}
		}
	}
	
	if (finish) {
		BukkitTask task = tasks.get(player);
		task.cancel();
		
		tasks.remove(player);
	}
	
	++currentRepetitions;
}
 
Example 18
Source File: LWC.java    From Modern-LWC with MIT License 4 votes vote down vote up
/**
 * Get the appropriate config value for the block (protections.block.node)
 *
 * @param block
 * @param node
 * @return
 */
@SuppressWarnings("deprecation")
public String resolveProtectionConfiguration(Block block, String node) {
    Material material = block.getType();
    if (material == null) {
        return null;
    }
    String cacheKey = block.getData() + "-" + material.toString() + "-" + node;
    if (protectionConfigurationCache.containsKey(cacheKey)) {
        return protectionConfigurationCache.get(cacheKey);
    }

    List<String> names = new ArrayList<>();

    String materialName = normalizeMaterialName(material);

    // add the name & the block id
    names.add(materialName);
    names.add(materialName + ":" + block.getData());

    // add both upper and lower material name
    names.add(material.toString());
    names.add(material.toString().toLowerCase());

    // Add the wildcards last so it can be overriden
    names.add("*");

    if (materialName.contains("_")) { // Prefix wildcarding for shulker boxes & gates
        names.add("*_" + materialName.substring(materialName.indexOf("_") + 1));
    }

    String value = configuration.getString("protections." + node);

    for (String name : names) {
        String temp = configuration.getString("protections.blocks." + name + "." + node);

        if (temp != null && !temp.isEmpty()) {
            value = temp;
        }
    }

    protectionConfigurationCache.put(cacheKey, value);
    return value;
}
 
Example 19
Source File: Core.java    From PGM with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
@SuppressWarnings("deprecation")
public boolean isObjectiveMaterial(Block block) {
  return block.getType() == this.material.getItemType()
      && block.getData() == this.material.getData();
}
 
Example 20
Source File: LWC.java    From Modern-LWC with MIT License 2 votes vote down vote up
/**
 * Compares two blocks if they are equal
 *
 * @param block
 * @param block2
 * @return
 */
@SuppressWarnings("deprecation")
public boolean blockEquals(Block block, Block block2) {
    return block.getType() == block2.getType() && block.getX() == block2.getX() && block.getY() == block2.getY()
            && block.getZ() == block2.getZ() && block.getData() == block2.getData();
}