this is my player saving
Code:
public class PlayerBackupTask extends Task {
//every 2 min
public PlayerBackupTask() {
super(250, true, StackType.NEVER_STACK, BreakType.NEVER, TaskIdentifier.CHARACTER_BACKUP);
}
@Override
public void execute() {
Thread t = new Thread(new Runnable() {
@Override
public void run() {
backup();
System.out.println("Saved all players on seperate thread.");
}
});
t.start();
try {
t.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
@Override
public void onStop() {
}
public static void backup() {
for (Player players : World.getPlayers()) {
if (players != null && players.isActive() && World.getActivePlayers() >= 1) {
PlayerSave.save(players);
}
}
}
// public static void copyFile(File sourceFile, File destFile) throws IOException {
// Files.copy(Paths.get(sourceFile.getPath()), Paths.get(destFile.getPath()), StandardCopyOption.COPY_ATTRIBUTES);
// }
}
it's like every 2 mins and is called on startup like so;
Code:
TaskQueue.queue(new PlayerBackupTask());
however, i could do this:
Code:
public class PlayerBackupTask extends Task {
private final Player player;
//every 2 min
public PlayerBackupTask(Player player) {
super(250, true, StackType.NEVER_STACK, BreakType.NEVER, TaskIdentifier.CHARACTER_BACKUP);
this.player = player;
}
@Override
public void execute() {
Thread t = new Thread(new Runnable() {
@Override
public void run() {
PlayerSave.save(player);
System.out.println("Saved all players on seperate thread.");
}
});
t.start();
try {
t.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
@Override
public void onStop() {
}
// public static void copyFile(File sourceFile, File destFile) throws IOException {
// Files.copy(Paths.get(sourceFile.getPath()), Paths.get(destFile.getPath()), StandardCopyOption.COPY_ATTRIBUTES);
// }
}
and then when a player logs in call this
Code:
TaskQueue.queue(new PlayerBackupTask());
instead of being called on start up and saving for every player all the time.
which would better for performance purposes