Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Waypoints #968

Open
cKnei opened this issue Aug 29, 2024 · 7 comments
Open

Waypoints #968

cKnei opened this issue Aug 29, 2024 · 7 comments
Labels
bug Something isn't working good first issue Welcome new contributors :)

Comments

@cKnei
Copy link

cKnei commented Aug 29, 2024

What happened?

Okay this was kind of on me, but at the same time I thought this might be something to address

When loading Waypoints, if it errors, the next time the game is loaded, the entire file is cleared of all waypoints due to overwriting it with the empty Waypoint List that is saved in memory

Screenshots

No response

Log output

No response

Minecraft Version

1.21.0/1.21.1

Skyblocker Version

skyblocker-1.20.6+1.21.2

Additional context

No response

@cKnei cKnei added the bug Something isn't working label Aug 29, 2024
@kevinthegreat1
Copy link
Collaborator

Simple fix by applying the following diff

    public static void loadWaypoints() {
-        waypoints.clear();
        try (BufferedReader reader = Files.newBufferedReader(waypointsFile)) {
            List<WaypointCategory> waypoints = CODEC.parse(JsonOps.INSTANCE, SkyblockerMod.GSON.fromJson(reader, JsonArray.class)).resultOrPartial(LOGGER::error).orElseThrow();
+            Waypoints.waypoints.clear();
            waypoints.forEach(waypointCategory -> Waypoints.waypoints.put(waypointCategory.island(), waypointCategory));
        } catch (Exception e) {
            LOGGER.error("[Skyblocker Waypoints] Encountered exception while loading waypoints", e);
        }
    }

to

public static void loadWaypoints() {
waypoints.clear();
try (BufferedReader reader = Files.newBufferedReader(waypointsFile)) {
List<WaypointCategory> waypoints = CODEC.parse(JsonOps.INSTANCE, SkyblockerMod.GSON.fromJson(reader, JsonArray.class)).resultOrPartial(LOGGER::error).orElseThrow();
waypoints.forEach(waypointCategory -> Waypoints.waypoints.put(waypointCategory.island(), waypointCategory));
} catch (Exception e) {
LOGGER.error("[Skyblocker Waypoints] Encountered exception while loading waypoints", e);
}
}

@kevinthegreat1
Copy link
Collaborator

I completely misunderstood your problem. Please ignore the above fix. The best solution for this is to probably backup the old waypoints file when saving a new one.

@cKnei
Copy link
Author

cKnei commented Oct 16, 2024

I completely misunderstood your problem. Please ignore the above fix. The best solution for this is to probably backup the old waypoints file when saving a new one.

It was also on me, I was not exactly paying attention when applying the diff, oops.
But I would like to ask, would it make sense to not save to a file if there are no waypoints at all?

eg.

public static void saveWaypoints(MinecraftClient client) {
+    if (waypoints.isEmpty()) return;
    try (BufferedWriter writer = Files.newBufferedWriter(waypointsFile)) {
        JsonElement waypointsJson = CODEC.encodeStart(JsonOps.INSTANCE, List.copyOf(waypoints.values())).resultOrPartial(LOGGER::error).orElseThrow();
        SkyblockerMod.GSON.toJson(waypointsJson, writer);
        LOGGER.info("[Skyblocker Waypoints] Saved waypoints");
    } catch (Exception e) {
        LOGGER.error("[Skyblocker Waypoints] Encountered exception while saving waypoints", e);
    }
}

Sorry if this sounds ridiculous I don't often work in public groups

@kevinthegreat1
Copy link
Collaborator

It was also on me, I was not exactly paying attention when applying the diff, oops. But I would like to ask, would it make sense to not save to a file if there are no waypoints at all?

Then you can't delete all the waypoints.

@cKnei
Copy link
Author

cKnei commented Oct 16, 2024

It was also on me, I was not exactly paying attention when applying the diff, oops. But I would like to ask, would it make sense to not save to a file if there are no waypoints at all?

Then you can't delete all the waypoints.

Well based on what I understand of the Waypoint class, it would only delete it from the the MultiMap, which should not effect the actual waypoint file in any way.

I probably am just be overthinking this and, yeah honestly keeping a copy is probably the best idea.

@kevinthegreat1
Copy link
Collaborator

Well based on what I understand of the Waypoint class, it would only delete it from the the MultiMap, which should not effect the actual waypoint file in any way.

If someone delets all the waypoints, under your proposal, then the file won't get saved. On the next launch, the old waypoints will be loaded again, even though the user has deleted all of them.

@cKnei
Copy link
Author

cKnei commented Oct 17, 2024

If someone delets all the waypoints, under your proposal, then the file won't get saved. On the next launch, the old waypoints will be loaded again, even though the user has deleted all of them.

You're absolutely right. Sorry didn't see that far ahead, but based off this it is all the solutions I had in mind.

In the end I will just stick to keeping a copy of my stuff, if that is all, feel free to close this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Welcome new contributors :)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants