Skip to content

Commit

Permalink
Warn uploading HD skins (#114)
Browse files Browse the repository at this point in the history
  • Loading branch information
samolego committed Dec 2, 2024
1 parent 383c47a commit 55ab8fd
Show file tree
Hide file tree
Showing 12 changed files with 24 additions and 58 deletions.
32 changes: 4 additions & 28 deletions src/main/java/org/samo_lego/fabrictailor/command/SkinCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
import static org.samo_lego.fabrictailor.util.SkinFetcher.setSkinFromFile;

public class SkinCommand {
private static final MutableComponent SKIN_SET_ERROR = TextTranslations.create("command.fabrictailor.skin.set.404").withStyle(ChatFormatting.RED);
private static final MutableComponent SKIN_SET_ERROR = TextTranslations.create("command.fabrictailor.skin.set.error").withStyle(ChatFormatting.RED);
private static final MutableComponent SET_SKIN_ATTEMPT = TextTranslations.create("command.fabrictailor.skin.set.attempt");

public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
Expand All @@ -56,12 +56,6 @@ public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
.executes(context -> setSkinUrl(context, true))
)
)
.executes(ctx -> {
ctx.getSource().sendFailure(
TextTranslations.create("command.fabrictailor.skin.set.404.url").withStyle(ChatFormatting.RED)
);
return 0;
})
)
.then(literal("upload")
.requires(src -> Permissions.check(src, "fabrictailor.command.skin.set.upload", true))
Expand All @@ -77,12 +71,6 @@ public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
.executes(context -> setSkinFile(context, true))
)
)
.executes(ctx -> {
ctx.getSource().sendFailure(
TextTranslations.create("command.fabrictailor.skin.set.404.path").withStyle(ChatFormatting.RED)
);
return 0;
})
)
.then(literal("custom")
.requires(src -> !config.customSkinServer.isEmpty() && Permissions.check(src, "fabrictailor.command.skin.set.custom", true))
Expand All @@ -98,12 +86,6 @@ public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
.executes(context -> setSkinCustom(context, true))
)
)
.executes(ctx -> {
ctx.getSource().sendFailure(
TextTranslations.create("command.fabrictailor.skin.set.404.playername").withStyle(ChatFormatting.RED)
);
return 0;
})
)
.then(literal("player")
.requires(src -> Permissions.check(src, "fabrictailor.command.skin.set.player", true))
Expand All @@ -117,16 +99,10 @@ public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
return 0;
})
)
.executes(ctx -> {
ctx.getSource().sendFailure(
TextTranslations.create("command.fabrictailor.skin.set.404").withStyle(ChatFormatting.RED)
);
return 0;
})
)
.then(literal("clear")
.requires(src -> Permissions.check(src, "fabrictailor.command.skin.clear", true))
.executes(context -> clearSkin(context.getSource().getPlayerOrException()) ? 1 : 0))
.then(literal("clear")
.requires(src -> Permissions.check(src, "fabrictailor.command.skin.clear", true))
.executes(context -> clearSkin(context.getSource().getPlayerOrException()) ? 1 : 0))
);
}

Expand Down
17 changes: 17 additions & 0 deletions src/main/java/org/samo_lego/fabrictailor/util/SkinFetcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import org.jetbrains.annotations.Nullable;
import org.samo_lego.fabrictailor.casts.TailoredPlayer;

