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

Whats wrong here?

Discussion in 'Development' started by InspectorGadget, Feb 4, 2017.

  1. InspectorGadget

    InspectorGadget Zombie Pigman

    Messages:
    462
    GitHub:
    InspectorGadget
    Hi! I have been working on this plugin. I'm not sure whats wrong with it
    My Loader:
    PHP:
    <?php

    namespace RTG\ChatFilter;

    /* Essentials */
    use pocketmine\plugin\PluginBase;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\Player;
    use 
    pocketmine\Server;
    use 
    pocketmine\utils\Config;

    /* Execution */
    use pocketmine\command\CommandExecutor;

    use 
    RTG\ChatFilter\CMD\FilterCommand;

    use 
    pocketmine\event\player\PlayerChatEvent;

    class 
    Loader extends PluginBase implements Listener {
       
        public 
    $whitelist;
       
        public function 
    onEnable() {
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
           
            
    /* For Commands */
            
    $this->getCommand("cf")->setExecutor(new FilterCommand ($this));
           
            
    /* CFG Setup */
           
            
    $this->whitelist = array();
           
            @
    mkdir ($this->getDataFolder());
            
    $list = new Config($this->getDataFolder() . "bannednames.txt"Config::ENUM);
            
    $this->whitelist explode(", "$list->getAll());
           
            
    $this->getLogger()->info("[LEET] ChatFilter has been enabled!");
        }
       
        public function 
    onSave() {
            
    $list = new Config($this->getDataFolder() . "bannednames.txt"Config::ENUM);
            
    $list->setAll($this->whitelist);
            
    $list->save();
        }
           
            public function 
    onChat(PlayerChatEvent $e) {
               
                
    $p $e->getPlayer();
                
    $msg $e->getMessage();
                
    $list = new Config($this->getDataFolder() . "bannednames.txt"Config::ENUM);
                
    $get $list->getAll();
                   
                    if(
    strpos(strtolower($msg$get) !== FALSE)) {
                        
    $p->sendMessage("[ChatFilter] Triggered!");
                        
    $e->setCancelled(true);
                    }
                   
            }
           
           
            public function 
    getList() {
                return 
    $this->whitelist;
            }

        public function 
    onDisable() {
            
    $this->onSave();
        }
       
    }
    My Command:
    PHP:

    <?php

    namespace RTG\ChatFilter\CMD;

    /* Essentials */
    use pocketmine\Server;
    use 
    pocketmine\Player;
    use 
    pocketmine\command\CommandExecutor;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\command\Command;

    use 
    RTG\ChatFilter\Loader;

    use 
    pocketmine\utils\Config;
    use 
    pocketmine\utils\TextFormat as TF;

    class 
    FilterCommand implements CommandExecutor {
       
        public 
    $plugin;
       
        public function 
    __construct(Loader $plugin) {
            
    $this->plugin $plugin;
        }
       
        public function 
    onCommand(CommandSender $senderCommand $cmd$label, array $param) {
            switch(
    strtolower($cmd->getName())) {
               
                                case 
    "cf":
               
                    if(
    $sender->hasPermission("chatfilter.command")) {
                       
                        if(isset(
    $param[0])) {
                           
                            switch(
    strtolower($param[0])) {
                               
                                case 
    "help":
                               
                                    
    $sender->sendMessage("[ChatFilter] /cf add [name]");
                                    
    $sender->sendMessage("[ChatFilter] /cf rm [name]");
                                                                    
    $sender->sendMessage("[ChatFilter] /cf help");
                               
                                    return 
    true;
                                break;
                               
                                case 
    "add":
                                   
                                    if(isset(
    $param[1])) {
                                       
                                        
    $n $param[1];
                                       
                                            if(isset(
    $this->plugin->whitelist[strtolower($n)])) {
                                               
                                                
    $sender->sendMessage("[ChatFilter] The word '$n' Exists!");
                                               
                                            }
                                            else {
                                               
                                                
    $this->plugin->whitelist[strtolower($n)] = $n;
                                                
    $sender->sendMessage("[ChatFilter] You have successfully added $n to the ban list!");
                                                
    $this->plugin->onSave();
                                               
                                            }
                                       
                                    }
                                    else {
                                        
    $sender->sendMessage("[ChatFilter] /cf help");
                                    }
                               
                                    return 
    true;
                                break;
                                                           
                                                            case 
    "rm":
                                                               
                                                                if(isset(
    $param[1])) {
                                                                   
                                                                    
    $n $param[1];
                                                                   
                                                                        if(isset(
    $this->plugin->whitelist[strtolower($n)])) {
                                                                            unset(
    $this->plugin->whitelist[strtolower($n)]);
                                                                            
    $sender->sendMessage("[ChatFilter] You have removed $n from the list!");
                                                                            
    $this->plugin->onSave();
                                                                        }
                                                                        else {
                                                                            
    $sender->sendMessage("[ChatFilter] The word $n doesn't exist in the List!");  
                                                                        }
                                                                     
                                                                }
                                                                else {
                                                                    
    $sender->sendMessage("[ChatFilter] /cf help");
                                                                }
                                                               
                                                                return 
    true;
                                                            break;
                                                           
                                                            case 
    "list":
                                                               
                                                                
    $list = new Config($this->plugin->getDataFolder() . "bannednames.txt"Config::ENUM);
                                                                
    $l $list->getAll(true);
                                                                
    $im implode(", "$l);
                                                                
    $sender->sendMessage($im);
                                                               
                                                                return 
    true;
                                                            break;
                                   
                            }
                               
                        }
                        else {
                            
    $sender->sendMessage("[ChatFilter] /cf help");
                        }

                    }
                    else {
                        
    $sender->sendMessage(TF::RED "You have no permission to use this command!");
                    }
               
                    return 
    true;
                                break;
               
            }
           
        }
           
    }
    GitHub: https://github.com/RTGDaCoder/ChatFilter
     
  2. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    Any errors or crashes given?
     
  3. InspectorGadget

    InspectorGadget Zombie Pigman

    Messages:
    462
    GitHub:
    InspectorGadget
    None
     
  4. InspectorGadget

    InspectorGadget Zombie Pigman

    Messages:
    462
    GitHub:
    InspectorGadget
    Capturew.PNG Capture.PNG

    It gives this
     
  5. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    $config->getAll() already returns an array of every key => value in the config. explode() can only be used on strings, not arrays.
     
  6. InspectorGadget

    InspectorGadget Zombie Pigman

    Messages:
    462
    GitHub:
    InspectorGadget
    What about getAll(true)?
     
  7. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    Why do you want to use explode?
     
  8. InspectorGadget

    InspectorGadget Zombie Pigman

    Messages:
    462
    GitHub:
    InspectorGadget
    I was trying to get that lines working with checking with the ChatEvent.
     
  9. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
  10. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    What you could do is: $data = file_get_contents($file)
    Then $words = explode(",", $data);
     
  11. InspectorGadget

    InspectorGadget Zombie Pigman

    Messages:
    462
    GitHub:
    InspectorGadget
  12. InspectorGadget

    InspectorGadget Zombie Pigman

    Messages:
    462
    GitHub:
    InspectorGadget
    Ok, noted
     
  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.