简体   繁体   English

参数1传递给某事:: __ construct必须是

[英]Argument 1 passed to something::__construct must be

i am working on an addon, but i got a problem 我正在开发插件,但出现了问题

[22:03:08] [CRITICAL]: "Could not pass event 'pocketmine\\event\\player\\PlayerInteractEvent' to 'MTeamPvP v1.0.0 Beta': Argument 1 passed to MCrafters\\TeamPvP\\GameManager::__construct() must be an instance of MCrafters\\TeamPvP\\TeamPvP, none given, called in C:\\Users\\USER\\Desktop\\Taha\\FlashCraft PE\\lobby 1\\plugins\\DevTools\\src\\MCrafters\\TeamPvP\\TeamPvP.php on line 120 and defined on MCrafters\\TeamPvP\\TeamPvP [22:03:08] [关键]:“无法将事件'pocketmine \\ event \\ player \\ PlayerInteractEvent'传递给'MTeamPvP v1.0.0 Beta':传递给MCrafters \\ TeamPvP \\ GameManager :: __ construct()的参数1必须是第120行上的C:\\ Users \\ USER \\ Desktop \\ Taha \\ FlashCraft PE \\ lobby 1 \\ plugins \\ DevTools \\ src \\ MCrafters \\ TeamPvP \\ TeamPvP.php上定义的MCrafters \\ TeamPvP \\ TeamPvP实例,未给出MCrafters \\ TeamPvP \\ TeamPvP
[22:03:08] [NOTICE]: InvalidArgumentException: "Argument 1 passed to MCrafters\\TeamPvP\\GameManager::__construct() must be an instance of MCrafters\\TeamPvP\\TeamPvP, none given, called in C:\\Users\\USER\\Desktop\\Taha\\FlashCraft PE\\lobby 1\\plugins\\DevTools\\src\\MCrafters\\TeamPvP\\TeamPvP.php on line 120 and defined" (E_RECOVERABLE_ERROR) in "/DevTools/src/MCrafters/TeamPvP/GameManager" at line 13 [22:03:08] [注意]:InvalidArgumentException:“传递给MCrafters \\ TeamPvP \\ GameManager :: __ construct()的参数1必须是MCrafters \\ TeamPvP \\ TeamPvP的实例,未指定,在C:\\ Users \\ USER中调用第120行的\\ Desktop \\ Taha \\ FlashCraft PE \\ lobby 1 \\ plugins \\ DevTools \\ src \\ MCrafters \\ TeamPvP \\ TeamPvP.php,并在第13行的“ / DevTools / src / MCrafters / TeamPvP / GameManager”中定义了“(E_RECOVERABLE_ERROR)”

also sorry for the different error broadcasting 也为不同的错误广播感到抱歉

