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

Remove permission after 60 min

Discussion in 'Development' started by Driesboy, Dec 29, 2016.

  1. Driesboy

    Driesboy Spider Jockey

    Messages:
    34
    GitHub:
    driesboy
    Hello everybody

    I want some help for my plugin
    after my player use the command /getvipforfree
    i want that they have vip for 60 min but after 60 min the vip permision for that person will be removed
     
  2. ZakousseMC

    ZakousseMC Spider Jockey

    Messages:
    46
    GitHub:
    ZakousseMC
  3. kaliiks

    kaliiks Zombie

    Messages:
    250
    create task and use
    PHP:
    $e->getPlayer()->removeAttachment();
    In the task
     
  4. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    Note that it could be cheated if you'd use a delayed task with 60 minutes and something happens for example a server restart.
     
    Muqsit likes this.
  5. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    Better save the time when issuing the command and then check every few ticks if the current time >= saved time +1
     
    Sandertv likes this.
  6. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    $e? A task is something different than an event. You have to either pass it on the task call, or foreach the online players.
     
  7. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Schedule a delayed task for 20*60*60 ticks. (20 ticks = 1second)
    Thing is, it won't be EXACTLY 60 minutes if you use a delayed task, not because my calculations aren't exact or anything, but because server's tick is not the most accurate way of timing your tasks. Ticks can change over time (due to lag).

    The alMOST accurate way would be a repeating task that's ran every 20 ticks (1second), with calculation of UNIX timestamp.
     
  8. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    That's what I wanted to say, yours just explained better :p
     
    Muqsit likes this.
  9. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    Better save it into config with TIME as markers
     
    Sandertv, HimbeersaftLP and Muqsit like this.
  10. Driesboy

    Driesboy Spider Jockey

    Messages:
    34
    GitHub:
    driesboy
    how i can add a player?
     
  11. Driesboy

    Driesboy Spider Jockey

    Messages:
    34
    GitHub:
    driesboy
  12. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    Save his name and the current time to config when the player issues the command
     
  13. Driesboy

    Driesboy Spider Jockey

    Messages:
    34
    GitHub:
    driesboy
    can you give me more info im not good in tasks :(
     
  14. Driesboy

    Driesboy Spider Jockey

    Messages:
    34
    GitHub:
    driesboy
  15. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    What I would do would be scheduling a repeatingtask on enable every second or so. In that repeating task check for every online player if time() - $times->get($playername) is equal to or bigger than 3600. (time() in secs right?) Then if it is remove the VIP.

    Then oncommand save time() in a player name using something like this: $times->set($playername, time()). Hope that helps.
     
    HimbeersaftLP likes this.
  16. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    You'll also have to check if the time is already set when issuing the cmd, so players can't cheat a longer time.
     
    Sandertv likes this.
  17. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    This is an exempt out of my delayedCMDs plugin:
    PHP:
    class delayedCMDsExecutor extends PluginTask{
        public function 
    __construct(rootPlugin $main$parent){
            
    parent::__construct($main);
            
    $this->server $parent->server;
            
    $this->delayedCMDs $parent;
        }
       
        public function 
    onRun($currentTick){
            
    $currTime time();
            foreach(
    $this->delayedCMDs->getDelayedCMDs() as $key => $delayedCMDdata){
                
    $scheduleTime $delayedCMDdata[0];
                
    $delay $delayedCMDdata[1];
                if(
    $currTime >= $scheduleTime $delay){
                    
    $command $delayedCMDdata[2];
                    
    $this->server->dispatchCommand(new ConsoleCommandSender(), $command);
                    
    $this->delayedCMDs->removeCmd($key);
                }
            }
        }
    }
     
  18. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    The best way would be Lambo's method from CombatLogger using '&' (reference).

    MainClass...(or not?)
    PHP:
    public $illuminati = [];

    public function 
    onEnable() {
        
    $this->getServer()->getScheduler()->scheduleRepeatingTask(new Illuminati($this$this->illuminati), 20);
    }

    public function 
    setPermission(Player $playerstring $permissionint $time 60) {
        
    //Time is in minutes.
        
    $player->addAttachment($permission);
        
    $time time() + ($time*60);//is there a better way?
        
    $this->illuminati[$player->getName()] = ["time" => $time"permission" => $permission];
    }
    Illuminati.php
    PHP:
    private $illuminati;
    public function 
    __construct(MainClass $plugin, &$illuminati) {
        
    $this->illuminati = &$illuminati;
        
    parent::__construct($plugin);
    }

    public function 
    onRun($tick) {
        foreach (
    $this->illuminati as $data) {
            if (
    $data["time"] - time() <= 0) {
                
    $player array_search($data$this->illuminati);
                
    $permission $data["permission"];
                
    Server::getInstance()->getPlayer($player)->removeAttachment($permission);
                unset(
    $this->illuminati[$player]);
            }
        }
    }


    pro spooner and spoonfeeder. (if u know what I mean...spooner e.e...lywin)
     
  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.