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

Need help

Discussion in 'Facepalm' started by NotRedd, Jun 12, 2017.

  1. NotRedd

    NotRedd Silverfish

    Messages:
    17
    Full code
    PHP:
    <?php

    namespace UHC\Commands;

    use 
    UHC\Loader;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\Player;
    use 
    pocketmine\Server;
    use 
    pocketmine\utils\TextFormat as TF;
    use 
    pocketmine\level\Position;
    use 
    pocketmine\math\Vector3;
    use 
    pocketmine\item\Item;
    use 
    pocketmine\inventory\PlayerInventory;
    use 
    pocketmine\entity\Effect;
    use 
    pocketmine\network\mcpe\protocol\SetDifficultyPacket;

    class 
    UHCCommand extends BaseCommand
    {
        
        public function 
    __construct(Loader $plugin)
        {
            
    $this->plugin $plugin;
            
    parent::__construct($plugin"uhc""Main UHC command!""/uhc [help|start]", []);
            
    $this->setPermission("uhc.op");
        }
        
        public function 
    execute(CommandSender $sender$commandLabel, array $args)
        {
            if (!
    $this->testPermission($sender)) {
                return 
    false;
            }
            
            if (
    count($args) < 1) {
                
    $sender->sendMessage(TF::RED $this->usageMessage);
                return 
    true;
            }
            
            if (isset(
    $args[0])) {
                switch (
    $args[0]) {
                    case 
    "help":
                        
    $sender->sendMessage("§7--- §aHosting Help §7---");
                        
    $sender->sendMessage("§7/uhc start");
                        
    $sender->sendMessage("§7/uhc restart");
                        
    $sender->sendMessage("§7/uhc reset");
                        
    $sender->sendMessage("§7/uhc tpall");
                        
    $sender->sendMessage("§7/uhc rtpall");
                        
    $sender->sendMessage("§7/uhc food");
                        
    $sender->sendMessage("§7/uhc healall");
                        
    $sender->sendMessage("§7/uhc ban");
                        break;
                }
            }
            
            if (isset(
    $args[0])) {
                switch (
    $args[0]) {
                    case 
    "start":
                        foreach (
    Server::getInstance()->getOnlinePlayers() as $p) {
                            
    $p->addEffect(Effect::getEffect(Effect::NIGHT_VISION)->setAmplifier(1)->setDuration(1000000));
                            
    $p->addEffect(Effect::getEffect(Effect::FIRE_RESISTANCE)->setAmplifier(1)->setDuration(100000));
                            
    $p->getInventory()->clearAll();
                            
    $p->getInventory()->addItem(Item::get(Item::STONE_PICKAXE01));
                            
    $p->getInventory()->addItem(Item::get(Item::STEAK064));
                            
    $this->plugin->getServer()->setConfigInt("white-list"true);
                            
    $this->plugin->getServer()->addWhitelist($p->getName());
                            
    $p->sendMessage("§e× §aGoodluck. The event started");
                            
                            
                            break;
                        }
                }
            }
            
            if (isset(
    $args[0])) {
                switch (
    $args[0]) {
                    case 
    "tpall":
                        foreach (
    Server::getInstance()->getOnlinePlayers() as $p) {
                            
    $p->teleport(new Vector3($sender->x$sender->y$sender->z$sender->getLevel()));
                            
    $p->sendMessage("§e× §9Teleporting...");
                            
                        }
                }
            }
            
            if (isset(
    $args[0])) {
                switch (
    $args[0]) {
                    case 
    "heal":
                        foreach (
    Server::getInstance()->getOnlinePlayers() as $p) {
                            
    $p->setHealth(20);
                            
    $p->setFood(20);
                            
                            
    $p->sendMessage("§e× §aEveryone has been healed");
                        }
                }
            }
            
            if (isset(
    $args[0])) {
                switch (
    $args[0]) {
                    case 
    "rtpall":
                        foreach (
    Server::getInstance()->getOnlinePlayers() as $p) {
                            
    $x mt_rand(-9090);
                            
    $y mt_rand(70200);
                            
    $z mt_rand(-9090);
                            
    $p->teleport(new Vector3($x$y$z));
                            
    $p->sendMessage("§e× §aRandomly spreading players around the map!");
                        }
                }
            }
            
            if (isset(
    $args[0])) {
                switch (
    $args[0]) {
                    case 
    "clear":
                        foreach (
    Server::getInstance()->getOnlinePlayers() as $p) {
                            
    $p->getInventory()->clearAll();
                            
    $p->removeAllEffects();
                            
    $p->setHealth(20);
                            
    $p->setFood(20);
                            
    $p->sendMessage("§e× §3This round has been reset");
                        }
                }
            }
            
            if (isset(
    $args[0])) {
                switch (
    $args[0]) {
                    case 
    "pvp":
                        switch (
    $args[1]) {
                            case 
    "on":
                                
    $this->plugin->getServer()->getConfigInt("difficulty"3);
                                
    $pk             = new SetDifficultyPacket();
                                
    $pk->difficulty $this->plugin->getServer()->getDifficulty();
                                foreach (
    Server::getInstance()->getOnlinePlayers() as $p) {
                                    
    $p->sendMessage("§e× §aPvP toggled on");
                                }
                        }
                        
                        switch (
    $args[1]) {
                            case 
    "off":
                                
    $this->plugin->getServer()->getConfigInt("difficulty"0);
                                
    $pk             = new SetDifficultyPacket();
                                
    $pk->difficulty $this->plugin->getServer()->getDifficulty();
                                foreach (
    Server::getInstance()->getOnlinePlayers() as $p) {
                                    
    $p->sendMessage("§e× §cPvP toggled off");
                                }
                        }
                }
            }
        }
    }
     

    Attached Files:

  2. Awzaw

    Awzaw Zombie Pigman Poggit Admin

    Messages:
    726
    GitHub:
    awzaw
    First, what are you trying to do with this code?
    PHP:
    $this->plugin->getServer()->getConfigInt("difficulty"3);
    The code throwing the error is in getConfigBoolean(). Here's the code from Server.php for reference:
    Code:
    public function getConfigBoolean(string $variable, bool $defaultValue = false) : bool{
       $v = getopt("", ["$variable::"]);
       if(isset($v[$variable])){
          $value = $v[$variable];
       }else{
          $value = $this->properties->exists($variable) ? $this->properties->get($variable) : $defaultValue;
       }
    
       if(is_bool($value)){
          return $value;
       }
       switch(strtolower($value)){
          case "on":
          case "true":
          case "1":
          case "yes":
             return true;
       }
    
       return false;
    }
    
    I can't see how the code you posted could possibly call this function and result in $value being an int, so maybe it's happening in your Loader class? Looks like your config is returning an integer (e.g 0 or 1) in getConfigBoolean() instead of a string (in quotes "0"), or something like that.
     
    Last edited: Jun 12, 2017
  3. NotRedd

    NotRedd Silverfish

    Messages:
    17
    Here is my Loader.

    PHP:
    <?php

    /* _    _           ??      _                 
     *| |  | |         | |    (_)               
     *| |__| |_   _  __| |_ __ _  ___  _   _ ___
     *|  __  | | | |/ _` | '__| |/ _ \| | | / __|
     *| |  | | |_| | (_| | |  | | (_) | |_| \__ \
     *|_|  |_|\__, |\__,_|_|  |_|\___/ \__,_|___/
     *         __/ |                             
     *        |___/                             
     *
     * This plugin cannot be shared or used ny anyone else.
     * The only people allowed to use this must have permission by Jon or Red
     *
     * @authors Jonathanftw2 & mnngold
     *
     */

    namespace UHC;


    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\utils\Config;

    //MANAGERS
    use UHC\Managers\CommandManager;
    use 
    UHC\Managers\EventManager;

    //COMMANDS
    use UHC\Commands\UHCCommand;
    use 
    UHC\Commands\ScenarioCommand;

    //SCENARIOS
    use UHC\Scenarios\NoAnvil;
    use 
    UHC\Scenarios\Goldless;
    use 
    UHC\Scenarios\TripleOres;
    use 
    UHC\Scenarios\QuadOres;
    use 
    UHC\Scenarios\DoubleOres;
    use 
    UHC\Scenarios\Diamondless;
    use 
    UHC\Scenarios\BloodDiamonds;
    use 
    UHC\Scenarios\CutClean;
    use 
    UHC\Scenarios\FastSmelt;
    use 
    UHC\Scenarios\CatEyes;
    use 
    UHC\Scenarios\NoFall;
    use 
    UHC\Scenarios\NoEnchant;
    use 
    UHC\Scenarios\Fireless;
    use 
    UHC\Scenarios\Applerate;

    class 
    Loader extends PluginBase implements Listener
    {
        
        public function 
    onEnable()
        {
            @
    mkdir($this->getDataFolder());
            
    $this->config = new Config($this->getDataFolder() . "/scenarios.yml"CONFIG::YAML, array(
                
    "cutclean" => true,
                
    "applerate" => true,
                
    "nofall" => true,
                
    "noenchant" => false,
                
    "noanvil" => false,
                
    "goldless" => false,
                
    "doubleores" => false,
                
    "tripleores" => false,
                
    "quadores" => false,
                
    "diamondless" => false,
                
    "fastsmelt" => false,
                
    "fireless" => false,
                
    "cateyes" => true
            
    ));
            
    $this->getServer()->getPluginManager()->registerEvents(new EventManager($this), $this);
            
    $this->sendManagers();
            
    $this->sendScenarios();
        }
        
        public function 
    sendScenarios()
        {
            
    $this->getServer()->getPluginManager()->registerEvents(new CatEyes($this), $this);
            
    $this->getServer()->getPluginManager()->registerEvents(new Fireless($this), $this);
            
    $this->getServer()->getPluginManager()->registerEvents(new CutClean($this), $this);
            
    $this->getServer()->getPluginManager()->registerEvents(new Nofall($this), $this);
            
    $this->getServer()->getPluginManager()->registerEvents(new Applerate($this), $this);
            
    $this->getServer()->getPluginManager()->registerEvents(new BloodDiamonds($this), $this);
            
    $this->getServer()->getPluginManager()->registerEvents(new Diamondless($this), $this);
            
    $this->getServer()->getPluginManager()->registerEvents(new NoEnchant($this), $this);
            
    $this->getServer()->getPluginManager()->registerEvents(new NoAnvil($this), $this);
            
    $this->getServer()->getPluginManager()->registerEvents(new Goldless($this), $this);
            
    $this->getServer()->getPluginManager()->registerEvents(new Diamondless($this), $this);
            
    $this->getServer()->getPluginManager()->registerEvents(new FastSmelt($this), $this);
            
    $this->getServer()->getPluginManager()->registerEvents(new DoubleOres($this), $this);
            
    $this->getServer()->getPluginManager()->registerEvents(new TripleOres($this), $this);
            
    $this->getServer()->getPluginManager()->registerEvents(new QuadOres($this), $this);
        }
        
        public function 
    sendManagers()
        {
            new 
    CommandManager($this);
            new 
    EventManager($this);
        }
        
        public function 
    onDisable()
        {
            
        }
    }
     
  4. NotRedd

    NotRedd Silverfish

    Messages:
    17
    Here isy loader
    PHP:
    <?php

    /* _    _           ??      _                 
     *| |  | |         | |    (_)               
     *| |__| |_   _  __| |_ __ _  ___  _   _ ___
     *|  __  | | | |/ _` | '__| |/ _ \| | | / __|
     *| |  | | |_| | (_| | |  | | (_) | |_| \__ \
     *|_|  |_|\__, |\__,_|_|  |_|\___/ \__,_|___/
     *         __/ |                             
     *        |___/                             
     *
     * This plugin cannot be shared or used ny anyone else.
     * The only people allowed to use this must have permission by Jon or Red
     *
     * @authors Jonathanftw2 & mnngold
     *
     */

    namespace UHC;


    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\utils\Config;

    //MANAGERS
    use UHC\Managers\CommandManager;
    use 
    UHC\Managers\EventManager;

    //COMMANDS
    use UHC\Commands\UHCCommand;
    use 
    UHC\Commands\ScenarioCommand;

    //SCENARIOS
    use UHC\Scenarios\NoAnvil;
    use 
    UHC\Scenarios\Goldless;
    use 
    UHC\Scenarios\TripleOres;
    use 
    UHC\Scenarios\QuadOres;
    use 
    UHC\Scenarios\DoubleOres;
    use 
    UHC\Scenarios\Diamondless;
    use 
    UHC\Scenarios\BloodDiamonds;
    use 
    UHC\Scenarios\CutClean;
    use 
    UHC\Scenarios\FastSmelt;
    use 
    UHC\Scenarios\CatEyes;
    use 
    UHC\Scenarios\NoFall;
    use 
    UHC\Scenarios\NoEnchant;
    use 
    UHC\Scenarios\Fireless;
    use 
    UHC\Scenarios\Applerate;

    class 
    Loader extends PluginBase implements Listener
    {
        
        public function 
    onEnable()
        {
            @
    mkdir($this->getDataFolder());
            
    $this->config = new Config($this->getDataFolder() . "/scenarios.yml"CONFIG::YAML, array(
                
    "cutclean" => true,
                
    "applerate" => true,
                
    "nofall" => true,
                
    "noenchant" => false,
                
    "noanvil" => false,
                
    "goldless" => false,
                
    "doubleores" => false,
                
    "tripleores" => false,
                
    "quadores" => false,
                
    "diamondless" => false,
                
    "fastsmelt" => false,
                
    "fireless" => false,
                
    "cateyes" => true
            
    ));
            
    $this->getServer()->getPluginManager()->registerEvents(new EventManager($this), $this);
            
    $this->sendManagers();
            
    $this->sendScenarios();
        }
        
        public function 
    sendScenarios()
        {
            
    $this->getServer()->getPluginManager()->registerEvents(new CatEyes($this), $this);
            
    $this->getServer()->getPluginManager()->registerEvents(new Fireless($this), $this);
            
    $this->getServer()->getPluginManager()->registerEvents(new CutClean($this), $this);
            
    $this->getServer()->getPluginManager()->registerEvents(new Nofall($this), $this);
            
    $this->getServer()->getPluginManager()->registerEvents(new Applerate($this), $this);
            
    $this->getServer()->getPluginManager()->registerEvents(new BloodDiamonds($this), $this);
            
    $this->getServer()->getPluginManager()->registerEvents(new Diamondless($this), $this);
            
    $this->getServer()->getPluginManager()->registerEvents(new NoEnchant($this), $this);
            
    $this->getServer()->getPluginManager()->registerEvents(new NoAnvil($this), $this);
            
    $this->getServer()->getPluginManager()->registerEvents(new Goldless($this), $this);
            
    $this->getServer()->getPluginManager()->registerEvents(new Diamondless($this), $this);
            
    $this->getServer()->getPluginManager()->registerEvents(new FastSmelt($this), $this);
            
    $this->getServer()->getPluginManager()->registerEvents(new DoubleOres($this), $this);
            
    $this->getServer()->getPluginManager()->registerEvents(new TripleOres($this), $this);
            
    $this->getServer()->getPluginManager()->registerEvents(new QuadOres($this), $this);
        }
        
        public function 
    sendManagers()
        {
            new 
    CommandManager($this);
            new 
    EventManager($this);
        }
        
        public function 
    onDisable()
        {
            
        }
    }
     
  5. Awzaw

    Awzaw Zombie Pigman Poggit Admin

    Messages:
    726
    GitHub:
    awzaw
    And the contents of scenarios.yml and any other yml files you have with boolean values.

    I also just noticed that your code does this - I'm not sure if using setConfigInt() directly is a good idea, and if you do use it you'll have to make sure the arguments you pass match the function signature; here you pass a boolean as the 2nd argument instead if an int.

    PHP:
    $this->plugin->getServer()->setConfigInt("white-list"true);
     
    Last edited: Jun 12, 2017
  6. NotRedd

    NotRedd Silverfish

    Messages:
    17
    PHP:
    <?php

    namespace UHC\Scenarios;

    use 
    UHC\Loader;
    use 
    pocketmine\event\block\BlockBreakEvent;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\item\Item;
    use 
    pocketmine\utils\Config;
    use 
    pocketmine\utils\TextFormat;
    use 
    pocketmine\Player;

    use 
    pocketmine\level\Level;
    use 
    pocketmine\level\sound\FizzSound;

    class 
    QuadOres implements Listener {
        
      public 
    $scenarios;
      private 
    $plugin;
     
      public function 
    __construct(Loader $plugin){
        
    $this->plugin $plugin;
        
    $this->scenarios = new Config($this->plugin->getDataFolder() . "scenarios.yml");
      }

      public function 
    getPlugin(){
        return 
    $this->plugin;
      }
     
      public function 
    onBreak(BlockBreakEvent $event){
        
        
    $this->scenarios = new Config($this->plugin->getDataFolder() . "scenarios.yml");
        if(
    $this->scenarios->get("quadores") === true){
           if(
    $event->getBlock()->getId() == 15){
             
    $drops = array(Item::get(26504));
             
    $event->setDrops($drops);
    $click = new FizzSound($player);
             
    $player->getLevel()->addSound($click);
           }
         }

        if(
    $this->scenarios->get("quadores") === true){
           if(
    $event->getBlock()->getId() == 14){
             
    $drops = array(Item::get(26604));
             
    $event->setDrops($drops);
    $click = new FizzSound($player);
             
    $player->getLevel()->addSound($click);
           }
         }

          if(
    $this->scenarios->get("quadores") === true){
           if(
    $event->getBlock()->getId() == 16){
             
    $drops = array(Item::get(5004));
             
    $event->setDrops($drops);
    $click = new FizzSound($player);
             
    $player->getLevel()->addSound($click);
           }
         }
          if(
    $this->scenarios->get("quadores") === true){
           if(
    $event->getBlock()->getId() == 56){
             
    $drops = array(Item::get(26404));
             
    $event->setDrops($drops);
    $click = new FizzSound($player);
             
    $player->getLevel()->addSound($click);
           }
         }
          if(
    $this->scenarios->get("quadores") === true){
           if(
    $event->getBlock()->getId() == 13){
             
    $drops = array(Item::get(31804));
             
    $event->setDrops($drops);
    $click = new FizzSound($player);
             
    $player->getLevel()->addSound($click);
           }
         }
      }
    }
    BaseCommand.php
    PHP:
    <?php

    namespace UHC\Commands;

    use 
    UHC\Loader;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\command\PluginIdentifiableCommand;

    class 
    BaseCommand extends Command implements PluginIdentifiableCommand
    {

        private 
    $plugin;

        public function 
    __construct(Loader $plugin$name$description$usageMessage$aliases)
        {
            
    parent::__construct($name$description$usageMessage$aliases);
            
    $this->plugin $plugin;
        }

        public function 
    execute(CommandSender $sender$commandLabel, array $args)
        {
            if (
    $this->testPermission($sender)) {
                
    $result $this->onExecute($sender$args);
                if (
    is_string($result)) {
                    
    $sender->sendMessage($result);
                }
                return 
    true;
            }
            return 
    false;
        }

        public function 
    onExecute(CommandSender $sender, array $args)
        {

        }

        public function 
    getPlugin()
        {
            return 
    $this->plugin;
        }
    }
    CommandManager.php
    PHP:
    <?php

    namespace UHC\Managers;

    use 
    UHC\Commands\UHCCommand;
    use 
    UHC\Commands\ScenarioCommand;
    use 
    UHC\Loader;

    class 
    CommandManager {

        public 
    $plugin;

        public function 
    __construct(Loader $loader) {
            
    $this->plugin $loader;
            
    $this->init();
        }

        private function 
    init() {
            
    $commandMap $this->plugin->getServer()->getCommandMap();

            
    $commandMap->registerAll("uhc", [
                new 
    UHCCommand($this->plugin),
                new 
    ScenarioCommand($this->plugin),
            ]);
        }
    }
     
  7. Awzaw

    Awzaw Zombie Pigman Poggit Admin

    Messages:
    726
    GitHub:
    awzaw
  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.