mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-01 23:59:53 +00:00
Death cause!
This commit is contained in:
parent
bc934a8940
commit
68a685a984
5
README
5
README
@ -35,7 +35,8 @@ How to connect to internet servers: http://www.minecraftforum.net/topic/1256915-
|
|||||||
|
|
||||||
|
|
||||||
Current features of the server:
|
Current features of the server:
|
||||||
- Players can connect and move around the world
|
- Players can connect and move around the world (and see each other)
|
||||||
|
- PvP, life regeneration and death cause!
|
||||||
- Online list broadcast
|
- Online list broadcast
|
||||||
- Configurable day/night cycle
|
- Configurable day/night cycle
|
||||||
- Health and position saving
|
- Health and position saving
|
||||||
@ -43,7 +44,5 @@ Current features of the server:
|
|||||||
- Whitelist and IP Ban files
|
- Whitelist and IP Ban files
|
||||||
- Survival & Creative
|
- Survival & Creative
|
||||||
- Awesome features in server list!
|
- Awesome features in server list!
|
||||||
- Players spawn and see each other moving!
|
|
||||||
- PvP and life regeneration!
|
|
||||||
- Multiple worlds and importing!
|
- Multiple worlds and importing!
|
||||||
+ more!
|
+ more!
|
@ -76,6 +76,9 @@ class PocketMinecraftServer{
|
|||||||
$this->events = array("disabled" => array());
|
$this->events = array("disabled" => array());
|
||||||
|
|
||||||
$this->event("onChat", "eventHandler", true);
|
$this->event("onChat", "eventHandler", true);
|
||||||
|
$this->event("onPlayerDeath", "eventHandler", true);
|
||||||
|
$this->event("onPlayerAdd", "eventHandler", true);
|
||||||
|
$this->event("onHealthChange", "eventHandler", true);
|
||||||
|
|
||||||
$this->action(100000, '$this->time += ceil($this->timePerSecond / 10);$this->trigger("onTimeChange", $this->time);');
|
$this->action(100000, '$this->time += ceil($this->timePerSecond / 10);$this->trigger("onTimeChange", $this->time);');
|
||||||
$this->action(5000000, '$this->trigger("onHealthRegeneration", 1);');
|
$this->action(5000000, '$this->trigger("onHealthRegeneration", 1);');
|
||||||
@ -87,6 +90,7 @@ class PocketMinecraftServer{
|
|||||||
|
|
||||||
public function startDatabase(){
|
public function startDatabase(){
|
||||||
$this->database = new SQLite3(":memory:");
|
$this->database = new SQLite3(":memory:");
|
||||||
|
$this->query("CREATE TABLE clients (clientID INTEGER PRIMARY KEY, EID NUMERIC, ip TEXT, port NUMERIC, name TEXT);");
|
||||||
$this->query("CREATE TABLE entities (EID INTEGER PRIMARY KEY, type NUMERIC, class NUMERIC, name TEXT, x NUMERIC, y NUMERIC, z NUMERIC, yaw NUMERIC, pitch NUMERIC, health NUMERIC);");
|
$this->query("CREATE TABLE entities (EID INTEGER PRIMARY KEY, type NUMERIC, class NUMERIC, name TEXT, x NUMERIC, y NUMERIC, z NUMERIC, yaw NUMERIC, pitch NUMERIC, health NUMERIC);");
|
||||||
$this->query("CREATE TABLE metadata (EID INTEGER PRIMARY KEY, name TEXT, value TEXT);");
|
$this->query("CREATE TABLE metadata (EID INTEGER PRIMARY KEY, name TEXT, value TEXT);");
|
||||||
$this->query("CREATE TABLE actions (ID INTEGER PRIMARY KEY, interval NUMERIC, last NUMERIC, code TEXT, repeat NUMERIC);");
|
$this->query("CREATE TABLE actions (ID INTEGER PRIMARY KEY, interval NUMERIC, last NUMERIC, code TEXT, repeat NUMERIC);");
|
||||||
@ -155,6 +159,34 @@ class PocketMinecraftServer{
|
|||||||
|
|
||||||
public function eventHandler($data, $event){
|
public function eventHandler($data, $event){
|
||||||
switch($event){
|
switch($event){
|
||||||
|
case "onPlayerDeath":
|
||||||
|
$message = $data["name"];
|
||||||
|
if(is_numeric($data["cause"]) and isset($this->entities[$data["cause"]])){
|
||||||
|
switch($this->entities[$data["cause"]]->class){
|
||||||
|
case ENTITY_PLAYER:
|
||||||
|
$message .= " was killed by ".$this->entities[$data["cause"]]->name;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$message .= " was killed";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
switch($data["cause"]){
|
||||||
|
default:
|
||||||
|
$message .= " was killed";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->chat(false, $message);
|
||||||
|
break;
|
||||||
|
case "onHealthChange":
|
||||||
|
if($data["health"] <= 0){
|
||||||
|
$this->trigger("onDeath", array("eid" => $data["eid"], "cause" => $data["cause"]));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "onPlayerAdd":
|
||||||
|
console("[DEBUG] Player \"".$data["username"]."\" EID ".$data["eid"]." spawned at X ".$data["x"]." Y ".$data["y"]." Z ".$data["z"], true, true, 2);
|
||||||
|
break;
|
||||||
case "onChat":
|
case "onChat":
|
||||||
console("[CHAT] $data");
|
console("[CHAT] $data");
|
||||||
break;
|
break;
|
||||||
|
@ -90,6 +90,11 @@ class Session{
|
|||||||
|
|
||||||
public function eventHandler($data, $event){
|
public function eventHandler($data, $event){
|
||||||
switch($event){
|
switch($event){
|
||||||
|
case "onDeath":
|
||||||
|
if($data["eid"] === $this->eid){
|
||||||
|
$this->server->trigger("onPlayerDeath", array("name" => $this->username, "cause" => $data["cause"]));
|
||||||
|
}
|
||||||
|
break;
|
||||||
case "onEntityMove":
|
case "onEntityMove":
|
||||||
if($data === $this->eid){
|
if($data === $this->eid){
|
||||||
break;
|
break;
|
||||||
@ -112,7 +117,7 @@ class Session{
|
|||||||
break;
|
break;
|
||||||
case "onHealthRegeneration":
|
case "onHealthRegeneration":
|
||||||
if($this->server->difficulty < 2){
|
if($this->server->difficulty < 2){
|
||||||
$this->server->trigger("onHealthChange", array("eid" => $this->eid, "health" => min(20, $this->data["health"] + $data)));
|
$this->server->trigger("onHealthChange", array("eid" => $this->eid, "health" => min(20, $this->data["health"] + $data), "cause" => "regeneration"));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "onHealthChange":
|
case "onHealthChange":
|
||||||
@ -277,6 +282,7 @@ class Session{
|
|||||||
}
|
}
|
||||||
$this->evid[] = array("onTimeChange", $this->server->event("onTimeChange", array($this, "eventHandler")));
|
$this->evid[] = array("onTimeChange", $this->server->event("onTimeChange", array($this, "eventHandler")));
|
||||||
$this->evid[] = array("onChat", $this->server->event("onChat", array($this, "eventHandler")));
|
$this->evid[] = array("onChat", $this->server->event("onChat", array($this, "eventHandler")));
|
||||||
|
$this->evid[] = array("onDeath", $this->server->event("onDeath", array($this, "eventHandler")));
|
||||||
$this->evid[] = array("onPlayerAdd", $this->server->event("onPlayerAdd", array($this, "eventHandler")));
|
$this->evid[] = array("onPlayerAdd", $this->server->event("onPlayerAdd", array($this, "eventHandler")));
|
||||||
$this->evid[] = array("onEntityRemove", $this->server->event("onEntityRemove", array($this, "eventHandler")));
|
$this->evid[] = array("onEntityRemove", $this->server->event("onEntityRemove", array($this, "eventHandler")));
|
||||||
$this->evid[] = array("onEntityMove", $this->server->event("onEntityMove", array($this, "eventHandler")));
|
$this->evid[] = array("onEntityMove", $this->server->event("onEntityMove", array($this, "eventHandler")));
|
||||||
@ -312,7 +318,7 @@ class Session{
|
|||||||
if(is_object($this->entity)){
|
if(is_object($this->entity)){
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
$this->server->trigger("onHealthChange", array("eid" => $this->eid, "health" => $this->data["health"]));
|
$this->server->trigger("onHealthChange", array("eid" => $this->eid, "health" => $this->data["health"], "cause" => "respawn"));
|
||||||
console("[DEBUG] Player with EID ".$this->eid." \"".$this->username."\" spawned!", true, true, 2);
|
console("[DEBUG] Player with EID ".$this->eid." \"".$this->username."\" spawned!", true, true, 2);
|
||||||
$this->entity = new Entity($this->eid, ENTITY_PLAYER, 0, $this->server);
|
$this->entity = new Entity($this->eid, ENTITY_PLAYER, 0, $this->server);
|
||||||
$this->entity->setName($this->username);
|
$this->entity->setName($this->username);
|
||||||
@ -392,15 +398,16 @@ class Session{
|
|||||||
++$this->counter[0];
|
++$this->counter[0];
|
||||||
break;
|
break;
|
||||||
case MC_INTERACT:
|
case MC_INTERACT:
|
||||||
if($this->server->difficulty > 0 and isset($this->server->entities[$data["target"]]) and Utils::distance($this->entity->position, $this->server->entities[$data["target"]]->position) <= 8){
|
if($this->server->gamemode !== 1 and $this->server->difficulty > 0 and isset($this->server->entities[$data["target"]]) and Utils::distance($this->entity->position, $this->server->entities[$data["target"]]->position) <= 8){
|
||||||
$this->server->trigger("onHealthChange", array("eid" => $data["target"], "health" => $this->server->entities[$data["target"]]->getHealth() - $this->server->difficulty));
|
console("[DEBUG] EID ".$this->eid." attacked EID ".$data["target"], true, true, 2);
|
||||||
|
$this->server->trigger("onHealthChange", array("eid" => $data["target"], "health" => $this->server->entities[$data["target"]]->getHealth() - $this->server->difficulty, "cause" => $this->eid));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case MC_ANIMATE:
|
case MC_ANIMATE:
|
||||||
$this->server->trigger("onAnimate", array("eid" => $this->eid, "action" => $data["action"]));
|
$this->server->trigger("onAnimate", array("eid" => $this->eid, "action" => $data["action"]));
|
||||||
break;
|
break;
|
||||||
case MC_RESPAWN:
|
case MC_RESPAWN:
|
||||||
$this->server->trigger("onHealthChange", array("eid" => $this->eid, "health" => 20));
|
$this->server->trigger("onHealthChange", array("eid" => $this->eid, "health" => 20, "cause" => "respawn"));
|
||||||
$this->entity->setPosition($data["x"], $data["y"], $data["z"], $data["x"], 0, 0);
|
$this->entity->setPosition($data["x"], $data["y"], $data["z"], $data["x"], 0, 0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user