Skip to content

Commit 2319c88

Browse files
committed
Fixed Saving/Loading bug
1 parent 13946fc commit 2319c88

File tree

1 file changed

+24
-18
lines changed

1 file changed

+24
-18
lines changed

src/client/java/com/veinbuddy/VeinBuddyClient.java

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ private void saveSelections(MinecraftClient client) {
221221
FileWriter fileWriter = new FileWriter(saveFile, false);
222222
fileWriter.write("Version 2\n");
223223
for (Vec3i selection : selections) {
224-
Vec3i ranges = selectionRanges.get(selection);
224+
Vec3i ranges = selectionRanges.get(selection);
225225
fileWriter.write(selection.getX() + " " + selection.getY() + " " + selection.getZ() + " " + ranges.getX() + " " + ranges.getY() + " " + ranges.getZ() + "\n");
226226
}
227227
fileWriter.close();
@@ -234,42 +234,48 @@ private void saveSelections(MinecraftClient client) {
234234
private void onStart(MinecraftClient client) {
235235
File configFile = getConfigFile(client);
236236
File saveFile = getSaveFile(client);
237-
if (null != configFile) {
237+
if (configFile.exists()) {
238238
try {
239239
Scanner sc = new Scanner(configFile);
240+
if (null != sc.findInLine("\\d+ \\d+ \\d+")) {
240241
int x = sc.nextInt();
241242
int y = sc.nextInt();
242243
int z = sc.nextInt();
243-
digRange = new Vec3i(x, y, z);
244+
digRange = new Vec3i(x, y, z);
245+
}
244246
} catch (IOException e) {
245247
System.out.println("Mad!");
246248
}
247249
}
248-
if (null == saveFile)
250+
if (null == saveFile || !saveFile.exists())
249251
return;
250252
try {
251253
Scanner sc = new Scanner(saveFile);
252-
String found = sc.next("Version \\d*");
253-
if (null == found) { // Version 1
254-
while (sc.hasNext()){
254+
if (!sc.hasNext("Version")) { //Version 1
255+
while (null != sc.findInLine("\\d+ \\d+ \\d+")) {
255256
int x = sc.nextInt();
256257
int y = sc.nextInt();
257258
int z = sc.nextInt();
258259
addSelection(new Vec3i(x, y, z), new Vec3i(defaultDigRange, defaultDigRange, defaultDigRange), true);
259260
sc.nextLine();
260261
}
261-
} else if ("Version 2" == found) { // Version 2
262-
sc.nextLine();
263-
while (sc.hasNext()){
264-
int x = sc.nextInt();
265-
int y = sc.nextInt();
266-
int z = sc.nextInt();
267-
int xRange = sc.nextInt();
268-
int yRange = sc.nextInt();
269-
int zRange = sc.nextInt();
270-
addSelection(new Vec3i(x, y, z), new Vec3i(xRange, yRange, zRange), true);
262+
}
263+
else {
264+
sc.next();
265+
String found = sc.next("\\d+");
266+
if (found.equals("2")) { // Version 2
271267
sc.nextLine();
272-
}
268+
while (sc.hasNext()) {
269+
int x = sc.nextInt();
270+
int y = sc.nextInt();
271+
int z = sc.nextInt();
272+
int xRange = sc.nextInt();
273+
int yRange = sc.nextInt();
274+
int zRange = sc.nextInt();
275+
addSelection(new Vec3i(x, y, z), new Vec3i(xRange, yRange, zRange), true);
276+
sc.nextLine();
277+
}
278+
}
273279
}
274280
} catch (IOException e) {
275281
System.out.println("Bad!");

0 commit comments

Comments
 (0)