code : (please don't care about the other classes except GameManager and TeamPvP) TeamPvP.php: 代码:(请不要关心GameManager和TeamPvP以外的其他类)TeamPvP.php:

<?php

namespace MCrafters\TeamPvP;

use pocketmine\plugin\PluginBase;
use pocketmine\utils\TextFormat as Color;
use pocketmine\utils\Config;
use pocketmine\event\Listener;
use pocketmine\event\entity\EntityDamageEvent;
use pocketmine\event\entity\EntityDamageByEntityEvent;
use pocketmine\event\player\PlayerInteractEvent;
use pocketmine\event\player\PlayerDeathEvent;
use pocketmine\math\Vector3;
use pocketmine\level\Position;
use pocketmine\command\Command;
use pocketmine\command\CommandSender;
use pocketmine\Player;
use pocketmine\block\Block;
use pocketmine\item\Item;
use pocketmine\block\WallSign;
use pocketmine\block\PostSign;
use pocketmine\scheduler\ServerScheduler;

class TeamPvP extends PluginBase implements Listener
{

// Teams
public $reds = [];
public $blues = [];
public $gameStarted = false;
public $yml;


public function onEnable()
{
    // Initializing config files
    $this->saveResource("config.yml");
    $yml = new Config($this->getDataFolder() . "config.yml", Config::YAML);
    $this->yml = $yml->getAll();

    $this->getLogger()->debug("Config files have been saved!");

    $this->getServer()->getScheduler()->scheduleRepeatingTask(new Tasks\SignUpdaterTask($this), 15);
    $this->getServer()->getPluginManager()->registerEvents($this, $this);
    $this->getServer()->getLogger()->info(Color::BOLD . Color::GOLD . "M" . Color::AQUA . "TeamPvP " . Color::GREEN . "Enabled" . Color::RED . "!");
}

public function isFriend($p1, $p2)
{
    if ($this->getTeam($p1) === $this->getTeam($p2) && $this->getTeam($p1) !== false) {
        return true;
    } else {
        return false;
    }
}

// isFriend
public function getTeam($p)
{
    if (in_array($p, $this->reds)) {
        return "red";
    } elseif (in_array($p, $this->blues)) {
        return "blue";
    } else {
        return false;
    }
}

public function setTeam($p, $team)
{
    if (strtolower($team) === "red") {
        if (count($this->reds) < 5) {
            if ($this->getTeam($p) === "blue") {
                unset($this->blues[array_search($p, $this->blues)]);
            }
            array_push($this->reds, $p);
            $this->getServer()->getPlayer($p)->setNameTag("§c§l" . $p);
            $this->getServer()->getPlayer($p)->teleport(new Vector3($this->yml["waiting_x"], $this->yml["waiting_y"], $this->yml["waiting_z"]));
            return true;
        } elseif (count($this->blues) < 5) {
            $this->setTeam($p, "blue");
        } else {
            return false;
        }
    } elseif (strtolower($team) === "blue") {
        if (count($this->blues) < 5) {
            if ($this->getTeam($p) === "red") {
                unset($this->reds[array_search($p, $this->reds)]);
            }
            array_push($this->blues, $p);
            $this->getServer()->getPlayer($p)->setNameTag("§b§l" . $p);
            $this->getServer()->getPlayer($p)->teleport(new Vector3($this->yml["waiting_x"], $this->yml["waiting_y"], $this->yml["waiting_z"]));
            return true;
        } elseif (count($this->reds) < 5) {
            $this->setTeam($p, "red");
        } else {
            return false;
        }
    }
}

public function removeFromTeam($p, $team)
{
    if (strtolower($team) == "red") {
        unset($this->reds[array_search($p, $this->reds)]);
        return true;
    } elseif (strtolower($team) == "blue") {
        unset($this->blues[array_search($p, $this->blues)]);
        return true;
    }
}

public function onInteract(PlayerInteractEvent $event)
{
    $p = $event->getPlayer();
    $teams = array("red", "blue");
    if ($event->getBlock()->getX() === $this->yml["sign_join_x"] && $event->getBlock()->getY() === $this->yml["sign_join_y"] && $event->getBlock()->getZ() === $this->yml["sign_join_z"]) {
        if (count($this->blues) < 5 && count($this->reds) < 5) {
            $this->setTeam($p->getName(), $teams[array_rand($teams, 1)]);
            $s = new GameManager();
            $s->run();
        } else {
            $p->sendMessage($this->yml["teams_are_full_message"]);
        }
  }
}

public function onEntityDamage(EntityDamageEvent $event)
{
    if ($event instanceof EntityDamageByEntityEvent) {
        if ($event->getEntity() instanceof Player) {
            if ($this->isFriend($event->getDamager()->getName(), $event->getEntity()->getName()) && $this->gameStarted == true) {
                $event->setCancelled(true);
                $event->getDamager()->sendMessage(str_replace("{player}", $event->getPlayer()->getName(), $this->yml["hit_same_team_message"]));
            }

            if ($this->isFriend($event->getDamager()->getName(), $event->getEntity()->getName())) {
                $event->setCancelled(true);
                 }
            }
        }
    }


public function onDeath(PlayerDeathEvent $event)
{
    if ($this->getTeam($event->getEntity()->getName()) == "red" && $this->gameStarted == true) {
        $this->removeFromTeam($event->getEntity()->getName(), "red");
        $event->getEntity()->teleport($this->getServer()->getLevelByName($this->yml["spawn_level"])->getSafeSpawn());
    } elseif ($this->getTeam($event->getEntity()->getName()) == "blue" && $this->gameStarted == true) {
        $this->removeFromTeam($event->getEntity()->getName(), "blue");
        $event->getEntity()->teleport($this->getServer()->getLevelByName($this->yml["spawn_level"])->getSafeSpawn());
    }
    foreach ($this->blues as $b) {
        foreach ($this->reds as $r) {
            if (count($this->reds) == 0 && $this->gameStarted == true) {

                $this->getServer()->getPlayer($b)->getInventory()->clearAll();
                $this->removeFromTeam($b, "blue");
                $this->getServer()->getPlayer($b)->teleport($this->getServer()->getLevelByName($this->yml["spawn_level"])->getSafeSpawn());
                $this->getServer()->broadcastMessage("Blue Team won TeamPvP!");
            } elseif (count($this->blues) == 0 && $this->gameStarted == true) {
                $this->getServer()->getPlayer($r)->getInventory()->clearAll();
                $this->removeFromTeam($r, "red");
                $this->getServer()->getPlayer($r)->teleport($this->getServer()->getLevelByName($this->yml["spawn_level"])->getSafeSpawn());
            }
        }
    }
}
}//class

GameManager.php : GameManager.php:

<?php
namespace MCrafters\TeamPvP;

use pocketmine\scheduler\ServerScheduler as Tasks;

class GameManager
{
public $reds;
public $blues;
public $gst;
public $gwt;

public function __construct(\MCrafters\TeamPvP\TeamPvP $plugin)
{
 parent::__construct($plugin);
 $this->plugin = $plugin;
}


public function run()
{
    $this->reds = $this->plugin->reds;
    $this->blues = $this->plugin->blues;

    if (count($this->reds) < 5 && count($this->blues) < 5) {
        $this->gst = Tasks::scheduleRepeatingTask(new Tasks\GameStartTask($this), 20)->getTaskId();
        Tasks::cancelTask($this->gwt);
    } else {
        $this->gwt = Tasks::scheduleRepeatingTask(new Tasks\GameWaitingTask($this), 15)->getTaskId();
    }
}
}

namespace correct, class and file name correct, and all other functions from other classes have nothing to do with this :) check the line where there is GameManager::run() in TeamPvP class.

