Thread: [Vencillio] - Adding 2min Auto Save to Prevent Rollback

Page 1 of 2 12 LastLast
Results 1 to 10 of 12
  1. #1 [Vencillio] - Adding 2min Auto Save to Prevent Rollback 
    Registered Member Rex_'s Avatar
    Join Date
    Jul 2015
    Posts
    43
    Thanks given
    3
    Thanks received
    7
    Rep Power
    0
    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.
    https://www.rune-server.ee/static/signaturepic/sigpic295363_1.gif
    Reply With Quote  
     

  2. #2  
    Banned

    Join Date
    Jul 2017
    Posts
    195
    Thanks given
    54
    Thanks received
    57
    Rep Power
    0
    Well done mate, thanks.
    Reply With Quote  
     

  3. #3  
    Software Developer

    Tyrant's Avatar
    Join Date
    Jul 2013
    Age
    24
    Posts
    1,562
    Thanks given
    678
    Thanks received
    423
    Rep Power
    1060
    No... why would you run this on a separated thread, and defiantly not like that.
    Reply With Quote  
     

  4. Thankful user:


  5. #4  
    Registered Member Rex_'s Avatar
    Join Date
    Jul 2015
    Posts
    43
    Thanks given
    3
    Thanks received
    7
    Rep Power
    0
    Quote Originally Posted by Tyrant View Post
    No... why would you run this on a separated thread, and defiantly not like that.
    Eh it works, and doesn't cause lag, and does the job. Haven't had a single problem with it even with 30+ active.

    Also if you're gonna criticize at least spell definitely right, as well as separate. Looking illiterate during insult is the ultimate irony.
    https://www.rune-server.ee/static/signaturepic/sigpic295363_1.gif
    Reply With Quote  
     

  6. #5  
    Banned

    Join Date
    Oct 2012
    Posts
    4,710
    Thanks given
    1,679
    Thanks received
    1,105
    Rep Power
    0
    Or just save the players when the server disconnects, no task needed for this.
    Reply With Quote  
     

  7. #6  
    Registered Member Rex_'s Avatar
    Join Date
    Jul 2015
    Posts
    43
    Thanks given
    3
    Thanks received
    7
    Rep Power
    0
    Quote Originally Posted by _Patrick_ View Post
    Or just save the players when the server disconnects, no task needed for this.
    Mate if your local hosting a server the server doesn't properly shutdown if your internet goes out, or you close the batch. If you are using an IDE or Batch file and close your server, the server doesn't properly shut down. Most servers have player saving on shutdown, don't know why a server wouldn't have one. Adding a 2 minute auto saver prevents roll-back from what I just listed. Like are you serious with that comment right now. Literally I can handle Tyrants ego filled comment, but this was just ignorant.
    https://www.rune-server.ee/static/signaturepic/sigpic295363_1.gif
    Reply With Quote  
     

  8. #7  
    Registered Member

    Join Date
    Nov 2014
    Posts
    253
    Thanks given
    39
    Thanks received
    146
    Rep Power
    248
    Quote Originally Posted by Rex_ View Post
    Mate if your local hosting a server the server doesn't properly shutdown if your internet goes out, or you close the batch. If you are using an IDE or Batch file and close your server, the server doesn't properly shut down. Most servers have player saving on shutdown, don't know why a server wouldn't have one. Adding a 2 minute auto saver prevents roll-back from what I just listed. Like are you serious with that comment right now. Literally I can handle Tyrants ego filled comment, but this was just ignorant.
    Then save players on important actions? Why every 2 minutes? I.E. picking up expensive drop, dropping an item, trading, dueling, dying.
    Reply With Quote  
     

  9. #8  
    Software Developer

    Tyrant's Avatar
    Join Date
    Jul 2013
    Age
    24
    Posts
    1,562
    Thanks given
    678
    Thanks received
    423
    Rep Power
    1060
    Quote Originally Posted by Rex_ View Post
    Eh it works, and doesn't cause lag, and does the job. Haven't had a single problem with it even with 30+ active.

    Also if you're gonna criticize at least spell definitely right, as well as separate. Looking illiterate during insult is the ultimate irony.
    Please refrain from posting any kind of clueless snippet posts until you know what you're talking about.
    If you don't know about thread safety issues and how to handle them then do not use them, and defiantly don't tell others to use something that is wrongly coded.
    Reply With Quote  
     

  10. Thankful users:


  11. #9  
    Software Developer

    Tyrant's Avatar
    Join Date
    Jul 2013
    Age
    24
    Posts
    1,562
    Thanks given
    678
    Thanks received
    423
    Rep Power
    1060
    Quote Originally Posted by Ultimate_ View Post
    defiantly
    definitely you negboi lol
    Reply With Quote  
     

  12. Thankful user:


  13. #10  
    Registered Member
    Join Date
    Feb 2018
    Posts
    17
    Thanks given
    1
    Thanks received
    0
    Rep Power
    0
    Will use it thanks for this!
    Reply With Quote  
     

Page 1 of 2 12 LastLast

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. Adding save to Xp Counter
    By Mr House in forum Snippets
    Replies: 11
    Last Post: 05-10-2015, 07:44 PM
  2. Replies: 49
    Last Post: 02-28-2013, 12:31 PM
  3. How to prevent rollbacks?
    By Sheep in forum Help
    Replies: 5
    Last Post: 01-13-2013, 03:06 PM
  4. Replies: 2
    Last Post: 07-24-2011, 11:16 PM
  5. Replies: 10
    Last Post: 10-05-2008, 12:51 AM
Tags for this Thread

View Tag Cloud

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •