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

ItemFactory frustration

Discussion in 'Development' started by Rim, Sep 19, 2019.

  1. Rim

    Rim Spider Jockey

    Messages:
    28
    GitHub:
    boomyourbang
    I have this in my MainListener class that is functioning fine:

    PHP:
    public function onPickup(InventoryPickupItemEvent $e){
        
    $player $e->getInventory()->getHolder();
        if(
    $player instanceof Player){
            if(
    $this->plugin->getArena()->getSpectate()->isSpectating($player)){
                
    $e->setCancelled(true);
                return;
            }

            
    $item $e->getItem();
            if(
    $item instanceof EffectPickup){
                
    $effect $item->getEffect();
                
    $player->addEffect($effect);
                
    $this->plugin->getServer()->broadcastMessage(TF::LIGHT_PURPLE "Envoy> " "Effect Pickup" "envoy has been claimed!");
            }
            if(
    $item instanceof FreePlay){
                
    $type $item->getFreePlayType();
                
    $count $item->amount();
                
    $this->plugin->getKits()->getSession($player)->addFreePlays($type$count);
                
    $player->sendMessage(TextFormat::OBFUSCATED "||" TextFormat::RESET " " TextFormat::GRAY "Picked up " TextFormat::YELLOW "x".$count." ".$type." Free Play".($count "s" "").TextFormat::GRAY."! ".TextFormat::WHITE.TextFormat::OBFUSCATED."||");
                
    $this->plugin->getServer()->broadcastMessage(TF::LIGHT_PURPLE "Envoy> " "Effect Pickup" "envoy has been claimed!");
            }
            if(
    $item instanceof CoinCluster){
                
    $mbp = new PvPFestPlayer();
                
    $mbp->addCoins($player20);
                
    $player->sendMessage(TextFormat::OBFUSCATED "||" TextFormat::RESET " " TextFormat::GRAY "Picked up " TextFormat::AQUA "20" ." Coins from a coin cluster".TextFormat::GRAY."! ".TextFormat::WHITE.TextFormat::OBFUSCATED."||");
                
    $this->plugin->getServer()->broadcastMessage(TF::LIGHT_PURPLE "Envoy> " "Coin Cluster" "envoy has been claimed!");
            }
        }
    }
    CoinCluster, FreePlay and EffectPickup all extend Item and are written like this:
    PHP:
    class CoinCluster extends Item{

        public function 
    __construct($count 1){
            
    parent::__construct(self::GOLD_INGOT0"Coin Cluster");
            
    $this->setCustomName(TextFormat::RESET TextFormat::AQUA $this->getName());
            
    $this->setCount($count);

        }
    }
    PHP:
    class EffectPickup extends Item{

        public 
    $effect;

        public function 
    __construct(EffectInstance $effect$count 1){
            
    parent::__construct(self::SLIMEBALL0"Effect Pickup");
            
    $this->setCustomName(TextFormat::RESET TextFormat::AQUA $this->getName());
            
    $this->setCount($count);
            
    $this->effect $effect;
        }
        public function 
    getEffect(){
            return 
    $this->effect;
        }
    }
    PHP:
    class FreePlay extends Item{

        public 
    $kit;
        public 
    $count;

        public function 
    __construct(string $kit$count 1){
            
    parent::__construct(self::MAGMA_CREAM0"Free Play");
            
    $this->setCustomName(TextFormat::RESET TextFormat::AQUA $this->getName());
            
    $this->kit $kit;
            
    $this->setCount($count);
            
    $this->count $count;
        }

        public function 
    getFreePlayType(){
            return 
    $this->kit;
        }

        public function 
    amount(){
            return 
    $this->count;
        }

    }
    A repeating task drops these items using Level->dropItem() with no errors. However, when I pick these items up in-game, nothing happens.

    I tried using ItemFactory to register them, but an exception was thrown stating they are already registered and thus I was trying to overwrite them. I tried it again using the 2nd parameter of ItemFactory::registerItem() and setting it to true, but now the first issue happens. Any help? Is this an issue with the Listener or something else?
     
  2. dktapps

    dktapps Administrator Staff Member PMMP Team

    Messages:
    774
    GitHub:
    dktapps
    Make sure you registered the listener like this.
     
  3. Rim

    Rim Spider Jockey

    Messages:
    28
    GitHub:
    boomyourbang
    Yes sir, that's what I have. All of the other events in the listener class are being called with no problem. I'm not using a custom player class either, Player in InventoryPickupItemEvent is normal \pocketmine\Player.
     
  4. dktapps

    dktapps Administrator Staff Member PMMP Team

    Messages:
    774
    GitHub:
    dktapps
    Make sure you imported the class. If the import is missing, it'll silently not be registered.
     
  5. Rim

    Rim Spider Jockey

    Messages:
    28
    GitHub:
    boomyourbang
    All of the classes I need are imported. It's just this one method in the listener class that seems to either a) not get called, or b) not recognize the picked up item as one of the three in the function, which is why I wasn't sure if I had to manually register them (which didn't seem to help regardless)
     
  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.