Skip to content

Commit

Permalink
added ticking entity problem for crash reports
Browse files Browse the repository at this point in the history
  • Loading branch information
matthi4s committed Jul 14, 2022
1 parent f6f10bc commit 63c4dc8
Show file tree
Hide file tree
Showing 11 changed files with 6,801 additions and 7 deletions.
4 changes: 3 additions & 1 deletion lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,7 @@
"bedrock-dbstorage-chain-problem": "Unable to decrypt world. Marketplace worlds can't be installed on dedicated servers.",
"mod-incompatible-problem": "The mods '{{first-mod-name}}' and '{{second-mod-name}}' are incompatible.",
"server-install-different-version-solution": "Install the version '{{software-version}}' of your server software.",
"plugin-api-version-problem": "The plugin '{{plugin-name}}' needs version '{{software-version}}' of your server software."
"plugin-api-version-problem": "The plugin '{{plugin-name}}' needs version '{{software-version}}' of your server software.",
"ticking-entity-problem": "The entity '{{name}}' at the location {{location}} is causing issues while ticking.",
"remove-entity-solution": "Remove the entity '{{name}}' at the location {{location}}."
}
2 changes: 2 additions & 0 deletions src/Analyser/CrashReport/MinecraftCrashReportAnalyser.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@

use Aternos\Codex\Minecraft\Analyser\MinecraftAnalyser;
use Aternos\Codex\Minecraft\Analysis\Information\CrashReport\VanillaVersionInformation;
use Aternos\Codex\Minecraft\Analysis\Problem\CrashReport\TickingEntityProblem;

class MinecraftCrashReportAnalyser extends MinecraftAnalyser
{
public function __construct()
{
$this->addPossibleInsightClass(VanillaVersionInformation::class);
$this->addPossibleInsightClass(TickingEntityProblem::class);
}
}
7 changes: 7 additions & 0 deletions src/Analysis/Problem/CrashReport/CrashReportProblem.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace Aternos\Codex\Minecraft\Analysis\Problem\CrashReport;

abstract class CrashReportProblem extends \Aternos\Codex\Minecraft\Analysis\Problem\MinecraftProblem
{
}
153 changes: 153 additions & 0 deletions src/Analysis/Problem/CrashReport/TickingEntityProblem.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
<?php

namespace Aternos\Codex\Minecraft\Analysis\Problem\CrashReport;

use Aternos\Codex\Minecraft\Analysis\Solution\CrashReport\RemoveEntitySolution;
use Aternos\Codex\Minecraft\Translator\Translator;

class TickingEntityProblem extends CrashReportProblem
{
const PATTERN_DESCRIPTION = "description";
const PATTERN_ENTITY_TYPE = "type";
const PATTERN_ENTITY_NAME = "name";
const PATTERN_ENTITY_LOCATION = "location";

protected ?string $matchedPattern = null;

protected ?string $type = null;
protected ?string $name = null;
protected ?float $locationX = null;
protected ?float $locationY = null;
protected ?float $locationZ = null;

public function getMessage(): string
{
return Translator::getInstance()->getTranslation("ticking-entity-problem", [
"name" => $this->getName(),
"location" => $this->getLocationX() . ", " . $this->getLocationY() . ", " . $this->getLocationZ()
]);
}

/**
* @return string[]
*/
public static function getPatterns(): array
{
return [
static::PATTERN_DESCRIPTION => "/^Description: Ticking entity$/",
static::PATTERN_ENTITY_TYPE => "/Entity Type: ([\w:_]+)/",
static::PATTERN_ENTITY_NAME => "/Entity Name: (.+)/",
static::PATTERN_ENTITY_LOCATION => "/Entity's Exact location: (-?[\d.]+), (-?[\d.]+), (-?[\d.]+)/"
];
}

public function setMatches(array $matches, $patternKey): void
{
$this->matchedPattern = $patternKey;
switch ($patternKey) {
case static::PATTERN_ENTITY_TYPE:
$this->type = $matches[1];
break;
case static::PATTERN_ENTITY_NAME:
$this->name = $matches[1];
break;
case static::PATTERN_ENTITY_LOCATION:
$this->locationX = (float)$matches[1];
$this->locationY = (float)$matches[2];
$this->locationZ = (float)$matches[3];
break;
}

$this->addSolution(new RemoveEntitySolution());
$this->updateSolution();
}

/**
* @return void
*/
protected function updateSolution(): void
{
$this->solutions[0]->setName($this->getName());
$this->solutions[0]->setLocationX($this->getLocationX());
$this->solutions[0]->setLocationY($this->getLocationY());
$this->solutions[0]->setLocationZ($this->getLocationZ());
}

/**
* @param $insight
* @return bool
*/
public function isEqual($insight): bool
{
if ($insight instanceof TickingEntityProblem) {
$this->addInformationFromProblem($insight);
return true;
}
return parent::isEqual($insight);
}

/**
* @return string|null
*/
public function getType(): ?string
{
return $this->type;
}

/**
* @return string|null
*/
public function getName(): ?string
{
return $this->name;
}

/**
* @return float|null
*/
public function getLocationX(): ?float
{
return $this->locationX;
}

/**
* @return float|null
*/
public function getLocationY(): ?float
{
return $this->locationY;
}

/**
* @return float|null
*/
public function getLocationZ(): ?float
{
return $this->locationZ;
}

/**
* @param static $problem
* @return void
*/
public function addInformationFromProblem(TickingEntityProblem $problem): void
{
if ($problem->getName() !== null) {
$this->name = $problem->getName();
}
if ($problem->getType() !== null) {
$this->type = $problem->getType();
}
if ($problem->getLocationX() !== null) {
$this->locationX = $problem->getLocationX();
}
if ($problem->getLocationY() !== null) {
$this->locationY = $problem->getLocationY();
}
if ($problem->getLocationZ() !== null) {
$this->locationZ = $problem->getLocationZ();
}
$this->updateSolution();
}

}
8 changes: 8 additions & 0 deletions src/Analysis/Solution/CrashReport/CrashReportSolution.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Aternos\Codex\Minecraft\Analysis\Solution\CrashReport;

abstract class CrashReportSolution extends \Aternos\Codex\Minecraft\Analysis\Solution\MinecraftSolution
{

}
96 changes: 96 additions & 0 deletions src/Analysis/Solution/CrashReport/RemoveEntitySolution.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?php

namespace Aternos\Codex\Minecraft\Analysis\Solution\CrashReport;

use Aternos\Codex\Minecraft\Translator\Translator;

class RemoveEntitySolution extends CrashReportSolution
{
protected ?string $name;
protected ?float $locationX;
protected ?float $locationY;
protected ?float $locationZ;

/**
* @inheritDoc
*/
public function getMessage(): string
{
return Translator::getInstance()->getTranslation("remove-entity-solution", [
"name" => $this->getName(),
"location" => $this->getLocationX() . ", " . $this->getLocationY() . ", " . $this->getLocationZ()
]);
}

/**
* @return string|null
*/
public function getName(): ?string
{
return $this->name;
}

/**
* @param string|null $name
* @return $this
*/
public function setName(?string $name): RemoveEntitySolution
{
$this->name = $name;
return $this;
}

/**
* @return float|null
*/
public function getLocationX(): ?float
{
return $this->locationX;
}

/**
* @param float|null $locationX
* @return $this
*/
public function setLocationX(?float $locationX): RemoveEntitySolution
{
$this->locationX = $locationX;
return $this;
}

/**
* @return float|null
*/
public function getLocationY(): ?float
{
return $this->locationY;
}

/**
* @param float|null $locationY
* @return $this
*/
public function setLocationY(?float $locationY): RemoveEntitySolution
{
$this->locationY = $locationY;
return $this;
}

/**
* @return float|null
*/
public function getLocationZ(): ?float
{
return $this->locationZ;
}

/**
* @param float|null $locationZ
* @return $this
*/
public function setLocationZ(?float $locationZ): RemoveEntitySolution
{
$this->locationZ = $locationZ;
return $this;
}
}
1 change: 1 addition & 0 deletions src/Log/CrashReport/ForgeCrashReportLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

class ForgeCrashReportLog extends MinecraftCrashReportLog
{

public function getSoftware(): string
{
return "Forge";
Expand Down
Loading

0 comments on commit 63c4dc8

Please sign in to comment.