mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-23 03:16:35 +00:00
This is better for performance because these then don't need to be reevaluated every time they are called. When encountering an unqualified function or constant reference, PHP will first try to locate a symbol in the current namespace by that name, and then fall back to the global namespace. This short-circuits the check, which has substantial performance effects in some cases - in particular, ord(), chr() and strlen() show ~1500x faster calls when they are fully qualified. However, this doesn't mean that PM is getting a massive amount faster. In real world terms, this translates to about 10-15% performance improvement. But before anyone gets excited, you should know that the CodeOptimizer in the PreProcessor repo has been applying fully-qualified symbol optimizations to Jenkins builds for years, which is one of the reasons why Jenkins builds have better performance than home-built or source installations. We're choosing to do this for the sake of future SafePHP integration and also to be able to get rid of the buggy CodeOptimizer, so that phar and source are more consistent.
152 lines
3.4 KiB
PHP
152 lines
3.4 KiB
PHP
<?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/
|
|
*
|
|
*
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace pocketmine\command;
|
|
|
|
use pocketmine\lang\TextContainer;
|
|
use pocketmine\permission\PermissibleBase;
|
|
use pocketmine\permission\Permission;
|
|
use pocketmine\permission\PermissionAttachment;
|
|
use pocketmine\permission\PermissionAttachmentInfo;
|
|
use pocketmine\plugin\Plugin;
|
|
use pocketmine\Server;
|
|
use pocketmine\utils\MainLogger;
|
|
use function explode;
|
|
use function trim;
|
|
use const PHP_INT_MAX;
|
|
|
|
class ConsoleCommandSender implements CommandSender{
|
|
|
|
private $perm;
|
|
|
|
/** @var int|null */
|
|
protected $lineHeight = null;
|
|
|
|
public function __construct(){
|
|
$this->perm = new PermissibleBase($this);
|
|
}
|
|
|
|
/**
|
|
* @param Permission|string $name
|
|
*
|
|
* @return bool
|
|
*/
|
|
public function isPermissionSet($name) : bool{
|
|
return $this->perm->isPermissionSet($name);
|
|
}
|
|
|
|
/**
|
|
* @param Permission|string $name
|
|
*
|
|
* @return bool
|
|
*/
|
|
public function hasPermission($name) : bool{
|
|
return $this->perm->hasPermission($name);
|
|
}
|
|
|
|
/**
|
|
* @param Plugin $plugin
|
|
* @param string $name
|
|
* @param bool $value
|
|
*
|
|
* @return PermissionAttachment
|
|
*/
|
|
public function addAttachment(Plugin $plugin, string $name = null, bool $value = null) : PermissionAttachment{
|
|
return $this->perm->addAttachment($plugin, $name, $value);
|
|
}
|
|
|
|
/**
|
|
* @param PermissionAttachment $attachment
|
|
*
|
|
* @return void
|
|
*/
|
|
public function removeAttachment(PermissionAttachment $attachment){
|
|
$this->perm->removeAttachment($attachment);
|
|
}
|
|
|
|
public function recalculatePermissions(){
|
|
$this->perm->recalculatePermissions();
|
|
}
|
|
|
|
/**
|
|
* @return PermissionAttachmentInfo[]
|
|
*/
|
|
public function getEffectivePermissions() : array{
|
|
return $this->perm->getEffectivePermissions();
|
|
}
|
|
|
|
/**
|
|
* @return Server
|
|
*/
|
|
public function getServer(){
|
|
return Server::getInstance();
|
|
}
|
|
|
|
/**
|
|
* @param TextContainer|string $message
|
|
*/
|
|
public function sendMessage($message){
|
|
if($message instanceof TextContainer){
|
|
$message = $this->getServer()->getLanguage()->translate($message);
|
|
}else{
|
|
$message = $this->getServer()->getLanguage()->translateString($message);
|
|
}
|
|
|
|
foreach(explode("\n", trim($message)) as $line){
|
|
MainLogger::getLogger()->info($line);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @return string
|
|
*/
|
|
public function getName() : string{
|
|
return "CONSOLE";
|
|
}
|
|
|
|
/**
|
|
* @return bool
|
|
*/
|
|
public function isOp() : bool{
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* @param bool $value
|
|
*/
|
|
public function setOp(bool $value){
|
|
|
|
}
|
|
|
|
public function getScreenLineHeight() : int{
|
|
return $this->lineHeight ?? PHP_INT_MAX;
|
|
}
|
|
|
|
public function setScreenLineHeight(int $height = null){
|
|
if($height !== null and $height < 1){
|
|
throw new \InvalidArgumentException("Line height must be at least 1");
|
|
}
|
|
$this->lineHeight = $height;
|
|
}
|
|
}
|