diff --git a/src/plugin/PluginBase.php b/src/plugin/PluginBase.php index c8f3e1c39..e4270de00 100644 --- a/src/plugin/PluginBase.php +++ b/src/plugin/PluginBase.php @@ -50,6 +50,8 @@ use const DIRECTORY_SEPARATOR; abstract class PluginBase implements Plugin, CommandExecutor{ private bool $isEnabled = false; + private string $resourceFolder; + private ?Config $config = null; private string $configFile; @@ -67,6 +69,8 @@ abstract class PluginBase implements Plugin, CommandExecutor{ $this->dataFolder = rtrim($dataFolder, "/" . DIRECTORY_SEPARATOR) . "/"; //TODO: this is accessed externally via reflection, not unused $this->file = rtrim($file, "/" . DIRECTORY_SEPARATOR) . "/"; + $this->resourceFolder = Path::join($this->file, "resources") . "/"; + $this->configFile = Path::join($this->dataFolder, "config.yml"); $prefix = $this->getDescription()->getPrefix(); @@ -209,6 +213,27 @@ abstract class PluginBase implements Plugin, CommandExecutor{ } /** + * Returns the path to the folder where the plugin's embedded resource files are usually located. + * Note: This is NOT the same as the data folder. The files in this folder should be considered read-only. + */ + public function getResourceFolder() : string{ + return $this->resourceFolder; + } + + /** + * Returns the full path to a data file in the plugin's resources folder. + * This path can be used with standard PHP functions like fopen() or file_get_contents(). + * + * Note: Any path returned by this function should be considered READ-ONLY. + */ + public function getResourcePath(string $filename) : string{ + return Path::join($this->getResourceFolder(), $filename); + } + + /** + * @deprecated Prefer using standard PHP functions with {@link PluginBase::getResourcePath()}, like + * file_get_contents() or fopen(). + * * Gets an embedded resource on the plugin file. * WARNING: You must close the resource given using fclose() *