Merge branch 'stable'

This commit is contained in:
Dylan K. Taylor 2019-04-15 16:11:49 +01:00
commit 209ae51a67
3 changed files with 21 additions and 4 deletions

View File

@ -36,6 +36,7 @@ use pocketmine\utils\TextFormat;
use function array_map;
use function assert;
use function floor;
use function strlen;
class Sign extends Transparent{
/** @var BlockIdentifierFlattened */
@ -151,8 +152,16 @@ class Sign extends Transparent{
* @param SignText $text
*
* @return bool if the sign update was successful.
* @throws \UnexpectedValueException if the text payload is too large
*/
public function updateText(Player $author, SignText $text) : bool{
$size = 0;
foreach($text->getLines() as $line){
$size += strlen($line);
}
if($size > 1000){
throw new \UnexpectedValueException($author->getName() . " tried to write $size bytes of text onto a sign (bigger than max 1000)");
}
$removeFormat = $author->getRemoveFormat();
$ev = new SignChangeEvent($this, $author, new SignText(array_map(function(string $line) use ($removeFormat){
return TextFormat::clean($line, $removeFormat);

View File

@ -115,8 +115,12 @@ class WhitelistCommand extends VanillaCommand{
return true;
}
private function badPerm(CommandSender $sender, string $perm) : bool{
if(!$sender->hasPermission("pocketmine.command.whitelist.$perm")){
private function badPerm(CommandSender $sender, string $subcommand) : bool{
static $map = [
"on" => "enable",
"off" => "disable"
];
if(!$sender->hasPermission("pocketmine.command.whitelist." . ($map[$subcommand] ?? $subcommand))){
$sender->sendMessage($sender->getServer()->getLanguage()->translateString(TextFormat::RED . "%commands.generic.permission"));
return true;

View File

@ -464,8 +464,12 @@ class SimpleSessionHandler extends SessionHandler{
throw new BadPacketException("Invalid sign text update: " . $e->getMessage(), 0, $e);
}
if(!$block->updateText($this->player, $text)){
$this->player->getLevel()->sendBlocks([$this->player], [$block]);
try{
if(!$block->updateText($this->player, $text)){
$this->player->getLevel()->sendBlocks([$this->player], [$block]);
}
}catch(\UnexpectedValueException $e){
throw new BadPacketException($e->getMessage(), 0, $e);
}
return true;