Huge commit (Block API, changed events)

Changed Session to Player
Block API
Block Data
This commit is contained in:
Shoghi Cervantes Pueyo
2012-12-24 00:44:13 +01:00
parent e47bacce74
commit b867ba559e
10 changed files with 311 additions and 102 deletions

112
classes/API/BlockAPI.php Normal file
View File

@ -0,0 +1,112 @@
<?php
/*
-
/ \
/ \
/ PocketMine \
/ MP \
|\ @shoghicp /|
|. \ / .|
| .. \ / .. |
| .. | .. |
| .. | .. |
\ | /
\ | /
\ | /
\ | /
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
*/
class BlockAPI{
private $server;
function __construct($server){
$this->server = $server;
}
public function init(){
$this->server->addHandler("world.block.update", array($this, "handle"));
$this->server->addHandler("player.block.action", array($this, "handle"));
}
public function handle($data, $event){
switch($event){
case "player.block.action":
$target = $this->server->api->level->getBlock($data["x"], $data["y"], $data["z"]);
$cancelPlace = false;
if(isset(Material::$activable[$target[0]])){
switch($target[0]){
case 2:
case 3:
case 6:
break;
default:
$cancelPlace = true;
break;
}
}
if($cancelPlace === true or $face < 0 or $face > 5){
return;
}
if(!isset(Material::$replaceable[$target[0]])){
switch($data["face"]){
case 0:
--$data["y"];
break;
case 1:
++$data["y"];
break;
case 2:
--$data["z"];
break;
case 3:
++$data["z"];
break;
case 4:
--$data["x"];
break;
case 5:
++$data["x"];
break;
}
}
$block = $this->server->api->level->getBlock($data["x"], $data["y"], $data["z"]);
if(!isset(Material::$replaceable[$block[0]])){
return;
}
if(isset(Material::$placeable[$data["block"]])){
$data["block"] = Material::$placeable[$data["block"]] === true ? $data["block"]:Material::$placeable[$data["block"]];
}else{
return;
}
$entity = $this->server->api->entity->get($this->eid);
switch($data["block"]){
case 53:
break;
}
$this->server->handle("player.block.place", $data);
$this->updateBlocksAround($data["x"], $data["x"], $data["z"]);
}
}
public function updateBlocksAround($x, $y, $z){
}
}

View File

@ -35,7 +35,7 @@ class ConsoleAPI{
}
public function init(){
$this->event = $this->server->event("onTick", array($this, "handle"));
$this->event = $this->server->event("server.tick", array($this, "handle"));
}
function __destroy(){
@ -236,7 +236,7 @@ class ConsoleAPI{
console("[INFO] Issued server command: /$cmd ".implode(" ", $params));
if(isset($this->help[$cmd]) and is_callable($this->help[$cmd][1])){
call_user_func($this->help[$cmd][1], $cmd, $params);
}elseif($this->server->trigger("onCommand", array("cmd" => $cmd, "params" => $params)) !== false){
}elseif($this->server->trigger("api.console.command", array("cmd" => $cmd, "params" => $params)) !== false){
$this->defaultCommands($cmd, $params);
}
}

View File

@ -36,18 +36,17 @@ class LevelAPI{
}
public function init(){
$this->server->addHandler("onBlockBreak", array($this, "handle"));
$this->server->addHandler("onBlockPlace", array($this, "handle"));
$this->server->addHandler("player.block.break", array($this, "handle"));
$this->server->addHandler("player.block.place", array($this, "handle"));
}
public function handle($data, $event){
switch($event){
case "onBlockPlace":
$block = $this->getBlock($data["x"], $data["y"], $data["z"]);
console("[DEBUG] EID ".$data["eid"]." placed ".$data["block"].":".$data["meta"]." into ".$block[0].":".$block[1]." at X ".$data["x"]." Y ".$data["y"]." Z ".$data["z"], true, true, 2);
case "player.block.place":
console("[DEBUG] EID ".$data["eid"]." placed ".$data["block"].":".$data["meta"]." at X ".$data["x"]." Y ".$data["y"]." Z ".$data["z"], true, true, 2);
$this->setBlock($data["x"], $data["y"], $data["z"], $data["block"], $data["meta"]);
break;
case "onBlockBreak":
case "player.block.break":
$block = $this->getBlock($data["x"], $data["y"], $data["z"]);
console("[DEBUG] EID ".$data["eid"]." broke block ".$block[0].":".$block[1]." at X ".$data["x"]." Y ".$data["y"]." Z ".$data["z"], true, true, 2);
@ -102,7 +101,7 @@ class LevelAPI{
if($this->check()){
$this->map->setBlock($x, $y, $z, $block, $meta);
}
$this->server->trigger("onBlockUpdate", array(
$this->server->trigger("world.block.change", array(
"x" => $x,
"y" => $y,
"z" => $z,

View File

@ -29,7 +29,7 @@ class PlayerAPI{
private $server;
function __construct($server){
$this->server = $server;
$this->server->event("onHealthRegeneration", array($this, "handle"));
$this->server->event("server.regeneration", array($this, "handle"));
}
public function init(){
@ -41,7 +41,7 @@ class PlayerAPI{
public function handle($data, $event){
switch($event){
case "onHealthRegeneration":
case "server.regeneration":
$result = $this->server->query("SELECT ip,port FROM players WHERE EID = (SELECT EID FROM entities WHERE health < 20);", true);
if($result !== true and $result !== false){
while(false !== ($player = $result->fetchArray())){