~Lester Knome's Easy-To-Use Tutorials~
MAKE SURE YOU MAKE A BACKUP
FIXED TIMER!!!
Make a new file called: Timer.java and add:
Code:
/*~Lester Knome's Easy-To-Use Tutorials~*/
public class Timer
{
//Milliseconds
public static int globalMili;
public static int miliTimer = -1;
//Seconds
public static int globalSeconds;
public static int secondsTimer = -1;
public static boolean secTick = false;
//Minutes
public static int globalMinutes;
public static int minutesTimer = -1;
public static int minTick = 0;
public void process()
{
//Milliseconds
if(globalMili < miliTimer) globalMili++;
//Resets after 1 hour
if(globalMili == 3600000) {
resetMilli(false);
}
//Seconds
if(globalSeconds < secondsTimer) {
if(secTick)
{
globalSeconds++;
}
if(secTick) secTick = false;
if(!secTick) secTick = true;
}
//Resets after 5 hours
if(globalSeconds == 18000) {
resetSec(false);
}
//Minutes
if(globalMinutes < minutesTimer) {
minTick++;
if(minTick == 120)
{
globalMinutes++;
minTick = 0;
}
}
//Resets after 25 hours
if(globalMinutes == 1500) {
resetMin(false);
}
}
//Milliseconds
public static void resetMilli(boolean timer)
{
globalMili = 0;
if (timer) miliTimer = -1;
}
//Seconds
public static void resetSec(boolean timer)
{
globalSeconds = 0;
secTick = false;
if (timer) secondsTimer = -1;
}
//Minutes
public static void resetMin(boolean timer)
{
globalMinutes = 0;
minTick = 0;
if (timer) minutesTimer = -1;
}
//Milliseconds
public static int Milliseconds(int milli, boolean reset)
{
if(reset)
{
resetMilli(true);
}
miliTimer = milli;
return milli - globalSeconds;
}
//Seconds
public static int Seconds(int secs, boolean reset)
{
if(reset)
{
resetSec(true);
}
secondsTimer = secs;
return secs - globalSeconds;
}
//Minutes
public static int Minutes(int mins, boolean reset)
{
if(reset)
{
resetMin(true);
}
minutesTimer = mins;
return mins - globalSeconds;
}
}
In server.java under:
Code:
public static PlayerHandler playerHandler = null;
add:
Code:
public static Timer Timer = null;
and under:
Code:
playerHandler = new PlayerHandler();
add:
Code:
Timer = new Timer();
Now to start the global Timer add:
Code:
server.Timer.process();
to procces.java
If you don't have it, just add it to client.java's process.
Using it:
To Start Timer:
For milliseconds:
Code:
Milliseconds(Milliseconds till reaches 0?, true);
For Seconds:
Code:
Seconds(Seconds till reaches 0?, true);
For Minutes:
Code:
Minutes(Minutes till reaches 0?, true);
To call timer:
For milliseconds:
Code:
if(Milliseconds(Milliseconds till reaches 0?, false)){
//Code
}
For Seconds:
Code:
if(Seconds(Seconds till reaches 0?, false)) {
//Code
}
For Minutes:
Code:
if(Minutes(Minutes till reaches 0?, false)) {
//Code
}
and to reset:
Milliseconds:
Seconds:
Minutes
Previous Tutorial: None
Next Tutorial: [Only registered and activated users can see links. ]