Hey, I did some googeling, But I couldn't find the best way for a code to tempban someone. I tought I should store the date and time the player will be unbanned on? I dont know if that would work
Store the currentTimeMillis. When user joins, check if the currentTime is greater then the storedTime + The Seconds that the user got banned.
Not sure. You could also store the date + time (Example: 24-04-2017 16:50) and when user joins, check the date and time.
The System.currentTimeMillis() returns the amount of miliseconds since the Epoch. That is 1970, Januar 1st. To store a tempban I would recommand the following code: Code (Text): long timeBan = System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(10); //store your data //check when trying to login long time = //get data if(System.currrentTimeMillist()-time > 0){ //ban over // remove ban data } You can change the TimeUnit to minutes, hours, days and whatver you like
You have to use "System.currentTimeMillis();". This will give you the difference in milli seconds between current time and 1st Jan. 1970 With this time you can calculate everything with Tempban.
Much better solution: https://bukkit.org/threads/how-to-temp-ban-ban-a-player-using-just-one-line.432451/
Yeah, but if you got more than just one server or want to implement the bans in a webinterface, this method wouldn't work.
Store the players info in a MySQL database with a SimpleDateFormat and when they log on, check to see if the current time is teh same time or later then when there were supposed to be unbanned and if so, unban them.