Added proper TextWrap width

This commit is contained in:
Shoghi Cervantes 2014-10-11 00:17:31 +02:00
parent 24c76acf30
commit afdf7bc2b9
2 changed files with 6 additions and 8 deletions

View File

@ -2240,7 +2240,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
return true; return true;
} }
return false;git return false;
} }
/** /**
@ -2250,14 +2250,14 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
*/ */
public function sendMessage($message){ public function sendMessage($message){
if($this->removeFormat !== false){ if($this->removeFormat !== false){
$message = TextWrapper::wrap($message); $message = TextWrapper::wrap(TextFormat::clean($message));
} }
$mes = explode("\n", $message); $mes = explode("\n", $message);
foreach($mes as $m){ foreach($mes as $m){
if($m !== ""){ if($m !== ""){
$pk = new MessagePacket; $pk = new MessagePacket;
$pk->source = ""; //Do not use this ;) $pk->source = ""; //Do not use this ;)
$pk->message = $this->removeFormat === false ? $m : TextFormat::clean($m); $pk->message = $m;
$this->dataPacket($pk); $this->dataPacket($pk);
} }
} }

View File

@ -32,7 +32,7 @@ abstract class TextWrapper{
6, 6, 6, 4, 6, 6, 6, 6, 6, 6, 5, 2, 5, 7 6, 6, 6, 4, 6, 6, 6, 6, 6, 6, 5, 2, 5, 7
]; ];
const CHAT_WINDOW_WIDTH = 320; const CHAT_WINDOW_WIDTH = 240;
const CHAT_STRING_LENGTH = 119; const CHAT_STRING_LENGTH = 119;
private static $allowedChars = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_abcdefghijklmnopqrstuvwxyz{|}~"; private static $allowedChars = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_abcdefghijklmnopqrstuvwxyz{|}~";
@ -57,7 +57,6 @@ abstract class TextWrapper{
$char = $text{$i}; $char = $text{$i};
if($char === "\n"){ if($char === "\n"){
$result .= "\n";
$lineLength = 0; $lineLength = 0;
$lineWidth = 0; $lineWidth = 0;
}elseif(isset(self::$allowedCharsArray[$char])){ }elseif(isset(self::$allowedCharsArray[$char])){
@ -71,10 +70,9 @@ abstract class TextWrapper{
++$lineLength; ++$lineLength;
$lineWidth += $width; $lineWidth += $width;
$result .= $char;
}else{
$result .= "\n";
} }
$result .= $char;
} }
return $result; return $result;