GenisysPro  for Minecraft PE/Windows 10 v1.1.x
Feature-rich server software for Minecraft PE and Windows 10 Edition
MetadataStore Class Reference

Public Member Functions

 setMetadata ($subject, $metadataKey, MetadataValue $newMetadataValue)
 
 getMetadata ($subject, $metadataKey)
 
 hasMetadata ($subject, $metadataKey)
 
 removeMetadata ($subject, $metadataKey, Plugin $owningPlugin)
 
 disambiguate (Metadatable $subject, $metadataKey)
 

Member Function Documentation

◆ disambiguate()

disambiguate ( Metadatable  $subject,
  $metadataKey 
)
abstract

Creates a unique name for the object receiving metadata by combining unique data from the subject with a metadataKey.

Parameters
Metadatable$subject
string$metadataKey
Returns
string
Exceptions

◆ getMetadata()

getMetadata (   $subject,
  $metadataKey 
)

Returns all metadata values attached to an object. If multiple have attached metadata, each will value will be included.

Parameters
mixed$subject
string$metadataKey
Returns
MetadataValue[]
Exceptions
71  {
72  $key = $this->disambiguate($subject, $metadataKey);
73  if(isset($this->metadataMap[$key])){
74  return $this->metadataMap[$key];
75  }else{
76  return [];
77  }
78  }

◆ hasMetadata()

hasMetadata (   $subject,
  $metadataKey 
)

Tests to see if a metadata attribute has been set on an object.

Parameters
mixed$subject
string$metadataKey
Returns
bool
Exceptions
90  {
91  return isset($this->metadataMap[$this->disambiguate($subject, $metadataKey)]);
92  }

◆ removeMetadata()

removeMetadata (   $subject,
  $metadataKey,
Plugin  $owningPlugin 
)

Removes a metadata item owned by a plugin from a subject.

Parameters
mixed$subject
string$metadataKey
Plugin$owningPlugin
Exceptions
103  {
104  $key = $this->disambiguate($subject, $metadataKey);
105  if(isset($this->metadataMap[$key])){
106  unset($this->metadataMap[$key][$owningPlugin]);
107  if($this->metadataMap[$key]->count() === 0){
108  unset($this->metadataMap[$key]);
109  }
110  }
111  }

◆ setMetadata()

setMetadata (   $subject,
  $metadataKey,
MetadataValue  $newMetadataValue 
)

Adds a metadata value to an object.

Parameters
mixed$subject
string$metadataKey
MetadataValue$newMetadataValue
Exceptions
44  {
45  $owningPlugin = $newMetadataValue->getOwningPlugin();
46  if($owningPlugin === null){
47  throw new PluginException("Plugin cannot be null");
48  }
49 
50  $key = $this->disambiguate($subject, $metadataKey);
51  if(!isset($this->metadataMap[$key])){
52  //$entry = new \WeakMap();
53  $this->metadataMap[$key] = new \SplObjectStorage();//$entry;
54  }else{
55  $entry = $this->metadataMap[$key];
56  }
57  $entry[$owningPlugin] = $newMetadataValue;
58  }

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