Skip to content

Commit

Permalink
Change: Remove deprecated Minecraft, Mojang and Yggdrasil classes
Browse files Browse the repository at this point in the history
  • Loading branch information
spnda committed Jan 24, 2022
1 parent 1396fab commit 96431c5
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 189 deletions.
3 changes: 0 additions & 3 deletions lib/dart_minecraft.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ export 'src/exceptions/auth_exception.dart';
export 'src/exceptions/ping_exception.dart';
export 'src/exceptions/too_many_requests_exception.dart';
export 'src/microsoft_api.dart';
export 'src/minecraft.dart';
export 'src/minecraft/blocked_server.dart';
export 'src/minecraft/minecraft_news.dart';
export 'src/minecraft/minecraft_patch.dart';
export 'src/minecraft/minecraft_statistics.dart';
export 'src/minecraft/version_manifest.dart';
export 'src/minecraft_api.dart';
export 'src/mojang.dart';
export 'src/mojang/mojang_status.dart';
export 'src/mojang/name.dart';
export 'src/mojang/profile.dart';
Expand All @@ -23,5 +21,4 @@ export 'src/packet/packets/server_packet.dart';
export 'src/ping/server_ping_stub.dart'
if (dart.library.io) 'src/ping/server_ping_io.dart';
export 'src/utilities/pair.dart';
export 'src/yggdrasil.dart';
export 'src/yggdrasil_api.dart';
33 changes: 0 additions & 33 deletions lib/src/minecraft.dart

This file was deleted.

94 changes: 0 additions & 94 deletions lib/src/mojang.dart

This file was deleted.

5 changes: 4 additions & 1 deletion lib/src/mojang/mojang_account.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
/// A JWT access token used for authentication in Minecraft.
typedef AccessToken = String;

