diff options
author | Kevinthegreat <92656833+kevinthegreat1@users.noreply.github.com> | 2024-02-04 16:10:04 -0500 |
---|---|---|
committer | Kevinthegreat <92656833+kevinthegreat1@users.noreply.github.com> | 2024-05-24 19:51:43 -0400 |
commit | d84b0ce5169c1aea99c6e4842665c6e3598e97d8 (patch) | |
tree | a87bfa6ad2fe06435ded3fa5c7e5cf3af503e605 /src/main/java/de/hysky/skyblocker/skyblock/waypoint/Waypoints.java | |
parent | bf4034da76adcc7760628d49e518404273efceee (diff) | |
download | Skyblocker-d84b0ce5169c1aea99c6e4842665c6e3598e97d8.tar.gz Skyblocker-d84b0ce5169c1aea99c6e4842665c6e3598e97d8.tar.bz2 Skyblocker-d84b0ce5169c1aea99c6e4842665c6e3598e97d8.zip |
Add waypoint adding
Diffstat (limited to 'src/main/java/de/hysky/skyblocker/skyblock/waypoint/Waypoints.java')
-rw-r--r-- | src/main/java/de/hysky/skyblocker/skyblock/waypoint/Waypoints.java | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/src/main/java/de/hysky/skyblocker/skyblock/waypoint/Waypoints.java b/src/main/java/de/hysky/skyblocker/skyblock/waypoint/Waypoints.java index 1a9d6836..89c3f051 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/waypoint/Waypoints.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/waypoint/Waypoints.java @@ -1,5 +1,7 @@ package de.hysky.skyblocker.skyblock.waypoint; +import com.google.common.collect.Multimap; +import com.google.common.collect.MultimapBuilder; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; @@ -20,13 +22,15 @@ import java.io.BufferedReader; import java.io.BufferedWriter; import java.nio.file.Files; import java.nio.file.Path; -import java.util.*; +import java.util.Base64; +import java.util.Collection; +import java.util.List; public class Waypoints { private static final Logger LOGGER = LoggerFactory.getLogger(Waypoints.class); private static final Codec<List<WaypointCategory>> CODEC = WaypointCategory.CODEC.listOf(); private static final Path waypointsFile = FabricLoader.getInstance().getConfigDir().resolve(SkyblockerMod.NAMESPACE).resolve("waypoints.json"); - private static final Map<String, WaypointCategory> waypoints = new HashMap<>(); + static final Multimap<String, WaypointCategory> waypoints = MultimapBuilder.hashKeys().arrayListValues().build(); public static void init() { loadWaypoints(); @@ -40,7 +44,7 @@ public class Waypoints { 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("Encountered exception while loading waypoints", e); + LOGGER.error("[Skyblocker Waypoints] Encountered exception while loading waypoints", e); } } @@ -58,17 +62,20 @@ public class Waypoints { public static void saveWaypoints(MinecraftClient client) { try (BufferedWriter writer = Files.newBufferedWriter(waypointsFile)) { - JsonElement waypointsJson = CODEC.encodeStart(JsonOps.INSTANCE, new ArrayList<>(waypoints.values())).resultOrPartial(LOGGER::error).orElseThrow(); + 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("Encountered exception while saving waypoints", e); + LOGGER.error("[Skyblocker Waypoints] Encountered exception while saving waypoints", e); } } public static void render(WorldRenderContext context) { - WaypointCategory category = waypoints.get(Utils.getLocationRaw()); - if (category != null) { - category.render(context); + Collection<WaypointCategory> categories = waypoints.get(Utils.getLocationRaw()); + for (WaypointCategory category : categories) { + if (category != null) { + category.render(context); + } } } } |