mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-13 05:15:13 +00:00
parent
bf2851f324
commit
c4b4575c74
@ -1 +1 @@
|
|||||||
Subproject commit 15a2b7d4f05959376e3ef6d71e793b7bbdb2b60e
|
Subproject commit 64844b7b6b94a866367831f998281801a86f07a1
|
@ -24,6 +24,10 @@ declare(strict_types=1);
|
|||||||
namespace pocketmine\plugin;
|
namespace pocketmine\plugin;
|
||||||
|
|
||||||
use pocketmine\utils\VersionString;
|
use pocketmine\utils\VersionString;
|
||||||
|
use function array_map;
|
||||||
|
use function array_push;
|
||||||
|
use function count;
|
||||||
|
use function usort;
|
||||||
|
|
||||||
final class ApiVersion{
|
final class ApiVersion{
|
||||||
|
|
||||||
@ -62,4 +66,38 @@ final class ApiVersion{
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string[] $versions
|
||||||
|
*
|
||||||
|
* @return string[]
|
||||||
|
*/
|
||||||
|
public static function checkAmbiguousVersions(array $versions) : array{
|
||||||
|
/** @var VersionString[][] $indexedVersions */
|
||||||
|
$indexedVersions = [];
|
||||||
|
|
||||||
|
foreach($versions as $str){
|
||||||
|
$v = new VersionString($str);
|
||||||
|
if($v->getSuffix() !== ""){ //suffix is always unambiguous
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if(!isset($indexedVersions[$v->getMajor()])){
|
||||||
|
$indexedVersions[$v->getMajor()] = [$v];
|
||||||
|
}else{
|
||||||
|
$indexedVersions[$v->getMajor()][] = $v;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @var VersionString[] $result */
|
||||||
|
$result = [];
|
||||||
|
foreach($indexedVersions as $major => $list){
|
||||||
|
if(count($list) > 1){
|
||||||
|
array_push($result, ...$list);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
usort($result, static function(VersionString $string1, VersionString $string2){ return $string1->compare($string2); });
|
||||||
|
|
||||||
|
return array_map(static function(VersionString $string){ return $string->getBaseVersion(); }, $result);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -258,6 +258,14 @@ class PluginManager{
|
|||||||
]));
|
]));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
$ambiguousVersions = ApiVersion::checkAmbiguousVersions($description->getCompatibleApis());
|
||||||
|
if(!empty($ambiguousVersions)){
|
||||||
|
$this->server->getLogger()->error($this->server->getLanguage()->translateString("pocketmine.plugin.loadError", [
|
||||||
|
$name,
|
||||||
|
$this->server->getLanguage()->translateString("pocketmine.plugin.ambiguousMinAPI", [implode(", ", $ambiguousVersions)])
|
||||||
|
]));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if(count($pluginMcpeProtocols = $description->getCompatibleMcpeProtocols()) > 0){
|
if(count($pluginMcpeProtocols = $description->getCompatibleMcpeProtocols()) > 0){
|
||||||
$serverMcpeProtocols = [ProtocolInfo::CURRENT_PROTOCOL];
|
$serverMcpeProtocols = [ProtocolInfo::CURRENT_PROTOCOL];
|
||||||
|
@ -52,4 +52,27 @@ class ApiVersionTest extends TestCase{
|
|||||||
public function testCompatibleApi(string $myVersion, string $wantVersion, bool $expected) : void{
|
public function testCompatibleApi(string $myVersion, string $wantVersion, bool $expected) : void{
|
||||||
self::assertSame($expected, ApiVersion::isCompatible($myVersion, [$wantVersion]), "my version: $myVersion, their version: $wantVersion, expect " . ($expected ? "yes" : "no"));
|
self::assertSame($expected, ApiVersion::isCompatible($myVersion, [$wantVersion]), "my version: $myVersion, their version: $wantVersion, expect " . ($expected ? "yes" : "no"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function ambiguousVersionsProvider() : \Generator{
|
||||||
|
yield [["3.0.0"], []];
|
||||||
|
yield [["3.0.0", "3.0.1"], ["3.0.0", "3.0.1"]];
|
||||||
|
yield [["3.0.0", "3.1.0", "4.0.0"], ["3.0.0", "3.1.0"]];
|
||||||
|
yield [["3.0.0", "4.0.0"], []];
|
||||||
|
yield [["3.0.0-ALPHA1", "3.0.0-ALPHA2"], []];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider ambiguousVersionsProvider
|
||||||
|
*
|
||||||
|
* @param string[] $input
|
||||||
|
* @param string[] $expectedOutput
|
||||||
|
*/
|
||||||
|
public function testFindAmbiguousVersions(array $input, array $expectedOutput) : void{
|
||||||
|
$ambiguous = ApiVersion::checkAmbiguousVersions($input);
|
||||||
|
|
||||||
|
sort($expectedOutput);
|
||||||
|
sort($ambiguous);
|
||||||
|
|
||||||
|
self::assertSame($expectedOutput, $ambiguous);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user