Cooldown Error
1) It's showing me this, how should I fix it?
2) How can I make it into seconds, rather then having it into miliseconds?

43 Replies
⌛
This post has been reserved for your question.
Hey @shazim! Please useTIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here./close
or theClose Post
button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
The miliseconds it is saying isn't even accurate
💤
Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping
.
Warning: abusing this will result in moderative actions taken against you.
you would need to put the
System.currentTimeMillis() - cooldown.get(p.getUniqueId())
in ()
also you'd probably want to use variables because if you run System.currentTimeMillis()
twice after each other, it's possible that these are giving you a different time
in some cases (e.g. automatic time synchronization or daylight saving time), it is even possible that the second time is earlier than the first (which could be avoided using monotonic clocks like System.nanoTime()
)
for converting to seconds - just divide it by 1000
but think about what should happen if it's less than one secondThe
TimeUnit
class is also useful for converting between time units
For example you can do TimeUnit.MILLISECONDS.toSeconds(timeInMillis)
to convert a millisecond value to seconds
there are also toHours
, toMinutes
methods and so onohh, thank y’all so much
If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
I can’t code rn but if I have any questions I’ll let you know
Sorry but in where would I put that?
If you are able to guide me, that would be great. I'm not really good at Java, since I'm just beginning.
You wrote
I suggested changing it to
Or better refactor it to use variables right upfront:
If I wanted it to be into seconds would I do the following?
that was my second suggestion but I would put the variable before the
if
: https://discord.com/channels/648956210850299986/1394822979627651193/1394904022787428472also you'd probably want to use variables because if you run
System.currentTimeMillis()
twice after each other, it's possible that these are giving you a different timeSo like this?
Overlooked it indeed. Problem is here that you want to handle nonexistence in the same
if
and Java has no if let
or something like this. But one could just default to Instant.EPOCH
.order of operation matters
oops 💀
So like what should I exactly do? Could you futher explain?
What did you change in this example?
look at the differences ;)
I replaced
this.cooldown.containsKey(p.getUniqueId())
and cooldown.get(p.getUniqueId())
by cooldown.getOrDefault(p.getUniqueId(), 0L)
.
(Hint: Only works until 17.08.+292278994 07:12:55 UTC
)that makes using
System.nanoTime()
harder
Yeah your program shouldn't run that long
you can ignore that issue
like it's an issue only if you run it for that long without restarting
You should update your JDK which includes restarting your Java applications at least every two years
You cannot update your Java on your time capsule orbiting some proximate black hole.
That's not how monotonic clocks work
even orbiting a black hole doesn't break it with
System.nanoTime()
It can break 292 years without restart though.
And how do you achieve that?
If you are orbiting a black hole, it may be 292 years from the outside but monotonic clocks don't synchronize or similar. They are measing the time difference on the system itself, not outside
I can still wait more than 292 years before I call the function the next time.
That requires keeping the JVM running for that time which is unreasonable.
So was my setting.
💤
Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping
.
Warning: abusing this will result in moderative actions taken against you.
This just gave me alot more errors

Nvm I did it wrong
How'd we get from a cooldown error to blackholes 💀
welcome to the java server :GnuTrolling:
:thonk:
:spring:
💤
Post marked as dormant
This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.
In case your post is not getting any attention, you can try to use /help ping
.
Warning: abusing this will result in moderative actions taken against you.
.
Ty
Post Closed
This post has been closed by <@810632160418988053>.