diff --git a/src/Deprecation.php b/src/Deprecation.php index 36d2eb5c8..7052af5f6 100644 --- a/src/Deprecation.php +++ b/src/Deprecation.php @@ -28,6 +28,7 @@ the Free Software Foundation, either version 3 of the License, or class Deprecation{ public static $events = array( + "server.time" => "time.change", "world.block.change" => "block.change", "block.drop" => "item.drop", "api.op.check" => "op.check", diff --git a/src/Player.php b/src/Player.php index c8e43caea..3699df666 100644 --- a/src/Player.php +++ b/src/Player.php @@ -441,10 +441,12 @@ class Player{ "eid" => $data->eid, )); break; - case "server.time": - $this->dataPacket(MC_SET_TIME, array( - "time" => $data, - )); + case "time.change": + if($data["level"] === $this->level){ + $this->dataPacket(MC_SET_TIME, array( + "time" => $data["time"], + )); + } break; case "entity.animate": if($data["eid"] === $this->eid or $data["entity"]->level !== $this->level){ @@ -906,7 +908,7 @@ class Player{ $this->entity->z = $this->data->get("position")["z"]; $this->entity->setName($this->username); $this->entity->data["clientID"] = $this->clientID; - $this->evid[] = $this->server->event("server.time", array($this, "eventHandler")); + $this->evid[] = $this->server->event("time.change", array($this, "eventHandler")); $this->evid[] = $this->server->event("server.chat", array($this, "eventHandler")); $this->evid[] = $this->server->event("entity.remove", array($this, "eventHandler")); $this->evid[] = $this->server->event("entity.move", array($this, "eventHandler")); diff --git a/src/PocketMinecraftServer.php b/src/PocketMinecraftServer.php index df19cdd7b..8af0bde8d 100644 --- a/src/PocketMinecraftServer.php +++ b/src/PocketMinecraftServer.php @@ -27,7 +27,7 @@ the Free Software Foundation, either version 3 of the License, or class PocketMinecraftServer{ public $tCnt; - public $version, $invisible, $api, $tickMeasure, $preparedSQL, $seed, $gamemode, $name, $maxClients, $clients, $eidCnt, $custom, $description, $motd, $timePerSecond; + public $version, $invisible, $api, $tickMeasure, $preparedSQL, $seed, $gamemode, $name, $maxClients, $clients, $eidCnt, $custom, $description, $motd; private $port, $serverip, $database, $interface, $evCnt, $handCnt, $events, $eventsID, $handlers, $serverType, $lastTick; private function load(){ @@ -65,8 +65,6 @@ class PocketMinecraftServer{ $this->whitelist = false; $this->clients = array(); $this->spawn = false; - $this->time = 0; - $this->timePerSecond = 20; $this->tickMeasure = array_fill(0, 40, 0); $this->setType("normal"); $this->interface = new MinecraftInterface("255.255.255.255", $this->port, true, false, $this->serverip); @@ -102,7 +100,6 @@ class PocketMinecraftServer{ if(ENABLE_ANSI === true){ $this->action(1500000, '$this->titleTick();'); } - $this->action(500000, '$this->time += (int) ($this->timePerSecond / 2);$this->api->dhandle("server.time", $this->time);'); $this->action(5000000, 'if($this->difficulty < 2){$this->api->dhandle("server.regeneration", 1);}'); $this->action(1000000 * 15, 'if($this->getTPS() < 15){console("[WARNING] Can\'t keep up! Is the server overloaded?");}'); $this->action(1000000 * 60 * 10, '$this->custom = array();'); diff --git a/src/world/Level.php b/src/world/Level.php index a5875cb98..ec26f1011 100644 --- a/src/world/Level.php +++ b/src/world/Level.php @@ -41,6 +41,14 @@ class Level{ $this->name = $name; } + public function checkThings(){ + $now = microtime(true); + $time = $this->startTime + ($now - $this->startCheck) * 20; + if($this->server->api->dhandle("time.change", array("level" => $this, "time" => $time)) !== false){ + $this->time = $time; + } + } + public function __destruct(){ $this->save(); unset($this->level); @@ -142,11 +150,6 @@ class Level{ $this->startCheck = microtime(true); } - public function checkThings(){ - $now = microtime(true); - $this->time = $this->startTime + ($now - $this->startCheck) * 20; - } - public function getSeed(){ return (int) $this->level->getData("seed"); }