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: 
  4: use pocketmine\entity\Human;
  5: use pocketmine\level\Location;
  6: 
  7: use pocketmine\nbt\tag\ByteTag;
  8: use pocketmine\nbt\tag\Tag;
  9: use pocketmine\nbt\tag\CompoundTag;
 10: use pocketmine\nbt\tag\DoubleTag;
 11: use pocketmine\nbt\tag\EnumTag;
 12: use pocketmine\nbt\tag\FloatTag;
 13: use pocketmine\nbt\tag\StringTag;
 14: use pocketmine\nbt\tag\IntTag;
 15: 
 16: /**
 17:  * This class implements an NPC player
 18:  */
 19: class Npc extends Human {
 20:     /**
 21:      * Spawns an NPC in game
 22:      * @param str $name - diplay name for this mob
 23:      * @param Location $pos - where to place this Mob
 24:      * @param str $classname - class to create
 25:      */
 26:     static public function spawnNpc($name,Location $pos,$classname,$opts=null){
 27:         if ($opts == null) $opts = [];
 28:         if (!isset($opts["skin"])) {
 29:             $opts["skin"] =
 30:                 str_repeat("\xFF", 32*16*2) . str_repeat("\xFF", 32*16*2) .
 31:                 str_repeat("\xFF", 32*16*2) . str_repeat("\xFF", 32*16*2) .
 32:                 str_repeat("\x80", 32*16*2) . str_repeat("\x80", 32*16*2) .
 33:                 str_repeat("\x80", 32*16*2) . str_repeat("\x80", 32*16*2);
 34:         }
 35:         if (!isset($opts["slim"])) $opts["slim"] = false;
 36:         $ndat = [];
 37:         $ndat["Pos"] = new EnumTag("Pos", [
 38:             new DoubleTag("", $pos->x),
 39:             new DoubleTag("", $pos->y),
 40:             new DoubleTag("", $pos->z)]);
 41:         if (isset($opts["motion"])) {
 42:             $ndat["Motion"] = new EnumTag("Motion", [
 43:                 new DoubleTag("",$opts["motion"][0]),
 44:                 new DoubleTag("",$opts["motion"][1]),
 45:                 new DoubleTag("",$opts["motion"][2])]);
 46:             unset($opts["motion"]);
 47:         } else {
 48:             $ndat["Motion"] = new EnumTag("Motion", [
 49:                 new DoubleTag("",0),
 50:                 new DoubleTag("",0),
 51:                 new DoubleTag("",0)]);
 52:         }
 53:         if (isset($opts["rotation"])) {
 54:             $ndat["Rotation"] = new EnumTag("Rotation", [
 55:                 new FloatTag("",$opts["rotation"][0]),
 56:                 new FloatTag("",$opts["rotation"][1])]);
 57:             unset($opts["rotation"]);
 58:         } else {
 59:             $ndat["Rotation"] = new EnumTag("Rotation", [
 60:                 new FloatTag("",$pos->yaw),
 61:                 new FloatTag("",$pos->pitch)]);
 62:         }
 63:         $ndat["Skin"] = new CompoundTag("Skin", [
 64:             "Data" => new StringTag("Data", $opts["skin"]),
 65:             "Slim" => new ByteTag("Slim", $opts["slim"] ? 1 : 0)]);
 66:         unset($opts["skin"]);
 67:         unset($opts["slim"]);
 68: 
 69:         foreach ($opts as $k=>$v) {
 70:             if ($v instanceof Tag) {
 71:                 $ndat[$k] = $v;
 72:                 continue;
 73:             }
 74:             if (is_array($v) && count($v) == 2) {
 75:                 list($type,$value) = $v;
 76:                 $type = "pocketmine\\nbt\\tag\\".$type;
 77:                 $ndat[$k] = new $type($k,$value);
 78:                 continue;
 79:             }
 80:             switch (gettype($v)) {
 81:                 case "boolean":
 82:                     $ndat[$k] = new ByteTag($k,$v ? 1 : 0);
 83:                     break;
 84:                 case "integer":
 85:                     $ndat[$k] = new IntTag($k, $v);
 86:                     break;
 87:                 case "double":
 88:                     $ndat[$k] = new DoubleTag($k,$v);
 89:                     break;
 90:                 case "string":
 91:                     $ndat[$k] = new StringTag($k,$v);
 92:             }
 93:         }
 94:         $npc = new $classname($pos->getLevel()->getChunk($pos->getX()>>4,
 95:                                                                          $pos->getZ()>>4),
 96:                                      new CompoundTag("",$ndat));
 97:         $npc->setNameTag($name);
 98:         return $npc;
 99:     }
100: }
101: 
API documentation generated by ApiGen