This commit is contained in:
Shoghi Cervantes Pueyo 2013-01-29 20:53:43 +01:00
parent 2011d1d339
commit 71b12191b2
4 changed files with 42 additions and 1 deletions

View File

@ -36,6 +36,7 @@ class PlayerAPI{
$this->server->addHandler("player.death", array($this, "handle"), 1);
$this->server->api->console->register("list", "Shows connected player list", array($this, "commandHandler"));
$this->server->api->console->register("kill", "Kills a player", array($this, "commandHandler"));
$this->server->api->console->register("harm", "Harms a player", array($this, "commandHandler"));
$this->server->api->console->register("tppos", "Teleports a player to a position", array($this, "commandHandler"));
$this->server->api->console->register("tp", "Teleports a player to another player", array($this, "commandHandler"));
}
@ -138,6 +139,15 @@ class PlayerAPI{
console("[INFO] Usage: /kill <player>");
}
break;
case "harm":
$dmg = (int) array_shift($params);
$player = $this->get(implode(" ", $params));
if($player !== false){
$this->server->api->entity->harm($player->eid, $dmg, "console", true);
}else{
console("[INFO] Usage: /harm <damage> <player>");
}
break;
case "list":
console("[INFO] Player list:");
foreach($this->server->clients as $c){

View File

@ -583,6 +583,30 @@ class Player{
}
//$this->entity->setHealth($data["health"], "client");
break;
case MC_ENTITY_EVENT:
$data["eid"] = $this->eid;
switch($data["event"]){
case 9: //Eating
$items = array(
260 => 2, //Apples
282 => 10, //Stew
297 => 5, //Bread
319 => 3,
320 => 8,
363 => 3,
364 => 8,
);
if(isset($items[$this->equipment[0]])){
$this->removeItem($this->equipment[0], 0, 1);
$this->dataPacket(MC_ENTITY_EVENT, array(
"eid" => 0,
"event" => 9,
));
$this->entity->heal($items[$this->equipment[0]], "eating");
}
break;
}
break;
case MC_DROP_ITEM:
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"]);

View File

@ -478,6 +478,9 @@ class CustomPacketHandler{
$this->raw .= Utils::writeInt($this->data["target"]);*/
}
break;
case MC_PLAYER_ACTION:
//TODO
break;
case MC_SET_ENTITY_DATA:
if($this->c === false){
$this->data["eid"] = Utils::readInt($this->get(4));

View File

@ -162,7 +162,7 @@ class Entity extends stdClass{
}
if($this->y < -16){
$this->harm(8, "void", true); //4 per second
$this->harm(8, "void", true);
}
if($this->fire > 0){
@ -470,6 +470,10 @@ class Entity extends stdClass{
return $this->setHealth($this->getHealth() - ((int) $dmg), $cause, $force);
}
public function heal($health, $cause = "generic"){
return $this->setHealth(min(20, $this->getHealth() + ((int) $health)), $cause);
}
public function setHealth($health, $cause = "generic", $force = false){
$health = (int) $health;
$harm = false;