fix index and /mojang/status routes

This commit is contained in:
Lee 2024-04-13 17:40:03 +01:00
parent 77f787b659
commit 1a0dd8844d
7 changed files with 21 additions and 19 deletions

@ -3,6 +3,7 @@ package cc.fascinated.controller;
import cc.fascinated.config.Config; import cc.fascinated.config.Config;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
@Controller @Controller
@ -15,7 +16,7 @@ public class HomeController {
private final String exampleUuid = "eeab5f8a-18dd-4d58-af78-2b3c4543da48"; private final String exampleUuid = "eeab5f8a-18dd-4d58-af78-2b3c4543da48";
private final String exampleServer = "aetheria.cc"; private final String exampleServer = "aetheria.cc";
@RequestMapping(value = "/") @GetMapping(value = "/")
public String home(Model model) { public String home(Model model) {
model.addAttribute("player_example_url", Config.INSTANCE.getWebPublicUrl() + "/player/" + exampleUuid); model.addAttribute("player_example_url", Config.INSTANCE.getWebPublicUrl() + "/player/" + exampleUuid);
model.addAttribute("java_server_example_url", Config.INSTANCE.getWebPublicUrl() + "/server/java/" + exampleServer); model.addAttribute("java_server_example_url", Config.INSTANCE.getWebPublicUrl() + "/server/java/" + exampleServer);

@ -5,6 +5,7 @@ import cc.fascinated.service.MojangService;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
@ -18,7 +19,7 @@ public class MojangController {
private MojangService mojangService; private MojangService mojangService;
@ResponseBody @ResponseBody
@RequestMapping(value = "/status") @GetMapping(value = "/status")
public CachedEndpointStatus getStatus() { public CachedEndpointStatus getStatus() {
return mojangService.getMojangApiStatus(); return mojangService.getMojangApiStatus();
} }

@ -2,7 +2,7 @@ package cc.fascinated.model.player;
import cc.fascinated.common.Tuple; import cc.fascinated.common.Tuple;
import cc.fascinated.common.UUIDUtils; import cc.fascinated.common.UUIDUtils;
import cc.fascinated.model.mojang.MojangProfile; import cc.fascinated.model.token.MojangProfileToken;
import cc.fascinated.model.skin.Skin; import cc.fascinated.model.skin.Skin;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
@ -43,9 +43,9 @@ public class Player {
/** /**
* The raw properties of the player * The raw properties of the player
*/ */
private MojangProfile.ProfileProperty[] rawProperties; private MojangProfileToken.ProfileProperty[] rawProperties;
public Player(MojangProfile profile) { public Player(MojangProfileToken profile) {
this.uniqueId = UUIDUtils.addDashes(profile.getId()); this.uniqueId = UUIDUtils.addDashes(profile.getId());
this.trimmedUniqueId = UUIDUtils.removeDashes(this.uniqueId); this.trimmedUniqueId = UUIDUtils.removeDashes(this.uniqueId);
this.username = profile.getName(); this.username = profile.getName();

@ -1,4 +1,4 @@
package cc.fascinated.model.mojang; package cc.fascinated.model.token;
import cc.fascinated.Main; import cc.fascinated.Main;
import cc.fascinated.common.Tuple; import cc.fascinated.common.Tuple;
@ -14,7 +14,7 @@ import lombok.NoArgsConstructor;
import java.util.Base64; import java.util.Base64;
@Getter @NoArgsConstructor @AllArgsConstructor @Getter @NoArgsConstructor @AllArgsConstructor
public class MojangProfile { public class MojangProfileToken {
/** /**
* The UUID of the player. * The UUID of the player.

@ -1,11 +1,11 @@
package cc.fascinated.model.mojang; package cc.fascinated.model.token;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Getter; import lombok.Getter;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
@Getter @NoArgsConstructor @Getter @NoArgsConstructor
public class MojangUsernameToUuid { public class MojangUsernameToUuidToken {
/** /**
* The UUID of the player. * The UUID of the player.

@ -6,8 +6,8 @@ import cc.fascinated.common.ExpiringSet;
import cc.fascinated.common.WebRequest; import cc.fascinated.common.WebRequest;
import cc.fascinated.config.Config; import cc.fascinated.config.Config;
import cc.fascinated.model.cache.CachedEndpointStatus; import cc.fascinated.model.cache.CachedEndpointStatus;
import cc.fascinated.model.mojang.MojangProfile; import cc.fascinated.model.token.MojangProfileToken;
import cc.fascinated.model.mojang.MojangUsernameToUuid; import cc.fascinated.model.token.MojangUsernameToUuidToken;
import cc.fascinated.repository.EndpointStatusRepository; import cc.fascinated.repository.EndpointStatusRepository;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
import com.google.common.base.Splitter; import com.google.common.base.Splitter;
@ -244,8 +244,8 @@ public class MojangService {
* @param id the uuid or name of the player * @param id the uuid or name of the player
* @return the profile * @return the profile
*/ */
public MojangProfile getProfile(String id) { public MojangProfileToken getProfile(String id) {
return WebRequest.getAsEntity(SESSION_SERVER_ENDPOINT + "/session/minecraft/profile/" + id, MojangProfile.class); return WebRequest.getAsEntity(SESSION_SERVER_ENDPOINT + "/session/minecraft/profile/" + id, MojangProfileToken.class);
} }
/** /**
@ -255,7 +255,7 @@ public class MojangService {
* @param id the name of the player * @param id the name of the player
* @return the profile * @return the profile
*/ */
public MojangUsernameToUuid getUuidFromUsername(String id) { public MojangUsernameToUuidToken getUuidFromUsername(String id) {
return WebRequest.getAsEntity(API_ENDPOINT + "/users/profiles/minecraft/" + id, MojangUsernameToUuid.class); return WebRequest.getAsEntity(API_ENDPOINT + "/users/profiles/minecraft/" + id, MojangUsernameToUuidToken.class);
} }
} }

@ -12,8 +12,8 @@ import cc.fascinated.exception.impl.ResourceNotFoundException;
import cc.fascinated.model.cache.CachedPlayer; import cc.fascinated.model.cache.CachedPlayer;
import cc.fascinated.model.cache.CachedPlayerName; import cc.fascinated.model.cache.CachedPlayerName;
import cc.fascinated.model.cache.CachedPlayerSkinPart; import cc.fascinated.model.cache.CachedPlayerSkinPart;
import cc.fascinated.model.mojang.MojangProfile; import cc.fascinated.model.token.MojangProfileToken;
import cc.fascinated.model.mojang.MojangUsernameToUuid; import cc.fascinated.model.token.MojangUsernameToUuidToken;
import cc.fascinated.model.player.Cape; import cc.fascinated.model.player.Cape;
import cc.fascinated.model.player.Player; import cc.fascinated.model.player.Player;
import cc.fascinated.model.skin.ISkinPart; import cc.fascinated.model.skin.ISkinPart;
@ -69,7 +69,7 @@ public class PlayerService {
try { try {
log.info("Getting player profile from Mojang: {}", id); log.info("Getting player profile from Mojang: {}", id);
MojangProfile mojangProfile = mojangAPIService.getProfile(uuid.toString()); // Get the player profile from Mojang MojangProfileToken mojangProfile = mojangAPIService.getProfile(uuid.toString()); // Get the player profile from Mojang
log.info("Got player profile from Mojang: {}", id); log.info("Got player profile from Mojang: {}", id);
Tuple<Skin, Cape> skinAndCape = mojangProfile.getSkinAndCape(); Tuple<Skin, Cape> skinAndCape = mojangProfile.getSkinAndCape();
CachedPlayer player = new CachedPlayer( CachedPlayer player = new CachedPlayer(
@ -106,7 +106,7 @@ public class PlayerService {
return cachedPlayerName.get(); return cachedPlayerName.get();
} }
try { try {
MojangUsernameToUuid mojangUsernameToUuid = mojangAPIService.getUuidFromUsername(username); MojangUsernameToUuidToken mojangUsernameToUuid = mojangAPIService.getUuidFromUsername(username);
if (mojangUsernameToUuid == null) { if (mojangUsernameToUuid == null) {
log.info("Player with username '{}' not found", username); log.info("Player with username '{}' not found", username);
throw new ResourceNotFoundException("Player with username '%s' not found".formatted(username)); throw new ResourceNotFoundException("Player with username '%s' not found".formatted(username));