Added player commands, better console API and implemented future player chat

This commit is contained in:
Shoghi Cervantes Pueyo 2013-02-07 09:23:37 +01:00
parent 72388fa3cb
commit c2e55941d8
6 changed files with 186 additions and 131 deletions

View file

@ -374,12 +374,19 @@ class Player{
}else{
$message = (string) $data;
}
$this->dataPacket(MC_CHAT, array(
"message" => str_replace("@username", $this->username, $message),
));
$this->sendChat($message);
break;
}
}
public function sendChat($message){
$mes = explode("\n", $message);
foreach($mes as $m){
$this->dataPacket(MC_CHAT, array(
"message" => str_replace("@username", $this->username, $m),
));
}
}
public function handle($pid, $data){
if($this->connected === true){
@ -724,6 +731,16 @@ class Player{
}
}
break;
case MC_CHAT:
$message = $data["message"];
if($message{0} === "/"){ //Command
$this->server->api->console->run(substr($message, 1), $this);
}else{
if($this->server->api->dhandle("player.chat", array("player" => $this, "message" => $message)) !== false){
$this->server->api->send($this, $message);
}
}
break;
default:
console("[DEBUG] Unhandled 0x".dechex($data["id"])." Data Packet for Client ID ".$this->clientID.": ".print_r($data, true), true, true, 2);
break;