2019-09-14 03:05:16 +00:00
|
|
|
package com.sk89q.worldedit.entity;
|
|
|
|
|
2019-10-23 16:58:36 +00:00
|
|
|
import org.jetbrains.annotations.NotNull;
|
|
|
|
import org.jetbrains.annotations.Nullable;
|
|
|
|
|
2019-09-14 03:05:16 +00:00
|
|
|
public interface Metadatable {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set some session only metadata for the player
|
|
|
|
*
|
|
|
|
* @param key
|
|
|
|
* @param value
|
|
|
|
* @return previous value
|
|
|
|
*/
|
|
|
|
void setMeta(String key, Object value);
|
|
|
|
|
|
|
|
<T> T getAndSetMeta(String key, T value);
|
|
|
|
|
2019-10-23 16:58:36 +00:00
|
|
|
/**
|
|
|
|
* Checks if the object contains any metadata.
|
|
|
|
*
|
|
|
|
* @return {@code true} if there is metadata set for the object
|
|
|
|
*/
|
2019-09-14 03:05:16 +00:00
|
|
|
boolean hasMeta();
|
|
|
|
|
|
|
|
/**
|
2019-10-23 16:58:36 +00:00
|
|
|
* Gets the metadata value to which the specified key is mapped,
|
|
|
|
* or {@code null} if the key is not set.
|
2019-09-14 03:05:16 +00:00
|
|
|
*
|
2019-10-23 16:58:36 +00:00
|
|
|
* @param key the key of the metadata value to retrieve
|
|
|
|
* @return the value of the metadata or {@code null} if none exists
|
2019-09-14 03:05:16 +00:00
|
|
|
*/
|
|
|
|
<V> V getMeta(String key);
|
|
|
|
|
|
|
|
/**
|
2019-10-23 16:58:36 +00:00
|
|
|
* Gets the metadata value to which the specified key is mapped,
|
|
|
|
* or the default value if no metadata exists for the key.
|
2019-09-14 03:05:16 +00:00
|
|
|
*
|
2019-10-23 16:58:36 +00:00
|
|
|
* @param key the key of the metadata value to retrieve
|
|
|
|
* @param defaultValue the value to return if there is no metadata for the given key
|
|
|
|
* @return the metadata value for the key, if present; else the default value
|
2019-09-14 03:05:16 +00:00
|
|
|
*/
|
2019-10-23 16:58:36 +00:00
|
|
|
@NotNull
|
|
|
|
default <V> V getMeta(String key, @NotNull V defaultValue) {
|
2019-09-14 03:05:16 +00:00
|
|
|
V value = (V) getMeta(key);
|
2019-10-23 16:58:36 +00:00
|
|
|
return value == null ? defaultValue : value; }
|
2019-09-14 03:05:16 +00:00
|
|
|
|
|
|
|
/**
|
2019-10-23 16:58:36 +00:00
|
|
|
* Deletes the given metadata key from object. Do not delete metadata set by another plugin
|
|
|
|
* unless you know what you are doing.
|
2019-09-14 03:05:16 +00:00
|
|
|
*
|
2019-10-23 16:58:36 +00:00
|
|
|
* @param key the key identifying the metadata to remove.
|
|
|
|
* @return the previous value associated with they given key
|
2019-09-14 03:05:16 +00:00
|
|
|
*/
|
2019-10-23 16:58:36 +00:00
|
|
|
@Nullable
|
2019-09-14 03:05:16 +00:00
|
|
|
<V> V deleteMeta(String key);
|
|
|
|
|
|
|
|
final class METADATA_KEYS {
|
|
|
|
|
|
|
|
public static final String ANVIL_CLIPBOARD = "anvil-clipboard";
|
|
|
|
public static final String ROLLBACK = "rollback";
|
|
|
|
}
|
|
|
|
}
|