diff --git a/src/main/java/cc/fascinated/controller/PlayerController.java b/src/main/java/cc/fascinated/controller/PlayerController.java index 0c0b0ae..1d2d858 100644 --- a/src/main/java/cc/fascinated/controller/PlayerController.java +++ b/src/main/java/cc/fascinated/controller/PlayerController.java @@ -2,6 +2,7 @@ package cc.fascinated.controller; import cc.fascinated.model.cache.CachedPlayer; import cc.fascinated.model.cache.CachedPlayerName; +import cc.fascinated.model.player.Player; import cc.fascinated.service.PlayerService; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; @@ -50,7 +51,8 @@ public class PlayerController { @Parameter(description = "The size of the image", example = "256") @RequestParam(required = false, defaultValue = "256") int size, @Parameter(description = "Whether to render the skin overlay (skin layers)", example = "false") @RequestParam(required = false, defaultValue = "false") boolean overlays, @Parameter(description = "Whether to download the image") @RequestParam(required = false, defaultValue = "false") boolean download) { - CachedPlayer player = playerService.getPlayer(id); + CachedPlayer cachedPlayer = playerService.getPlayer(id); + Player player = cachedPlayer.getPlayer(); String dispositionHeader = download ? "attachment; filename=%s.png" : "inline; filename=%s.png"; // Return the part image diff --git a/src/main/java/cc/fascinated/model/cache/CacheInformation.java b/src/main/java/cc/fascinated/model/cache/CacheInformation.java new file mode 100644 index 0000000..c56b490 --- /dev/null +++ b/src/main/java/cc/fascinated/model/cache/CacheInformation.java @@ -0,0 +1,48 @@ +package cc.fascinated.model.cache; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.Setter; + +@AllArgsConstructor @Getter @Setter +public class CacheInformation { + /** + * Whether this request is cached. + */ + private boolean cached; + + /** + * The unix timestamp of when this was cached. + */ + private long cachedTime; + + /** + * Create a new cache information object with the default values. + *
+ * The default values are:
+ *
+ *
- * This could be due to high load or other issues. - *
+ * The service is online, but may be experiencing issues. + * This could be due to high load or other issues. */ DEGRADED, diff --git a/src/main/java/cc/fascinated/model/cache/CachedMinecraftServer.java b/src/main/java/cc/fascinated/model/cache/CachedMinecraftServer.java index 943ef03..4545452 100644 --- a/src/main/java/cc/fascinated/model/cache/CachedMinecraftServer.java +++ b/src/main/java/cc/fascinated/model/cache/CachedMinecraftServer.java @@ -27,8 +27,7 @@ public final class CachedMinecraftServer implements Serializable { private final MinecraftServer server; /** - * The unix timestamp of when this - * server was cached, -1 if not cached. + * The cache information about the request. */ - private long cached; + private CacheInformation cache; } \ No newline at end of file diff --git a/src/main/java/cc/fascinated/model/cache/CachedPlayer.java b/src/main/java/cc/fascinated/model/cache/CachedPlayer.java index 5803bb5..955e031 100644 --- a/src/main/java/cc/fascinated/model/cache/CachedPlayer.java +++ b/src/main/java/cc/fascinated/model/cache/CachedPlayer.java @@ -1,12 +1,11 @@ package cc.fascinated.model.cache; -import cc.fascinated.model.mojang.MojangProfile; -import cc.fascinated.model.player.Cape; import cc.fascinated.model.player.Player; -import cc.fascinated.model.skin.Skin; +import com.fasterxml.jackson.annotation.JsonIgnore; +import lombok.AllArgsConstructor; import lombok.Getter; import lombok.Setter; -import lombok.ToString; +import org.springframework.data.annotation.Id; import org.springframework.data.redis.core.RedisHash; import java.io.Serializable; @@ -18,17 +17,22 @@ import java.util.UUID; * @author Braydon */ @Setter @Getter -@ToString(callSuper = true) +@AllArgsConstructor @RedisHash(value = "player", timeToLive = 60L * 60L) // 1 hour (in seconds) -public final class CachedPlayer extends Player implements Serializable { +public final class CachedPlayer implements Serializable { /** - * The unix timestamp of when this - * player was cached, -1 if not cached. + * The unique id of the player. */ - private long cached; + @JsonIgnore + @Id private UUID uniqueId; - public CachedPlayer(UUID uniqueId, String trimmedUniqueId, String username, Skin skin, Cape cape, MojangProfile.ProfileProperty[] rawProperties, long cached) { - super(uniqueId, trimmedUniqueId, username, skin, cape, rawProperties); - this.cached = cached; - } + /** + * The player to cache. + */ + private Player player; + + /** + * The cache information about the request. + */ + private CacheInformation cache; } \ No newline at end of file diff --git a/src/main/java/cc/fascinated/model/player/Player.java b/src/main/java/cc/fascinated/model/player/Player.java index 5ac567e..a5dec85 100644 --- a/src/main/java/cc/fascinated/model/player/Player.java +++ b/src/main/java/cc/fascinated/model/player/Player.java @@ -6,7 +6,6 @@ import cc.fascinated.model.mojang.MojangProfile; import cc.fascinated.model.skin.Skin; import lombok.AllArgsConstructor; import lombok.Getter; -import org.springframework.data.annotation.Id; import java.util.UUID; @@ -16,7 +15,7 @@ public class Player { /** * The UUID of the player */ - @Id private final UUID uniqueId; + private final UUID uniqueId; /** * The trimmed UUID of the player diff --git a/src/main/java/cc/fascinated/service/MojangService.java b/src/main/java/cc/fascinated/service/MojangService.java index 518fab8..20ffef3 100644 --- a/src/main/java/cc/fascinated/service/MojangService.java +++ b/src/main/java/cc/fascinated/service/MojangService.java @@ -5,6 +5,7 @@ import cc.fascinated.common.EndpointStatus; import cc.fascinated.common.ExpiringSet; import cc.fascinated.common.WebRequest; import cc.fascinated.config.Config; +import cc.fascinated.model.cache.CacheInformation; import cc.fascinated.model.cache.CachedEndpointStatus; import cc.fascinated.model.mojang.MojangProfile; import cc.fascinated.model.mojang.MojangUsernameToUuid; @@ -231,10 +232,10 @@ public class MojangService { CachedEndpointStatus status = new CachedEndpointStatus( MOJANG_ENDPOINT_STATUS_KEY, endpoints, - System.currentTimeMillis() + CacheInformation.defaultCache() ); mojangEndpointStatusRepository.save(status); - status.setCached(-1L); // Indicate that the status is not cached + status.getCache().setCached(false); return status; } diff --git a/src/main/java/cc/fascinated/service/PlayerService.java b/src/main/java/cc/fascinated/service/PlayerService.java index 51fca2e..3231036 100644 --- a/src/main/java/cc/fascinated/service/PlayerService.java +++ b/src/main/java/cc/fascinated/service/PlayerService.java @@ -9,6 +9,7 @@ import cc.fascinated.exception.impl.BadRequestException; import cc.fascinated.exception.impl.MojangAPIRateLimitException; import cc.fascinated.exception.impl.RateLimitException; import cc.fascinated.exception.impl.ResourceNotFoundException; +import cc.fascinated.model.cache.CacheInformation; import cc.fascinated.model.cache.CachedPlayer; import cc.fascinated.model.cache.CachedPlayerName; import cc.fascinated.model.cache.CachedPlayerSkinPart; @@ -74,16 +75,19 @@ public class PlayerService { Tuple