Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/pm5'
Browse files Browse the repository at this point in the history
  • Loading branch information
mitsuakki committed Oct 30, 2024
2 parents 0facfcd + cf0d009 commit 26e97ad
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 19 deletions.
4 changes: 2 additions & 2 deletions plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: DEVirion
author: poggit
authors: [SOFe]
main: poggit\virion\devirion\DEVirion
version: 1.2.5-ALPHA12
version: 1.3.0
api:
- 4.0.0
- 5.0.0
load: STARTUP
2 changes: 1 addition & 1 deletion src/poggit/virion/devirion/DEVirion.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

class DEVirion extends PluginBase{
/** @var VirionClassLoader */
private $classLoader;
private VirionClassLoader $classLoader;

/**
* Called when the plugin is loaded, before calling onEnable()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

class RegisterClassLoaderAsyncTask extends AsyncTask{
/** @var VirionClassLoader */
private $classLoader;
private VirionClassLoader $classLoader;

public function __construct(VirionClassLoader $classLoader){
$this->classLoader = $classLoader;
Expand Down
31 changes: 16 additions & 15 deletions src/poggit/virion/devirion/VirionClassLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,28 @@

namespace poggit\virion\devirion;

use BaseClassLoader;
use Threaded;
use pmmp\thread\ThreadSafeArray;
use pocketmine\thread\ThreadSafeClassLoader;
use function file_exists;
use function str_replace;
use function stripos;
use const DIRECTORY_SEPARATOR;
use const PHP_INT_SIZE;

class VirionClassLoader extends BaseClassLoader{
private $messages;
class VirionClassLoader extends ThreadSafeClassLoader{
/** @var ThreadSafeArray<string> */
private ThreadSafeArray $messages;

/** @var Threaded|string[] */
private $antigenMap;
/** @var Threaded|string[] */
private $mappedClasses;
/** @var ThreadSafeArray<string> */
private ThreadSafeArray $antigenMap;
/** @var ThreadSafeArray<string> */
private ThreadSafeArray $mappedClasses;

public function __construct(){
parent::__construct();
$this->messages = new Threaded;
$this->antigenMap = new Threaded;
$this->mappedClasses = new Threaded;
$this->messages = new ThreadSafeArray();
$this->antigenMap = new ThreadSafeArray();
$this->mappedClasses = new ThreadSafeArray();
}

public function addAntigen(string $antigen, string $path) : void{
Expand All @@ -57,7 +58,7 @@ public function getKnownAntigens() : array{
return $antigens;
}

public function findClass($class) : ?string{
public function findClass(string $class) : ?string{
$baseName = str_replace("\\", DIRECTORY_SEPARATOR, $class);
foreach($this->antigenMap as $path => $antigen){
if(stripos($class, $antigen) === 0){
Expand All @@ -83,10 +84,10 @@ public function findClass($class) : ?string{
return null;
}

public function loadClass($name) : bool{
public function loadClass(string $name) : bool{
try{
return parent::loadClass($name);
}catch(\Exception $e){
}catch(\Exception){
return false;
}
}
Expand All @@ -95,7 +96,7 @@ public function getSourceViralAntigen(string $loadedClass) : ?string{
return $this->mappedClasses[$loadedClass] ?? null;
}

public function getMessages() : Threaded{
public function getMessages() : ThreadSafeArray{
return $this->messages;
}
}

0 comments on commit 26e97ad

Please sign in to comment.