Skip to content

Commit

Permalink
Merge pull request #22 from poggit/4.0
Browse files Browse the repository at this point in the history
4.0
  • Loading branch information
SOF3 authored Dec 5, 2021
2 parents 58412e0 + c72e0fe commit b5fe3d7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 44 deletions.
2 changes: 1 addition & 1 deletion plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ authors: [SOFe]
main: poggit\virion\devirion\DEVirion
version: 1.2.5-ALPHA12
api:
- 3.0.0
- 4.0.0
load: STARTUP
43 changes: 6 additions & 37 deletions src/poggit/virion/devirion/DEVirion.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

namespace poggit\virion\devirion;

use pocketmine\plugin\ApiVersion;
use pocketmine\plugin\PluginBase;
use pocketmine\scheduler\Task;
use function array_map;
Expand All @@ -41,7 +42,6 @@
use function realpath;
use function rtrim;
use function str_replace;
use function strtoupper;
use function substr;
use function yaml_parse;
use const PHP_MAJOR_VERSION;
Expand All @@ -55,7 +55,7 @@ class DEVirion extends PluginBase{
* Called when the plugin is loaded, before calling onEnable()
*/
public function onLoad() : void{
$this->classLoader = new VirionClassLoader($this->getServer()->getLoader());
$this->classLoader = new VirionClassLoader();

$dirs = [$this->getServer()->getDataPath() . "virions/"];
foreach((array) (getopt("", ["load-virions::"])["load-virions"] ?? []) as $path){
Expand Down Expand Up @@ -106,7 +106,7 @@ public function __construct(DEVirion $plugin){
$this->plugin = $plugin;
}

public function onRun(int $currentTick) : void{
public function onRun() : void{
$messages = $this->plugin->getVirionClassLoader()->getMessages();
while($messages->count() > 0){
$this->plugin->getLogger()->warning($messages->shift());
Expand Down Expand Up @@ -165,41 +165,10 @@ public function loadVirion(string $path, bool $explicit = false) : void{
return;
}
}
if(isset($data["api"])){
$compatible = false;
foreach((array) $data["api"] as $version){
$version = (string) $version;
//Format: majorVersion.minorVersion.patch (3.0.0)
// or: majorVersion.minorVersion.patch-devBuild (3.0.0-alpha1)
if($version !== $this->getServer()->getApiVersion()){
$virionApi = array_pad(explode("-", $version), 2, ""); //0 = version, 1 = suffix (optional)
$serverApi = array_pad(explode("-", $this->getServer()->getApiVersion()), 2, "");

if(strtoupper($virionApi[1]) !== strtoupper($serverApi[1])){ //Different release phase (alpha vs. beta) or phase build (alpha.1 vs alpha.2)
continue;
}

$virionNumbers = array_map("intval", explode(".", $virionApi[0]));
$serverNumbers = array_map("intval", explode(".", $serverApi[0]));

if($virionNumbers[0] !== $serverNumbers[0]){ //Completely different API version
continue;
}

if($virionNumbers[1] > $serverNumbers[1]){ //If the plugin requires new API features, being backwards compatible
continue;
}
}

$compatible = true;
break;
}

if($compatible === false){
$this->getLogger()->error("Cannot load virion $name: Server has incompatible API version {$this->getServer()->getApiVersion()}");
return;
if(isset($data["api"]) && !ApiVersion::isCompatible($this->getServer()->getApiVersion(), (array) $data["api"])){
$this->getLogger()->error("Cannot load virion $name: Server has incompatible API version {$this->getServer()->getApiVersion()}");
return;

}
}

if(!isset($data["api"]) && !isset($data["php"])){
Expand Down
11 changes: 5 additions & 6 deletions src/poggit/virion/devirion/VirionClassLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
namespace poggit\virion\devirion;

use BaseClassLoader;
use ClassLoader;
use Threaded;
use function file_exists;
use function str_replace;
Expand All @@ -39,8 +38,8 @@ class VirionClassLoader extends BaseClassLoader{
/** @var Threaded|string[] */
private $mappedClasses;

public function __construct(ClassLoader $parent = null){
parent::__construct($parent);
public function __construct(){
parent::__construct();
$this->messages = new Threaded;
$this->antigenMap = new Threaded;
$this->mappedClasses = new Threaded;
Expand Down Expand Up @@ -84,11 +83,11 @@ public function findClass($class) : ?string{
return null;
}

public function loadClass($name) : ?bool{
public function loadClass($name) : bool{
try{
return parent::loadClass($name);
}catch(\ClassNotFoundException $e){
return null;
}catch(\Exception $e){
return false;
}
}

Expand Down

3 comments on commit b5fe3d7

@NhanAZ
Copy link

@NhanAZ NhanAZ commented on b5fe3d7 Jan 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PM5 and PHP 8.2 pls

@IvanCraft623
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not until they are stable

@SOF3
Copy link
Member Author

@SOF3 SOF3 commented on b5fe3d7 Jan 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't use devirion... compile plugin directly. try the plugin-dev script in https://GitHub.com/SOF3/pharynx instead.

Please sign in to comment.