Merge branch 'release/3.4'

This commit is contained in:
Dylan K. Taylor 2018-11-01 15:51:50 +00:00
commit acd3116591
4 changed files with 34 additions and 16 deletions

View File

@ -201,9 +201,6 @@ class Server{
/** @var ResourcePackManager */ /** @var ResourcePackManager */
private $resourceManager; private $resourceManager;
/** @var ConsoleCommandSender */
private $consoleSender;
/** @var int */ /** @var int */
private $maxPlayers; private $maxPlayers;
@ -1545,10 +1542,18 @@ class Server{
$this->doTitleTick = ((bool) $this->getProperty("console.title-tick", true)) && Terminal::hasFormattingCodes(); $this->doTitleTick = ((bool) $this->getProperty("console.title-tick", true)) && Terminal::hasFormattingCodes();
$consoleSender = new ConsoleCommandSender();
PermissionManager::getInstance()->subscribeToPermission(Server::BROADCAST_CHANNEL_ADMINISTRATIVE, $consoleSender);
$consoleNotifier = new SleeperNotifier(); $consoleNotifier = new SleeperNotifier();
$this->console = new CommandReader($consoleNotifier); $this->console = new CommandReader($consoleNotifier);
$this->tickSleeper->addNotifier($consoleNotifier, function() : void{ $this->tickSleeper->addNotifier($consoleNotifier, function() use ($consoleSender) : void{
$this->checkConsole(); Timings::$serverCommandTimer->startTiming();
while(($line = $this->console->getLine()) !== null){
$this->dispatchCommand($consoleSender, $line);
}
Timings::$serverCommandTimer->stopTiming();
}); });
$this->console->start(PTHREADS_INHERIT_NONE); $this->console->start(PTHREADS_INHERIT_NONE);
@ -1624,7 +1629,6 @@ class Server{
Timings::init(); Timings::init();
TimingsHandler::setEnabled((bool) $this->getProperty("settings.enable-profiling", false)); TimingsHandler::setEnabled((bool) $this->getProperty("settings.enable-profiling", false));
$this->consoleSender = new ConsoleCommandSender();
$this->commandMap = new SimpleCommandMap($this); $this->commandMap = new SimpleCommandMap($this);
Entity::init(); Entity::init();
@ -1641,7 +1645,6 @@ class Server{
$this->resourceManager = new ResourcePackManager($this->getDataPath() . "resource_packs" . DIRECTORY_SEPARATOR, $this->logger); $this->resourceManager = new ResourcePackManager($this->getDataPath() . "resource_packs" . DIRECTORY_SEPARATOR, $this->logger);
$this->pluginManager = new PluginManager($this, $this->commandMap, ((bool) $this->getProperty("plugins.legacy-data-dir", true)) ? null : $this->getDataPath() . "plugin_data" . DIRECTORY_SEPARATOR); $this->pluginManager = new PluginManager($this, $this->commandMap, ((bool) $this->getProperty("plugins.legacy-data-dir", true)) ? null : $this->getDataPath() . "plugin_data" . DIRECTORY_SEPARATOR);
PermissionManager::getInstance()->subscribeToPermission(Server::BROADCAST_CHANNEL_ADMINISTRATIVE, $this->consoleSender);
$this->profilingTickRate = (float) $this->getProperty("settings.profile-report-trigger", 20); $this->profilingTickRate = (float) $this->getProperty("settings.profile-report-trigger", 20);
$this->pluginManager->registerInterface(new PharPluginLoader($this->autoloader)); $this->pluginManager->registerInterface(new PharPluginLoader($this->autoloader));
$this->pluginManager->registerInterface(new ScriptPluginLoader()); $this->pluginManager->registerInterface(new ScriptPluginLoader());
@ -1971,14 +1974,6 @@ class Server{
$this->pluginManager->disablePlugins(); $this->pluginManager->disablePlugins();
} }
public function checkConsole(){
Timings::$serverCommandTimer->startTiming();
while(($line = $this->console->getLine()) !== null){
$this->dispatchCommand($this->consoleSender, $line);
}
Timings::$serverCommandTimer->stopTiming();
}
/** /**
* Executes a command from a CommandSender * Executes a command from a CommandSender
* *

View File

@ -23,6 +23,8 @@ declare(strict_types=1);
namespace pocketmine\scheduler; namespace pocketmine\scheduler;
use pocketmine\utils\Utils;
abstract class Task{ abstract class Task{
/** @var TaskHandler */ /** @var TaskHandler */
@ -46,6 +48,10 @@ abstract class Task{
return -1; return -1;
} }
public function getName() : string{
return Utils::getNiceClassName($this);
}
/** /**
* @param TaskHandler|null $taskHandler * @param TaskHandler|null $taskHandler
*/ */

View File

@ -66,7 +66,7 @@ class TaskHandler{
$this->taskId = $taskId; $this->taskId = $taskId;
$this->delay = $delay; $this->delay = $delay;
$this->period = $period; $this->period = $period;
$this->taskName = get_class($task); $this->taskName = $task->getName();
$this->ownerName = $ownerName ?? "Unknown"; $this->ownerName = $ownerName ?? "Unknown";
$this->timings = Timings::getScheduledTaskTimings($this, $period); $this->timings = Timings::getScheduledTaskTimings($this, $period);
$this->task->setHandler($this); $this->task->setHandler($this);

View File

@ -52,6 +52,23 @@ class Utils{
} }
} }
/**
* Returns a readable identifier for the class of the given object. Sanitizes class names for closures.
*
* @param object $obj
*
* @return string
* @throws \ReflectionException
*/
public static function getNiceClassName(object $obj) : string{
$reflect = new \ReflectionClass($obj);
if($reflect->isAnonymous()){
return "anonymous@" . self::cleanPath($reflect->getFileName()) . "#L" . $reflect->getStartLine();
}
return $reflect->getName();
}
/** /**
* Gets this machine / server instance unique ID * Gets this machine / server instance unique ID
* Returns a hash, the first 32 characters (or 16 if raw) * Returns a hash, the first 32 characters (or 16 if raw)