PocketMine-MP  1.4 - API 1.10.0
 All Classes Namespaces Functions Variables Pages
BlockMetadataStore.php
1 <?php
2 
3 /*
4  *
5  * ____ _ _ __ __ _ __ __ ____
6  * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
7  * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
8  * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
9  * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
10  *
11  * This program is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License as published by
13  * the Free Software Foundation, either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * @author PocketMine Team
17  * @link http://www.pocketmine.net/
18  *
19  *
20 */
21 
22 namespace pocketmine\metadata;
23 
24 use pocketmine\Block\Block;
27 
30  private $owningLevel;
31 
32  public function __construct(Level $owningLevel){
33  $this->owningLevel = $owningLevel;
34  }
35 
36  public function disambiguate(Metadatable $block, $metadataKey){
37  if(!($block instanceof Block)){
38  throw new \InvalidArgumentException("Argument must be a Block instance");
39  }
40 
41  return $block->x . ":" . $block->y . ":" . $block->z . ":" . $metadataKey;
42  }
43 
44  public function getMetadata($block, $metadataKey){
45  if($block instanceof Block){
46  throw new \InvalidArgumentException("Object must be a Block");
47  }
48  if($block->getLevel() === $this->owningLevel){
49  return parent::getMetadata($block, $metadataKey);
50  }else{
51  throw new \InvalidStateException("Block does not belong to world " . $this->owningLevel->getName());
52  }
53  }
54 
55  public function hasMetadata($block, $metadataKey){
56  if($block instanceof Block){
57  throw new \InvalidArgumentException("Object must be a Block");
58  }
59  if($block->getLevel() === $this->owningLevel){
60  return parent::hasMetadata($block, $metadataKey);
61  }else{
62  throw new \InvalidStateException("Block does not belong to world " . $this->owningLevel->getName());
63  }
64  }
65 
66  public function removeMetadata($block, $metadataKey, Plugin $owningPlugin){
67  if($block instanceof Block){
68  throw new \InvalidArgumentException("Object must be a Block");
69  }
70  if($block->getLevel() === $this->owningLevel){
71  parent::hasMetadata($block, $metadataKey, $owningPlugin);
72  }else{
73  throw new \InvalidStateException("Block does not belong to world " . $this->owningLevel->getName());
74  }
75  }
76 
77  public function setMetadata($block, $metadataKey, MetadataValue $newMetadatavalue){
78  if($block instanceof Block){
79  throw new \InvalidArgumentException("Object must be a Block");
80  }
81  if($block->getLevel() === $this->owningLevel){
82  parent::setMetadata($block, $metadataKey, $newMetadatavalue);
83  }else{
84  throw new \InvalidStateException("Block does not belong to world " . $this->owningLevel->getName());
85  }
86  }
87 }