private static function parseRecipe($recipe)
 {
     $recipe = explode("=>", $recipe);
     $recipeItems = array();
     foreach (explode(",", $recipe[0]) as $item) {
         $item = explode("x", $item);
         $id = explode(":", $item[0]);
         $meta = array_pop($id);
         $id = $id[0];
         $it = BlockAPI::fromString($id);
         $recipeItems[$it->getID()] = array($it->getID(), $meta === "?" ? false : intval($meta) & 0xffff, intval($item[1]));
     }
     ksort($recipeItems);
     $item = explode("x", $recipe[1]);
     $id = explode(":", $item[0]);
     $meta = array_pop($id);
     $id = $id[0];
     $it = BlockAPI::fromString($id);
     $craftItem = array($it->getID(), intval($meta) & 0xffff, intval($item[1]));
     $recipeString = "";
     foreach ($recipeItems as $item) {
         $recipeString .= $item[0] . "x" . $item[2] . ",";
     }
     $recipeString = substr($recipeString, 0, -1) . "=>" . $craftItem[0] . "x" . $craftItem[2];
     return array($recipeItems, $craftItem, $recipeString);
 }
 public function initPlayer($player)
 {
     if ($player->gamemode === CREATIVE) {
         foreach ($player->inventory as $slot => $item) {
             if ($this->api->ban->isOp($player->__get("iusername"))) {
                 $player->setSlot($slot, BlockAPI::fromString($this->config["creative-item-op"][$slot]));
             } else {
                 $player->setSlot($slot, BlockAPI::fromString($this->config["creative-item"][$slot]));
             }
         }
     }
 }
 public function handler(&$data, $event)
 {
     switch ($event) {
         case "server.close":
             //file_put_contents("./plugins/Essentials/Protectdata.dat", serialize($this->save));
             break;
         case "plugin.forge.api":
             $data["CommandAPI"]->register("blundo", "<player>", array($this, "defaultCommands"));
             break;
         case "entity.explosion":
             if ($this->config["allow-explosion"] === false) {
                 return true;
             }
             break;
         case "tile.update":
             break;
         case "player.block.place":
             if ($data["item"]->getID() === CHEST) {
                 $this->protect["chest"][$data["player"]->__get("iusername")][] = new Protect($this->api, $data["player"]->__get("iusername"), new Position($data["block"]->x, $data["block"]->y, $data["block"]->z, $data["player"]->level));
                 break;
             }
             if ($this->api->ban->isOp($data["player"]->__get("iusername")) === false) {
                 $items = BlockAPI::fromString($this->config["blacklist"]["placement"], true);
                 foreach ($items as $item) {
                     if ($data["item"]->getID() === $item->getID() and $data["item"]->getMetadata() === $item->getMetadata()) {
                         return false;
                     }
                 }
             }
             break;
         case "player.block.break":
             if ($data["target"]->getID() === CHEST) {
                 $t = $this->get(new Position($data["target"]->x, $data["target"]->y, $data["target"]->z, $data["player"]->level));
                 if ($t !== false) {
                     if ($this->api->ban->isOp($data["player"]->__get("iusername"))) {
                         $t->__destruct();
                         break;
                     }
                     $break = $t->onBreak($output, $data["player"]);
                     if ($output != "") {
                         $data["player"]->sendChat($output);
                     }
                     return $break;
                 }
                 break;
             }
             if ($this->api->ban->isOp($data["player"]->__get("iusername")) === false) {
                 $items = BlockAPI::fromString($this->config["blacklist"]["break"], true);
                 foreach ($items as $item) {
                     if ($data["target"]->getID() === $item->getID() and $data["target"]->getMetadata() === $item->getMetadata()) {
                         return false;
                     }
                 }
             }
             break;
         case "player.block.activate":
             if ($data["target"]->getID() === CHEST) {
                 $output = "";
                 $t = $this->get(new Position($data["target"]->x, $data["target"]->y, $data["target"]->z, $data["player"]->level));
                 if ($data["item"]->getID() === STICK and ($this->api->ban->isOp($data["player"]->__get("iusername")) or $t->owner === $data["player"]->__get("iusername"))) {
                     $t->protectChange($output);
                     if ($output != "") {
                         $data["player"]->sendChat($output);
                     }
                     return false;
                 }
                 if ($t !== false) {
                     $open = $t->onOpen($output, $data["player"]);
                     if ($output != "") {
                         $data["player"]->sendChat($output);
                     }
                     return $open;
                 }
             } elseif ($data["target"]->getID() === WOOD_DOOR_BLOCK) {
                 return false;
             }
             break;
     }
 }
