From d1692a63acb6db5ba245288cb83139dc776340ee Mon Sep 17 00:00:00 2001 From: Scribble Date: Fri, 1 Oct 2021 23:30:02 +0200 Subject: [PATCH] Started working on #112 Too tired to continue... -Moved FileThread.class to util package --- build.gradle | 1 + .../savestates/server/SavestateHandler.java | 20 ++++++++++++++++++- .../server/SavestatePacketHandler.java | 2 +- .../lp/tasmod/util/ContainerSerialiser.java | 1 - .../savetas => util}/FileThread.java | 2 +- 5 files changed, 22 insertions(+), 4 deletions(-) rename src/main/java/de/scribble/lp/tasmod/{commands/savetas => util}/FileThread.java (95%) diff --git a/build.gradle b/build.gradle index c180563e..5ce7d23b 100644 --- a/build.gradle +++ b/build.gradle @@ -68,6 +68,7 @@ dependencies { compile 'org.msgpack:msgpack-core:0.8.16' compile 'org.msgpack:jackson-dataformat-msgpack:0.8.16' compile files('libs/KillTheRNG-1.12.2-1.0-deobf.jar') + //compile files('libs/BigArrayList-1.3.jar') compile 'com.dselent:bigarraylist:1.0' // real examples //compile 'com.mod-buildcraft:buildcraft:6.0.8:dev' // adds buildcraft to the dev env diff --git a/src/main/java/de/scribble/lp/tasmod/savestates/server/SavestateHandler.java b/src/main/java/de/scribble/lp/tasmod/savestates/server/SavestateHandler.java index 45630b34..306392fe 100644 --- a/src/main/java/de/scribble/lp/tasmod/savestates/server/SavestateHandler.java +++ b/src/main/java/de/scribble/lp/tasmod/savestates/server/SavestateHandler.java @@ -1,6 +1,7 @@ package de.scribble.lp.tasmod.savestates.server; import java.io.File; +import java.io.FileFilter; import java.io.IOException; import org.apache.commons.io.FileUtils; @@ -46,10 +47,11 @@ public class SavestateHandler { * Called in {@link SavestatePacketHandler}
*
* Side: Server + * @param savestateIndex The index where the mod will save the savestate -1 if it should load the latest * @throws SavestateException * @throws IOException */ - public static void saveState() throws SavestateException, IOException { + public static void saveState(int savestateIndex) throws SavestateException, IOException { if(state==SavestateState.SAVING) { throw new SavestateException("A savestating operation is already being carried out"); } @@ -107,6 +109,20 @@ public static void saveState() throws SavestateException, IOException { state=SavestateState.NONE; } + private static String nextSaveName(String worldname, int index) { + File[] listofFiles=savestateDirectory.listFiles(new FileFilter() { + + @Override + public boolean accept(File pathname) { + return pathname.getName().startsWith(worldname); + } + + }); + if(index<0) { + } + return ""; + } + /** * Searches through the savestate folder to look for the next possible savestate foldername
* Savestate equivalent to {@link SavestateHandler#getLatestSavestateLocation(String)} @@ -114,6 +130,7 @@ public static void saveState() throws SavestateException, IOException { * @return targetsavefolder The file where the savestate should be copied to * @throws SavestateException if the found savestates count is greater or equal than 300 */ + @Deprecated private static File getNextSaveFolderLocation(String worldname) throws SavestateException { int i = 1; int limit=300; @@ -138,6 +155,7 @@ private static File getNextSaveFolderLocation(String worldname) throws Savestate * @param worldname the name of the world currently on the server * @return The correct name of the next savestate */ + @Deprecated private static String nameWhenSaving(String worldname) { int i = 1; int limit=300; diff --git a/src/main/java/de/scribble/lp/tasmod/savestates/server/SavestatePacketHandler.java b/src/main/java/de/scribble/lp/tasmod/savestates/server/SavestatePacketHandler.java index 65e278dd..f63bcd87 100644 --- a/src/main/java/de/scribble/lp/tasmod/savestates/server/SavestatePacketHandler.java +++ b/src/main/java/de/scribble/lp/tasmod/savestates/server/SavestatePacketHandler.java @@ -30,7 +30,7 @@ public IMessage onMessage(SavestatePacket message, MessageContext ctx) { return; } try { - SavestateHandler.saveState(); + SavestateHandler.saveState(-1); } catch (SavestateException e) { player.sendMessage(new TextComponentString(TextFormatting.RED+"Failed to create a savestate: "+ e.getMessage())); diff --git a/src/main/java/de/scribble/lp/tasmod/util/ContainerSerialiser.java b/src/main/java/de/scribble/lp/tasmod/util/ContainerSerialiser.java index ee7b7d1f..bedd0129 100644 --- a/src/main/java/de/scribble/lp/tasmod/util/ContainerSerialiser.java +++ b/src/main/java/de/scribble/lp/tasmod/util/ContainerSerialiser.java @@ -11,7 +11,6 @@ import com.dselent.bigarraylist.BigArrayList; -import de.scribble.lp.tasmod.commands.savetas.FileThread; import de.scribble.lp.tasmod.inputcontainer.InputContainer; import de.scribble.lp.tasmod.inputcontainer.TickInputContainer; import de.scribble.lp.tasmod.monitoring.DesyncMonitoring; diff --git a/src/main/java/de/scribble/lp/tasmod/commands/savetas/FileThread.java b/src/main/java/de/scribble/lp/tasmod/util/FileThread.java similarity index 95% rename from src/main/java/de/scribble/lp/tasmod/commands/savetas/FileThread.java rename to src/main/java/de/scribble/lp/tasmod/util/FileThread.java index df3c0eba..1f3e80a7 100644 --- a/src/main/java/de/scribble/lp/tasmod/commands/savetas/FileThread.java +++ b/src/main/java/de/scribble/lp/tasmod/util/FileThread.java @@ -1,4 +1,4 @@ -package de.scribble.lp.tasmod.commands.savetas; +package de.scribble.lp.tasmod.util; import java.io.File; import java.io.FileNotFoundException;