/
Inventory.php
219 lines (186 loc) · 4.24 KB
/
Inventory.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
/**
* Handles the creation of virtual inventories or mapped to an InventoryHolder
*/
namespace pocketmine\inventory;
use pocketmine\item\Item;
use pocketmine\Player;
interface Inventory{
const MAX_STACK = 64;
public function getSize();
public function getMaxStackSize();
/**
* @param int $size
*/
public function setMaxStackSize($size);
public function getName();
public function getTitle();
/**
* @param int $index
*
* @return Item
*/
public function getItem($index);
/**
* Puts an Item in a slot.
* If a plugin refuses the update or $index is invalid, it'll return false
* If a source Player is specified, it won't send a Inventory update to it
*
* @param int $index
* @param Item $item
*
* @return bool
*/
public function setItem($index, Item $item);
/**
* Stores the given Items in the inventory. This will try to fill
* existing stacks and empty slots as well as it can.
*
* Returns the Items that did not fit.
*
* @param Item ...$item
*
* @return Item[]
*/
public function addItem(...$slots);
/**
* Checks if a given Item can be added to the inventory
*
* @param Item $item
*
* @return bool
*/
public function canAddItem(Item $item);
/**
* Removes the given Item from the inventory.
* It will return the Items that couldn't be removed.
*
* @param Item ...$item
*
* @return Item[]
*/
public function removeItem(...$slots);
/**
* @return Item[]
*/
public function getContents();
/**
* @param Item[] $items
*/
public function setContents(array $items);
/**
* @param Player|Player[] $target
*/
public function sendContents($target);
/**
* @param int $index
* @param Player|Player[] $target
*/
public function sendSlot($index, $target);
/**
* Checks if the inventory contains any Item with the same material data.
* It will check id, amount, and metadata (if not null)
*
* @param Item $item
*
* @return bool
*/
public function contains(Item $item);
/**
* Will return all the Items that has the same id and metadata (if not null).
* Won't check amount
*
* @param Item $item
*
* @return Item[]
*/
public function all(Item $item);
/**
* Will return the first slot has the same id and metadata (if not null) as the Item.
* -1 if not found, will check amount
*
* @param Item $item
*
* @return int
*/
public function first(Item $item);
/**
* Returns the first empty slot, or -1 if not found
*
* @return int
*/
public function firstEmpty();
/**
* Will remove all the Items that has the same id and metadata (if not null)
*
* @param Item $item
*/
public function remove(Item $item);
/**
* Will clear a specific slot
*
* @param int $index
*
* @return bool
*/
public function clear($index);
/**
* Clears all the slots
*/
public function clearAll();
/**
* Gets all the Players viewing the inventory
* Players will view their inventory at all times, even when not open.
*
* @return Player[]
*/
public function getViewers();
/**
* @return InventoryType
*/
public function getType();
/**
* @return InventoryHolder
*/
public function getHolder();
/**
* @param Player $who
*/
public function onOpen(Player $who);
/**
* Tries to open the inventory to a player
*
* @param Player $who
*
* @return bool
*/
public function open(Player $who);
public function close(Player $who);
/**
* @param Player $who
*/
public function onClose(Player $who);
/**
* @param int $index
* @param Item $before
*/
public function onSlotChange($index, $before);
}