Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
org.bukkit.metadata.MetadataValueAdapter Class Referenceabstract
Inheritance diagram for org.bukkit.metadata.MetadataValueAdapter:
org.bukkit.metadata.MetadataValue org.bukkit.metadata.LazyMetadataValue org.bukkit.metadata.FixedMetadataValue

Public Member Functions

Plugin getOwningPlugin ()
 
int asInt ()
 
float asFloat ()
 
double asDouble ()
 
long asLong ()
 
short asShort ()
 
byte asByte ()
 
boolean asBoolean ()
 
String asString ()
 

Protected Member Functions

 MetadataValueAdapter (Plugin owningPlugin)
 

Protected Attributes

final WeakReference< PluginowningPlugin
 

Detailed Description

Optional base class for facilitating MetadataValue implementations.

This provides all the conversion functions for MetadataValue so that writing an implementation of MetadataValue is as simple as implementing value() and invalidate().

Definition at line 16 of file MetadataValueAdapter.java.

Member Function Documentation

boolean org.bukkit.metadata.MetadataValueAdapter.asBoolean ( )

Attempts to convert the value of this metadata item into a boolean.

Returns
the value as a boolean.

Implements org.bukkit.metadata.MetadataValue.

Definition at line 52 of file MetadataValueAdapter.java.

References org.bukkit.metadata.MetadataValue.value().

52  {
53  Object value = value();
54  if (value instanceof Boolean) {
55  return (Boolean) value;
56  }
57 
58  if (value instanceof Number) {
59  return ((Number) value).intValue() != 0;
60  }
61 
62  if (value instanceof String) {
63  return Boolean.parseBoolean((String) value);
64  }
65 
66  return value != null;
67  }
byte org.bukkit.metadata.MetadataValueAdapter.asByte ( )

Attempts to convert the value of this metadata item into a byte.

Returns
the value as a byte.

Implements org.bukkit.metadata.MetadataValue.

Definition at line 48 of file MetadataValueAdapter.java.

References org.bukkit.metadata.MetadataValue.value().

48  {
49  return NumberConversions.toByte(value());
50  }
double org.bukkit.metadata.MetadataValueAdapter.asDouble ( )

Attempts to convert the value of this metadata item into a double.

Returns
the value as a double.

Implements org.bukkit.metadata.MetadataValue.

Definition at line 36 of file MetadataValueAdapter.java.

References org.bukkit.metadata.MetadataValue.value().

36  {
37  return NumberConversions.toDouble(value());
38  }
float org.bukkit.metadata.MetadataValueAdapter.asFloat ( )

Attempts to convert the value of this metadata item into a float.

Returns
the value as a float.

Implements org.bukkit.metadata.MetadataValue.

Definition at line 32 of file MetadataValueAdapter.java.

References org.bukkit.metadata.MetadataValue.value().

32  {
33  return NumberConversions.toFloat(value());
34  }
int org.bukkit.metadata.MetadataValueAdapter.asInt ( )

Attempts to convert the value of this metadata item into an int.

Returns
the value as an int.

Implements org.bukkit.metadata.MetadataValue.

Definition at line 28 of file MetadataValueAdapter.java.

References org.bukkit.metadata.MetadataValue.value().

28  {
29  return NumberConversions.toInt(value());
30  }
long org.bukkit.metadata.MetadataValueAdapter.asLong ( )

Attempts to convert the value of this metadata item into a long.

Returns
the value as a long.

Implements org.bukkit.metadata.MetadataValue.

Definition at line 40 of file MetadataValueAdapter.java.

References org.bukkit.metadata.MetadataValue.value().

40  {
41  return NumberConversions.toLong(value());
42  }
short org.bukkit.metadata.MetadataValueAdapter.asShort ( )

Attempts to convert the value of this metadata item into a short.

Returns
the value as a short.

Implements org.bukkit.metadata.MetadataValue.

Definition at line 44 of file MetadataValueAdapter.java.

References org.bukkit.metadata.MetadataValue.value().

44  {
45  return NumberConversions.toShort(value());
46  }
String org.bukkit.metadata.MetadataValueAdapter.asString ( )

Attempts to convert the value of this metadata item into a string.

Returns
the value as a string.

Implements org.bukkit.metadata.MetadataValue.

Definition at line 69 of file MetadataValueAdapter.java.

References org.bukkit.metadata.MetadataValue.value().

69  {
70  Object value = value();
71 
72  if (value == null) {
73  return "";
74  }
75  return value.toString();
76  }
Plugin org.bukkit.metadata.MetadataValueAdapter.getOwningPlugin ( )

Returns the Plugin that created this metadata item.

Returns
the plugin that owns this metadata value. This should never be null.

Implements org.bukkit.metadata.MetadataValue.

Definition at line 24 of file MetadataValueAdapter.java.

24  {
25  return owningPlugin.get();
26  }

The documentation for this class was generated from the following file: