@@ -147,66 +147,6 @@ public void saveState(int savestateIndex) throws SavestateException, IOException
147147 state = SavestateState .NONE ;
148148 }
149149
150- /**
151- * Searches through the savestate folder to look for the next possible savestate
152- * foldername <br>
153- * Savestate equivalent to
154- * {@link SavestateHandler#getLatestSavestateLocation(String)}
155- *
156- * @param worldname The worldname of the current world
157- * @return targetsavefolder The file where the savestate should be copied to
158- * @throws SavestateException if the found savestates count is greater or equal
159- * than 300
160- */
161- @ SuppressWarnings ("unused" )
162- @ Deprecated
163- private File getNextSaveFolderLocation (String worldname ) throws SavestateException {
164- int i = 1 ;
165- int limit = 300 ;
166- File targetsavefolder = null ;
167- while (i <= limit ) {
168- if (i >= limit ) {
169- throw new SavestateException ("Savestatecount is greater or equal than " + limit );
170- }
171- targetsavefolder = new File (savestateDirectory , worldname + "-Savestate" + Integer .toString (i ) + File .separator );
172-
173- if (!targetsavefolder .exists ()) {
174- break ;
175- }
176- i ++;
177- }
178- return targetsavefolder ;
179- }
180-
181- /**
182- * Get's the correct string of the savestate, used in
183- * {@linkplain InputSavestatesHandler#savestate(String)}
184- *
185- * @param worldname the name of the world currently on the server
186- * @return The correct name of the next savestate
187- */
188- @ SuppressWarnings ("unused" )
189- @ Deprecated
190- private String nameWhenSaving (String worldname ) {
191- int i = 1 ;
192- int limit = 300 ;
193- File targetsavefolder = null ;
194- String name = "" ;
195- while (i <= limit ) {
196- if (i >= limit ) {
197- break ;
198- }
199- name = worldname + "-Savestate" + Integer .toString (i );
200- targetsavefolder = new File (savestateDirectory , name + File .separator );
201-
202- if (!targetsavefolder .exists ()) {
203- break ;
204- }
205- i ++;
206- }
207- return name ;
208- }
209-
210150 /**
211151 * Loads the latest savestate it can find in
212152 * .minecraft/saves/savestates/worldname-Savestate
@@ -236,12 +176,9 @@ public void loadState(int savestateIndex) throws LoadstateException, IOException
236176 // Update the server instance
237177 server = TASmod .getServerInstance ();
238178
239- if (savestateIndex < 0 ) {
240- setCurrentIndex ( currentIndex );
179+ if (! get ( savestateIndex ). exists () ) {
180+ throw new LoadstateException ( "The savestate to load doesn't exist" );
241181 } else {
242- if (!get (savestateIndex ).exists ()) {
243- throw new LoadstateException ("The savestate to load doesn't exist" );
244- }
245182 setCurrentIndex (savestateIndex );
246183 }
247184
@@ -303,72 +240,6 @@ public void loadState(int savestateIndex) throws LoadstateException, IOException
303240 state = SavestateState .WASLOADING ;
304241 }
305242
306- /**
307- * Searches through the savestate folder to look for the latest savestate<br>
308- * Loadstate equivalent to
309- * {@link SavestateHandler#getNextSaveFolderLocation(String)}
310- *
311- * @param worldname
312- * @return targetsavefolder
313- * @throws LoadstateException if there is no savestate or more than 300
314- * savestates
315- */
316- @ SuppressWarnings ("unused" )
317- @ Deprecated
318- private File getLatestSavestateLocation (String worldname ) throws LoadstateException {
319- int i = 1 ;
320- int limit = 300 ;
321-
322- File targetsavefolder = null ;
323- while (i <= 300 ) {
324- targetsavefolder = new File (savestateDirectory , worldname + "-Savestate" + Integer .toString (i ));
325- if (!targetsavefolder .exists ()) {
326- if (i - 1 == 0 ) {
327- throw new LoadstateException ("Couldn't find any savestates" );
328- }
329- if (i > 300 ) {
330- throw new LoadstateException ("Savestatecount is greater or equal than " + limit );
331- }
332- targetsavefolder = new File (savestateDirectory , worldname + "-Savestate" + Integer .toString (i - 1 ));
333- break ;
334- }
335- i ++;
336- }
337- return targetsavefolder ;
338- }
339-
340- /**
341- * Get's the correct string of the loadstate, used in
342- * {@linkplain InputSavestatesHandler#loadstate(String)}
343- *
344- * @param worldname the name of the world currently on the server
345- * @return The correct name of the next loadstate
346- */
347- @ SuppressWarnings ("unused" )
348- @ Deprecated
349- private String nameWhenLoading (String worldname ) throws LoadstateException {
350- int i = 1 ;
351- int limit = 300 ;
352- String name = "" ;
353- File targetsavefolder = null ;
354- while (i <= 300 ) {
355- targetsavefolder = new File (savestateDirectory , worldname + "-Savestate" + Integer .toString (i ));
356- if (!targetsavefolder .exists ()) {
357- if (i - 1 == 0 ) {
358- throw new LoadstateException ("Couldn't find any savestates" );
359- }
360- if (i > 300 ) {
361- throw new LoadstateException ("Savestatecount is greater or equal than " + limit );
362- }
363-
364- name = worldname + "-Savestate" + Integer .toString (i - 1 );
365- break ;
366- }
367- i ++;
368- }
369- return name ;
370- }
371-
372243 /**
373244 * Creates the savestate directory in case the user deletes it between
374245 * savestates
@@ -386,7 +257,7 @@ private void createSavestateDirectory() {
386257
387258 private final List <Integer > indexList = new ArrayList <>();
388259
389- private int nextFreeIndex = 0 ;
260+ private int latestIndex = 0 ;
390261
391262 private int currentIndex ;
392263
@@ -421,7 +292,8 @@ public boolean accept(File pathname) {
421292 if (indexList .isEmpty ()) {
422293 indexList .add (0 );
423294 }
424- nextFreeIndex = indexList .get (indexList .size () - 1 );
295+ latestIndex = indexList .get (indexList .size () - 1 );
296+ System .out .println ("LatestIndex: " + latestIndex );
425297 }
426298
427299 public void deleteIndex (int index ) throws SavestateDeleteException {
@@ -435,10 +307,13 @@ public void deleteIndex(int index) throws SavestateDeleteException {
435307 } catch (IOException e ) {
436308 e .printStackTrace ();
437309 }
310+ } else {
311+ server .getPlayerList ().sendMessage (new TextComponentString (TextFormatting .YELLOW + "Savestate " + index + " doesn't exist so it can't be deleted" ));
312+ return ;
438313 }
439314 refresh ();
440- if (!indexList .contains (currentIndex )) {
441- setCurrentIndex (nextFreeIndex );
315+ if (!indexList .contains (currentIndex )) {
316+ setCurrentIndex (latestIndex );
442317 }
443318 // Send a notification that the savestate has been deleted
444319 server .getPlayerList ().sendMessage (new TextComponentString (TextFormatting .GREEN + "Savestate " + index + " deleted" ));
@@ -501,7 +376,7 @@ public void loadCurrentIndexFromFile() {
501376
502377 private void setCurrentIndex (int index ) {
503378 if (index < 0 ) {
504- currentIndex = nextFreeIndex - 1 ;
379+ currentIndex = latestIndex - 1 ;
505380 } else {
506381 currentIndex = index ;
507382 }
0 commit comments