mirror of
https://github.com/Suiranoil/SkinRestorer.git
synced 2026-01-16 04:42:12 +00:00
Compare commits
3 Commits
v2.1.0+1.2
...
v2.0.2+1.2
| Author | SHA1 | Date | |
|---|---|---|---|
|
bfd8843b44
|
|||
|
cfdfee11b3
|
|||
|
5c31b5f881
|
2
.github/workflows/build.yml
vendored
2
.github/workflows/build.yml
vendored
@@ -4,6 +4,8 @@ on:
|
||||
paths-ignore:
|
||||
- '.github/**'
|
||||
- '*.md'
|
||||
tags-ignore:
|
||||
- '*'
|
||||
pull_request:
|
||||
paths-ignore:
|
||||
- '.github/**'
|
||||
|
||||
2
.github/workflows/release.yml
vendored
2
.github/workflows/release.yml
vendored
@@ -2,7 +2,7 @@ name: release
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- "v**"
|
||||
- "v*"
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
|
||||
17
CHANGELOG.md
17
CHANGELOG.md
@@ -4,23 +4,6 @@ All notable changes to this project will be documented in this file.
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [2.1.0] - 2024-09-26
|
||||
### Added
|
||||
- Added `config reload` command for dynamic configuration updates
|
||||
- Added `refreshSkinOnJoin` config option (see [wiki](https://github.com/Suiranoil/SkinRestorer/wiki/Configuration#refreshskinonjoin))
|
||||
- Implemented caching for skin providers
|
||||
- Added provider configurations (see [wiki](https://github.com/Suiranoil/SkinRestorer/wiki/Configuration#providers))
|
||||
- Added username and url validation for requests
|
||||
### Fixed
|
||||
- Fixed old skin directory migration not working
|
||||
- Prevented overwriting existing skin files during migration
|
||||
|
||||
## [2.0.3] - 2024-08-20
|
||||
### Added
|
||||
- Added `firstJoinSkinProvider` config option (see [wiki](https://github.com/Suiranoil/SkinRestorer/wiki/Config#firstjoinskinprovider))
|
||||
### Fixed
|
||||
- Fixed ability to set config values to `null`
|
||||
|
||||
## [2.0.2] - 2024-08-04
|
||||
### Added
|
||||
- Backported to minecraft 1.20-1.20.2
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
### Added
|
||||
- Added `config reload` command for dynamic configuration updates
|
||||
- Added `refreshSkinOnJoin` config option (see [wiki](https://github.com/Suiranoil/SkinRestorer/wiki/Configuration#refreshskinonjoin))
|
||||
- Implemented caching for skin providers
|
||||
- Added provider configurations (see [wiki](https://github.com/Suiranoil/SkinRestorer/wiki/Configuration#providers))
|
||||
- Added username and url validation for requests
|
||||
### Fixed
|
||||
- Fixed old skin directory migration not working
|
||||
- Prevented overwriting existing skin files during migration
|
||||
- Backported to minecraft 1.20-1.20.2
|
||||
- [Forge] Added support for Forge
|
||||
### Changed
|
||||
- Changed minimum java version to 17 for minecraft 1.20-1.20.4
|
||||
|
||||
66
README.md
66
README.md
@@ -1,34 +1,58 @@
|
||||
# SkinRestorer
|
||||
|
||||
<a href="https://modrinth.com/mod/skinrestorer"><img src="https://raw.githubusercontent.com/Suiranoil/badges/main/assets/minecraft/platform/modrinth/mini/badge.svg" alt="Modrinth" height="32"></a>
|
||||
<a href="https://www.curseforge.com/minecraft/mc-mods/skinrestorer"><img src="https://raw.githubusercontent.com/Suiranoil/badges/main/assets/minecraft/platform/curseforge/mini/badge.svg" alt="CurseForge" height="32"></a>
|
||||

|
||||

|
||||
[](https://www.curseforge.com/minecraft/mc-mods/skinrestorer)
|
||||
[](https://modrinth.com/mod/skinrestorer)
|
||||
|
||||
A server-side mod for managing and restoring player skins.
|
||||
SkinRestorer is a **server-side** only mod for Fabric that allows players to use and change skins on servers running in
|
||||
offline/insecure mode.
|
||||
|
||||
## ✨ Features
|
||||
## Features
|
||||
|
||||
- **Set skins from Mojang Account**: Fetch and apply skins using a valid Minecraft username.
|
||||
- **Set skins from Ely.by**: Fetch and apply skins using a valid [Ely.by](https://ely.by/) username.
|
||||
- **Set skins from URL**: Fetch and apply skins from any image URL, supporting both classic (Steve) and slim (Alex) skin models.
|
||||
- **Automatic skin fetching**: Automatically fetch skin from Mojang/Ely.by when a player joins the server running in offline/insecure mode ([configurable](https://github.com/Suiranoil/SkinRestorer/wiki/Configuration)).
|
||||
- **Singleplayer support**: Apply skins individually for each world.
|
||||
- **Permissions API support**
|
||||
- **Set Skins from Mojang Account**: Fetch and apply skins using a valid Minecraft account name.
|
||||
- **Set Skins from URL**: Apply skins from any image URL, supporting both classic (Steve) and slim (Alex) skin models.
|
||||
|
||||
## 📜 Command Usage Guide
|
||||
## Command Usage Guide
|
||||
|
||||
For a detailed list of available commands and their usage, please visit the [commands wiki page](https://github.com/Suiranoil/SkinRestorer/wiki/Commands).
|
||||
### Set Mojang Skin
|
||||
|
||||
## ❌ Known Incompatibilities
|
||||
```
|
||||
/skin set mojang <username> [<targets>]
|
||||
```
|
||||
|
||||
- **[Arclight](https://github.com/IzzelAliz/Arclight) (<=1.20.1)**: Trials or older versions are not compatible due to mixin conflicts.
|
||||
As an alternative, consider using the [SkinsRestorer](https://www.spigotmc.org/resources/skinsrestorer.2124/) plugin.
|
||||
- **Parameters:**
|
||||
- `<username>`: Minecraft account name to fetch the skin from.
|
||||
- `[<targets>]`: (Optional, server operators only) Player(s) to apply the skin to.
|
||||
|
||||
## 🪙 Donation
|
||||
### Set Web Skin
|
||||
|
||||
If you enjoy using **SkinRestorer** and would like to support its development, you can contribute through cryptocurrency donations.
|
||||
```
|
||||
/skin set web (classic|slim) "<url>" [<targets>]
|
||||
```
|
||||
|
||||
Bitcoin (BTC): `1Ndbwny8pxdnWXFgadp95fp97y5JqMJKTX`\
|
||||
USDT (TRC20): `TGXn8wrqku5KLzwPWQAeH7wgnV4UzwHEae`\
|
||||
USDT (TON): `UQAQF18Xlmx-V1oZ90C2YOju5qI7q1LgrCP5QaIUhqIELmDS`
|
||||
- **Parameters:**
|
||||
- `(classic|slim)`: Type of the skin model (`classic` for Steve model, `slim` for Alex model).
|
||||
- `"<url>"`: URL pointing to the skin image file (ensure it follows Minecraft's skin size and format requirements).
|
||||
- `[<targets>]`: (Optional, server operators only) Player(s) to apply the skin to.
|
||||
|
||||
Thank you for your generosity!
|
||||
### Clear Skin
|
||||
|
||||
```
|
||||
/skin clear [<targets>]
|
||||
```
|
||||
|
||||
- **Parameters:**
|
||||
- `[<targets>]`: (Optional, server operators only) Player(s) to clear the skin for.
|
||||
|
||||
### Notes:
|
||||
|
||||
- If `targets` is not specified, the command will apply to the player executing the command.
|
||||
|
||||
### Examples:
|
||||
|
||||
```
|
||||
/skin set mojang Notch
|
||||
/skin set web classic "https://example.com/skin.png"
|
||||
/skin clear @a
|
||||
```
|
||||
|
||||
@@ -3,8 +3,8 @@ plugins {
|
||||
}
|
||||
|
||||
base {
|
||||
archivesName = "${mod_id}"
|
||||
version = "${mod_version}+${minecraft_version}-${project.name}"
|
||||
archivesName = "${mod_id}-${project.name}"
|
||||
version = "${mod_version}+${minecraft_version}"
|
||||
}
|
||||
|
||||
java {
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
package net.lionarius.skinrestorer;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import net.lionarius.skinrestorer.config.BuiltInProviderConfig;
|
||||
import net.lionarius.skinrestorer.config.Config;
|
||||
import net.lionarius.skinrestorer.platform.Services;
|
||||
import net.lionarius.skinrestorer.skin.SkinIO;
|
||||
import net.lionarius.skinrestorer.skin.SkinStorage;
|
||||
import net.lionarius.skinrestorer.skin.SkinValue;
|
||||
@@ -12,7 +10,6 @@ import net.lionarius.skinrestorer.translation.Translation;
|
||||
import net.lionarius.skinrestorer.util.FileUtils;
|
||||
import net.lionarius.skinrestorer.util.PlayerUtils;
|
||||
import net.lionarius.skinrestorer.util.Result;
|
||||
import net.lionarius.skinrestorer.util.WebUtils;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.level.storage.LevelResource;
|
||||
@@ -20,7 +17,6 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Optional;
|
||||
@@ -57,28 +53,19 @@ public final class SkinRestorer {
|
||||
return Optional.ofNullable(SkinRestorer.providersRegistry.get(name));
|
||||
}
|
||||
|
||||
public static void onInitialize() {
|
||||
SkinRestorer.configDir = Services.PLATFORM.getConfigDirectory().resolve(SkinRestorer.MOD_ID);
|
||||
public static void onInitialize(Path rootConfigDir) {
|
||||
SkinRestorer.configDir = rootConfigDir.resolve(SkinRestorer.MOD_ID);
|
||||
SkinRestorer.reloadConfig();
|
||||
|
||||
SkinRestorer.providersRegistry.register(EmptySkinProvider.PROVIDER_NAME, SkinProvider.EMPTY, false);
|
||||
|
||||
SkinRestorer.registerDefaultSkinProvider(MojangSkinProvider.PROVIDER_NAME, SkinProvider.MOJANG, SkinRestorer.getConfig().providersConfig().mojang());
|
||||
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 && Arrays.stream(SkinProvider.BUILTIN_PROVIDER_NAMES).noneMatch(name -> name.equals(config.name())))
|
||||
SkinRestorer.providersRegistry.register(config.name(), provider, config.enabled());
|
||||
SkinRestorer.providersRegistry.register(MojangSkinProvider.PROVIDER_NAME, SkinProvider.MOJANG);
|
||||
SkinRestorer.providersRegistry.register(ElyBySkinProvider.PROVIDER_NAME, SkinProvider.ELY_BY);
|
||||
SkinRestorer.providersRegistry.register(MineskinSkinProvider.PROVIDER_NAME, SkinProvider.MINESKIN);
|
||||
}
|
||||
|
||||
public static void onServerStarted(MinecraftServer server) {
|
||||
Path worldSkinDirectory = server.getWorldPath(LevelResource.ROOT).resolve(SkinRestorer.MOD_ID);
|
||||
FileUtils.tryMigrateOldSkinDirectory(SkinRestorer.getConfigDir(), worldSkinDirectory);
|
||||
FileUtils.tryMigrateOldSkinDirectory(worldSkinDirectory);
|
||||
|
||||
SkinRestorer.skinStorage = new SkinStorage(new SkinIO(worldSkinDirectory));
|
||||
}
|
||||
@@ -86,14 +73,9 @@ public final class SkinRestorer {
|
||||
public static void reloadConfig() {
|
||||
SkinRestorer.config = Config.load(SkinRestorer.getConfigDir());
|
||||
Translation.reloadTranslations();
|
||||
WebUtils.recreateHttpClient();
|
||||
|
||||
MojangSkinProvider.createCache();
|
||||
ElyBySkinProvider.createCache();
|
||||
MineskinSkinProvider.createCache();
|
||||
}
|
||||
|
||||
public static String assetPath(String name) {
|
||||
public static String resource(String name) {
|
||||
return String.format("/assets/%s/%s", SkinRestorer.MOD_ID, name);
|
||||
}
|
||||
|
||||
@@ -134,7 +116,7 @@ public final class SkinRestorer {
|
||||
boolean save
|
||||
) {
|
||||
return CompletableFuture.supplyAsync(
|
||||
() -> SkinRestorer.getProvider(context.name()).map(provider -> provider.fetchSkin(context.argument(), context.variant()))
|
||||
() -> SkinRestorer.getProvider(context.name()).map(provider -> provider.getSkin(context.argument(), context.variant()))
|
||||
)
|
||||
.thenApplyAsync(result -> {
|
||||
if (result.isEmpty())
|
||||
|
||||
@@ -49,14 +49,8 @@ public final class SkinCommand {
|
||||
var providers = SkinRestorer.getProvidersRegistry().getPublicProviders();
|
||||
for (var entry : providers)
|
||||
set.then(buildSetSubcommand(entry.first(), entry.second()));
|
||||
if (!providers.isEmpty())
|
||||
base.then(set);
|
||||
|
||||
base.then(
|
||||
literal("config")
|
||||
.requires(commandSourceStack -> commandSourceStack.hasPermission(4))
|
||||
.then(literal("reload").executes(SkinCommand::configReloadSubcommand))
|
||||
);
|
||||
base.then(set);
|
||||
|
||||
dispatcher.register(base);
|
||||
}
|
||||
@@ -166,16 +160,6 @@ public final class SkinCommand {
|
||||
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) {
|
||||
if (updatedPlayers.isEmpty()) {
|
||||
src.sendSuccess(() -> Translation.translatableWithFallback(
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
package net.lionarius.skinrestorer.config;
|
||||
|
||||
public record CacheConfig(boolean enabled, long duration) {
|
||||
public boolean isValid() {
|
||||
return this.duration > 0;
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,6 @@ import net.lionarius.skinrestorer.util.FileUtils;
|
||||
import net.lionarius.skinrestorer.util.JsonUtils;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.Optional;
|
||||
|
||||
public final class Config {
|
||||
|
||||
@@ -14,47 +13,28 @@ public final class Config {
|
||||
|
||||
private String language = "en_us";
|
||||
|
||||
private boolean refreshSkinOnJoin = true;
|
||||
|
||||
private boolean fetchSkinOnFirstJoin = true;
|
||||
|
||||
private FirstJoinSkinProvider firstJoinSkinProvider = FirstJoinSkinProvider.MOJANG;
|
||||
|
||||
private String proxy = "";
|
||||
private transient Proxy parsedProxy = null;
|
||||
|
||||
private long requestTimeout = 10;
|
||||
|
||||
private ProvidersConfig providers = ProvidersConfig.DEFAULT;
|
||||
|
||||
public String language() {
|
||||
public String getLanguage() {
|
||||
return this.language;
|
||||
}
|
||||
|
||||
public boolean refreshSkinOnJoin() {
|
||||
return this.refreshSkinOnJoin;
|
||||
}
|
||||
|
||||
public boolean fetchSkinOnFirstJoin() {
|
||||
return this.fetchSkinOnFirstJoin;
|
||||
}
|
||||
|
||||
public FirstJoinSkinProvider firstJoinSkinProvider() {
|
||||
return this.firstJoinSkinProvider;
|
||||
public String getProxy() {
|
||||
return this.proxy;
|
||||
}
|
||||
|
||||
public Optional<Proxy> proxy() {
|
||||
return Optional.ofNullable(this.parsedProxy);
|
||||
}
|
||||
|
||||
public long requestTimeout() {
|
||||
public long getRequestTimeout() {
|
||||
return this.requestTimeout;
|
||||
}
|
||||
|
||||
public ProvidersConfig providersConfig() {
|
||||
return this.providers;
|
||||
}
|
||||
|
||||
public static Config load(Path path) {
|
||||
var configFile = path.resolve(Config.CONFIG_FILENAME);
|
||||
|
||||
@@ -68,49 +48,8 @@ public final class Config {
|
||||
if (config == null)
|
||||
config = new Config();
|
||||
|
||||
config.verifyAndFix();
|
||||
|
||||
FileUtils.writeFile(path.resolve(Config.CONFIG_FILENAME), JsonUtils.toJson(config));
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
private void verifyAndFix() {
|
||||
if (this.language == null || this.language.isEmpty()) {
|
||||
SkinRestorer.LOGGER.warn("Language config is null or empty, defaulting to 'en_us'");
|
||||
this.language = "en_us";
|
||||
}
|
||||
|
||||
if (this.firstJoinSkinProvider == null) {
|
||||
SkinRestorer.LOGGER.warn("FirstJoinSkinProvider config is null, defaulting to MOJANG");
|
||||
this.firstJoinSkinProvider = FirstJoinSkinProvider.MOJANG;
|
||||
}
|
||||
|
||||
if (this.proxy == null) {
|
||||
SkinRestorer.LOGGER.warn("Proxy config is null, defaulting to an empty string");
|
||||
this.proxy = "";
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
if (this.providers == null) {
|
||||
SkinRestorer.LOGGER.warn("Providers config is null, using default");
|
||||
this.providers = ProvidersConfig.DEFAULT;
|
||||
}
|
||||
|
||||
if (!this.providers.isValid())
|
||||
this.providers.fix();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
package net.lionarius.skinrestorer.config;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import net.lionarius.skinrestorer.skin.provider.ElyBySkinProvider;
|
||||
import net.lionarius.skinrestorer.skin.provider.MojangSkinProvider;
|
||||
|
||||
public enum FirstJoinSkinProvider {
|
||||
@SerializedName(value = "MOJANG", alternate = {"mojang"})
|
||||
MOJANG(MojangSkinProvider.PROVIDER_NAME),
|
||||
@SerializedName(value = "ELY.BY", alternate = {"ely.by", "ELY_BY", "ely_by"})
|
||||
ELY_BY(ElyBySkinProvider.PROVIDER_NAME);
|
||||
|
||||
private final String name;
|
||||
|
||||
FirstJoinSkinProvider(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,6 @@ import net.lionarius.skinrestorer.SkinRestorer;
|
||||
import net.minecraft.network.Connection;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.network.CommonListenerCookie;
|
||||
import net.minecraft.server.players.PlayerList;
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
@@ -38,7 +37,7 @@ public abstract class PlayerListMixin {
|
||||
}
|
||||
|
||||
@Inject(method = "placeNewPlayer", at = @At("HEAD"))
|
||||
private void placeNewPlayer(Connection connection, ServerPlayer player, CommonListenerCookie cookie, CallbackInfo ci) {
|
||||
private void placeNewPlayer(Connection connection, ServerPlayer player, CallbackInfo ci) {
|
||||
if (SkinRestorer.getSkinStorage().hasSavedSkin(player.getUUID()))
|
||||
SkinRestorer.applySkin(server, Collections.singleton(player.getGameProfile()), SkinRestorer.getSkinStorage().getSkin(player.getUUID()));
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package net.lionarius.skinrestorer.mixin;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import net.lionarius.skinrestorer.SkinRestorer;
|
||||
import net.lionarius.skinrestorer.skin.SkinValue;
|
||||
import net.lionarius.skinrestorer.skin.provider.MojangSkinProvider;
|
||||
import net.lionarius.skinrestorer.skin.provider.SkinProviderContext;
|
||||
import net.lionarius.skinrestorer.util.PlayerUtils;
|
||||
import net.lionarius.skinrestorer.util.Result;
|
||||
@@ -21,68 +22,50 @@ import java.util.concurrent.CompletableFuture;
|
||||
public abstract class ServerLoginPacketListenerImplMixin {
|
||||
|
||||
@Shadow @Nullable
|
||||
private GameProfile authenticatedProfile;
|
||||
private GameProfile gameProfile;
|
||||
|
||||
@Unique
|
||||
private CompletableFuture<Void> skinrestorer$pendingSkin;
|
||||
private CompletableFuture<Void> skinrestorer_pendingSkin;
|
||||
|
||||
@Inject(method = "verifyLoginAndFinishConnectionSetup", at = @At(value = "INVOKE",
|
||||
@Inject(method = "handleAcceptedLogin", at = @At(value = "INVOKE",
|
||||
target = "Lnet/minecraft/server/players/PlayerList;canPlayerLogin(Ljava/net/SocketAddress;Lcom/mojang/authlib/GameProfile;)Lnet/minecraft/network/chat/Component;"),
|
||||
cancellable = true)
|
||||
public void waitForSkin(CallbackInfo ci) {
|
||||
if (skinrestorer$pendingSkin == null) {
|
||||
skinrestorer$pendingSkin = CompletableFuture.supplyAsync(() -> {
|
||||
final var profile = authenticatedProfile;
|
||||
if (skinrestorer_pendingSkin == null) {
|
||||
skinrestorer_pendingSkin = CompletableFuture.supplyAsync(() -> {
|
||||
assert gameProfile != null;
|
||||
var originalSkin = PlayerUtils.getPlayerSkin(gameProfile);
|
||||
|
||||
assert profile != null;
|
||||
var originalSkin = PlayerUtils.getPlayerSkin(profile);
|
||||
|
||||
if (SkinRestorer.getSkinStorage().hasSavedSkin(profile.getId())) {
|
||||
if (SkinRestorer.getSkinStorage().hasSavedSkin(gameProfile.getId())) {
|
||||
if (originalSkin != null) { // update to the latest official skin
|
||||
var value = SkinRestorer.getSkinStorage().getSkin(profile.getId());
|
||||
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);
|
||||
var value = SkinRestorer.getSkinStorage().getSkin(gameProfile.getId());
|
||||
SkinRestorer.getSkinStorage().setSkin(gameProfile.getId(), value.setOriginalValue(originalSkin));
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
if (originalSkin == null && SkinRestorer.getConfig().fetchSkinOnFirstJoin()) {
|
||||
var context = new SkinProviderContext(
|
||||
SkinRestorer.getConfig().firstJoinSkinProvider().getName(),
|
||||
profile.getName(),
|
||||
null
|
||||
);
|
||||
skinrestorer$fetchSkin(profile, context);
|
||||
SkinRestorer.LOGGER.debug("Fetching {}'s skin", gameProfile.getName());
|
||||
|
||||
var context = new SkinProviderContext(MojangSkinProvider.PROVIDER_NAME, gameProfile.getName(), null);
|
||||
var result = SkinRestorer.getProvider(context.name()).map(
|
||||
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(gameProfile.getId(), value);
|
||||
} else {
|
||||
SkinRestorer.LOGGER.warn("failed to fetch skin on first join", result.getErrorValue());
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
if (!skinrestorer$pendingSkin.isDone())
|
||||
if (!skinrestorer_pendingSkin.isDone())
|
||||
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;
|
||||
|
||||
@Mixin(targets = "net.minecraft.server.level.ChunkMap$TrackedEntity")
|
||||
public interface TrackedEntityAccessorInvoker {
|
||||
public interface TrackedEntityMixin {
|
||||
|
||||
@Accessor
|
||||
Set<ServerPlayerConnection> getSeenBy();
|
||||
@@ -1,21 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
package net.lionarius.skinrestorer.platform.services;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
public interface PlatformHelper {
|
||||
|
||||
String getPlatformName();
|
||||
|
||||
boolean isModLoaded(String modId);
|
||||
|
||||
Path getConfigDirectory();
|
||||
}
|
||||
@@ -1,59 +1,32 @@
|
||||
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.mojang.authlib.GameProfile;
|
||||
import com.google.gson.JsonObject;
|
||||
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.util.JsonUtils;
|
||||
import net.lionarius.skinrestorer.util.PlayerUtils;
|
||||
import net.lionarius.skinrestorer.util.Result;
|
||||
import net.lionarius.skinrestorer.util.WebUtils;
|
||||
import net.minecraft.util.StringUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.util.Locale;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public final class ElyBySkinProvider implements SkinProvider {
|
||||
|
||||
public static final String PROVIDER_NAME = "ely.by";
|
||||
|
||||
private static final URI API_URI;
|
||||
|
||||
private static LoadingCache<String, Optional<Property>> SKIN_CACHE;
|
||||
|
||||
static {
|
||||
try {
|
||||
API_URI = new URI("http://skinsystem.ely.by");
|
||||
API_URI = new URI("http://skinsystem.ely.by/");
|
||||
} catch (URISyntaxException 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
|
||||
public String getArgumentName() {
|
||||
return "username";
|
||||
@@ -65,32 +38,23 @@ public final class ElyBySkinProvider implements SkinProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<Optional<Property>, Exception> fetchSkin(String username, SkinVariant variant) {
|
||||
public Result<Optional<Property>, Exception> getSkin(String username, SkinVariant variant) {
|
||||
try {
|
||||
if (!StringUtil.isValidPlayerName(username))
|
||||
throw new IllegalArgumentException("invalid username");
|
||||
var profile = ElyBySkinProvider.getElyByProfile(username);
|
||||
|
||||
var usernameLowerCase = username.toLowerCase(Locale.ROOT);
|
||||
var properties = profile.getAsJsonArray("properties");
|
||||
var textures = PlayerUtils.findTexturesProperty(properties);
|
||||
|
||||
return Result.success(SKIN_CACHE.get(usernameLowerCase));
|
||||
} catch (UncheckedExecutionException e) {
|
||||
return Result.error((Exception) e.getCause());
|
||||
return Result.ofNullable(textures);
|
||||
} catch (Exception e) {
|
||||
return Result.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
private static JsonObject getElyByProfile(String username) throws IOException {
|
||||
var request = HttpRequest.newBuilder()
|
||||
.uri(ElyBySkinProvider.API_URI
|
||||
.resolve("/textures/signed/")
|
||||
.resolve("textures/signed/")
|
||||
.resolve(username + "?unsigned=false")
|
||||
)
|
||||
.GET()
|
||||
@@ -102,6 +66,6 @@ public final class ElyBySkinProvider implements SkinProvider {
|
||||
if (response.statusCode() != 200)
|
||||
throw new IllegalArgumentException("no profile with name " + username);
|
||||
|
||||
return JsonUtils.fromJson(response.body(), MinecraftProfilePropertiesResponse.class).toProfile();
|
||||
return JsonUtils.parseJson(response.body());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,11 +21,11 @@ public final class EmptySkinProvider implements SkinProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<Optional<Property>, Exception> fetchSkin(String argument, SkinVariant variant) {
|
||||
return this.fetchSkin();
|
||||
public Result<Optional<Property>, Exception> getSkin(String argument, SkinVariant variant) {
|
||||
return this.getSkin();
|
||||
}
|
||||
|
||||
public Result<Optional<Property>, Exception> fetchSkin() {
|
||||
public Result<Optional<Property>, Exception> getSkin() {
|
||||
return Result.ofNullable(null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,26 +1,18 @@
|
||||
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.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.util.JsonUtils;
|
||||
import net.lionarius.skinrestorer.util.PlayerUtils;
|
||||
import net.lionarius.skinrestorer.util.Result;
|
||||
import net.lionarius.skinrestorer.util.WebUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public final class MineskinSkinProvider implements SkinProvider {
|
||||
|
||||
@@ -28,30 +20,14 @@ public final class MineskinSkinProvider implements SkinProvider {
|
||||
|
||||
private static final URI API_URI;
|
||||
|
||||
private static LoadingCache<Pair<URI, SkinVariant>, Optional<Property>> SKIN_CACHE;
|
||||
|
||||
static {
|
||||
try {
|
||||
API_URI = new URI("https://api.mineskin.org");
|
||||
API_URI = new URI("https://api.mineskin.org/");
|
||||
} catch (URISyntaxException 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
|
||||
public String getArgumentName() {
|
||||
return "url";
|
||||
@@ -63,32 +39,23 @@ public final class MineskinSkinProvider implements SkinProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<Optional<Property>, Exception> fetchSkin(String url, SkinVariant variant) {
|
||||
public Result<Optional<Property>, Exception> getSkin(String url, SkinVariant variant) {
|
||||
try {
|
||||
var uri = new URI(url);
|
||||
var result = MineskinSkinProvider.uploadToMineskin(url, variant);
|
||||
var texture = result.getAsJsonObject("data").getAsJsonObject("texture");
|
||||
|
||||
return Result.success(SKIN_CACHE.get(Pair.of(uri, variant)));
|
||||
} catch (UncheckedExecutionException e) {
|
||||
return Result.error((Exception) e.getCause());
|
||||
return Result.ofNullable(new Property(PlayerUtils.TEXTURES_KEY, texture.get("value").getAsString(), texture.get("signature").getAsString()));
|
||||
} catch (Exception e) {
|
||||
return Result.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
private static JsonObject uploadToMineskin(String url, SkinVariant variant) throws IOException {
|
||||
var body = ("{\"variant\":\"%s\",\"name\":\"%s\",\"visibility\":%d,\"url\":\"%s\"}")
|
||||
.formatted(variant.toString(), "none", 0, url);
|
||||
|
||||
var request = HttpRequest.newBuilder()
|
||||
.uri(MineskinSkinProvider.API_URI.resolve("/generate/url"))
|
||||
.uri(MineskinSkinProvider.API_URI.resolve("generate/url"))
|
||||
.POST(HttpRequest.BodyPublishers.ofString(body))
|
||||
.header("Content-Type", "application/json")
|
||||
.build();
|
||||
|
||||
@@ -1,30 +1,19 @@
|
||||
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.mojang.authlib.GameProfile;
|
||||
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.util.JsonUtils;
|
||||
import net.lionarius.skinrestorer.util.PlayerUtils;
|
||||
import net.lionarius.skinrestorer.util.Result;
|
||||
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.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public final class MojangSkinProvider implements SkinProvider {
|
||||
|
||||
@@ -33,45 +22,13 @@ public final class MojangSkinProvider implements SkinProvider {
|
||||
private static final URI API_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 {
|
||||
try {
|
||||
API_URI = new URI("https://api.mojang.com");
|
||||
SESSION_SERVER_URI = new URI("https://sessionserver.mojang.com");
|
||||
API_URI = new URI("https://api.mojang.com/");
|
||||
SESSION_SERVER_URI = new URI("https://sessionserver.mojang.com/");
|
||||
} catch (URISyntaxException 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) {
|
||||
@@ -89,34 +46,24 @@ public final class MojangSkinProvider implements SkinProvider {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Result<Optional<Property>, Exception> fetchSkin(String username, SkinVariant variant) {
|
||||
public Result<Optional<Property>, Exception> getSkin(String username, SkinVariant variant) {
|
||||
try {
|
||||
if (!StringUtil.isValidPlayerName(username))
|
||||
throw new IllegalArgumentException("invalid username");
|
||||
var uuid = MojangSkinProvider.getUuid(username);
|
||||
var profile = MojangSkinProvider.getMojangProfile(uuid);
|
||||
|
||||
var cachedProfile = MojangSkinProvider.PROFILE_CACHE.get(username);
|
||||
if (cachedProfile.isEmpty())
|
||||
throw new IllegalArgumentException("no profile found for " + username);
|
||||
var properties = profile.getAsJsonArray("properties");
|
||||
var textures = PlayerUtils.findTexturesProperty(properties);
|
||||
|
||||
return Result.success(SKIN_CACHE.get(cachedProfile.get().getId()));
|
||||
} catch (UncheckedExecutionException e) {
|
||||
return Result.error((Exception) e.getCause());
|
||||
return Result.ofNullable(textures);
|
||||
} catch (Exception e) {
|
||||
return Result.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
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 {
|
||||
private static String getUuid(final String name) throws IOException {
|
||||
var request = HttpRequest.newBuilder()
|
||||
.uri(MojangSkinProvider.API_URI
|
||||
.resolve("/users/profiles/minecraft/")
|
||||
.resolve("users/profiles/minecraft/")
|
||||
.resolve(name)
|
||||
)
|
||||
.GET()
|
||||
@@ -128,14 +75,18 @@ public final class MojangSkinProvider implements SkinProvider {
|
||||
if (response.statusCode() != 200)
|
||||
throw new IllegalArgumentException("no profile with name " + name);
|
||||
|
||||
return JsonUtils.fromJson(response.body(), GameProfile.class);
|
||||
var profile = JsonUtils.parseJson(response.body());
|
||||
if (profile == null)
|
||||
return null;
|
||||
|
||||
return profile.get("id").getAsString();
|
||||
}
|
||||
|
||||
private static GameProfile getProfileWithProperties(UUID uuid) throws IOException {
|
||||
private static JsonObject getMojangProfile(String uuid) throws IOException {
|
||||
var request = HttpRequest.newBuilder()
|
||||
.uri(MojangSkinProvider.SESSION_SERVER_URI
|
||||
.resolve("/session/minecraft/profile/")
|
||||
.resolve(UndashedUuid.toString(uuid) + "?unsigned=false")
|
||||
.resolve("session/minecraft/profile/")
|
||||
.resolve(uuid + "?unsigned=false")
|
||||
)
|
||||
.GET()
|
||||
.build();
|
||||
@@ -146,6 +97,6 @@ public final class MojangSkinProvider implements SkinProvider {
|
||||
if (response.statusCode() != 200)
|
||||
throw new IllegalArgumentException("no profile with uuid " + uuid);
|
||||
|
||||
return JsonUtils.fromJson(response.body(), MinecraftProfilePropertiesResponse.class).toProfile();
|
||||
return JsonUtils.parseJson(response.body());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,11 +12,9 @@ public interface SkinProvider {
|
||||
ElyBySkinProvider ELY_BY = new ElyBySkinProvider();
|
||||
MineskinSkinProvider MINESKIN = new MineskinSkinProvider();
|
||||
|
||||
String[] BUILTIN_PROVIDER_NAMES = new String[]{EmptySkinProvider.PROVIDER_NAME, MojangSkinProvider.PROVIDER_NAME, ElyBySkinProvider.PROVIDER_NAME, MineskinSkinProvider.PROVIDER_NAME};
|
||||
|
||||
String getArgumentName();
|
||||
|
||||
boolean hasVariantSupport();
|
||||
|
||||
Result<Optional<Property>, Exception> fetchSkin(String argument, SkinVariant variant);
|
||||
Result<Optional<Property>, Exception> getSkin(String argument, SkinVariant variant);
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ public final class SkinProviderRegistry {
|
||||
|
||||
public void register(@NotNull String name, @NotNull SkinProvider provider, boolean isPublic) {
|
||||
if (this.registry.containsKey(name))
|
||||
return;
|
||||
throw new IllegalArgumentException("Skin provider with name " + name + " is already registered");
|
||||
|
||||
this.registry.put(name, new Entry(provider, isPublic));
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ public final class Translation {
|
||||
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_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 final Map<String, String> fallback;
|
||||
@@ -47,11 +46,11 @@ public final class Translation {
|
||||
}
|
||||
|
||||
public static void reloadTranslations() {
|
||||
translations = Translation.loadTranslationMap(SkinRestorer.getConfig().language());
|
||||
translations = Translation.loadTranslationMap(SkinRestorer.getConfig().getLanguage());
|
||||
}
|
||||
|
||||
private static ImmutableMap<String, String> loadTranslationMap(String lang) {
|
||||
var json = FileUtils.readResource(SkinRestorer.assetPath(String.format("lang/%s.json", lang)));
|
||||
var json = FileUtils.readResource(SkinRestorer.resource(String.format("lang/%s.json", lang)));
|
||||
|
||||
var type = new TypeToken<Map<String, String>>() {}.getType();
|
||||
Map<String, String> map = null;
|
||||
|
||||
@@ -3,7 +3,6 @@ package net.lionarius.skinrestorer.util;
|
||||
import net.lionarius.skinrestorer.SkinRestorer;
|
||||
import net.lionarius.skinrestorer.config.Config;
|
||||
import net.lionarius.skinrestorer.skin.SkinIO;
|
||||
import net.lionarius.skinrestorer.skin.provider.MojangSkinProvider;
|
||||
import net.lionarius.skinrestorer.translation.Translation;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
@@ -18,28 +17,24 @@ public final class FileUtils {
|
||||
|
||||
private FileUtils() {}
|
||||
|
||||
public static void tryMigrateOldSkinDirectory(Path oldDirectory, Path newDirectory) {
|
||||
public static void tryMigrateOldSkinDirectory(Path newDirectory) {
|
||||
try {
|
||||
try (var stream = Files.list(oldDirectory)) {
|
||||
var configDirectory = SkinRestorer.getConfigDir();
|
||||
try (var stream = Files.list(configDirectory)) {
|
||||
var files = stream.filter(file -> {
|
||||
var name = file.getFileName().toString();
|
||||
var name = file.getFileName();
|
||||
return Files.isRegularFile(file)
|
||||
&& !name.startsWith(Translation.LEGACY_TRANSLATION_FILENAME)
|
||||
&& !name.startsWith(Config.CONFIG_FILENAME)
|
||||
&& !name.startsWith(MojangSkinProvider.PROFILE_CACHE_FILENAME)
|
||||
&& name.endsWith(SkinIO.FILE_EXTENSION);
|
||||
}).toList();
|
||||
|
||||
if (!files.isEmpty() && !Files.exists(newDirectory))
|
||||
Files.createDirectories(newDirectory);
|
||||
|
||||
for (var file : files) {
|
||||
var newFile = newDirectory.resolve(file.getFileName());
|
||||
if (!Files.exists(newFile))
|
||||
Files.move(file, newFile, StandardCopyOption.ATOMIC_MOVE);
|
||||
else
|
||||
Files.delete(file);
|
||||
}
|
||||
|
||||
for (var file : files)
|
||||
Files.move(file, newDirectory.resolve(file.getFileName()), StandardCopyOption.REPLACE_EXISTING);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
SkinRestorer.LOGGER.error("could not migrate skin directory", e);
|
||||
|
||||
@@ -1,28 +1,16 @@
|
||||
package net.lionarius.skinrestorer.util;
|
||||
|
||||
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.google.gson.*;
|
||||
import com.mojang.authlib.properties.Property;
|
||||
import com.mojang.authlib.properties.PropertyMap;
|
||||
import com.mojang.util.UUIDTypeAdapter;
|
||||
import net.lionarius.skinrestorer.SkinRestorer;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Base64;
|
||||
import java.util.UUID;
|
||||
|
||||
public final class JsonUtils {
|
||||
|
||||
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 static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
|
||||
|
||||
private JsonUtils() {}
|
||||
|
||||
@@ -43,12 +31,12 @@ public final class JsonUtils {
|
||||
}
|
||||
|
||||
public static JsonObject parseJson(String json) {
|
||||
return GSON.fromJson(json, JsonObject.class);
|
||||
return JsonParser.parseString(json).getAsJsonObject();
|
||||
}
|
||||
|
||||
public static JsonObject skinPropertyToJson(Property property) {
|
||||
try {
|
||||
JsonObject json = GSON.fromJson(new String(Base64.getDecoder().decode(property.value()), StandardCharsets.UTF_8), JsonObject.class);
|
||||
JsonObject json = GSON.fromJson(new String(Base64.getDecoder().decode(property.getValue()), StandardCharsets.UTF_8), JsonObject.class);
|
||||
if (json != null)
|
||||
json.remove("timestamp");
|
||||
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
package net.lionarius.skinrestorer.util;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.authlib.properties.Property;
|
||||
import com.mojang.authlib.yggdrasil.response.MinecraftProfilePropertiesResponse;
|
||||
import net.lionarius.skinrestorer.mixin.ChunkMapAccessor;
|
||||
import net.lionarius.skinrestorer.mixin.TrackedEntityAccessorInvoker;
|
||||
import net.lionarius.skinrestorer.mixin.TrackedEntityMixin;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.protocol.game.*;
|
||||
import net.minecraft.server.level.ChunkMap;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.players.PlayerList;
|
||||
import net.minecraft.world.level.biome.BiomeManager;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@@ -50,14 +50,14 @@ public final class PlayerUtils {
|
||||
)
|
||||
));
|
||||
|
||||
var trackedEntity = (TrackedEntityAccessorInvoker) ((ChunkMapAccessor) chunkMap).getEntityMap().get(player.getId());
|
||||
var trackedEntity = (TrackedEntityMixin) ((ChunkMapAccessor) chunkMap).getEntityMap().get(player.getId());
|
||||
if (trackedEntity != null) {
|
||||
var seenBy = Set.copyOf(trackedEntity.getSeenBy());
|
||||
for (var observerConnection : seenBy) {
|
||||
var observer = observerConnection.getPlayer();
|
||||
trackedEntity.invokeRemovePlayer(observer);
|
||||
|
||||
var trackedObserverEntity = (TrackedEntityAccessorInvoker) ((ChunkMapAccessor) chunkMap).getEntityMap().get(observer.getId());
|
||||
var trackedObserverEntity = (TrackedEntityMixin) ((ChunkMapAccessor) chunkMap).getEntityMap().get(observer.getId());
|
||||
if (trackedObserverEntity != null) {
|
||||
trackedObserverEntity.invokeRemovePlayer(player);
|
||||
trackedObserverEntity.invokeUpdatePlayer(player);
|
||||
@@ -67,12 +67,20 @@ public final class PlayerUtils {
|
||||
}
|
||||
|
||||
if (!player.isDeadOrDying()) {
|
||||
player.connection.send(new ClientboundBundlePacket(
|
||||
List.of(
|
||||
new ClientboundRespawnPacket(player.createCommonSpawnInfo(serverLevel), ClientboundRespawnPacket.KEEP_ALL_DATA),
|
||||
new ClientboundGameEventPacket(ClientboundGameEventPacket.LEVEL_CHUNKS_LOAD_START, 0)
|
||||
player.connection.send(
|
||||
new ClientboundRespawnPacket(
|
||||
player.level().dimensionTypeId(),
|
||||
player.level().dimension(),
|
||||
BiomeManager.obfuscateSeed(player.serverLevel().getSeed()),
|
||||
player.gameMode.getGameModeForPlayer(),
|
||||
player.gameMode.getPreviousGameModeForPlayer(),
|
||||
player.level().isDebug(),
|
||||
player.serverLevel().isFlat(),
|
||||
(byte) 3,
|
||||
player.getLastDeathLocation(),
|
||||
player.getPortalCooldown()
|
||||
)
|
||||
));
|
||||
);
|
||||
player.connection.teleport(player.getX(), player.getY(), player.getZ(), player.getYRot(), player.getXRot());
|
||||
player.connection.send(new ClientboundSetEntityMotionPacket(player));
|
||||
var vehicle = player.getVehicle();
|
||||
@@ -90,14 +98,14 @@ public final class PlayerUtils {
|
||||
}
|
||||
}
|
||||
|
||||
private static void sendActivePlayerEffects(ServerPlayer player) {
|
||||
public static void sendActivePlayerEffects(ServerPlayer player) {
|
||||
for (var effect : player.getActiveEffects()) {
|
||||
player.connection.send(new ClientboundUpdateMobEffectPacket(player.getId(), effect, false));
|
||||
player.connection.send(new ClientboundUpdateMobEffectPacket(player.getId(), effect));
|
||||
}
|
||||
}
|
||||
|
||||
public static Property getPlayerSkin(GameProfile profile) {
|
||||
return Iterables.getFirst(profile.getProperties().get(TEXTURES_KEY), null);
|
||||
return profile.getProperties().get(TEXTURES_KEY).stream().findFirst().orElse(null);
|
||||
}
|
||||
|
||||
public static void applyRestoredSkin(GameProfile profile, Property skin) {
|
||||
@@ -107,6 +115,7 @@ public final class PlayerUtils {
|
||||
profile.getProperties().put(TEXTURES_KEY, skin);
|
||||
}
|
||||
|
||||
|
||||
public static boolean areSkinPropertiesEquals(Property x, Property y) {
|
||||
if (x == y)
|
||||
return true;
|
||||
@@ -126,9 +135,24 @@ public final class PlayerUtils {
|
||||
return xJson.equals(yJson);
|
||||
}
|
||||
|
||||
public static GameProfile toProfile(MinecraftProfilePropertiesResponse response) {
|
||||
final GameProfile profile = new GameProfile(response.id(), response.name());
|
||||
profile.getProperties().putAll(response.properties());
|
||||
return profile;
|
||||
public static Property findTexturesProperty(JsonArray properties) {
|
||||
Property textures = null;
|
||||
for (var property : properties) {
|
||||
var propertyObject = property.getAsJsonObject();
|
||||
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,8 +17,4 @@ public final class StringUtils {
|
||||
|
||||
return response.toString();
|
||||
}
|
||||
|
||||
public static boolean isValidPlayerName(String playerName) {
|
||||
return playerName.length() <= 16 && playerName.chars().filter(i -> i <= 32 || i >= 127).findAny().isEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import java.time.Duration;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.Date;
|
||||
|
||||
public final class WebUtils {
|
||||
|
||||
@@ -17,32 +18,36 @@ public final class WebUtils {
|
||||
|
||||
public static final String USER_AGENT;
|
||||
|
||||
private static HttpClient HTTP_CLIENT = null;
|
||||
|
||||
static {
|
||||
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 proxy = SkinRestorer.getConfig().proxy();
|
||||
proxy.ifPresent(value -> builder.proxy(ProxySelector.of(InetSocketAddress.createUnresolved(value.host(), value.port()))));
|
||||
|
||||
var proxy = SkinRestorer.getConfig().getProxy();
|
||||
try {
|
||||
builder.connectTimeout(Duration.of(SkinRestorer.getConfig().requestTimeout(), ChronoUnit.SECONDS));
|
||||
if (proxy != null) {
|
||||
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) {
|
||||
SkinRestorer.LOGGER.error("failed to set request timeout", e);
|
||||
builder.connectTimeout(Duration.of(10, ChronoUnit.SECONDS));
|
||||
}
|
||||
|
||||
return builder.build();
|
||||
HTTP_CLIENT = builder.build();
|
||||
}
|
||||
|
||||
private static final HttpClient HTTP_CLIENT;
|
||||
|
||||
public static HttpResponse<String> executeRequest(HttpRequest request) throws IOException {
|
||||
try {
|
||||
var modifiedRequest = HttpRequest.newBuilder(request, (name, value) -> true)
|
||||
@@ -62,16 +67,30 @@ public final class WebUtils {
|
||||
}
|
||||
|
||||
public static void throwOnClientErrors(HttpResponse<?> response) {
|
||||
String message = switch (response.statusCode()) {
|
||||
case 400 -> "bad request";
|
||||
case 401 -> "unauthorized";
|
||||
case 403 -> "forbidden";
|
||||
case 404 -> "not found";
|
||||
case 405 -> "method not allowed";
|
||||
case 408 -> "request timeout";
|
||||
case 429 -> "too many requests";
|
||||
default -> null;
|
||||
};
|
||||
String message = null;
|
||||
switch (response.statusCode()) {
|
||||
case 400:
|
||||
message = "bad request";
|
||||
break;
|
||||
case 401:
|
||||
message = "unauthorized";
|
||||
break;
|
||||
case 403:
|
||||
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)
|
||||
throw new IllegalStateException(message);
|
||||
|
||||
@@ -3,6 +3,5 @@
|
||||
"skinrestorer.command.skin.no_changes": "Žádné změny skinu",
|
||||
"skinrestorer.command.skin.failed": "Nepodařilo se změnit skin: %s",
|
||||
"skinrestorer.command.skin.ok": "Skin změněn",
|
||||
"skinrestorer.command.skin.loading": "Načítání skinu...",
|
||||
"skinrestorer.command.skin.config_reloaded": "Konfigurace byla znovu načtena"
|
||||
"skinrestorer.command.skin.loading": "Načítání skinu..."
|
||||
}
|
||||
|
||||
@@ -3,6 +3,5 @@
|
||||
"skinrestorer.command.skin.no_changes": "Keine Skinänderungen",
|
||||
"skinrestorer.command.skin.failed": "Skin konnte nicht geändert werden: %s",
|
||||
"skinrestorer.command.skin.ok": "Skin geändert",
|
||||
"skinrestorer.command.skin.loading": "Skin wird geladen...",
|
||||
"skinrestorer.command.skin.config_reloaded": "Konfiguration wurde neu geladen"
|
||||
"skinrestorer.command.skin.loading": "Skin wird geladen..."
|
||||
}
|
||||
|
||||
@@ -3,6 +3,5 @@
|
||||
"skinrestorer.command.skin.no_changes": "No skin changes",
|
||||
"skinrestorer.command.skin.failed": "Failed to change skin: %s",
|
||||
"skinrestorer.command.skin.ok": "Skin changed",
|
||||
"skinrestorer.command.skin.loading": "Loading skin...",
|
||||
"skinrestorer.command.skin.config_reloaded": "Config has been reloaded"
|
||||
"skinrestorer.command.skin.loading": "Loading skin..."
|
||||
}
|
||||
|
||||
@@ -3,6 +3,5 @@
|
||||
"skinrestorer.command.skin.no_changes": "No hay cambios de skin",
|
||||
"skinrestorer.command.skin.failed": "Error al cambiar el skin: %s",
|
||||
"skinrestorer.command.skin.ok": "Skin cambiado",
|
||||
"skinrestorer.command.skin.loading": "Cargando skin...",
|
||||
"skinrestorer.command.skin.config_reloaded": "La configuración se ha recargado"
|
||||
"skinrestorer.command.skin.loading": "Cargando skin..."
|
||||
}
|
||||
|
||||
@@ -3,6 +3,5 @@
|
||||
"skinrestorer.command.skin.no_changes": "No hay cambios de skin",
|
||||
"skinrestorer.command.skin.failed": "Error al cambiar el skin: %s",
|
||||
"skinrestorer.command.skin.ok": "Skin cambiado",
|
||||
"skinrestorer.command.skin.loading": "Cargando skin...",
|
||||
"skinrestorer.command.skin.config_reloaded": "La configuración se ha recargado"
|
||||
"skinrestorer.command.skin.loading": "Cargando skin..."
|
||||
}
|
||||
|
||||
@@ -3,6 +3,5 @@
|
||||
"skinrestorer.command.skin.no_changes": "No hay cambios de skin",
|
||||
"skinrestorer.command.skin.failed": "Error al cambiar el skin: %s",
|
||||
"skinrestorer.command.skin.ok": "Skin cambiado",
|
||||
"skinrestorer.command.skin.loading": "Cargando skin...",
|
||||
"skinrestorer.command.skin.config_reloaded": "La configuración se ha recargado"
|
||||
"skinrestorer.command.skin.loading": "Cargando skin..."
|
||||
}
|
||||
|
||||
@@ -3,6 +3,5 @@
|
||||
"skinrestorer.command.skin.no_changes": "Walang pagbabago sa skin",
|
||||
"skinrestorer.command.skin.failed": "Nabigo sa pagbabago ng skin: %s",
|
||||
"skinrestorer.command.skin.ok": "Nabago ang skin",
|
||||
"skinrestorer.command.skin.loading": "Naglo-load ng skin...",
|
||||
"skinrestorer.command.skin.config_reloaded": "Na-reload ang config"
|
||||
"skinrestorer.command.skin.loading": "Naglo-load ng skin..."
|
||||
}
|
||||
|
||||
@@ -3,6 +3,5 @@
|
||||
"skinrestorer.command.skin.no_changes": "Aucun changement de skin",
|
||||
"skinrestorer.command.skin.failed": "Échec du changement de skin : %s",
|
||||
"skinrestorer.command.skin.ok": "Skin changé",
|
||||
"skinrestorer.command.skin.loading": "Chargement du skin...",
|
||||
"skinrestorer.command.skin.config_reloaded": "La configuration a été rechargée"
|
||||
"skinrestorer.command.skin.loading": "Chargement du skin..."
|
||||
}
|
||||
|
||||
@@ -3,6 +3,5 @@
|
||||
"skinrestorer.command.skin.no_changes": "Aucun changement de skin",
|
||||
"skinrestorer.command.skin.failed": "Échec du changement de skin : %s",
|
||||
"skinrestorer.command.skin.ok": "Skin changé",
|
||||
"skinrestorer.command.skin.loading": "Chargement du skin...",
|
||||
"skinrestorer.command.skin.config_reloaded": "La configuration a été rechargée"
|
||||
"skinrestorer.command.skin.loading": "Chargement du skin..."
|
||||
}
|
||||
|
||||
@@ -3,6 +3,5 @@
|
||||
"skinrestorer.command.skin.no_changes": "कोई त्वचा परिवर्तन नहीं",
|
||||
"skinrestorer.command.skin.failed": "त्वचा बदलने में विफल: %s",
|
||||
"skinrestorer.command.skin.ok": "त्वचा बदल दी गई",
|
||||
"skinrestorer.command.skin.loading": "त्वचा लोड हो रही है...",
|
||||
"skinrestorer.command.skin.config_reloaded": "कॉन्फ़िगरेशन फिर से लोड किया गया है"
|
||||
"skinrestorer.command.skin.loading": "त्वचा लोड हो रही है..."
|
||||
}
|
||||
|
||||
@@ -3,6 +3,5 @@
|
||||
"skinrestorer.command.skin.no_changes": "Nincsenek skin változások",
|
||||
"skinrestorer.command.skin.failed": "Skin változtatás sikertelen: %s",
|
||||
"skinrestorer.command.skin.ok": "Skin megváltoztatva",
|
||||
"skinrestorer.command.skin.loading": "Skin betöltése...",
|
||||
"skinrestorer.command.skin.config_reloaded": "A konfiguráció újratöltve"
|
||||
"skinrestorer.command.skin.loading": "Skin betöltése..."
|
||||
}
|
||||
|
||||
@@ -3,6 +3,5 @@
|
||||
"skinrestorer.command.skin.no_changes": "Tidak ada perubahan skin",
|
||||
"skinrestorer.command.skin.failed": "Gagal mengubah skin: %s",
|
||||
"skinrestorer.command.skin.ok": "Skin diubah",
|
||||
"skinrestorer.command.skin.loading": "Memuat skin...",
|
||||
"skinrestorer.command.skin.config_reloaded": "Konfigurasi telah dimuat ulang"
|
||||
"skinrestorer.command.skin.loading": "Memuat skin..."
|
||||
}
|
||||
|
||||
@@ -3,6 +3,5 @@
|
||||
"skinrestorer.command.skin.no_changes": "Nessuna modifica alla skin",
|
||||
"skinrestorer.command.skin.failed": "Impossibile cambiare la skin: %s",
|
||||
"skinrestorer.command.skin.ok": "Skin cambiata",
|
||||
"skinrestorer.command.skin.loading": "Caricamento della skin...",
|
||||
"skinrestorer.command.skin.config_reloaded": "La configurazione è stata ricaricata"
|
||||
"skinrestorer.command.skin.loading": "Caricamento della skin..."
|
||||
}
|
||||
|
||||
@@ -3,6 +3,5 @@
|
||||
"skinrestorer.command.skin.no_changes": "Brak zmian skina",
|
||||
"skinrestorer.command.skin.failed": "Nie udało się zmienić skina: %s",
|
||||
"skinrestorer.command.skin.ok": "Skin zmieniony",
|
||||
"skinrestorer.command.skin.loading": "Ładowanie skina...",
|
||||
"skinrestorer.command.skin.config_reloaded": "Konfiguracja została przeładowana"
|
||||
"skinrestorer.command.skin.loading": "Ładowanie skina..."
|
||||
}
|
||||
|
||||
@@ -3,6 +3,5 @@
|
||||
"skinrestorer.command.skin.no_changes": "Nenhuma alteração de skin",
|
||||
"skinrestorer.command.skin.failed": "Falha ao alterar a skin: %s",
|
||||
"skinrestorer.command.skin.ok": "Skin alterada",
|
||||
"skinrestorer.command.skin.loading": "Carregando skin...",
|
||||
"skinrestorer.command.skin.config_reloaded": "Configuração recarregada"
|
||||
"skinrestorer.command.skin.loading": "Carregando skin..."
|
||||
}
|
||||
|
||||
@@ -3,6 +3,5 @@
|
||||
"skinrestorer.command.skin.no_changes": "Nenhuma alteração de skin",
|
||||
"skinrestorer.command.skin.failed": "Falha ao alterar a skin: %s",
|
||||
"skinrestorer.command.skin.ok": "Skin alterada",
|
||||
"skinrestorer.command.skin.loading": "Carregando skin...",
|
||||
"skinrestorer.command.skin.config_reloaded": "Configuração recarregada"
|
||||
"skinrestorer.command.skin.loading": "Carregando skin..."
|
||||
}
|
||||
|
||||
@@ -3,6 +3,5 @@
|
||||
"skinrestorer.command.skin.no_changes": "Изменений скина нет",
|
||||
"skinrestorer.command.skin.failed": "Не удалось изменить скин: %s",
|
||||
"skinrestorer.command.skin.ok": "Скин изменён",
|
||||
"skinrestorer.command.skin.loading": "Загрузка скина...",
|
||||
"skinrestorer.command.skin.config_reloaded": "Конфигурация была перезагружена"
|
||||
"skinrestorer.command.skin.loading": "Загрузка скина..."
|
||||
}
|
||||
|
||||
@@ -3,6 +3,5 @@
|
||||
"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.ok": "Skin değiştirildi",
|
||||
"skinrestorer.command.skin.loading": "Skin yükleniyor...",
|
||||
"skinrestorer.command.skin.config_reloaded": "Yapılandırma yeniden yüklendi"
|
||||
"skinrestorer.command.skin.loading": "Skin yükleniyor..."
|
||||
}
|
||||
|
||||
@@ -3,6 +3,5 @@
|
||||
"skinrestorer.command.skin.no_changes": "Змін скіна немає",
|
||||
"skinrestorer.command.skin.failed": "Не вдалося змінити скіна: %s",
|
||||
"skinrestorer.command.skin.ok": "Скін змінено",
|
||||
"skinrestorer.command.skin.loading": "Завантаження скіна...",
|
||||
"skinrestorer.command.skin.config_reloaded": "Конфігурацію перезавантажено"
|
||||
"skinrestorer.command.skin.loading": "Завантаження скіна..."
|
||||
}
|
||||
|
||||
@@ -3,6 +3,5 @@
|
||||
"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.ok": "Đã thay đổi skin",
|
||||
"skinrestorer.command.skin.loading": "Đang tải skin...",
|
||||
"skinrestorer.command.skin.config_reloaded": "Cấu hình đã được tải lại"
|
||||
"skinrestorer.command.skin.loading": "Đang tải skin..."
|
||||
}
|
||||
|
||||
@@ -3,6 +3,5 @@
|
||||
"skinrestorer.command.skin.no_changes": "没有皮肤更改",
|
||||
"skinrestorer.command.skin.failed": "更改皮肤失败:%s",
|
||||
"skinrestorer.command.skin.ok": "皮肤已更改",
|
||||
"skinrestorer.command.skin.loading": "正在加载皮肤...",
|
||||
"skinrestorer.command.skin.config_reloaded": "配置已重新加载"
|
||||
"skinrestorer.command.skin.loading": "正在加载皮肤..."
|
||||
}
|
||||
|
||||
@@ -3,6 +3,5 @@
|
||||
"skinrestorer.command.skin.no_changes": "沒有外觀變更",
|
||||
"skinrestorer.command.skin.failed": "變更外觀失敗:%s",
|
||||
"skinrestorer.command.skin.ok": "已變更外觀",
|
||||
"skinrestorer.command.skin.loading": "正在載入外觀...",
|
||||
"skinrestorer.command.skin.config_reloaded": "配置已重新載入"
|
||||
"skinrestorer.command.skin.loading": "正在載入外觀..."
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
"PlayerListMixin",
|
||||
"ServerLoginPacketListenerImplMixin",
|
||||
"ChunkMapAccessor",
|
||||
"TrackedEntityAccessorInvoker"
|
||||
"TrackedEntityMixin"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
package net.lionarius.skinrestorer.fabric;
|
||||
|
||||
import net.fabricmc.api.ModInitializer;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.lionarius.skinrestorer.SkinRestorer;
|
||||
|
||||
public final class SkinRestorerFabric implements ModInitializer {
|
||||
@Override
|
||||
public void onInitialize() {
|
||||
SkinRestorer.onInitialize();
|
||||
SkinRestorer.onInitialize(FabricLoader.getInstance().getConfigDir());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
public abstract class MinecraftServerMixin {
|
||||
|
||||
@Inject(method = "runServer",
|
||||
at = @At(value = "INVOKE", target = "Lnet/minecraft/Util;getNanos()J", ordinal = 0))
|
||||
at = @At(value = "INVOKE", target = "Lnet/minecraft/Util;getMillis()J", ordinal = 0))
|
||||
private void onServerStarted(CallbackInfo ci) {
|
||||
SkinRestorer.onServerStarted((MinecraftServer) (Object) this);
|
||||
}
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
net.lionarius.skinrestorer.fabric.platform.FabricPlatformHelper
|
||||
@@ -20,8 +20,6 @@ minecraft {
|
||||
|
||||
copyIdeResources = true //Calls processResources when in dev
|
||||
|
||||
reobf = false // Forge 1.20.6+ uses official mappings at runtime, so we shouldn't reobf from official to SRG
|
||||
|
||||
// Automatically enable forge AccessTransformers if the file exists
|
||||
// This location is hardcoded in Forge and can not be changed.
|
||||
// https://github.com/MinecraftForge/MinecraftForge/blob/be1698bb1554f9c8fa2f58e32b9ab70bc4385e60/fmlloader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/ModFile.java#L123
|
||||
|
||||
@@ -7,6 +7,7 @@ import net.minecraftforge.event.RegisterCommandsEvent;
|
||||
import net.minecraftforge.event.server.ServerStartedEvent;
|
||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||
import net.minecraftforge.fml.common.Mod;
|
||||
import net.minecraftforge.fml.loading.FMLPaths;
|
||||
|
||||
@Mod(SkinRestorer.MOD_ID)
|
||||
@Mod.EventBusSubscriber(modid = SkinRestorer.MOD_ID)
|
||||
@@ -15,7 +16,7 @@ public final class SkinRestorerForge {
|
||||
public SkinRestorerForge() {
|
||||
MinecraftForge.EVENT_BUS.register(SkinRestorerForge.class);
|
||||
|
||||
SkinRestorer.onInitialize();
|
||||
SkinRestorer.onInitialize(FMLPaths.CONFIGDIR.get());
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
net.lionarius.skinrestorer.forge.platform.ForgePlatformHelper
|
||||
@@ -1,16 +1,19 @@
|
||||
# Important Notes:
|
||||
# Every field you add must be added to the root build.gradle expandProps map.
|
||||
|
||||
# Project
|
||||
group=net.lionarius.skinrestorer
|
||||
java_version=21
|
||||
java_version=17
|
||||
|
||||
# Common
|
||||
minecraft_version=1.20.5
|
||||
minecraft_version_list=1.20.5,1.20.6
|
||||
minecraft_version_range=[1.20.5,1.20.6]
|
||||
minecraft_version=1.20
|
||||
minecraft_version_list=1.20,1.20.1
|
||||
minecraft_version_range=[1.20, 1.20.1]
|
||||
mod_id=skinrestorer
|
||||
mod_name=SkinRestorer
|
||||
mod_version=2.1.0
|
||||
mod_version=2.0.2
|
||||
mod_author=Lionarius
|
||||
mod_homepage=https://modrinth.com/mod/skinrestorer
|
||||
mod_homepage=https://www.curseforge.com/minecraft/mc-mods/skinrestorer
|
||||
mod_sources=https://github.com/Suiranoil/SkinRestorer
|
||||
mod_issues=https://github.com/Suiranoil/SkinRestorer/issues
|
||||
license=MIT
|
||||
@@ -18,21 +21,21 @@ credits=
|
||||
description=A server-side mod for managing skins.
|
||||
|
||||
# ParchmentMC mappings, see https://parchmentmc.org/docs/getting-started#choose-a-version for new versions
|
||||
parchment_minecraft=1.20.6
|
||||
parchment_version=2024.06.16
|
||||
parchment_minecraft=1.20.1
|
||||
parchment_version=2023.09.03
|
||||
|
||||
# Fabric, see https://fabricmc.net/develop/ for new versions
|
||||
fabric_loader_version=0.15.0
|
||||
|
||||
# Forge, see https://files.minecraftforge.net/net/minecraftforge/forge/ for new versions
|
||||
forge_version=50.0.0
|
||||
forge_loader_version_range=[50,)
|
||||
forge_version=46.0.1
|
||||
forge_loader_version_range=[46,)
|
||||
# Forge sometimes skips minor minecraft versions (like 1.20.5)
|
||||
forge_minecraft_version=1.20.6
|
||||
forge_minecraft_version=1.20
|
||||
|
||||
# NeoForge, see https://projects.neoforged.net/neoforged/neoforge for new versions
|
||||
neoforge_version=20.5.0-beta
|
||||
neoforge_loader_version_range=[3,)
|
||||
neoforge_version=20.2.3-beta
|
||||
neoforge_loader_version_range=[1,)
|
||||
|
||||
# Publishing
|
||||
curseforge_id=443823
|
||||
|
||||
@@ -3,20 +3,20 @@ package net.lionarius.skinrestorer.neoforge;
|
||||
import net.lionarius.skinrestorer.SkinRestorer;
|
||||
import net.lionarius.skinrestorer.command.SkinCommand;
|
||||
import net.neoforged.bus.api.SubscribeEvent;
|
||||
import net.neoforged.fml.common.EventBusSubscriber;
|
||||
import net.neoforged.fml.common.Mod;
|
||||
import net.neoforged.fml.loading.FMLPaths;
|
||||
import net.neoforged.neoforge.common.NeoForge;
|
||||
import net.neoforged.neoforge.event.RegisterCommandsEvent;
|
||||
import net.neoforged.neoforge.event.server.ServerStartedEvent;
|
||||
|
||||
@Mod(SkinRestorer.MOD_ID)
|
||||
@EventBusSubscriber(modid = SkinRestorer.MOD_ID)
|
||||
@Mod.EventBusSubscriber(modid = SkinRestorer.MOD_ID)
|
||||
public final class SkinRestorerNeoForge {
|
||||
|
||||
public SkinRestorerNeoForge() {
|
||||
NeoForge.EVENT_BUS.register(SkinRestorerNeoForge.class);
|
||||
|
||||
SkinRestorer.onInitialize();
|
||||
SkinRestorer.onInitialize(FMLPaths.CONFIGDIR.get());
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
@@ -17,14 +17,14 @@ config = "${mod_id}.mixins.json"
|
||||
|
||||
[[dependencies.${mod_id}]]
|
||||
modId = "neoforge"
|
||||
type = "required"
|
||||
mandatory = true
|
||||
versionRange = "[${neoforge_version},)"
|
||||
ordering = "NONE"
|
||||
side = "BOTH"
|
||||
|
||||
[[dependencies.${mod_id}]]
|
||||
modId = "minecraft"
|
||||
type = "required"
|
||||
mandatory = true
|
||||
versionRange = "${minecraft_version_range}"
|
||||
ordering = "NONE"
|
||||
side = "BOTH"
|
||||
@@ -1 +0,0 @@
|
||||
net.lionarius.skinrestorer.neoforge.platform.NeoForgePlatformHelper
|
||||
@@ -71,4 +71,5 @@ rootProject.name = 'skin-restorer'
|
||||
include('common')
|
||||
include('fabric')
|
||||
include('forge')
|
||||
include('neoforge')
|
||||
// There is no NeoForge for versions <1.20.2
|
||||
// include('neoforge')
|
||||
|
||||
Reference in New Issue
Block a user