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

Solved TimeBan help

Discussion in 'Development' started by Kyd, Dec 2, 2017.

  1. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    Hi, I want to ban player for selected amount of days.. I have tried it, but all time it's bugging all times (because my maths is on low level)

    Here I add ban to player:
    PHP:
    public static function addBan($player,$days){
            
    $time time() / 1000;
            
    self::getConnection()->query
            
    (
                
    "UPDATE players SET bantime = '".$time."' WHERE name = '".self::getConnection()->escape_string(trim(strtolower($player)))."'"
            
    );
            
    $final $days 86400;
            
    self::getConnection()->query
            
    (
                
    "UPDATE players SET bandays = '".$final."' WHERE name = '".self::getConnection()->escape_string(trim(strtolower($player)))."'"
            
    );
            echo 
    'Banned player ' $player ' for ' $days ' days.';
        }
    and then I check time that player is banned
    PHP:
    public function onJoin(PlayerJoinEvent $e){
       
    $p $e->getPlayer();
       if(
    DatabaseManager::getPlayer($p->getName()) == null){
       
    DatabaseManager::registerPlayer($p->getName());
       
    $p->sendMessage("§aYou we're registred into database!");
       }
       if(
    DatabaseManager::getPlayer($p->getName())['bandays'] !== 0){
       
    $duration time() / 1000 DatabaseManager::getPlayer($p->getName())['bantime'];
       if(
    $duration DatabaseManager::getPlayer($p->getName())['bantime']){
        
    $p->sendMessage('§cYour ban expired!');
       }else{
        
    $p->sendMessage('§eYour ban expire in: ' $duration);
       }
       }
       }
    but when it say when ban expire it say things like -0.24399999994785 etc.. :/ and I want it to say days that is player banned...
    I can't find what I'm doing bad..
    DatabaseManager::getPlayer($p->getName())['bantime'] is time() / 1000 when player was banned and
    DatabaseManager::getPlayer($p->getName())['bandays'] is number of days * 86400 to get seconds of days player is banned for.

    EDIT: I'm saving all data into MySQL
     
  2. Derpific

    Derpific Spider Jockey

    Messages:
    44
    GitHub:
    Derpific
  3. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
  4. Teamblocket

    Teamblocket Zombie

    Messages:
    301
    GitHub:
    teamblocket
    Why divide?
     
  5. DaPigGuy

    DaPigGuy Slime

    Messages:
    86
    GitHub:
    DaPigGuy
    jasonwynn10, Kyd and Teamblocket like this.
  6. SkyZone

    SkyZone Slime

    Messages:
    95
    Use /DateTime()
     
  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.