Esempio n. 1
0
 public function onUpdate($type)
 {
     if ($type === BLOCK_UPDATE_NORMAL) {
         if ($this->getSide(0)->isTransparent === true) {
             //Replace with common break method
             ServerAPI::request()->api->entity->drop($this, BlockAPI::getItem($this->id));
             $this->level->setBlock($this, new AirBlock(), false, false, true);
             return BLOCK_UPDATE_NORMAL;
         }
     } elseif ($type === BLOCK_UPDATE_RANDOM) {
         //Growth
         if (mt_rand(1, 7) === 1) {
             if (($this->meta & 0x8) === 0x8) {
                 TreeObject::growTree($this->level, $this, new Random(), $this->meta & 0x3);
             } else {
                 $this->meta |= 0x8;
                 $this->level->setBlock($this, $this, true, false, true);
                 return BLOCK_UPDATE_RANDOM;
             }
         } else {
             return BLOCK_UPDATE_RANDOM;
         }
     }
     return false;
 }
 public function commandH($cmd, $params, $issuer, $alias)
 {
     $output = "";
     switch ($cmd) {
         case "god":
             if (!($issuer == "Console") and $params[0] == "") {
                 $output .= "Usage: /{$cmd} <player>\n";
                 break;
             }
             if ($params[0] != "") {
                 $issuer = $this->api->player->get($params[0]);
                 if ($issuer === false) {
                     $output .= "player " . $params[0] . " NotFound";
                     break;
                 }
             }
             $this->api->entity->heal($issuer->eid, 32767);
             break;
         case "heal":
             if (!$issuer instanceof Player and $params[0] == "") {
                 $output .= "Usage: /{$cmd} <player>\n";
                 break;
             }
             if ($params[0] != "") {
                 $issuer = $this->api->player->get($params[0]);
                 if ($issuer === false) {
                     $output .= "player " . $params[0] . " NotFound";
                     break;
                 }
             }
             $this->api->entity->heal($issuer->eid, 20);
             break;
         case "tree":
             if (!$issuer instanceof Player) {
                 $output .= "Please run this command in-game.\n";
                 break;
             }
             switch (strtolower($params[0])) {
                 case "redwood":
                 case 1:
                     $meta = 1;
                     break;
                 case "brich":
                 case 2:
                     $meta = 2;
                     break;
                 case "tree":
                 case 0:
                     $meta = 0;
                     break;
                 case "r":
                     $meta = (int) rand(0, 2);
                     break;
                 default:
                     $output .= "Usage: /{$cmd} <tree|brich|redwood>\n";
                     break 2;
             }
             TreeObject::growTree($issuer->level, new Vector3((int) $issuer->entity->x, (int) $issuer->entity->y, (int) $issuer->entity->z), new Random(), $meta);
             $output .= "tree " . strtolower($params[0]) . " spawned";
             break;
         case "setMapSpawn":
             $this->api->level->getDefault()->setSpawn(new Vector3((int) $issuer->entity->x, (int) $issuer->entity->y, (int) $issuer->entity->z));
             break;
     }
     return $output;
 }
 public function defaultCommands($cmd, $params, $issuer, $alias)
 {
     $output = "";
     switch ($cmd) {
         case "?":
         case "help":
             $output = $this->forge["CommandAPI"]->getHelp($params, $issuer);
             break;
         case "say":
             $s = implode(" ", $params);
             if (trim($s) == "") {
                 $output .= "Usage: /say <message ...>\n";
                 break;
             }
             $gm = $this->getGM($issuer->__get("username"));
             $this->api->chat->broadcast(str_replace(array("{DISPLAYNAME}", "{MESSAGE}", "{WORLDNAME}", "{GROUP}"), array($gm["groups"]["info"]["prefix"] . $issuer->__get("username") . $gm["groups"]["info"]["suffix"], $s, $issuer->level->getName(), $gm["users"]["group"]), $this->config["chat-format"]));
             break;
         case "home":
             break;
         case "sethome":
             break;
         case "delhome":
             break;
         case "mute":
             break;
         case "back":
             break;
         case "tree":
             switch (strtolower($params[0])) {
                 case "redwood":
                     $meta = 1;
                     $output .= "Redwood tree spawned.";
                     break;
                 case "brich":
                     $meta = 2;
                     $output .= "Brich tree spawned.";
                     break;
                 case "tree":
                     $meta = 0;
                     $output .= "Tree spawned.";
                     break;
                 default:
                     $output .= "Usage: /tree <tree|brich|redwood>";
                     break 2;
             }
             TreeObject::growTree($issuer->level, new Vector3((int) $issuer->entity->x, (int) $issuer->entity->y, (int) $issuer->entity->z), $meta);
             break;
         case "clear":
         case "stop":
         case "status":
         case "invisible":
         case "difficulty":
         case "defaultgamemode":
             $output = $this->api->console->defaultCommands($cmd, $params, $issuer, false);
             break;
         case "seed":
         case "save-all":
         case "save-on":
         case "save-off":
             $output = $this->api->level->commandHandler($cmd, $params, $issuer, false);
             break;
         case "list":
         case "kill":
         case "gamemode":
         case "tp":
         case "spawnpoint":
         case "spawn":
         case "lag":
             $output = $this->api->player->commandHandler($cmd, $params, $issuer, false);
             break;
         case "time":
             $output = $this->api->time->commandHandler($cmd, $params, $issuer, false);
             break;
         case "banip":
         case "ban":
         case "kick":
         case "whitelist":
         case "op":
         case "deop":
         case "sudo":
             $output = $this->api->ban->commandHandler($cmd, $params, $issuer, false);
             break;
         case "give":
             $output = $this->api->block->commandHandler($cmd, $params, $issuer, false);
             break;
         case "tell":
         case "me":
             $output = $this->api->chat->commandHandler($cmd, $params, $issuer, false);
             break;
     }
     return $output;
 }
 /**
  * Returns the category tree for the given array of categories.
  */
 public function getCategoryTree($categories)
 {
     // create root object
     $root = new TreeObject(null);
     // get all paths to the root
     $allPaths = array();
     $vistedNodes = array();
     // used internally to prevent infinite cycles
     foreach ($categories as $cat) {
         $init_path = array();
         $this->getAllCategoryPaths($cat, $init_path, $allPaths, $vistedNodes);
     }
     // reverse paths
     $reversedPaths = array();
     foreach ($allPaths as $path) {
         $reversedPaths[] = array_reverse($path);
     }
     // build tree of TreeObjects
     foreach ($reversedPaths as $path) {
         $node = $root;
         foreach ($path as $c) {
             $node = $node->addChild($c);
         }
     }
     // sort first level
     $root->sortChildren();
     // serialize tree as XML
     $serializedXML = $root->serializeAsXML('conceptTreeElement');
     return $serializedXML == '' ? "<result isEmpty=\"true\" textToDisplay=\"" . wfMsg('smw_ob_no_categories') . "\"/>" : '<result>' . $serializedXML . '</result>';
 }
 public function populateLevel()
 {
     $this->random->setSeed($this->level->getSeed());
     if (isset($this->options["spawn"])) {
         $spawn = array(10, new SandstoneBlock());
         if (isset($this->options["spawn"]["radius"])) {
             $spawn[0] = intval($this->options["spawn"]["radius"]);
         }
         if (isset($this->options["spawn"]["block"])) {
             $spawn[1] = BlockAPI::fromString($this->options["spawn"]["block"])->getBlock();
             if (!$spawn[1] instanceof Block) {
                 $spawn[1] = new SandstoneBlock();
             }
         }
         $start = 128 - $spawn[0];
         $end = 128 + $spawn[0];
         for ($x = $start; $x <= $end; ++$x) {
             for ($z = $start; $z <= $end; ++$z) {
                 if (floor(sqrt(pow($x - 128, 2) + pow($z - 128, 2))) <= $spawn[0]) {
                     $this->level->setBlockRaw(new Vector3($x, $this->floorLevel - 1, $z), $spawn[1], null);
                 }
             }
         }
     }
     if (isset($this->options["decoration"])) {
         $treecount = 80;
         $grasscount = 120;
         if (isset($this->options["spawn"]["treecount"])) {
             $treecount = intval($this->options["spawn"]["treecount"]);
         }
         if (isset($this->options["spawn"]["grasscount"])) {
             $grasscount = intval($this->options["spawn"]["grasscount"]);
         }
         for ($t = 0; $t < $treecount; ++$t) {
             $centerX = $this->random->nextRange(0, 255);
             $centerZ = $this->random->nextRange(0, 255);
             $down = $this->level->level->getBlockID($centerX, $this->floorLevel - 1, $centerZ);
             if ($down === DIRT or $down === GRASS or $down === FARMLAND) {
                 TreeObject::growTree($this->level, new Vector3($centerX, $this->floorLevel, $centerZ), $this->random, $this->random->nextRange(0, 3));
             }
         }
         for ($t = 0; $t < $grasscount; ++$t) {
             $centerX = $this->random->nextRange(0, 255);
             $centerZ = $this->random->nextRange(0, 255);
             $down = $this->level->level->getBlockID($centerX, $this->floorLevel - 1, $centerZ);
             if ($down === GRASS) {
                 TallGrassObject::growGrass($this->level, new Vector3($centerX, $this->floorLevel - 1, $centerZ), $this->random, $this->random->nextRange(8, 40));
             }
         }
     }
 }
 private function find_parent_currencies(TreeObject $object = null)
 {
     //Traverses back the tree to the head seaching by parent
     //and correctly populates the rates array.
     if ($object->has_parents()) {
         $this->find_in_rates_array($object->get_parent()->get_value(), $object->get_value());
         $this->find_parent_currencies($object->get_parent());
     }
 }