org.bukkit.inventory.meta.BlockStateMeta Java Examples

The following examples show how to use org.bukkit.inventory.meta.BlockStateMeta. 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: SignEditListener.java    From NyaaUtils with MIT License 6 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockPlace(BlockPlaceEvent event) {
    Block block = event.getBlock();
    ItemStack item = event.getItemInHand();
    if (block != null && item != null &&
            isSign(item.getType()) &&
            isSign(block.getType())) {
        Player player = event.getPlayer();
        if ((player.isOp() && player.getGameMode().equals(GameMode.CREATIVE)) ||
                !item.hasItemMeta() || !(item.getItemMeta() instanceof BlockStateMeta) ||
                !player.hasPermission("nu.se.player")) {
            return;
        }
        SignContent c = SignContent.fromItemStack(item);
        if (!c.getContent().isEmpty()) {
            signContents.put(event.getPlayer().getUniqueId(), c);
        }
    }
}
 
Example #2
Source File: SignContent.java    From NyaaUtils with MIT License 5 votes vote down vote up
public static SignContent fromItemStack(ItemStack item) {
    SignContent content = new SignContent();
    if (item.hasItemMeta() && item.getItemMeta() instanceof BlockStateMeta) {
        BlockStateMeta blockStateMeta = (BlockStateMeta) item.getItemMeta();
        if (blockStateMeta.hasBlockState() && blockStateMeta.getBlockState() instanceof Sign) {
            Sign sign = ((Sign) blockStateMeta.getBlockState());
            for (int i = 0; i < 4; i++) {
                content.setLine(i, sign.getLine(i));
            }
        }
    }
    return content;
}
 
Example #3
Source File: SignContent.java    From NyaaUtils with MIT License 5 votes vote down vote up
public ItemStack toItemStack(ItemStack item) {
    if (item.getItemMeta() instanceof BlockStateMeta) {
        BlockStateMeta blockStateMeta = (BlockStateMeta) item.getItemMeta();
        if (blockStateMeta.getBlockState() instanceof Sign) {
            Sign sign = ((Sign) blockStateMeta.getBlockState());
            for (int i = 0; i < 4; i++) {
                sign.setLine(i, getLine(i));
            }
            blockStateMeta.setBlockState(sign);
        }
        item.setItemMeta(blockStateMeta);
    }
    return item;
}
 
Example #4
Source File: BannerUtils.java    From NovaGuilds with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Applies meta to a shield
 *
 * @param itemStack  shield item
 * @param bannerMeta banner meta
 * @return shield item
 */
public static ItemStack applyMeta(ItemStack itemStack, BannerMeta bannerMeta) {
	if(itemStack.getType() != Material.SHIELD && itemStack.getType() != CompatibilityUtils.Mat.WHITE_BANNER.get()) {
		throw new IllegalArgumentException("Passed ItemStack is not a shield nor a banner");
	}

	ItemMeta meta = itemStack.getItemMeta();
	BlockStateMeta blockStateMeta = (BlockStateMeta) meta;
	Banner banner = (Banner) blockStateMeta.getBlockState();
	applyMeta(banner, bannerMeta);
	banner.update();
	blockStateMeta.setBlockState(banner);
	itemStack.setItemMeta(blockStateMeta);
	return itemStack;
}
 
Example #5
Source File: Craftbukkit18R3.java    From factions-top with MIT License 4 votes vote down vote up
@Override
public EntityType getSpawnerType(ItemStack item) {
    BlockStateMeta bsm = (BlockStateMeta) item.getItemMeta();
    CreatureSpawner bs = (CreatureSpawner) bsm.getBlockState();
    return bs.getSpawnedType();
}