Skip to content

Commit

Permalink
Merge pull request #91 from aternosorg/fix-paper-remapped-paths
Browse files Browse the repository at this point in the history
Remove ".paper-remapped/" from plugin path
  • Loading branch information
pavog authored Oct 18, 2024
2 parents 7e72b14 + 56e0568 commit 874a5d1
Show file tree
Hide file tree
Showing 36 changed files with 4,754 additions and 221 deletions.
15 changes: 3 additions & 12 deletions src/Analysis/Problem/Bukkit/AmbiguousPluginNameProblem.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@
*
* @package Aternos\Codex\Minecraft\Analysis\Problem\Bukkit
*/
class AmbiguousPluginNameProblem extends BukkitProblem
class AmbiguousPluginNameProblem extends PluginProblem
{
protected ?string $firstPluginPath = null;
protected ?string $secondPluginPath = null;
protected ?string $pluginName = null;

/**
* Get a human-readable message
Expand Down Expand Up @@ -62,8 +61,8 @@ public static function getPatterns(): array
public function setMatches(array $matches, mixed $patternKey): void
{
$this->pluginName = $matches[1];
$this->firstPluginPath = $matches[2];
$this->secondPluginPath = $matches[3];
$this->firstPluginPath = $this->correctPluginPath($matches[2]);
$this->secondPluginPath = $this->correctPluginPath($matches[3]);

$this->addSolution((new FileDeleteSolution())->setRelativePath($this->getFirstPluginPath()));
$this->addSolution((new FileDeleteSolution())->setRelativePath($this->getSecondPluginPath()));
Expand All @@ -85,14 +84,6 @@ public function getSecondPluginPath(): string
return $this->secondPluginPath;
}

/**
* @return string
*/
public function getPluginName(): string
{
return $this->pluginName;
}

/**
* @param InsightInterface $insight
* @return bool
Expand Down
42 changes: 15 additions & 27 deletions src/Analysis/Problem/Bukkit/PluginDependenciesProblem.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Aternos\Codex\Minecraft\Analysis\Problem\Bukkit;

use Aternos\Codex\Analysis\InsightInterface;
use Aternos\Codex\Minecraft\Analysis\Solution\Bukkit\PluginInstallDifferentVersionSolution;
use Aternos\Codex\Minecraft\Analysis\Solution\Bukkit\PluginInstallSolution;
use Aternos\Codex\Minecraft\Analysis\Solution\File\FileDeleteSolution;
use Aternos\Codex\Minecraft\Translator\Translator;
Expand All @@ -12,32 +13,13 @@
*
* @package Aternos\Codex\Minecraft\Analysis\Problem\Bukkit
*/
class PluginDependenciesProblem extends BukkitProblem
class PluginDependenciesProblem extends PluginFileProblem
{
protected ?string $pluginPath = null;
protected ?string $pluginName = null;

/**
* @var string[]
*/
protected array $dependencyPluginNames = [];

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

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

/**
* get a list of missing dependencies
* @return string[]
Expand Down Expand Up @@ -89,8 +71,9 @@ public function getMessage(): string
public static function getPatterns(): array
{
return [
'/Could not load \'(plugins[\/\\\]((?!\.jar).*)\.jar)\' in (?:folder )?\'[^\']+\''
. '\norg\.bukkit\.plugin\.UnknownDependencyException\: Unknown\/missing dependency plugins: \[([\w ,]+)\]/'];
'/Could not load \'(plugins[\/\\\][^\']+\.jar)\' in (?:folder )?\'([^\']+)\''
. '\norg\.bukkit\.plugin\.UnknownDependencyException\: Unknown\/missing dependency plugins: \[([\w ,]+)\](?:\. Please download and install these plugins to run \'([^\']+)\')?/'
];
}

/**
Expand All @@ -102,14 +85,19 @@ public static function getPatterns(): array
*/
public function setMatches(array $matches, mixed $patternKey): void
{
$this->pluginPath = $matches[1];
$this->pluginName = $matches[2];
$this->dependencyPluginNames = preg_split("/, ?/", $matches[3]);
if ($matches[4]) {
$this->pluginName = $matches[4];
$this->pluginFilePath = $this->correctPluginPath($matches[1]);
$this->addSolution((new PluginInstallDifferentVersionSolution())->setPluginName($this->getPluginName()));
$this->addSolution((new FileDeleteSolution())->setRelativePath($this->getPluginFilePath()));
} else {
parent::setMatches($matches, $patternKey);
}

$this->dependencyPluginNames = preg_split("/, ?/", $matches[3]);
foreach ($this->dependencyPluginNames as $name) {
$this->addSolution((new PluginInstallSolution())->setPluginName($name));
}
$this->addSolution((new FileDeleteSolution())->setRelativePath($this->getPluginPath()));
}

/**
Expand All @@ -122,7 +110,7 @@ public function isEqual(InsightInterface $insight): bool
return false;
}

if ($this->getPluginName() !== $insight->getPluginName() || $this->getPluginPath() !== $insight->getPluginPath()) {
if ($this->getPluginName() !== $insight->getPluginName()) {
return false;
}

Expand Down
30 changes: 4 additions & 26 deletions src/Analysis/Problem/Bukkit/PluginDependencyProblem.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,17 @@

use Aternos\Codex\Analysis\InsightInterface;
use Aternos\Codex\Minecraft\Analysis\Solution\Bukkit\PluginInstallSolution;
use Aternos\Codex\Minecraft\Analysis\Solution\File\FileDeleteSolution;
use Aternos\Codex\Minecraft\Translator\Translator;

/**
* Class PluginDependencyProblem
*
* @package Aternos\Codex\Minecraft\Analysis\Problem\Bukkit
*/
class PluginDependencyProblem extends BukkitProblem
class PluginDependencyProblem extends PluginFileProblem
{
protected ?string $pluginPath = null;
protected ?string $pluginName = null;
protected ?string $dependencyPluginName = null;

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

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

/**
* @return string|null
*/
Expand Down Expand Up @@ -65,7 +46,7 @@ public function getMessage(): string
public static function getPatterns(): array
{
return [
'/Could not load \'(plugins[\/\\\]((?!\.jar).*)\.jar)\' in (?:folder )?\'[^\']+\''
'/Could not load \'(plugins[\/\\\][^\']+\.jar)\' in (?:folder )?\'([^\']+)\''
. '\norg\.bukkit\.plugin\.UnknownDependencyException\: (?:(\w+)\n|Unknown dependency (\w+)\.)/'];
}

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

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

/**
Expand All @@ -94,7 +73,6 @@ public function isEqual(InsightInterface $insight): bool
{
return $insight instanceof static
&& $this->getPluginName() === $insight->getPluginName()
&& $this->getPluginPath() === $insight->getPluginPath()
&& $this->getDependencyPluginName() === $insight->getDependencyPluginName();
}
}
63 changes: 63 additions & 0 deletions src/Analysis/Problem/Bukkit/PluginFileProblem.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

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

use Aternos\Codex\Analysis\InsightInterface;
use Aternos\Codex\Minecraft\Analysis\Solution\Bukkit\PluginInstallDifferentVersionSolution;
use Aternos\Codex\Minecraft\Analysis\Solution\File\FileDeleteSolution;

/**
* Class PluginFileProblem
*
* Represents a problem with a Bukkit plugin file and provides:
* - The plugins' file path {@see PluginFileProblem::getPluginFilePath()}
* - {@link PluginInstallDifferentVersionSolution} and {@link FileDeleteSolution}
* - All features from {@link PluginProblem} (extends {@link PluginProblem})
*
* @package Aternos\Codex\Minecraft\Analysis\Problem\Bukkit
*/
abstract class PluginFileProblem extends PluginProblem
{
protected ?string $pluginFilePath = null;

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

/**
* Apply the matches from the pattern
*
* @param array $matches
* @param mixed $patternKey
* @return void
*/
public function setMatches(array $matches, mixed $patternKey): void
{
// worldedit-bukkit-7.3.4-beta-01.jar OR .paper-remapped/worldedit-bukkit-7.3.4-beta-01.jar
$pluginFileName = $this->extractPluginFileName($matches[1]);
// plugins OR plugins/.paper-remapped
$folderPath = $this->correctPluginPath($matches[2]);

$this->pluginFilePath = $folderPath . '/' . $pluginFileName;
$this->pluginName = $this->extractPluginName($matches[1]);

$this->addSolution((new PluginInstallDifferentVersionSolution())->setPluginName($this->getPluginName()));
$this->addSolution((new FileDeleteSolution())->setRelativePath($this->getPluginFilePath()));
}

/**
* @param InsightInterface $insight
* @return bool
*/
public function isEqual(InsightInterface $insight): bool
{
return parent::isEqual($insight)
&& $insight instanceof static
&& $this->getPluginFilePath() === $insight->getPluginFilePath();
}

}
44 changes: 2 additions & 42 deletions src/Analysis/Problem/Bukkit/PluginLoadProblem.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,15 @@

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

use Aternos\Codex\Analysis\InsightInterface;
use Aternos\Codex\Minecraft\Analysis\Solution\Bukkit\PluginInstallDifferentVersionSolution;
use Aternos\Codex\Minecraft\Analysis\Solution\File\FileDeleteSolution;
use Aternos\Codex\Minecraft\Translator\Translator;

/**
* Class PluginLoadProblem
*
* @package Aternos\Codex\Minecraft\Analysis\Problem\Bukkit
*/
class PluginLoadProblem extends PluginProblem
class PluginLoadProblem extends PluginFileProblem
{
protected ?string $pluginPath = null;

/**
* Get a human-readable message
*
Expand All @@ -36,43 +31,8 @@ public function getMessage(): string
public static function getPatterns(): array
{
return [
'/Could not load \'(plugins[\/\\\]((?!\.jar).*)\.jar)\' in folder \'[^\']+\''
'/Could not load \'(plugins[\/\\\][^\']+\.jar)\' in (?:folder )?\'([^\']+)\''
. '(?!\n(org.bukkit.plugin.UnknownDependencyException|org.bukkit.plugin.InvalidPluginException\: (Unsupported API version|java\.lang\.UnsupportedClassVersionError)))/'
];
}

/**
* Apply the matches from the pattern
*
* @param array $matches
* @param mixed $patternKey
* @return void
*/
public function setMatches(array $matches, mixed $patternKey): void
{
$this->pluginPath = $matches[1];
$this->pluginName = $matches[2];

$this->addSolution((new PluginInstallDifferentVersionSolution())->setPluginName($this->getPluginName()));
$this->addSolution((new FileDeleteSolution())->setRelativePath($this->getPluginPath()));
}

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

/**
* @param InsightInterface $insight
* @return bool
*/
public function isEqual(InsightInterface $insight): bool
{
return $insight instanceof static
&& $this->getPluginPath() === $insight->getPluginPath()
&& parent::isEqual($insight);
}
}
45 changes: 43 additions & 2 deletions src/Analysis/Problem/Bukkit/PluginProblem.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@
/**
* Class PluginProblem
*
* Represents a problem with a Bukkit plugin and provides:
* - The plugin name {@see PluginProblem::getPluginName()}
* - {@link PluginInstallDifferentVersionSolution} and {@link PluginRemoveSolution}
* - Utility function to correct the plugin path {@see PluginProblem::correctPluginPath()}
* - Utility function to extract the plugin name (without the file extension) from a plugin path {@see PluginProblem::extractPluginName()}
* - Utility function to extract the file name (with the file extension) from a plugin path {@see PluginProblem::extractPluginFileName()}
*
* @package Aternos\Codex\Minecraft\Analysis\Problem\Bukkit
*/
abstract class PluginProblem extends BukkitProblem
Expand All @@ -32,7 +39,7 @@ public function getPluginName(): ?string
*/
public function setMatches(array $matches, mixed $patternKey): void
{
$this->pluginName = $matches[1];
$this->pluginName = $this->extractPluginName($matches[1]);

$this->addSolution((new PluginInstallDifferentVersionSolution())->setPluginName($this->getPluginName()));
$this->addSolution((new PluginRemoveSolution())->setPluginName($this->getPluginName()));
Expand All @@ -44,6 +51,40 @@ public function setMatches(array $matches, mixed $patternKey): void
*/
public function isEqual(InsightInterface $insight): bool
{
return $insight instanceof static && $this->getPluginName() === $insight->getPluginName();
return $insight instanceof static
&& $this->getPluginName() === $insight->getPluginName();
}

/**
* Corrects the plugin path by removing the ".paper-remapped" part
*
* @param string $pluginPath
* @return string
*/
protected function correctPluginPath(string $pluginPath): string
{
return str_replace("plugins/.paper-remapped", "plugins", $pluginPath);
}

/**
* Extracts the plugin name without the file extension (usually .jar) from a plugin path
*
* @param string $pluginPath
* @return string
*/
protected function extractPluginName(string $pluginPath): string
{
return pathinfo($pluginPath, PATHINFO_FILENAME);
}

/**
* Extracts the plugin file name including the file extension (usually .jar) from a plugin path
*
* @param string $pluginPath
* @return string
*/
protected function extractPluginFileName(string $pluginPath): string
{
return pathinfo($pluginPath, PATHINFO_BASENAME);
}
}
Loading

0 comments on commit 874a5d1

Please sign in to comment.