diff --git a/src/wrapper/mojang-api.ts b/src/wrapper/mojang-api.ts index c02af26..845af7c 100644 --- a/src/wrapper/mojang-api.ts +++ b/src/wrapper/mojang-api.ts @@ -3,24 +3,24 @@ import axios from "axios"; import TwoWayMap from "../utils/two-way-map.js"; class MojangAPI { - private cached: TwoWayMap = new TwoWayMap(); // uuid, id + private cache: TwoWayMap = new TwoWayMap(); // uuid, id async getIdFromUUID(minecraft_uuid: string): Promise { - let id = this.cached.get_by_first(minecraft_uuid); + let id = this.cache.get_by_first(minecraft_uuid); if (id) return id; const request = await axios.get( `https://api.mojang.com/user/profile/${minecraft_uuid}` ); id = request.data.name; - if (!id) throw new Error("Failed to get minecraft id from api"); - this.cached.set_by_first(minecraft_uuid, id); + this.cache.remove_by_second(id); + this.cache.set_by_first(minecraft_uuid, id); return id; } async getUUIDFromId(minecraft_id): Promise { - let uuid = this.cached.get_by_second(minecraft_id); + let uuid = this.cache.get_by_second(minecraft_id); if (uuid) return uuid; const response = await axios.get( @@ -29,8 +29,8 @@ class MojangAPI { uuid = response.data.id; if (!uuid) throw new Error("Failed to get minecraft id from api"); - this.cached.remove_by_first(uuid); - this.cached.set_by_second(uuid, minecraft_id); + this.cache.remove_by_first(uuid); + this.cache.set_by_second(uuid, minecraft_id); return uuid; } }