This will add a 2 minute auto save to prevent rollback. This is literally if your vps goes down, you accidentally close eclipse or your server.bat, or if the server crashes.
Step One:
Open your Vencillio source, and navigate to
Code:
Src/Com/Vencillio/core/task/impl
You'll know you're in the right place if you see a file called "WalktoTask.java"
Create a new Java Document and call it PlayerBackupTask
Paste this code inside of it
Code:
package com.vencillio.core.task.impl;
import java.util.Arrays;
import java.util.Optional;
import com.vencillio.core.task.Task;
import com.vencillio.rs2.content.io.PlayerSave;
import com.vencillio.rs2.entity.World;
import com.vencillio.rs2.entity.player.Player;
public class PlayerBackupTask extends Task {
//every 2 min
public PlayerBackupTask() {
super(650, 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("Starting up Anti-Rollback Task...");
}
});
t.start();
try {
t.join();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
@Override
public void onStop() {
}
public static void backup() {
Arrays.stream(World.getPlayers()).forEach(player -> {
Optional<Player> node = Optional.ofNullable(player);
node.ifPresent(p -> PlayerSave.save(p));
});
}
}
Save and Close the File.
Step Two:
Now navigate to
Code:
Src/Com/Vencillio/Core
And open up "GameThread.java"
Ctrl-F and search for
Code:
GameDataLoader.load();
You should see this
Code:
logger.info("Loading game data..");
GameDataLoader.load();
Directly under the GameDataLoader.load(); paste this
Code:
logger.info("Turning on Player Backup System...");
TaskQueue.queue(new PlayerBackupTask());
Don't close the file yet. If you're not using an IDE it wont suggest the import. If you are using an IDE when it will suggest the Import. Lets go ahead and manually add the import, unless you feel like IDE should do it.
At the top where you see all the imports add this import.
Code:
import com.vencillio.core.task.impl.PlayerBackupTask;
Save and Close the File.
Step Three:
Let me state this clearly because last snippet I got shit for this. If you're using an IDE it will compile your source automatically. If you're not using an IDE, Compile your server.
Congratulations you're done.