Example #4
0
 public function command($cmd, $params, $issuer, $alias)
 {
     $output = "";
     if ($alias !== false) {
         $cmd = $alias;
     }
     if ($cmd[0] === "/") {
         $cmd = substr($cmd, 1);
     }
     switch ($cmd) {
         case "paste":
             if (!$issuer instanceof Player) {
                 $output .= "Please run this command in-game.\n";
                 break;
             }
             $session =& $this->session($issuer);
             $this->W_paste($session["clipboard"], $issuer->entity, $output);
             break;
         case "copy":
             if (!$issuer instanceof Player) {
                 $output .= "Please run this command in-game.\n";
                 break;
             }
             $session =& $this->session($issuer);
             $count = $this->countBlocks($session["selection"], $startX, $startY, $startZ);
             if ($count > $session["block-limit"] and $session["block-limit"] > 0) {
                 $output .= "Block limit of " . $session["block-limit"] . " exceeded, tried to copy {$count} block(s).\n";
                 break;
             }
             $blocks = $this->W_copy($session["selection"], $output);
             if (count($blocks) > 0) {
                 $offset = array($startX - $issuer->entity->x - 0.5, $startY - $issuer->entity->y, $startZ - $issuer->entity->z - 0.5);
                 $session["clipboard"] = array($offset, $blocks);
             }
             break;
         case "cut":
             if (!$issuer instanceof Player) {
                 $output .= "Please run this command in-game.\n";
                 break;
             }
             $session =& $this->session($issuer);
             $count = $this->countBlocks($session["selection"], $startX, $startY, $startZ);
             if ($count > $session["block-limit"] and $session["block-limit"] > 0) {
                 $output .= "Block limit of " . $session["block-limit"] . " exceeded, tried to cut {$count} block(s).\n";
                 break;
             }
             $blocks = $this->W_cut($session["selection"], $output);
             if (count($blocks) > 0) {
                 $offset = array($startX - $issuer->entity->x - 0.5, $startY - $issuer->entity->y, $startZ - $issuer->entity->z - 0.5);
                 $session["clipboard"] = array($offset, $blocks);
             }
             break;
         case "toggleeditwand":
             if (!$issuer instanceof Player) {
                 $output .= "Please run this command in-game.\n";
                 break;
             }
             $session =& $this->session($issuer);
             $session["wand-usage"] = $session["wand-usage"] == true ? false : true;
             $output .= "Wand Item is now " . ($session["wand-usage"] === true ? "enabled" : "disabled") . ".\n";
             break;
         case "wand":
             if (!$issuer instanceof Player) {
                 $output .= "Please run this command in-game.\n";
                 break;
             }
             if ($issuer->hasItem($this->config->get("wand-item"))) {
                 $output .= "You already have the wand item.\n";
                 break;
             } elseif ($issuer->gamemode === CREATIVE) {
                 $output .= "You are on creative mode.\n";
             } else {
                 $this->api->entity->drop(new Position($issuer->entity->x - 0.5, $issuer->entity->y, $issuer->entity->z - 0.5, $issuer->entity->level), BlockAPI::getItem($this->config->get("wand-item")));
             }
             $output .= "Break a block to set the #1 position, place for the #1.\n";
             break;
         case "desel":
             if (!$issuer instanceof Player) {
                 $output .= "Please run this command in-game.\n";
                 break;
             }
             $session =& $this->session($issuer);
             $session["selection"] = array(false, false);
             $output = "Selection cleared.\n";
             break;
         case "limit":
             if (!isset($params[0]) or trim($params[0]) === "") {
                 $output .= "Usage: //limit <limit>\n";
                 break;
             }
             $limit = intval($params[0]);
             if ($limit < 0) {
                 $limit = -1;
             }
             if ($this->config->get("block-limit") > 0) {
                 $limit = $limit === -1 ? $this->config->get("block-limit") : min($this->config->get("block-limit"), $limit);
             }
             $this->session($issuer)["block-limit"] = $limit;
             $output .= "Block limit set to " . ($limit === -1 ? "infinite" : $limit) . " block(s).\n";
             break;
         case "pos1":
             if (!$issuer instanceof Player) {
                 $output .= "Please run this command in-game.\n";
                 break;
             }
             $this->setPosition1($this->session($issuer), new Position($issuer->entity->x - 0.5, $issuer->entity->y, $issuer->entity->z - 0.5, $issuer->entity->level), $output);
             break;
         case "pos2":
             if (!$issuer instanceof Player) {
                 $output .= "Please run this command in-game.\n";
                 break;
             }
             $this->setPosition2($this->session($issuer), new Position($issuer->entity->x - 0.5, $issuer->entity->y, $issuer->entity->z - 0.5, $issuer->entity->level), $output);
             break;
         case "hsphere":
             $filled = false;
         case "sphere":
             if (!$issuer instanceof Player) {
                 $output .= "Please run this command in-game.\n";
                 break;
             }
             if (!isset($filled)) {
                 $filled = true;
             }
             if (!isset($params[1]) or $params[1] == "") {
                 $output .= "Usage: //{$cmd} <block> <radius>.\n";
                 break;
             }
             $radius = abs(floatval($params[1]));
             $session =& $this->session($issuer);
             $items = BlockAPI::fromString($params[0], true);
             foreach ($items as $item) {
                 if ($item->getID() > 0xff) {
                     $output .= "Incorrect block.\n";
                     return $output;
                 }
             }
             $this->W_sphere(new Position($issuer->entity->x - 0.5, $issuer->entity->y, $issuer->entity->z - 0.5, $issuer->entity->level), $items, $radius, $radius, $radius, $filled, $output);
             break;
         case "set":
             if (!$issuer instanceof Player) {
                 $output .= "Please run this command in-game.\n";
                 break;
             }
             $session =& $this->session($issuer);
             $count = $this->countBlocks($session["selection"]);
             if ($count > $session["block-limit"] and $session["block-limit"] > 0) {
                 $output .= "Block limit of " . $session["block-limit"] . " exceeded, tried to change {$count} block(s).\n";
                 break;
             }
             $items = BlockAPI::fromString($params[0], true);
             foreach ($items as $item) {
                 if ($item->getID() > 0xff) {
                     $output .= "Incorrect block.\n";
                     return $output;
                 }
             }
             $this->W_set($session["selection"], $items, $output);
             break;
         case "replace":
             if (!$issuer instanceof Player) {
                 $output .= "Please run this command in-game.\n";
                 break;
             }
             $session =& $this->session($issuer);
             $count = $this->countBlocks($session["selection"]);
             if ($count > $session["block-limit"] and $session["block-limit"] > 0) {
                 $output .= "Block limit of " . $session["block-limit"] . " exceeded, tried to change {$count} block(s).\n";
                 break;
             }
             $item1 = BlockAPI::fromString($params[0]);
             if ($item1->getID() > 0xff) {
                 $output .= "Incorrect target block.\n";
                 break;
             }
             $items2 = BlockAPI::fromString($params[1], true);
             foreach ($items2 as $item) {
                 if ($item->getID() > 0xff) {
                     $output .= "Incorrect replacement block.\n";
                     return $output;
                 }
             }
             $this->W_replace($session["selection"], $item1, $items2, $output);
             break;
         default:
         case "help":
             $output .= "Commands: //cut, //copy, //paste, //sphere, //hsphere, //desel, //limit, //pos1, //pos2, //set, //replace, //help, //wand, /toggleeditwand\n";
             break;
     }
     return $output;
 }
 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));
             }
         }
     }
 }
Example #6
0
 public function commandHandler($cmd, $params, $issuer, $alias)
 {
     $output = "";
     switch ($cmd) {
         case "give":
             if (!isset($params[0]) or !isset($params[1])) {
                 $output .= "Usage: /give <player> <item[:damage]> [amount]\n";
                 break;
             }
             $player = $this->server->api->player->get($params[0]);
             $item = BlockAPI::fromString($params[1]);
             if (!isset($params[2])) {
                 $item->count = $item->getMaxStackSize();
             } else {
                 $item->count = (int) $params[2];
             }
             if ($player instanceof Player) {
                 if (($player->gamemode & 0x1) === 0x1) {
                     $output .= "Player is in creative mode.\n";
                     break;
                 }
                 if ($item->getID() == 0) {
                     $output .= "You cannot give an air block to a player.\n";
                     break;
                 }
                 $player->addItem($item->getID(), $item->getMetadata(), $item->count);
                 $output .= "Giving " . $item->count . " of " . $item->getName() . " (" . $item->getID() . ":" . $item->getMetadata() . ") to " . $player->username . "\n";
             } else {
                 $output .= "Unknown player.\n";
             }
             break;
     }
     return $output;
 }