diff --git a/src/API/PlayerAPI.php b/src/API/PlayerAPI.php index 8c3272f9..b4908833 100644 --- a/src/API/PlayerAPI.php +++ b/src/API/PlayerAPI.php @@ -190,8 +190,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 +297,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); diff --git a/src/API/TimeAPI.php b/src/API/TimeAPI.php index 51924611..225f4046 100644 --- a/src/API/TimeAPI.php +++ b/src/API/TimeAPI.php @@ -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){ diff --git a/src/PocketMinecraftServer.php b/src/PocketMinecraftServer.php index bcc5825d..54e02ad7 100644 --- a/src/PocketMinecraftServer.php +++ b/src/PocketMinecraftServer.php @@ -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); diff --git a/src/config.php b/src/config.php index 5b9eceb8..09c6681e 100644 --- a/src/config.php +++ b/src/config.php @@ -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); diff --git a/src/dependencies.php b/src/dependencies.php index 097eaed1..0e6613e7 100644 --- a/src/dependencies.php +++ b/src/dependencies.php @@ -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); diff --git a/src/functions.php b/src/functions.php index fee2a0a4..cf512b7b 100644 --- a/src/functions.php +++ b/src/functions.php @@ -140,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); @@ -152,7 +152,7 @@ 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; } diff --git a/src/utils/Utils.php b/src/utils/Utils.php index 98f3666d..bd418cc2 100644 --- a/src/utils/Utils.php +++ b/src/utils/Utils.php @@ -87,7 +87,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 +148,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";