Added PluginLogger

This commit is contained in:
Shoghi Cervantes 2014-04-05 00:20:09 +02:00
parent 0d91be62cf
commit 6d58f32c91
4 changed files with 93 additions and 0 deletions

View File

@ -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
*/

View File

@ -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
*/

View File

@ -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
*/

View File

@ -0,0 +1,44 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
namespace pocketmine\plugin;
class PluginLogger{
private $pluginName;
/**
* @param Plugin $context
*/
public function __construct(Plugin $context){
$prefix = $context->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);
}
}