Java Edition

attribute

エンティティの属性の読み取り・編集を行います

動作環境:

attribute コマンドは、エンティティの属性の読み取り・編集を行うために使用されます。

構文

test.mcfunction
attribute @s minecraft:generic.armor get
属性コマンドの詳細な説明を見る

attribute コマンドは、エンティティの属性を操作するためのコマンドです。 主に、エンティティの防具や攻撃力などの属性を取得・設定するために使用されます。

ノート

Useful information that users should know, even when skimming content.

ヒント

Helpful advice for doing things better or more easily.

重要

Key information users need to know to achieve their goal.

警告

Urgent info that needs immediate user attention to avoid problems.

危険

Advises about risks or negative outcomes of certain actions.

test.md
# heading
 
abcde.
 
```java
public class Test {
}
```
 
fghij.

使用例

基本的な使用方法

https://google.com にアクセスしてみましょう。次のコードがあります。

image

test.ts
import fs from "fs";
import path from "path";
import matter from "gray-matter";
 
const commandsDirectory = path.join(process.cwd(), "src/content/commands")aaaaaaaaaaaa;
 
export interface CommandMetadata {
  command?: string;
  description?: string;
  [key: string]: any;
}
 
export interface Command {
  slug: string;
  metadata: CommandMetadata;
  content: string;
}
 
export function getAllCommands(): Command[] {
  if (!fs.existsSync(commandsDirectory)) {
    return [];
  }
 
  const fileNames = fs.readdirSync(commandsDirectory);
  const commands = fileNames
    .filter((name) => name.endsWith(".mdx"))
    .map((name) => {
      const slug = name.replace(/\.mdx$/, "");
      const fullPath = path.join(commandsDirectory, name);
      const fileContents = fs.readFileSync(fullPath, "utf8");
      const { data, content } = matter(fileContents);
 
      return {
        slug,
        metadata: data as CommandMetadata,
        content,
      };
    });
 
  return commands;
}
 
export function getCommandBySlug(slug: string): Command | null {
  try {
    const fullPath = path.join(commandsDirectory, `${slug}.mdx`);
 
    if (!fs.existsSync(fullPath)) {
      return null;
    }
 
    const fileContents = fs.readFileSync(fullPath, "utf8");
    const { data, content } = matter(fileContents);
 
    return {
      slug,
      metadata: data as CommandMetadata,
      content,
    };
  } catch (error) {
    return null;
  }
}
 
export function getAllCommandSlugs(): string[] {
  if (!fs.existsSync(commandsDirectory)) {
    return [];
  }
 
  const fileNames = fs.readdirSync(commandsDirectory);
  return fileNames
    .filter((name) => name.endsWith(".mdx"))
    .map((name) => name.replace(/\.mdx$/, ""));
}

複数の属性を同時に設定

# ファイルを読み取り専用かつ隠しファイルに設定
attribute -r -h important.doc

注意事項

重要: システムファイルの属性を変更する際は十分注意してください。

  • 管理者権限が必要な場合があります
  • 一部のファイルシステムでは対応していない属性があります
  • バックアップを取ってから実行することを推奨します

関連コマンド

  • ls - ファイル一覧表示
  • chmod - ファイル権限変更
  • chown - ファイル所有者変更