From f0393f9b934b1f0fc65e429683f8c3b1479c3d03 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Pueyo Date: Sat, 5 Jan 2013 11:34:08 +0100 Subject: [PATCH] /give command --- src/API/BlockAPI.php | 35 +++++++++++++++++++++++++++++++++++ src/API/EntityAPI.php | 10 ---------- 2 files changed, 35 insertions(+), 10 deletions(-) diff --git a/src/API/BlockAPI.php b/src/API/BlockAPI.php index 0544c4e40..629a3ccc7 100644 --- a/src/API/BlockAPI.php +++ b/src/API/BlockAPI.php @@ -42,6 +42,41 @@ class BlockAPI{ $this->server->addHandler("world.block.update", array($this, "updateBlockRemote"), 1); $this->server->addHandler("player.block.break", array($this, "blockBreak"), 1); $this->server->addHandler("player.block.action", array($this, "blockAction"), 1); + $this->server->api->console->register("give", "Give items to a player", array($this, "commandHandler")); + } + + public function commandHandler($cmd, $params){ + switch($cmd){ + case "give": + if(!isset($params[0]) or !isset($params[1])){ + console("[INFO] Usage: /give [amount] [damage]"); + break; + } + $username = $params[0]; + $b = explode(":", $params[1]); + if(!isset($b[1])){ + $meta = 0; + }else{ + $meta = ((int) $b[1]) & 0x0F; + } + $block = ((int) $b[0]) & 0xFF; + if(!isset($params[2])){ + $amount = 64; + }else{ + $amount = $params[2] & 0xFF; + } + if(isset($params[3])){ + $meta = $params[3] & 0x0F; + } + if(($player = $this->server->api->player->get($username)) !== false){ + $this->drop($player->entity->x, $player->entity->y, $player->entity->z, $block, $meta, $amount); + console("[INFO] Giving ".$amount." of ".$block.":".$meta." to ".$username); + }else{ + console("[INFO] Unknown player"); + } + + break; + } } private function cancelAction($block){ diff --git a/src/API/EntityAPI.php b/src/API/EntityAPI.php index 3422df269..46e30b07a 100644 --- a/src/API/EntityAPI.php +++ b/src/API/EntityAPI.php @@ -33,7 +33,6 @@ class EntityAPI{ public function init(){ $this->server->addHandler("player.death", array($this, "handle"), 1); - $this->server->api->console->register("give", "Give items to a player [DUMMY]", array($this, "commandHandler")); } public function handle($data, $event){ @@ -61,15 +60,6 @@ class EntityAPI{ break; } } - - - - public function commandHandler($cmd, $params){ - switch($cmd){ - case "give": - break; - } - } public function get($eid){ if(isset($this->server->entities[$eid])){