Skip to content

Commit 874a5d1

Browse files
authored
Merge pull request #91 from aternosorg/fix-paper-remapped-paths
Remove ".paper-remapped/" from plugin path
2 parents 7e72b14 + 56e0568 commit 874a5d1

36 files changed

+4754
-221
lines changed

src/Analysis/Problem/Bukkit/AmbiguousPluginNameProblem.php

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@
1111
*
1212
* @package Aternos\Codex\Minecraft\Analysis\Problem\Bukkit
1313
*/
14-
class AmbiguousPluginNameProblem extends BukkitProblem
14+
class AmbiguousPluginNameProblem extends PluginProblem
1515
{
1616
protected ?string $firstPluginPath = null;
1717
protected ?string $secondPluginPath = null;
18-
protected ?string $pluginName = null;
1918

2019
/**
2120
* Get a human-readable message
@@ -62,8 +61,8 @@ public static function getPatterns(): array
6261
public function setMatches(array $matches, mixed $patternKey): void
6362
{
6463
$this->pluginName = $matches[1];
65-
$this->firstPluginPath = $matches[2];
66-
$this->secondPluginPath = $matches[3];
64+
$this->firstPluginPath = $this->correctPluginPath($matches[2]);
65+
$this->secondPluginPath = $this->correctPluginPath($matches[3]);
6766

6867
$this->addSolution((new FileDeleteSolution())->setRelativePath($this->getFirstPluginPath()));
6968
$this->addSolution((new FileDeleteSolution())->setRelativePath($this->getSecondPluginPath()));
@@ -85,14 +84,6 @@ public function getSecondPluginPath(): string
8584
return $this->secondPluginPath;
8685
}
8786

88-
/**
89-
* @return string
90-
*/
91-
public function getPluginName(): string
92-
{
93-
return $this->pluginName;
94-
}
95-
9687
/**
9788
* @param InsightInterface $insight
9889
* @return bool

src/Analysis/Problem/Bukkit/PluginDependenciesProblem.php

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Aternos\Codex\Minecraft\Analysis\Problem\Bukkit;
44

55
use Aternos\Codex\Analysis\InsightInterface;
6+
use Aternos\Codex\Minecraft\Analysis\Solution\Bukkit\PluginInstallDifferentVersionSolution;
67
use Aternos\Codex\Minecraft\Analysis\Solution\Bukkit\PluginInstallSolution;
78
use Aternos\Codex\Minecraft\Analysis\Solution\File\FileDeleteSolution;
89
use Aternos\Codex\Minecraft\Translator\Translator;
@@ -12,32 +13,13 @@
1213
*
1314
* @package Aternos\Codex\Minecraft\Analysis\Problem\Bukkit
1415
*/
15-
class PluginDependenciesProblem extends BukkitProblem
16+
class PluginDependenciesProblem extends PluginFileProblem
1617
{
17-
protected ?string $pluginPath = null;
18-
protected ?string $pluginName = null;
19-
2018
/**
2119
* @var string[]
2220
*/
2321
protected array $dependencyPluginNames = [];
2422

25-
/**
26-
* @return string|null
27-
*/
28-
public function getPluginPath(): ?string
29-
{
30-
return $this->pluginPath;
31-
}
32-
33-
/**
34-
* @return string|null
35-
*/
36-
public function getPluginName(): ?string
37-
{
38-
return $this->pluginName;
39-
}
40-
4123
/**
4224
* get a list of missing dependencies
4325
* @return string[]
@@ -89,8 +71,9 @@ public function getMessage(): string
8971
public static function getPatterns(): array
9072
{
9173
return [
92-
'/Could not load \'(plugins[\/\\\]((?!\.jar).*)\.jar)\' in (?:folder )?\'[^\']+\''
93-
. '\norg\.bukkit\.plugin\.UnknownDependencyException\: Unknown\/missing dependency plugins: \[([\w ,]+)\]/'];
74+
'/Could not load \'(plugins[\/\\\][^\']+\.jar)\' in (?:folder )?\'([^\']+)\''
75+
. '\norg\.bukkit\.plugin\.UnknownDependencyException\: Unknown\/missing dependency plugins: \[([\w ,]+)\](?:\. Please download and install these plugins to run \'([^\']+)\')?/'
76+
];
9477
}
9578

9679
/**
@@ -102,14 +85,19 @@ public static function getPatterns(): array
10285
*/
10386
public function setMatches(array $matches, mixed $patternKey): void
10487
{
105-
$this->pluginPath = $matches[1];
106-
$this->pluginName = $matches[2];
107-
$this->dependencyPluginNames = preg_split("/, ?/", $matches[3]);
88+
if ($matches[4]) {
89+
$this->pluginName = $matches[4];
90+
$this->pluginFilePath = $this->correctPluginPath($matches[1]);
91+
$this->addSolution((new PluginInstallDifferentVersionSolution())->setPluginName($this->getPluginName()));
92+
$this->addSolution((new FileDeleteSolution())->setRelativePath($this->getPluginFilePath()));
93+
} else {
94+
parent::setMatches($matches, $patternKey);
95+
}
10896

97+
$this->dependencyPluginNames = preg_split("/, ?/", $matches[3]);
10998
foreach ($this->dependencyPluginNames as $name) {
11099
$this->addSolution((new PluginInstallSolution())->setPluginName($name));
111100
}
112-
$this->addSolution((new FileDeleteSolution())->setRelativePath($this->getPluginPath()));
113101
}
114102

115103
/**
@@ -122,7 +110,7 @@ public function isEqual(InsightInterface $insight): bool
122110
return false;
123111
}
124112

125-
if ($this->getPluginName() !== $insight->getPluginName() || $this->getPluginPath() !== $insight->getPluginPath()) {
113+
if ($this->getPluginName() !== $insight->getPluginName()) {
126114
return false;
127115
}
128116

src/Analysis/Problem/Bukkit/PluginDependencyProblem.php

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,17 @@
44

55
use Aternos\Codex\Analysis\InsightInterface;
66
use Aternos\Codex\Minecraft\Analysis\Solution\Bukkit\PluginInstallSolution;
7-
use Aternos\Codex\Minecraft\Analysis\Solution\File\FileDeleteSolution;
87
use Aternos\Codex\Minecraft\Translator\Translator;
98

109
/**
1110
* Class PluginDependencyProblem
1211
*
1312
* @package Aternos\Codex\Minecraft\Analysis\Problem\Bukkit
1413
*/
15-
class PluginDependencyProblem extends BukkitProblem
14+
class PluginDependencyProblem extends PluginFileProblem
1615
{
17-
protected ?string $pluginPath = null;
18-
protected ?string $pluginName = null;
1916
protected ?string $dependencyPluginName = null;
2017

21-
/**
22-
* @return string|null
23-
*/
24-
public function getPluginPath(): ?string
25-
{
26-
return $this->pluginPath;
27-
}
28-
29-
/**
30-
* @return string|null
31-
*/
32-
public function getPluginName(): ?string
33-
{
34-
return $this->pluginName;
35-
}
36-
3718
/**
3819
* @return string|null
3920
*/
@@ -65,7 +46,7 @@ public function getMessage(): string
6546
public static function getPatterns(): array
6647
{
6748
return [
68-
'/Could not load \'(plugins[\/\\\]((?!\.jar).*)\.jar)\' in (?:folder )?\'[^\']+\''
49+
'/Could not load \'(plugins[\/\\\][^\']+\.jar)\' in (?:folder )?\'([^\']+)\''
6950
. '\norg\.bukkit\.plugin\.UnknownDependencyException\: (?:(\w+)\n|Unknown dependency (\w+)\.)/'];
7051
}
7152

@@ -78,12 +59,10 @@ public static function getPatterns(): array
7859
*/
7960
public function setMatches(array $matches, mixed $patternKey): void
8061
{
81-
$this->pluginPath = $matches[1];
82-
$this->pluginName = $matches[2];
83-
$this->dependencyPluginName = $matches[3] ?: $matches[4];
62+
parent::setMatches($matches, $patternKey);
8463

64+
$this->dependencyPluginName = $matches[3] ?: $matches[4];
8565
$this->addSolution((new PluginInstallSolution())->setPluginName($this->getDependencyPluginName()));
86-
$this->addSolution((new FileDeleteSolution())->setRelativePath($this->getPluginPath()));
8766
}
8867

8968
/**
@@ -94,7 +73,6 @@ public function isEqual(InsightInterface $insight): bool
9473
{
9574
return $insight instanceof static
9675
&& $this->getPluginName() === $insight->getPluginName()
97-
&& $this->getPluginPath() === $insight->getPluginPath()
9876
&& $this->getDependencyPluginName() === $insight->getDependencyPluginName();
9977
}
10078
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
namespace Aternos\Codex\Minecraft\Analysis\Problem\Bukkit;
4+
5+
use Aternos\Codex\Analysis\InsightInterface;
6+
use Aternos\Codex\Minecraft\Analysis\Solution\Bukkit\PluginInstallDifferentVersionSolution;
7+
use Aternos\Codex\Minecraft\Analysis\Solution\File\FileDeleteSolution;
8+
9+
/**
10+
* Class PluginFileProblem
11+
*
12+
* Represents a problem with a Bukkit plugin file and provides:
13+
* - The plugins' file path {@see PluginFileProblem::getPluginFilePath()}
14+
* - {@link PluginInstallDifferentVersionSolution} and {@link FileDeleteSolution}
15+
* - All features from {@link PluginProblem} (extends {@link PluginProblem})
16+
*
17+
* @package Aternos\Codex\Minecraft\Analysis\Problem\Bukkit
18+
*/
19+
abstract class PluginFileProblem extends PluginProblem
20+
{
21+
protected ?string $pluginFilePath = null;
22+
23+
/**
24+
* @return string|null
25+
*/
26+
public function getPluginFilePath(): ?string
27+
{
28+
return $this->pluginFilePath;
29+
}
30+
31+
/**
32+
* Apply the matches from the pattern
33+
*
34+
* @param array $matches
35+
* @param mixed $patternKey
36+
* @return void
37+
*/
38+
public function setMatches(array $matches, mixed $patternKey): void
39+
{
40+
// worldedit-bukkit-7.3.4-beta-01.jar OR .paper-remapped/worldedit-bukkit-7.3.4-beta-01.jar
41+
$pluginFileName = $this->extractPluginFileName($matches[1]);
42+
// plugins OR plugins/.paper-remapped
43+
$folderPath = $this->correctPluginPath($matches[2]);
44+
45+
$this->pluginFilePath = $folderPath . '/' . $pluginFileName;
46+
$this->pluginName = $this->extractPluginName($matches[1]);
47+
48+
$this->addSolution((new PluginInstallDifferentVersionSolution())->setPluginName($this->getPluginName()));
49+
$this->addSolution((new FileDeleteSolution())->setRelativePath($this->getPluginFilePath()));
50+
}
51+
52+
/**
53+
* @param InsightInterface $insight
54+
* @return bool
55+
*/
56+
public function isEqual(InsightInterface $insight): bool
57+
{
58+
return parent::isEqual($insight)
59+
&& $insight instanceof static
60+
&& $this->getPluginFilePath() === $insight->getPluginFilePath();
61+
}
62+
63+
}

src/Analysis/Problem/Bukkit/PluginLoadProblem.php

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,15 @@
22

33
namespace Aternos\Codex\Minecraft\Analysis\Problem\Bukkit;
44

5-
use Aternos\Codex\Analysis\InsightInterface;
6-
use Aternos\Codex\Minecraft\Analysis\Solution\Bukkit\PluginInstallDifferentVersionSolution;
7-
use Aternos\Codex\Minecraft\Analysis\Solution\File\FileDeleteSolution;
85
use Aternos\Codex\Minecraft\Translator\Translator;
96

107
/**
118
* Class PluginLoadProblem
129
*
1310
* @package Aternos\Codex\Minecraft\Analysis\Problem\Bukkit
1411
*/
15-
class PluginLoadProblem extends PluginProblem
12+
class PluginLoadProblem extends PluginFileProblem
1613
{
17-
protected ?string $pluginPath = null;
18-
1914
/**
2015
* Get a human-readable message
2116
*
@@ -36,43 +31,8 @@ public function getMessage(): string
3631
public static function getPatterns(): array
3732
{
3833
return [
39-
'/Could not load \'(plugins[\/\\\]((?!\.jar).*)\.jar)\' in folder \'[^\']+\''
34+
'/Could not load \'(plugins[\/\\\][^\']+\.jar)\' in (?:folder )?\'([^\']+)\''
4035
. '(?!\n(org.bukkit.plugin.UnknownDependencyException|org.bukkit.plugin.InvalidPluginException\: (Unsupported API version|java\.lang\.UnsupportedClassVersionError)))/'
4136
];
4237
}
43-
44-
/**
45-
* Apply the matches from the pattern
46-
*
47-
* @param array $matches
48-
* @param mixed $patternKey
49-
* @return void
50-
*/
51-
public function setMatches(array $matches, mixed $patternKey): void
52-
{
53-
$this->pluginPath = $matches[1];
54-
$this->pluginName = $matches[2];
55-
56-
$this->addSolution((new PluginInstallDifferentVersionSolution())->setPluginName($this->getPluginName()));
57-
$this->addSolution((new FileDeleteSolution())->setRelativePath($this->getPluginPath()));
58-
}
59-
60-
/**
61-
* @return string|null
62-
*/
63-
public function getPluginPath(): ?string
64-
{
65-
return $this->pluginPath;
66-
}
67-
68-
/**
69-
* @param InsightInterface $insight
70-
* @return bool
71-
*/
72-
public function isEqual(InsightInterface $insight): bool
73-
{
74-
return $insight instanceof static
75-
&& $this->getPluginPath() === $insight->getPluginPath()
76-
&& parent::isEqual($insight);
77-
}
7838
}

src/Analysis/Problem/Bukkit/PluginProblem.php

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@
99
/**
1010
* Class PluginProblem
1111
*
12+
* Represents a problem with a Bukkit plugin and provides:
13+
* - The plugin name {@see PluginProblem::getPluginName()}
14+
* - {@link PluginInstallDifferentVersionSolution} and {@link PluginRemoveSolution}
15+
* - Utility function to correct the plugin path {@see PluginProblem::correctPluginPath()}
16+
* - Utility function to extract the plugin name (without the file extension) from a plugin path {@see PluginProblem::extractPluginName()}
17+
* - Utility function to extract the file name (with the file extension) from a plugin path {@see PluginProblem::extractPluginFileName()}
18+
*
1219
* @package Aternos\Codex\Minecraft\Analysis\Problem\Bukkit
1320
*/
1421
abstract class PluginProblem extends BukkitProblem
@@ -32,7 +39,7 @@ public function getPluginName(): ?string
3239
*/
3340
public function setMatches(array $matches, mixed $patternKey): void
3441
{
35-
$this->pluginName = $matches[1];
42+
$this->pluginName = $this->extractPluginName($matches[1]);
3643

3744
$this->addSolution((new PluginInstallDifferentVersionSolution())->setPluginName($this->getPluginName()));
3845
$this->addSolution((new PluginRemoveSolution())->setPluginName($this->getPluginName()));
@@ -44,6 +51,40 @@ public function setMatches(array $matches, mixed $patternKey): void
4451
*/
4552
public function isEqual(InsightInterface $insight): bool
4653
{
47-
return $insight instanceof static && $this->getPluginName() === $insight->getPluginName();
54+
return $insight instanceof static
55+
&& $this->getPluginName() === $insight->getPluginName();
56+
}
57+
58+
/**
59+
* Corrects the plugin path by removing the ".paper-remapped" part
60+
*
61+
* @param string $pluginPath
62+
* @return string
63+
*/
64+
protected function correctPluginPath(string $pluginPath): string
65+
{
66+
return str_replace("plugins/.paper-remapped", "plugins", $pluginPath);
67+
}
68+
69+
/**
70+
* Extracts the plugin name without the file extension (usually .jar) from a plugin path
71+
*
72+
* @param string $pluginPath
73+
* @return string
74+
*/
75+
protected function extractPluginName(string $pluginPath): string
76+
{
77+
return pathinfo($pluginPath, PATHINFO_FILENAME);
78+
}
79+
80+
/**
81+
* Extracts the plugin file name including the file extension (usually .jar) from a plugin path
82+
*
83+
* @param string $pluginPath
84+
* @return string
85+
*/
86+
protected function extractPluginFileName(string $pluginPath): string
87+
{
88+
return pathinfo($pluginPath, PATHINFO_BASENAME);
4889
}
4990
}

0 commit comments

Comments
 (0)