Your PocketMine logger seems too old? Not any longer with CustomLogger !
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
2.0 KiB

  1. <?php
  2. namespace Ad5001\CustomLogger;
  3. use pocketmine\command\CommandSender;
  4. use pocketmine\command\Command;
  5. use pocketmine\event\Listener;
  6. use pocketmine\plugin\PluginBase;
  7. use pocketmine\utils\TextFormat;
  8. use pocketmine\utils\MainLogger;
  9. use pocketmine\Server;
  10. use pocketmine\Player;
  11. class Main extends PluginBase implements Listener {
  12. public function onEnable(){
  13. $this->getServer()->getPluginManager()->registerEvents($this, $this);
  14. }
  15. public function onLoad(){
  16. $this->saveDefaultConfig();
  17. if(!file_exists($this->getDataFolder() . "logs.txt")) {
  18. file_get_contents($this->getDataFolder() . "logs.txt", '');
  19. }
  20. $logger = new CustomLogger($this->getDataFolder() . "logs.txt", $this->getConfig()->get("Log_debug"), $this->getConfig()->getAll());
  21. $thread = \Thread::getCurrentThread();
  22. if($thread === null){
  23. $threadName = "PocketMine thread";
  24. }elseif($thread instanceof Thread or $thread instanceof Worker){
  25. $threadName = $thread->getThreadName() . " thread";
  26. }else{
  27. $threadName = (new \ReflectionClass($thread))->getShortName() . " thread";
  28. }
  29. echo str_repeat(" ", strlen(TextFormat::clean(TextFormat::toANSI(MainLogger::$logger->translateMsg($this->getConfig()->get("LoggerPrefix"), "", "", "§f", $threadName)))));
  30. }
  31. /*
  32. When the owner enters a command in the console. Here to addsome space.
  33. @param $event \pocketmine\event\server\ServerCommandEvent
  34. */
  35. public function onServerCommand(\pocketmine\event\server\ServerCommandEvent $event) {
  36. $thread = \Thread::getCurrentThread();
  37. if($thread === null){
  38. $threadName = "PocketMine thread";
  39. }elseif($thread instanceof Thread or $thread instanceof Worker){
  40. $threadName = $thread->getThreadName() . " thread";
  41. }else{
  42. $threadName = (new \ReflectionClass($thread))->getShortName() . " thread";
  43. }
  44. echo str_repeat(" ", strlen(TextFormat::clean(TextFormat::toANSI(MainLogger::$logger->translateMsg($this->getConfig()->get("LoggerPrefix"), "", "", "§f", $threadName)))));
  45. }
  46. }