Player: remove removeFormat, chat formatting is now unconditionally available

This change was made after exploring turning this into a permission. It occurred to me that this feature is entirely superfluous because it's non-vanilla, can be done by plugins, and is usually considered as a bug. In addition, disabling this behaviour required third party code just for this one thing because it was not able to be managed by a permissions plugin.
Instead, it's better to produce a plugin which implements this behaviour if it's desired, by making use of SignChangeEvent and PlayerChatEvent/PlayerCommandPreprocessEvent.

close #3856, close #2288
This commit is contained in:
Dylan K. Taylor 2020-10-06 14:00:23 +01:00
parent e39d2c4621
commit 78bddac823
2 changed files with 3 additions and 17 deletions

View File

@ -105,9 +105,8 @@ abstract class BaseSign extends Transparent{
if($size > 1000){ if($size > 1000){
throw new \UnexpectedValueException($author->getName() . " tried to write $size bytes of text onto a sign (bigger than max 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) : string{
$ev = new SignChangeEvent($this, $author, new SignText(array_map(function(string $line) use ($removeFormat) : string{ return TextFormat::clean($line, false);
return TextFormat::clean($line, $removeFormat);
}, $text->getLines()))); }, $text->getLines())));
$ev->call(); $ev->call();
if(!$ev->isCancelled()){ if(!$ev->isCancelled()){

View File

@ -183,8 +183,6 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
/** @var int */ /** @var int */
protected $messageCounter = 2; protected $messageCounter = 2;
/** @var bool */
protected $removeFormat = true;
/** @var int */ /** @var int */
protected $firstPlayed; protected $firstPlayed;
@ -345,9 +343,6 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
} }
$this->keepMovement = true; $this->keepMovement = true;
if($this->isOp()){
$this->setRemoveFormat(false);
}
$this->setNameTagVisible(); $this->setNameTagVisible();
$this->setNameTagAlwaysVisible(); $this->setNameTagAlwaysVisible();
@ -485,14 +480,6 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
return $this->server; return $this->server;
} }
public function getRemoveFormat() : bool{
return $this->removeFormat;
}
public function setRemoveFormat(bool $remove = true) : void{
$this->removeFormat = $remove;
}
public function getScreenLineHeight() : int{ public function getScreenLineHeight() : int{
return $this->lineHeight ?? 7; return $this->lineHeight ?? 7;
} }
@ -1370,7 +1357,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{
public function chat(string $message) : bool{ public function chat(string $message) : bool{
$this->doCloseInventory(); $this->doCloseInventory();
$message = TextFormat::clean($message, $this->removeFormat); $message = TextFormat::clean($message, false);
foreach(explode("\n", $message) as $messagePart){ foreach(explode("\n", $message) as $messagePart){
if(trim($messagePart) !== "" and strlen($messagePart) <= 255 and $this->messageCounter-- > 0){ if(trim($messagePart) !== "" and strlen($messagePart) <= 255 and $this->messageCounter-- > 0){
if(strpos($messagePart, './') === 0){ if(strpos($messagePart, './') === 0){