From 6d58f32c914b28e000c70ef716404eb2985d02e1 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Sat, 5 Apr 2014 00:20:09 +0200 Subject: [PATCH] Added PluginLogger --- src/pocketmine/plugin/Plugin.php | 27 +++++++++++++ src/pocketmine/plugin/PluginBase.php | 11 ++++++ src/pocketmine/plugin/PluginDescription.php | 11 ++++++ src/pocketmine/plugin/PluginLogger.php | 44 +++++++++++++++++++++ 4 files changed, 93 insertions(+) create mode 100644 src/pocketmine/plugin/PluginLogger.php diff --git a/src/pocketmine/plugin/Plugin.php b/src/pocketmine/plugin/Plugin.php index 5348e58b1..6233bbb9d 100644 --- a/src/pocketmine/plugin/Plugin.php +++ b/src/pocketmine/plugin/Plugin.php @@ -36,14 +36,24 @@ interface Plugin{ */ public function onLoad(); + /** + * Called when the plugin is enabled + */ public function onEnable(); public function isEnabled(); + /** + * Called when the plugin is disabled + * Use this to free open things and finish actions + */ public function onDisable(); public function isDisabled(); + /** + * Gets the plugin's data folder to save files and configuration + */ public function getDataFolder(); /** @@ -56,6 +66,12 @@ interface Plugin{ */ public function getResource($filename); + /** + * Saves an embedded resource to its relative location in the data folder + * + * @param string $filename + * @param bool $replace + */ public function saveResource($filename, $replace = false); /** @@ -63,6 +79,9 @@ interface Plugin{ */ public function getResources(); + /** + * @return \pocketmine\utils\Config + */ public function getConfig(); public function saveConfig(); @@ -71,10 +90,18 @@ interface Plugin{ public function reloadConfig(); + /** + * @return \pocketmine\Server + */ public function getServer(); public function getName(); + /** + * @return PluginLogger + */ + public function getLogger(); + /** * @return PluginLoader */ diff --git a/src/pocketmine/plugin/PluginBase.php b/src/pocketmine/plugin/PluginBase.php index 9a5d55f28..42711c25b 100644 --- a/src/pocketmine/plugin/PluginBase.php +++ b/src/pocketmine/plugin/PluginBase.php @@ -53,6 +53,9 @@ abstract class PluginBase implements Plugin{ private $configFile; private $file; + /** @var PluginLogger */ + private $logger; + /** * Called when the plugin is loaded, before calling onEnable() */ @@ -113,9 +116,17 @@ abstract class PluginBase implements Plugin{ $this->dataFolder = rtrim($dataFolder, "\\/") . "/"; $this->file = rtrim($file, "\\/") . "/"; $this->configFile = $this->dataFolder . "config.yml"; + $this->logger = new PluginLogger($this); } } + /** + * @return PluginLogger + */ + public function getLogger(){ + return $this->logger; + } + /** * @return bool */ diff --git a/src/pocketmine/plugin/PluginDescription.php b/src/pocketmine/plugin/PluginDescription.php index 7a66945cb..85e98bd30 100644 --- a/src/pocketmine/plugin/PluginDescription.php +++ b/src/pocketmine/plugin/PluginDescription.php @@ -35,6 +35,7 @@ class PluginDescription{ private $description = null; private $authors = array(); private $website = null; + private $prefix = null; private $order = PluginLoadOrder::POSTWORLD; /** @@ -86,6 +87,9 @@ class PluginDescription{ if(isset($plugin["description"])){ $this->description = $plugin["description"]; } + if(isset($plugin["prefix"])){ + $this->prefix = $plugin["prefix"]; + } if(isset($plugin["load"])){ $order = strtoupper($plugin["load"]); if(!defined("pocketmine\\plugin\\PluginLoadOrder::" . $order)){ @@ -132,6 +136,13 @@ class PluginDescription{ return $this->authors; } + /** + * @return string + */ + public function getPrefix(){ + return $this->prefix; + } + /** * @return array */ diff --git a/src/pocketmine/plugin/PluginLogger.php b/src/pocketmine/plugin/PluginLogger.php new file mode 100644 index 000000000..398bbb11f --- /dev/null +++ b/src/pocketmine/plugin/PluginLogger.php @@ -0,0 +1,44 @@ +getDescription()->getPrefix(); + $this->pluginName = $prefix != null ? "[$prefix] " : "[".$context->getDescription()->getName()."] "; + } + + /** + * Logs a message to the console + * + * @param string $message + */ + public function log($message){ + console($this->pluginName . $message); + } +} \ No newline at end of file