如果这篇文章的标题措辞方式不明显,我理解出了什么问题,但我不知道通过谷歌获得答案所需的词汇。
实际上,它归结为我有一个 php 主类,它正在注册一个事件侦听器:
class Main extends PluginBase {
public function onEnable(){
$this->getServer()->getLogger()->info("Loading all the things");
$pluginManager = $this->getServer()->getPluginManager();
$pluginManager->registerEvents(new SimpleOverrides($this), $this);
$pluginManager->registerEvents(new AntiGreifListeners($this), $this);
}
}
“SimpleOverrides.php”位于一个名为的单独文件夹中"Listeners"
,其代码如下所示:
class SimpleOverrides implements Listener{
private $plguin;
public function __construct(Main $plugin){
$this->plugin = $plugin;
$this->plugin->getLogger()->info("SimpleOverrides setup!");
}
public function onPluginCommand(PlayerCommandPreprocessEvent $event){
$message = $event.getMessage();
$array = split(' ', $message);
if(strtolower($array[0]) == "pl" || strtolower($array[0]) == "plugins"){
$event->setCancelled(true);
$event->getPlayer()->sendMessage(TextFormat::GREEN . "This server operates using 100% custom plugins!");
}
}
}
问题是在构造函数中,它希望被传递给主类。但是代码会抛出一个TypeError
,因为它在文件夹中寻找 Main.php "Listeners"
。如何让它使用主文件夹中的 Main 类?