diff --git a/src/API/BlockAPI.php b/src/API/BlockAPI.php index 123495e8..09fe763f 100644 --- a/src/API/BlockAPI.php +++ b/src/API/BlockAPI.php @@ -136,14 +136,14 @@ class BlockAPI{ if($down[0] === 64){ $data2 = $data; --$data2["y"]; - $this->server->event("player.block.break", $data2); + $this->server->trigger("player.block.break", $data2); } }else{ $up = $this->server->api->level->getBlock($data["x"], $data["y"] + 1, $data["z"]); if($up[0] === 64){ $data2 = $data; ++$data2["y"]; - $this->server->event("player.block.break", $data2); + $this->server->trigger("player.block.break", $data2); } } break; @@ -151,7 +151,7 @@ class BlockAPI{ if($drop !== false and $drop[0] !== 0 and $drop[2] > 0){ $this->drop($data["x"], $data["y"], $data["z"], $drop[0], $drop[1] & 0x0F, $drop[2] & 0xFF); } - $this->server->event("player.block.break", $data); + $this->server->trigger("player.block.break", $data); return false; } diff --git a/src/API/EntityAPI.php b/src/API/EntityAPI.php index 945fdc06..3422df26 100644 --- a/src/API/EntityAPI.php +++ b/src/API/EntityAPI.php @@ -62,6 +62,8 @@ class EntityAPI{ } } + + public function commandHandler($cmd, $params){ switch($cmd){ case "give": diff --git a/src/API/LevelAPI.php b/src/API/LevelAPI.php index 727f4ddf..a298e690 100644 --- a/src/API/LevelAPI.php +++ b/src/API/LevelAPI.php @@ -47,13 +47,13 @@ class LevelAPI{ $this->setBlock($data["x"], $data["y"], $data["z"], $data["block"], $data["meta"]); break; case "player.block.break": - $block = $this->getBlock($data["x"], $data["y"], $data["z"]); - console("[DEBUG] EID ".$data["eid"]." broke ".$block[0].":".$block[1]." at X ".$data["x"]." Y ".$data["y"]." Z ".$data["z"], true, true, 2); - - if($block[0] === 0){ - break; - } - $this->setBlock($data["x"], $data["y"], $data["z"], 0, 0); + $block = $this->getBlock($data["x"], $data["y"], $data["z"]); + console("[DEBUG] EID ".$data["eid"]." broke ".$block[0].":".$block[1]." at X ".$data["x"]." Y ".$data["y"]." Z ".$data["z"], true, true, 2); + + if($block[0] === 0){ + break; + } + $this->setBlock($data["x"], $data["y"], $data["z"], 0, 0); break; } } diff --git a/src/API/ServerAPI.php b/src/API/ServerAPI.php index e583ddb1..45b979fd 100644 --- a/src/API/ServerAPI.php +++ b/src/API/ServerAPI.php @@ -126,7 +126,7 @@ class ServerAPI extends stdClass{ //Yay! I can add anything to this class in run console("[NOTICE] A new STABLE version of PocketMine-MP has been released"); console("[NOTICE] Version \"".$info["name"]."\" [".substr($info["commit"]["sha"], 0, 10)."]"); console("[NOTICE] Download it at ".$info["zipball_url"]); - console("[NOTICE] This message will dissapear as soon as you update\""); + console("[NOTICE] This message will dissapear as soon as you update"); sleep(5); }else{ $this->setProperty("last-update", time()); diff --git a/src/classes/CustomPacketHandler.class.php b/src/classes/CustomPacketHandler.class.php index 6c880b15..bca58eeb 100644 --- a/src/classes/CustomPacketHandler.class.php +++ b/src/classes/CustomPacketHandler.class.php @@ -288,6 +288,15 @@ class CustomPacketHandler{ $this->raw .= Utils::writeByte($this->data["roll"]); } break; + case MC_TAKE_ITEM_ENTITY: + if($this->c === false){ + $this->data["target"] = Utils::readInt($this->get(4)); + $this->data["eid"] = Utils::readInt($this->get(4)); + }else{ + $this->raw .= Utils::writeInt($this->data["target"]); + $this->raw .= Utils::writeInt($this->data["eid"]); + } + break; case MC_MOVE_ENTITY: if($this->c === false){ $this->data["eid"] = Utils::readInt($this->get(4)); diff --git a/src/classes/Entity.class.php b/src/classes/Entity.class.php index 007b4710..228239cd 100644 --- a/src/classes/Entity.class.php +++ b/src/classes/Entity.class.php @@ -49,7 +49,7 @@ class Entity extends stdClass{ $this->closed = false; $this->name = ""; $this->server->query("INSERT OR REPLACE INTO entities (EID, type, class, health) VALUES (".$this->eid.", ".$this->type.", ".$this->class.", ".$this->health.");"); - $this->ev = $this->server->event("server.tick", array($this, "update")); + $this->server->schedule(20, array($this, "update"), array(), true); $this->metadata = array(); $this->x = isset($this->data["x"]) ? $this->data["x"]:0; $this->y = isset($this->data["y"]) ? $this->data["y"]:0; @@ -76,7 +76,17 @@ class Entity extends stdClass{ } public function update(){ - + if($this->class === ENTITY_ITEM){ + $player = $this->server->query("SELECT EID FROM entities WHERE class == ".ENTITY_PLAYER." AND abs(x - {$this->x}) <= 1.5 AND abs(y - {$this->y}) <= 1.5 AND abs(z - {$this->z}) <= 1.5 LIMIT 1;", true); + if($player !== true and $player !== false){ + if($this->server->api->dhandle("player.item.pick", array( + "eid" => $player["EID"], + "target" => $this->eid + )) !== false){ + $this->close(); + } + } + } } public function getDirection(){ @@ -152,7 +162,6 @@ class Entity extends stdClass{ if($this->closed === false){ $this->server->query("DELETE FROM entities WHERE EID = ".$this->eid.";"); $this->server->api->dhandle("entity.remove", $this->eid); - $this->server->deleteEvent($this->ev); $this->closed = true; } } diff --git a/src/classes/Player.class.php b/src/classes/Player.class.php index d6d63672..b68a5f98 100644 --- a/src/classes/Player.class.php +++ b/src/classes/Player.class.php @@ -113,6 +113,9 @@ class Player{ public function eventHandler($data, $event){ switch($event){ + case "player.item.pick": + $this->dataPacket(MC_TAKE_ITEM_ENTITY, $data); + break; case "player.equipment.change": if($data["eid"] === $this->eid){ break; @@ -140,7 +143,7 @@ class Player{ if($data === $this->eid){ break; } - $this->dataPacket(MC_ENTITY_REMOVE, array( + $this->dataPacket(MC_REMOVE_ENTITY, array( "eid" => $data, )); break; @@ -292,6 +295,7 @@ class Player{ $this->evid[] = $this->server->event("entity.move", array($this, "eventHandler")); $this->evid[] = $this->server->event("entity.animate", array($this, "eventHandler")); $this->evid[] = $this->server->event("player.equipment.change", array($this, "eventHandler")); + $this->evid[] = $this->server->event("player.item.pick", array($this, "eventHandler")); $this->evid[] = $this->server->event("world.block.change", array($this, "eventHandler")); console("[DEBUG] Player with EID ".$this->eid." \"".$this->username."\" spawned!", true, true, 2); diff --git a/src/classes/PocketMinecraftServer.class.php b/src/classes/PocketMinecraftServer.class.php index 48264d22..884c88fa 100644 --- a/src/classes/PocketMinecraftServer.class.php +++ b/src/classes/PocketMinecraftServer.class.php @@ -494,7 +494,7 @@ class PocketMinecraftServer extends stdClass{ $add = ' unset($this->schedule['.$this->scheduleCnt.']);'; } $this->schedule[$this->scheduleCnt] = array($callback, $data, $eventName); - $this->action(50000 * $ticks, '$schedule = $this->schedule['.$this->scheduleCnt.'];'.$add.' call_user_func($schedule[0], $schedule[1], $schedule[2]);', (bool) $repeat); + $this->action(50000 * $ticks, '$schedule = $this->schedule['.$this->scheduleCnt.'];'.$add.'if(!is_callable($schedule[0])){unset($this->schedule['.$this->scheduleCnt.']);return;} call_user_func($schedule[0], $schedule[1], $schedule[2]);', (bool) $repeat); return $this->scheduleCnt++; } diff --git a/src/pstruct/dataName.php b/src/pstruct/dataName.php index 9004d666..6d7f76d9 100644 --- a/src/pstruct/dataName.php +++ b/src/pstruct/dataName.php @@ -50,6 +50,7 @@ $dataName = array( MC_ADD_ENTITY => "AddEntity", MC_REMOVE_ENTITY => "RemoveEntity", MC_ADD_ITEM_ENTITY => "AddItemEntity", + MC_TAKE_ITEM_ENTITY => "TakeItemEntity", MC_MOVE_ENTITY => "MoveEntity", diff --git a/src/pstruct/protocol.php b/src/pstruct/protocol.php index cd03aaa2..ee8f770c 100644 --- a/src/pstruct/protocol.php +++ b/src/pstruct/protocol.php @@ -52,6 +52,7 @@ define("MC_ADD_PLAYER", 0x89); define("MC_ADD_ENTITY", 0x8c); define("MC_REMOVE_ENTITY", 0x8d); define("MC_ADD_ITEM_ENTITY", 0x8e); +define("MC_TAKE_ITEM_ENTITY", 0x8f); define("MC_MOVE_ENTITY", 0x90);