@MG127 afraid not, but you can use a repeating task of 1 interval to check it. (the time increments by one every tick)
Make a repeating task that is executed every 24000 ticks (1 day), starting after 24000-world.getTime() ticks. But i guess this will break if any plugin changes the time of the world, although i don't know for sure.
If you do a repeating task, make sure it stays consistant with the world with something like this... Code: int time = 0; (repeating task here) if (time == world.getTime()) { time++; } else { time = world.getTime(); time++; } (end repeating task)
Please re-read what you posted, it currently simply sets time to world.getTime()+1, no matter what is was before.
@steaks4uce never ask if a variable is identical with a large value (long,float,double etc) you will never hit it
No, it keeps it in line with the world time and adds one, which is why its in a async task, and if it doesn't, set it to the world time (too keep from being invalid), and adds one, like the earlier statement.
@MG127 that is only the case with values that use decimal calculations, like the location values of an entity. The long time value is simply incremented with one every tick, so it's perfectly fine to use == every tick there. == Always works, unless the value to check against is not bit-precise. (checking against locX == 12.0 is such an example, this will never happen unless the entity is spawned at those coordinates)
Just look at your code again: Code: int time = 0; (repeating task here)// time can be anything after this if (time == world.getTime()) {//if true, time is world.getTime() here time++; //time is world.getTime()+1 here } else { time = world.getTime();//time is world.getTime() here time++; //time is world.getTime()+1 here } //time is world.getTime()+1 here, no matter what. The if statement has no effect at all. (end repeating task)
checking every tick if the time has reached the target value is damn ineffective. i would check at least every 200 ticks. even if you start at a value that would reach the target value after x*200, there is at least a 50% chance to miss it with check for being equal.
@MG127 What exactly do you mean with 'miss it'? The synchronized tasks are executed right before/after the world tick functions, which means they are 100% synchronized with the world time. If you increment the time in your task and check it with the world time, it is guaranteed it will always be equal, unless another plugin altered the time in the meantime. Anyway, this is not needed at all, since you only want to know if the time changed from night to day. So all you have to do is get if it's day from the time value and store a boolean with 'isDay'. If they are not the same, then it either turned day or night.
@bergerkiller i'll allmost never use synchonized thasks, they use more performance or drain more from the main thread and for such a simple task to check if it's a new day it's just a waste of ressources the isDay boolean is maybe something good to start with
Thats the point, it keeps the world time inlined with the integer, so then you could create a simple method to check, or just operate off world.getTime().