Files
Backend/src/main/java/cc/fascinated/service/MojangAPIService.java

41 lines
1.2 KiB
Java
Raw Normal View History

2024-04-08 06:28:43 +01:00
package cc.fascinated.service;
2024-04-08 04:56:59 +01:00
2024-04-08 06:28:43 +01:00
import cc.fascinated.model.mojang.MojangProfile;
import cc.fascinated.model.mojang.MojangUsernameToUuid;
2024-04-08 04:56:59 +01:00
import cc.fascinated.util.WebRequest;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
@Service @Log4j2
public class MojangAPIService {
@Value("${mojang.session-server}")
private String mojangSessionServerUrl;
@Value("${mojang.api}")
private String mojangApiUrl;
/**
2024-04-08 05:22:54 +01:00
* Gets the Session Server profile of the
* player with the given UUID.
2024-04-08 04:56:59 +01:00
*
* @param id the uuid or name of the player
* @return the profile
*/
2024-04-08 05:22:54 +01:00
public MojangProfile getProfile(String id) {
return WebRequest.get(mojangSessionServerUrl + "/session/minecraft/profile/" + id, MojangProfile.class);
2024-04-08 04:56:59 +01:00
}
/**
2024-04-08 05:22:54 +01:00
* Gets the UUID of the player using
* the name of the player.
2024-04-08 04:56:59 +01:00
*
* @param id the name of the player
* @return the profile
*/
2024-04-08 05:22:54 +01:00
public MojangUsernameToUuid getUuidFromUsername(String id) {
return WebRequest.get(mojangApiUrl + "/users/profiles/minecraft/" + id, MojangUsernameToUuid.class);
2024-04-08 04:56:59 +01:00
}
}