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

error that I can't understand

Discussion in 'Plugin Help' started by Soupiia, May 16, 2020.

  1. Soupiia

    Soupiia Creeper

    Messages:
    4
    GitHub:
    soupiia
    I have no experience in PHP at all, I need some help in resolving this issue


    The code


    ?php

    /*
    *
    * ____ _ _ __ __ _ __ __ ____
    * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
    * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
    * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
    * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
    *
    * This program is free software: you can redistribute it and/or modify
    * it under the terms of the GNU Lesser General Public License as published by
    * the Free Software Foundation, either version 3 of the License, or
    * (at your option) any later version.
    *
    * @author PocketMine Team
    * @link http://www.pocketmine.net/
    *
    *
    */

    declare(strict_types=1);

    namespace sys\arenapvp\utils;


    use pocketmine\entity\Entity;
    use pocketmine\event\entity\EntityShootBowEvent;
    use pocketmine\event\entity\ProjectileLaunchEvent;
    use pocketmine\item\enchantment\Enchantment;
    use pocketmine\item\Item;
    use pocketmine\item\Tool;
    use pocketmine\level\sound\LaunchSound;
    use pocketmine\nbt\tag\CompoundTag;
    use pocketmine\nbt\tag\DoubleTag;
    use pocketmine\nbt\tag\FloatTag;
    use pocketmine\nbt\tag\ListTag;
    use pocketmine\nbt\tag\ShortTag;
    use pocketmine\network\mcpe\protocol\LevelSoundEventPacket;
    use pocketmine\Player;

    /*
    * Message to all, this is here because Pocketmine doesn't support the Infinity enchantment.
    */
    class CustomBow extends Tool {

    public function onReleaseUsing(Player $player) : bool{
    /** @var Item $arrow */
    $arrow = null;
    if(($index = $player->getInventory()->first(self::get(self::ARROW, -1, 1))) === -1){
    if($player->isSurvival()){
    return false;
    }else {
    $arrow = Item::get(Item::ARROW, 0, 1); //Default to a normal arrow for creative
    }
    }else{ //TODO: check offhand slot first (MCPE 1.1)
    $arrow = $player->getInventory()->getItem($index);
    $arrow->setCount(1);
    }

    //TODO: add effects for tipped arrows

    $vector = $player->getDirectionVector();

    $nbt = new CompoundTag("", [
    new ListTag("Pos", [
    new DoubleTag("", $player->x),
    new DoubleTag("", $player->y + $player->getEyeHeight() + 0.25),
    new DoubleTag("", $player->z)
    ]),
    new ListTag("Motion", [
    new DoubleTag("", $vector->x),
    new DoubleTag("", $vector->y),
    new DoubleTag("", $vector->z)
    ]),
    new ListTag("Rotation", [
    new FloatTag("", ($player->yaw > 180 ? 360 : 0) - $player->yaw),
    new FloatTag("", -$player->pitch)
    ]),
    new ShortTag("Fire", $player->isOnFire() ? 45 * 60 : 0)
    //TODO: add Power and Flame enchantment effects
    ]);

    $diff = $player->getItemUseDuration();
    $p = $diff / 20;
    $f = min((($p ** 2) + $p * 2) / 3, 1) * 2;
    $ev = new EntityShootBowEvent($player, $this, Entity::createEntity("Arrow", $player->getLevel(), $nbt, $player, $f == 2), $f);

    if($f < 0.05 or $diff < 7){
    $ev->setCancelled();
    }

    $player->getServer()->getPluginManager()->callEvent($ev);

    if($ev->isCancelled()){
    $ev->getProjectile()->close();
    return false;
    }else{
    $player->getLevel()->broadcastLevelSoundEvent($player, LevelSoundEventPacket::SOUND_BOW);
    $ev->getProjectile()->setMotion($ev->getProjectile()->getMotion()->multiply($ev->getForce()));
    if($player->isSurvival()) {
    if(!$this->hasEnchantment(Enchantment::INFINITY)) {
    $player->getInventory()->removeItem($arrow);
    }
    $this->meta++;
    }
    if($ev->getProjectile() instanceof Projectile){
    $player->getServer()->getPluginManager()->callEvent($projectileEv = new ProjectileLaunchEvent($ev->getProjectile()));
    if($projectileEv->isCancelled()){
    $ev->getProjectile()->close();
    }else{
    $ev->getProjectile()->spawnToAll();
    $player->getLevel()->addSound(new LaunchSound($player), $player->getViewers());
    }
    }else{
    $ev->getProjectile()->spawnToAll();
    }
    }

    return true;
    }
    }










    The crashdump

    Error: Class sys\arenapvp\utils\CustomBow contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (pocketmine\item\Durable::getMaxDurability)
    File: plugins/ArenaPvP-master/src/sys/arenapvp/utils/CustomBow
    Line: 122
    Type: E_ERROR
     
  2. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    just add this function
    PHP:
    public function getMaxDurability():int{
    return 
    384;//durability for bow
    }
     
  3. Soupiia

    Soupiia Creeper

    Messages:
    4
    GitHub:
    soupiia
    what line do I insert the code into, I get an error saying unexpected 'public'
     
  4. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    add it before the last closing curly bracket }
     
  5. Soupiia

    Soupiia Creeper

    Messages:
    4
    GitHub:
    soupiia
    thanks for the help but now I get this error


    PHP:
    [12:54:29] [Server thread/INFO]: Loading ArenaPvP v1.2.0
    [12:54:29] [Server thread/INFO]: [ArenaPvPThere are no arenas to load!
    [
    12:54:29] [Server thread/CRITICAL]: RuntimeException"Trying to overwrite an already registered item" (EXCEPTIONin "src/pocketmine/item/ItemFactory" at line 298
     
  6. Seeker

    Seeker Spider Jockey

    Messages:
    45
    GitHub:
    seeker-devs
    You are trying to overwrite an existing item, read the error
     
  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.