Hello, i have created a ban system with database server and i don't have idea how to do a sys that when player is banned then remove that ban for example on the next day or 01/01/2018 or after hours.. How can i do that? Tasks? Calendar function(has on pmmp?)?
When banning player just store time() + 1 day and then check if time() if bigger than time that's saved when you was banning player
strtotime() PHP: $tomorrow = strtotime("+1 day");$nextMin = strtotime("+1 minute");$tomorrowPlus30Mins = strtotime("+1 day 30 minute"); You can use a plugin task that runs throughout OR check out mysql events, its an interesting topic. I'd go with mysql events if I were you.
But have any example? Like if i use strtotime on a database then the time updates automatically? Like.. They goes to null alone?
That's where the tasks come in. You can't automate the process so you use tasks or mysql events. strtotime() returns Unix timestamp strtotime("+5 minutes") is the same as time() + 300[citation needed] I don't think you got me on that, strtotime() doesn't exist in MySQL but you can have a MySQL event run every 1 minute or so which executes Code: DELETE FROM table WHERE time < UNIX_TIMESTAMP();
He don't want to use tasks PHP: /** @var \mysqli $mysql */ public $mysql; public static function addBan($player,$days){ $time = time() + $days * 24 * 3600; $this->mysql->query ( "UPDATE players SET bantime = '".$time."' WHERE name = '".$this->escape_string(trim(strtolower($player)))."'" ); } Then check if is banned or not when joining PHP: if(time() >= $bantime){ //Unban} You can use strtime() as Muqsit said, this is just only example
Or you could just use PMMP API...... https://github.com/pmmp/PocketMine-MP/blob/master/src/pocketmine/permission/BanList.php#L108 to check if the player is banned https://github.com/pmmp/PocketMine-MP/blob/master/src/pocketmine/permission/BanList.php#L86
Why delete the ban entirely? Just check the timestamp to make sure that they’re still banned before kicking them.
He never said he doesn't need any tasks involved. Plus you'll be stacking up on a crap ton of expired entries in the table that way.
That's right! I prefer without using tasks. So if i use that, the 'bantime' of that player goes to null automatically?
No it doesn't. Everything will remain as it is, nothing gets changed. You'll need to compare the time field in the table with the current Unix timestamp. If you use tasks, you'll only need to check if the entry exists. Code: SELECT EXISTS(SELECT 1 FROM table WHERE player=?) But it's up to you, bans are manually handled so having 10k+ entries will take years and yet it's an insignificant number for mysql db. Use tasks only if you want to clean out the expired entries automatically. Assuming you have a well-structured table, you will need to call ...ON DUPLICATE KEY UPDATE... because you aren't sweeping off the expired entries. Or alternatively a delete query before insert.
Note that time string parsing is an expensive operation, and this is totally avoidable. If you write it clearly (e.g. write 60 * 60 * 24 * 7 rather than 604800), everyone (who knows that PHP's time unit is in seconds) knows you're trying to write "one week", especially when you put it after time().