From 978c2f06adcb505e8b2f3920b0b54f3c7cbd6c44 Mon Sep 17 00:00:00 2001 From: Moritz Zwerger Date: Sun, 29 Oct 2023 12:16:16 +0100 Subject: [PATCH] account util: MinecraftNotPurchasedError --- .../bixilon/minosoft/util/account/AccountUtil.kt | 9 +++++---- .../minecraft/MinecraftNotPurchasedError.kt | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 src/main/java/de/bixilon/minosoft/util/account/microsoft/minecraft/MinecraftNotPurchasedError.kt diff --git a/src/main/java/de/bixilon/minosoft/util/account/AccountUtil.kt b/src/main/java/de/bixilon/minosoft/util/account/AccountUtil.kt index 02b0b6df2..73efc3ac4 100644 --- a/src/main/java/de/bixilon/minosoft/util/account/AccountUtil.kt +++ b/src/main/java/de/bixilon/minosoft/util/account/AccountUtil.kt @@ -15,6 +15,7 @@ package de.bixilon.minosoft.util.account import de.bixilon.kutil.uuid.UUIDUtil.trim import de.bixilon.minosoft.util.account.microsoft.minecraft.MinecraftAPIException +import de.bixilon.minosoft.util.account.microsoft.minecraft.MinecraftNotPurchasedError import de.bixilon.minosoft.util.account.microsoft.minecraft.MinecraftProfile import de.bixilon.minosoft.util.account.minecraft.MinecraftPrivateKey import de.bixilon.minosoft.util.account.minecraft.MinecraftTokens @@ -36,11 +37,11 @@ object AccountUtil { "Authorization" to "Bearer ${token.accessToken}", )) - if (response.statusCode != 200) { - throw MinecraftAPIException(response) // 404 means that the account has not purchased minecraft + when (response.statusCode) { + 404 -> throw MinecraftNotPurchasedError() + 200 -> return Jackson.MAPPER.convertValue(response.body, MinecraftProfile::class.java) + else -> throw MinecraftAPIException(response) } - - return Jackson.MAPPER.convertValue(response.body, MinecraftProfile::class.java) } fun joinMojangServer(accessToken: String, profile: UUID, serverId: String) { diff --git a/src/main/java/de/bixilon/minosoft/util/account/microsoft/minecraft/MinecraftNotPurchasedError.kt b/src/main/java/de/bixilon/minosoft/util/account/microsoft/minecraft/MinecraftNotPurchasedError.kt new file mode 100644 index 000000000..da2f5fe5a --- /dev/null +++ b/src/main/java/de/bixilon/minosoft/util/account/microsoft/minecraft/MinecraftNotPurchasedError.kt @@ -0,0 +1,16 @@ +/* + * Minosoft + * Copyright (C) 2020-2023 Moritz Zwerger + * + * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with this program. If not, see . + * + * This software is not affiliated with Mojang AB, the original developer of Minecraft. + */ + +package de.bixilon.minosoft.util.account.microsoft.minecraft + +class MinecraftNotPurchasedError : Exception("This microsoft account must have minecraft java edition purchased!")