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

Unpunish command

Discussion in 'Development' started by ZackyVN, Jan 26, 2019.

  1. ZackyVN

    ZackyVN Baby Zombie

    Messages:
    150
    I have this code
    PHP:
    <?php

    namespace Core\command;

    use 
    Core\Main;
    use 
    pocketmine\Player;
    use 
    pocketmine\Server;
    use 
    pocketmine\command\CommandSender;

    class 
    UNPunishCommand extends BaseCommand implements Listener{

        public function 
    __construct(Main $plugin){
                
    $this->plugin $plugin;
                
    parent::__construct($plugin"unpunish""Unpunish A Player""/unpunish [Player]", ["unp"]);
            }

        public function 
    execute(CommandSender $sender$commandLabel, array $args) : bool{
            if(!
    $sender->hasPermission("core.punish") || !$sender->hasPermission("core")){
                
    $sender->sendMessage(Main::PERM_RANK);
                return 
    true;
            }
                if(empty(
    $args[0])){
                    
    $sender->sendMessage("§c§l!§r§e Usage: /unpunish <Player>. Pleason enter full name!");
                return 
    true;
            }
            
    $target $this->plugin->getServer()->getPlayer($args[0]);
            
    $banInfo $this->plugin->db->query("SELECT * FROM banPlayers");
                if(
    $target === $banInfo){
                    
    $banInfo $this->db->query("SELECT * FROM banPlayers WHERE player = '$target';");
                    
    $array $banInfo->fetchArray(SQLITE3_ASSOC);
                        if(!empty(
    $array)) {
                            
    $this->db->query("DELETE FROM banPlayers WHERE player = '$target';");
                            
    $sender->sendMessage("§aYou unbanned $target");
                        }
                }
                return 
    false;
        }
    }
    WHen i typed the command with a player name (in the .db file), it didnt do anything
     
  2. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    Replace $this->db with $this->plugin->db
     
  3. ZackyVN

    ZackyVN Baby Zombie

    Messages:
    150
    It still the same
    Updated code:
    PHP:
    ?php

    namespace Core\command;

    use 
    Core\Main;
    use 
    pocketmine\Player;
    use 
    pocketmine\Server;
    use 
    pocketmine\command\CommandSender;
    use 
    muqsit\invmenu\InvMenuHandler;
    use 
    muqsit\invmenu\InvMenu;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\item\Item;
    use 
    pocketmine\inventory\transaction\action\SlotChangeAction;
    use 
    pocketmine\block\Block;

    class 
    UNPunishCommand extends BaseCommand implements Listener{

        public function 
    __construct(Main $plugin){
                
    $this->plugin $plugin;
                
    parent::__construct($plugin"unpunish""Unpunish A Player""/unpunish [Player]", ["unp"]);
            }

        public function 
    execute(CommandSender $sender$commandLabel, array $args) : bool{
            if(!
    $sender->hasPermission("core.punish") || !$sender->hasPermission("core")){
                
    $sender->sendMessage(Main::PERM_RANK);
                return 
    true;
            }
                if(empty(
    $args[0])){
                    
    $sender->sendMessage("§c§l!§r§e Usage: /unpunish <Player>. Pleason enter full name!");
                return 
    true;
            }
            
    $banInfo $this->plugin->db->query("SELECT * FROM banPlayers");
            
    $target $args[0];
                if(
    $target === $banInfo){
                    
    $banInfo $this->plugin->db->query("SELECT * FROM banPlayers WHERE player = '$target';");
                    
    $array $banInfo->fetchArray(SQLITE3_ASSOC);
                        if(!empty(
    $array)) {
                            
    $this->plugin->db->query("DELETE FROM banPlayers WHERE player = '$target';");
                            
    $sender->sendMessage("§aYou unbanned $target");
                        }else{
                            
    $sender->sendMessage("§c$target isnt banned from server!");
                        }
                }
                return 
    true;
        }
    }
     
  4. Diduhless

    Diduhless Baby Zombie

    Messages:
    199
    GitHub:
    Diduhless
    You are comparing an object (player) with a bool (query), it's not gonna do anything because the if won't be executed.
     
  5. ZackyVN

    ZackyVN Baby Zombie

    Messages:
    150
    How to make this work?
     
  6. Diduhless

    Diduhless Baby Zombie

    Messages:
    199
    GitHub:
    Diduhless
    Just delete the if, there's no need to check if the player is in the table if you do this
    PHP:
    WHERE player '$target'
     
  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.