程序包 org.bukkit

类 NamespacedKey

java.lang.Object
org.bukkit.NamespacedKey

public final class NamespacedKey extends Object
代表基于字符串的 key, 由两部分组成: 命名空间名和键名.

命名空间名只能包含小写字母和数字, 点(.), 下划线(_) 和连字符(-).

键名只能包含小写字母和数字, 点(.), 下划线(_), 连字符(-) 和正斜杠(/).

  • 字段详细资料

    • MINECRAFT

      public static final String MINECRAFT
      代表所有内建 key 的命名空间.
      另请参阅:
    • BUKKIT

      public static final String BUKKIT
      代表所有由 Bukkit 生成的 key, 用于保障向后兼容性.
      另请参阅:
  • 构造器详细资料

    • NamespacedKey

      @Deprecated public NamespacedKey(@NotNull @NotNull String namespace, @NotNull @NotNull String key)
      已过时。
      插件应永不使用此构造器, 仅供内部使用!!
      在指定的命名空间内创建一个 key.

      原文:Create a key in a specific namespace.

      参数:
      namespace - 命名空间
      key - key
    • NamespacedKey

      public NamespacedKey(@NotNull @NotNull Plugin plugin, @NotNull @NotNull String key)
      在插件的命名空间内创建一个 key.

      命名空间名只能包含小写字母和数字, 点(.), 下划线(_) 和连字符(-).

      键名只能包含小写字母和数字, 点(.), 下划线(_), 连字符(-) 和正斜杠(/).

      原文:Create a key in the plugin's namespace.

      Namespaces may only contain lowercase alphanumeric characters, periods, underscores, and hyphens.

      Keys may only contain lowercase alphanumeric characters, periods, underscores, hyphens, and forward slashes.

      参数:
      plugin - 用于命名空间的插件对象 (命名空间名为插件名的小写表示)
      key - 要创建的 key
  • 方法详细资料

    • getNamespace

      @NotNull public @NotNull String getNamespace()
    • getKey

      @NotNull public @NotNull String getKey()
    • hashCode

      public int hashCode()
      覆盖:
      hashCode 在类中 Object
    • equals

      public boolean equals(Object obj)
      覆盖:
      equals 在类中 Object
    • toString

      public String toString()
      覆盖:
      toString 在类中 Object
    • randomKey

      @Deprecated @NotNull public static @NotNull NamespacedKey randomKey()
      已过时。
      插件应永不使用此方法, 仅供内部使用!!
      BUKKIT 命名空间创建一个随机的 key 并返回.

      原文:Return a new random key in the BUKKIT namespace.

      返回:
      新 key
    • minecraft

      @NotNull public static @NotNull NamespacedKey minecraft(@NotNull @NotNull String key)
      获取 Minecraft 命名空间内的一个 key.

      原文:Get a key in the Minecraft namespace.

      参数:
      key - 要使用的 key
      返回:
      Minecraft 命名空间内的新 key
    • fromString

      @Nullable public static @Nullable NamespacedKey fromString(@NotNull @NotNull String string, @Nullable @Nullable Plugin defaultNamespace)
      根据提供的字符串获取 NamespacedKey 对象, 若字符串未指定命名空间名, 将使用参数给定的默认命名空间. 这是一个根据用户输入获取 NamespacedKey 对象的实用方法. 请注意本方法大小写敏感, 且字符串内若存在任何大写字母将被视为无效输入 (建议先对字符串 toLowerCase). 关于输入内容的约定如下:
       fromString("foo", plugin) -> "plugin:foo"
       fromString("foo:bar", plugin) -> "foo:bar"
       fromString(":foo", null) -> "minecraft:foo"
       fromString("foo", null) -> "minecraft:foo"
       fromString("Foo", plugin) -> null
       fromString(":Foo", plugin) -> null
       fromString("foo:bar:bazz", plugin) -> null
       fromString("", plugin) -> null
       

      原文:Get a NamespacedKey from the supplied string with a default namespace if a namespace is not defined. This is a utility method meant to fetch a NamespacedKey from user input. Please note that casing does matter and any instance of uppercase characters will be considered invalid. The input contract is as follows:

       fromString("foo", plugin) -> "plugin:foo"
       fromString("foo:bar", plugin) -> "foo:bar"
       fromString(":foo", null) -> "minecraft:foo"
       fromString("foo", null) -> "minecraft:foo"
       fromString("Foo", plugin) -> null
       fromString(":Foo", plugin) -> null
       fromString("foo:bar:bazz", plugin) -> null
       fromString("", plugin) -> null
       
      参数:
      string - 需转换为 NamespacedKey 对象的字符串
      defaultNamespace - 未提供命名空间时使用的默认命名空间. 若为 null, 将使用 "minecraft" 命名空间 (minecraft(String))
      返回:
      创建的 NamespacedKey 对象. 如果 key 无效, 则为 null
      另请参阅:
    • fromString

      @Nullable public static @Nullable NamespacedKey fromString(@NotNull @NotNull String key)
      根据提供的字符串获取 NamespacedKey 对象. 默认命名空间为 "minecraft" (minecraft(String)).

      原文:Get a NamespacedKey from the supplied string. The default namespace will be Minecraft's (i.e. minecraft(String)).

      参数:
      key - 需转换为 NamespacedKey 对象的 key
      返回:
      创建的 NamespacedKey 对象. 如果 key 无效, 则为 null
      另请参阅: