/**
* @param string $str
*
* @return BanEntry
*/
public static function fromString($str)
{
if (strlen($str) < 2) {
return null;
} else {
$str = explode("|", trim($str));
$entry = new BanEntry(trim(array_shift($str)));
if (count($str) > 0) {
$datetime = \DateTime::createFromFormat(self::$format, array_shift($str));
if (!$datetime instanceof \DateTime) {
MainLogger::getLogger()->alert("Error parsing date for BanEntry for player \"" . $entry->getName() . "\", the format may be invalid!");
return $entry;
}
$entry->setCreated($datetime);
if (count($str) > 0) {
$entry->setSource(trim(array_shift($str)));
if (count($str) > 0) {
$expire = trim(array_shift($str));
if (strtolower($expire) !== "forever" and strlen($expire) > 0) {
$entry->setExpires(\DateTime::createFromFormat(self::$format, $expire));
}
if (count($str) > 0) {
$entry->setReason(trim(array_shift($str)));
}
}
}
}
return $entry;
}
}