Anybody?
|
Okay, I'm making a member system from scratch for my server. Everything is working apart from the days don't count down.
I've made it record the System.currentTimeMillis() when the member registers to a text file.
I've got a FileReader reading the currentTimeMillis which is in the text files. The data goes into player.java in public String lastTime = "";
I need the currentTimeMillis subtracted from the read data. So it's something like this.
if((System.currentTimeMillis - lastTime) >= 86400000){
But it wont work because the lastTime is a string or whatever... I've been trying to make it work and it's started annoying me badly. Can somebody please help... :/
Anybody?
what are you trying to say? explain a little more.
something like...
make lasttime an int and run a timer in process??
@ Dennis
I'm trying to make the string lastTime into an int so it can be subtracted from the System.currentTime... (how do I change it from a string to an int without it nackering up the filereader etc?)
And I wasn't planning on putting it into the process. I was going to put it in login.java etc. When a user logs in (and they are a member) it checks to see if a day or more has advanced since the FileReader's time. If the time has advanced it removes the member days and then it puts the current time into the file to be checked next time, so it doesn't keep taking days each time a user logs in.
Heres one way to convert a string to a int
use that code ^Code:if((System.currentTimeMillis - Integer.parseInt(lastTime))
@ Dennis
It didn't work last time.. But I'll have another go now.
@ Zachhh
Thanks I think i'll try that before trying what Dennis said!
---------- Post added at 05:19 PM ---------- Previous post was at 04:52 PM ----------
Okay guys it works in compiling but when I actually try(with a command), the debug gets an error.
Here's the code I used:
Here's the error:Code:public void RefreshMemberDay(Player p) { LoadMemberDay(p); if((System.currentTimeMillis() - Integer.parseInt(p.lastTime)) >= 86400000){ p.frames.sendMessage(p, "Membership day test succesfull."); } }
Uhh now what?Code:java.lang.NumberFormatException: For input string: "1235066653625" at java.lang.NumberFormatException.forInputString(Unknown Source) at java.lang.Integer.parseInt(Unknown Source) at java.lang.Integer.parseInt(Unknown Source) at Bulby.players.MemberHandler.RefreshMemberDay(MemberHandler.java:67) at Bulby.io.packets.Commands.handlePacket(Commands.java:947) at Bulby.io.PacketManager.parsePacket(PacketManager.java:382) at Bulby.io.Packets.parseIncomingPackets(Packets.java:94) at Bulby.Engine.run(Engine.java:187) at java.lang.Thread.run(Unknown Source)
lol oh wait, i see the problem (well one of them if there are any more) you are going out of bounds on int (it only goes so far) so use a double (or long) instead of parse int
i don't know i'm still confused i just need to take a second and think about this.Code:double.parseDouble(p.lastTime)
Lol I was thinking that the number was too long for the int, according to some java forum thingy anyway. I'll try the parseDouble what you said ^ and let you know.
Yay thanks mate. Got it working after adding a capital D for Double.parse... All I need to do now is try make it check for two days, then 3 days. Then anything after 3 days can just remove 3 days member
Sure I'll be able to do that - Thanks for everything.. Rep+
sorry for lowercase d, didn't mean it
but np
« Previous Thread | Next Thread » |
Thread Information |
Users Browsing this ThreadThere are currently 1 users browsing this thread. (0 members and 1 guests) |