i already know there is one about this, but i didn't understand it. 我已经知道有一个关于这个的信息,但是我不明白。

Thank You for your help. 谢谢您的帮助。

You have a type hint 您有类型提示

public function __construct(\MCrafters\TeamPvP\TeamPvP $plugin)
{
 parent::__construct($plugin);
 $this->plugin = $plugin;
}

So when you go to instantiate MCrafters\\TeamPvP\\GameManager you have to pass it an instance of \\MCrafters\\TeamPvP\\TeamPvP 因此,当您实例化MCrafters\\TeamPvP\\GameManager您必须向其传递\\MCrafters\\TeamPvP\\TeamPvP的实例

$team = new \MCrafters\TeamPvP\TeamPvP();
$manager = new \MCrafters\TeamPvP\GameManager($team)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 传递给__construct()的参数1必须是GuzzleHttp \\ Client的实例 - Argument 1 passed to __construct() must be an instance of GuzzleHttp\Client 传递给:: __ construct()的参数1必须是DateTimeInterface的实例 - Argument 1 passed to ::__construct() must be an instance of DateTimeInterface Doctrine - 传递给 __construct 的参数必须是一个数组 - Doctrine - Argument passed to __construct must be an array Laravel 7 adminLTE 参数 1 传递::__construct() 必须是数组类型,null 给定 - Laravel 7 adminLTE Argument 1 passed::__construct() must be of the type array, null given 传递给 DoctrineDataCollector::__construct() 的参数 1 必须是 Doctrine\Common\Persistence\ManagerRegistry 的一个实例 - Argument 1 passed to DoctrineDataCollector::__construct() must be an instance of Doctrine\Common\Persistence\ManagerRegistry 传递给__construct的参数1必须是Services \\ ProductManager的实例,未给出任何实例 - Argument 1 passed to __construct must be an instance of Services\ProductManager, none given 持久化Doctrine关系,Argument 1传递给.. \\ ArrayCollection :: __ construct()必须是类型数组 - Persisting Doctrine relationship, Argument 1 passed to ..\ArrayCollection::__construct() must be of the type array Laravel API - 传递给 TokenGuard::__construct() 的参数 1 必须实现接口 UserProvider - Laravel API - Argument 1 passed to TokenGuard::__construct() must implement interface UserProvider 传递给 App\Events\NoticeAnnouncement::__construct() 的参数 3 必须是 App\User 的实例 - Argument 3 passed to App\Events\NoticeAnnouncement::__construct() must be an instance of App\User 可捕获的致命错误:传递给“…\\ FormType :: __ construct()的参数1必须实现接口 - Catchable Fatal Error: Argument 1 passed to "…\FormType::__construct() must implement interface
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM