public static function wrap($text)
{
$result = "";
$len = strlen($text);
$lineWidth = 0;
$lineLength = 0;
for ($i = 0; $i < $len; ++$i) {
$char = $text[$i];
if ($char === "\n") {
$lineLength = 0;
$lineWidth = 0;
} elseif (isset(self::$allowedCharsArray[$char])) {
$width = self::$allowedCharsArray[$char];
if ($lineLength + 1 > self::CHAT_STRING_LENGTH or $lineWidth + $width > self::CHAT_WINDOW_WIDTH) {
$result .= "\n";
$lineLength = 0;
$lineWidth = 0;
}
++$lineLength;
$lineWidth += $width;
} else {
return $text;
}
$result .= $char;
}
return $result;
}
/** * Sends a direct chat message to a player * * @param string $message */ public function sendMessage($message) { if ($this->removeFormat !== false) { $message = TextWrapper::wrap(TextFormat::clean($message)); } $mes = explode("\n", $message); foreach ($mes as $m) { if ($m !== "") { $pk = new MessagePacket(); $pk->source = ""; //Do not use this ;) $pk->message = $m; $this->dataPacket($pk); } } }