You are viewing an older version of the site. Click here to view
the latest version of this page. (This may be a dead link, if so, try the root page of the docs
here.)
== get_metadata ==
object, key, [plugin] |- ! scope="row" | Throws | [[../objects/com.commandhelper.BadEntityException|com.commandhelper.BadEntityException]]
[[../objects/ms.lang.CastException|ms.lang.CastException]]
[[../objects/ms.lang.FormatException|ms.lang.FormatException]]
[[../objects/com.commandhelper.InvalidPluginException|com.commandhelper.InvalidPluginException]]
[[../objects/ms.lang.LengthException|ms.lang.LengthException]]
[[../objects/com.commandhelper.InvalidWorldException|com.commandhelper.InvalidWorldException]]
[[../objects/com.commandhelper.PlayerOfflineException|com.commandhelper.PlayerOfflineException]] |- ! scope="row" | Since | 3.3.1 |- ! scope="row" | Restricted |
Copy Code
The output might be:
Copy Code
The output might be:
Copy Code
The output might be:
Copy Code
The output might be:
Copy Code
The output might be:
Returns the metadata values attached to the given object. object can be a location array (it will designate a block), an entityID (it will designate an entity) or a string (it will designate a world). If only the key is given, the object is the current player. The function returns an associative array where the values are keyed by plugin which have registered the metadata with the given key, and the array values the registered metadata values. If the plugin argument is given (a string that represent the plugin name), the function simply returns the value of the metadata registered by the plugin with this key, or null if no metadata is found. --- The Bukkit metadata allow to attach information to entities, blocks and worlds, and allow plugins to exchange these information between them without requiring one to be dependant on each other. The metadata are persistent across server reloads, but not across server restarts. The metadata attached to a player are also persistent between logins.
=== Vital Info ===
{| style="width: 40%;" cellspacing="1" cellpadding="1" border="1" class="wikitable"
|-
! scope="col" width="20%" |
! scope="col" width="80%" |
|-
! scope="row" | Name
| get_metadata
|-
! scope="row" | Returns
| mixed
|-
! scope="row" | Usages
| [object], key object, key, [plugin] |- ! scope="row" | Throws | [[../objects/com.commandhelper.BadEntityException|com.commandhelper.BadEntityException]]
[[../objects/ms.lang.CastException|ms.lang.CastException]]
[[../objects/ms.lang.FormatException|ms.lang.FormatException]]
[[../objects/com.commandhelper.InvalidPluginException|com.commandhelper.InvalidPluginException]]
[[../objects/ms.lang.LengthException|ms.lang.LengthException]]
[[../objects/com.commandhelper.InvalidWorldException|com.commandhelper.InvalidWorldException]]
[[../objects/com.commandhelper.PlayerOfflineException|com.commandhelper.PlayerOfflineException]] |- ! scope="row" | Since | 3.3.1 |- ! scope="row" | Restricted |
Yes
|-
! scope="row" | Optimizations
| None
|}
=== Usages ===
get_metadata([object], key)
get_metadata(object, key, [plugin])=== Examples === ====Example 1==== Attaches the string 'example' at the key 'key' to the player running the function, and outputs all values attached at the same key. Given the following code:
set_metadata('key', 'example')
msg(get_metadata('rank'))

1 {{function|set_metadata}}('key', 'example')
2 {{function|msg}}({{function|get_metadata}}('rank'))
<would set the value in the metadata>====Example 2==== Attaches the name of the player running the function at the key 'aKey' to the block at the given location, and outputs all values attached to the same block and at the same key. Given the following code:
assign(@block, array('x': 100, 'y': 63, 'z': 0))
set_metadata(@block, 'aKey', player())
msg(get_metadata(@block, 'aKey'))

1 {{function|assign}}(@block, {{function|array}}('x': 100, 'y': 63, 'z': 0))
2 {{function|set_metadata}}(@block, 'aKey', {{function|player}}())
3 {{function|msg}}({{function|get_metadata}}(@block, 'aKey'))
<would set the value in the metadata>====Example 3==== Attaches the boolean value true at the key 'my.key' to the entity whose the id is 1001, and outputs the value attached to the same entity and at the same key byMethodScript. Given the following code:
assign(@entity, 1001)
set_metadata(@entity, 'my.key', true)
msg(get_metadata(@entity, 'my.key', 'MethodScript'))

1 {{function|assign}}(@entity, 1001)
2 {{function|set_metadata}}(@entity, 'my.key', {{keyword|true}})
3 {{function|msg}}({{function|get_metadata}}(@entity, 'my.key', 'MethodScript'))
<would set the value in the metadata>====Example 4==== Attaches an array at the key 'anotherKey' to the world named 'world', and outputs all values attached to the same world and at the same key. Given the following code:
set_metadata('world', 'anotherKey', array(1, 50, 3))
msg(get_metadata('world', 'anotherKey'))

1 {{function|set_metadata}}('world', 'anotherKey', {{function|array}}(1, 50, 3))
2 {{function|msg}}({{function|get_metadata}}('world', 'anotherKey'))
<would set the value in the metadata>====Example 5==== Attaches null at the key 'key' to the player named 'player', and outputs the value attached to the same player and at the same key byMethodScript. Given the following code:
assign(@peid, pinfo()[13])
set_metadata(@peid, 'key', null)
msg(get_metadata(@peid, 'key', 'MethodScript'))

1 {{function|assign}}(@peid, {{function|pinfo}}()[13])
2 {{function|set_metadata}}(@peid, 'key', {{keyword|null}})
3 {{function|msg}}({{function|get_metadata}}(@peid, 'key', 'MethodScript'))
<would set the value in the metadata>
Find a bug in this page? Edit this page yourself, then submit a pull request. (Note this page is automatically generated from the documentation in the source code.)