Merge branch 'stable'

# Conflicts:
#	resources/vanilla
#	src/CrashDump.php
#	src/utils/Utils.php
This commit is contained in:
Dylan K. Taylor 2020-12-09 01:47:05 +00:00
commit 22c8bdeeeb
2 changed files with 19 additions and 14 deletions

View File

@ -280,8 +280,8 @@ class CrashDump{
} }
private function determinePluginFromFile(string $filePath, bool $crashFrame) : bool{ private function determinePluginFromFile(string $filePath, bool $crashFrame) : bool{
$frameCleanPath = Filesystem::cleanPath($filePath); //this will be empty in phar stub $frameCleanPath = Filesystem::cleanPath($filePath);
if(strpos($frameCleanPath, "plugins") === 0 and file_exists($filePath)){ if(strpos($frameCleanPath, Filesystem::CLEAN_PATH_SRC_PREFIX) !== 0){
$this->addLine(); $this->addLine();
if($crashFrame){ if($crashFrame){
$this->addLine("THIS CRASH WAS CAUSED BY A PLUGIN"); $this->addLine("THIS CRASH WAS CAUSED BY A PLUGIN");
@ -291,15 +291,17 @@ class CrashDump{
$this->data["plugin_involvement"] = self::PLUGIN_INVOLVEMENT_INDIRECT; $this->data["plugin_involvement"] = self::PLUGIN_INVOLVEMENT_INDIRECT;
} }
$reflection = new \ReflectionClass(PluginBase::class); if(file_exists($filePath)){
$file = $reflection->getProperty("file"); $reflection = new \ReflectionClass(PluginBase::class);
$file->setAccessible(true); $file = $reflection->getProperty("file");
foreach($this->server->getPluginManager()->getPlugins() as $plugin){ $file->setAccessible(true);
$filePath = Filesystem::cleanPath($file->getValue($plugin)); foreach($this->server->getPluginManager()->getPlugins() as $plugin){
if(strpos($frameCleanPath, $filePath) === 0){ $filePath = Filesystem::cleanPath($file->getValue($plugin));
$this->data["plugin"] = $plugin->getName(); if(strpos($frameCleanPath, $filePath) === 0){
$this->addLine("BAD PLUGIN: " . $plugin->getDescription()->getFullName()); $this->data["plugin"] = $plugin->getName();
break; $this->addLine("BAD PLUGIN: " . $plugin->getDescription()->getFullName());
break;
}
} }
} }
return true; return true;

View File

@ -53,6 +53,9 @@ final class Filesystem{
/** @var resource[] */ /** @var resource[] */
private static $lockFileHandles = []; private static $lockFileHandles = [];
public const CLEAN_PATH_SRC_PREFIX = "pmsrc";
public const CLEAN_PATH_PLUGINS_PREFIX = "plugins";
private function __construct(){ private function __construct(){
//NOOP //NOOP
} }
@ -87,13 +90,13 @@ final class Filesystem{
//remove relative paths //remove relative paths
//TODO: make these paths dynamic so they can be unit-tested against //TODO: make these paths dynamic so they can be unit-tested against
static $cleanPaths = [ static $cleanPaths = [
\pocketmine\PLUGIN_PATH => "plugins", //this has to come BEFORE \pocketmine\PATH because it's inside that by default on src installations \pocketmine\PLUGIN_PATH => self::CLEAN_PATH_PLUGINS_PREFIX, //this has to come BEFORE \pocketmine\PATH because it's inside that by default on src installations
\pocketmine\PATH => "" \pocketmine\PATH => self::CLEAN_PATH_SRC_PREFIX
]; ];
foreach($cleanPaths as $cleanPath => $replacement){ foreach($cleanPaths as $cleanPath => $replacement){
$cleanPath = rtrim(str_replace([DIRECTORY_SEPARATOR, "phar://"], ["/", ""], $cleanPath), "/"); $cleanPath = rtrim(str_replace([DIRECTORY_SEPARATOR, "phar://"], ["/", ""], $cleanPath), "/");
if(strpos($result, $cleanPath) === 0){ if(strpos($result, $cleanPath) === 0){
$result = ltrim(str_replace($cleanPath, $replacement, $result), "/"); $result = ltrim(str_replace($cleanPath, "[$replacement]", $result), "/");
} }
} }
return $result; return $result;