import javax.imageio.ImageIO;
import javax.net.ssl.HttpsURLConnection;
import java.awt.image.*;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URI;
Expand All @@ -27,10 +29,20 @@ public class SkinFetcher {
* @return property containing skin value and signature if successful, otherwise null.
*/
public static Property setSkinFromFile(String skinFilePath, boolean useSlim) {
Logging.debug("Fetching skin from file: " + skinFilePath);
File skinFile = new File(skinFilePath);
try (FileInputStream input = new FileInputStream(skinFile)) {
Logging.debug("Checking file type: " + input.read());
if (input.read() == 137) {
// Check image dimensions
BufferedImage image = ImageIO.read(skinFile);
if (image.getWidth() != 64 || (image.getHeight() != 64 && image.getHeight() != 32)) {
Logging.error("Image dimensions are not 64x64 or 32x64! The actual format is: " + image.getWidth() + "x" + image.getHeight());
return null;
}

try {
Logging.debug("Uploading skin to MineSkin.");
String reply = urlRequest(URI.create("https://api.mineskin.org/generate/upload?model=" + (useSlim ? "slim" : "steve")).toURL(), false, skinFile);
return getSkinFromReply(reply);
} catch (IOException e) {
Expand All @@ -53,6 +65,7 @@ public static Property setSkinFromFile(String skinFilePath, boolean useSlim) {
*/
@Nullable
public static Property fetchSkinByUrl(String skinUrl, boolean useSlim) {
Logging.debug("Fetching skin from URL: " + skinUrl);
try {
URL url = URI.create(String.format("https://api.mineskin.org/generate/url?url=%s&model=%s", URLEncoder.encode(skinUrl, StandardCharsets.UTF_8), useSlim ? "slim" : "steve")).toURL();
String reply = urlRequest(url, false, null);
Expand All @@ -71,13 +84,16 @@ public static Property fetchSkinByUrl(String skinUrl, boolean useSlim) {
*/
@Nullable
public static Property fetchSkinByName(String playername) {
Logging.debug("Fetching Mojang skin of player: " + playername);
try {
String reply = urlRequest(URI.create("https://api.mojang.com/users/profiles/minecraft/" + playername).toURL(), true, null);

if (reply == null || !reply.contains("id")) {
Logging.debug("Mojang skin not found, trying via proxy.");
reply = urlRequest(URI.create(String.format("http://skinsystem.ely.by/textures/signed/%s.png?proxy=true", playername)).toURL(), false, null);
} else {
String uuid = JsonParser.parseString(reply).getAsJsonObject().get("id").getAsString();
Logging.debug("Mojang skin found. UUID: " + uuid);
reply = urlRequest(URI.create("https://sessionserver.mojang.com/session/minecraft/profile/" + uuid + "?unsigned=false").toURL(), true, null);
}
return getSkinFromReply(reply);
Expand All @@ -96,6 +112,7 @@ public static Property fetchSkinByName(String playername) {
*/
@Nullable
protected static Property getSkinFromReply(String reply) {
Logging.debug("Parsing skin reply: " + reply);
if (reply == null || reply.contains("error") || reply.isEmpty()) {
return null;
}
Expand Down
3 changes: 0 additions & 3 deletions src/main/resources/assets/fabrictailor/lang/uk_ua.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
{
"command.fabrictailor.skin.set.attempt": "Спроба встановити шкіру ... Будь ласка, зачекайте.",
"command.fabrictailor.skin.404": "Сталася помилка під час спроби отримати шкіру.",
"command.fabrictailor.skin.set.404": "Ви повинні надати URL, ім'я гравця або файл скіна, яку ви хочете встановити.",
"command.fabrictailor.skin.set.404.url": "Ви повинні надати URL та варіант скіна, яку ви хочете встановити.",
"command.fabrictailor.skin.set.404.path": "Ви повинні надати шлях до файлу та варіант скіна, яку ви хочете встановити.",
"command.fabrictailor.skin.set.404.playername": "Ви повинні надати ім'я гравця.",
"command.fabrictailor.skin.set.success": "Шкіру успішно встановлено.",
"command.fabrictailor.skin.set.error": "Здається, у цього гравця немає збережених шкір.",
"command.fabrictailor.skin.clear.success": "Шкіру успішно видалено.",
"command.fabrictailor.skin.clear.error": "Сталася помилка під час спроби видалити шкіру.",
"command.fabrictailor.skin.please_wait": "Завантаження скіна. Будь ласка, зачекайте.",
Expand Down
5 changes: 2 additions & 3 deletions src/main/resources/data/fabrictailor/lang/en_us.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
{

"command.fabrictailor.skin.set.attempt": "Trying to set the skin ... Please wait.",
"command.fabrictailor.skin.404": "An error occurred when trying to fetch skin.",
"command.fabrictailor.skin.set.404": "You have to provide URL, player's name or file of the skin you want.",
"command.fabrictailor.skin.error": "An error occurred when trying to set this skin.",
"command.fabrictailor.skin.set.error": "There was a problem with fetching the skin.",
"command.fabrictailor.skin.set.404.url": "You have to provide URL and variant of the skin you want.",
"command.fabrictailor.skin.set.404.path": "You have to provide file path and variant of the skin you want.",
"command.fabrictailor.skin.set.404.playername": "You have to provide player's name.",
"command.fabrictailor.skin.set.success": "Skin was set successfully.",
"command.fabrictailor.skin.set.error": "This player doesn't seem to have any skins saved.",
"command.fabrictailor.skin.clear.success": "Skin was cleared successfully.",
"command.fabrictailor.skin.clear.error": "An error occurred when trying to clear your skin.",
"command.fabrictailor.skin.please_wait": "Uploading skin. Please wait.",
Expand Down
3 changes: 0 additions & 3 deletions src/main/resources/data/fabrictailor/lang/fr_fr.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
{
"command.fabrictailor.skin.set.attempt": "Tentative de définir le skin... Veuillez patienter.",
"command.fabrictailor.skin.404": "Une erreur est survenue lors de la récupération du skin.",
"command.fabrictailor.skin.set.404": "Vous devez fournir une URL, un nom de joueur ou un fichier du skin que vous voulez.",
"command.fabrictailor.skin.set.404.url": "Vous devez fournir l'URL et la variante du skin que vous voulez.",
"command.fabrictailor.skin.set.404.path": "Vous devez fournir le chemin du fichier et la variante du skin que vous voulez.",
"command.fabrictailor.skin.set.404.playername": "Vous devez fournir le nom du joueur.",
"command.fabrictailor.skin.set.success": "Le skin a été définie avec succès.",
"command.fabrictailor.skin.set.error": "Ce joueur ne semble pas avoir de skins enregistrées.",
"command.fabrictailor.skin.clear.success": "Le skin a été effacée avec succès.",
"command.fabrictailor.skin.clear.error": "Une erreur est survenue lors de la suppression de votre skin.",
"command.fabrictailor.skin.please_wait": "Téléversement du skin. Veuillez patienter.",
Expand Down
3 changes: 0 additions & 3 deletions src/main/resources/data/fabrictailor/lang/ko_kr.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
{

"command.fabrictailor.skin.set.attempt": "스킨 설정을 시도하는 중입니다... 잠시 기다려주세요.",
"command.fabrictailor.skin.404": "스킨을 가져오는 중 에러가 발생했습니다.",
"command.fabrictailor.skin.set.404": "원하는 스킨의 URL 주소 또는 플레이어 이름 혹은 파일 경로를 입력해야 합니다.",
"command.fabrictailor.skin.set.404.url": "원하는 스킨의 URL 주소와 모델을 입력해야 합니다.",
"command.fabrictailor.skin.set.404.path": "원하는 스킨의 파일 경로와 모델을 입력해야 합니다.",
"command.fabrictailor.skin.set.404.playername": "플레이어 이름을 입력해야 합니다.",
"command.fabrictailor.skin.set.success": "스킨이 성공적으로 설정되었습니다..",
"command.fabrictailor.skin.set.error": "이 플레이어는 저장한 스킨이 없는 것 같네요.",
"command.fabrictailor.skin.clear.success": "스킨이 성공적으로 초기화 되었습니다.",
"command.fabrictailor.skin.clear.error": "스킨을 초기화 하는 중 에러가 발생했습니다.",
"command.fabrictailor.skin.please_wait": "스킨을 업로드하는 중입니다. 잠시 기다려주세요.",
Expand Down
3 changes: 0 additions & 3 deletions src/main/resources/data/fabrictailor/lang/pt_br.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
{

"command.fabrictailor.skin.set.attempt": "Tentando inserir skin... Por favor aguarde.",
"command.fabrictailor.skin.404": "Um erro ocorreu ao tentar buscar a skin.",
"command.fabrictailor.skin.set.404": "Você deve preencher com uma URL, nome do jogador ou o arquivo com a skin que deseja.",
"command.fabrictailor.skin.set.404.url": "Você deve preencher com a URL e variante da skin que deseja.",
"command.fabrictailor.skin.set.404.path": "Você deve preencher com o caminho do arquivo e variante da skin que deseja.",
"command.fabrictailor.skin.set.404.playername": "Você deve preencher com o nome do jogador.",
"command.fabrictailor.skin.set.success": "A skin foi definida com sucesso.",
"command.fabrictailor.skin.set.error": "Esse jogador não aparenta ter alguma skin salva.",
"command.fabrictailor.skin.clear.success": "A skin foi removida com sucesso.",
"command.fabrictailor.skin.clear.error": "Um erro ocorreu ao tentar remover sua skin.",
"command.fabrictailor.skin.please_wait": "Enviando skin. Por favor aguarde.",
Expand Down
3 changes: 0 additions & 3 deletions src/main/resources/data/fabrictailor/lang/ru_ru.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
{

"command.fabrictailor.skin.set.attempt": "Пытаемся поставить скин... Пожалуйста, подождите.",
"command.fabrictailor.skin.404": "При попытке получить скин произошла ошибка.",
"command.fabrictailor.skin.set.404": "Вы должны предоставить URL, ник игрока или файл скина который, вы хотите.",
"command.fabrictailor.skin.set.404.url": "Вы должны предоставить URL и тип скина, который вы хотите.",
"command.fabrictailor.skin.set.404.path": "Вы должны предоставить путь до файла и тип скина, который вы хотите.",
"command.fabrictailor.skin.set.404.playername": "Вы должны предоставить никнейм игрока.",
"command.fabrictailor.skin.set.success": "Скин установлен успешно.",
"command.fabrictailor.skin.set.error": "Похоже, что этот игрок не имеет сохраненных скинов.",
"command.fabrictailor.skin.clear.success": "Скин был успешно отчищен.",
"command.fabrictailor.skin.clear.error": "При поытке отчстить скин произошла ошибка.",
"command.fabrictailor.skin.please_wait": "Загружаем скин. Пожалуйста, подождите.",
Expand Down
4 changes: 1 addition & 3 deletions src/main/resources/data/fabrictailor/lang/sl_si.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
{

"command.fabrictailor.skin.set.attempt": "Poteka nastavitev izgleda ... Prosim počakaj.",
"command.fabrictailor.skin.404": "Prišlo je do napake pri pridobivanju slike izgleda.",
"command.fabrictailor.skin.set.404": "Navesti moraš URL, igralčevo ime ali pot do datoteke za nastavljanje izgleda.",
"command.fabrictailor.skin.set.404.url": "Navesti moraš URL in tip izgleda, ki ga želiš.",
"command.fabrictailor.skin.set.404.path": "Navesti moraš pot datoteke in tip izgleda, ki ga želiš.",
"command.fabrictailor.skin.set.404.playername": "Vnesti moraš igralčevo ime.",
"command.fabrictailor.skin.set.success": "Izgled je bil uspešno nastavljen.",
"command.fabrictailor.skin.set.error": "Ta igralec nima shranjenih posebnih izgledov.",
"command.fabrictailor.skin.set.error": "Prišlo je do napake pri pridobivanju izgleda.",
"command.fabrictailor.skin.clear.success": "Izgled je bil uspešno počiščen.",
"command.fabrictailor.skin.clear.error": "Prišlo je do napake pri čiščenju izgleda.",
"command.fabrictailor.skin.please_wait": "Nalaganje slike izgleda. Prosim počakaj.",
Expand Down
3 changes: 0 additions & 3 deletions src/main/resources/data/fabrictailor/lang/uk_ua.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
{
"command.fabrictailor.skin.set.attempt": "Спроба встановити шкіру ... Будь ласка, зачекайте.",
"command.fabrictailor.skin.404": "Сталася помилка під час спроби отримати шкіру.",
"command.fabrictailor.skin.set.404": "Ви повинні надати URL, ім'я гравця або файл скіна, яку ви хочете встановити.",
"command.fabrictailor.skin.set.404.url": "Ви повинні надати URL та варіант скіна, яку ви хочете встановити.",
"command.fabrictailor.skin.set.404.path": "Ви повинні надати шлях до файлу та варіант скіна, яку ви хочете встановити.",
"command.fabrictailor.skin.set.404.playername": "Ви повинні надати ім'я гравця.",
"command.fabrictailor.skin.set.success": "Шкіру успішно встановлено.",
"command.fabrictailor.skin.set.error": "Здається, у цього гравця немає збережених шкір.",
"command.fabrictailor.skin.clear.success": "Шкіру успішно видалено.",
"command.fabrictailor.skin.clear.error": "Сталася помилка під час спроби видалити шкіру.",
"command.fabrictailor.skin.please_wait": "Завантаження скіна. Будь ласка, зачекайте.",
Expand Down
3 changes: 0 additions & 3 deletions src/main/resources/data/fabrictailor/lang/vi_vn.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
{

"command.fabrictailor.skin.set.attempt": "Đang thay đổi skin ... Vui lòng chờ.",
"command.fabrictailor.skin.404": "Có lỗi xảy ra khi đang lấy skin.",
"command.fabrictailor.skin.set.404": "Bạn phải cung cấp URL, tên của người chơi hoặc tập tin của skin bạn muốn.",
"command.fabrictailor.skin.set.404.url": "Bạn phải cung cấp URL và loại skin bạn muốn.",
"command.fabrictailor.skin.set.404.path": "Bạn phải cung cấp đường dẫn của tập tin và loại skin bạn muốn.",
"command.fabrictailor.skin.set.404.playername": "Bạn phải cung cấp tên của người chơi.",
"command.fabrictailor.skin.set.success": "Skin đã thay đổi thành công.",
"command.fabrictailor.skin.set.error": "Người chơi này hình như không lưu skins nào.",
"command.fabrictailor.skin.clear.success": "Skin đã xoá thành công.",
"command.fabrictailor.skin.clear.error": "Có lỗi xảy ra khi đang xoá skin.",
"command.fabrictailor.skin.please_wait": "Đang tải skin lên. Vui lòng chờ.",
Expand Down
3 changes: 0 additions & 3 deletions src/main/resources/data/fabrictailor/lang/zh_tw.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
{

"command.fabrictailor.skin.set.attempt": "正在嘗試設定外觀...請稍候。",
"command.fabrictailor.skin.404": "嘗試取得外觀時發生錯誤。",
"command.fabrictailor.skin.set.404": "您必須提供您想要的外觀的網址、玩家名稱或檔案。",
"command.fabrictailor.skin.set.404.url": "您必須提供您想要的外觀的網址和變種。",
"command.fabrictailor.skin.set.404.path": "您必須提供您想要的外觀的檔案路徑和變種。",
"command.fabrictailor.skin.set.404.playername": "您必須提供玩家名稱。",
"command.fabrictailor.skin.set.success": "外觀設定成功。",
"command.fabrictailor.skin.set.error": "這個玩家似乎沒有儲存任何外觀。",
"command.fabrictailor.skin.clear.success": "外觀已成功清除。",
"command.fabrictailor.skin.clear.error": "嘗試清除您的外觀時發生錯誤。",
"command.fabrictailor.skin.please_wait": "正在上傳外觀。請稍候。",
Expand Down

0 comments on commit 55ab8fd

Please sign in to comment.