mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-30 23:29:54 +00:00
Added __toString() to Player, Block and Item classes & added protocol order enforcement after login
This commit is contained in:
parent
4d05d7da0d
commit
e7d56a837f
@ -549,6 +549,9 @@ class Player{
|
|||||||
));
|
));
|
||||||
break;
|
break;
|
||||||
case MC_READY:
|
case MC_READY:
|
||||||
|
if($this->loggedIn === false){
|
||||||
|
break;
|
||||||
|
}
|
||||||
switch($data["status"]){
|
switch($data["status"]){
|
||||||
case 1: //Spawn!!
|
case 1: //Spawn!!
|
||||||
if($this->spawned !== false){
|
if($this->spawned !== false){
|
||||||
@ -623,12 +626,18 @@ class Player{
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case MC_MOVE_PLAYER:
|
case MC_MOVE_PLAYER:
|
||||||
|
if($this->loggedIn === false){
|
||||||
|
break;
|
||||||
|
}
|
||||||
if($this->entity instanceof Entity){
|
if($this->entity instanceof 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->api->dhandle("player.move", $this->entity);
|
$this->server->api->dhandle("player.move", $this->entity);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case MC_PLAYER_EQUIPMENT:
|
case MC_PLAYER_EQUIPMENT:
|
||||||
|
if($this->loggedIn === false){
|
||||||
|
break;
|
||||||
|
}
|
||||||
$data["eid"] = $this->eid;
|
$data["eid"] = $this->eid;
|
||||||
if($this->server->handle("player.equipment.change", $data) !== false){
|
if($this->server->handle("player.equipment.change", $data) !== false){
|
||||||
$this->equipment = BlockAPI::getItem($data["block"], $data["meta"]);
|
$this->equipment = BlockAPI::getItem($data["block"], $data["meta"]);
|
||||||
@ -636,8 +645,14 @@ class Player{
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case MC_REQUEST_CHUNK:
|
case MC_REQUEST_CHUNK:
|
||||||
|
if($this->loggedIn === false){
|
||||||
|
break;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case MC_USE_ITEM:
|
case MC_USE_ITEM:
|
||||||
|
if($this->loggedIn === false){
|
||||||
|
break;
|
||||||
|
}
|
||||||
$data["eid"] = $this->eid;
|
$data["eid"] = $this->eid;
|
||||||
if(Utils::distance($this->entity->position, $data) > 10){
|
if(Utils::distance($this->entity->position, $data) > 10){
|
||||||
break;
|
break;
|
||||||
@ -648,16 +663,25 @@ class Player{
|
|||||||
$this->server->api->block->playerBlockAction($this, new Vector3($data["x"], $data["y"], $data["z"]), $data["face"], $data["fx"], $data["fy"], $data["fz"]);
|
$this->server->api->block->playerBlockAction($this, new Vector3($data["x"], $data["y"], $data["z"]), $data["face"], $data["fx"], $data["fy"], $data["fz"]);
|
||||||
break;
|
break;
|
||||||
case MC_REMOVE_BLOCK:
|
case MC_REMOVE_BLOCK:
|
||||||
|
if($this->loggedIn === false){
|
||||||
|
break;
|
||||||
|
}
|
||||||
if(Utils::distance($this->entity->position, $data) > 8){
|
if(Utils::distance($this->entity->position, $data) > 8){
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
$this->server->api->block->playerBlockBreak($this, new Vector3($data["x"], $data["y"], $data["z"]));
|
$this->server->api->block->playerBlockBreak($this, new Vector3($data["x"], $data["y"], $data["z"]));
|
||||||
break;
|
break;
|
||||||
case MC_PLAYER_ARMOR_EQUIPMENT:
|
case MC_PLAYER_ARMOR_EQUIPMENT:
|
||||||
|
if($this->loggedIn === false){
|
||||||
|
break;
|
||||||
|
}
|
||||||
$data["eid"] = $this->eid;
|
$data["eid"] = $this->eid;
|
||||||
$this->server->handle("player.armor", $data);
|
$this->server->handle("player.armor", $data);
|
||||||
break;
|
break;
|
||||||
case MC_INTERACT:
|
case MC_INTERACT:
|
||||||
|
if($this->loggedIn === false){
|
||||||
|
break;
|
||||||
|
}
|
||||||
if(isset($this->server->entities[$data["target"]]) and Utils::distance($this->entity->position, $this->server->entities[$data["target"]]->position) <= 8){
|
if(isset($this->server->entities[$data["target"]]) and Utils::distance($this->entity->position, $this->server->entities[$data["target"]]->position) <= 8){
|
||||||
if($this->handle("player.interact", $data) !== false){
|
if($this->handle("player.interact", $data) !== false){
|
||||||
console("[DEBUG] EID ".$this->eid." attacked EID ".$data["target"], true, true, 2);
|
console("[DEBUG] EID ".$this->eid." attacked EID ".$data["target"], true, true, 2);
|
||||||
@ -668,9 +692,15 @@ class Player{
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case MC_ANIMATE:
|
case MC_ANIMATE:
|
||||||
|
if($this->loggedIn === false){
|
||||||
|
break;
|
||||||
|
}
|
||||||
$this->server->api->dhandle("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:
|
||||||
|
if($this->loggedIn === false){
|
||||||
|
break;
|
||||||
|
}
|
||||||
if($this->entity->dead === false){
|
if($this->entity->dead === false){
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -681,12 +711,18 @@ class Player{
|
|||||||
$this->entity->updateMetadata();
|
$this->entity->updateMetadata();
|
||||||
break;
|
break;
|
||||||
case MC_SET_HEALTH:
|
case MC_SET_HEALTH:
|
||||||
|
if($this->loggedIn === false){
|
||||||
|
break;
|
||||||
|
}
|
||||||
if($this->gamemode === 1){
|
if($this->gamemode === 1){
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
//$this->entity->setHealth($data["health"], "client");
|
//$this->entity->setHealth($data["health"], "client");
|
||||||
break;
|
break;
|
||||||
case MC_ENTITY_EVENT:
|
case MC_ENTITY_EVENT:
|
||||||
|
if($this->loggedIn === false){
|
||||||
|
break;
|
||||||
|
}
|
||||||
$data["eid"] = $this->eid;
|
$data["eid"] = $this->eid;
|
||||||
switch($data["event"]){
|
switch($data["event"]){
|
||||||
case 9: //Eating
|
case 9: //Eating
|
||||||
@ -711,11 +747,17 @@ class Player{
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case MC_DROP_ITEM:
|
case MC_DROP_ITEM:
|
||||||
|
if($this->loggedIn === false){
|
||||||
|
break;
|
||||||
|
}
|
||||||
if($this->server->handle("player.drop", $data) !== false){
|
if($this->server->handle("player.drop", $data) !== false){
|
||||||
$this->server->api->block->drop($this->entity->x, $this->entity->y, $this->entity->z, $data["block"], $data["meta"], $data["stack"]);
|
$this->server->api->block->drop($this->entity->x, $this->entity->y, $this->entity->z, $data["block"], $data["meta"], $data["stack"]);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case MC_SIGN_UPDATE:
|
case MC_SIGN_UPDATE:
|
||||||
|
if($this->loggedIn === false){
|
||||||
|
break;
|
||||||
|
}
|
||||||
$t = $this->server->api->tileentity->get($data["x"], $data["y"], $data["z"]);
|
$t = $this->server->api->tileentity->get($data["x"], $data["y"], $data["z"]);
|
||||||
if(($t[0] instanceof TileEntity) and $t[0]->class === TILE_SIGN){
|
if(($t[0] instanceof TileEntity) and $t[0]->class === TILE_SIGN){
|
||||||
$t = $t[0];
|
$t = $t[0];
|
||||||
@ -732,6 +774,9 @@ class Player{
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case MC_CHAT:
|
case MC_CHAT:
|
||||||
|
if($this->loggedIn === false){
|
||||||
|
break;
|
||||||
|
}
|
||||||
$message = $data["message"];
|
$message = $data["message"];
|
||||||
if($message{0} === "/"){ //Command
|
if($message{0} === "/"){ //Command
|
||||||
$this->server->api->console->run(substr($message, 1), $this);
|
$this->server->api->console->run(substr($message, 1), $this);
|
||||||
@ -781,4 +826,11 @@ class Player{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function __toString(){
|
||||||
|
if($this->username != ""){
|
||||||
|
return $this->username;
|
||||||
|
}
|
||||||
|
return $this->clientID;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -135,7 +135,6 @@ abstract class Block{
|
|||||||
);
|
);
|
||||||
protected $id;
|
protected $id;
|
||||||
protected $meta;
|
protected $meta;
|
||||||
protected $shortname = "";
|
|
||||||
protected $name = "";
|
protected $name = "";
|
||||||
public $isActivable = false;
|
public $isActivable = false;
|
||||||
public $breakable = true;
|
public $breakable = true;
|
||||||
@ -154,7 +153,6 @@ abstract class Block{
|
|||||||
$this->id = (int) $id;
|
$this->id = (int) $id;
|
||||||
$this->meta = (int) $meta;
|
$this->meta = (int) $meta;
|
||||||
$this->name = $name;
|
$this->name = $name;
|
||||||
$this->shortname = strtolower(str_replace(" ", "_", $name));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getName(){
|
public function getName(){
|
||||||
@ -186,6 +184,10 @@ abstract class Block{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final public function __toString(){
|
||||||
|
return $this->name ." (".$this->id.":".$this->meta.")";
|
||||||
|
}
|
||||||
|
|
||||||
abstract function isBreakable(Item $item, Player $player);
|
abstract function isBreakable(Item $item, Player $player);
|
||||||
|
|
||||||
abstract function onBreak(BlockAPI $level, Item $item, Player $player);
|
abstract function onBreak(BlockAPI $level, Item $item, Player $player);
|
||||||
|
@ -123,6 +123,10 @@ class Item{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final public function __toString(){
|
||||||
|
return $this->name ." (".$this->id.":".$this->meta.")";
|
||||||
|
}
|
||||||
|
|
||||||
public function getDestroySpeed(Block $block, Player $player){
|
public function getDestroySpeed(Block $block, Player $player){
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user