mirror of
https://github.com/Suiranoil/SkinRestorer.git
synced 2026-01-16 04:42:12 +00:00
code styling
This commit is contained in:
@@ -32,30 +32,30 @@ public final class SkinRestorer {
|
||||
private static Path configDir;
|
||||
|
||||
public static SkinStorage getSkinStorage() {
|
||||
return skinStorage;
|
||||
return SkinRestorer.skinStorage;
|
||||
}
|
||||
|
||||
public static Path getConfigDir() {
|
||||
return configDir;
|
||||
return SkinRestorer.configDir;
|
||||
}
|
||||
|
||||
public static Iterable<Map.Entry<String, SkinProvider>> getProviders() {
|
||||
return providers.entrySet();
|
||||
return SkinRestorer.providers.entrySet();
|
||||
}
|
||||
|
||||
public static Optional<SkinProvider> getProvider(String name) {
|
||||
return Optional.ofNullable(providers.get(name));
|
||||
return Optional.ofNullable(SkinRestorer.providers.get(name));
|
||||
}
|
||||
|
||||
public static void onInitialize(Path rootConfigDir) {
|
||||
SkinRestorer.configDir = rootConfigDir.resolve(MOD_ID);
|
||||
SkinRestorer.configDir = rootConfigDir.resolve(SkinRestorer.MOD_ID);
|
||||
|
||||
SkinRestorer.providers.put("mojang", new MojangSkinProvider());
|
||||
SkinRestorer.providers.put("web", new MineskinSkinProvider());
|
||||
}
|
||||
|
||||
public static void onServerStarted(MinecraftServer server) {
|
||||
Path worldSkinDirectory = server.getSavePath(WorldSavePath.ROOT).resolve(MOD_ID);
|
||||
Path worldSkinDirectory = server.getSavePath(WorldSavePath.ROOT).resolve(SkinRestorer.MOD_ID);
|
||||
FileUtils.tryMigrateOldSkinDirectory(worldSkinDirectory);
|
||||
|
||||
SkinRestorer.skinStorage = new SkinStorage(new SkinIO(worldSkinDirectory));
|
||||
|
||||
@@ -26,7 +26,9 @@ import java.util.function.Supplier;
|
||||
import static net.minecraft.server.command.CommandManager.argument;
|
||||
import static net.minecraft.server.command.CommandManager.literal;
|
||||
|
||||
public class SkinCommand {
|
||||
public final class SkinCommand {
|
||||
|
||||
private SkinCommand() {}
|
||||
|
||||
public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
|
||||
LiteralArgumentBuilder<ServerCommandSource> base =
|
||||
|
||||
@@ -11,7 +11,7 @@ import net.lionarius.skinrestorer.util.WebUtils;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
|
||||
public class MineskinSkinProvider implements SkinProvider {
|
||||
public final class MineskinSkinProvider implements SkinProvider {
|
||||
|
||||
private static final String API = "https://api.mineskin.org/generate/url";
|
||||
private static final String USER_AGENT = "SkinRestorer";
|
||||
@@ -33,7 +33,7 @@ public class MineskinSkinProvider implements SkinProvider {
|
||||
String input = ("{\"variant\":\"%s\",\"name\":\"%s\",\"visibility\":%d,\"url\":\"%s\"}")
|
||||
.formatted(variant.toString(), "none", 1, url);
|
||||
|
||||
JsonObject texture = JsonUtils.parseJson(WebUtils.POSTRequest(new URL(API), USER_AGENT, TYPE, TYPE, input))
|
||||
JsonObject texture = JsonUtils.parseJson(WebUtils.postRequest(new URL(API), USER_AGENT, TYPE, TYPE, input))
|
||||
.getAsJsonObject("data").getAsJsonObject("texture");
|
||||
|
||||
return SkinResult.success(new Property(PlayerUtils.TEXTURES_KEY, texture.get("value").getAsString(), texture.get("signature").getAsString()));
|
||||
|
||||
@@ -12,7 +12,7 @@ import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.UUID;
|
||||
|
||||
public class MojangSkinProvider implements SkinProvider {
|
||||
public final class MojangSkinProvider implements SkinProvider {
|
||||
|
||||
private static final String API = "https://api.mojang.com/users/profiles/minecraft/";
|
||||
private static final String SESSION_SERVER = "https://sessionserver.mojang.com/session/minecraft/profile/";
|
||||
@@ -31,7 +31,7 @@ public class MojangSkinProvider implements SkinProvider {
|
||||
public SkinResult getSkin(String username, SkinVariant variant) {
|
||||
try {
|
||||
UUID uuid = getUUID(username);
|
||||
JsonObject texture = JsonUtils.parseJson(WebUtils.GETRequest(new URL(SESSION_SERVER + uuid + "?unsigned=false")))
|
||||
JsonObject texture = JsonUtils.parseJson(WebUtils.getRequest(new URL(SESSION_SERVER + uuid + "?unsigned=false")))
|
||||
.getAsJsonArray("properties").get(0).getAsJsonObject();
|
||||
|
||||
return SkinResult.success(new Property(PlayerUtils.TEXTURES_KEY, texture.get("value").getAsString(), texture.get("signature").getAsString()));
|
||||
@@ -41,7 +41,7 @@ public class MojangSkinProvider implements SkinProvider {
|
||||
}
|
||||
|
||||
private static UUID getUUID(String name) throws IOException {
|
||||
return UUID.fromString(JsonUtils.parseJson(WebUtils.GETRequest(new URL(API + name))).get("id").getAsString()
|
||||
return UUID.fromString(JsonUtils.parseJson(WebUtils.getRequest(new URL(API + name))).get("id").getAsString()
|
||||
.replaceFirst("(\\p{XDigit}{8})(\\p{XDigit}{4})(\\p{XDigit}{4})(\\p{XDigit}{4})(\\p{XDigit}+)", "$1-$2-$3-$4-$5"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,9 @@ import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
|
||||
public class FileUtils {
|
||||
public final class FileUtils {
|
||||
|
||||
private FileUtils() {}
|
||||
|
||||
public static void tryMigrateOldSkinDirectory(Path newDirectory) {
|
||||
try {
|
||||
|
||||
@@ -9,7 +9,9 @@ import com.mojang.authlib.properties.Property;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Base64;
|
||||
|
||||
public class JsonUtils {
|
||||
public final class JsonUtils {
|
||||
|
||||
private JsonUtils() {}
|
||||
|
||||
private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
|
||||
|
||||
|
||||
@@ -12,7 +12,9 @@ import net.minecraft.server.world.ServerWorld;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class PlayerUtils {
|
||||
public final class PlayerUtils {
|
||||
|
||||
private PlayerUtils() {}
|
||||
|
||||
public static final String TEXTURES_KEY = "textures";
|
||||
|
||||
|
||||
@@ -3,7 +3,9 @@ package net.lionarius.skinrestorer.util;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
|
||||
public class StringUtils {
|
||||
public final class StringUtils {
|
||||
|
||||
private StringUtils() {}
|
||||
|
||||
public static String readString(BufferedReader reader) throws IOException {
|
||||
String inputLine;
|
||||
|
||||
@@ -7,7 +7,7 @@ import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Objects;
|
||||
|
||||
public class TranslationUtils {
|
||||
public final class TranslationUtils {
|
||||
public static class Translation {
|
||||
public String skinActionAffectedProfile = "Skin has been saved for %s";
|
||||
public String skinActionAffectedPlayer = "Apply live skin changes for %s";
|
||||
@@ -18,6 +18,8 @@ public class TranslationUtils {
|
||||
public static final String TRANSLATION_FILENAME = "translation";
|
||||
private static Translation translation = new Translation();
|
||||
|
||||
private TranslationUtils() {}
|
||||
|
||||
public static Translation getTranslation() {
|
||||
return translation;
|
||||
}
|
||||
|
||||
@@ -8,9 +8,11 @@ import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class WebUtils {
|
||||
public final class WebUtils {
|
||||
|
||||
public static String POSTRequest(URL url, String userAgent, String contentType, String responseType, String input)
|
||||
private WebUtils() {}
|
||||
|
||||
public static String postRequest(URL url, String userAgent, String contentType, String responseType, String input)
|
||||
throws IOException {
|
||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||
|
||||
@@ -30,7 +32,7 @@ public class WebUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static String GETRequest(URL url) throws IOException {
|
||||
public static String getRequest(URL url) throws IOException {
|
||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||
|
||||
connection.setRequestMethod("GET");
|
||||
|
||||
Reference in New Issue
Block a user