/// A MojangAccount with data as returned by /authenticate.
class MojangAccount {
/// The access token used to access APIs and authenticate to Minecraft Servers.
///
/// This token is a replacement for logging in using a username and password each time,
/// so keep good track of it!
String accessToken;
AccessToken accessToken;

/// This account's client token.
String clientToken;
Expand Down
23 changes: 12 additions & 11 deletions lib/src/mojang_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'exceptions/auth_exception.dart';
import 'exceptions/too_many_requests_exception.dart';
import 'minecraft/blocked_server.dart';
import 'minecraft/minecraft_statistics.dart';
import 'mojang/mojang_account.dart';
import 'mojang/mojang_status.dart';
import 'mojang/name.dart';
import 'mojang/profile.dart';
Expand Down Expand Up @@ -126,7 +127,7 @@ Future<Profile> getProfile(String uuid) async {

/// Get's the Minecraft profile for the currently logged
/// in user. This requires a valid access token.
Future<Profile> getCurrentProfile(String accessToken) async {
Future<Profile> getCurrentProfile(AccessToken accessToken) async {
final response = await request(
http.get, _minecraftServicesApi, 'minecraft/profile',
headers: {
Expand All @@ -148,8 +149,8 @@ Future<Profile> getCurrentProfile(String accessToken) async {
}

/// Changes the Mojang account name to [newName].
Future<bool> changeName(
String uuid, String newName, String accessToken, String password) async {
Future<bool> changeName(String uuid, String newName, AccessToken accessToken,
String password) async {
final body = <String, String>{'name': newName, 'password': password};
final headers = <String, String>{
'authorization': 'Bearer $accessToken',
Expand Down Expand Up @@ -183,7 +184,7 @@ Future<bool> changeName(

/// Reserves the [newName] for this Mojang Account.
// TODO: Improved return type including error message. Or just throw an error?
Future<bool> reserveName(String newName, String accessToken) async {
Future<bool> reserveName(String newName, AccessToken accessToken) async {
final headers = {
'authorization': 'Bearer $accessToken',
'Origin': 'https://checkout.minecraft.net',
Expand Down Expand Up @@ -226,7 +227,7 @@ Future<bool> isNameAvailableNoAuth(String name) async {
/// long and not include any invalid characters to be valid.
/// If your access token is invalid, this will silently fail
/// and return false.
Future<bool> isNameAvailable(String name, String accessToken) async {
Future<bool> isNameAvailable(String name, AccessToken accessToken) async {
final response = await request(
http.get, _minecraftServicesApi, 'minecraft/profile/name/$name/available',
headers: {'authorization': 'Bearer $accessToken'});
Expand All @@ -241,7 +242,7 @@ Future<bool> isNameAvailable(String name, String accessToken) async {
}

/// Reset's the player's skin.
Future<void> resetSkin(String uuid, String accessToken) async {
Future<void> resetSkin(String uuid, AccessToken accessToken) async {
final headers = {
'authorization': 'Bearer $accessToken',
};
Expand All @@ -255,7 +256,7 @@ Future<void> resetSkin(String uuid, String accessToken) async {
}

/// Change the skin with the texture of the skin at [skinUrl].
Future<bool> changeSkin(Uri skinUrl, String accessToken,
Future<bool> changeSkin(Uri skinUrl, AccessToken accessToken,
[SkinModel skinModel = SkinModel.classic]) async {
final headers = {
'authorization': 'Bearer $accessToken',
Expand Down Expand Up @@ -311,7 +312,7 @@ Future<List<BlockedServer>> getBlockedServers() async {
/// Checks whether or not the user has to answer the security challenges.
/// This will return true if the current location is not verified and needs
/// to be verified using [getSecurityChallenges] and [answerSecurityChallenges].
Future<bool> areSecurityChallengesNeeded(String accessToken) async {
Future<bool> areSecurityChallengesNeeded(AccessToken accessToken) async {
final headers = {
'authorization': 'Bearer $accessToken',
};
Expand All @@ -324,7 +325,7 @@ Future<bool> areSecurityChallengesNeeded(String accessToken) async {
/// to access the account.
/// Check if this is needed using [areSecurityChallengesNeeded].
Future<List<SecurityChallenge>> getSecurityChallenges(
String accessToken) async {
AccessToken accessToken) async {
final headers = {
'authorization': 'Bearer $accessToken',
};
Expand All @@ -343,7 +344,7 @@ Future<List<SecurityChallenge>> getSecurityChallenges(
/// You can get the security challenges through [getSecurityChallenges].
/// Also check if this is needed using [areSecurityChallengesNeeded].
Future<bool> answerSecurityChallenges(
String accessToken, List<SecurityChallenge> answers) async {
AccessToken accessToken, List<SecurityChallenge> answers) async {
/// Verify we have enough answers passed.
if (answers.length != 3) {
throw ArgumentError.value(
Expand All @@ -369,7 +370,7 @@ Future<bool> answerSecurityChallenges(
/// from a Mojang account to a Microsoft account. This function
/// will simply return 'false' if the access token is invalid
/// or expired.
Future<bool> canMigrate(String accessToken) async {
Future<bool> canMigrate(AccessToken accessToken) async {
final response = await request(
http.get, _minecraftServicesApi, 'rollout/v1/msamigration',
headers: {
Expand Down
45 changes: 0 additions & 45 deletions lib/src/yggdrasil.dart

This file was deleted.

4 changes: 2 additions & 2 deletions lib/src/yggdrasil_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ Future<MojangAccount> refresh(MojangAccount account) async {
///
/// [clientToken] is optional, though if provided should match the client token
/// that was used to obtained given [accessToken].
Future<bool> validate(String accessToken, {String? clientToken}) async {
Future<bool> validate(AccessToken accessToken, {String? clientToken}) async {
final headers = {
'content-type': 'application/json',
};
Expand Down Expand Up @@ -147,7 +147,7 @@ Future<bool> invalidate(MojangAccount mojangAccount) async {
/// Be careful to what values you pass into [newPassword], as the [accessToken] will
/// get invalidated and you will need it to log into your account again.
Future<bool> changePassword(
String currentPassword, String newPassword, String accessToken) async {
String currentPassword, String newPassword, AccessToken accessToken) async {
if (currentPassword.isEmpty) {
throw ArgumentError.value(currentPassword, 'currentPassword',
'The current password cannot be empty.');
Expand Down

0 comments on commit 96431c5

Please sign in to comment.