mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-23 13:09:44 +00:00
PHP8: new str_* function
This commit is contained in:
parent
69385e16f2
commit
1275a4558c
7 changed files with 15 additions and 15 deletions
|
|
@ -190,8 +190,8 @@ class PlayerAPI{
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "tp":
|
case "tp":
|
||||||
if(count($args) <= 2 or substr($args[0], 0, 2) === "w:" or substr($args[1], 0, 2) === "w:"){
|
if(count($args) <= 2 or str_starts_with($args[0], "w:") or str_starts_with($args[1], "w:")){
|
||||||
if((!isset($args[1]) or substr($args[0], 0, 2) === "w:") and isset($args[0]) and ($issuer instanceof Player)){
|
if((!isset($args[1]) or str_starts_with($args[0], "w:")) and isset($args[0]) and ($issuer instanceof Player)){
|
||||||
$name = $issuer->username;
|
$name = $issuer->username;
|
||||||
$target = implode(" ", $args);
|
$target = implode(" ", $args);
|
||||||
}elseif(isset($args[1]) and isset($args[0])){
|
}elseif(isset($args[1]) and isset($args[0])){
|
||||||
|
|
@ -297,7 +297,7 @@ class PlayerAPI{
|
||||||
}
|
}
|
||||||
|
|
||||||
public function teleport(&$name, &$target){
|
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));
|
$lv = $this->server->api->level->get(substr($target, 2));
|
||||||
if($lv instanceof Level){
|
if($lv instanceof Level){
|
||||||
$origin = $this->get($name);
|
$origin = $this->get($name);
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ class TimeAPI{
|
||||||
$p = strtolower(array_shift($args));
|
$p = strtolower(array_shift($args));
|
||||||
switch($p){
|
switch($p){
|
||||||
case "check":
|
case "check":
|
||||||
if(substr($args[0] ?? "", 0, 2) === "w:"){
|
if(str_starts_with($args[0] ?? "", "w:")){
|
||||||
$levelName = preg_replace("/w:/", "", $args[0]);
|
$levelName = preg_replace("/w:/", "", $args[0]);
|
||||||
$level = $this->server->api->level->get($levelName);
|
$level = $this->server->api->level->get($levelName);
|
||||||
if($level instanceof Level){
|
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";
|
$output .= "Time" . $world . ": " . $this->getDate($level) . ", " . $this->getPhase($level) . " (" . $this->get(true, $level) . " ticks)\n";
|
||||||
break;
|
break;
|
||||||
case "add":
|
case "add":
|
||||||
if(substr($args[1] ?? "", 0, 2) === "w:"){
|
if(str_starts_with($args[1] ?? "", "w:")){
|
||||||
$levelName = preg_replace("/w:/", "", $args[1]);
|
$levelName = preg_replace("/w:/", "", $args[1]);
|
||||||
$level = $this->server->api->level->get($levelName);
|
$level = $this->server->api->level->get($levelName);
|
||||||
if($level instanceof Level){
|
if($level instanceof Level){
|
||||||
|
|
@ -65,7 +65,7 @@ class TimeAPI{
|
||||||
$output .= "Added $addTime ticks" . $world . "\n";
|
$output .= "Added $addTime ticks" . $world . "\n";
|
||||||
break;
|
break;
|
||||||
case "set":
|
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]);
|
$levelName = preg_replace("/w:/", "", $args[1]);
|
||||||
$level = $this->server->api->level->get($levelName);
|
$level = $this->server->api->level->get($levelName);
|
||||||
if($level instanceof Level){
|
if($level instanceof Level){
|
||||||
|
|
@ -92,7 +92,7 @@ class TimeAPI{
|
||||||
case "day":
|
case "day":
|
||||||
case "sunset":
|
case "sunset":
|
||||||
case "night":
|
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]);
|
$levelName = preg_replace("/w:/", "", $args[1]);
|
||||||
$level = $this->server->api->level->get($levelName);
|
$level = $this->server->api->level->get($levelName);
|
||||||
if($level instanceof Level){
|
if($level instanceof Level){
|
||||||
|
|
|
||||||
|
|
@ -548,7 +548,7 @@ class PocketMinecraftServer{
|
||||||
$this->custom["times_" . $CID] = 0;
|
$this->custom["times_" . $CID] = 0;
|
||||||
}
|
}
|
||||||
$ln = 15;
|
$ln = 15;
|
||||||
if($this->description == "" or substr($this->description, -1) != " "){
|
if($this->description == "" or !str_ends_with($this->description, " ")){
|
||||||
$this->description .= " ";
|
$this->description .= " ";
|
||||||
}
|
}
|
||||||
$txt = substr($this->description, $this->custom["times_" . $CID], $ln);
|
$txt = substr($this->description, $this->custom["times_" . $CID], $ln);
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ set_time_limit(0);
|
||||||
|
|
||||||
if(ini_get("date.timezone") == ""){ //No Timezone set
|
if(ini_get("date.timezone") == ""){ //No Timezone set
|
||||||
date_default_timezone_set("GMT");
|
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();
|
||||||
$time -= $time % 60;
|
$time -= $time % 60;
|
||||||
//Example: USA
|
//Example: USA
|
||||||
|
|
@ -24,7 +24,7 @@ if(ini_get("date.timezone") == ""){ //No Timezone set
|
||||||
date_default_timezone_set($d);
|
date_default_timezone_set($d);
|
||||||
}else{
|
}else{
|
||||||
$d = @date_default_timezone_get();
|
$d = @date_default_timezone_get();
|
||||||
if(strpos($d, "/") === false){
|
if(!str_contains($d, "/")){
|
||||||
$d = timezone_name_from_abbr($d);
|
$d = timezone_name_from_abbr($d);
|
||||||
@ini_set("date.timezone", $d);
|
@ini_set("date.timezone", $d);
|
||||||
date_default_timezone_set($d);
|
date_default_timezone_set($d);
|
||||||
|
|
|
||||||
|
|
@ -120,7 +120,7 @@ $inc = get_included_files();
|
||||||
$inc[] = array_shift($inc);
|
$inc[] = array_shift($inc);
|
||||||
$srcdir = realpath(FILE_PATH . "src/");
|
$srcdir = realpath(FILE_PATH . "src/");
|
||||||
foreach($inc as $s){
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
$sha1sum ^= sha1_file($s, true);
|
$sha1sum ^= sha1_file($s, true);
|
||||||
|
|
|
||||||
|
|
@ -140,7 +140,7 @@ function arguments($args){
|
||||||
foreach($args as $arg){
|
foreach($args as $arg){
|
||||||
|
|
||||||
// Is it a command? (prefixed with --)
|
// Is it a command? (prefixed with --)
|
||||||
if(substr($arg, 0, 2) === '--'){
|
if(str_starts_with($arg, '--')){
|
||||||
|
|
||||||
$value = preg_split('/[= ]/', $arg, 2);
|
$value = preg_split('/[= ]/', $arg, 2);
|
||||||
$com = substr(array_shift($value), 2);
|
$com = substr(array_shift($value), 2);
|
||||||
|
|
@ -152,7 +152,7 @@ function arguments($args){
|
||||||
}
|
}
|
||||||
|
|
||||||
// Is it a flag? (prefixed with -)
|
// Is it a flag? (prefixed with -)
|
||||||
if(substr($arg, 0, 1) === '-'){
|
if(str_starts_with($arg, '-')){
|
||||||
$ret['flags'][] = substr($arg, 1);
|
$ret['flags'][] = substr($arg, 1);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -87,7 +87,7 @@ class Utils{
|
||||||
* PHP8 has internal function for doing it: {@link str_ends_with}
|
* PHP8 has internal function for doing it: {@link str_ends_with}
|
||||||
*/
|
*/
|
||||||
public static function endsWith($str, $check) {
|
public static function endsWith($str, $check) {
|
||||||
return substr($str, -strlen($check)) === $check;
|
return str_ends_with($str, $check);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function hasEmoji($s){
|
public static function hasEmoji($s){
|
||||||
|
|
@ -148,7 +148,7 @@ class Utils{
|
||||||
public static function getOS(){
|
public static function getOS(){
|
||||||
$uname = php_uname("s");
|
$uname = php_uname("s");
|
||||||
if(stripos($uname, "Darwin") !== false){
|
if(stripos($uname, "Darwin") !== false){
|
||||||
if(strpos(php_uname("m"), "iP") === 0){
|
if(str_starts_with(php_uname("m"), "iP")){
|
||||||
return "ios";
|
return "ios";
|
||||||
}else{
|
}else{
|
||||||
return "mac";
|
return "mac";
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue