1
+ <?php
2
+
3
+ namespace Aternos \Codex \Minecraft \Analysis \Problem \CrashReport ;
4
+
5
+ use Aternos \Codex \Minecraft \Analysis \Solution \CrashReport \RemoveEntitySolution ;
6
+ use Aternos \Codex \Minecraft \Translator \Translator ;
7
+
8
+ class TickingEntityProblem extends CrashReportProblem
9
+ {
10
+ const PATTERN_DESCRIPTION = "description " ;
11
+ const PATTERN_ENTITY_TYPE = "type " ;
12
+ const PATTERN_ENTITY_NAME = "name " ;
13
+ const PATTERN_ENTITY_LOCATION = "location " ;
14
+
15
+ protected ?string $ matchedPattern = null ;
16
+
17
+ protected ?string $ type = null ;
18
+ protected ?string $ name = null ;
19
+ protected ?float $ locationX = null ;
20
+ protected ?float $ locationY = null ;
21
+ protected ?float $ locationZ = null ;
22
+
23
+ public function getMessage (): string
24
+ {
25
+ return Translator::getInstance ()->getTranslation ("ticking-entity-problem " , [
26
+ "name " => $ this ->getName (),
27
+ "location " => $ this ->getLocationX () . ", " . $ this ->getLocationY () . ", " . $ this ->getLocationZ ()
28
+ ]);
29
+ }
30
+
31
+ /**
32
+ * @return string[]
33
+ */
34
+ public static function getPatterns (): array
35
+ {
36
+ return [
37
+ static ::PATTERN_DESCRIPTION => "/^Description: Ticking entity$/ " ,
38
+ static ::PATTERN_ENTITY_TYPE => "/Entity Type: ([\w:_]+)/ " ,
39
+ static ::PATTERN_ENTITY_NAME => "/Entity Name: (.+)/ " ,
40
+ static ::PATTERN_ENTITY_LOCATION => "/Entity's Exact location: (-?[\d.]+), (-?[\d.]+), (-?[\d.]+)/ "
41
+ ];
42
+ }
43
+
44
+ public function setMatches (array $ matches , $ patternKey ): void
45
+ {
46
+ $ this ->matchedPattern = $ patternKey ;
47
+ switch ($ patternKey ) {
48
+ case static ::PATTERN_ENTITY_TYPE :
49
+ $ this ->type = $ matches [1 ];
50
+ break ;
51
+ case static ::PATTERN_ENTITY_NAME :
52
+ $ this ->name = $ matches [1 ];
53
+ break ;
54
+ case static ::PATTERN_ENTITY_LOCATION :
55
+ $ this ->locationX = (float )$ matches [1 ];
56
+ $ this ->locationY = (float )$ matches [2 ];
57
+ $ this ->locationZ = (float )$ matches [3 ];
58
+ break ;
59
+ }
60
+
61
+ $ this ->addSolution (new RemoveEntitySolution ());
62
+ $ this ->updateSolution ();
63
+ }
64
+
65
+ /**
66
+ * @return void
67
+ */
68
+ protected function updateSolution (): void
69
+ {
70
+ $ this ->solutions [0 ]->setName ($ this ->getName ());
71
+ $ this ->solutions [0 ]->setLocationX ($ this ->getLocationX ());
72
+ $ this ->solutions [0 ]->setLocationY ($ this ->getLocationY ());
73
+ $ this ->solutions [0 ]->setLocationZ ($ this ->getLocationZ ());
74
+ }
75
+
76
+ /**
77
+ * @param $insight
78
+ * @return bool
79
+ */
80
+ public function isEqual ($ insight ): bool
81
+ {
82
+ if ($ insight instanceof TickingEntityProblem) {
83
+ $ this ->addInformationFromProblem ($ insight );
84
+ return true ;
85
+ }
86
+ return parent ::isEqual ($ insight );
87
+ }
88
+
89
+ /**
90
+ * @return string|null
91
+ */
92
+ public function getType (): ?string
93
+ {
94
+ return $ this ->type ;
95
+ }
96
+
97
+ /**
98
+ * @return string|null
99
+ */
100
+ public function getName (): ?string
101
+ {
102
+ return $ this ->name ;
103
+ }
104
+
105
+ /**
106
+ * @return float|null
107
+ */
108
+ public function getLocationX (): ?float
109
+ {
110
+ return $ this ->locationX ;
111
+ }
112
+
113
+ /**
114
+ * @return float|null
115
+ */
116
+ public function getLocationY (): ?float
117
+ {
118
+ return $ this ->locationY ;
119
+ }
120
+
121
+ /**
122
+ * @return float|null
123
+ */
124
+ public function getLocationZ (): ?float
125
+ {
126
+ return $ this ->locationZ ;
127
+ }
128
+
129
+ /**
130
+ * @param static $problem
131
+ * @return void
132
+ */
133
+ public function addInformationFromProblem (TickingEntityProblem $ problem ): void
134
+ {
135
+ if ($ problem ->getName () !== null ) {
136
+ $ this ->name = $ problem ->getName ();
137
+ }
138
+ if ($ problem ->getType () !== null ) {
139
+ $ this ->type = $ problem ->getType ();
140
+ }
141
+ if ($ problem ->getLocationX () !== null ) {
142
+ $ this ->locationX = $ problem ->getLocationX ();
143
+ }
144
+ if ($ problem ->getLocationY () !== null ) {
145
+ $ this ->locationY = $ problem ->getLocationY ();
146
+ }
147
+ if ($ problem ->getLocationZ () !== null ) {
148
+ $ this ->locationZ = $ problem ->getLocationZ ();
149
+ }
150
+ $ this ->updateSolution ();
151
+ }
152
+
153
+ }
0 commit comments