mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-20 19:49:44 +00:00
added nullsafe function, time should be set instantly after player joined, some php8 fixes
This commit is contained in:
parent
695f9f1484
commit
a66176b75d
5 changed files with 41 additions and 22 deletions
|
|
@ -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.";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 <mob> [amount] [baby]";
|
||||
break;
|
||||
return "Usage: /$cmd <mob> [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 <mob>
|
||||
$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 <mob> [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 <mob> [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 <mob> [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":
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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 . "/");
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue