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

Issue with config + addSound()

Discussion in 'Development' started by minijaham, Jul 13, 2020.

  1. minijaham

    minijaham Skeleton

    Messages:
    801
    GitHub:
    minijaham
    Here's my code:
    PHP:
    <?php

    namespace FeedHealCMD\Commands;

    use 
    FeedHealCMD\Main;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\Player;
    use 
    pocketmine\level\sound\{
        
    AnvilBreakSound,
        
    AnvilFallSound,
        
    AnvilUseSound,
        
    BlazeShootSound,
        
    ClickSOund,
        
    DoorBumpSound,
        
    DoorCrashSound,
        
    DoorSound,
        
    EndermanTeleportSound,
        
    FizSound,
        
    GenericSound,
        
    GhastShootSound,
        
    GhastSound,
        
    LaunchSound,
        
    PopSound
    };

    class 
    FeedCommand extends Command
    {
        private 
    $plugin;
        private 
    $config;

        public function 
    __construct()
        {
            
    $this->plugin Main::getInstance();
            
    parent::__construct("feed");
            
    $this->setDescription("Feed yourself!");
            
    $this->setPermission("command.use.feed");
            
    $this->config Main::$config;
        }
        public function 
    execute(CommandSender $senderstring $commandLabel, array $args)
        {
            if (
    $sender instanceof Player) {
                if (
    $sender->hasPermission("command.use.feed")) {
                    if (empty(
    $args[0])) {
                        
    $sender->setFood(20);
                        
    $sender->setSaturation(20);
                        
    $sender->sendMessage($this->config["feedsuccess"]);
                        
    $sender->getLevel()->addSound(new $this->config["feedsound"]($sender));
                        return 
    false;
                    }
                    if (
    Main::getInstance()->getServer()->getPlayer($args[0])) {
                        
    $player Main::getInstance()->getServer()->getPlayer($args[0]);
                        
    $player->setFood(20);
                        
    $player->setSaturation(20);
                        
    $sender->sendMessage($this->config["feedsuccess"]);
                        
    $sender->getLevel()->addSound(new $this->config["feedsound"]($sender));
                    }
                } else {
                    
    $sender->sendMessage($this->config["nopermission"]);
                }
            } else {
                
    $sender->sendMessage("The command must be executed in-game.");
            }
        }
    }
    I am having trouble with using config with adding sounds ._.

    My config:
    PHP:
    # Message it sends when successfully executes /feed
    feedsuccess"Successfully Fed!"
    # Message it sends when successfully executes /heal
    healsuccess"Successfully Healed!"
    # Message that sends to player who executed the commands without permission
    nopermission"You do not have permission to use this command"
    # Sound effect when player executes /feed. Default: AnvilUseSound.
    feedsound"AnvilUseSound"
    # Sound effect when player executes /heal. Default: AnvilUseSound.
    healsound"AnvilUseSound"
    # AnvilBreakSound
    # AnvilFallSound
    # AnvilUseSound
    # BlazeShootSound
    # ClickSOund
    # DoorBumpSound
    # DoorCrashSound
    # DoorSound
    # EndermanTeleportSound
    # FizSound
    # GenericSound
    # GhastShootSound
    # GhastSound
    # LaunchSound
    # PopSound
    I am getting this issue:
     
  2. Primus

    Primus Zombie Pigman

    Messages:
    749
    PHP:
    new "\\pocketmine\\level\\sound\\".$this->config["feedsound"]($sender)
     
  3. minijaham

    minijaham Skeleton

    Messages:
    801
    GitHub:
    minijaham
    Thank you!
     
    Primus likes this.
  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.