mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-20 11:39:43 +00:00
goodbye php5, u wont be missed
This commit is contained in:
parent
2858b43748
commit
d7d346a237
16 changed files with 26 additions and 33 deletions
|
|
@ -339,10 +339,10 @@ class BlockAPI{
|
|||
}
|
||||
break;
|
||||
case "give":
|
||||
$player = $this->server->api->player->get(nullsafe($args[0], ""));
|
||||
$player = $this->server->api->player->get($args[0] ?? "");
|
||||
|
||||
if($player instanceof Player){
|
||||
$item = self::fromString(nullsafe($args[1], ""));
|
||||
$item = self::fromString($args[1] ?? "");
|
||||
if(($player->gamemode & 0x01) === 0x01){
|
||||
$output .= "Player is in creative mode.";
|
||||
break;
|
||||
|
|
@ -362,7 +362,7 @@ class BlockAPI{
|
|||
$output .= "Giving ".$item->count." of ".$item->getName()." (".$item->getID().":".$item->getMetadata().") to ".$player->username;
|
||||
break;
|
||||
}else{
|
||||
$item = self::fromString(nullsafe($args[0], ""));
|
||||
$item = self::fromString($args[0] ?? "");
|
||||
if(!($issuer instanceof Player)){
|
||||
return "You cant give an item to a non-player.";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -175,7 +175,7 @@ class EntityAPI{
|
|||
}
|
||||
|
||||
public function get($eid){
|
||||
return nullsafe($this->entities[$eid], false);
|
||||
return $this->entities[$eid] ?? false;
|
||||
}
|
||||
|
||||
public function remove($eid){
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ class TimeAPI{
|
|||
$p = strtolower(array_shift($args));
|
||||
switch($p){
|
||||
case "check":
|
||||
if(substr(nullsafe($args[0], ""), 0, 2) === "w:"){
|
||||
if(substr($args[0] ?? "", 0, 2) === "w:"){
|
||||
$levelName = preg_replace("/w:/", "", $args[0]);
|
||||
$level = $this->server->api->level->get($levelName);
|
||||
if($level instanceof Level){
|
||||
|
|
@ -44,7 +44,7 @@ class TimeAPI{
|
|||
$output .= "Time" . $world . ": " . $this->getDate($level) . ", " . $this->getPhase($level) . " (" . $this->get(true, $level) . " ticks)\n";
|
||||
break;
|
||||
case "add":
|
||||
if(substr(nullsafe($args[1], ""), 0, 2) === "w:"){
|
||||
if(substr($args[1] ?? "", 0, 2) === "w:"){
|
||||
$levelName = preg_replace("/w:/", "", $args[1]);
|
||||
$level = $this->server->api->level->get($levelName);
|
||||
if($level instanceof Level){
|
||||
|
|
|
|||
|
|
@ -1274,6 +1274,7 @@ class Player{
|
|||
if(EventHandler::callEvent(new DataPacketReceiveEvent($this, $packet)) === BaseEvent::DENY){
|
||||
return;
|
||||
}
|
||||
console($packet->pid());
|
||||
switch($packet->pid()){
|
||||
case 0x01:
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -17,8 +17,8 @@ set_error_handler("error_handler", E_ALL);
|
|||
|
||||
$errors = 0;
|
||||
|
||||
if(version_compare("5.4.0", PHP_VERSION) > 0){
|
||||
console("[ERROR] Use PHP >= 5.4.0", true, true, 0);
|
||||
if(version_compare("8.0.0", PHP_VERSION) > 0){
|
||||
console("[ERROR] Use PHP >= 8.0.0", true, true, 0);
|
||||
++$errors;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ class Slime extends Monster{
|
|||
* SlimeSize = Slime::getSlimeSize(this);
|
||||
* return SlimeSize * SlimeSize;
|
||||
*/
|
||||
$this->setSlimeSize(nullsafe($data["Size"], (1 << mt_rand(0, 2))));
|
||||
$this->setSlimeSize($data["Size"] ?? (1 << mt_rand(0, 2)));
|
||||
}
|
||||
|
||||
public function getSlimeSize(){
|
||||
|
|
|
|||
|
|
@ -61,19 +61,11 @@ 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 ".
|
||||
/**
|
||||
* @deprecated Use $expr ?? $null
|
||||
*/
|
||||
function nullsafe(&$a, $null){
|
||||
return $a ?? $null;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ class CyanFlowerBlock extends FlowableBlock{
|
|||
8 => "Oxeye Daisy",
|
||||
];
|
||||
public function __construct($meta = 0){
|
||||
parent::__construct(CYAN_FLOWER, $meta, nullsafe(self::$names[$meta], "Poppy"));
|
||||
parent::__construct(CYAN_FLOWER, $meta, self::$names[$meta] ?? "Poppy");
|
||||
$this->hardness = 0;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ class StoneBlock extends SolidBlock{
|
|||
];
|
||||
|
||||
public function __construct($meta = 0){
|
||||
parent::__construct(STONE, $meta, nullsafe(self::$names[$meta], "Stone"));
|
||||
parent::__construct(STONE, $meta, self::$names[$meta] ?? "Stone");
|
||||
$this->hardness = 30;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ class WoolBlock extends SolidBlock{
|
|||
);
|
||||
|
||||
public function __construct($meta = 0){
|
||||
parent::__construct(WOOL, $meta, nullsafe(self::$names[$meta], "Wool"));
|
||||
parent::__construct(WOOL, $meta, self::$names[$meta] ?? "Wool");
|
||||
$this->hardness = 4;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ class BucketItem extends Item{
|
|||
10 => "Lava Bucket"
|
||||
);
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(BUCKET, $meta, $count, nullsafe(self::$possiblenames[$meta], "Bucket"));
|
||||
parent::__construct(BUCKET, $meta, $count, self::$possiblenames[$meta] ?? "Bucket");
|
||||
$this->isActivable = true;
|
||||
$this->maxStackSize = 1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,6 @@ class DyeItem extends Item{
|
|||
);
|
||||
|
||||
public function __construct($meta = 0, $count = 1){
|
||||
parent::__construct(DYE, $meta, $count, nullsafe(self::$names[$meta], "Dye"));
|
||||
parent::__construct(DYE, $meta, $count, self::$names[$meta] ?? "Dye");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -444,7 +444,7 @@ class PMFLevel extends PMF{
|
|||
$X = $x >> 4;
|
||||
$Z = $z >> 4;
|
||||
$index = $this->getIndex($X, $Z);
|
||||
return nullsafe($this->chunks[$index], 0);
|
||||
return $this->chunks[$index] ?? 0;
|
||||
}
|
||||
|
||||
public function getBlockID($x, $y, $z){
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ abstract class Structure{
|
|||
}
|
||||
|
||||
protected function getMappingFor($char){
|
||||
return nullsafe($this->map[$char], self::MAP_NO_KEY);
|
||||
return $this->map[$char] ?? self::MAP_NO_KEY;
|
||||
}
|
||||
|
||||
protected function placeBlock(Level $level, $char, $vector){
|
||||
|
|
|
|||
|
|
@ -395,7 +395,7 @@ class Level{
|
|||
foreach($this->usedChunks as $c => $eids){
|
||||
$xz = explode(".", $c); //bad idea, TODO use better indexes
|
||||
foreach($eids as $cid => $_){
|
||||
$p = nullsafe($this->server->clients[$cid], false);
|
||||
$p = $this->server->clients[$cid] ?? false;
|
||||
if($p instanceof Player){
|
||||
$dist = abs($xz[0] - ($p->entity->x >> 4)) + abs($xz[1] - ($p->entity->z >> 4));
|
||||
if($dist > 8){
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ class BiomeSelector
|
|||
* @return Biome | false
|
||||
*/
|
||||
public static function get($id){
|
||||
return nullsafe(self::$biomes[$id], false);
|
||||
return self::$biomes[$id] ?? false;
|
||||
}
|
||||
|
||||
public function generateBiomeLookup(){
|
||||
|
|
@ -92,8 +92,8 @@ class BiomeSelector
|
|||
$temperature = (int) ($this->getTemperature($x, $z) * 63);
|
||||
$rainfall = (int) ($this->getRainfall($x, $z) * 63);
|
||||
|
||||
$biomeId = nullsafe($this->map[$temperature + ($rainfall << 6)], -1);
|
||||
return nullsafe(self::$biomes[$biomeId], $this->fallback);
|
||||
$biomeId = $this->map[$temperature + ($rainfall << 6)] ?? -1;
|
||||
return self::$biomes[$biomeId] ?? $this->fallback;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue