Inventory: remove a bunch of crap from interface

some of these (notably the on* methods) are internal and shouldn't be exposed via interface (same crap as Plugin->onEnable() onDisable() etc) and the rest of the stuff is entirely unused.
This commit is contained in:
Dylan K. Taylor 2019-02-27 10:36:05 +00:00
parent 9b3230aa9c
commit 2d8480d801
13 changed files with 13 additions and 93 deletions

View File

@ -40,10 +40,6 @@ class AnvilInventory extends ContainerInventory{
return WindowTypes::ANVIL;
}
public function getName() : string{
return "Anvil";
}
public function getDefaultSize() : int{
return 2; //1 input, 1 material
}
@ -56,7 +52,7 @@ class AnvilInventory extends ContainerInventory{
return $this->holder;
}
public function onClose(Player $who) : void{
protected function onClose(Player $who) : void{
parent::onClose($who);
foreach($this->getContents() as $item){

View File

@ -50,10 +50,6 @@ class ArmorInventory extends BaseInventory{
return $this->holder;
}
public function getName() : string{
return "Armor";
}
public function getDefaultSize() : int{
return 4;
}

View File

@ -41,10 +41,6 @@ abstract class BaseInventory implements Inventory{
/** @var int */
protected $maxStackSize = Inventory::MAX_STACK;
/** @var string */
protected $name;
/** @var string */
protected $title;
/** @var \SplFixedArray|Item[] */
protected $slots = [];
/** @var Player[] */
@ -55,21 +51,13 @@ abstract class BaseInventory implements Inventory{
/**
* @param Item[] $items
* @param int $size
* @param string $title
*/
public function __construct(array $items = [], ?int $size = null, ?string $title = null){
public function __construct(array $items = [], ?int $size = null){
$this->slots = new \SplFixedArray($size ?? $this->getDefaultSize());
$this->title = $title ?? $this->getName();
$this->setContents($items, false);
}
abstract public function getName() : string;
public function getTitle() : string{
return $this->title;
}
/**
* Returns the size of the inventory.
* @return int
@ -401,21 +389,20 @@ abstract class BaseInventory implements Inventory{
$this->onClose($who);
}
public function onOpen(Player $who) : void{
protected function onOpen(Player $who) : void{
$this->viewers[spl_object_id($who)] = $who;
}
public function onClose(Player $who) : void{
protected function onClose(Player $who) : void{
unset($this->viewers[spl_object_id($who)]);
}
public function onSlotChange(int $index, Item $before, bool $send) : void{
protected function onSlotChange(int $index, Item $before, bool $send) : void{
if($send){
$this->sendSlot($index, $this->getViewers());
}
}
/**
* @param Player|Player[] $target
*/

View File

@ -46,10 +46,6 @@ class ChestInventory extends ContainerInventory{
return WindowTypes::CONTAINER;
}
public function getName() : string{
return "Chest";
}
public function getDefaultSize() : int{
return 27;
}
@ -70,7 +66,7 @@ class ChestInventory extends ContainerInventory{
return LevelSoundEventPacket::SOUND_CHEST_CLOSED;
}
public function onOpen(Player $who) : void{
protected function onOpen(Player $who) : void{
parent::onOpen($who);
if(count($this->getViewers()) === 1 and $this->getHolder()->isValid()){
@ -80,7 +76,7 @@ class ChestInventory extends ContainerInventory{
}
}
public function onClose(Player $who) : void{
protected function onClose(Player $who) : void{
if(count($this->getViewers()) === 1 and $this->getHolder()->isValid()){
//TODO: this crap really shouldn't be managed by the inventory
$this->broadcastBlockEventPacket(false);

View File

@ -35,10 +35,10 @@ abstract class ContainerInventory extends BaseInventory{
public function __construct(Vector3 $holder, array $items = [], ?int $size = null, ?string $title = null){
$this->holder = $holder;
parent::__construct($items, $size, $title);
parent::__construct($items, $size);
}
public function onOpen(Player $who) : void{
protected function onOpen(Player $who) : void{
parent::onOpen($who);
$pk = new ContainerOpenPacket();
$pk->windowId = $who->getWindowId($this);
@ -61,7 +61,7 @@ abstract class ContainerInventory extends BaseInventory{
$this->sendContents($who);
}
public function onClose(Player $who) : void{
protected function onClose(Player $who) : void{
$pk = new ContainerClosePacket();
$pk->windowId = $who->getWindowId($this);
$who->sendDataPacket($pk);

View File

@ -65,10 +65,6 @@ class CraftingGrid extends BaseInventory{
throw new \BadMethodCallException("Cannot change the size of a crafting grid");
}
public function getName() : string{
return "Crafting";
}
public function setItem(int $index, Item $item, bool $send = true) : bool{
if(parent::setItem($index, $item, $send)){
$this->seekRecipeBounds();

View File

@ -43,10 +43,6 @@ class DoubleChestInventory extends ChestInventory implements InventoryHolder{
BaseInventory::__construct($items);
}
public function getName() : string{
return "Double Chest";
}
public function getDefaultSize() : int{
return $this->left->getDefaultSize() + $this->right->getDefaultSize();
}
@ -113,7 +109,7 @@ class DoubleChestInventory extends ChestInventory implements InventoryHolder{
}
}
public function onOpen(Player $who) : void{
protected function onOpen(Player $who) : void{
parent::onOpen($who);
if(count($this->getViewers()) === 1 and $this->right->getHolder()->isValid()){
@ -121,7 +117,7 @@ class DoubleChestInventory extends ChestInventory implements InventoryHolder{
}
}
public function onClose(Player $who) : void{
protected function onClose(Player $who) : void{
if(count($this->getViewers()) === 1 and $this->right->getHolder()->isValid()){
$this->right->broadcastBlockEventPacket(false);
}

View File

@ -40,10 +40,6 @@ class EnchantInventory extends ContainerInventory{
return WindowTypes::ENCHANTMENT;
}
public function getName() : string{
return "Enchantment Table";
}
public function getDefaultSize() : int{
return 2; //1 input, 1 lapis
}
@ -56,7 +52,7 @@ class EnchantInventory extends ContainerInventory{
return $this->holder;
}
public function onClose(Player $who) : void{
protected function onClose(Player $who) : void{
parent::onClose($who);
foreach($this->getContents() as $item){

View File

@ -41,10 +41,6 @@ class EnderChestInventory extends ChestInventory{
return WindowTypes::CONTAINER;
}
public function getName() : string{
return "EnderChest";
}
public function getDefaultSize() : int{
return 27;
}

View File

@ -39,10 +39,6 @@ class FurnaceInventory extends ContainerInventory{
return WindowTypes::FURNACE;
}
public function getName() : string{
return "Furnace";
}
public function getDefaultSize() : int{
return 3; //1 input, 1 fuel, 1 output
}

View File

@ -47,16 +47,6 @@ interface Inventory{
*/
public function setMaxStackSize(int $size) : void;
/**
* @return string
*/
public function getName() : string;
/**
* @return string
*/
public function getTitle() : string;
/**
* @param int $index
*
@ -212,11 +202,6 @@ interface Inventory{
*/
public function getViewers() : array;
/**
* @param Player $who
*/
public function onOpen(Player $who) : void;
/**
* Tries to open the inventory to a player
*
@ -228,18 +213,6 @@ interface Inventory{
public function close(Player $who) : void;
/**
* @param Player $who
*/
public function onClose(Player $who) : void;
/**
* @param int $index
* @param Item $before
* @param bool $send
*/
public function onSlotChange(int $index, Item $before, bool $send) : void;
/**
* Returns whether the specified slot exists in the inventory.
*

View File

@ -34,10 +34,6 @@ class PlayerCursorInventory extends BaseInventory{
parent::__construct();
}
public function getName() : string{
return "Cursor";
}
public function getDefaultSize() : int{
return 1;
}

View File

@ -48,10 +48,6 @@ class PlayerInventory extends BaseInventory{
parent::__construct();
}
public function getName() : string{
return "Player";
}
public function getDefaultSize() : int{
return 36;
}