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

Client Ban assistance

Discussion in 'Development' started by InspectorGadget, Dec 6, 2016.

  1. InspectorGadget

    InspectorGadget Zombie Pigman

    Messages:
    462
    GitHub:
    InspectorGadget
    Hi! I have been working on a BanCID plugin recently.. I am not very sure about the issue with the plugin. The plugin is suppose to can a players CID when I do /bancid <name> and stores into a YAML file and checks it when the player joins even with a different Username or IP. Any help would be appreciated! Thanks
    Code:
    PHP:
    <?php

    namespace BCID;

    use 
    pocketmine\Server;
    use 
    pocketmine\Player;
    use 
    pocketmine\utils\Config;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\event\player\PlayerJoinEvent;
    use 
    pocketmine\command\CommandSender;

    class 
    Main extends PluginBase implements Listener {

        public function 
    onEnable() {
           
            if(!
    is_dir($this->getDataFolder())) {
                @
    mkdir($this->getDataFolder());
            }
       
            
    //$this->saveResource("clientBan.yml");
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
            
    $this->clientBan = new Config($this->getDataFolder() . "clientBan.yml"Config::YAML, array());
           
           
        }

        public function 
    onCommand(CommandSender $senderCommand $cmd$label, array $args) {
            switch(
    $cmd->getName()) {
                case 
    "bancid":
                if(
    $sender->hasPermission("bancid")) {
                    if(isset(
    $args[0])) {
                        
    $name $args[0];
                        
    $pl $this->getServer()->getPlayer($args[0]);
                        if(
    $pl instanceof Player) {
                            
    $this->clientBan->set(strtolower($pl->getName()), $pl->getClientId());
                            
    $this->clientBan->save();
                            
    //$pl->setBanned(true);
                            
    $pl->kick("You have been banned"false);
                            
    $sender->sendMessage("You have successfully CID banned $name!");
                        } else {
                            
    $sender->sendMessage($args[0] . " isn't online!");
                        }
                    } else {
                        
    $sender->sendMessage("Usage: /bancid {name}");
                    }
                } else {
                    
    $sender->sendMessage("You have no permission to use this command!");
                }
                       return 
    true;
                case 
    "pardoncid":
                if(
    $sender->hasPermission("pardoncid")) {
                    if(isset(
    $args[0])) {
                       if(
    $this->clientBan->exists($name strtolower($args[0]))) {
                        
    $this->clientBan->remove($name);
                        
    $this->clientBan->save();
                        
    $sender->sendMessage("You have CID pardoned $name!");
                       } else {
                        
    $sender->sendMessage($args[0] . " doesn't exist!");
                       }
                    } else {
                        
    $sender->sendMessage("Usage: /pardoncid {name}");
                    }
                } else {
                    
    $sender->sendMessage("You have no permission to use this command!");
                }
                return 
    true;
            }
        }
       
        public function 
    onJoin(PlayerJoinEvent $e) {
        
    $cid $e->getPlayer()->getClientId();
        
    $name strtolower($e->getPlayer()->getName());
            
    //if($this->clientBan->exists(strtolower($name))) {
                
    if($cid == $this->clientBan->getAll()) {
                    
    $e->getPlayer()->kick("You have been CID banned!");
                    
    //$e->getPlayer()->setBanned(true);
                //}
            
    }
        }
       
        public function 
    onDisable() {
            
    $this->clientBan->save();
        }
    }
    GitHub SRC: https://github.com/RTGNetworkkk/BanCID
     
  2. LilCrispy2o9

    LilCrispy2o9 Spider Jockey

    Messages:
    43
    GitHub:
    lilcrispy2o9
    PHP:
    public function onJoin(PlayerJoinEvent $e) {
        
    $cid $e->getPlayer()->getClientId();
        
    $name strtolower($e->getPlayer()->getName());
            
    //if($this->clientBan->exists(strtolower($name))) {
                
    if($cid == $this->clientBan->get($name)) {  //You need to get the value associated with the player name
                    
    $e->getPlayer()->kick("You have been CID banned!");
                    
    //$e->getPlayer()->setBanned(true);
                //}
            
    }
        }
    Try that
     
  3. InspectorGadget

    InspectorGadget Zombie Pigman

    Messages:
    462
    GitHub:
    InspectorGadget
    It doesn't work, it allows the player to use a different username and join..
     
  4. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
  5. InspectorGadget

    InspectorGadget Zombie Pigman

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