mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-10-16 19:59:11 +00:00
Merge branch 'stable'
This commit is contained in:
@@ -166,29 +166,28 @@ class Config{
|
||||
$this->save();
|
||||
}else{
|
||||
$content = file_get_contents($this->file);
|
||||
$config = null;
|
||||
switch($this->type){
|
||||
case Config::PROPERTIES:
|
||||
$this->parseProperties($content);
|
||||
$config = $this->parseProperties($content);
|
||||
break;
|
||||
case Config::JSON:
|
||||
$this->config = json_decode($content, true);
|
||||
$config = json_decode($content, true);
|
||||
break;
|
||||
case Config::YAML:
|
||||
$content = self::fixYAMLIndexes($content);
|
||||
$this->config = yaml_parse($content);
|
||||
$config = yaml_parse($content);
|
||||
break;
|
||||
case Config::SERIALIZED:
|
||||
$this->config = unserialize($content);
|
||||
$config = unserialize($content);
|
||||
break;
|
||||
case Config::ENUM:
|
||||
$this->parseList($content);
|
||||
$config = self::parseList($content);
|
||||
break;
|
||||
default:
|
||||
throw new \InvalidStateException("Config type is unknown");
|
||||
}
|
||||
if(!is_array($this->config)){
|
||||
$this->config = $default;
|
||||
}
|
||||
$this->config = is_array($config) ? $config : $default;
|
||||
if($this->fillDefaults($default, $this->config) > 0){
|
||||
$this->save();
|
||||
}
|
||||
@@ -508,14 +507,20 @@ class Config{
|
||||
return $changed;
|
||||
}
|
||||
|
||||
private function parseList(string $content) : void{
|
||||
/**
|
||||
* @return true[]
|
||||
* @phpstan-return array<string, true>
|
||||
*/
|
||||
private static function parseList(string $content) : array{
|
||||
$result = [];
|
||||
foreach(explode("\n", trim(str_replace("\r\n", "\n", $content))) as $v){
|
||||
$v = trim($v);
|
||||
if($v == ""){
|
||||
continue;
|
||||
}
|
||||
$this->config[$v] = true;
|
||||
$result[$v] = true;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function writeProperties() : string{
|
||||
@@ -532,7 +537,12 @@ class Config{
|
||||
return $content;
|
||||
}
|
||||
|
||||
private function parseProperties(string $content) : void{
|
||||
/**
|
||||
* @return mixed[]
|
||||
* @phpstan-return array<string, mixed>
|
||||
*/
|
||||
private function parseProperties(string $content) : array{
|
||||
$result = [];
|
||||
if(preg_match_all('/^\s*([a-zA-Z0-9\-_\.]+)[ \t]*=([^\r\n]*)/um', $content, $matches) > 0){ //false or 0 matches
|
||||
foreach($matches[1] as $i => $k){
|
||||
$v = trim($matches[2][$i]);
|
||||
@@ -548,11 +558,13 @@ class Config{
|
||||
$v = false;
|
||||
break;
|
||||
}
|
||||
if(isset($this->config[$k])){
|
||||
if(isset($result[$k])){
|
||||
\GlobalLogger::get()->debug("[Config] Repeated property " . $k . " on file " . $this->file);
|
||||
}
|
||||
$this->config[$k] = $v;
|
||||
$result[$k] = $v;
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
@@ -252,7 +252,7 @@ class MainLogger extends \AttachableThreadedLogger{
|
||||
|
||||
public function syncFlushBuffer() : void{
|
||||
$this->syncFlush = true;
|
||||
$this->synchronized(function(){
|
||||
$this->synchronized(function() : void{
|
||||
$this->notify(); //write immediately
|
||||
|
||||
while($this->syncFlush){
|
||||
@@ -284,7 +284,7 @@ class MainLogger extends \AttachableThreadedLogger{
|
||||
|
||||
while(!$this->shutdown){
|
||||
$this->writeLogStream($logResource);
|
||||
$this->synchronized(function(){
|
||||
$this->synchronized(function() : void{
|
||||
$this->wait(25000);
|
||||
});
|
||||
}
|
||||
|
@@ -126,7 +126,7 @@ final class Process{
|
||||
}
|
||||
switch(Utils::getOS()){
|
||||
case "win":
|
||||
exec("taskkill.exe /F /PID " . ((int) $pid) . " > NUL");
|
||||
exec("taskkill.exe /F /PID $pid > NUL");
|
||||
break;
|
||||
case "mac":
|
||||
case "linux":
|
||||
@@ -134,7 +134,7 @@ final class Process{
|
||||
if(function_exists("posix_kill")){
|
||||
posix_kill($pid, 9); //SIGKILL
|
||||
}else{
|
||||
exec("kill -9 " . ((int) $pid) . " > /dev/null 2>&1");
|
||||
exec("kill -9 $pid > /dev/null 2>&1");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -44,7 +44,7 @@ class ServerKiller extends Thread{
|
||||
|
||||
protected function onRun() : void{
|
||||
$start = time();
|
||||
$this->synchronized(function(){
|
||||
$this->synchronized(function() : void{
|
||||
if(!$this->stopped){
|
||||
$this->wait($this->time * 1000000);
|
||||
}
|
||||
|
@@ -337,7 +337,7 @@ class Utils{
|
||||
$hash = 0;
|
||||
for($i = 0, $len = strlen($string); $i < $len; $i++){
|
||||
$ord = ord($string[$i]);
|
||||
if($ord & 0x80){
|
||||
if(($ord & 0x80) !== 0){
|
||||
$ord -= 0x100;
|
||||
}
|
||||
$hash = 31 * $hash + $ord;
|
||||
@@ -408,7 +408,7 @@ class Utils{
|
||||
$args = $trace[$i]["params"];
|
||||
}
|
||||
|
||||
$params = implode(", ", array_map(function($value) use($maxStringLength){
|
||||
$params = implode(", ", array_map(function($value) use($maxStringLength) : string{
|
||||
if(is_object($value)){
|
||||
return "object " . self::getNiceClassName($value);
|
||||
}
|
||||
|
Reference in New Issue
Block a user