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: 
  5: /**
  6:  * ItemName database
  7:  */
  8: abstract class ItemName {
  9:     /** @var array $xnames extended names */
 10:     static protected $xnames = null;
 11:     /** @var str[] $items Nice names for items */
 12:     static protected $items = [];
 13:     /** @var str[] $usrnames Possibly localized names for items */
 14:     static protected $usrnames = [];
 15:     /**
 16:      * Initialize $usrnames
 17:      * @param str[] $names - names to load
 18:      */
 19:     static public function initUsrNames(array $names) {
 20:         self::$usrnames = $names;
 21:     }
 22:     /**
 23:      * Load the specified item names.
 24:      * Return number of items read, -1 in case of error.
 25:      * @param str $f - Filename to load
 26:      * @return int
 27:      */
 28:     public static function loadUsrNames($f) {
 29:         $tx = file($f, FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES);
 30:         $i = 0;
 31:         if ($tx === false) return -1;
 32:         foreach ($tx as $x) {
 33:             $x = trim($x);
 34:             if (substr($x,0,1) == "#" || substr($x,0,1) == ";") continue;
 35:             $x = preg_split('/\s*=\s*/',$x,2);
 36:             if (count($x) != 2) continue;
 37:             ++$i;
 38:             self::$usrnames[$x[0]] = $x[1];
 39:         }
 40:         return $i;
 41:     }
 42: 
 43:     /**
 44:      * Initialize extended names table
 45:      */
 46:     static protected function initXnames() {
 47:         self::$xnames = [
 48:             Item::DYE => [
 49:                 0 => "Ink Sac",
 50:                 1 => "Rose Red",
 51:                 2 => "Cactus Green",
 52:                 3 => "Cocoa Beans",
 53:                 4 => "Lapis Lazuli",
 54:                 5 => "Purple Dye",
 55:                 6 => "Cyan Dye",
 56:                 7 => "Light Gray Dye",
 57:                 8 => "Gray Dye",
 58:                 9 => "Pink Dye",
 59:                 10 => "Lime Dye",
 60:                 11 => "Dandelion Yellow",
 61:                 12 => "Light Blue Dye",
 62:                 13 => "Magenta Dye",
 63:                 14 => "Orange Dye",
 64:                 15 => "Bone Meal",
 65:                 "*" => "Dye",
 66:             ],
 67:             Item::SPAWN_EGG => [
 68:                 "*" => "Spawn Egg",
 69:                 32 => "Spawn Zombie",
 70:                 33 => "Spawn Creeper",
 71:                 34 => "Spawn Skeleton",
 72:                 35 => "Spawn Spider",
 73:                 36 => "Spawn Zombie Pigman",
 74:                 37 => "Spawn Slime",
 75:                 38 => "Spawn Enderman",
 76:                 39 => "Spawn Silverfish",
 77:                 40 => "Spawn Cave Spider",
 78:                 41 => "Spawn Ghast",
 79:                 42 => "Spawn Magma Cube",
 80:                 10 => "Spawn Chicken",
 81:                 11 => "Spawn Cow",
 82:                 12 => "Spawn Pig",
 83:                 13 => "Spawn Sheep",
 84:                 14 => "Spawn Wolf",
 85:                 16 => "Spawn Mooshroom",
 86:                 17 => "Spawn Squid",
 87:                 19 => "Spawn Bat",
 88:                 15 => "Spawn Villager",
 89:             ]
 90:         ];
 91:     }
 92: 
 93:     /**
 94:      * Given an pocketmine\item\Item object, it returns a friendly name
 95:      * for it.
 96:      *
 97:      * @param Item item
 98:      * @return str
 99:      */
100:     static public function str(Item $item) {
101:         $id = $item->getId();
102:         $meta = $item->getDamage();
103:         if (isset(self::$usrnames[$id.":".$meta])) return self::$usrnames[$id.":".$meta];
104:         if (isset(self::$usrnames[$id])) return self::$usrnames[$id];
105:         if (self::$xnames == null) self::initXnames();
106: 
107:         if (isset(self::$xnames[$id])) {
108:             if (isset(self::$xnames[$id][$meta])) {
109:                 return self::$xnames[$id][$meta];
110:             } elseif (isset(self::$xnames[$id]["*"])) {
111:                 return self::$xnames[$id]["*"];
112:             } else {
113:                 return self::$xnames[$id][0];
114:             }
115:         }
116:         $n = $item->getName();
117:         if ($n != "Unknown") return $n;
118:         if (count(self::$items) == 0) {
119:             $constants = array_keys((new \ReflectionClass("pocketmine\\item\\Item"))->getConstants());
120:             foreach ($constants as $constant) {
121:                 $cid = constant("pocketmine\\item\\Item::$constant");
122:                 $constant = str_replace("_", " ", $constant);
123:                 self::$items[$cid] = $constant;
124:             }
125:         }
126:         if (isset(self::$items[$id])) return self::$items[$id];
127:         return $n;
128:     }
129: }
130: 
API documentation generated by ApiGen