mirror of
https://github.com/Suiranoil/SkinRestorer.git
synced 2026-01-16 04:42:12 +00:00
Merge branch 'refs/heads/1.20.5-multiloader' into 1.20.3-multiloader
This commit is contained in:
2
.github/workflows/build.yml
vendored
2
.github/workflows/build.yml
vendored
@@ -4,8 +4,6 @@ on:
|
|||||||
paths-ignore:
|
paths-ignore:
|
||||||
- '.github/**'
|
- '.github/**'
|
||||||
- '*.md'
|
- '*.md'
|
||||||
tags-ignore:
|
|
||||||
- '*'
|
|
||||||
pull_request:
|
pull_request:
|
||||||
paths-ignore:
|
paths-ignore:
|
||||||
- '.github/**'
|
- '.github/**'
|
||||||
|
|||||||
2
.github/workflows/release.yml
vendored
2
.github/workflows/release.yml
vendored
@@ -2,7 +2,7 @@ name: release
|
|||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
tags:
|
tags:
|
||||||
- "v*"
|
- "v**"
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
base {
|
base {
|
||||||
archivesName = "${mod_id}-${project.name}"
|
archivesName = "${mod_id}"
|
||||||
version = "${mod_version}+${minecraft_version}"
|
version = "${mod_version}+${minecraft_version}-${project.name}"
|
||||||
}
|
}
|
||||||
|
|
||||||
java {
|
java {
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
package net.lionarius.skinrestorer;
|
package net.lionarius.skinrestorer;
|
||||||
|
|
||||||
import com.mojang.authlib.GameProfile;
|
import com.mojang.authlib.GameProfile;
|
||||||
|
import net.lionarius.skinrestorer.config.BuiltInProviderConfig;
|
||||||
import net.lionarius.skinrestorer.config.Config;
|
import net.lionarius.skinrestorer.config.Config;
|
||||||
|
import net.lionarius.skinrestorer.platform.Services;
|
||||||
import net.lionarius.skinrestorer.skin.SkinIO;
|
import net.lionarius.skinrestorer.skin.SkinIO;
|
||||||
import net.lionarius.skinrestorer.skin.SkinStorage;
|
import net.lionarius.skinrestorer.skin.SkinStorage;
|
||||||
import net.lionarius.skinrestorer.skin.SkinValue;
|
import net.lionarius.skinrestorer.skin.SkinValue;
|
||||||
@@ -10,6 +12,7 @@ import net.lionarius.skinrestorer.translation.Translation;
|
|||||||
import net.lionarius.skinrestorer.util.FileUtils;
|
import net.lionarius.skinrestorer.util.FileUtils;
|
||||||
import net.lionarius.skinrestorer.util.PlayerUtils;
|
import net.lionarius.skinrestorer.util.PlayerUtils;
|
||||||
import net.lionarius.skinrestorer.util.Result;
|
import net.lionarius.skinrestorer.util.Result;
|
||||||
|
import net.lionarius.skinrestorer.util.WebUtils;
|
||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import net.minecraft.world.level.storage.LevelResource;
|
import net.minecraft.world.level.storage.LevelResource;
|
||||||
@@ -53,19 +56,28 @@ public final class SkinRestorer {
|
|||||||
return Optional.ofNullable(SkinRestorer.providersRegistry.get(name));
|
return Optional.ofNullable(SkinRestorer.providersRegistry.get(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void onInitialize(Path rootConfigDir) {
|
public static void onInitialize() {
|
||||||
SkinRestorer.configDir = rootConfigDir.resolve(SkinRestorer.MOD_ID);
|
SkinRestorer.configDir = Services.PLATFORM.getConfigDirectory().resolve(SkinRestorer.MOD_ID);
|
||||||
SkinRestorer.reloadConfig();
|
SkinRestorer.reloadConfig();
|
||||||
|
|
||||||
SkinRestorer.providersRegistry.register(EmptySkinProvider.PROVIDER_NAME, SkinProvider.EMPTY, false);
|
SkinRestorer.providersRegistry.register(EmptySkinProvider.PROVIDER_NAME, SkinProvider.EMPTY, false);
|
||||||
SkinRestorer.providersRegistry.register(MojangSkinProvider.PROVIDER_NAME, SkinProvider.MOJANG);
|
|
||||||
SkinRestorer.providersRegistry.register(ElyBySkinProvider.PROVIDER_NAME, SkinProvider.ELY_BY);
|
SkinRestorer.registerDefaultSkinProvider(MojangSkinProvider.PROVIDER_NAME, SkinProvider.MOJANG, SkinRestorer.getConfig().providersConfig().mojang());
|
||||||
SkinRestorer.providersRegistry.register(MineskinSkinProvider.PROVIDER_NAME, SkinProvider.MINESKIN);
|
SkinRestorer.registerDefaultSkinProvider(ElyBySkinProvider.PROVIDER_NAME, SkinProvider.ELY_BY, SkinRestorer.getConfig().providersConfig().ely_by());
|
||||||
|
SkinRestorer.registerDefaultSkinProvider(MineskinSkinProvider.PROVIDER_NAME, SkinProvider.MINESKIN, SkinRestorer.getConfig().providersConfig().mineskin());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void registerDefaultSkinProvider(String defaultName, SkinProvider provider, BuiltInProviderConfig config) {
|
||||||
|
var isDefaultName = config.name().equals(defaultName);
|
||||||
|
SkinRestorer.providersRegistry.register(defaultName, provider, config.enabled() && isDefaultName);
|
||||||
|
|
||||||
|
if (!isDefaultName)
|
||||||
|
SkinRestorer.providersRegistry.register(config.name(), provider, config.enabled());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void onServerStarted(MinecraftServer server) {
|
public static void onServerStarted(MinecraftServer server) {
|
||||||
Path worldSkinDirectory = server.getWorldPath(LevelResource.ROOT).resolve(SkinRestorer.MOD_ID);
|
Path worldSkinDirectory = server.getWorldPath(LevelResource.ROOT).resolve(SkinRestorer.MOD_ID);
|
||||||
FileUtils.tryMigrateOldSkinDirectory(worldSkinDirectory);
|
FileUtils.tryMigrateOldSkinDirectory(SkinRestorer.getConfigDir(), worldSkinDirectory);
|
||||||
|
|
||||||
SkinRestorer.skinStorage = new SkinStorage(new SkinIO(worldSkinDirectory));
|
SkinRestorer.skinStorage = new SkinStorage(new SkinIO(worldSkinDirectory));
|
||||||
}
|
}
|
||||||
@@ -73,9 +85,14 @@ public final class SkinRestorer {
|
|||||||
public static void reloadConfig() {
|
public static void reloadConfig() {
|
||||||
SkinRestorer.config = Config.load(SkinRestorer.getConfigDir());
|
SkinRestorer.config = Config.load(SkinRestorer.getConfigDir());
|
||||||
Translation.reloadTranslations();
|
Translation.reloadTranslations();
|
||||||
|
WebUtils.recreateHttpClient();
|
||||||
|
|
||||||
|
MojangSkinProvider.createCache();
|
||||||
|
ElyBySkinProvider.createCache();
|
||||||
|
MineskinSkinProvider.createCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String resource(String name) {
|
public static String assetPath(String name) {
|
||||||
return String.format("/assets/%s/%s", SkinRestorer.MOD_ID, name);
|
return String.format("/assets/%s/%s", SkinRestorer.MOD_ID, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,7 +133,7 @@ public final class SkinRestorer {
|
|||||||
boolean save
|
boolean save
|
||||||
) {
|
) {
|
||||||
return CompletableFuture.supplyAsync(
|
return CompletableFuture.supplyAsync(
|
||||||
() -> SkinRestorer.getProvider(context.name()).map(provider -> provider.getSkin(context.argument(), context.variant()))
|
() -> SkinRestorer.getProvider(context.name()).map(provider -> provider.fetchSkin(context.argument(), context.variant()))
|
||||||
)
|
)
|
||||||
.thenApplyAsync(result -> {
|
.thenApplyAsync(result -> {
|
||||||
if (result.isEmpty())
|
if (result.isEmpty())
|
||||||
|
|||||||
@@ -49,9 +49,14 @@ public final class SkinCommand {
|
|||||||
var providers = SkinRestorer.getProvidersRegistry().getPublicProviders();
|
var providers = SkinRestorer.getProvidersRegistry().getPublicProviders();
|
||||||
for (var entry : providers)
|
for (var entry : providers)
|
||||||
set.then(buildSetSubcommand(entry.first(), entry.second()));
|
set.then(buildSetSubcommand(entry.first(), entry.second()));
|
||||||
|
|
||||||
base.then(set);
|
base.then(set);
|
||||||
|
|
||||||
|
base.then(
|
||||||
|
literal("config")
|
||||||
|
.requires(commandSourceStack -> commandSourceStack.hasPermission(4))
|
||||||
|
.then(literal("reload").executes(SkinCommand::configReloadSubcommand))
|
||||||
|
);
|
||||||
|
|
||||||
dispatcher.register(base);
|
dispatcher.register(base);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,6 +165,16 @@ public final class SkinCommand {
|
|||||||
return setSubcommand(src, Collections.singleton(src.getPlayer().getGameProfile()), context, false);
|
return setSubcommand(src, Collections.singleton(src.getPlayer().getGameProfile()), context, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static int configReloadSubcommand(CommandContext<CommandSourceStack> context) {
|
||||||
|
SkinRestorer.reloadConfig();
|
||||||
|
|
||||||
|
context.getSource().sendSuccess(() -> Translation.translatableWithFallback(
|
||||||
|
Translation.COMMAND_SKIN_CONFIG_RELOADED_KEY
|
||||||
|
), true);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
private static void sendResponse(CommandSourceStack src, Collection<ServerPlayer> updatedPlayers, boolean setByOperator) {
|
private static void sendResponse(CommandSourceStack src, Collection<ServerPlayer> updatedPlayers, boolean setByOperator) {
|
||||||
if (updatedPlayers.isEmpty()) {
|
if (updatedPlayers.isEmpty()) {
|
||||||
src.sendSuccess(() -> Translation.translatableWithFallback(
|
src.sendSuccess(() -> Translation.translatableWithFallback(
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package net.lionarius.skinrestorer.config;
|
||||||
|
|
||||||
|
public record BuiltInProviderConfig(boolean enabled, String name, CacheConfig cache) {
|
||||||
|
public boolean isValid() {
|
||||||
|
return this.name != null && this.cache != null && !this.name.isEmpty() && this.cache.isValid();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package net.lionarius.skinrestorer.config;
|
||||||
|
|
||||||
|
public record CacheConfig(boolean enabled, long duration) {
|
||||||
|
public boolean isValid() {
|
||||||
|
return this.duration > 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,6 +5,7 @@ import net.lionarius.skinrestorer.util.FileUtils;
|
|||||||
import net.lionarius.skinrestorer.util.JsonUtils;
|
import net.lionarius.skinrestorer.util.JsonUtils;
|
||||||
|
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
public final class Config {
|
public final class Config {
|
||||||
|
|
||||||
@@ -13,34 +14,47 @@ public final class Config {
|
|||||||
|
|
||||||
private String language = "en_us";
|
private String language = "en_us";
|
||||||
|
|
||||||
|
private boolean refreshSkinOnJoin = false;
|
||||||
|
|
||||||
private boolean fetchSkinOnFirstJoin = true;
|
private boolean fetchSkinOnFirstJoin = true;
|
||||||
|
|
||||||
private FirstJoinSkinProvider firstJoinSkinProvider = FirstJoinSkinProvider.MOJANG;
|
private FirstJoinSkinProvider firstJoinSkinProvider = FirstJoinSkinProvider.MOJANG;
|
||||||
|
|
||||||
private String proxy = "";
|
private String proxy = "";
|
||||||
|
private transient Proxy parsedProxy = null;
|
||||||
|
|
||||||
private long requestTimeout = 10;
|
private long requestTimeout = 10;
|
||||||
|
|
||||||
public String getLanguage() {
|
private ProvidersConfig providers = ProvidersConfig.DEFAULT;
|
||||||
|
|
||||||
|
public String language() {
|
||||||
return this.language;
|
return this.language;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean refreshSkinOnJoin() {
|
||||||
|
return this.refreshSkinOnJoin;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean fetchSkinOnFirstJoin() {
|
public boolean fetchSkinOnFirstJoin() {
|
||||||
return this.fetchSkinOnFirstJoin;
|
return this.fetchSkinOnFirstJoin;
|
||||||
}
|
}
|
||||||
|
|
||||||
public FirstJoinSkinProvider getFirstJoinSkinProvider() {
|
public FirstJoinSkinProvider firstJoinSkinProvider() {
|
||||||
return this.firstJoinSkinProvider;
|
return this.firstJoinSkinProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getProxy() {
|
public Optional<Proxy> proxy() {
|
||||||
return this.proxy;
|
return Optional.ofNullable(this.parsedProxy);
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getRequestTimeout() {
|
public long requestTimeout() {
|
||||||
return this.requestTimeout;
|
return this.requestTimeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ProvidersConfig providersConfig() {
|
||||||
|
return this.providers;
|
||||||
|
}
|
||||||
|
|
||||||
public static Config load(Path path) {
|
public static Config load(Path path) {
|
||||||
var configFile = path.resolve(Config.CONFIG_FILENAME);
|
var configFile = path.resolve(Config.CONFIG_FILENAME);
|
||||||
|
|
||||||
@@ -62,16 +76,41 @@ public final class Config {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void verifyAndFix() {
|
private void verifyAndFix() {
|
||||||
if (this.language == null || this.language.isEmpty())
|
if (this.language == null || this.language.isEmpty()) {
|
||||||
|
SkinRestorer.LOGGER.warn("Language config is null or empty, defaulting to 'en_us'");
|
||||||
this.language = "en_us";
|
this.language = "en_us";
|
||||||
|
}
|
||||||
|
|
||||||
if (this.firstJoinSkinProvider == null)
|
if (this.firstJoinSkinProvider == null) {
|
||||||
|
SkinRestorer.LOGGER.warn("FirstJoinSkinProvider config is null, defaulting to MOJANG");
|
||||||
this.firstJoinSkinProvider = FirstJoinSkinProvider.MOJANG;
|
this.firstJoinSkinProvider = FirstJoinSkinProvider.MOJANG;
|
||||||
|
}
|
||||||
|
|
||||||
if (this.proxy == null)
|
if (this.proxy == null) {
|
||||||
|
SkinRestorer.LOGGER.warn("Proxy config is null, defaulting to an empty string");
|
||||||
this.proxy = "";
|
this.proxy = "";
|
||||||
|
}
|
||||||
|
|
||||||
if (this.requestTimeout <= 0)
|
if (!this.proxy.isEmpty()) {
|
||||||
|
try {
|
||||||
|
this.parsedProxy = Proxy.parse(this.proxy);
|
||||||
|
} catch (Exception e) {
|
||||||
|
SkinRestorer.LOGGER.warn("Could not parse proxy config", e);
|
||||||
|
this.parsedProxy = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.requestTimeout <= 0) {
|
||||||
|
SkinRestorer.LOGGER.warn("Request timeout config is less than or equal to 0, defaulting to 10");
|
||||||
this.requestTimeout = 10;
|
this.requestTimeout = 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.providers == null) {
|
||||||
|
SkinRestorer.LOGGER.warn("Providers config is null, using default");
|
||||||
|
this.providers = ProvidersConfig.DEFAULT;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.providers.isValid())
|
||||||
|
this.providers.fix();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,65 @@
|
|||||||
|
package net.lionarius.skinrestorer.config;
|
||||||
|
|
||||||
|
import net.lionarius.skinrestorer.SkinRestorer;
|
||||||
|
import net.lionarius.skinrestorer.skin.provider.ElyBySkinProvider;
|
||||||
|
import net.lionarius.skinrestorer.skin.provider.MineskinSkinProvider;
|
||||||
|
import net.lionarius.skinrestorer.skin.provider.MojangSkinProvider;
|
||||||
|
|
||||||
|
public final class ProvidersConfig {
|
||||||
|
public static final ProvidersConfig DEFAULT = new ProvidersConfig(
|
||||||
|
new BuiltInProviderConfig(true, MojangSkinProvider.PROVIDER_NAME, new CacheConfig(true, 60)),
|
||||||
|
new BuiltInProviderConfig(true, ElyBySkinProvider.PROVIDER_NAME, new CacheConfig(true, 60)),
|
||||||
|
new BuiltInProviderConfig(true, MineskinSkinProvider.PROVIDER_NAME, new CacheConfig(true, 300))
|
||||||
|
);
|
||||||
|
|
||||||
|
private BuiltInProviderConfig mojang;
|
||||||
|
private BuiltInProviderConfig ely_by;
|
||||||
|
private BuiltInProviderConfig mineskin;
|
||||||
|
|
||||||
|
public ProvidersConfig(BuiltInProviderConfig mojang, BuiltInProviderConfig ely_by, BuiltInProviderConfig mineskin) {
|
||||||
|
this.mojang = mojang;
|
||||||
|
this.ely_by = ely_by;
|
||||||
|
this.mineskin = mineskin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isValid() {
|
||||||
|
if (this == ProvidersConfig.DEFAULT)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return this.mojang == null || !this.mojang.isValid()
|
||||||
|
|| this.ely_by == null || !this.ely_by.isValid()
|
||||||
|
|| this.mineskin == null || !this.mineskin.isValid();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void fix() {
|
||||||
|
if (this == ProvidersConfig.DEFAULT)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (this.mojang == null || !this.mojang.isValid()) {
|
||||||
|
SkinRestorer.LOGGER.warn("Mojang provider config is invalid, using default");
|
||||||
|
this.mojang = ProvidersConfig.DEFAULT.mojang();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.ely_by == null || !this.ely_by.isValid()) {
|
||||||
|
SkinRestorer.LOGGER.warn("Ely.By provider config is invalid, using default");
|
||||||
|
this.ely_by = ProvidersConfig.DEFAULT.ely_by();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.mineskin == null || !this.mineskin.isValid()) {
|
||||||
|
SkinRestorer.LOGGER.warn("Mineskin provider config is invalid, using default");
|
||||||
|
this.mineskin = ProvidersConfig.DEFAULT.mineskin();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public BuiltInProviderConfig mojang() {
|
||||||
|
return this.mojang;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BuiltInProviderConfig ely_by() {
|
||||||
|
return this.ely_by;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BuiltInProviderConfig mineskin() {
|
||||||
|
return this.mineskin;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package net.lionarius.skinrestorer.config;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public record Proxy(@NotNull String host, int port) {
|
||||||
|
|
||||||
|
public static Proxy parse(@NotNull String proxy) {
|
||||||
|
var colonIndex = proxy.lastIndexOf(':');
|
||||||
|
if (colonIndex == -1)
|
||||||
|
throw new IllegalArgumentException("no port in hostname");
|
||||||
|
|
||||||
|
var port = Integer.parseInt(proxy.substring(colonIndex + 1));
|
||||||
|
|
||||||
|
if (port < 0 || port > 0xFFFF)
|
||||||
|
throw new IllegalArgumentException("port out of range: " + port);
|
||||||
|
|
||||||
|
var host = proxy.substring(0, colonIndex);
|
||||||
|
|
||||||
|
return new Proxy(host, port);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -24,51 +24,65 @@ public abstract class ServerLoginPacketListenerImplMixin {
|
|||||||
private GameProfile authenticatedProfile;
|
private GameProfile authenticatedProfile;
|
||||||
|
|
||||||
@Unique
|
@Unique
|
||||||
private CompletableFuture<Void> skinrestorer_pendingSkin;
|
private CompletableFuture<Void> skinrestorer$pendingSkin;
|
||||||
|
|
||||||
@Inject(method = "verifyLoginAndFinishConnectionSetup", at = @At(value = "INVOKE",
|
@Inject(method = "verifyLoginAndFinishConnectionSetup", at = @At(value = "INVOKE",
|
||||||
target = "Lnet/minecraft/server/players/PlayerList;canPlayerLogin(Ljava/net/SocketAddress;Lcom/mojang/authlib/GameProfile;)Lnet/minecraft/network/chat/Component;"),
|
target = "Lnet/minecraft/server/players/PlayerList;canPlayerLogin(Ljava/net/SocketAddress;Lcom/mojang/authlib/GameProfile;)Lnet/minecraft/network/chat/Component;"),
|
||||||
cancellable = true)
|
cancellable = true)
|
||||||
public void waitForSkin(CallbackInfo ci) {
|
public void waitForSkin(CallbackInfo ci) {
|
||||||
if (skinrestorer_pendingSkin == null) {
|
if (skinrestorer$pendingSkin == null) {
|
||||||
skinrestorer_pendingSkin = CompletableFuture.supplyAsync(() -> {
|
skinrestorer$pendingSkin = CompletableFuture.supplyAsync(() -> {
|
||||||
assert authenticatedProfile != null;
|
final var profile = authenticatedProfile;
|
||||||
var originalSkin = PlayerUtils.getPlayerSkin(authenticatedProfile);
|
|
||||||
|
|
||||||
if (SkinRestorer.getSkinStorage().hasSavedSkin(authenticatedProfile.getId())) {
|
assert profile != null;
|
||||||
|
var originalSkin = PlayerUtils.getPlayerSkin(profile);
|
||||||
|
|
||||||
|
if (SkinRestorer.getSkinStorage().hasSavedSkin(profile.getId())) {
|
||||||
if (originalSkin != null) { // update to the latest official skin
|
if (originalSkin != null) { // update to the latest official skin
|
||||||
var value = SkinRestorer.getSkinStorage().getSkin(authenticatedProfile.getId());
|
var value = SkinRestorer.getSkinStorage().getSkin(profile.getId());
|
||||||
SkinRestorer.getSkinStorage().setSkin(authenticatedProfile.getId(), value.setOriginalValue(originalSkin));
|
SkinRestorer.getSkinStorage().setSkin(profile.getId(), value.setOriginalValue(originalSkin));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (SkinRestorer.getConfig().refreshSkinOnJoin()) {
|
||||||
|
var currentSkin = SkinRestorer.getSkinStorage().getSkin(profile.getId());
|
||||||
|
var context = currentSkin.toProviderContext();
|
||||||
|
|
||||||
|
skinrestorer$fetchSkin(profile, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (originalSkin == null && SkinRestorer.getConfig().fetchSkinOnFirstJoin()) {
|
if (originalSkin == null && SkinRestorer.getConfig().fetchSkinOnFirstJoin()) {
|
||||||
SkinRestorer.LOGGER.debug("Fetching {}'s skin", authenticatedProfile.getName());
|
|
||||||
|
|
||||||
var context = new SkinProviderContext(
|
var context = new SkinProviderContext(
|
||||||
SkinRestorer.getConfig().getFirstJoinSkinProvider().getName(),
|
SkinRestorer.getConfig().firstJoinSkinProvider().getName(),
|
||||||
authenticatedProfile.getName(),
|
profile.getName(),
|
||||||
null
|
null
|
||||||
);
|
);
|
||||||
var result = SkinRestorer.getProvider(context.name()).map(
|
skinrestorer$fetchSkin(profile, context);
|
||||||
provider -> provider.getSkin(context.argument(), context.variant())
|
|
||||||
).orElse(Result.ofNullable(null));
|
|
||||||
|
|
||||||
if (!result.isError()) {
|
|
||||||
var value = SkinValue.fromProviderContextWithValue(context, result.getSuccessValue().orElse(null));
|
|
||||||
SkinRestorer.getSkinStorage().setSkin(authenticatedProfile.getId(), value);
|
|
||||||
} else {
|
|
||||||
SkinRestorer.LOGGER.warn("failed to fetch skin on first join", result.getErrorValue());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!skinrestorer_pendingSkin.isDone())
|
if (!skinrestorer$pendingSkin.isDone())
|
||||||
ci.cancel();
|
ci.cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Unique
|
||||||
|
private static void skinrestorer$fetchSkin(GameProfile profile, SkinProviderContext context) {
|
||||||
|
SkinRestorer.LOGGER.debug("fetching {}'s skin", profile.getName());
|
||||||
|
|
||||||
|
var result = SkinRestorer.getProvider(context.name()).map(
|
||||||
|
provider -> provider.fetchSkin(context.argument(), context.variant())
|
||||||
|
).orElseGet(() -> Result.error(new IllegalArgumentException("skin provider is not registered: " + context.name())));
|
||||||
|
|
||||||
|
if (!result.isError()) {
|
||||||
|
var value = SkinValue.fromProviderContextWithValue(context, result.getSuccessValue().orElse(null));
|
||||||
|
SkinRestorer.getSkinStorage().setSkin(profile.getId(), value);
|
||||||
|
} else {
|
||||||
|
SkinRestorer.LOGGER.warn("failed to fetch skin", result.getErrorValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import org.spongepowered.asm.mixin.gen.Invoker;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@Mixin(targets = "net.minecraft.server.level.ChunkMap$TrackedEntity")
|
@Mixin(targets = "net.minecraft.server.level.ChunkMap$TrackedEntity")
|
||||||
public interface TrackedEntityMixin {
|
public interface TrackedEntityAccessorInvoker {
|
||||||
|
|
||||||
@Accessor
|
@Accessor
|
||||||
Set<ServerPlayerConnection> getSeenBy();
|
Set<ServerPlayerConnection> getSeenBy();
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package net.lionarius.skinrestorer.platform;
|
||||||
|
|
||||||
|
import net.lionarius.skinrestorer.SkinRestorer;
|
||||||
|
import net.lionarius.skinrestorer.platform.services.PlatformHelper;
|
||||||
|
|
||||||
|
import java.util.ServiceLoader;
|
||||||
|
|
||||||
|
public final class Services {
|
||||||
|
|
||||||
|
private Services() {}
|
||||||
|
|
||||||
|
public final static PlatformHelper PLATFORM = load(PlatformHelper.class);
|
||||||
|
|
||||||
|
private static <T> T load(Class<T> clazz) {
|
||||||
|
final T loadedService = ServiceLoader.load(clazz)
|
||||||
|
.findFirst()
|
||||||
|
.orElseThrow(() -> new NullPointerException("Failed to load service for " + clazz.getName()));
|
||||||
|
SkinRestorer.LOGGER.debug("Loaded {} for service {}", loadedService, clazz);
|
||||||
|
return loadedService;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package net.lionarius.skinrestorer.platform.services;
|
||||||
|
|
||||||
|
import java.nio.file.Path;
|
||||||
|
|
||||||
|
public interface PlatformHelper {
|
||||||
|
|
||||||
|
String getPlatformName();
|
||||||
|
|
||||||
|
boolean isModLoaded(String modId);
|
||||||
|
|
||||||
|
Path getConfigDirectory();
|
||||||
|
}
|
||||||
@@ -1,32 +1,59 @@
|
|||||||
package net.lionarius.skinrestorer.skin.provider;
|
package net.lionarius.skinrestorer.skin.provider;
|
||||||
|
|
||||||
import com.google.gson.JsonObject;
|
import com.google.common.cache.CacheBuilder;
|
||||||
|
import com.google.common.cache.CacheLoader;
|
||||||
|
import com.google.common.cache.LoadingCache;
|
||||||
|
import com.google.common.util.concurrent.UncheckedExecutionException;
|
||||||
|
import com.mojang.authlib.GameProfile;
|
||||||
import com.mojang.authlib.properties.Property;
|
import com.mojang.authlib.properties.Property;
|
||||||
|
import com.mojang.authlib.yggdrasil.response.MinecraftProfilePropertiesResponse;
|
||||||
|
import net.lionarius.skinrestorer.SkinRestorer;
|
||||||
import net.lionarius.skinrestorer.skin.SkinVariant;
|
import net.lionarius.skinrestorer.skin.SkinVariant;
|
||||||
import net.lionarius.skinrestorer.util.JsonUtils;
|
import net.lionarius.skinrestorer.util.JsonUtils;
|
||||||
import net.lionarius.skinrestorer.util.PlayerUtils;
|
import net.lionarius.skinrestorer.util.PlayerUtils;
|
||||||
import net.lionarius.skinrestorer.util.Result;
|
import net.lionarius.skinrestorer.util.Result;
|
||||||
import net.lionarius.skinrestorer.util.WebUtils;
|
import net.lionarius.skinrestorer.util.WebUtils;
|
||||||
|
import net.minecraft.util.StringUtil;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.net.http.HttpRequest;
|
import java.net.http.HttpRequest;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public final class ElyBySkinProvider implements SkinProvider {
|
public final class ElyBySkinProvider implements SkinProvider {
|
||||||
|
|
||||||
public static final String PROVIDER_NAME = "ely.by";
|
public static final String PROVIDER_NAME = "ely.by";
|
||||||
|
|
||||||
private static final URI API_URI;
|
private static final URI API_URI;
|
||||||
|
|
||||||
|
private static LoadingCache<String, Optional<Property>> SKIN_CACHE;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
try {
|
try {
|
||||||
API_URI = new URI("http://skinsystem.ely.by/");
|
API_URI = new URI("http://skinsystem.ely.by");
|
||||||
} catch (URISyntaxException e) {
|
} catch (URISyntaxException e) {
|
||||||
throw new IllegalArgumentException(e);
|
throw new IllegalArgumentException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void createCache() {
|
||||||
|
var config = SkinRestorer.getConfig().providersConfig().ely_by();
|
||||||
|
var time = config.cache().enabled() ? config.cache().duration() : 0;
|
||||||
|
|
||||||
|
SKIN_CACHE = CacheBuilder.newBuilder()
|
||||||
|
.expireAfterWrite(time, TimeUnit.SECONDS)
|
||||||
|
.build(new CacheLoader<>() {
|
||||||
|
@Override
|
||||||
|
public @NotNull Optional<Property> load(@NotNull String key) throws Exception {
|
||||||
|
return ElyBySkinProvider.loadSkin(key);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getArgumentName() {
|
public String getArgumentName() {
|
||||||
return "username";
|
return "username";
|
||||||
@@ -38,23 +65,32 @@ public final class ElyBySkinProvider implements SkinProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Result<Optional<Property>, Exception> getSkin(String username, SkinVariant variant) {
|
public Result<Optional<Property>, Exception> fetchSkin(String username, SkinVariant variant) {
|
||||||
try {
|
try {
|
||||||
var profile = ElyBySkinProvider.getElyByProfile(username);
|
if (!StringUtil.isValidPlayerName(username))
|
||||||
|
throw new IllegalArgumentException("invalid username");
|
||||||
|
|
||||||
var properties = profile.getAsJsonArray("properties");
|
var usernameLowerCase = username.toLowerCase(Locale.ROOT);
|
||||||
var textures = PlayerUtils.findTexturesProperty(properties);
|
|
||||||
|
|
||||||
return Result.ofNullable(textures);
|
return Result.success(SKIN_CACHE.get(usernameLowerCase));
|
||||||
|
} catch (UncheckedExecutionException e) {
|
||||||
|
return Result.error((Exception) e.getCause());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return Result.error(e);
|
return Result.error(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static JsonObject getElyByProfile(String username) throws IOException {
|
private static Optional<Property> loadSkin(String username) throws Exception {
|
||||||
|
var profile = ElyBySkinProvider.getElyByProfile(username);
|
||||||
|
var textures = PlayerUtils.getPlayerSkin(profile);
|
||||||
|
|
||||||
|
return Optional.ofNullable(textures);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static GameProfile getElyByProfile(String username) throws IOException {
|
||||||
var request = HttpRequest.newBuilder()
|
var request = HttpRequest.newBuilder()
|
||||||
.uri(ElyBySkinProvider.API_URI
|
.uri(ElyBySkinProvider.API_URI
|
||||||
.resolve("textures/signed/")
|
.resolve("/textures/signed/")
|
||||||
.resolve(username + "?unsigned=false")
|
.resolve(username + "?unsigned=false")
|
||||||
)
|
)
|
||||||
.GET()
|
.GET()
|
||||||
@@ -66,6 +102,6 @@ public final class ElyBySkinProvider implements SkinProvider {
|
|||||||
if (response.statusCode() != 200)
|
if (response.statusCode() != 200)
|
||||||
throw new IllegalArgumentException("no profile with name " + username);
|
throw new IllegalArgumentException("no profile with name " + username);
|
||||||
|
|
||||||
return JsonUtils.parseJson(response.body());
|
return JsonUtils.fromJson(response.body(), MinecraftProfilePropertiesResponse.class).toProfile();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,11 +21,11 @@ public final class EmptySkinProvider implements SkinProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Result<Optional<Property>, Exception> getSkin(String argument, SkinVariant variant) {
|
public Result<Optional<Property>, Exception> fetchSkin(String argument, SkinVariant variant) {
|
||||||
return this.getSkin();
|
return this.fetchSkin();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Result<Optional<Property>, Exception> getSkin() {
|
public Result<Optional<Property>, Exception> fetchSkin() {
|
||||||
return Result.ofNullable(null);
|
return Result.ofNullable(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,26 @@
|
|||||||
package net.lionarius.skinrestorer.skin.provider;
|
package net.lionarius.skinrestorer.skin.provider;
|
||||||
|
|
||||||
|
import com.google.common.cache.CacheBuilder;
|
||||||
|
import com.google.common.cache.CacheLoader;
|
||||||
|
import com.google.common.cache.LoadingCache;
|
||||||
|
import com.google.common.util.concurrent.UncheckedExecutionException;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.mojang.authlib.properties.Property;
|
import com.mojang.authlib.properties.Property;
|
||||||
|
import it.unimi.dsi.fastutil.Pair;
|
||||||
|
import net.lionarius.skinrestorer.SkinRestorer;
|
||||||
import net.lionarius.skinrestorer.skin.SkinVariant;
|
import net.lionarius.skinrestorer.skin.SkinVariant;
|
||||||
import net.lionarius.skinrestorer.util.JsonUtils;
|
import net.lionarius.skinrestorer.util.JsonUtils;
|
||||||
import net.lionarius.skinrestorer.util.PlayerUtils;
|
import net.lionarius.skinrestorer.util.PlayerUtils;
|
||||||
import net.lionarius.skinrestorer.util.Result;
|
import net.lionarius.skinrestorer.util.Result;
|
||||||
import net.lionarius.skinrestorer.util.WebUtils;
|
import net.lionarius.skinrestorer.util.WebUtils;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.net.http.HttpRequest;
|
import java.net.http.HttpRequest;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public final class MineskinSkinProvider implements SkinProvider {
|
public final class MineskinSkinProvider implements SkinProvider {
|
||||||
|
|
||||||
@@ -20,14 +28,30 @@ public final class MineskinSkinProvider implements SkinProvider {
|
|||||||
|
|
||||||
private static final URI API_URI;
|
private static final URI API_URI;
|
||||||
|
|
||||||
|
private static LoadingCache<Pair<URI, SkinVariant>, Optional<Property>> SKIN_CACHE;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
try {
|
try {
|
||||||
API_URI = new URI("https://api.mineskin.org/");
|
API_URI = new URI("https://api.mineskin.org");
|
||||||
} catch (URISyntaxException e) {
|
} catch (URISyntaxException e) {
|
||||||
throw new IllegalArgumentException(e);
|
throw new IllegalArgumentException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void createCache() {
|
||||||
|
var config = SkinRestorer.getConfig().providersConfig().mineskin();
|
||||||
|
var time = config.cache().enabled() ? config.cache().duration() : 0;
|
||||||
|
|
||||||
|
SKIN_CACHE = CacheBuilder.newBuilder()
|
||||||
|
.expireAfterWrite(time, TimeUnit.SECONDS)
|
||||||
|
.build(new CacheLoader<>() {
|
||||||
|
@Override
|
||||||
|
public @NotNull Optional<Property> load(@NotNull Pair<URI, SkinVariant> key) throws Exception {
|
||||||
|
return MineskinSkinProvider.loadSkin(key.first(), key.second());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getArgumentName() {
|
public String getArgumentName() {
|
||||||
return "url";
|
return "url";
|
||||||
@@ -39,23 +63,32 @@ public final class MineskinSkinProvider implements SkinProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Result<Optional<Property>, Exception> getSkin(String url, SkinVariant variant) {
|
public Result<Optional<Property>, Exception> fetchSkin(String url, SkinVariant variant) {
|
||||||
try {
|
try {
|
||||||
var result = MineskinSkinProvider.uploadToMineskin(url, variant);
|
var uri = new URI(url);
|
||||||
var texture = result.getAsJsonObject("data").getAsJsonObject("texture");
|
|
||||||
|
|
||||||
return Result.ofNullable(new Property(PlayerUtils.TEXTURES_KEY, texture.get("value").getAsString(), texture.get("signature").getAsString()));
|
return Result.success(SKIN_CACHE.get(Pair.of(uri, variant)));
|
||||||
|
} catch (UncheckedExecutionException e) {
|
||||||
|
return Result.error((Exception) e.getCause());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return Result.error(e);
|
return Result.error(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static JsonObject uploadToMineskin(String url, SkinVariant variant) throws IOException {
|
private static Optional<Property> loadSkin(URI uri, SkinVariant variant) throws Exception {
|
||||||
|
var result = MineskinSkinProvider.uploadToMineskin(uri, variant);
|
||||||
|
var texture = result.getAsJsonObject("data").getAsJsonObject("texture");
|
||||||
|
var textures = new Property(PlayerUtils.TEXTURES_KEY, texture.get("value").getAsString(), texture.get("signature").getAsString());
|
||||||
|
|
||||||
|
return Optional.of(textures);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static JsonObject uploadToMineskin(URI url, SkinVariant variant) throws IOException {
|
||||||
var body = ("{\"variant\":\"%s\",\"name\":\"%s\",\"visibility\":%d,\"url\":\"%s\"}")
|
var body = ("{\"variant\":\"%s\",\"name\":\"%s\",\"visibility\":%d,\"url\":\"%s\"}")
|
||||||
.formatted(variant.toString(), "none", 0, url);
|
.formatted(variant.toString(), "none", 0, url);
|
||||||
|
|
||||||
var request = HttpRequest.newBuilder()
|
var request = HttpRequest.newBuilder()
|
||||||
.uri(MineskinSkinProvider.API_URI.resolve("generate/url"))
|
.uri(MineskinSkinProvider.API_URI.resolve("/generate/url"))
|
||||||
.POST(HttpRequest.BodyPublishers.ofString(body))
|
.POST(HttpRequest.BodyPublishers.ofString(body))
|
||||||
.header("Content-Type", "application/json")
|
.header("Content-Type", "application/json")
|
||||||
.build();
|
.build();
|
||||||
|
|||||||
@@ -1,19 +1,30 @@
|
|||||||
package net.lionarius.skinrestorer.skin.provider;
|
package net.lionarius.skinrestorer.skin.provider;
|
||||||
|
|
||||||
import com.google.gson.JsonObject;
|
import com.google.common.cache.CacheBuilder;
|
||||||
|
import com.google.common.cache.CacheLoader;
|
||||||
|
import com.google.common.cache.LoadingCache;
|
||||||
|
import com.google.common.util.concurrent.UncheckedExecutionException;
|
||||||
import com.mojang.authlib.GameProfile;
|
import com.mojang.authlib.GameProfile;
|
||||||
import com.mojang.authlib.properties.Property;
|
import com.mojang.authlib.properties.Property;
|
||||||
|
import com.mojang.authlib.yggdrasil.response.MinecraftProfilePropertiesResponse;
|
||||||
|
import com.mojang.util.UndashedUuid;
|
||||||
|
import net.lionarius.skinrestorer.SkinRestorer;
|
||||||
import net.lionarius.skinrestorer.skin.SkinVariant;
|
import net.lionarius.skinrestorer.skin.SkinVariant;
|
||||||
import net.lionarius.skinrestorer.util.JsonUtils;
|
import net.lionarius.skinrestorer.util.JsonUtils;
|
||||||
import net.lionarius.skinrestorer.util.PlayerUtils;
|
import net.lionarius.skinrestorer.util.PlayerUtils;
|
||||||
import net.lionarius.skinrestorer.util.Result;
|
import net.lionarius.skinrestorer.util.Result;
|
||||||
import net.lionarius.skinrestorer.util.WebUtils;
|
import net.lionarius.skinrestorer.util.WebUtils;
|
||||||
|
import net.minecraft.server.players.GameProfileCache;
|
||||||
|
import net.minecraft.util.StringUtil;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.net.http.HttpRequest;
|
import java.net.http.HttpRequest;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public final class MojangSkinProvider implements SkinProvider {
|
public final class MojangSkinProvider implements SkinProvider {
|
||||||
|
|
||||||
@@ -22,13 +33,45 @@ public final class MojangSkinProvider implements SkinProvider {
|
|||||||
private static final URI API_URI;
|
private static final URI API_URI;
|
||||||
private static final URI SESSION_SERVER_URI;
|
private static final URI SESSION_SERVER_URI;
|
||||||
|
|
||||||
|
public static final String PROFILE_CACHE_FILENAME = "mojang_profile_cache.json";
|
||||||
|
private static final GameProfileCache PROFILE_CACHE;
|
||||||
|
|
||||||
|
private static LoadingCache<UUID, Optional<Property>> SKIN_CACHE;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
try {
|
try {
|
||||||
API_URI = new URI("https://api.mojang.com/");
|
API_URI = new URI("https://api.mojang.com");
|
||||||
SESSION_SERVER_URI = new URI("https://sessionserver.mojang.com/");
|
SESSION_SERVER_URI = new URI("https://sessionserver.mojang.com");
|
||||||
} catch (URISyntaxException e) {
|
} catch (URISyntaxException e) {
|
||||||
throw new IllegalArgumentException(e);
|
throw new IllegalArgumentException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PROFILE_CACHE = new GameProfileCache((names, callback) -> {
|
||||||
|
for (var name : names) {
|
||||||
|
try {
|
||||||
|
var profile = MojangSkinProvider.getProfile(name);
|
||||||
|
callback.onProfileLookupSucceeded(profile);
|
||||||
|
} catch (IOException e) {
|
||||||
|
callback.onProfileLookupFailed(name, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, SkinRestorer.getConfigDir().resolve(PROFILE_CACHE_FILENAME).toFile());
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void createCache() {
|
||||||
|
var config = SkinRestorer.getConfig().providersConfig().mojang();
|
||||||
|
var time = config.cache().enabled() ? config.cache().duration() : 0;
|
||||||
|
|
||||||
|
SKIN_CACHE = CacheBuilder.newBuilder()
|
||||||
|
.expireAfterWrite(time, TimeUnit.SECONDS)
|
||||||
|
.build(new CacheLoader<>() {
|
||||||
|
@Override
|
||||||
|
public @NotNull Optional<Property> load(@NotNull UUID key) throws Exception {
|
||||||
|
return MojangSkinProvider.loadSkin(key);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SkinProviderContext skinProviderContextFromProfile(GameProfile gameProfile) {
|
public static SkinProviderContext skinProviderContextFromProfile(GameProfile gameProfile) {
|
||||||
@@ -46,24 +89,34 @@ public final class MojangSkinProvider implements SkinProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Result<Optional<Property>, Exception> getSkin(String username, SkinVariant variant) {
|
public Result<Optional<Property>, Exception> fetchSkin(String username, SkinVariant variant) {
|
||||||
try {
|
try {
|
||||||
var uuid = MojangSkinProvider.getUuid(username);
|
if (!StringUtil.isValidPlayerName(username))
|
||||||
var profile = MojangSkinProvider.getMojangProfile(uuid);
|
throw new IllegalArgumentException("invalid username");
|
||||||
|
|
||||||
var properties = profile.getAsJsonArray("properties");
|
var cachedProfile = MojangSkinProvider.PROFILE_CACHE.get(username);
|
||||||
var textures = PlayerUtils.findTexturesProperty(properties);
|
if (cachedProfile.isEmpty())
|
||||||
|
throw new IllegalArgumentException("no profile found for " + username);
|
||||||
|
|
||||||
return Result.ofNullable(textures);
|
return Result.success(SKIN_CACHE.get(cachedProfile.get().getId()));
|
||||||
|
} catch (UncheckedExecutionException e) {
|
||||||
|
return Result.error((Exception) e.getCause());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return Result.error(e);
|
return Result.error(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getUuid(final String name) throws IOException {
|
private static Optional<Property> loadSkin(UUID uuid) throws Exception {
|
||||||
|
var profile = MojangSkinProvider.getProfileWithProperties(uuid);
|
||||||
|
var textures = PlayerUtils.getPlayerSkin(profile);
|
||||||
|
|
||||||
|
return Optional.ofNullable(textures);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static GameProfile getProfile(final String name) throws IOException {
|
||||||
var request = HttpRequest.newBuilder()
|
var request = HttpRequest.newBuilder()
|
||||||
.uri(MojangSkinProvider.API_URI
|
.uri(MojangSkinProvider.API_URI
|
||||||
.resolve("users/profiles/minecraft/")
|
.resolve("/users/profiles/minecraft/")
|
||||||
.resolve(name)
|
.resolve(name)
|
||||||
)
|
)
|
||||||
.GET()
|
.GET()
|
||||||
@@ -75,18 +128,14 @@ public final class MojangSkinProvider implements SkinProvider {
|
|||||||
if (response.statusCode() != 200)
|
if (response.statusCode() != 200)
|
||||||
throw new IllegalArgumentException("no profile with name " + name);
|
throw new IllegalArgumentException("no profile with name " + name);
|
||||||
|
|
||||||
var profile = JsonUtils.parseJson(response.body());
|
return JsonUtils.fromJson(response.body(), GameProfile.class);
|
||||||
if (profile == null)
|
|
||||||
return null;
|
|
||||||
|
|
||||||
return profile.get("id").getAsString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static JsonObject getMojangProfile(String uuid) throws IOException {
|
private static GameProfile getProfileWithProperties(UUID uuid) throws IOException {
|
||||||
var request = HttpRequest.newBuilder()
|
var request = HttpRequest.newBuilder()
|
||||||
.uri(MojangSkinProvider.SESSION_SERVER_URI
|
.uri(MojangSkinProvider.SESSION_SERVER_URI
|
||||||
.resolve("session/minecraft/profile/")
|
.resolve("/session/minecraft/profile/")
|
||||||
.resolve(uuid + "?unsigned=false")
|
.resolve(UndashedUuid.toString(uuid) + "?unsigned=false")
|
||||||
)
|
)
|
||||||
.GET()
|
.GET()
|
||||||
.build();
|
.build();
|
||||||
@@ -97,6 +146,6 @@ public final class MojangSkinProvider implements SkinProvider {
|
|||||||
if (response.statusCode() != 200)
|
if (response.statusCode() != 200)
|
||||||
throw new IllegalArgumentException("no profile with uuid " + uuid);
|
throw new IllegalArgumentException("no profile with uuid " + uuid);
|
||||||
|
|
||||||
return JsonUtils.parseJson(response.body());
|
return JsonUtils.fromJson(response.body(), MinecraftProfilePropertiesResponse.class).toProfile();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,5 +16,5 @@ public interface SkinProvider {
|
|||||||
|
|
||||||
boolean hasVariantSupport();
|
boolean hasVariantSupport();
|
||||||
|
|
||||||
Result<Optional<Property>, Exception> getSkin(String argument, SkinVariant variant);
|
Result<Optional<Property>, Exception> fetchSkin(String argument, SkinVariant variant);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ public final class SkinProviderRegistry {
|
|||||||
|
|
||||||
public void register(@NotNull String name, @NotNull SkinProvider provider, boolean isPublic) {
|
public void register(@NotNull String name, @NotNull SkinProvider provider, boolean isPublic) {
|
||||||
if (this.registry.containsKey(name))
|
if (this.registry.containsKey(name))
|
||||||
throw new IllegalArgumentException("Skin provider with name " + name + " is already registered");
|
return;
|
||||||
|
|
||||||
this.registry.put(name, new Entry(provider, isPublic));
|
this.registry.put(name, new Entry(provider, isPublic));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ public final class Translation {
|
|||||||
public static final String COMMAND_SKIN_FAILED_KEY = "skinrestorer.command.skin.failed";
|
public static final String COMMAND_SKIN_FAILED_KEY = "skinrestorer.command.skin.failed";
|
||||||
public static final String COMMAND_SKIN_OK_KEY = "skinrestorer.command.skin.ok";
|
public static final String COMMAND_SKIN_OK_KEY = "skinrestorer.command.skin.ok";
|
||||||
public static final String COMMAND_SKIN_LOADING_KEY = "skinrestorer.command.skin.loading";
|
public static final String COMMAND_SKIN_LOADING_KEY = "skinrestorer.command.skin.loading";
|
||||||
|
public static final String COMMAND_SKIN_CONFIG_RELOADED_KEY = "skinrestorer.command.skin.config_reloaded";
|
||||||
|
|
||||||
private static Map<String, String> translations;
|
private static Map<String, String> translations;
|
||||||
private static final Map<String, String> fallback;
|
private static final Map<String, String> fallback;
|
||||||
@@ -46,11 +47,11 @@ public final class Translation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void reloadTranslations() {
|
public static void reloadTranslations() {
|
||||||
translations = Translation.loadTranslationMap(SkinRestorer.getConfig().getLanguage());
|
translations = Translation.loadTranslationMap(SkinRestorer.getConfig().language());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ImmutableMap<String, String> loadTranslationMap(String lang) {
|
private static ImmutableMap<String, String> loadTranslationMap(String lang) {
|
||||||
var json = FileUtils.readResource(SkinRestorer.resource(String.format("lang/%s.json", lang)));
|
var json = FileUtils.readResource(SkinRestorer.assetPath(String.format("lang/%s.json", lang)));
|
||||||
|
|
||||||
var type = new TypeToken<Map<String, String>>() {}.getType();
|
var type = new TypeToken<Map<String, String>>() {}.getType();
|
||||||
Map<String, String> map = null;
|
Map<String, String> map = null;
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package net.lionarius.skinrestorer.util;
|
|||||||
import net.lionarius.skinrestorer.SkinRestorer;
|
import net.lionarius.skinrestorer.SkinRestorer;
|
||||||
import net.lionarius.skinrestorer.config.Config;
|
import net.lionarius.skinrestorer.config.Config;
|
||||||
import net.lionarius.skinrestorer.skin.SkinIO;
|
import net.lionarius.skinrestorer.skin.SkinIO;
|
||||||
|
import net.lionarius.skinrestorer.skin.provider.MojangSkinProvider;
|
||||||
import net.lionarius.skinrestorer.translation.Translation;
|
import net.lionarius.skinrestorer.translation.Translation;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
@@ -17,24 +18,28 @@ public final class FileUtils {
|
|||||||
|
|
||||||
private FileUtils() {}
|
private FileUtils() {}
|
||||||
|
|
||||||
public static void tryMigrateOldSkinDirectory(Path newDirectory) {
|
public static void tryMigrateOldSkinDirectory(Path oldDirectory, Path newDirectory) {
|
||||||
try {
|
try {
|
||||||
var configDirectory = SkinRestorer.getConfigDir();
|
try (var stream = Files.list(oldDirectory)) {
|
||||||
try (var stream = Files.list(configDirectory)) {
|
|
||||||
var files = stream.filter(file -> {
|
var files = stream.filter(file -> {
|
||||||
var name = file.getFileName();
|
var name = file.getFileName().toString();
|
||||||
return Files.isRegularFile(file)
|
return Files.isRegularFile(file)
|
||||||
&& !name.startsWith(Translation.LEGACY_TRANSLATION_FILENAME)
|
&& !name.startsWith(Translation.LEGACY_TRANSLATION_FILENAME)
|
||||||
&& !name.startsWith(Config.CONFIG_FILENAME)
|
&& !name.startsWith(Config.CONFIG_FILENAME)
|
||||||
|
&& !name.startsWith(MojangSkinProvider.PROFILE_CACHE_FILENAME)
|
||||||
&& name.endsWith(SkinIO.FILE_EXTENSION);
|
&& name.endsWith(SkinIO.FILE_EXTENSION);
|
||||||
}).toList();
|
}).toList();
|
||||||
|
|
||||||
if (!files.isEmpty() && !Files.exists(newDirectory))
|
if (!files.isEmpty() && !Files.exists(newDirectory))
|
||||||
Files.createDirectories(newDirectory);
|
Files.createDirectories(newDirectory);
|
||||||
|
|
||||||
|
for (var file : files) {
|
||||||
for (var file : files)
|
var newFile = newDirectory.resolve(file.getFileName());
|
||||||
Files.move(file, newDirectory.resolve(file.getFileName()), StandardCopyOption.REPLACE_EXISTING);
|
if (!Files.exists(newFile))
|
||||||
|
Files.move(file, newFile, StandardCopyOption.ATOMIC_MOVE);
|
||||||
|
else
|
||||||
|
Files.delete(file);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
SkinRestorer.LOGGER.error("could not migrate skin directory", e);
|
SkinRestorer.LOGGER.error("could not migrate skin directory", e);
|
||||||
|
|||||||
@@ -1,16 +1,28 @@
|
|||||||
package net.lionarius.skinrestorer.util;
|
package net.lionarius.skinrestorer.util;
|
||||||
|
|
||||||
import com.google.gson.*;
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.GsonBuilder;
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import com.mojang.authlib.GameProfile;
|
||||||
import com.mojang.authlib.properties.Property;
|
import com.mojang.authlib.properties.Property;
|
||||||
|
import com.mojang.authlib.properties.PropertyMap;
|
||||||
|
import com.mojang.util.UUIDTypeAdapter;
|
||||||
import net.lionarius.skinrestorer.SkinRestorer;
|
import net.lionarius.skinrestorer.SkinRestorer;
|
||||||
|
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Base64;
|
import java.util.Base64;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public final class JsonUtils {
|
public final class JsonUtils {
|
||||||
|
|
||||||
private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
|
private static final Gson GSON = new GsonBuilder()
|
||||||
|
.registerTypeAdapter(UUID.class, new UUIDTypeAdapter())
|
||||||
|
.registerTypeAdapter(PropertyMap.class, new PropertyMap.Serializer())
|
||||||
|
.registerTypeAdapter(GameProfile.class, new GameProfile.Serializer())
|
||||||
|
.setPrettyPrinting()
|
||||||
|
.create();
|
||||||
|
|
||||||
private JsonUtils() {}
|
private JsonUtils() {}
|
||||||
|
|
||||||
@@ -31,7 +43,7 @@ public final class JsonUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static JsonObject parseJson(String json) {
|
public static JsonObject parseJson(String json) {
|
||||||
return JsonParser.parseString(json).getAsJsonObject();
|
return GSON.fromJson(json, JsonObject.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static JsonObject skinPropertyToJson(Property property) {
|
public static JsonObject skinPropertyToJson(Property property) {
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
package net.lionarius.skinrestorer.util;
|
package net.lionarius.skinrestorer.util;
|
||||||
|
|
||||||
import com.google.gson.JsonArray;
|
import com.google.common.collect.Iterables;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.mojang.authlib.GameProfile;
|
import com.mojang.authlib.GameProfile;
|
||||||
import com.mojang.authlib.properties.Property;
|
import com.mojang.authlib.properties.Property;
|
||||||
|
import com.mojang.authlib.yggdrasil.response.MinecraftProfilePropertiesResponse;
|
||||||
import net.lionarius.skinrestorer.mixin.ChunkMapAccessor;
|
import net.lionarius.skinrestorer.mixin.ChunkMapAccessor;
|
||||||
import net.lionarius.skinrestorer.mixin.TrackedEntityMixin;
|
import net.lionarius.skinrestorer.mixin.TrackedEntityAccessorInvoker;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.network.protocol.game.*;
|
import net.minecraft.network.protocol.game.*;
|
||||||
import net.minecraft.server.level.ChunkMap;
|
import net.minecraft.server.level.ChunkMap;
|
||||||
@@ -49,14 +50,14 @@ public final class PlayerUtils {
|
|||||||
)
|
)
|
||||||
));
|
));
|
||||||
|
|
||||||
var trackedEntity = (TrackedEntityMixin) ((ChunkMapAccessor) chunkMap).getEntityMap().get(player.getId());
|
var trackedEntity = (TrackedEntityAccessorInvoker) ((ChunkMapAccessor) chunkMap).getEntityMap().get(player.getId());
|
||||||
if (trackedEntity != null) {
|
if (trackedEntity != null) {
|
||||||
var seenBy = Set.copyOf(trackedEntity.getSeenBy());
|
var seenBy = Set.copyOf(trackedEntity.getSeenBy());
|
||||||
for (var observerConnection : seenBy) {
|
for (var observerConnection : seenBy) {
|
||||||
var observer = observerConnection.getPlayer();
|
var observer = observerConnection.getPlayer();
|
||||||
trackedEntity.invokeRemovePlayer(observer);
|
trackedEntity.invokeRemovePlayer(observer);
|
||||||
|
|
||||||
var trackedObserverEntity = (TrackedEntityMixin) ((ChunkMapAccessor) chunkMap).getEntityMap().get(observer.getId());
|
var trackedObserverEntity = (TrackedEntityAccessorInvoker) ((ChunkMapAccessor) chunkMap).getEntityMap().get(observer.getId());
|
||||||
if (trackedObserverEntity != null) {
|
if (trackedObserverEntity != null) {
|
||||||
trackedObserverEntity.invokeRemovePlayer(player);
|
trackedObserverEntity.invokeRemovePlayer(player);
|
||||||
trackedObserverEntity.invokeUpdatePlayer(player);
|
trackedObserverEntity.invokeUpdatePlayer(player);
|
||||||
@@ -89,14 +90,14 @@ public final class PlayerUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void sendActivePlayerEffects(ServerPlayer player) {
|
private static void sendActivePlayerEffects(ServerPlayer player) {
|
||||||
for (var effect : player.getActiveEffects()) {
|
for (var effect : player.getActiveEffects()) {
|
||||||
player.connection.send(new ClientboundUpdateMobEffectPacket(player.getId(), effect));
|
player.connection.send(new ClientboundUpdateMobEffectPacket(player.getId(), effect));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Property getPlayerSkin(GameProfile profile) {
|
public static Property getPlayerSkin(GameProfile profile) {
|
||||||
return profile.getProperties().get(TEXTURES_KEY).stream().findFirst().orElse(null);
|
return Iterables.getFirst(profile.getProperties().get(TEXTURES_KEY), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void applyRestoredSkin(GameProfile profile, Property skin) {
|
public static void applyRestoredSkin(GameProfile profile, Property skin) {
|
||||||
@@ -106,7 +107,6 @@ public final class PlayerUtils {
|
|||||||
profile.getProperties().put(TEXTURES_KEY, skin);
|
profile.getProperties().put(TEXTURES_KEY, skin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static boolean areSkinPropertiesEquals(Property x, Property y) {
|
public static boolean areSkinPropertiesEquals(Property x, Property y) {
|
||||||
if (x == y)
|
if (x == y)
|
||||||
return true;
|
return true;
|
||||||
@@ -126,24 +126,9 @@ public final class PlayerUtils {
|
|||||||
return xJson.equals(yJson);
|
return xJson.equals(yJson);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Property findTexturesProperty(JsonArray properties) {
|
public static GameProfile toProfile(MinecraftProfilePropertiesResponse response) {
|
||||||
Property textures = null;
|
final GameProfile profile = new GameProfile(response.id(), response.name());
|
||||||
for (var property : properties) {
|
profile.getProperties().putAll(response.properties());
|
||||||
var propertyObject = property.getAsJsonObject();
|
return profile;
|
||||||
if (propertyObject == null)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
try {
|
|
||||||
textures = JsonUtils.fromJson(propertyObject, Property.class);
|
|
||||||
break;
|
|
||||||
} catch (Exception e) {
|
|
||||||
// ignored
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (textures == null)
|
|
||||||
throw new IllegalStateException("no textures in profile");
|
|
||||||
|
|
||||||
return textures;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,4 +17,8 @@ public final class StringUtils {
|
|||||||
|
|
||||||
return response.toString();
|
return response.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isValidPlayerName(String playerName) {
|
||||||
|
return playerName.length() <= 16 && playerName.chars().filter(i -> i <= 32 || i >= 127).findAny().isEmpty();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import java.net.http.HttpRequest;
|
|||||||
import java.net.http.HttpResponse;
|
import java.net.http.HttpResponse;
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.time.temporal.ChronoUnit;
|
import java.time.temporal.ChronoUnit;
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
public final class WebUtils {
|
public final class WebUtils {
|
||||||
|
|
||||||
@@ -18,36 +17,32 @@ public final class WebUtils {
|
|||||||
|
|
||||||
public static final String USER_AGENT;
|
public static final String USER_AGENT;
|
||||||
|
|
||||||
|
private static HttpClient HTTP_CLIENT = null;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
USER_AGENT = String.format("SkinRestorer/%d", System.currentTimeMillis() % 65535);
|
USER_AGENT = String.format("SkinRestorer/%d", System.currentTimeMillis() % 65535);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void recreateHttpClient() {
|
||||||
|
HTTP_CLIENT = WebUtils.buildClient();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static HttpClient buildClient() {
|
||||||
var builder = HttpClient.newBuilder();
|
var builder = HttpClient.newBuilder();
|
||||||
var proxy = SkinRestorer.getConfig().getProxy();
|
|
||||||
|
var proxy = SkinRestorer.getConfig().proxy();
|
||||||
|
proxy.ifPresent(value -> builder.proxy(ProxySelector.of(InetSocketAddress.createUnresolved(value.host(), value.port()))));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (proxy != null) {
|
builder.connectTimeout(Duration.of(SkinRestorer.getConfig().requestTimeout(), ChronoUnit.SECONDS));
|
||||||
var colonIndex = proxy.lastIndexOf(':');
|
|
||||||
if (colonIndex != -1) {
|
|
||||||
var host = proxy.substring(0, colonIndex);
|
|
||||||
var port = Integer.parseInt(proxy.substring(colonIndex + 1));
|
|
||||||
|
|
||||||
builder.proxy(ProxySelector.of(InetSocketAddress.createUnresolved(host, port)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
SkinRestorer.LOGGER.error("failed to parse proxy", e);
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
builder.connectTimeout(Duration.of(SkinRestorer.getConfig().getRequestTimeout(), ChronoUnit.SECONDS));
|
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
SkinRestorer.LOGGER.error("failed to set request timeout", e);
|
SkinRestorer.LOGGER.error("failed to set request timeout", e);
|
||||||
builder.connectTimeout(Duration.of(10, ChronoUnit.SECONDS));
|
builder.connectTimeout(Duration.of(10, ChronoUnit.SECONDS));
|
||||||
}
|
}
|
||||||
|
|
||||||
HTTP_CLIENT = builder.build();
|
return builder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final HttpClient HTTP_CLIENT;
|
|
||||||
|
|
||||||
public static HttpResponse<String> executeRequest(HttpRequest request) throws IOException {
|
public static HttpResponse<String> executeRequest(HttpRequest request) throws IOException {
|
||||||
try {
|
try {
|
||||||
var modifiedRequest = HttpRequest.newBuilder(request, (name, value) -> true)
|
var modifiedRequest = HttpRequest.newBuilder(request, (name, value) -> true)
|
||||||
@@ -67,30 +62,16 @@ public final class WebUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void throwOnClientErrors(HttpResponse<?> response) {
|
public static void throwOnClientErrors(HttpResponse<?> response) {
|
||||||
String message = null;
|
String message = switch (response.statusCode()) {
|
||||||
switch (response.statusCode()) {
|
case 400 -> "bad request";
|
||||||
case 400:
|
case 401 -> "unauthorized";
|
||||||
message = "bad request";
|
case 403 -> "forbidden";
|
||||||
break;
|
case 404 -> "not found";
|
||||||
case 401:
|
case 405 -> "method not allowed";
|
||||||
message = "unauthorized";
|
case 408 -> "request timeout";
|
||||||
break;
|
case 429 -> "too many requests";
|
||||||
case 403:
|
default -> null;
|
||||||
message = "forbidden";
|
};
|
||||||
break;
|
|
||||||
case 404:
|
|
||||||
message = "not found";
|
|
||||||
break;
|
|
||||||
case 405:
|
|
||||||
message = "method not allowed";
|
|
||||||
break;
|
|
||||||
case 408:
|
|
||||||
message = "request timeout";
|
|
||||||
break;
|
|
||||||
case 429:
|
|
||||||
message = "too many requests";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (message != null)
|
if (message != null)
|
||||||
throw new IllegalStateException(message);
|
throw new IllegalStateException(message);
|
||||||
|
|||||||
@@ -3,5 +3,6 @@
|
|||||||
"skinrestorer.command.skin.no_changes": "Žádné změny skinu",
|
"skinrestorer.command.skin.no_changes": "Žádné změny skinu",
|
||||||
"skinrestorer.command.skin.failed": "Nepodařilo se změnit skin: %s",
|
"skinrestorer.command.skin.failed": "Nepodařilo se změnit skin: %s",
|
||||||
"skinrestorer.command.skin.ok": "Skin změněn",
|
"skinrestorer.command.skin.ok": "Skin změněn",
|
||||||
"skinrestorer.command.skin.loading": "Načítání skinu..."
|
"skinrestorer.command.skin.loading": "Načítání skinu...",
|
||||||
|
"skinrestorer.command.skin.config_reloaded": "Konfigurace byla znovu načtena"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,5 +3,6 @@
|
|||||||
"skinrestorer.command.skin.no_changes": "Keine Skinänderungen",
|
"skinrestorer.command.skin.no_changes": "Keine Skinänderungen",
|
||||||
"skinrestorer.command.skin.failed": "Skin konnte nicht geändert werden: %s",
|
"skinrestorer.command.skin.failed": "Skin konnte nicht geändert werden: %s",
|
||||||
"skinrestorer.command.skin.ok": "Skin geändert",
|
"skinrestorer.command.skin.ok": "Skin geändert",
|
||||||
"skinrestorer.command.skin.loading": "Skin wird geladen..."
|
"skinrestorer.command.skin.loading": "Skin wird geladen...",
|
||||||
|
"skinrestorer.command.skin.config_reloaded": "Konfiguration wurde neu geladen"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,5 +3,6 @@
|
|||||||
"skinrestorer.command.skin.no_changes": "No skin changes",
|
"skinrestorer.command.skin.no_changes": "No skin changes",
|
||||||
"skinrestorer.command.skin.failed": "Failed to change skin: %s",
|
"skinrestorer.command.skin.failed": "Failed to change skin: %s",
|
||||||
"skinrestorer.command.skin.ok": "Skin changed",
|
"skinrestorer.command.skin.ok": "Skin changed",
|
||||||
"skinrestorer.command.skin.loading": "Loading skin..."
|
"skinrestorer.command.skin.loading": "Loading skin...",
|
||||||
|
"skinrestorer.command.skin.config_reloaded": "Config has been reloaded"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,5 +3,6 @@
|
|||||||
"skinrestorer.command.skin.no_changes": "No hay cambios de skin",
|
"skinrestorer.command.skin.no_changes": "No hay cambios de skin",
|
||||||
"skinrestorer.command.skin.failed": "Error al cambiar el skin: %s",
|
"skinrestorer.command.skin.failed": "Error al cambiar el skin: %s",
|
||||||
"skinrestorer.command.skin.ok": "Skin cambiado",
|
"skinrestorer.command.skin.ok": "Skin cambiado",
|
||||||
"skinrestorer.command.skin.loading": "Cargando skin..."
|
"skinrestorer.command.skin.loading": "Cargando skin...",
|
||||||
|
"skinrestorer.command.skin.config_reloaded": "La configuración se ha recargado"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,5 +3,6 @@
|
|||||||
"skinrestorer.command.skin.no_changes": "No hay cambios de skin",
|
"skinrestorer.command.skin.no_changes": "No hay cambios de skin",
|
||||||
"skinrestorer.command.skin.failed": "Error al cambiar el skin: %s",
|
"skinrestorer.command.skin.failed": "Error al cambiar el skin: %s",
|
||||||
"skinrestorer.command.skin.ok": "Skin cambiado",
|
"skinrestorer.command.skin.ok": "Skin cambiado",
|
||||||
"skinrestorer.command.skin.loading": "Cargando skin..."
|
"skinrestorer.command.skin.loading": "Cargando skin...",
|
||||||
|
"skinrestorer.command.skin.config_reloaded": "La configuración se ha recargado"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,5 +3,6 @@
|
|||||||
"skinrestorer.command.skin.no_changes": "No hay cambios de skin",
|
"skinrestorer.command.skin.no_changes": "No hay cambios de skin",
|
||||||
"skinrestorer.command.skin.failed": "Error al cambiar el skin: %s",
|
"skinrestorer.command.skin.failed": "Error al cambiar el skin: %s",
|
||||||
"skinrestorer.command.skin.ok": "Skin cambiado",
|
"skinrestorer.command.skin.ok": "Skin cambiado",
|
||||||
"skinrestorer.command.skin.loading": "Cargando skin..."
|
"skinrestorer.command.skin.loading": "Cargando skin...",
|
||||||
|
"skinrestorer.command.skin.config_reloaded": "La configuración se ha recargado"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,5 +3,6 @@
|
|||||||
"skinrestorer.command.skin.no_changes": "Walang pagbabago sa skin",
|
"skinrestorer.command.skin.no_changes": "Walang pagbabago sa skin",
|
||||||
"skinrestorer.command.skin.failed": "Nabigo sa pagbabago ng skin: %s",
|
"skinrestorer.command.skin.failed": "Nabigo sa pagbabago ng skin: %s",
|
||||||
"skinrestorer.command.skin.ok": "Nabago ang skin",
|
"skinrestorer.command.skin.ok": "Nabago ang skin",
|
||||||
"skinrestorer.command.skin.loading": "Naglo-load ng skin..."
|
"skinrestorer.command.skin.loading": "Naglo-load ng skin...",
|
||||||
|
"skinrestorer.command.skin.config_reloaded": "Na-reload ang config"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,5 +3,6 @@
|
|||||||
"skinrestorer.command.skin.no_changes": "Aucun changement de skin",
|
"skinrestorer.command.skin.no_changes": "Aucun changement de skin",
|
||||||
"skinrestorer.command.skin.failed": "Échec du changement de skin : %s",
|
"skinrestorer.command.skin.failed": "Échec du changement de skin : %s",
|
||||||
"skinrestorer.command.skin.ok": "Skin changé",
|
"skinrestorer.command.skin.ok": "Skin changé",
|
||||||
"skinrestorer.command.skin.loading": "Chargement du skin..."
|
"skinrestorer.command.skin.loading": "Chargement du skin...",
|
||||||
|
"skinrestorer.command.skin.config_reloaded": "La configuration a été rechargée"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,5 +3,6 @@
|
|||||||
"skinrestorer.command.skin.no_changes": "Aucun changement de skin",
|
"skinrestorer.command.skin.no_changes": "Aucun changement de skin",
|
||||||
"skinrestorer.command.skin.failed": "Échec du changement de skin : %s",
|
"skinrestorer.command.skin.failed": "Échec du changement de skin : %s",
|
||||||
"skinrestorer.command.skin.ok": "Skin changé",
|
"skinrestorer.command.skin.ok": "Skin changé",
|
||||||
"skinrestorer.command.skin.loading": "Chargement du skin..."
|
"skinrestorer.command.skin.loading": "Chargement du skin...",
|
||||||
|
"skinrestorer.command.skin.config_reloaded": "La configuration a été rechargée"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,5 +3,6 @@
|
|||||||
"skinrestorer.command.skin.no_changes": "कोई त्वचा परिवर्तन नहीं",
|
"skinrestorer.command.skin.no_changes": "कोई त्वचा परिवर्तन नहीं",
|
||||||
"skinrestorer.command.skin.failed": "त्वचा बदलने में विफल: %s",
|
"skinrestorer.command.skin.failed": "त्वचा बदलने में विफल: %s",
|
||||||
"skinrestorer.command.skin.ok": "त्वचा बदल दी गई",
|
"skinrestorer.command.skin.ok": "त्वचा बदल दी गई",
|
||||||
"skinrestorer.command.skin.loading": "त्वचा लोड हो रही है..."
|
"skinrestorer.command.skin.loading": "त्वचा लोड हो रही है...",
|
||||||
|
"skinrestorer.command.skin.config_reloaded": "कॉन्फ़िगरेशन फिर से लोड किया गया है"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,5 +3,6 @@
|
|||||||
"skinrestorer.command.skin.no_changes": "Nincsenek skin változások",
|
"skinrestorer.command.skin.no_changes": "Nincsenek skin változások",
|
||||||
"skinrestorer.command.skin.failed": "Skin változtatás sikertelen: %s",
|
"skinrestorer.command.skin.failed": "Skin változtatás sikertelen: %s",
|
||||||
"skinrestorer.command.skin.ok": "Skin megváltoztatva",
|
"skinrestorer.command.skin.ok": "Skin megváltoztatva",
|
||||||
"skinrestorer.command.skin.loading": "Skin betöltése..."
|
"skinrestorer.command.skin.loading": "Skin betöltése...",
|
||||||
|
"skinrestorer.command.skin.config_reloaded": "A konfiguráció újratöltve"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,5 +3,6 @@
|
|||||||
"skinrestorer.command.skin.no_changes": "Tidak ada perubahan skin",
|
"skinrestorer.command.skin.no_changes": "Tidak ada perubahan skin",
|
||||||
"skinrestorer.command.skin.failed": "Gagal mengubah skin: %s",
|
"skinrestorer.command.skin.failed": "Gagal mengubah skin: %s",
|
||||||
"skinrestorer.command.skin.ok": "Skin diubah",
|
"skinrestorer.command.skin.ok": "Skin diubah",
|
||||||
"skinrestorer.command.skin.loading": "Memuat skin..."
|
"skinrestorer.command.skin.loading": "Memuat skin...",
|
||||||
|
"skinrestorer.command.skin.config_reloaded": "Konfigurasi telah dimuat ulang"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,5 +3,6 @@
|
|||||||
"skinrestorer.command.skin.no_changes": "Nessuna modifica alla skin",
|
"skinrestorer.command.skin.no_changes": "Nessuna modifica alla skin",
|
||||||
"skinrestorer.command.skin.failed": "Impossibile cambiare la skin: %s",
|
"skinrestorer.command.skin.failed": "Impossibile cambiare la skin: %s",
|
||||||
"skinrestorer.command.skin.ok": "Skin cambiata",
|
"skinrestorer.command.skin.ok": "Skin cambiata",
|
||||||
"skinrestorer.command.skin.loading": "Caricamento della skin..."
|
"skinrestorer.command.skin.loading": "Caricamento della skin...",
|
||||||
|
"skinrestorer.command.skin.config_reloaded": "La configurazione è stata ricaricata"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,5 +3,6 @@
|
|||||||
"skinrestorer.command.skin.no_changes": "Brak zmian skina",
|
"skinrestorer.command.skin.no_changes": "Brak zmian skina",
|
||||||
"skinrestorer.command.skin.failed": "Nie udało się zmienić skina: %s",
|
"skinrestorer.command.skin.failed": "Nie udało się zmienić skina: %s",
|
||||||
"skinrestorer.command.skin.ok": "Skin zmieniony",
|
"skinrestorer.command.skin.ok": "Skin zmieniony",
|
||||||
"skinrestorer.command.skin.loading": "Ładowanie skina..."
|
"skinrestorer.command.skin.loading": "Ładowanie skina...",
|
||||||
|
"skinrestorer.command.skin.config_reloaded": "Konfiguracja została przeładowana"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,5 +3,6 @@
|
|||||||
"skinrestorer.command.skin.no_changes": "Nenhuma alteração de skin",
|
"skinrestorer.command.skin.no_changes": "Nenhuma alteração de skin",
|
||||||
"skinrestorer.command.skin.failed": "Falha ao alterar a skin: %s",
|
"skinrestorer.command.skin.failed": "Falha ao alterar a skin: %s",
|
||||||
"skinrestorer.command.skin.ok": "Skin alterada",
|
"skinrestorer.command.skin.ok": "Skin alterada",
|
||||||
"skinrestorer.command.skin.loading": "Carregando skin..."
|
"skinrestorer.command.skin.loading": "Carregando skin...",
|
||||||
|
"skinrestorer.command.skin.config_reloaded": "Configuração recarregada"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,5 +3,6 @@
|
|||||||
"skinrestorer.command.skin.no_changes": "Nenhuma alteração de skin",
|
"skinrestorer.command.skin.no_changes": "Nenhuma alteração de skin",
|
||||||
"skinrestorer.command.skin.failed": "Falha ao alterar a skin: %s",
|
"skinrestorer.command.skin.failed": "Falha ao alterar a skin: %s",
|
||||||
"skinrestorer.command.skin.ok": "Skin alterada",
|
"skinrestorer.command.skin.ok": "Skin alterada",
|
||||||
"skinrestorer.command.skin.loading": "Carregando skin..."
|
"skinrestorer.command.skin.loading": "Carregando skin...",
|
||||||
|
"skinrestorer.command.skin.config_reloaded": "Configuração recarregada"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,5 +3,6 @@
|
|||||||
"skinrestorer.command.skin.no_changes": "Изменений скина нет",
|
"skinrestorer.command.skin.no_changes": "Изменений скина нет",
|
||||||
"skinrestorer.command.skin.failed": "Не удалось изменить скин: %s",
|
"skinrestorer.command.skin.failed": "Не удалось изменить скин: %s",
|
||||||
"skinrestorer.command.skin.ok": "Скин изменён",
|
"skinrestorer.command.skin.ok": "Скин изменён",
|
||||||
"skinrestorer.command.skin.loading": "Загрузка скина..."
|
"skinrestorer.command.skin.loading": "Загрузка скина...",
|
||||||
|
"skinrestorer.command.skin.config_reloaded": "Конфигурация была перезагружена"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,5 +3,6 @@
|
|||||||
"skinrestorer.command.skin.no_changes": "Skin değişikliği yok",
|
"skinrestorer.command.skin.no_changes": "Skin değişikliği yok",
|
||||||
"skinrestorer.command.skin.failed": "Skin değiştirme başarısız: %s",
|
"skinrestorer.command.skin.failed": "Skin değiştirme başarısız: %s",
|
||||||
"skinrestorer.command.skin.ok": "Skin değiştirildi",
|
"skinrestorer.command.skin.ok": "Skin değiştirildi",
|
||||||
"skinrestorer.command.skin.loading": "Skin yükleniyor..."
|
"skinrestorer.command.skin.loading": "Skin yükleniyor...",
|
||||||
|
"skinrestorer.command.skin.config_reloaded": "Yapılandırma yeniden yüklendi"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,5 +3,6 @@
|
|||||||
"skinrestorer.command.skin.no_changes": "Змін скіна немає",
|
"skinrestorer.command.skin.no_changes": "Змін скіна немає",
|
||||||
"skinrestorer.command.skin.failed": "Не вдалося змінити скіна: %s",
|
"skinrestorer.command.skin.failed": "Не вдалося змінити скіна: %s",
|
||||||
"skinrestorer.command.skin.ok": "Скін змінено",
|
"skinrestorer.command.skin.ok": "Скін змінено",
|
||||||
"skinrestorer.command.skin.loading": "Завантаження скіна..."
|
"skinrestorer.command.skin.loading": "Завантаження скіна...",
|
||||||
|
"skinrestorer.command.skin.config_reloaded": "Конфігурацію перезавантажено"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,5 +3,6 @@
|
|||||||
"skinrestorer.command.skin.no_changes": "Không có thay đổi skin",
|
"skinrestorer.command.skin.no_changes": "Không có thay đổi skin",
|
||||||
"skinrestorer.command.skin.failed": "Thay đổi skin thất bại: %s",
|
"skinrestorer.command.skin.failed": "Thay đổi skin thất bại: %s",
|
||||||
"skinrestorer.command.skin.ok": "Đã thay đổi skin",
|
"skinrestorer.command.skin.ok": "Đã thay đổi skin",
|
||||||
"skinrestorer.command.skin.loading": "Đang tải skin..."
|
"skinrestorer.command.skin.loading": "Đang tải skin...",
|
||||||
|
"skinrestorer.command.skin.config_reloaded": "Cấu hình đã được tải lại"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,5 +3,6 @@
|
|||||||
"skinrestorer.command.skin.no_changes": "没有皮肤更改",
|
"skinrestorer.command.skin.no_changes": "没有皮肤更改",
|
||||||
"skinrestorer.command.skin.failed": "更改皮肤失败:%s",
|
"skinrestorer.command.skin.failed": "更改皮肤失败:%s",
|
||||||
"skinrestorer.command.skin.ok": "皮肤已更改",
|
"skinrestorer.command.skin.ok": "皮肤已更改",
|
||||||
"skinrestorer.command.skin.loading": "正在加载皮肤..."
|
"skinrestorer.command.skin.loading": "正在加载皮肤...",
|
||||||
|
"skinrestorer.command.skin.config_reloaded": "配置已重新加载"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,5 +3,6 @@
|
|||||||
"skinrestorer.command.skin.no_changes": "沒有外觀變更",
|
"skinrestorer.command.skin.no_changes": "沒有外觀變更",
|
||||||
"skinrestorer.command.skin.failed": "變更外觀失敗:%s",
|
"skinrestorer.command.skin.failed": "變更外觀失敗:%s",
|
||||||
"skinrestorer.command.skin.ok": "已變更外觀",
|
"skinrestorer.command.skin.ok": "已變更外觀",
|
||||||
"skinrestorer.command.skin.loading": "正在載入外觀..."
|
"skinrestorer.command.skin.loading": "正在載入外觀...",
|
||||||
|
"skinrestorer.command.skin.config_reloaded": "配置已重新載入"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
"PlayerListMixin",
|
"PlayerListMixin",
|
||||||
"ServerLoginPacketListenerImplMixin",
|
"ServerLoginPacketListenerImplMixin",
|
||||||
"ChunkMapAccessor",
|
"ChunkMapAccessor",
|
||||||
"TrackedEntityMixin"
|
"TrackedEntityAccessorInvoker"
|
||||||
],
|
],
|
||||||
"injectors": {
|
"injectors": {
|
||||||
"defaultRequire": 1
|
"defaultRequire": 1
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
package net.lionarius.skinrestorer.fabric;
|
package net.lionarius.skinrestorer.fabric;
|
||||||
|
|
||||||
import net.fabricmc.api.ModInitializer;
|
import net.fabricmc.api.ModInitializer;
|
||||||
import net.fabricmc.loader.api.FabricLoader;
|
|
||||||
import net.lionarius.skinrestorer.SkinRestorer;
|
import net.lionarius.skinrestorer.SkinRestorer;
|
||||||
|
|
||||||
public final class SkinRestorerFabric implements ModInitializer {
|
public final class SkinRestorerFabric implements ModInitializer {
|
||||||
@Override
|
@Override
|
||||||
public void onInitialize() {
|
public void onInitialize() {
|
||||||
SkinRestorer.onInitialize(FabricLoader.getInstance().getConfigDir());
|
SkinRestorer.onInitialize();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package net.lionarius.skinrestorer.fabric.platform;
|
||||||
|
|
||||||
|
import net.fabricmc.loader.api.FabricLoader;
|
||||||
|
import net.lionarius.skinrestorer.platform.services.PlatformHelper;
|
||||||
|
|
||||||
|
import java.nio.file.Path;
|
||||||
|
|
||||||
|
public final class FabricPlatformHelper implements PlatformHelper {
|
||||||
|
@Override
|
||||||
|
public String getPlatformName() {
|
||||||
|
return "fabric";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isModLoaded(String modId) {
|
||||||
|
return FabricLoader.getInstance().isModLoaded(modId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Path getConfigDirectory() {
|
||||||
|
return FabricLoader.getInstance().getConfigDir();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
net.lionarius.skinrestorer.fabric.platform.FabricPlatformHelper
|
||||||
@@ -7,7 +7,6 @@ import net.minecraftforge.event.RegisterCommandsEvent;
|
|||||||
import net.minecraftforge.event.server.ServerStartedEvent;
|
import net.minecraftforge.event.server.ServerStartedEvent;
|
||||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||||
import net.minecraftforge.fml.common.Mod;
|
import net.minecraftforge.fml.common.Mod;
|
||||||
import net.minecraftforge.fml.loading.FMLPaths;
|
|
||||||
|
|
||||||
@Mod(SkinRestorer.MOD_ID)
|
@Mod(SkinRestorer.MOD_ID)
|
||||||
@Mod.EventBusSubscriber(modid = SkinRestorer.MOD_ID)
|
@Mod.EventBusSubscriber(modid = SkinRestorer.MOD_ID)
|
||||||
@@ -16,7 +15,7 @@ public final class SkinRestorerForge {
|
|||||||
public SkinRestorerForge() {
|
public SkinRestorerForge() {
|
||||||
MinecraftForge.EVENT_BUS.register(SkinRestorerForge.class);
|
MinecraftForge.EVENT_BUS.register(SkinRestorerForge.class);
|
||||||
|
|
||||||
SkinRestorer.onInitialize(FMLPaths.CONFIGDIR.get());
|
SkinRestorer.onInitialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package net.lionarius.skinrestorer.forge.platform;
|
||||||
|
|
||||||
|
import net.lionarius.skinrestorer.platform.services.PlatformHelper;
|
||||||
|
import net.minecraftforge.fml.ModList;
|
||||||
|
import net.minecraftforge.fml.loading.FMLPaths;
|
||||||
|
|
||||||
|
import java.nio.file.Path;
|
||||||
|
|
||||||
|
public final class ForgePlatformHelper implements PlatformHelper {
|
||||||
|
@Override
|
||||||
|
public String getPlatformName() {
|
||||||
|
return "forge";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isModLoaded(String modId) {
|
||||||
|
return ModList.get().isLoaded(modId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Path getConfigDirectory() {
|
||||||
|
return FMLPaths.CONFIGDIR.get();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
net.lionarius.skinrestorer.forge.platform.ForgePlatformHelper
|
||||||
@@ -1,6 +1,3 @@
|
|||||||
# Important Notes:
|
|
||||||
# Every field you add must be added to the root build.gradle expandProps map.
|
|
||||||
|
|
||||||
# Project
|
# Project
|
||||||
group=net.lionarius.skinrestorer
|
group=net.lionarius.skinrestorer
|
||||||
java_version=17
|
java_version=17
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import net.lionarius.skinrestorer.SkinRestorer;
|
|||||||
import net.lionarius.skinrestorer.command.SkinCommand;
|
import net.lionarius.skinrestorer.command.SkinCommand;
|
||||||
import net.neoforged.bus.api.SubscribeEvent;
|
import net.neoforged.bus.api.SubscribeEvent;
|
||||||
import net.neoforged.fml.common.Mod;
|
import net.neoforged.fml.common.Mod;
|
||||||
import net.neoforged.fml.loading.FMLPaths;
|
|
||||||
import net.neoforged.neoforge.common.NeoForge;
|
import net.neoforged.neoforge.common.NeoForge;
|
||||||
import net.neoforged.neoforge.event.RegisterCommandsEvent;
|
import net.neoforged.neoforge.event.RegisterCommandsEvent;
|
||||||
import net.neoforged.neoforge.event.server.ServerStartedEvent;
|
import net.neoforged.neoforge.event.server.ServerStartedEvent;
|
||||||
@@ -16,7 +15,7 @@ public final class SkinRestorerNeoForge {
|
|||||||
public SkinRestorerNeoForge() {
|
public SkinRestorerNeoForge() {
|
||||||
NeoForge.EVENT_BUS.register(SkinRestorerNeoForge.class);
|
NeoForge.EVENT_BUS.register(SkinRestorerNeoForge.class);
|
||||||
|
|
||||||
SkinRestorer.onInitialize(FMLPaths.CONFIGDIR.get());
|
SkinRestorer.onInitialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package net.lionarius.skinrestorer.neoforge.platform;
|
||||||
|
|
||||||
|
import net.lionarius.skinrestorer.platform.services.PlatformHelper;
|
||||||
|
import net.neoforged.fml.ModList;
|
||||||
|
import net.neoforged.fml.loading.FMLPaths;
|
||||||
|
|
||||||
|
import java.nio.file.Path;
|
||||||
|
|
||||||
|
public final class NeoForgePlatformHelper implements PlatformHelper {
|
||||||
|
@Override
|
||||||
|
public String getPlatformName() {
|
||||||
|
return "neoforge";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isModLoaded(String modId) {
|
||||||
|
return ModList.get().isLoaded(modId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Path getConfigDirectory() {
|
||||||
|
return FMLPaths.CONFIGDIR.get();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
net.lionarius.skinrestorer.neoforge.platform.NeoForgePlatformHelper
|
||||||
Reference in New Issue
Block a user