Jump to content
Sign in to follow this  
Dally

[PI] Character Saving Timer

Recommended Posts

This is somewhat a tutorial, but I'll consider it as a snippet as its simple. It can be converted easily for higher revisions.

Create the class [B]Saving [/B]in a new package named [B]timers[/B] and add this in it:

[CODE]
package server.timers;

/**
*
* @author thaBoom
*
*/

public class Saving {

static Client c;

/**
* Runs the timer.
*/
public static void startTimer() {
int timer = Config.SAVE_TIMER;
if (timer == 1) {
PlayerSave.saveGame(c);
c.sendMessage("Your player has been saved.");
timer = 250;
}
if (timer > 0) {
timer--;
}
}

private transient Player player;

public Saving(Player player) {
this.player = player;
}
}
[/CODE]

Add this constant anywhere in your [B]Config [/B]class.

[CODE]
public static final int SAVE_TIMER = 120;
[/CODE]

In the void [B]initialize()[/B] of the class [B]Client [/B]add:

[CODE]
Saving.startTimer();
[/CODE]

Add the [U][COLOR="#FFA500"]necessary imports in the classes above to prevent errors.[/COLOR][/U] and then this should save all your players every couple minutes. Edited by Thee Lion

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×