Overview

Namespaces

  • aliuly
    • common
      • selectors
    • loader
  • xPaw

Classes

  • aliuly\common\ArmorItems
  • aliuly\common\BasicCli
  • aliuly\common\BasicHelp
  • aliuly\common\BasicPlugin
  • aliuly\common\ChatSession
  • aliuly\common\Cmd
  • aliuly\common\CmdSelector
  • aliuly\common\ExpandVars
  • aliuly\common\FastTransfer
  • aliuly\common\FileUtils
  • aliuly\common\FreezeSession
  • aliuly\common\GetMotd
  • aliuly\common\GetMotdAsyncTask
  • aliuly\common\InvisibleSession
  • aliuly\common\InvUtils
  • aliuly\common\ItemName
  • aliuly\common\mc
  • aliuly\common\mc2
  • aliuly\common\MoneyAPI
  • aliuly\common\MPMU
  • aliuly\common\Npc
  • aliuly\common\PermUtils
  • aliuly\common\PluginAsyncTask
  • aliuly\common\PluginCallbackTask
  • aliuly\common\PMScript
  • aliuly\common\QueryAsyncTask
  • aliuly\common\Rcon
  • aliuly\common\RconTask
  • aliuly\common\selectors\All
  • aliuly\common\selectors\AllEntity
  • aliuly\common\selectors\BaseSelector
  • aliuly\common\selectors\Random
  • aliuly\common\Session
  • aliuly\common\ShieldSession
  • aliuly\common\ShoppingCart
  • aliuly\common\SignUtils
  • aliuly\common\SkinUtils
  • aliuly\common\SpySession
  • aliuly\common\SubCommandMap
  • aliuly\common\TPUtils
  • aliuly\loader\Main
  • xPaw\MinecraftQuery

Exceptions

  • xPaw\MinecraftQueryException
  • Overview
  • Namespace
  • Class
 1: <?php
 2: namespace aliuly\common;
 3: use pocketmine\item\Item;
 4: use pocketmine\Player;
 5: 
 6: /**
 7:  * Inventory related utilities
 8:  */
 9: abstract class InvUtils {
10:     /**
11:      * Clear players inventory
12:      * @param Player $target
13:      */
14:     static public function clearInventory(Player $target) {
15:         if ($target->isCreative() || $target->isSpectator()) return;
16:         $target->getInventory()->clearAll();
17:     }
18:     /**
19:      * Clear hotbar
20:      * @param Player $target
21:      */
22:     static public function clearHotBar(Player $target) {
23:         $inv = $target->getInventory();
24:         for ($i=0;$i < $inv->getHotbarSize(); $i++) {
25:             $inv->setHotbarSlotIndex($i,-1);
26:         }
27:         // Make sure inventory is updated...
28:         $inv->sendContents($target);
29:     }
30:     /**
31:      * Remove item from inventory....
32:      * @param Player $target
33:      * @param Item $item
34:      * @param int|null $count
35:      */
36:     static public function rmInvItem(Player $target, Item $item, $count = null) {
37:         $k = 0;
38:         foreach ($target->getInventory()->getContents() as $slot => &$inv) {
39:             if ($inv->getId() != $item->getId()) continue;
40:             if ($count !== null) {
41:                 if ($inv->getCount() > $count) {
42:                     $k += $count;
43:                     $inv->setCount($inv->getCount()-$count);
44:                     $target->getInventory()->setItem($slot,clone $inv);
45:                     break;
46:                 }
47:                 $count -= $inv->getCount();
48:             }
49:             $k += $inv->getCount();
50:             $target->getInventory()->clear($slot);
51:             if ($count === 0) break;
52:         }
53:         $target->getInventory()->sendContents($target);
54:         return $k;
55:     }
56:     /**
57:      * Count amount of items
58:      * @param Player $target
59:      * @param Item $item
60:      * @return int
61:      */
62:     static public function countInvItem(Player $target,Item $item) {
63:         $k = 0;
64:         foreach ($target->getInventory()->getContents() as $slot => &$inv) {
65:             if ($inv->getId() == $item->getId()) $k += $inv->getCount();
66:         }
67:         return $k;
68:     }
69: 
70: }
71: 
API documentation generated by ApiGen