cleanup
All checks were successful
deploy / deploy (push) Successful in 42s

This commit is contained in:
Lee
2024-04-08 06:21:53 +01:00
parent 29c842aaf8
commit 1773ec7d9c
7 changed files with 14 additions and 11 deletions

View File

@ -1,8 +1,8 @@
package cc.fascinated.service.mojang.model;
import cc.fascinated.Main;
import cc.fascinated.model.player.Cape;
import cc.fascinated.model.player.Skin;
import cc.fascinated.service.player.model.Cape;
import cc.fascinated.service.player.model.Skin;
import cc.fascinated.util.Tuple;
import cc.fascinated.util.UUIDUtils;
import com.google.gson.JsonObject;

View File

@ -1,6 +1,6 @@
package cc.fascinated.service;
package cc.fascinated.service.player;
import cc.fascinated.model.player.Player;
import cc.fascinated.service.player.model.Player;
import cc.fascinated.service.mojang.MojangAPIService;
import cc.fascinated.service.mojang.model.MojangProfile;
import cc.fascinated.service.mojang.model.MojangUsernameToUuid;

View File

@ -0,0 +1,27 @@
package cc.fascinated.service.player.model;
import com.google.gson.JsonObject;
import lombok.AllArgsConstructor;
import lombok.Getter;
@Getter @AllArgsConstructor
public class Cape {
/**
* The URL of the cape
*/
private final String url;
/**
* Gets the cape from a {@link JsonObject}.
*
* @param json the JSON object
* @return the cape
*/
public static Cape fromJson(JsonObject json) {
if (json == null) {
return null;
}
return new Cape(json.get("url").getAsString());
}
}

View File

@ -0,0 +1,46 @@
package cc.fascinated.service.player.model;
import cc.fascinated.service.mojang.model.MojangProfile;
import cc.fascinated.util.Tuple;
import cc.fascinated.util.UUIDUtils;
import lombok.Getter;
import java.util.UUID;
@Getter
public class Player {
/**
* The UUID of the player
*/
private final UUID uuid;
/**
* The name of the player
*/
private final String name;
/**
* The skin of the player, null if the
* player does not have a skin
*/
private Skin skin;
/**
* The cape of the player, null if the
* player does not have a cape
*/
private Cape cape;
public Player(MojangProfile profile) {
this.uuid = UUID.fromString(UUIDUtils.addUuidDashes(profile.getId()));
this.name = profile.getName();
// Get the skin and cape
Tuple<Skin, Cape> skinAndCape = profile.getSkinAndCape();
if (skinAndCape != null) {
this.skin = skinAndCape.getLeft();
this.cape = skinAndCape.getRight();
}
}
}

View File

@ -0,0 +1,134 @@
package cc.fascinated.service.player.model;
import cc.fascinated.config.Config;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.gson.JsonObject;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.extern.log4j.Log4j2;
import java.util.HashMap;
import java.util.Map;
@Getter @Log4j2
public class Skin {
/**
* The default skin, usually used when the skin is not found.
*/
public static final Skin DEFAULT_SKIN = new Skin("http://textures.minecraft.net/texture/60a5bd016b3c9a1b9272e4929e30827a67be4ebb219017adbbc4a4d22ebd5b1",
Model.DEFAULT);
/**
* The URL of the skin
*/
private final String url;
/**
* The model of the skin
*/
private final Model model;
/**
* The part URLs of the skin
*/
@JsonProperty("parts")
private final Map<String, String> partUrls = new HashMap<>();
public Skin(String url, Model model) {
this.url = url;
this.model = model;
}
/**
* Gets the skin from a {@link JsonObject}.
*
* @param json the JSON object
* @return the skin
*/
public static Skin fromJson(JsonObject json) {
if (json == null) {
return null;
}
String url = json.get("url").getAsString();
JsonObject metadata = json.getAsJsonObject("metadata");
Model model = Model.fromName(metadata == null ? "slim" : // Fall back to slim if the model is not found
metadata.get("model").getAsString());
return new Skin(url, model);
}
/**
* Populates the part URLs for the skin.
*
* @param playerUuid the player's UUID
*/
public Skin populatePartUrls(String playerUuid) {
for (Parts part : Parts.values()) {
String partName = part.name().toLowerCase();
this.partUrls.put(partName, Config.INSTANCE.getWebPublicUrl() + "/player/" + partName + "/" + playerUuid + "?size=" + part.getDefaultSize());
}
return this;
}
/**
* The skin part enum that contains the
* information about the part.
*/
@Getter @AllArgsConstructor
public enum Parts {
HEAD(8, 8, 8, 8, 128);
/**
* The x and y position of the part.
*/
private final int x, y;
/**
* The width and height of the part.
*/
private final int width, height;
/**
* The scale of the part.
*/
private final int defaultSize;
/**
* Gets the skin part from its name.
*
* @param name the name of the part
* @return the skin part
*/
public static Parts fromName(String name) {
for (Parts part : values()) {
if (part.name().equalsIgnoreCase(name)) {
return part;
}
}
return null;
}
}
/**
* The model of the skin.
*/
public enum Model {
DEFAULT,
SLIM;
/**
* Gets the model from its name.
*
* @param name the name of the model
* @return the model
*/
public static Model fromName(String name) {
for (Model model : values()) {
if (model.name().equalsIgnoreCase(name)) {
return model;
}
}
return null;
}
}
}