Merge pull request #49 from Sunch233/master-enchant

a big code enchant
This commit is contained in:
GameHerobrine 2024-08-17 16:23:54 +03:00 • committed by GitHub
commit 83585f8d6a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
80 changed files with 408 additions and 702 deletions

View file

@ -130,7 +130,7 @@ class AchievementAPI{
return false;
}
if(!isset($player->achievements[$achievementId]) or $player->achievements[$achievementId] == false){
if(!isset($player->achievements[$achievementId]) or !$player->achievements[$achievementId]){
return false;
}
return true;
@ -140,7 +140,7 @@ class AchievementAPI{
if(isset(self::$achievements[$achievementId])){
$result = ServerAPI::request()->api->dhandle("achievement.broadcast", ["player" => $player, "achievementId" => $achievementId]);
if($result !== false and $result !== true){
if(ServerAPI::request()->api->getProperty("announce-player-achievements") == true){
if(ServerAPI::request()->api->getProperty("announce-player-achievements")){
ServerAPI::request()->api->chat->broadcast($player->username . " has just earned the achievement [" . self::$achievements[$achievementId]["name"] . "]");
}else{
$player->sendChat("You have just earned the achievement [" . self::$achievements[$achievementId]["name"] . "]");

View file

@ -145,17 +145,11 @@ class LevelAPI{
if($generator !== false and class_exists($generator)){
$generator = new $generator($options);
}else{
switch(strtoupper($this->server->api->getProperty("level-type"))){
case "FLAT":
$generator = new SuperflatGenerator($options);
break;
case "VANILLA":
$generator = new VanillaGenerator($options);
break;
default:
$generator = new TemporalGenerator($options);
break;
}
$generator = match (strtoupper($this->server->api->getProperty("level-type"))) {
"FLAT" => new SuperflatGenerator($options),
"VANILLA" => new VanillaGenerator($options),
default => new TemporalGenerator($options),
};
}
$gen = new WorldGenerator($generator, $name, $seed === false ? Utils::readInt(Utils::getRandomBytes(4, false)) : (int) $seed);
$gen->generate();

View file

@ -57,38 +57,18 @@ class PlayerAPI{
}
}
}else{
switch($data["cause"]){
case "cactus":
$message = " was pricked to death";
break;
case "lava":
$message = " tried to swim in lava";
break;
case "fire":
$message = " went up in flames";
break;
case "burning":
$message = " burned to death";
break;
case "suffocation":
$message = " suffocated in a wall";
break;
case "water":
$message = " drowned";
break;
case "void":
$message = " fell out of the world";
break;
case "fall":
$message = " hit the ground too hard";
break;
case "explosion":
$message = " blew up";
break;
default:
$message = " died";
break;
}
$message = match ($data["cause"]) {
"cactus" => " was pricked to death",
"lava" => " tried to swim in lava",
"fire" => " went up in flames",
"burning" => " burned to death",
"suffocation" => " suffocated in a wall",
"water" => " drowned",
"void" => " fell out of the world",
"fall" => " hit the ground too hard",
"explosion" => " blew up",
default => " died",
};
}
$this->server->api->chat->broadcast($data["player"]->username . $message);
return true;
@ -190,8 +170,8 @@ class PlayerAPI{
}
break;
case "tp":
if(count($args) <= 2 or substr($args[0], 0, 2) === "w:" or substr($args[1], 0, 2) === "w:"){
if((!isset($args[1]) or substr($args[0], 0, 2) === "w:") and isset($args[0]) and ($issuer instanceof Player)){
if(count($args) <= 2 or str_starts_with($args[0], "w:") or str_starts_with($args[1], "w:")){
if((!isset($args[1]) or str_starts_with($args[0], "w:")) and isset($args[0]) and ($issuer instanceof Player)){
$name = $issuer->username;
$target = implode(" ", $args);
}elseif(isset($args[1]) and isset($args[0])){
@ -297,7 +277,7 @@ class PlayerAPI{
}
public function teleport(&$name, &$target){
if(substr($target, 0, 2) === "w:"){
if(str_starts_with($target, "w:")){
$lv = $this->server->api->level->get(substr($target, 2));
if($lv instanceof Level){
$origin = $this->get($name);

View file

@ -55,7 +55,7 @@ class PluginAPI extends stdClass{
return;
}
foreach($this->plugins as $p){
if(method_exists($p[0], "__destruct")){$p[0]->__destruct();};
if(method_exists($p[0], "__destruct")) $p[0]->__destruct();
}
unset($this->plugins);
}

View file

@ -152,7 +152,7 @@ class ServerAPI{
//define("MAX_CHUNK_RATE", 20 / $this->getProperty("max-chunks-per-second", 8)); //Default rate ~512 kB/s
MobSpawner::$spawnAnimals = $this->getProperty("spawn-animals");
MobSpawner::$spawnMobs = $this->getProperty("spawn-mobs");
if($this->getProperty("upnp-forwarding") == true){
if($this->getProperty("upnp-forwarding")){
console("[INFO] [UPnP] Trying to port forward...");
UPnP_PortForward($this->getProperty("server-port"));
}
@ -245,7 +245,7 @@ class ServerAPI{
public function setProperty($name, $value, $save = true){
$this->config->set($name, $value);
if($save == true){
if($save){
$this->writeProperties();
}
$this->loadProperties();

View file

@ -31,7 +31,7 @@ class TimeAPI{
$p = strtolower(array_shift($args));
switch($p){
case "check":
if(substr($args[0] ?? "", 0, 2) === "w:"){
if(str_starts_with($args[0] ?? "", "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($args[1] ?? "", 0, 2) === "w:"){
if(str_starts_with($args[1] ?? "", "w:")){
$levelName = preg_replace("/w:/", "", $args[1]);
$level = $this->server->api->level->get($levelName);
if($level instanceof Level){
@ -65,7 +65,7 @@ class TimeAPI{
$output .= "Added $addTime ticks" . $world . "\n";
break;
case "set":
if(isset($args[1]) and substr($args[1], 0, 2) === "w:"){
if(isset($args[1]) and str_starts_with($args[1], "w:")){
$levelName = preg_replace("/w:/", "", $args[1]);
$level = $this->server->api->level->get($levelName);
if($level instanceof Level){
@ -92,7 +92,7 @@ class TimeAPI{
case "day":
case "sunset":
case "night":
if(count($args) > 1 && substr($args[1], 0, 2) === "w:"){
if(count($args) > 1 && str_starts_with($args[1], "w:")){
$levelName = preg_replace("/w:/", "", $args[1]);
$level = $this->server->api->level->get($levelName);
if($level instanceof Level){

View file

@ -413,11 +413,7 @@ class Player{
* @return Item
*/
public function getSlot($slot){
if(isset($this->inventory[(int) $slot])){
return $this->inventory[(int) $slot];
}else{
return BlockAPI::getItem(AIR, 0, 0);
}
return $this->inventory[(int)$slot] ?? BlockAPI::getItem(AIR, 0, 0);
}
/**
@ -724,11 +720,7 @@ class Player{
* @return Item
*/
public function getArmor($slot){
if(isset($this->armor[(int) $slot])){
return $this->armor[(int) $slot];
}else{
return BlockAPI::getItem(AIR, 0, 0);
}
return $this->armor[(int)$slot] ?? BlockAPI::getItem(AIR, 0, 0);
}
public function setArmor($slot, Item $armor, $send = true){
@ -779,7 +771,7 @@ class Player{
if($w === $data["tile"]){
$pk = new ContainerSetSlotPacket;
$pk->windowid = $id;
$pk->slot = $data["slot"] + (isset($data["offset"]) ? $data["offset"] : 0);
$pk->slot = $data["slot"] + ($data["offset"] ?? 0);
$pk->item = $data["slotdata"];
$this->dataPacket($pk);
}
@ -1730,7 +1722,7 @@ class Player{
$pos = new Position($this->entity->x, $this->entity->y, $this->entity->z, $this->level);
$pData = $this->data->get("position");
$this->teleport($pos, isset($pData["yaw"]) ? $pData["yaw"] : false, isset($pData["pitch"]) ? $pData["pitch"] : false, true, true);
$this->teleport($pos, $pData["yaw"] ?? false, $pData["pitch"] ?? false, true, true);
$this->entity->setHealth($this->data->get("health"), "spawn", true);
$this->spawned = true;
$this->server->api->player->spawnAllPlayers($this);

View file

@ -106,7 +106,7 @@ class PocketMinecraftServer{
if(self::$FORCE_20_TPS){
ConsoleAPI::warn("Forcing 20 tps. This may result in higher CPU usage!");
}
if($this->extraprops->get("discord-msg") == true){
if($this->extraprops->get("discord-msg")){
if($this->extraprops->get("discord-webhook-url") !== "none"){
console("[INFO] Discord Logger is enabled.");
}else{
@ -226,7 +226,7 @@ class PocketMinecraftServer{
}
public function send2Discord($msg){
if($this->extraprops->get("discord-msg") == true and $this->extraprops->get("discord-webhook-url") !== "none"){
if($this->extraprops->get("discord-msg") and $this->extraprops->get("discord-webhook-url") !== "none"){
$url = $this->extraprops->get("discord-webhook-url");
$name = $this->extraprops->get("discord-bot-name");
$this->asyncOperation(ASYNC_CURL_POST, [
@ -548,7 +548,7 @@ class PocketMinecraftServer{
$this->custom["times_" . $CID] = 0;
}
$ln = 15;
if($this->description == "" or substr($this->description, -1) != " "){
if($this->description == "" or !str_ends_with($this->description, " ")){
$this->description .= " ";
}
$txt = substr($this->description, $this->custom["times_" . $CID], $ln);
@ -688,7 +688,7 @@ class PocketMinecraftServer{
E_DEPRECATED => "E_DEPRECATED",
E_USER_DEPRECATED => "E_USER_DEPRECATED",
];
$er["type"] = isset($errorConversion[$er["type"]]) ? $errorConversion[$er["type"]] : $er["type"];
$er["type"] = $errorConversion[$er["type"]] ?? $er["type"];
$dump .= "Error: " . var_export($er, true) . "\r\n\r\n";
if(stripos($er["file"], "plugin") !== false){
$dump .= "THIS ERROR WAS CAUSED BY A PLUGIN. REPORT IT TO THE PLUGIN DEVELOPER.\r\n";

View file

@ -4,7 +4,7 @@ set_time_limit(0);
if(ini_get("date.timezone") == ""){ //No Timezone set
date_default_timezone_set("GMT");
if(strpos(" " . strtoupper(php_uname("s")), " WIN") !== false){
if(str_contains(" " . strtoupper(php_uname("s")), " WIN")){
$time = time();
$time -= $time % 60;
//Example: USA
@ -24,7 +24,7 @@ if(ini_get("date.timezone") == ""){ //No Timezone set
date_default_timezone_set($d);
}else{
$d = @date_default_timezone_get();
if(strpos($d, "/") === false){
if(!str_contains($d, "/")){
$d = timezone_name_from_abbr($d);
@ini_set("date.timezone", $d);
date_default_timezone_set($d);

View file

@ -7,7 +7,7 @@ require_once(FILE_PATH . "/src/functions.php");
/***REM_END***/
define("DATA_PATH", realpath(arg("data-path", FILE_PATH)) . "/");
if(arg("enable-ansi", strpos(strtoupper(php_uname("s")), "WIN") === 0 ? false : true) === true and arg("disable-ansi", false) !== true){
if(arg("enable-ansi", !(strpos(strtoupper(php_uname("s")), "WIN") === 0)) === true and arg("disable-ansi", false) !== true){
define("ENABLE_ANSI", true);
}else{
define("ENABLE_ANSI", false);
@ -120,7 +120,7 @@ $inc = get_included_files();
$inc[] = array_shift($inc);
$srcdir = realpath(FILE_PATH . "src/");
foreach($inc as $s){
if(strpos(realpath(dirname($s)), $srcdir) === false and strtolower(basename($s)) !== "pocketmine-mp.php"){
if(!str_contains(realpath(dirname($s)), $srcdir) and strtolower(basename($s)) !== "pocketmine-mp.php"){
continue;
}
$sha1sum ^= sha1_file($s, true);
@ -130,7 +130,7 @@ ini_set("opcache.mmap_base", bin2hex(Utils::getRandomBytes(8, false))); //Fix OP
define("SOURCE_SHA1SUM", bin2hex($sha1sum));
/***REM_START***/
if(!file_exists(DATA_PATH . "server.properties") and arg("no-wizard", false) != true){
if(!file_exists(DATA_PATH . "server.properties") and !arg("no-wizard", false)){
$installer = new Installer();
}
/***REM_END***/

View file

@ -14,7 +14,7 @@ abstract class Animal extends Creature implements Ageable, Breedable{
public function __construct(Level $level, $eid, $class, $type = 0, $data = []){
parent::__construct($level, $eid, $class, $type, $data);
$this->setAge(isset($data["Age"]) ? $data["Age"] : 0);
$this->setAge($data["Age"] ?? 0);
if(isset($this->data["IsBaby"]) && $this->data["IsBaby"] && $this->getAge() >= 0){
$this->setAge(-24000);
}

View file

@ -11,7 +11,7 @@ abstract class Creature extends Living{
public function __construct(Level $level, $eid, $class, $type = 0, $data = []){
$this->inPanic = false; //force for now
parent::__construct($level, $eid, $class, $type, $data);
$this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 1, "generic");
$this->setHealth($this->data["Health"] ?? 1, "generic");
$this->enableAutojump = true;
$this->searchForClosestPlayers = true;
}

View file

@ -141,7 +141,7 @@ class Entity extends Position
$this->isStatic = false;
$this->name = "";
$this->gravity = 0.08;
$this->state = $this->data["State"] = isset($this->data["State"]) ? $this->data["State"] : 0;
$this->state = $this->data["State"] = $this->data["State"] ?? 0;
$this->tickCounter = 0;
$this->x = isset($this->data["x"]) ? (float) $this->data["x"] : 0;
$this->y = isset($this->data["y"]) ? (float) $this->data["y"] : 0;
@ -151,7 +151,7 @@ class Entity extends Position
$this->speedZ = isset($this->data["speedZ"]) ? (float) $this->data["speedZ"] : 0;
$this->speed = 0;
$this->yaw = isset($this->data["yaw"]) ? (float) $this->data["yaw"] : 0;
$this->headYaw = isset($this->data["headYaw"]) ? $this->data["headYaw"] : $this->yaw;
$this->headYaw = $this->data["headYaw"] ?? $this->yaw;
$this->pitch = isset($this->data["pitch"]) ? (float) $this->data["pitch"] : 0;
$this->position = array(
"level" => $this->level,
@ -178,9 +178,9 @@ class Entity extends Position
break;
case ENTITY_OBJECT:
$this->x = isset($this->data["TileX"]) ? $this->data["TileX"] : $this->x;
$this->y = isset($this->data["TileY"]) ? $this->data["TileY"] : $this->y;
$this->z = isset($this->data["TileZ"]) ? $this->data["TileZ"] : $this->z;
$this->x = $this->data["TileX"] ?? $this->x;
$this->y = $this->data["TileY"] ?? $this->y;
$this->z = $this->data["TileZ"] ?? $this->z;
$this->setHealth(1, "generic");
$this->stepHeight = false;
$this->setSize(1, 1);
@ -383,7 +383,7 @@ class Entity extends Position
* @return boolean
*/
public function isPickable(){
return $this->isPlayer() ? !$this->dead : false;
return $this->isPlayer() && !$this->dead;
}
public function handleLavaMovement(){ //TODO maybe try merging with water?
@ -1496,7 +1496,6 @@ class Entity extends Position
{
if($this->class === ENTITY_PLAYER){
$this->player->teleport(new Vector3($this->x, $this->y, $this->z), false, false, true, false);
return;
}
}

View file

@ -51,7 +51,7 @@ class EntityAI
* @return TaskBase | false
*/
public function getTask($id){
return isset($this->tasks[$id]) ? $this->tasks[$id] : false;
return $this->tasks[$id] ?? false;
}
public function isStarted($id){

View file

@ -87,7 +87,7 @@ class TaskAttackPlayer extends TaskBase
}
public function onEnd(EntityAI $ai)
{
{
$ai->entity->target = false;
}

View file

@ -7,7 +7,7 @@ class Chicken extends Animal{
$this->timeUntilEgg = mt_rand(0,6000) + 6000;
$this->setSize(0.4, 0.7);
parent::__construct($level, $eid, $class, $type, $data);
$this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 4, "generic");
$this->setHealth($this->data["Health"] ?? 4, "generic");
$this->setName('Chicken');
$this->setSpeed(0.25);
@ -37,10 +37,6 @@ class Chicken extends Animal{
public function fall(){} //chickens have no fall dmg?
public function update($now){
parent::update($now);
}
public function dropAnEgg(){
if($this->closed){
return;

View file

@ -5,7 +5,7 @@ class Cow extends Animal{
function __construct(Level $level, $eid, $class, $type = 0, $data = []){
$this->setSize(0.9, 1.3);
parent::__construct($level, $eid, $class, $type, $data);
$this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 10, "generic");
$this->setHealth($this->data["Health"] ?? 10, "generic");
$this->setName("Cow");
$this->setSpeed(0.2);
$this->ai->addTask(new TaskRandomWalk(0.8));

View file

@ -5,7 +5,7 @@ class Pig extends Animal implements Rideable{
public function __construct(Level $level, $eid, $class, $type = 0, $data = []){
$this->setSize(0.9, 0.9);
parent::__construct($level, $eid, $class, $type, $data);
$this->setHealth(isset($this->data["Health"]) ? $this->data["Health"]:10, "generic");
$this->setHealth($this->data["Health"] ?? 10, "generic");
$this->server = ServerAPI::request();
$this->setName("Pig");
$this->setSpeed(0.25);

View file

@ -7,10 +7,10 @@ class Sheep extends Animal{
function __construct(Level $level, $eid, $class, $type = 0, $data = []){
$this->setSize(0.9, 1.3);
parent::__construct($level, $eid, $class, $type, $data);
$this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 8, "generic");
$this->setHealth($this->data["Health"] ?? 8, "generic");
$this->setName("Sheep");
$this->data["Sheared"] = isset($this->data["Sheared"]) ? $this->data["Sheared"] : 0;
$this->data["Color"] = isset($this->data["Color"]) ? $this->data["Color"] : $this->sheepColor();
$this->data["Sheared"] = $this->data["Sheared"] ?? 0;
$this->data["Color"] = $this->data["Color"] ?? $this->sheepColor();
$this->setSpeed(0.25);
$this->ai->addTask(new TaskRandomWalk(1.0));

View file

@ -7,7 +7,7 @@ class Creeper extends Monster{
function __construct(Level $level, $eid, $class, $type = 0, $data = []){
$this->setSize(0.6, 1.7);
parent::__construct($level, $eid, $class, $type, $data);
$this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 16, "generic");
$this->setHealth($this->data["Health"] ?? 16, "generic");
$this->setName("Creeper");
$this->ignited = 0;
$this->setSpeed(0.25);

View file

@ -4,7 +4,7 @@ class PigZombie extends Monster{ //TODO extends zombie
function __construct(Level $level, $eid, $class, $type = 0, $data = []){
$this->setSize(0.3, 1.95);
parent::__construct($level, $eid, $class, $type, $data);
$this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 12, "generic");
$this->setHealth($this->data["Health"] ?? 12, "generic");
$this->setName("Pigman");
$this->setSpeed(0.25);
$this->isImmuneToFire = true;

View file

@ -4,7 +4,7 @@ class Skeleton extends Monster{
function __construct(Level $level, $eid, $class, $type = 0, $data = []){
$this->setSize(0.6, 1.99);
parent::__construct($level, $eid, $class, $type, $data);
$this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 10, "generic");
$this->setHealth($this->data["Health"] ?? 10, "generic");
$this->setName("Skeleton");
$this->ai->removeTask("TaskAttackPlayer");
$this->setSpeed(0.25);

View file

@ -5,7 +5,7 @@ class Spider extends Monster{
function __construct(Level $level, $eid, $class, $type = 0, $data = array()){
$this->setSize(1.4, 0.9);
parent::__construct($level, $eid, $class, $type, $data);
$this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 8, "generic");
$this->setHealth($this->data["Health"] ?? 8, "generic");
$this->setName("Spider");
$this->setSpeed(0.3);
$this->ai->addTask(new TaskRandomWalk(1.2));

View file

@ -4,7 +4,7 @@ class Zombie extends Monster{
function __construct(Level $level, $eid, $class, $type = 0, $data = array()){
$this->setSize(0.6, 1.85);
parent::__construct($level, $eid, $class, $type, $data);
$this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 12, "generic");
$this->setHealth($this->data["Health"] ?? 12, "generic");
$this->setName("Zombie");
$this->setSpeed(0.23);

View file

@ -139,7 +139,6 @@ class Arrow extends Entity{
++$this->groundTicks;
if($this->groundTicks >= 1200){ //TODO customizeable?
$this->close();
return;
}
}else{
$this->inGround = false;
@ -278,4 +277,4 @@ class Arrow extends Entity{
$player->dataPacket($pk);
}
}
}
}

View file

@ -59,9 +59,9 @@ class Minecart extends Vehicle{
function __construct(Level $level, $eid, $class, $type = 0, $data = []){
parent::__construct($level, $eid, $class, $type, $data);
$this->canBeAttacked = true;
$this->x = isset($this->data["TileX"]) ? $this->data["TileX"]:$this->x;
$this->y = isset($this->data["TileY"]) ? $this->data["TileY"]:$this->y;
$this->z = isset($this->data["TileZ"]) ? $this->data["TileZ"]:$this->z;
$this->x = $this->data["TileX"] ?? $this->x;
$this->y = $this->data["TileY"] ?? $this->y;
$this->z = $this->data["TileZ"] ?? $this->z;
$this->setHealth(1, "generic"); //orig: 3
$this->setSize(0.98, 0.7);
$this->yOffset = $this->height / 2;

View file

@ -5,9 +5,9 @@ class Painting extends Entity{
const TYPE = OBJECT_PAINTING;
public function __construct(Level $level, $eid, $class, $type = 0, $data = []){
parent::__construct($level, $eid, $class, $type, $data);
$this->x = isset($this->data["TileX"]) ? $this->data["TileX"] : $this->x;
$this->y = isset($this->data["TileY"]) ? $this->data["TileY"] : $this->y;
$this->z = isset($this->data["TileZ"]) ? $this->data["TileZ"] : $this->z;
$this->x = $this->data["TileX"] ?? $this->x;
$this->y = $this->data["TileY"] ?? $this->y;
$this->z = $this->data["TileZ"] ?? $this->z;
$this->setHealth(1, "generic");
$this->canBeAttacked = true;
$this->width = 1;

View file

@ -118,11 +118,7 @@ function arg($name, $default = false){
$arguments = arguments($argv);
}
if(isset($arguments["commands"][$name])){
return $arguments["commands"][$name];
}else{
return $default;
}
return $arguments["commands"][$name] ?? $default;
}
function arguments($args){
@ -144,7 +140,7 @@ function arguments($args){
foreach($args as $arg){
// Is it a command? (prefixed with --)
if(substr($arg, 0, 2) === '--'){
if(str_starts_with($arg, '--')){
$value = preg_split('/[= ]/', $arg, 2);
$com = substr(array_shift($value), 2);
@ -156,13 +152,12 @@ function arguments($args){
}
// Is it a flag? (prefixed with -)
if(substr($arg, 0, 1) === '-'){
if(str_starts_with($arg, '-')){
$ret['flags'][] = substr($arg, 1);
continue;
}
$ret['input'][] = $arg;
continue;
}
@ -180,25 +175,13 @@ function console($message, $EOL = true, $log = true, $level = 1){
if(ENABLE_ANSI === true){
$add = "";
if(preg_match("/\[([a-zA-Z0-9]*)\]/", $message, $matches) > 0){
switch($matches[1]){
case "ERROR":
case "SEVERE":
$add .= FORMAT_RED;
break;
case "INTERNAL":
case "DEBUG":
$add .= FORMAT_WHITE;
break;
case "WARNING":
$add .= FORMAT_YELLOW;
break;
case "NOTICE":
$add .= FORMAT_AQUA;
break;
default:
$add .= FORMAT_GRAY;
break;
}
$add .= match ($matches[1]) {
"ERROR", "SEVERE" => FORMAT_RED,
"INTERNAL", "DEBUG" => FORMAT_WHITE,
"WARNING" => FORMAT_YELLOW,
"NOTICE" => FORMAT_AQUA,
default => FORMAT_GRAY,
};
}
$message = TextFormat::toANSI($time . $add . $message . FORMAT_RESET);
}else{
@ -218,7 +201,7 @@ function getTrace($start = 1){
foreach($trace[$i]["args"] as $name => $value){
$params .= (is_object($value) ? get_class($value) . " " . (method_exists($value, "__toString") ? $value->__toString() : "object") : gettype($value) . " " . @strval($value)) . ", ";
}
$messages[] = "#$j " . (isset($trace[$i]["file"]) ? $trace[$i]["file"] : "") . "(" . (isset($trace[$i]["line"]) ? $trace[$i]["line"] : "") . "): " . (isset($trace[$i]["class"]) ? $trace[$i]["class"] . $trace[$i]["type"] : "") . $trace[$i]["function"] . "(" . substr($params, 0, -2) . ")";
$messages[] = "#$j " . ($trace[$i]["file"] ?? "") . "(" . ($trace[$i]["line"] ?? "") . "): " . (isset($trace[$i]["class"]) ? $trace[$i]["class"] . $trace[$i]["type"] : "") . $trace[$i]["function"] . "(" . substr($params, 0, -2) . ")";
}
return $messages;
}
@ -244,7 +227,7 @@ function error_handler($errno, $errstr, $errfile, $errline){
E_DEPRECATED => "E_DEPRECATED",
E_USER_DEPRECATED => "E_USER_DEPRECATED",
];
$errno = isset($errorConversion[$errno]) ? $errorConversion[$errno] : $errno;
$errno = $errorConversion[$errno] ?? $errno;
console("[ERROR] A " . $errno . " error happened: \"$errstr\" in \"$errfile\" at line $errline", true, true, 0);
foreach(getTrace() as $i => $line){
console("[TRACE] $line");

View file

@ -163,15 +163,15 @@ abstract class Block extends Position{
}
public static function containsX($id, $v){
return $v == null ? false : $v->y >= StaticBlock::$minYs[$id] && $v->y <= StaticBlock::$maxYs[$id] && $v->z >= StaticBlock::$minZs[$id] && $v->z <= StaticBlock::$maxZs[$id];
return !($v == null) && $v->y >= StaticBlock::$minYs[$id] && $v->y <= StaticBlock::$maxYs[$id] && $v->z >= StaticBlock::$minZs[$id] && $v->z <= StaticBlock::$maxZs[$id];
}
public static function containsY($id, $v){
return $v == null ? false : $v->x >= StaticBlock::$minXs[$id] && $v->x <= StaticBlock::$maxXs[$id] && $v->z >= StaticBlock::$minZs[$id] && $v->z <= StaticBlock::$maxZs[$id];
return !($v == null) && $v->x >= StaticBlock::$minXs[$id] && $v->x <= StaticBlock::$maxXs[$id] && $v->z >= StaticBlock::$minZs[$id] && $v->z <= StaticBlock::$maxZs[$id];
}
public static function containsZ($id, $v){
return $v == null ? false : $v->x >= StaticBlock::$minXs[$id] && $v->x <= StaticBlock::$maxXs[$id] && $v->y >= StaticBlock::$minYs[$id] && $v->y <= StaticBlock::$maxYs[$id];
return !($v == null) && $v->x >= StaticBlock::$minXs[$id] && $v->x <= StaticBlock::$maxXs[$id] && $v->y >= StaticBlock::$minYs[$id] && $v->y <= StaticBlock::$maxYs[$id];
}
public static function updateShape(Level $level, $x, $y, $z){

View file

@ -259,20 +259,14 @@ class Item{
//TODO remove?
public function getPickaxeLevel(){ //Returns false or level of the pickaxe
switch($this->id){
case WOODEN_PICKAXE:
return 1;
case GOLDEN_PICKAXE:
return 2;
case STONE_PICKAXE:
return 3;
case IRON_PICKAXE:
return 4;
case DIAMOND_PICKAXE:
return 5;
default:
return false;
}
return match ($this->id) {
WOODEN_PICKAXE => 1,
GOLDEN_PICKAXE => 2,
STONE_PICKAXE => 3,
IRON_PICKAXE => 4,
DIAMOND_PICKAXE => 5,
default => false,
};
}
public function isAxe(){

View file

@ -80,7 +80,7 @@ class StairBlock extends TransparentBlock{
for($v15 = 0; $v15 < /*count($v11}*/ 2; ++$v15){
$v16 = $v11[$v15];
if($v16 == $v12){
; //wat
//wat
}
}
@ -360,4 +360,4 @@ class StairBlock extends TransparentBlock{
return array();
}
}
}
}

View file

@ -11,21 +11,15 @@ class IronDoorBlock extends DoorBlock{
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
switch($item->getPickaxeLevel()){
case 5:
return 0.95;
case 4:
return 1.25;
case 3:
return 1.9;
case 2:
return 0.65;
case 1:
return 3.75;
default:
return 25;
}
return match ($item->getPickaxeLevel()) {
5 => 0.95,
4 => 1.25,
3 => 1.9,
2 => 0.65,
1 => 3.75,
default => 25,
};
}
public function getDrops(Item $item, Player $player){

View file

@ -93,21 +93,15 @@ class SlabBlock extends TransparentBlock{
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
switch($item->getPickaxeLevel()){
case 5:
return 0.4;
case 4:
return 0.5;
case 3:
return 0.75;
case 2:
return 0.25;
case 1:
return 1.5;
default:
return 10;
}
return match ($item->getPickaxeLevel()) {
5 => 0.4,
4 => 0.5,
3 => 0.75,
2 => 0.25,
1 => 1.5,
default => 10,
};
}
public function getDrops(Item $item, Player $player){
@ -119,4 +113,4 @@ class SlabBlock extends TransparentBlock{
return array();
}
}
}
}

View file

@ -89,21 +89,15 @@ class WoodSlabBlock extends TransparentBlock{
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
switch($item->isAxe()){
case 5:
return 0.4;
case 4:
return 0.5;
case 3:
return 0.75;
case 2:
return 0.25;
case 1:
return 1.5;
default:
return 3;
}
return match ($item->isAxe()) {
5 => 0.4,
4 => 0.5,
3 => 0.75,
2 => 0.25,
1 => 1.5,
default => 3,
};
}
public function getDrops(Item $item, Player $player){
@ -111,4 +105,4 @@ class WoodSlabBlock extends TransparentBlock{
array($this->id, $this->meta & 0x07, 1),
);
}
}
}

View file

@ -9,21 +9,15 @@ class WoodStairsBlock extends StairBlock{
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
switch($item->isAxe()){
case 5:
return 0.4;
case 4:
return 0.5;
case 3:
return 0.75;
case 2:
return 0.25;
case 1:
return 1.5;
default:
return 3;
}
return match ($item->isAxe()) {
5 => 0.4,
4 => 0.5,
3 => 0.75,
2 => 0.25,
1 => 1.5,
default => 3,
};
}
public function getDrops(Item $item, Player $player){
@ -31,4 +25,4 @@ class WoodStairsBlock extends StairBlock{
array($this->id, 0, 1),
);
}
}
}

View file

@ -10,21 +10,15 @@ class CoalOreBlock extends SolidBlock{
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
switch($item->getPickaxeLevel()){
case 5:
return 0.6;
case 4:
return 0.75;
case 3:
return 1.15;
case 2:
return 0.4;
case 1:
return 2.25;
default:
return 15;
}
return match ($item->getPickaxeLevel()) {
5 => 0.6,
4 => 0.75,
3 => 1.15,
2 => 0.4,
1 => 2.25,
default => 15,
};
}
public function getDrops(Item $item, Player $player){
@ -37,4 +31,4 @@ class CoalOreBlock extends SolidBlock{
}
}
}
}

View file

@ -10,15 +10,12 @@ class DiamondOreBlock extends SolidBlock{
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
switch($item->getPickaxeLevel()){
case 5:
return 0.6;
case 4:
return 0.75;
default:
return 15;
}
return match ($item->getPickaxeLevel()) {
5 => 0.6,
4 => 0.75,
default => 15,
};
}
public function getDrops(Item $item, Player $player){
@ -30,4 +27,4 @@ class DiamondOreBlock extends SolidBlock{
return array();
}
}
}
}

View file

@ -18,15 +18,12 @@ class GlowingRedstoneOreBlock extends SolidBlock implements LightingBlock{
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
switch($item->getPickaxeLevel()){
case 5:
return 0.6;
case 4:
return 0.75;
default:
return 15;
}
return match ($item->getPickaxeLevel()) {
5 => 0.6,
4 => 0.75,
default => 15,
};
}
public function getDrops(Item $item, Player $player){
@ -39,4 +36,4 @@ class GlowingRedstoneOreBlock extends SolidBlock implements LightingBlock{
}
}
}
}

View file

@ -10,15 +10,12 @@ class GoldOreBlock extends SolidBlock{
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
switch($item->getPickaxeLevel()){
case 5:
return 0.6;
case 4:
return 0.75;
default:
return 15;
}
return match ($item->getPickaxeLevel()) {
5 => 0.6,
4 => 0.75,
default => 15,
};
}
public function getDrops(Item $item, Player $player){
@ -30,4 +27,4 @@ class GoldOreBlock extends SolidBlock{
return array();
}
}
}
}

View file

@ -10,17 +10,13 @@ class IronOreBlock extends SolidBlock{
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
switch($item->getPickaxeLevel()){
case 5:
return 0.6;
case 4:
return 0.75;
case 3:
return 1.15;
default:
return 15;
}
return match ($item->getPickaxeLevel()) {
5 => 0.6,
4 => 0.75,
3 => 1.15,
default => 15,
};
}
public function getDrops(Item $item, Player $player){
@ -32,4 +28,4 @@ class IronOreBlock extends SolidBlock{
return array();
}
}
}
}

View file

@ -10,17 +10,13 @@ class LapisOreBlock extends SolidBlock{
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
switch($item->getPickaxeLevel()){
case 5:
return 0.6;
case 4:
return 0.75;
case 3:
return 1.15;
default:
return 15;
}
return match ($item->getPickaxeLevel()) {
5 => 0.6,
4 => 0.75,
3 => 1.15,
default => 15,
};
}
public function getDrops(Item $item, Player $player){
@ -33,4 +29,4 @@ class LapisOreBlock extends SolidBlock{
}
}
}
}

View file

@ -10,21 +10,15 @@ class BricksBlock extends SolidBlock{
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
switch($item->getPickaxeLevel()){
case 5:
return 0.4;
case 4:
return 0.5;
case 3:
return 0.75;
case 2:
return 0.25;
case 1:
return 1.5;
default:
return 10;
}
return match ($item->getPickaxeLevel()) {
5 => 0.4,
4 => 0.5,
3 => 0.75,
2 => 0.25,
1 => 1.5,
default => 10,
};
}
public function getDrops(Item $item, Player $player){
@ -36,4 +30,4 @@ class BricksBlock extends SolidBlock{
return array();
}
}
}
}

View file

@ -55,21 +55,15 @@ class BurningFurnaceBlock extends SolidBlock implements LightingBlock{
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
switch($item->getPickaxeLevel()){
case 5:
return 0.7;
case 4:
return 0.9;
case 3:
return 1.35;
case 2:
return 0.45;
case 1:
return 2.65;
default:
return 17.5;
}
return match ($item->getPickaxeLevel()) {
5 => 0.7,
4 => 0.9,
3 => 1.35,
2 => 0.45,
1 => 2.65,
default => 17.5,
};
}
public function getDrops(Item $item, Player $player){
@ -88,4 +82,4 @@ class BurningFurnaceBlock extends SolidBlock implements LightingBlock{
}
return $drops;
}
}
}

View file

@ -10,21 +10,15 @@ class CoalBlock extends SolidBlock{
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
switch($item->getPickaxeLevel()){
case 5:
return 0.95;
case 4:
return 1.25;
case 3:
return 1.9;
case 2:
return 0.65;
case 1:
return 3.75;
default:
return 25;
}
return match ($item->getPickaxeLevel()) {
5 => 0.95,
4 => 1.25,
3 => 1.9,
2 => 0.65,
1 => 3.75,
default => 25,
};
}
public function getDrops(Item $item, Player $player){
@ -36,4 +30,4 @@ class CoalBlock extends SolidBlock{
return array();
}
}
}
}

View file

@ -10,21 +10,15 @@ class CobblestoneBlock extends SolidBlock{
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
switch($item->getPickaxeLevel()){
case 5:
return 0.4;
case 4:
return 0.5;
case 3:
return 0.75;
case 2:
return 0.25;
case 1:
return 1.5;
default:
return 10;
}
return match ($item->getPickaxeLevel()) {
5 => 0.4,
4 => 0.5,
3 => 0.75,
2 => 0.25,
1 => 1.5,
default => 10,
};
}
public function getDrops(Item $item, Player $player){
@ -36,4 +30,4 @@ class CobblestoneBlock extends SolidBlock{
return array();
}
}
}
}

View file

@ -10,15 +10,12 @@ class DiamondBlock extends SolidBlock{
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
switch($item->getPickaxeLevel()){
case 5:
return 0.95;
case 4:
return 1.25;
default:
return 25;
}
return match ($item->getPickaxeLevel()) {
5 => 0.95,
4 => 1.25,
default => 25,
};
}
public function getDrops(Item $item, Player $player){
@ -30,4 +27,4 @@ class DiamondBlock extends SolidBlock{
return array();
}
}
}
}

View file

@ -21,21 +21,15 @@ class DoubleSlabBlock extends SolidBlock{
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
switch($item->getPickaxeLevel()){
case 5:
return 0.4;
case 4:
return 0.5;
case 3:
return 0.75;
case 2:
return 0.25;
case 1:
return 1.5;
default:
return 10;
}
return match ($item->getPickaxeLevel()) {
5 => 0.4,
4 => 0.5,
3 => 0.75,
2 => 0.25,
1 => 1.5,
default => 10,
};
}
public function getDrops(Item $item, Player $player){

View file

@ -17,21 +17,15 @@ class DoubleWoodSlabBlock extends SolidBlock{
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
switch($item->isAxe()){
case 5:
return 0.4;
case 4:
return 0.5;
case 3:
return 0.75;
case 2:
return 0.25;
case 1:
return 1.5;
default:
return 3;
}
return match ($item->isAxe()) {
5 => 0.4,
4 => 0.5,
3 => 0.75,
2 => 0.25,
1 => 1.5,
default => 3,
};
}
public function getDrops(Item $item, Player $player){
@ -40,4 +34,4 @@ class DoubleWoodSlabBlock extends SolidBlock{
);
}
}
}

View file

@ -10,15 +10,12 @@ class GoldBlock extends SolidBlock{
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
switch($item->getPickaxeLevel()){
case 5:
return 0.6;
case 4:
return 0.75;
default:
return 15;
}
return match ($item->getPickaxeLevel()) {
5 => 0.6,
4 => 0.75,
default => 15,
};
}
public function getDrops(Item $item, Player $player){
@ -30,4 +27,4 @@ class GoldBlock extends SolidBlock{
return array();
}
}
}
}

View file

@ -45,7 +45,6 @@ class GrassBlock extends SolidBlock{
ServerAPI::request()->api->entity->drop(new Position($this->x+0.5, $this->y+1, $this->z+0.5, $this->level), BlockAPI::getItem(295,0,1));
return;
}
return;
}
public static function onRandomTick(Level $level, $x, $y, $z){
if(!StaticBlock::getIsTransparent($level->level->getBlockID($x, $y + 1, $z)) && mt_rand(0, 2) == 1){
@ -65,4 +64,4 @@ class GrassBlock extends SolidBlock{
}
}
}
}

View file

@ -57,21 +57,15 @@ class IceBlock extends TransparentBlock{
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
switch($item->getPickaxeLevel()){
case 5:
return 0.1;
case 4:
return 0.15;
case 3:
return 0.2;
case 2:
return 0.1;
case 1:
return 0.4;
default:
return 0.75;
}
return match ($item->getPickaxeLevel()) {
5 => 0.1,
4 => 0.15,
3 => 0.2,
2 => 0.1,
1 => 0.4,
default => 0.75,
};
}
public function getDrops(Item $item, Player $player){

View file

@ -10,17 +10,13 @@ class IronBlock extends SolidBlock{
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
switch($item->getPickaxeLevel()){
case 5:
return 0.95;
case 4:
return 1.25;
case 3:
return 1.9;
default:
return 25;
}
return match ($item->getPickaxeLevel()) {
5 => 0.95,
4 => 1.25,
3 => 1.9,
default => 25,
};
}
public function getDrops(Item $item, Player $player){
@ -32,4 +28,4 @@ class IronBlock extends SolidBlock{
return array();
}
}
}
}

View file

@ -10,17 +10,13 @@ class LapisBlock extends SolidBlock{
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
switch($item->getPickaxeLevel()){
case 5:
return 0.6;
case 4:
return 0.75;
case 3:
return 1.15;
default:
return 15;
}
return match ($item->getPickaxeLevel()) {
5 => 0.6,
4 => 0.75,
3 => 1.15,
default => 15,
};
}
public function getDrops(Item $item, Player $player){
@ -33,4 +29,4 @@ class LapisBlock extends SolidBlock{
}
}
}
}

View file

@ -10,21 +10,15 @@ class MossStoneBlock extends SolidBlock{
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
switch($item->getPickaxeLevel()){
case 5:
return 0.4;
case 4:
return 0.5;
case 3:
return 0.75;
case 2:
return 0.25;
case 1:
return 1.5;
default:
return 10;
}
return match ($item->getPickaxeLevel()) {
5 => 0.4,
4 => 0.5,
3 => 0.75,
2 => 0.25,
1 => 1.5,
default => 10,
};
}
public function getDrops(Item $item, Player $player){
@ -36,4 +30,4 @@ class MossStoneBlock extends SolidBlock{
return array();
}
}
}
}

View file

@ -10,21 +10,15 @@ class NetherBricksBlock extends SolidBlock{
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
switch($item->getPickaxeLevel()){
case 5:
return 0.4;
case 4:
return 0.5;
case 3:
return 0.75;
case 2:
return 0.25;
case 1:
return 1.5;
default:
return 10;
}
return match ($item->getPickaxeLevel()) {
5 => 0.4,
4 => 0.5,
3 => 0.75,
2 => 0.25,
1 => 1.5,
default => 10,
};
}
public function getDrops(Item $item, Player $player){
@ -36,4 +30,4 @@ class NetherBricksBlock extends SolidBlock{
return array();
}
}
}
}

View file

@ -10,21 +10,15 @@ class NetherrackBlock extends SolidBlock{
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
switch($item->getPickaxeLevel()){
case 5:
return 0.1;
case 4:
return 0.1;
case 3:
return 0.15;
case 2:
return 0.05;
case 1:
return 0.3;
default:
return 2;
}
return match ($item->getPickaxeLevel()) {
5 => 0.1,
4 => 0.1,
3 => 0.15,
2 => 0.05,
1 => 0.3,
default => 2,
};
}
public function getDrops(Item $item, Player $player){
@ -36,4 +30,4 @@ class NetherrackBlock extends SolidBlock{
return array();
}
}
}
}

View file

@ -16,21 +16,15 @@ class QuartzBlock extends SolidBlock{
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
switch($item->getPickaxeLevel()){
case 5:
return 0.15;
case 4:
return 0.2;
case 3:
return 0.3;
case 2:
return 0.1;
case 1:
return 0.6;
default:
return 4;
}
return match ($item->getPickaxeLevel()) {
5 => 0.15,
4 => 0.2,
3 => 0.3,
2 => 0.1,
1 => 0.6,
default => 4,
};
}
public function getDrops(Item $item, Player $player){
@ -42,4 +36,4 @@ class QuartzBlock extends SolidBlock{
return array();
}
}
}
}

View file

@ -16,21 +16,15 @@ class SandstoneBlock extends SolidBlock{
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
switch($item->getPickaxeLevel()){
case 5:
return 0.15;
case 4:
return 0.2;
case 3:
return 0.3;
case 2:
return 0.1;
case 1:
return 0.6;
default:
return 4;
}
return match ($item->getPickaxeLevel()) {
5 => 0.15,
4 => 0.2,
3 => 0.3,
2 => 0.1,
1 => 0.6,
default => 4,
};
}
public function getDrops(Item $item, Player $player){
@ -43,4 +37,4 @@ class SandstoneBlock extends SolidBlock{
}
}
}
}

View file

@ -10,21 +10,15 @@ class StoneBlock extends SolidBlock{
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
switch($item->getPickaxeLevel()){
case 5:
return 0.4;
case 4:
return 0.5;
case 3:
return 0.75;
case 2:
return 0.25;
case 1:
return 1.5;
default:
return 7.5;
}
return match ($item->getPickaxeLevel()) {
5 => 0.4,
4 => 0.5,
3 => 0.75,
2 => 0.25,
1 => 1.5,
default => 7.5,
};
}
public function getDrops(Item $item, Player $player){
@ -37,4 +31,4 @@ class StoneBlock extends SolidBlock{
}
}
}
}

View file

@ -17,21 +17,15 @@ class StoneBricksBlock extends SolidBlock{
public function getBreakTime(Item $item, Player $player){
if(($player->gamemode & 0x01) === 0x01){
return 0.20;
}
switch($item->getPickaxeLevel()){
case 5:
return 0.4;
case 4:
return 0.5;
case 3:
return 0.75;
case 2:
return 0.25;
case 1:
return 1.5;
default:
return 7.5;
}
return match ($item->getPickaxeLevel()) {
5 => 0.4,
4 => 0.5,
3 => 0.75,
2 => 0.25,
1 => 1.5,
default => 7.5,
};
}
public function getDrops(Item $item, Player $player){
@ -44,4 +38,4 @@ class StoneBricksBlock extends SolidBlock{
}
}
}
}

View file

@ -7,20 +7,14 @@ abstract class ItemAxe extends ItemTool
}
public function getLevel(){
switch($this->id){
case WOODEN_AXE:
return 1;
case GOLDEN_AXE:
return 2;
case STONE_AXE:
return 3;
case IRON_AXE:
return 4;
case DIAMOND_AXE:
return 5;
default:
return false;
}
return match ($this->id) {
WOODEN_AXE => 1,
GOLDEN_AXE => 2,
STONE_AXE => 3,
IRON_AXE => 4,
DIAMOND_AXE => 5,
default => false,
};
}
}

View file

@ -16,20 +16,14 @@ abstract class ItemHoe extends ItemTool
}
public function getLevel(){
switch($this->id){
case WOODEN_HOE:
return 1;
case GOLDEN_HOE:
return 2;
case STONE_HOE:
return 3;
case IRON_HOE:
return 4;
case DIAMOND_HOE:
return 5;
default:
return false;
}
return match ($this->id) {
WOODEN_HOE => 1,
GOLDEN_HOE => 2,
STONE_HOE => 3,
IRON_HOE => 4,
DIAMOND_HOE => 5,
default => false,
};
}
}

View file

@ -12,20 +12,14 @@ abstract class ItemPickaxe extends ItemTool
}
public function getLevel(){
switch($this->id){
case WOODEN_PICKAXE:
return 1;
case GOLDEN_PICKAXE:
return 2;
case STONE_PICKAXE:
return 3;
case IRON_PICKAXE:
return 4;
case DIAMOND_PICKAXE:
return 5;
default:
return false;
}
return match ($this->id) {
WOODEN_PICKAXE => 1,
GOLDEN_PICKAXE => 2,
STONE_PICKAXE => 3,
IRON_PICKAXE => 4,
DIAMOND_PICKAXE => 5,
default => false,
};
}
}

View file

@ -7,20 +7,14 @@ class ItemShovel extends ItemTool
}
public function getLevel(){
switch($this->id){
case WOODEN_SHOVEL:
return 1;
case GOLDEN_SHOVEL:
return 2;
case STONE_SHOVEL:
return 3;
case IRON_SHOVEL:
return 4;
case DIAMOND_SHOVEL:
return 5;
default:
return false;
}
return match ($this->id) {
WOODEN_SHOVEL => 1,
GOLDEN_SHOVEL => 2,
STONE_SHOVEL => 3,
IRON_SHOVEL => 4,
DIAMOND_SHOVEL => 5,
default => false,
};
}
}

View file

@ -8,20 +8,14 @@ abstract class ItemSword extends ItemTool
}
public function getLevel(){
switch($this->id){
case WOODEN_SWORD:
return 1;
case GOLDEN_SWORD:
return 2;
case STONE_SWORD:
return 3;
case IRON_SWORD:
return 4;
case DIAMOND_SWORD:
return 5;
default:
return false;
}
return match ($this->id) {
WOODEN_SWORD => 1,
GOLDEN_SWORD => 2,
STONE_SWORD => 3,
IRON_SWORD => 4,
DIAMOND_SWORD => 5,
default => false,
};
}
}

View file

@ -16,7 +16,7 @@ class Matrix implements ArrayAccess{
for($r = 0; $r < $this->rows; ++$r){
$this->matrix[$r] = [];
for($c = 0; $c < $this->columns; ++$c){
$this->matrix[$r][$c] = isset($m[$r][$c]) ? $m[$r][$c] : 0;
$this->matrix[$r][$c] = $m[$r][$c] ?? 0;
}
}
}
@ -140,15 +140,12 @@ class Matrix implements ArrayAccess{
if($this->isSquare() !== true){
return false;
}
switch($this->rows){
case 1:
return 0;
case 2:
return $this->matrix[0][0] * $this->matrix[1][1] - $this->matrix[0][1] * $this->matrix[1][0];
case 3:
return $this->matrix[0][0] * $this->matrix[1][1] * $this->matrix[2][2] + $this->matrix[0][1] * $this->matrix[1][2] * $this->matrix[2][0] + $this->matrix[0][2] * $this->matrix[1][0] * $this->matrix[2][1] - $this->matrix[2][0] * $this->matrix[1][1] * $this->matrix[0][2] - $this->matrix[2][1] * $this->matrix[1][2] * $this->matrix[0][0] - $this->matrix[2][2] * $this->matrix[1][0] * $this->matrix[0][1];
}
return false;
return match ($this->rows) {
1 => 0,
2 => $this->matrix[0][0] * $this->matrix[1][1] - $this->matrix[0][1] * $this->matrix[1][0],
3 => $this->matrix[0][0] * $this->matrix[1][1] * $this->matrix[2][2] + $this->matrix[0][1] * $this->matrix[1][2] * $this->matrix[2][0] + $this->matrix[0][2] * $this->matrix[1][0] * $this->matrix[2][1] - $this->matrix[2][0] * $this->matrix[1][1] * $this->matrix[0][2] - $this->matrix[2][1] * $this->matrix[1][2] * $this->matrix[0][0] - $this->matrix[2][2] * $this->matrix[1][0] * $this->matrix[0][1],
default => false,
};
}
@ -166,4 +163,4 @@ class Matrix implements ArrayAccess{
return "Matrix({$this->rows}x{$this->columns};" . substr($s, 0, -1) . ")";
}
}
}

View file

@ -104,22 +104,15 @@ class Vector3{
}
public function getSide($side, $step = 1){
switch((int) $side){
case 0:
return new Vector3($this->x, $this->y - $step, $this->z);
case 1:
return new Vector3($this->x, $this->y + $step, $this->z);
case 2:
return new Vector3($this->x, $this->y, $this->z - $step);
case 3:
return new Vector3($this->x, $this->y, $this->z + $step);
case 4:
return new Vector3($this->x - $step, $this->y, $this->z);
case 5:
return new Vector3($this->x + $step, $this->y, $this->z);
default:
return $this;
}
return match ((int)$side) {
0 => new Vector3($this->x, $this->y - $step, $this->z),
1 => new Vector3($this->x, $this->y + $step, $this->z),
2 => new Vector3($this->x, $this->y, $this->z - $step),
3 => new Vector3($this->x, $this->y, $this->z + $step),
4 => new Vector3($this->x - $step, $this->y, $this->z),
5 => new Vector3($this->x + $step, $this->y, $this->z),
default => $this,
};
}
public function distance($x = 0, $y = 0, $z = 0){
@ -277,4 +270,4 @@ class Vector3{
public function getIntermediateWithZValue(Vector3 $v, $y){
return $this->clipZ($v, $y);
}
}
}

View file

@ -15,7 +15,7 @@ class SetTimePacket extends RakNetDataPacket{
public function encode(){
$this->reset();
$this->putInt($this->time);
$this->putByte($this->started == true ? 0x80:0x00);
$this->putByte($this->started ? 0x80:0x00);
}
}

View file

@ -39,7 +39,7 @@ class QueryHandler{
public function regenerateInfo(){
$str = "";
$plist = "NostalgiaCore " . MAJOR_VERSION;
if($this->server->extraprops->get("query-plugins") == true){
if($this->server->extraprops->get("query-plugins")){
$pl = $this->server->api->plugin->getList();
if(count($pl) > 0){
$plist .= ":";

View file

@ -38,37 +38,9 @@ abstract class RakNetInfo{
const ACK = 0xc0;
public static function isValid($pid){
switch((int) $pid){
case RakNetInfo::UNCONNECTED_PING:
case RakNetInfo::UNCONNECTED_PING_OPEN_CONNECTIONS:
case RakNetInfo::OPEN_CONNECTION_REQUEST_1:
case RakNetInfo::OPEN_CONNECTION_REPLY_1:
case RakNetInfo::OPEN_CONNECTION_REQUEST_2:
case RakNetInfo::OPEN_CONNECTION_REPLY_2:
case RakNetInfo::INCOMPATIBLE_PROTOCOL_VERSION:
case RakNetInfo::UNCONNECTED_PONG:
case RakNetInfo::ADVERTISE_SYSTEM:
case RakNetInfo::DATA_PACKET_0:
case RakNetInfo::DATA_PACKET_1:
case RakNetInfo::DATA_PACKET_2:
case RakNetInfo::DATA_PACKET_3:
case RakNetInfo::DATA_PACKET_4:
case RakNetInfo::DATA_PACKET_5:
case RakNetInfo::DATA_PACKET_6:
case RakNetInfo::DATA_PACKET_7:
case RakNetInfo::DATA_PACKET_8:
case RakNetInfo::DATA_PACKET_9:
case RakNetInfo::DATA_PACKET_A:
case RakNetInfo::DATA_PACKET_B:
case RakNetInfo::DATA_PACKET_C:
case RakNetInfo::DATA_PACKET_D:
case RakNetInfo::DATA_PACKET_E:
case RakNetInfo::DATA_PACKET_F:
case RakNetInfo::NACK:
case RakNetInfo::ACK:
return true;
default:
return false;
}
return match ((int)$pid) {
RakNetInfo::UNCONNECTED_PING, RakNetInfo::UNCONNECTED_PING_OPEN_CONNECTIONS, RakNetInfo::OPEN_CONNECTION_REQUEST_1, RakNetInfo::OPEN_CONNECTION_REPLY_1, RakNetInfo::OPEN_CONNECTION_REQUEST_2, RakNetInfo::OPEN_CONNECTION_REPLY_2, RakNetInfo::INCOMPATIBLE_PROTOCOL_VERSION, RakNetInfo::UNCONNECTED_PONG, RakNetInfo::ADVERTISE_SYSTEM, RakNetInfo::DATA_PACKET_0, RakNetInfo::DATA_PACKET_1, RakNetInfo::DATA_PACKET_2, RakNetInfo::DATA_PACKET_3, RakNetInfo::DATA_PACKET_4, RakNetInfo::DATA_PACKET_5, RakNetInfo::DATA_PACKET_6, RakNetInfo::DATA_PACKET_7, RakNetInfo::DATA_PACKET_8, RakNetInfo::DATA_PACKET_9, RakNetInfo::DATA_PACKET_A, RakNetInfo::DATA_PACKET_B, RakNetInfo::DATA_PACKET_C, RakNetInfo::DATA_PACKET_D, RakNetInfo::DATA_PACKET_E, RakNetInfo::DATA_PACKET_F, RakNetInfo::NACK, RakNetInfo::ACK => true,
default => false,
};
}
}
}

View file

@ -143,7 +143,7 @@ class RakNetParser{
$orderChannel = false;
}
if($hasSplit == true){
if($hasSplit){
$splitCount = $this->getInt();
$splitID = $this->getShort();
$splitIndex = $this->getInt();

View file

@ -3,7 +3,7 @@
class CraftingRecipes{
private static $small = [ // Probably means craftable on crafting bench and in inventory. Name it better!
// Building
// Building
"CLAY:?x4=>CLAY_BLOCK:0x1",
"WOODEN_PLANKS:?x4=>WORKBENCH:0x1",
"GLOWSTONE_DUST:?x4=>GLOWSTONE_BLOCK:0x1",
@ -73,7 +73,7 @@ class CraftingRecipes{
];
private static $big = [ // Probably means only craftable on crafting bench. Name it better!
// Building
// Building
"WOOL:?x3,WOODEN_PLANKS:?x3=>BED:0x1",
"WOODEN_PLANKS:?x8=>CHEST:0x1",
"STICK:?x6=>FENCE:0x2",

View file

@ -26,7 +26,7 @@ abstract class Structure{
$this->mapSymToID[$sym] = $id;
}
public function getMappingFor($sym){
return isset($this->mapSymToID[$sym]) ? $this->mapSymToID[$sym] : Structure::MAP_NO_KEY;
return $this->mapSymToID[$sym] ?? Structure::MAP_NO_KEY;
}
protected function placeBlock($level, $sym, $tv){

View file

@ -15,6 +15,6 @@ class LightUtils{
$diffZ = ($source->z - $block->z);
$distance = $diffX*$diffX + $diffY*$diffY + $diffZ*$diffZ;
$result = floor($source->getMaxLightValue() - $distance);
return $result <= 0 ? 0 : $result;
return max($result, 0);
}
}

View file

@ -125,7 +125,7 @@ class MersenneTwister{
$this->init_with_integer(19650218);
$i = 1;
$j = 0;
$k = (N > $key_length ? N : $key_length);
$k = (max(N, $key_length));
for(; $k; $k--){
$mt[$i] = add_3($mt[$i] ^
mul_by_1664525($mt[$i - 1] ^ (($mt[$i - 1] >> 30) & 3)),

View file

@ -63,7 +63,7 @@ class RailLogic
}
public function canConnectTo(RailLogic $rail){
return $this->connectsTo($rail) ? true : (count($this->railPositions) == 2 ? false : (empty($this->railPositions) ? true : true));
return $this->connectsTo($rail) || ((count($this->railPositions) == 2 ? false : (empty($this->railPositions) ? true : true)));
}
public function hasNeighborRail($x, $y, $z){

View file

@ -4,7 +4,7 @@ class StopMessageThread extends Thread
{
private $page, $msg;
public function __construct(PocketMinecraftServer $server, $msg){
if($server->extraprops->get("discord-msg") == true and ($this->page = $server->extraprops->get("discord-webhook-url")) !== "none"){
if($server->extraprops->get("discord-msg") and ($this->page = $server->extraprops->get("discord-webhook-url")) !== "none"){
$this->msg = $server->extraprops->get("discord-ru-smiles") ? str_replace("@", " ", str_replace("Ы", "<:ru_cool:960113011383738369>", str_replace("Ь", "<:ru_cry:960112920346390548>", str_replace("Ъ", "<:ru_happy:960112868601237504>", $msg)))) : str_replace("@", "", $msg);
$this->name = $server->extraprops->get("discord-bot-name");
$this->start();

View file

@ -14,29 +14,12 @@ class Utils{
}*/
const emojiRegex = "([*#0-9](?>\\xEF\\xB8\\x8F)?\\xE2\\x83\\xA3|\\xC2[\\xA9\\xAE]|\\xE2..(\\xF0\\x9F\\x8F[\\xBB-\\xBF])?(?>\\xEF\\xB8\\x8F)?|\\xE3(?>\\x80[\\xB0\\xBD]|\\x8A[\\x97\\x99])(?>\\xEF\\xB8\\x8F)?|\\xF0\\x9F(?>[\\x80-\\x86].(?>\\xEF\\xB8\\x8F)?|\\x87.\\xF0\\x9F\\x87.|..(\\xF0\\x9F\\x8F[\\xBB-\\xBF])?|(((?<zwj>\\xE2\\x80\\x8D)\\xE2\\x9D\\xA4\\xEF\\xB8\\x8F\k<zwj>\\xF0\\x9F..(\k<zwj>\\xF0\\x9F\\x91.)?|(\\xE2\\x80\\x8D\\xF0\\x9F\\x91.){2,3}))?))";
public static function getEntityTypeByID($id){
switch($id){
case 10:
case 11:
case 12:
case 13:
case 32:
case 33:
case 34:
case 35:
case 36:
return ENTITY_MOB;
case 62:
case 65:
case 80:
case 81:
case 82:
case 83:
case 84:
return ENTITY_OBJECT;
case 66:
return FALLING_SAND;
}
return $id;
return match ($id) {
10, 11, 12, 13, 32, 33, 34, 35, 36 => ENTITY_MOB,
62, 65, 80, 81, 82, 83, 84 => ENTITY_OBJECT,
66 => FALLING_SAND,
default => $id,
};
}
public static function wrapAngleTo360($angle)
@ -87,7 +70,7 @@ class Utils{
* PHP8 has internal function for doing it: {@link str_ends_with}
*/
public static function endsWith($str, $check) {
return substr($str, -strlen($check)) === $check;
return str_ends_with($str, $check);
}
public static function hasEmoji($s){
@ -148,7 +131,7 @@ class Utils{
public static function getOS(){
$uname = php_uname("s");
if(stripos($uname, "Darwin") !== false){
if(strpos(php_uname("m"), "iP") === 0){
if(str_starts_with(php_uname("m"), "iP")){
return "ios";
}else{
return "mac";
@ -581,7 +564,7 @@ class Utils{
}
public static function readBool($b){
return Utils::readByte($b, false) === 0 ? false : true;
return Utils::readByte($b, false) != 0;
}
public static function writeBool($b){

View file

@ -376,7 +376,7 @@ class Level{
if(count($this->players) == 0) return false;
if($this->server->api->time->getPhase($this) === "night"){ //TODO vanilla
foreach($this->players as $p){
if($p->isSleeping == false || $p->sleepingTime < 100){
if(!$p->isSleeping || $p->sleepingTime < 100){
return false;
}
}
@ -906,7 +906,7 @@ class Level{
return false;
}
$now = microtime(true);
if($this->stopTime == true){
if($this->stopTime){
$time = $this->startTime;
}else{
$time = $this->startTime + ($now - $this->startCheck) * 20;

View file

@ -133,8 +133,8 @@ class MobSpawner{
$b1 = $this->level->level->getBlockID($x, $y - 1, $z);
if(
!StaticBlock::getIsSolid($b) && !StaticBlock::getIsLiquid($b) &&
(StaticBlock::getIsSolid($b1) && ($grassOnly ? $b1 === GRASS : true) &&
($highMob ? !StaticBlock::getIsSolid($b2) && !StaticBlock::getIsLiquid($b2) : true))
(StaticBlock::getIsSolid($b1) && (!$grassOnly || $b1 === GRASS) &&
(!$highMob || !StaticBlock::getIsSolid($b2) && !StaticBlock::getIsLiquid($b2)))
){
$allowed[] = $y;
}