account util: MinecraftNotPurchasedError

This commit is contained in:
Moritz Zwerger 2023-10-29 12:16:16 +01:00
parent 3adc8d919e
commit 978c2f06ad
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
2 changed files with 21 additions and 4 deletions

View File

@ -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) {

View File

@ -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 <https://www.gnu.org/licenses/>.
*
* 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!")