diff --git a/src/API/BlockAPI.php b/src/API/BlockAPI.php index 6098ec43..9569d988 100755 --- a/src/API/BlockAPI.php +++ b/src/API/BlockAPI.php @@ -293,10 +293,10 @@ class BlockAPI{ } break; case "give": - $player = $this->server->api->player->get($args[0]); + $player = $this->server->api->player->get(nullsafe($args[0], "")); if($player instanceof Player){ - $item = self::fromString($args[1]); + $item = self::fromString(nullsafe($args[1], "")); if(($player->gamemode & 0x01) === 0x01){ $output .= "Player is in creative mode."; break; @@ -316,7 +316,7 @@ class BlockAPI{ $output .= "Giving ".$item->count." of ".$item->getName()." (".$item->getID().":".$item->getMetadata().") to ".$player->username; break; }else{ - $item = self::fromString($args[0]); + $item = self::fromString(nullsafe($args[0], "")); if(!($issuer instanceof Player)){ return "You cant give an item to a non-player."; } diff --git a/src/API/EntityAPI.php b/src/API/EntityAPI.php index 12e99ee8..05f5c377 100644 --- a/src/API/EntityAPI.php +++ b/src/API/EntityAPI.php @@ -41,25 +41,21 @@ class EntityAPI{ case "summon": case "spawnmob": if(!($issuer instanceof Player)){ - $output .= "Please run this command in-game."; - break; + return "Please run this command in-game."; } if((count($args) < 1) or (count($args) > 3)){ - $output .= "Usage: /$cmd [amount] [baby]"; - break; + return "Usage: /$cmd [amount] [baby]"; } if(is_int($args[0])) $type = $args[0]; else $type = $mob[strtolower($args[0])]; - if($type != (10 or 11 or 12 or 13 or 32 or 33 or 34 or 35 or 36)){ - $output .= "Unknown mob."; - break; + if($type < 10 || $type > 36){ + return "Unknown mob."; } $mobName = ucfirst(array_flip($mob)[$type]); - if((isset($args[1]) || isset($args[2])) && (strtolower($args[1] === "baby") or strtolower($args[2] === "baby")) and !Utils::in_range($type, 10, 13)){ - $output .= "$mobName cannot be a baby!"; - break; + if(((isset($args[1]) && strtolower($args[1]) === "baby") || (isset($args[2]) && strtolower($args[2]) === "baby")) && !Utils::in_range($type, 10, 13)){ + return "$mobName cannot be a baby!"; } $x = round($issuer->entity->x, 2, PHP_ROUND_HALF_UP); @@ -70,14 +66,12 @@ class EntityAPI{ if(count($args) === 1){//summon $this->summon($pos, ENTITY_MOB, $type); - $output .= "$mobName spawned in $x, $y, $z."; - break; + return "$mobName spawned in $x, $y, $z."; } elseif(is_numeric($args[1])){//summon [amount] $amount = (int) $args[1]; if($amount > 100){ - $output .= "Cannot spawn > 100 mobs"; - break; + return "Cannot spawn > 100 mobs"; } $isBaby = false; if(isset($args[2]) and strtolower($args[2]) === 'baby'){//summon [amount] [baby] @@ -88,13 +82,11 @@ class EntityAPI{ $this->summon($pos, ENTITY_MOB, $type, ["IsBaby" => $isBaby]); } - $output .= "$amount ".($isBaby === 1 ? "Baby" : "")." $mobName".(($type !== 13 || $amount > 1) ? "s" : "")." spawned in $x, $y, $z."; - break; + return "$amount ".($isBaby === 1 ? "Baby" : "")." $mobName(s) spawned in $x, $y, $z."; } elseif(strtolower($args[1]) == "baby"){//summon [baby] $this->summon($pos, ENTITY_MOB, $type, ["IsBaby" => 1]); - $output .= "Baby $mobName spawned in $x, $y, $z."; - break; + return "Baby $mobName spawned in $x, $y, $z."; } break; case "despawn": diff --git a/src/Player.php b/src/Player.php index 15bd2794..efc4ec51 100755 --- a/src/Player.php +++ b/src/Player.php @@ -1455,6 +1455,13 @@ class Player{ $this->evid[] = $this->server->event("player.block.break", [$this, "eventHandler"]); $this->lastMeasure = microtime(true); $this->server->schedule(50, [$this, "measureLag"], [], true); + + $pk = new SetTimePacket; + $pk->time = (int) $this->level->getTime(); + $pk->started = !$this->level->isTimeStopped(); + $this->dataPacket($pk); + + console("[INFO] " . FORMAT_AQUA . $this->username . FORMAT_RESET . "[/" . $this->ip . ":" . $this->port . "] logged in with entity id " . $this->eid . " at (" . $this->entity->level->getName() . ", " . round($this->entity->x, 2) . ", " . round($this->entity->y, 2) . ", " . round($this->entity->z, 2) . ")"); break; case ProtocolInfo::READY_PACKET: diff --git a/src/functions.php b/src/functions.php index b6169f2f..49983ebb 100644 --- a/src/functions.php +++ b/src/functions.php @@ -61,6 +61,22 @@ function kill($pid){ } } +if(version_compare(PHP_VERSION, '7.0.0') >= 0){ //php > 7.0 + eval(' + function nullsafe(&$a, $null){ + return $a ?? $null; + } + '); + +}else{ + eval(' + function nullsafe(&$value, $null){ + return isset($value) ? $value : $null; + } + '); //behavior will change if you replace ' with ". +} + + function require_all($path, &$count = 0){ $dir = dir($path . "/"); diff --git a/src/world/Level.php b/src/world/Level.php index ca356d63..487bd922 100644 --- a/src/world/Level.php +++ b/src/world/Level.php @@ -516,7 +516,11 @@ class Level{ $this->time -= 20 * 13; } } - + + public function isTimeStopped(){ + return $this->stopTime; + } + public function stopTime(){ $this->stopTime = true; $this->startCheck = 0;