1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Plugin Spawnentity

Discussion in 'Development' started by STONEEEX, Feb 1, 2023.

  1. STONEEEX

    STONEEEX Creeper

    Messages:
    1
    I'm creating a plugin when using the /spawnentity command a zombie appears to attack you, but it's giving an error

    Error: Call to undefined method pocketmine\command\ConsoleCommandSender::getLevel()
    File: plugins/Guardiões/src/Will/Plugin/Main
    Line: 26
    Type: Error

    THIS CRASH WAS CAUSED BY A PLUGIN
    BAD PLUGIN: Guardioes v1

    Code:
    [17] }
    [18]
    [19] public function onCommand(CommandSender $sender, Command $command, string $label, array $args): bool {
    [20] if ($command->getName() == "spawnentity") {
    [21] if (!$sender->hasPermission("spawnentity.command")) {
    [22] $sender->sendMessage(TextFormat::RED . "Você não tem permissão para executar este comando.");
    [23] return false;
    [24] }
    [25]
    [26] $level = $sender->getLevel();
    [27] $x = $sender->getX();
    [28] $y = $sender->getY();
    [29] $z = $sender->getZ();
    [30] $entity = Entity::createEntity("Zombie", $level, new Vector3($x + 2, $y, $z + 2));
    [31] $entity->spawnToAll();
    [32]
    [33] $sender->sendMessage(TextFormat::GREEN . "Entidade Zombie gerada com sucesso.");
    [34] return true;
    [35] }
    [36]
     
  2. iRainDrop

    iRainDrop Creeper

    Messages:
    5
    I don't know much about coding/PHP myself but it seems the error is happening because you sent the command from the console and the method used on line 26 "$level = $sender->getLevel();" is not a method if sent by console. You should enclose your code with another if check to see if the sender is an instance of player because the console will never be in a world/level....
     
    Last edited: Feb 7, 2023
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.