mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-04 00:59:51 +00:00
Updated triggers to handle or dhandle API method
This commit is contained in:
parent
d7b1ae4b47
commit
b9eca491e8
@ -45,12 +45,13 @@ class BlockAPI{
|
|||||||
}
|
}
|
||||||
|
|
||||||
private function cancelAction($block){
|
private function cancelAction($block){
|
||||||
$this->server->trigger("world.block.change", array(
|
$this->server->api->dhandle("world.block.change", array(
|
||||||
"x" => $block[2][0],
|
"x" => $block[2][0],
|
||||||
"y" => $block[2][1],
|
"y" => $block[2][1],
|
||||||
"z" => $block[2][2],
|
"z" => $block[2][2],
|
||||||
"block" => $block[0],
|
"block" => $block[0],
|
||||||
"meta" => $block[1],
|
"meta" => $block[1],
|
||||||
|
"fake" => true,
|
||||||
));
|
));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -135,16 +136,14 @@ class BlockAPI{
|
|||||||
if($down[0] === 64){
|
if($down[0] === 64){
|
||||||
$data2 = $data;
|
$data2 = $data;
|
||||||
--$data2["y"];
|
--$data2["y"];
|
||||||
$this->server->trigger("player.block.break", $data2);
|
$this->server->handle("player.block.break", $data2);
|
||||||
$this->updateBlocksAround($data2["x"], $data2["y"], $data2["z"], BLOCK_UPDATE_NORMAL);
|
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
$up = $this->server->api->level->getBlock($data["x"], $data["y"] + 1, $data["z"]);
|
$up = $this->server->api->level->getBlock($data["x"], $data["y"] + 1, $data["z"]);
|
||||||
if($up[0] === 64){
|
if($up[0] === 64){
|
||||||
$data2 = $data;
|
$data2 = $data;
|
||||||
++$data2["y"];
|
++$data2["y"];
|
||||||
$this->server->trigger("player.block.break", $data2);
|
$this->server->handle("player.block.break", $data2);
|
||||||
$this->updateBlocksAround($data2["x"], $data2["y"], $data2["z"], BLOCK_UPDATE_NORMAL);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -152,8 +151,7 @@ class BlockAPI{
|
|||||||
if($drop !== false and $drop[0] !== 0 and $drop[2] > 0){
|
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->drop($data["x"], $data["y"], $data["z"], $drop[0], $drop[1] & 0x0F, $drop[2] & 0xFF);
|
||||||
}
|
}
|
||||||
$this->server->trigger("player.block.break", $data);
|
$this->server->handle("player.block.break", $data);
|
||||||
$this->updateBlocksAround($data["x"], $data["y"], $data["z"], BLOCK_UPDATE_NORMAL);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -203,8 +201,7 @@ class BlockAPI{
|
|||||||
if($data["block"] === 292){ //Hoe
|
if($data["block"] === 292){ //Hoe
|
||||||
$data["block"] = 60;
|
$data["block"] = 60;
|
||||||
$data["meta"] = 0;
|
$data["meta"] = 0;
|
||||||
$this->server->trigger("player.block.place", $data);
|
$this->server->handle("player.block.place", $data);
|
||||||
$this->updateBlocksAround($data["x"], $data["y"], $data["z"], BLOCK_UPDATE_NORMAL);
|
|
||||||
$cancelPlace = true;
|
$cancelPlace = true;
|
||||||
}
|
}
|
||||||
case 59:
|
case 59:
|
||||||
@ -212,8 +209,7 @@ class BlockAPI{
|
|||||||
if($data["block"] === 351 and $data["meta"] === 0x0F){ //Bonemeal
|
if($data["block"] === 351 and $data["meta"] === 0x0F){ //Bonemeal
|
||||||
$data["block"] = $target[0];
|
$data["block"] = $target[0];
|
||||||
$data["meta"] = 0x07;
|
$data["meta"] = 0x07;
|
||||||
$this->server->trigger("player.block.place", $data);
|
$this->server->handle("player.block.place", $data);
|
||||||
$this->updateBlocksAround($data["x"], $data["y"], $data["z"], BLOCK_UPDATE_NORMAL);
|
|
||||||
$cancelPlace = true;
|
$cancelPlace = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -230,14 +226,14 @@ class BlockAPI{
|
|||||||
"meta" => $down[1],
|
"meta" => $down[1],
|
||||||
"eid" => $data["eid"],
|
"eid" => $data["eid"],
|
||||||
);
|
);
|
||||||
$this->server->trigger("player.block.update", $data2);
|
if($this->server->handle("player.block.update", $data2) !== false){
|
||||||
$this->updateBlocksAround($data2["x"], $data2["y"], $data2["z"], BLOCK_UPDATE_NORMAL);
|
|
||||||
$this->updateBlocksAround($data["x"], $data["y"], $data["z"], BLOCK_UPDATE_NORMAL);
|
$this->updateBlocksAround($data["x"], $data["y"], $data["z"], BLOCK_UPDATE_NORMAL);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}else{
|
}else{
|
||||||
$data["block"] = $target[0];
|
$data["block"] = $target[0];
|
||||||
$data["meta"] = $target[1] ^ 0x04;
|
$data["meta"] = $target[1] ^ 0x04;
|
||||||
$this->server->trigger("player.block.update", $data);
|
if($this->server->handle("player.block.update", $data) !== false){
|
||||||
$up = $this->server->api->level->getBlock($data["x"], $data["y"] + 1, $data["z"]);
|
$up = $this->server->api->level->getBlock($data["x"], $data["y"] + 1, $data["z"]);
|
||||||
if($up[0] === 64){
|
if($up[0] === 64){
|
||||||
$data2 = $data;
|
$data2 = $data;
|
||||||
@ -247,14 +243,14 @@ class BlockAPI{
|
|||||||
}
|
}
|
||||||
$this->updateBlocksAround($data["x"], $data["y"], $data["z"], BLOCK_UPDATE_NORMAL);
|
$this->updateBlocksAround($data["x"], $data["y"], $data["z"], BLOCK_UPDATE_NORMAL);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
$cancelPlace = true;
|
$cancelPlace = true;
|
||||||
break;
|
break;
|
||||||
case 96: //Trapdoor
|
case 96: //Trapdoor
|
||||||
case 107: //Fence gates
|
case 107: //Fence gates
|
||||||
$data["block"] = $target[0];
|
$data["block"] = $target[0];
|
||||||
$data["meta"] = $target[1] ^ 0x04;
|
$data["meta"] = $target[1] ^ 0x04;
|
||||||
$this->server->trigger("player.block.update", $data);
|
$this->server->handle("player.block.update", $data);
|
||||||
$this->updateBlocksAround($data["x"], $data["y"], $data["z"], BLOCK_UPDATE_NORMAL);
|
|
||||||
$cancelPlace = true;
|
$cancelPlace = true;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -398,8 +394,7 @@ class BlockAPI{
|
|||||||
$data2["meta"] = 0x08;
|
$data2["meta"] = 0x08;
|
||||||
$data["meta"] = $direction & 0x03;
|
$data["meta"] = $direction & 0x03;
|
||||||
++$data2["y"];
|
++$data2["y"];
|
||||||
$this->server->trigger("player.block.place", $data2);
|
$this->server->handle("player.block.place", $data2);
|
||||||
$this->updateBlocksAround($data2["x"], $data2["y"], $data2["z"], BLOCK_UPDATE_NORMAL);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 54:
|
case 54:
|
||||||
@ -429,8 +424,7 @@ class BlockAPI{
|
|||||||
$data2["x"] = $next[2][0];
|
$data2["x"] = $next[2][0];
|
||||||
$data2["y"] = $next[2][1];
|
$data2["y"] = $next[2][1];
|
||||||
$data2["z"] = $next[2][2];
|
$data2["z"] = $next[2][2];
|
||||||
$this->server->trigger("player.block.place", $data2);
|
$this->server->handle("player.block.place", $data2);
|
||||||
$this->updateBlocksAround($data2["x"], $data2["y"], $data2["z"], BLOCK_UPDATE_NORMAL);
|
|
||||||
break;
|
break;
|
||||||
case 65: //Ladder
|
case 65: //Ladder
|
||||||
if(isset(Material::$transparent[$target[0]])){
|
if(isset(Material::$transparent[$target[0]])){
|
||||||
@ -466,9 +460,7 @@ class BlockAPI{
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
$this->server->trigger("player.block.place", $data);
|
$this->server->handle("player.block.place", $data);
|
||||||
$this->updateBlock($data["x"], $data["y"], $data["z"], BLOCK_UPDATE_NORMAL);
|
|
||||||
$this->updateBlocksAround($data["x"], $data["y"], $data["z"], BLOCK_UPDATE_NORMAL);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -249,7 +249,7 @@ class ConsoleAPI{
|
|||||||
console("[INFO] Issued server command: /$cmd ".implode(" ", $params));
|
console("[INFO] Issued server command: /$cmd ".implode(" ", $params));
|
||||||
if(isset($this->cmds[$cmd]) and is_callable($this->cmds[$cmd])){
|
if(isset($this->cmds[$cmd]) and is_callable($this->cmds[$cmd])){
|
||||||
call_user_func($this->cmds[$cmd], $cmd, $params);
|
call_user_func($this->cmds[$cmd], $cmd, $params);
|
||||||
}elseif($this->server->trigger("api.console.command", array("cmd" => $cmd, "params" => $params)) !== false){
|
}elseif($this->server->api->dhandle("api.console.command", array("cmd" => $cmd, "params" => $params)) !== false){
|
||||||
$this->defaultCommands($cmd, $params);
|
$this->defaultCommands($cmd, $params);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -88,13 +88,16 @@ class LevelAPI{
|
|||||||
public function setBlock($x, $y, $z, $block, $meta = 0){
|
public function setBlock($x, $y, $z, $block, $meta = 0){
|
||||||
$this->map->setBlock($x, $y, $z, $block, $meta);
|
$this->map->setBlock($x, $y, $z, $block, $meta);
|
||||||
$this->heightMap[$z][$x] = $this->map->getFloor($x, $z);
|
$this->heightMap[$z][$x] = $this->map->getFloor($x, $z);
|
||||||
$this->server->trigger("world.block.change", array(
|
if($this->server->api->dhandle("world.block.change", array(
|
||||||
"x" => $x,
|
"x" => $x,
|
||||||
"y" => $y,
|
"y" => $y,
|
||||||
"z" => $z,
|
"z" => $z,
|
||||||
"block" => $block,
|
"block" => $block,
|
||||||
"meta" => $meta,
|
"meta" => $meta,
|
||||||
));
|
)) !== false){
|
||||||
|
$this->server->api->block->updateBlock($x, $y, $z, BLOCK_UPDATE_NORMAL);
|
||||||
|
$this->server->api->block->updateBlocksAround($x, $y, $z, BLOCK_UPDATE_NORMAL);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getOrderedChunk($X, $Z, $columnsPerPacket = 2){
|
public function getOrderedChunk($X, $Z, $columnsPerPacket = 2){
|
||||||
|
@ -295,6 +295,10 @@ class ServerAPI extends stdClass{ //Yay! I can add anything to this class in run
|
|||||||
return $this->server->addHandler($e, $c, $p);
|
return $this->server->addHandler($e, $c, $p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function dhandle($e, $d){
|
||||||
|
return $this->server->handle($e, $d);
|
||||||
|
}
|
||||||
|
|
||||||
public function handle($e, &$d){
|
public function handle($e, &$d){
|
||||||
return $this->server->handle($e, $d);
|
return $this->server->handle($e, $d);
|
||||||
}
|
}
|
||||||
|
@ -151,7 +151,7 @@ class Entity extends stdClass{
|
|||||||
public function close(){
|
public function close(){
|
||||||
if($this->closed === false){
|
if($this->closed === false){
|
||||||
$this->server->query("DELETE FROM entities WHERE EID = ".$this->eid.";");
|
$this->server->query("DELETE FROM entities WHERE EID = ".$this->eid.";");
|
||||||
$this->server->trigger("entity.remove", $this->eid);
|
$this->server->api->dhandle("entity.remove", $this->eid);
|
||||||
$this->server->deleteEvent($this->ev);
|
$this->server->deleteEvent($this->ev);
|
||||||
$this->closed = true;
|
$this->closed = true;
|
||||||
}
|
}
|
||||||
@ -217,7 +217,7 @@ class Entity extends stdClass{
|
|||||||
public function setHealth($health, $cause = ""){
|
public function setHealth($health, $cause = ""){
|
||||||
$this->health = (int) $health;
|
$this->health = (int) $health;
|
||||||
$this->server->query("UPDATE entities SET health = ".$this->health." WHERE EID = ".$this->eid.";");
|
$this->server->query("UPDATE entities SET health = ".$this->health." WHERE EID = ".$this->eid.";");
|
||||||
$this->server->trigger("entity.health.change", array("eid" => $this->eid, "health" => $health, "cause" => $cause));
|
$this->server->api->dhandle("entity.health.change", array("eid" => $this->eid, "health" => $health, "cause" => $cause));
|
||||||
if($this->player !== false){
|
if($this->player !== false){
|
||||||
$this->player->dataPacket(MC_SET_HEALTH, array(
|
$this->player->dataPacket(MC_SET_HEALTH, array(
|
||||||
"health" => $this->health,
|
"health" => $this->health,
|
||||||
@ -226,7 +226,7 @@ class Entity extends stdClass{
|
|||||||
if($this->health <= 0 and $this->dead === false){
|
if($this->health <= 0 and $this->dead === false){
|
||||||
$this->dead = true;
|
$this->dead = true;
|
||||||
if($this->player !== false){
|
if($this->player !== false){
|
||||||
$this->server->handle("player.death", array("name" => $this->name, "cause" => $cause));
|
$this->server->api->dhandle("player.death", array("name" => $this->name, "cause" => $cause));
|
||||||
}
|
}
|
||||||
}elseif($this->health > 0){
|
}elseif($this->health > 0){
|
||||||
$this->dead = false;
|
$this->dead = false;
|
||||||
|
@ -105,7 +105,7 @@ class Player{
|
|||||||
|
|
||||||
$this->connected = false;
|
$this->connected = false;
|
||||||
if($msg === true){
|
if($msg === true){
|
||||||
$this->server->trigger("server.chat", $this->username." left the game");
|
$this->server->api->dhandle("server.chat", $this->username." left the game");
|
||||||
}
|
}
|
||||||
console("[INFO] Session with ".$this->ip.":".$this->port." Client ID ".$this->clientID." closed due to ".$reason);
|
console("[INFO] Session with ".$this->ip.":".$this->port." Client ID ".$this->clientID." closed due to ".$reason);
|
||||||
$this->server->api->player->remove($this->CID);
|
$this->server->api->player->remove($this->CID);
|
||||||
@ -303,7 +303,7 @@ class Player{
|
|||||||
case MC_MOVE_PLAYER:
|
case MC_MOVE_PLAYER:
|
||||||
if(is_object($this->entity)){
|
if(is_object($this->entity)){
|
||||||
$this->entity->setPosition($data["x"], $data["y"], $data["z"], $data["yaw"], $data["pitch"]);
|
$this->entity->setPosition($data["x"], $data["y"], $data["z"], $data["yaw"], $data["pitch"]);
|
||||||
$this->server->trigger("entity.move", $this->eid);
|
$this->server->api->dhandle("entity.move", $this->eid);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case MC_PLAYER_EQUIPMENT:
|
case MC_PLAYER_EQUIPMENT:
|
||||||
@ -354,7 +354,7 @@ class Player{
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case MC_ANIMATE:
|
case MC_ANIMATE:
|
||||||
$this->server->trigger("entity.animate", array("eid" => $this->eid, "action" => $data["action"]));
|
$this->server->api->dhandle("entity.animate", array("eid" => $this->eid, "action" => $data["action"]));
|
||||||
break;
|
break;
|
||||||
case MC_RESPAWN:
|
case MC_RESPAWN:
|
||||||
$this->entity->setHealth(20, "respawn");
|
$this->entity->setHealth(20, "respawn");
|
||||||
|
@ -88,8 +88,8 @@ class PocketMinecraftServer extends stdClass{
|
|||||||
$this->event("server.chat", array($this, "eventHandler"));
|
$this->event("server.chat", array($this, "eventHandler"));
|
||||||
$this->event("player.new", array($this, "eventHandler"));
|
$this->event("player.new", array($this, "eventHandler"));
|
||||||
|
|
||||||
$this->action(500000, '$this->time += (int) ($this->timePerSecond / 2);$this->trigger("server.time.change", $this->time);');
|
$this->action(500000, '$this->time += (int) ($this->timePerSecond / 2);$this->api->dhandle("server.time.change", $this->time);');
|
||||||
$this->action(5000000, 'if($this->difficulty < 2){$this->trigger("server.regeneration", 1);}');
|
$this->action(5000000, 'if($this->difficulty < 2){$this->api->dhandle("server.regeneration", 1);}');
|
||||||
$this->action(1000000 * 60, '$this->reloadConfig();');
|
$this->action(1000000 * 60, '$this->reloadConfig();');
|
||||||
$this->action(1000000 * 60 * 10, '$this->custom = array();');
|
$this->action(1000000 * 60 * 10, '$this->custom = array();');
|
||||||
if($this->api !== false){
|
if($this->api !== false){
|
||||||
@ -167,7 +167,7 @@ class PocketMinecraftServer extends stdClass{
|
|||||||
$message = "<".$owner."> ";
|
$message = "<".$owner."> ";
|
||||||
}
|
}
|
||||||
$message .= $text;
|
$message .= $text;
|
||||||
$this->trigger("server.chat", $message);
|
$this->handle("server.chat", $message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setType($type = "normal"){
|
public function setType($type = "normal"){
|
||||||
|
@ -37,7 +37,7 @@ class PineTreeObject extends TreeObject{
|
|||||||
public function canPlaceObject(LevelAPI $level, $x, $y, $z){
|
public function canPlaceObject(LevelAPI $level, $x, $y, $z){
|
||||||
$this->findRandomLeavesSize();
|
$this->findRandomLeavesSize();
|
||||||
$checkRadius = 0;
|
$checkRadius = 0;
|
||||||
for($yy = 0; $yy < $this->totalHeight + 2; ++$yy) {
|
for($yy = 0; $yy < ($this->totalHeight + 2); ++$yy) {
|
||||||
if($yy === $this->leavesSizeY) {
|
if($yy === $this->leavesSizeY) {
|
||||||
$checkRadius = $this->leavesAbsoluteMaxRadius;
|
$checkRadius = $this->leavesAbsoluteMaxRadius;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user