mirror of
https://github.com/Suiranoil/SkinRestorer.git
synced 2026-01-16 04:42:12 +00:00
Compare commits
73 Commits
v2.0.3+1.2
...
v2.2.0-1.2
| Author | SHA1 | Date | |
|---|---|---|---|
|
33e5d80825
|
|||
|
9150179391
|
|||
|
374137bc47
|
|||
|
a35a64c017
|
|||
|
8338f5dac9
|
|||
|
b475168fb1
|
|||
|
b5ad427ff3
|
|||
|
f2b53f4f3f
|
|||
|
8820e3ba3f
|
|||
|
8329adc476
|
|||
|
71c826e8b7
|
|||
|
7e063977c5
|
|||
|
0d56c339d1
|
|||
|
fb7020354a
|
|||
|
da9afc4bef
|
|||
|
43df28381d
|
|||
|
1884256051
|
|||
|
60c890d2b0
|
|||
|
ba47986e94
|
|||
|
aa02759780
|
|||
|
4a43a0de41
|
|||
|
eeda2f5857
|
|||
|
5e0f67a1e6
|
|||
|
557ff88299
|
|||
|
7292a25d7f
|
|||
|
62256c77a9
|
|||
|
5f6236cdf5
|
|||
|
30f027d37f
|
|||
|
4be7335d7c
|
|||
|
bec3c9d179
|
|||
|
d9b5d6c12b
|
|||
|
86a1d4de14
|
|||
|
adcb696e35
|
|||
|
b3ca228d02
|
|||
|
f43fa13044
|
|||
|
9bd8a53657
|
|||
|
4a40a52d24
|
|||
|
48976117cb
|
|||
|
7aa3316d0f
|
|||
|
7eedb79453
|
|||
|
93e9907e03
|
|||
|
de4e8a3178
|
|||
|
04faa2953f
|
|||
|
75b3abb847
|
|||
|
e7d8dfa6b6
|
|||
|
017478374d
|
|||
|
3360bc567b
|
|||
|
75889944e9
|
|||
|
8baad37227
|
|||
|
4280659c70
|
|||
|
2e7c42b619
|
|||
|
9873747dfb
|
|||
|
b209893511
|
|||
|
3a8a513180
|
|||
|
9e0c41482f
|
|||
|
449e286fba
|
|||
|
299a8b621f
|
|||
|
c536dd36e2
|
|||
|
5b45fcb25c
|
|||
|
b2ae60ac73
|
|||
|
b850086ad8
|
|||
|
6611077b93
|
|||
|
417ed7d695
|
|||
|
40cddfc2a7
|
|||
|
0d6ed15014
|
|||
|
182f0c4497
|
|||
|
3492f82214
|
|||
|
2f5edc7069
|
|||
|
29a8b406c1
|
|||
|
304c3b371d
|
|||
|
d286270bdc
|
|||
|
2bd9e55b53
|
|||
|
19677fe63b
|
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/**'
|
||||||
|
|||||||
3
.github/workflows/release.yml
vendored
3
.github/workflows/release.yml
vendored
@@ -1,8 +1,5 @@
|
|||||||
name: release
|
name: release
|
||||||
on:
|
on:
|
||||||
push:
|
|
||||||
tags:
|
|
||||||
- "v*"
|
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
|||||||
23
CHANGELOG.md
23
CHANGELOG.md
@@ -4,6 +4,29 @@ 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/),
|
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).
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
|
## [2.2.0] - 2024-11-28
|
||||||
|
### Added
|
||||||
|
- Added support for [SkinShuffle](https://modrinth.com/mod/skinshuffle) clients (requires FabricAPI on Fabric)
|
||||||
|
(closes [#34](https://github.com/Suiranoil/SkinRestorer/issues/34))
|
||||||
|
- Added `providers.mineskin.apiKey` config option (see [wiki](https://github.com/Suiranoil/SkinRestorer/wiki/Configuration#providersmineskin))
|
||||||
|
### Changed
|
||||||
|
- Migrated to MineSkin's new API V2
|
||||||
|
### Fixed
|
||||||
|
- Fixed `providers` config validation
|
||||||
|
### Removed
|
||||||
|
- Dropped support for NeoForge on Minecraft 1.20.2-1.20.4
|
||||||
|
|
||||||
|
## [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
|
## [2.0.3] - 2024-08-20
|
||||||
### Added
|
### Added
|
||||||
- Added `firstJoinSkinProvider` config option (see [wiki](https://github.com/Suiranoil/SkinRestorer/wiki/Config#firstjoinskinprovider))
|
- Added `firstJoinSkinProvider` config option (see [wiki](https://github.com/Suiranoil/SkinRestorer/wiki/Config#firstjoinskinprovider))
|
||||||
|
|||||||
@@ -1,4 +1,10 @@
|
|||||||
### Added
|
### Added
|
||||||
- Added `firstJoinSkinProvider` config option (see [wiki](https://github.com/Suiranoil/SkinRestorer/wiki/Config#firstjoinskinprovider))
|
- Added support for [SkinShuffle](https://modrinth.com/mod/skinshuffle) clients (requires FabricAPI on Fabric)
|
||||||
|
(closes [#34](https://github.com/Suiranoil/SkinRestorer/issues/34))
|
||||||
|
- Added `providers.mineskin.apiKey` config option (see [wiki](https://github.com/Suiranoil/SkinRestorer/wiki/Configuration#providersmineskin))
|
||||||
|
### Changed
|
||||||
|
- Migrated to MineSkin's new API V2
|
||||||
### Fixed
|
### Fixed
|
||||||
- Fixed ability to set config values to `null`
|
- Fixed `providers` config validation
|
||||||
|
### Removed
|
||||||
|
- Dropped support for NeoForge on Minecraft 1.20.2-1.20.4
|
||||||
|
|||||||
101
README.md
101
README.md
@@ -1,7 +1,7 @@
|
|||||||
# SkinRestorer
|
# SkinRestorer
|
||||||
|
|
||||||
<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>
|
|
||||||
<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://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>
|
||||||
|
|
||||||
A server-side mod for managing and restoring player skins.
|
A server-side mod for managing and restoring player skins.
|
||||||
|
|
||||||
@@ -9,95 +9,34 @@ A server-side mod for managing and restoring player skins.
|
|||||||
|
|
||||||
- **Set skins from Mojang Account**: Fetch and apply skins using a valid Minecraft username.
|
- **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 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.
|
- **Set skins from URL**: Fetch and apply skins from any image URL, supporting both classic (Steve) and slim (Alex) skin
|
||||||
- **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/Config)).
|
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.
|
- **Singleplayer support**: Apply skins individually for each world.
|
||||||
- **Permissions API support**
|
- **Permissions API support**
|
||||||
|
- **SkinShuffle support**: Allow players with [SkinShuffle](https://modrinth.com/mod/skinshuffle) installed to apply skins using GUI.
|
||||||
|
|
||||||
## 📜 Command Usage Guide
|
## 📜 Command Usage Guide
|
||||||
|
|
||||||
### Set Mojang skin
|
For a detailed list of available commands and their usage, please visit
|
||||||
|
the [commands wiki page](https://github.com/Suiranoil/SkinRestorer/wiki/Commands).
|
||||||
|
|
||||||
Fetch and apply skins using a valid Minecraft username.
|
## ❌ Known Incompatibilities
|
||||||
|
|
||||||
```
|
- **[Arclight](https://github.com/IzzelAliz/Arclight) (<=1.20.1)**: Trials or older versions are not compatible due to
|
||||||
/skin set mojang <username> [<targets>]
|
mixin conflicts.
|
||||||
```
|
As an alternative, consider using the [SkinsRestorer](https://www.spigotmc.org/resources/skinsrestorer.2124/) plugin.
|
||||||
|
|
||||||
- **Parameters**
|
## 🪙 Donation
|
||||||
- `<username>`: Minecraft username to fetch the skin from.
|
|
||||||
- `[<targets>]`: (Optional, server operators only) Player(s) to apply the skin to.
|
|
||||||
|
|
||||||
### Set Ely.by skin
|
If you enjoy using **SkinRestorer** and would like to support its development, you can contribute through the following
|
||||||
|
platforms:
|
||||||
|
|
||||||
Fetch and apply skins using a valid [Ely.by](https://ely.by/) username.
|
[](https://ko-fi.com/lionarius)
|
||||||
|
|
||||||
```
|
Bitcoin (BTC): `1Ndbwny8pxdnWXFgadp95fp97y5JqMJKTX`
|
||||||
/skin set ely.by <username> [<targets>]
|
USDT (TRC20): `TGXn8wrqku5KLzwPWQAeH7wgnV4UzwHEae`
|
||||||
```
|
USDT (TON): `UQAQF18Xlmx-V1oZ90C2YOju5qI7q1LgrCP5QaIUhqIELmDS`
|
||||||
|
|
||||||
- **Parameters**
|
Thank you for your generosity!
|
||||||
- `<username>`: Ely.by username to fetch the skin from.
|
|
||||||
- `[<targets>]`: (Optional, server operators only) Player(s) to apply the skin to.
|
|
||||||
|
|
||||||
### Set Web skin
|
|
||||||
|
|
||||||
Fetch and apply skins from any image URL, supporting both classic (Steve) and slim (Alex) skin models.
|
|
||||||
|
|
||||||
Uses [mineskin api](https://mineskin.org/) under the hood.
|
|
||||||
|
|
||||||
```
|
|
||||||
/skin set web (classic|slim) "<url>" [<targets>]
|
|
||||||
```
|
|
||||||
|
|
||||||
- **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.
|
|
||||||
|
|
||||||
### Refresh skin
|
|
||||||
|
|
||||||
Refetch and reapply the currently applied skins.
|
|
||||||
|
|
||||||
```
|
|
||||||
/skin refresh [<targets>]
|
|
||||||
```
|
|
||||||
|
|
||||||
- **Parameters**
|
|
||||||
- `[<targets>]`: (Optional, server operators only) Player(s) to refresh the skin for.
|
|
||||||
|
|
||||||
### Clear skin
|
|
||||||
|
|
||||||
Remove the currently applied skins.
|
|
||||||
|
|
||||||
```
|
|
||||||
/skin clear [<targets>]
|
|
||||||
```
|
|
||||||
|
|
||||||
- **Parameters**
|
|
||||||
- `[<targets>]`: (Optional, server operators only) Player(s) to clear the skin for.
|
|
||||||
|
|
||||||
### Reset skin
|
|
||||||
|
|
||||||
Reset to the default skin or remove any custom skin.
|
|
||||||
|
|
||||||
If [automatic skin fetching](https://github.com/Suiranoil/SkinRestorer/wiki/Config#fetchskinonfirstjoin) is enabled, a new skin will be fetched when the player rejoins the server.
|
|
||||||
|
|
||||||
```
|
|
||||||
/skin reset [<targets>]
|
|
||||||
```
|
|
||||||
|
|
||||||
- **Parameters**
|
|
||||||
- `[<targets>]`: (Optional, server operators only) Player(s) to reset 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
|
|
||||||
```
|
|
||||||
|
|||||||
22
build.gradle
22
build.gradle
@@ -1,13 +1,29 @@
|
|||||||
plugins {
|
plugins {
|
||||||
// see https://fabricmc.net/develop/ for new versions
|
// see https://fabricmc.net/develop/ for new versions
|
||||||
id 'fabric-loom' version '1.7-SNAPSHOT' apply false
|
id 'fabric-loom' version '1.8-SNAPSHOT' apply false
|
||||||
// see https://projects.neoforged.net/neoforged/neogradle for new versions
|
// see https://projects.neoforged.net/neoforged/neogradle for new versions
|
||||||
id 'net.neoforged.gradle.userdev' version '7.0.153' apply false
|
id 'net.neoforged.gradle.userdev' version '7.0.153' apply false
|
||||||
// see https://files.minecraftforge.net/net/minecraftforge/gradle/ForgeGradle/ for new versions
|
// see https://files.minecraftforge.net/net/minecraftforge/gradle/ForgeGradle/ for new versions
|
||||||
id 'net.minecraftforge.gradle' version '6.0.26' apply false
|
id 'net.minecraftforge.gradle' version '6.0.29' apply false
|
||||||
id 'org.parchmentmc.librarian.forgegradle' version '1.+' apply false
|
id 'org.parchmentmc.librarian.forgegradle' version '1.+' apply false
|
||||||
|
|
||||||
id 'org.spongepowered.mixin' version '0.7-SNAPSHOT' apply false
|
id 'org.spongepowered.mixin' version '0.7-SNAPSHOT' apply false
|
||||||
|
|
||||||
id 'me.modmuss50.mod-publish-plugin' version '0.6.3' apply false
|
id 'me.modmuss50.mod-publish-plugin' version '0.8.1' apply false
|
||||||
|
}
|
||||||
|
|
||||||
|
allprojects {
|
||||||
|
repositories {
|
||||||
|
exclusiveContent {
|
||||||
|
forRepository {
|
||||||
|
maven {
|
||||||
|
name = 'lionarius-repository'
|
||||||
|
url = 'https://reposilite.lionarius.ru/releases'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
filter {
|
||||||
|
includeGroupAndSubgroups('org.mineskin')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 {
|
||||||
|
|||||||
@@ -3,10 +3,10 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
configurations {
|
configurations {
|
||||||
commonJava{
|
commonJava {
|
||||||
canBeResolved = true
|
canBeResolved = true
|
||||||
}
|
}
|
||||||
commonResources{
|
commonResources {
|
||||||
canBeResolved = true
|
canBeResolved = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ publishMods {
|
|||||||
if (project.name == 'fabric')
|
if (project.name == 'fabric')
|
||||||
file = remapJar.archiveFile
|
file = remapJar.archiveFile
|
||||||
else
|
else
|
||||||
file = jar.archiveFile
|
file = tasks.named('jarJar').get().archiveFile
|
||||||
|
|
||||||
modLoaders.add(project.name)
|
modLoaders.add(project.name)
|
||||||
type = STABLE
|
type = STABLE
|
||||||
@@ -22,6 +22,9 @@ publishMods {
|
|||||||
|
|
||||||
minecraftVersions.addAll(minecraft_version_list.split(','))
|
minecraftVersions.addAll(minecraft_version_list.split(','))
|
||||||
serverRequired = true
|
serverRequired = true
|
||||||
|
|
||||||
|
if (project.name == 'fabric')
|
||||||
|
optional(fabric_optional_dependencies.split(','))
|
||||||
}
|
}
|
||||||
|
|
||||||
modrinth {
|
modrinth {
|
||||||
@@ -31,5 +34,8 @@ publishMods {
|
|||||||
accessToken = providers.environmentVariable("MODRINTH_TOKEN")
|
accessToken = providers.environmentVariable("MODRINTH_TOKEN")
|
||||||
|
|
||||||
minecraftVersions.addAll(minecraft_version_list.split(','))
|
minecraftVersions.addAll(minecraft_version_list.split(','))
|
||||||
|
|
||||||
|
if (project.name == 'fabric')
|
||||||
|
optional(fabric_optional_dependencies.split(','))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
plugins {
|
plugins {
|
||||||
id 'multiloader-common'
|
id 'multiloader-common'
|
||||||
|
|
||||||
id 'fabric-loom'
|
id 'fabric-loom'
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -11,6 +11,8 @@ dependencies {
|
|||||||
parchment("org.parchmentmc.data:parchment-${parchment_minecraft}:${parchment_version}@zip")
|
parchment("org.parchmentmc.data:parchment-${parchment_minecraft}:${parchment_version}@zip")
|
||||||
}
|
}
|
||||||
compileOnly group: 'org.spongepowered', name: 'mixin', version: '0.8.5'
|
compileOnly group: 'org.spongepowered', name: 'mixin', version: '0.8.5'
|
||||||
|
|
||||||
|
implementation("org.mineskin:java-client:${mineskin_client_version}")
|
||||||
}
|
}
|
||||||
|
|
||||||
loom {
|
loom {
|
||||||
@@ -18,7 +20,7 @@ loom {
|
|||||||
if (aw.exists()) {
|
if (aw.exists()) {
|
||||||
accessWidenerPath.set(aw)
|
accessWidenerPath.set(aw)
|
||||||
}
|
}
|
||||||
|
|
||||||
mixin {
|
mixin {
|
||||||
useLegacyMixinAp = false
|
useLegacyMixinAp = false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
fabric.loom.dontRemap = true
|
fabric.loom.dontRemap=true
|
||||||
|
|||||||
@@ -1,7 +1,11 @@
|
|||||||
package net.lionarius.skinrestorer;
|
package net.lionarius.skinrestorer;
|
||||||
|
|
||||||
import com.mojang.authlib.GameProfile;
|
import com.mojang.authlib.GameProfile;
|
||||||
|
import com.mojang.brigadier.CommandDispatcher;
|
||||||
|
import net.lionarius.skinrestorer.command.SkinCommand;
|
||||||
import net.lionarius.skinrestorer.config.Config;
|
import net.lionarius.skinrestorer.config.Config;
|
||||||
|
import net.lionarius.skinrestorer.config.provider.BuiltInProviderConfig;
|
||||||
|
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 +14,9 @@ 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.commands.CommandSourceStack;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
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,30 +60,42 @@ 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 ResourceLocation resourceLocation(String name) {
|
||||||
SkinRestorer.configDir = rootConfigDir.resolve(SkinRestorer.MOD_ID);
|
return ResourceLocation.fromNamespaceAndPath(SkinRestorer.MOD_ID, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String assetPath(String name) {
|
||||||
|
return String.format("/assets/%s/%s", SkinRestorer.MOD_ID, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void onInitialize() {
|
||||||
|
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(SkinShuffleSkinProvider.PROVIDER_NAME, SkinProvider.SKIN_SHUFFLE, false);
|
||||||
SkinRestorer.providersRegistry.register(ElyBySkinProvider.PROVIDER_NAME, SkinProvider.ELY_BY);
|
|
||||||
SkinRestorer.providersRegistry.register(MineskinSkinProvider.PROVIDER_NAME, SkinProvider.MINESKIN);
|
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());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void onServerStarted(MinecraftServer server) {
|
private static void registerDefaultSkinProvider(String defaultName, SkinProvider provider, BuiltInProviderConfig config) {
|
||||||
Path worldSkinDirectory = server.getWorldPath(LevelResource.ROOT).resolve(SkinRestorer.MOD_ID);
|
var isDefaultName = config.name().equals(defaultName);
|
||||||
FileUtils.tryMigrateOldSkinDirectory(worldSkinDirectory);
|
SkinRestorer.providersRegistry.register(defaultName, provider, config.enabled() && isDefaultName);
|
||||||
|
|
||||||
SkinRestorer.skinStorage = new SkinStorage(new SkinIO(worldSkinDirectory));
|
if (!isDefaultName && !SkinProvider.BUILTIN_PROVIDER_NAMES.contains(config.name()))
|
||||||
|
SkinRestorer.providersRegistry.register(config.name(), provider, config.enabled());
|
||||||
}
|
}
|
||||||
|
|
||||||
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();
|
||||||
|
|
||||||
public static String resource(String name) {
|
MojangSkinProvider.reload();
|
||||||
return String.format("/assets/%s/%s", SkinRestorer.MOD_ID, name);
|
ElyBySkinProvider.reload();
|
||||||
|
MineskinSkinProvider.reload();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Collection<ServerPlayer> applySkin(MinecraftServer server, Iterable<GameProfile> targets, SkinValue value, boolean save) {
|
public static Collection<ServerPlayer> applySkin(MinecraftServer server, Iterable<GameProfile> targets, SkinValue value, boolean save) {
|
||||||
@@ -86,12 +105,12 @@ public final class SkinRestorer {
|
|||||||
if (!SkinRestorer.getSkinStorage().hasSavedSkin(profile.getId()))
|
if (!SkinRestorer.getSkinStorage().hasSavedSkin(profile.getId()))
|
||||||
value = value.setOriginalValue(PlayerUtils.getPlayerSkin(profile));
|
value = value.setOriginalValue(PlayerUtils.getPlayerSkin(profile));
|
||||||
|
|
||||||
if (save)
|
|
||||||
SkinRestorer.getSkinStorage().setSkin(profile.getId(), value);
|
|
||||||
|
|
||||||
if (PlayerUtils.areSkinPropertiesEquals(value.value(), PlayerUtils.getPlayerSkin(profile)))
|
if (PlayerUtils.areSkinPropertiesEquals(value.value(), PlayerUtils.getPlayerSkin(profile)))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
if (save)
|
||||||
|
SkinRestorer.getSkinStorage().setSkin(profile.getId(), value);
|
||||||
|
|
||||||
PlayerUtils.applyRestoredSkin(profile, value.value());
|
PlayerUtils.applyRestoredSkin(profile, value.value());
|
||||||
|
|
||||||
var player = server.getPlayerList().getPlayer(profile.getId());
|
var player = server.getPlayerList().getPlayer(profile.getId());
|
||||||
@@ -116,7 +135,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())
|
||||||
@@ -137,4 +156,23 @@ public final class SkinRestorer {
|
|||||||
return Result.error(e.getMessage());
|
return Result.error(e.getMessage());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class Events {
|
||||||
|
private Events() {}
|
||||||
|
|
||||||
|
public static void onServerStarted(MinecraftServer server) {
|
||||||
|
Path worldSkinDirectory = server.getWorldPath(LevelResource.ROOT).resolve(SkinRestorer.MOD_ID);
|
||||||
|
FileUtils.tryMigrateOldSkinDirectory(SkinRestorer.getConfigDir(), worldSkinDirectory);
|
||||||
|
|
||||||
|
SkinRestorer.skinStorage = new SkinStorage(new SkinIO(worldSkinDirectory));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void onCommandRegister(CommandDispatcher<CommandSourceStack> dispatcher) {
|
||||||
|
SkinCommand.register(dispatcher);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void onPlayerDisconnect(ServerPlayer player) {
|
||||||
|
SkinRestorer.getSkinStorage().removeSkin(player.getUUID());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,8 +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()));
|
||||||
|
if (!providers.isEmpty())
|
||||||
|
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 +166,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,55 @@
|
|||||||
|
package net.lionarius.skinrestorer.compat.skinshuffle;
|
||||||
|
|
||||||
|
import net.lionarius.skinrestorer.SkinRestorer;
|
||||||
|
import net.lionarius.skinrestorer.platform.Services;
|
||||||
|
import net.lionarius.skinrestorer.skin.SkinValue;
|
||||||
|
import net.lionarius.skinrestorer.skin.provider.SkinShuffleSkinProvider;
|
||||||
|
import net.lionarius.skinrestorer.util.PlayerUtils;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraft.server.MinecraftServer;
|
||||||
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
|
public class SkinShuffleCompatibility {
|
||||||
|
|
||||||
|
public static final String MOD_ID = "skinshuffle";
|
||||||
|
|
||||||
|
private static final boolean SHOULD_APPLY = !Services.PLATFORM.isModLoaded(SkinShuffleCompatibility.MOD_ID);
|
||||||
|
|
||||||
|
private SkinShuffleCompatibility() {}
|
||||||
|
|
||||||
|
public static boolean shouldApply() {
|
||||||
|
return SkinShuffleCompatibility.SHOULD_APPLY;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ResourceLocation resourceLocation(String name) {
|
||||||
|
return ResourceLocation.fromNamespaceAndPath(SkinShuffleCompatibility.MOD_ID, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void onPlayerJoin(ServerPlayer player) {
|
||||||
|
Services.COMPATIBILITY.skinShuffle_sendHandshake(player);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void handleSkinRefresh(MinecraftServer server, ServerPlayer player, SkinShuffleSkinRefreshPayload payload) {
|
||||||
|
var property = payload.textureProperty();
|
||||||
|
|
||||||
|
if (!property.name().equals(PlayerUtils.TEXTURES_KEY))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!property.hasSignature())
|
||||||
|
return;
|
||||||
|
|
||||||
|
server.execute(() -> {
|
||||||
|
SkinRestorer.applySkin(
|
||||||
|
server,
|
||||||
|
Collections.singleton(player.getGameProfile()),
|
||||||
|
new SkinValue(SkinShuffleSkinProvider.PROVIDER_NAME, null, null, property),
|
||||||
|
!server.usesAuthentication()
|
||||||
|
);
|
||||||
|
|
||||||
|
if (server.usesAuthentication() && SkinRestorer.getSkinStorage().hasSavedSkin(player.getUUID()))
|
||||||
|
SkinRestorer.getSkinStorage().deleteSkin(player.getUUID());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package net.lionarius.skinrestorer.compat.skinshuffle;
|
||||||
|
|
||||||
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
|
import net.minecraft.network.codec.StreamCodec;
|
||||||
|
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public record SkinShuffleHandshakePayload() implements CustomPacketPayload {
|
||||||
|
|
||||||
|
public static final SkinShuffleHandshakePayload INSTANCE = new SkinShuffleHandshakePayload();
|
||||||
|
|
||||||
|
public static final CustomPacketPayload.Type<SkinShuffleHandshakePayload> PACKET_ID = new CustomPacketPayload.Type<>(SkinShuffleCompatibility.resourceLocation("handshake"));
|
||||||
|
public static final StreamCodec<FriendlyByteBuf, SkinShuffleHandshakePayload> PACKET_CODEC = StreamCodec.unit(INSTANCE);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CustomPacketPayload.@NotNull Type<? extends CustomPacketPayload> type() {
|
||||||
|
return PACKET_ID;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package net.lionarius.skinrestorer.compat.skinshuffle;
|
||||||
|
|
||||||
|
import com.mojang.authlib.properties.Property;
|
||||||
|
|
||||||
|
public interface SkinShuffleSkinRefreshPayload {
|
||||||
|
Property textureProperty();
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
package net.lionarius.skinrestorer.compat.skinshuffle;
|
||||||
|
|
||||||
|
import com.mojang.authlib.properties.Property;
|
||||||
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
|
import net.minecraft.network.codec.StreamCodec;
|
||||||
|
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public record SkinShuffleSkinRefreshV1Payload(
|
||||||
|
Property textureProperty) implements CustomPacketPayload, SkinShuffleSkinRefreshPayload {
|
||||||
|
|
||||||
|
public static final CustomPacketPayload.Type<SkinShuffleSkinRefreshV1Payload> PACKET_ID = new CustomPacketPayload.Type<>(SkinShuffleCompatibility.resourceLocation("refresh"));
|
||||||
|
public static final StreamCodec<FriendlyByteBuf, SkinShuffleSkinRefreshV1Payload> PACKET_CODEC = StreamCodec.of(
|
||||||
|
SkinShuffleSkinRefreshV1Payload::encode,
|
||||||
|
SkinShuffleSkinRefreshV1Payload::decode
|
||||||
|
);
|
||||||
|
|
||||||
|
public static void encode(FriendlyByteBuf buf, SkinShuffleSkinRefreshV1Payload value) {
|
||||||
|
var textureProperty = value.textureProperty();
|
||||||
|
|
||||||
|
buf.writeUtf(textureProperty.name());
|
||||||
|
buf.writeUtf(textureProperty.value());
|
||||||
|
buf.writeNullable(textureProperty.signature(), FriendlyByteBuf::writeUtf);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static SkinShuffleSkinRefreshV1Payload decode(FriendlyByteBuf buf) {
|
||||||
|
return new SkinShuffleSkinRefreshV1Payload(new Property(buf.readUtf(), buf.readUtf(), buf.readNullable(FriendlyByteBuf::readUtf)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull CustomPacketPayload.Type<? extends CustomPacketPayload> type() {
|
||||||
|
return PACKET_ID;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
package net.lionarius.skinrestorer.compat.skinshuffle;
|
||||||
|
|
||||||
|
import com.mojang.authlib.properties.Property;
|
||||||
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
|
import net.minecraft.network.codec.StreamCodec;
|
||||||
|
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public record SkinShuffleSkinRefreshV2Payload(
|
||||||
|
Property textureProperty) implements CustomPacketPayload, SkinShuffleSkinRefreshPayload {
|
||||||
|
|
||||||
|
public static final CustomPacketPayload.Type<SkinShuffleSkinRefreshV2Payload> PACKET_ID = new CustomPacketPayload.Type<>(SkinShuffleCompatibility.resourceLocation("skin_refresh"));
|
||||||
|
public static final StreamCodec<FriendlyByteBuf, SkinShuffleSkinRefreshV2Payload> PACKET_CODEC = StreamCodec.of(
|
||||||
|
SkinShuffleSkinRefreshV2Payload::encode,
|
||||||
|
SkinShuffleSkinRefreshV2Payload::decode
|
||||||
|
);
|
||||||
|
|
||||||
|
public static void encode(FriendlyByteBuf buf, SkinShuffleSkinRefreshV2Payload value) {
|
||||||
|
var textureProperty = value.textureProperty();
|
||||||
|
|
||||||
|
buf.writeBoolean(textureProperty.hasSignature());
|
||||||
|
buf.writeUtf(textureProperty.name());
|
||||||
|
buf.writeUtf(textureProperty.value());
|
||||||
|
if (textureProperty.hasSignature()) {
|
||||||
|
assert textureProperty.signature() != null;
|
||||||
|
|
||||||
|
buf.writeUtf(textureProperty.signature());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static SkinShuffleSkinRefreshV2Payload decode(FriendlyByteBuf buf) {
|
||||||
|
if (buf.readBoolean()) {
|
||||||
|
return new SkinShuffleSkinRefreshV2Payload(new Property(buf.readUtf(), buf.readUtf(), buf.readUtf()));
|
||||||
|
}
|
||||||
|
return new SkinShuffleSkinRefreshV2Payload(new Property(buf.readUtf(), buf.readUtf(), null));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull CustomPacketPayload.Type<? extends CustomPacketPayload> type() {
|
||||||
|
return PACKET_ID;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,46 +1,62 @@
|
|||||||
package net.lionarius.skinrestorer.config;
|
package net.lionarius.skinrestorer.config;
|
||||||
|
|
||||||
import net.lionarius.skinrestorer.SkinRestorer;
|
import net.lionarius.skinrestorer.SkinRestorer;
|
||||||
|
import net.lionarius.skinrestorer.config.provider.ProvidersConfig;
|
||||||
import net.lionarius.skinrestorer.util.FileUtils;
|
import net.lionarius.skinrestorer.util.FileUtils;
|
||||||
import net.lionarius.skinrestorer.util.JsonUtils;
|
import net.lionarius.skinrestorer.util.JsonUtils;
|
||||||
|
import net.lionarius.skinrestorer.util.gson.GsonPostProcessable;
|
||||||
|
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
public final class Config {
|
public final class Config implements GsonPostProcessable {
|
||||||
|
|
||||||
public static final String CONFIG_FILENAME = "config.json";
|
public static final String CONFIG_FILENAME = "config.json";
|
||||||
|
|
||||||
|
|
||||||
private String language = "en_us";
|
private String language = "en_us";
|
||||||
|
|
||||||
|
private boolean refreshSkinOnJoin = true;
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
@@ -54,24 +70,45 @@ public final class Config {
|
|||||||
if (config == null)
|
if (config == null)
|
||||||
config = new Config();
|
config = new Config();
|
||||||
|
|
||||||
config.verifyAndFix();
|
|
||||||
|
|
||||||
FileUtils.writeFile(path.resolve(Config.CONFIG_FILENAME), JsonUtils.toJson(config));
|
FileUtils.writeFile(path.resolve(Config.CONFIG_FILENAME), JsonUtils.toJson(config));
|
||||||
|
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void verifyAndFix() {
|
@Override
|
||||||
if (this.language == null || this.language.isEmpty())
|
public void gsonPostProcess() {
|
||||||
|
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.getMessage());
|
||||||
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package net.lionarius.skinrestorer.config.provider;
|
||||||
|
|
||||||
|
public interface BuiltInProviderConfig {
|
||||||
|
|
||||||
|
boolean enabled();
|
||||||
|
|
||||||
|
String name();
|
||||||
|
|
||||||
|
CacheConfig cache();
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package net.lionarius.skinrestorer.config.provider;
|
||||||
|
|
||||||
|
import net.lionarius.skinrestorer.SkinRestorer;
|
||||||
|
|
||||||
|
public final class CacheConfig {
|
||||||
|
private boolean enabled;
|
||||||
|
private long duration;
|
||||||
|
|
||||||
|
public CacheConfig(boolean enabled, long duration) {
|
||||||
|
this.enabled = enabled;
|
||||||
|
this.duration = duration;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean enabled() {
|
||||||
|
return enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long duration() {
|
||||||
|
return duration;
|
||||||
|
}
|
||||||
|
|
||||||
|
void validate(CacheConfig defaultValue) {
|
||||||
|
if (this.duration <= 0) {
|
||||||
|
SkinRestorer.LOGGER.warn("Cache duration is less than or equal to zero, defaulting to {}", defaultValue.duration());
|
||||||
|
this.duration = defaultValue.duration();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
package net.lionarius.skinrestorer.config.provider;
|
||||||
|
|
||||||
|
import net.lionarius.skinrestorer.SkinRestorer;
|
||||||
|
import net.lionarius.skinrestorer.skin.provider.ElyBySkinProvider;
|
||||||
|
import net.lionarius.skinrestorer.util.gson.GsonPostProcessable;
|
||||||
|
|
||||||
|
public class ElyByProviderConfig implements BuiltInProviderConfig, GsonPostProcessable {
|
||||||
|
private static final CacheConfig DEFAULT_CACHE_VALUE = new CacheConfig(true, 60);
|
||||||
|
|
||||||
|
private boolean enabled;
|
||||||
|
private String name;
|
||||||
|
private CacheConfig cache;
|
||||||
|
|
||||||
|
public ElyByProviderConfig() {
|
||||||
|
this.enabled = true;
|
||||||
|
this.name = ElyBySkinProvider.PROVIDER_NAME;
|
||||||
|
this.cache = DEFAULT_CACHE_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean enabled() {
|
||||||
|
return enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String name() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CacheConfig cache() {
|
||||||
|
return cache;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void gsonPostProcess() {
|
||||||
|
if (this.name == null || this.name.isEmpty()) {
|
||||||
|
SkinRestorer.LOGGER.warn("Ely.By provider name is null or empty, defaulting to '{}'", ElyBySkinProvider.PROVIDER_NAME);
|
||||||
|
this.name = ElyBySkinProvider.PROVIDER_NAME;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.cache == null) {
|
||||||
|
SkinRestorer.LOGGER.warn("Ely.By provider cache is null, using default");
|
||||||
|
this.cache = DEFAULT_CACHE_VALUE;
|
||||||
|
} else {
|
||||||
|
this.cache.validate(DEFAULT_CACHE_VALUE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
package net.lionarius.skinrestorer.config.provider;
|
||||||
|
|
||||||
|
import net.lionarius.skinrestorer.SkinRestorer;
|
||||||
|
import net.lionarius.skinrestorer.skin.provider.MineskinSkinProvider;
|
||||||
|
import net.lionarius.skinrestorer.util.gson.GsonPostProcessable;
|
||||||
|
|
||||||
|
public class MineskinProviderConfig implements BuiltInProviderConfig, GsonPostProcessable {
|
||||||
|
private static final CacheConfig DEFAULT_CACHE_VALUE = new CacheConfig(true, 300);
|
||||||
|
|
||||||
|
private boolean enabled;
|
||||||
|
private String name;
|
||||||
|
private CacheConfig cache;
|
||||||
|
private String apiKey;
|
||||||
|
|
||||||
|
public MineskinProviderConfig() {
|
||||||
|
this.enabled = true;
|
||||||
|
this.name = MineskinSkinProvider.PROVIDER_NAME;
|
||||||
|
this.cache = DEFAULT_CACHE_VALUE;
|
||||||
|
this.apiKey = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean enabled() {
|
||||||
|
return enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String name() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CacheConfig cache() {
|
||||||
|
return cache;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String apiKey() {
|
||||||
|
return apiKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void gsonPostProcess() {
|
||||||
|
if (this.name == null || this.name.isEmpty()) {
|
||||||
|
SkinRestorer.LOGGER.warn("Mineskin provider name is null or empty, defaulting to '{}'", MineskinSkinProvider.PROVIDER_NAME);
|
||||||
|
this.name = MineskinSkinProvider.PROVIDER_NAME;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.cache == null) {
|
||||||
|
SkinRestorer.LOGGER.warn("Mineskin cache is null, using default");
|
||||||
|
this.cache = DEFAULT_CACHE_VALUE;
|
||||||
|
} else {
|
||||||
|
this.cache.validate(DEFAULT_CACHE_VALUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.apiKey == null) {
|
||||||
|
SkinRestorer.LOGGER.warn("Mineskin API key is null, defaulting to an empty string");
|
||||||
|
this.apiKey = "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
package net.lionarius.skinrestorer.config.provider;
|
||||||
|
|
||||||
|
import net.lionarius.skinrestorer.SkinRestorer;
|
||||||
|
import net.lionarius.skinrestorer.skin.provider.MojangSkinProvider;
|
||||||
|
import net.lionarius.skinrestorer.util.gson.GsonPostProcessable;
|
||||||
|
|
||||||
|
public class MojangProviderConfig implements BuiltInProviderConfig, GsonPostProcessable {
|
||||||
|
private static final CacheConfig DEFAULT_CACHE_VALUE = new CacheConfig(true, 60);
|
||||||
|
|
||||||
|
private boolean enabled;
|
||||||
|
private String name;
|
||||||
|
private CacheConfig cache;
|
||||||
|
|
||||||
|
public MojangProviderConfig() {
|
||||||
|
this.enabled = true;
|
||||||
|
this.name = MojangSkinProvider.PROVIDER_NAME;
|
||||||
|
this.cache = DEFAULT_CACHE_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean enabled() {
|
||||||
|
return enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String name() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CacheConfig cache() {
|
||||||
|
return cache;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void gsonPostProcess() {
|
||||||
|
if (this.name == null || this.name.isEmpty()) {
|
||||||
|
SkinRestorer.LOGGER.warn("Mojang provider name is null or empty, defaulting to '{}'", MojangSkinProvider.PROVIDER_NAME);
|
||||||
|
this.name = MojangSkinProvider.PROVIDER_NAME;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.cache == null) {
|
||||||
|
SkinRestorer.LOGGER.warn("Mojang provider cache is null, using default");
|
||||||
|
this.cache = DEFAULT_CACHE_VALUE;
|
||||||
|
} else {
|
||||||
|
this.cache.validate(DEFAULT_CACHE_VALUE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
package net.lionarius.skinrestorer.config.provider;
|
||||||
|
|
||||||
|
import net.lionarius.skinrestorer.SkinRestorer;
|
||||||
|
import net.lionarius.skinrestorer.util.gson.GsonPostProcessable;
|
||||||
|
|
||||||
|
public final class ProvidersConfig implements GsonPostProcessable {
|
||||||
|
public static final ProvidersConfig DEFAULT = new ProvidersConfig(
|
||||||
|
new MojangProviderConfig(),
|
||||||
|
new ElyByProviderConfig(),
|
||||||
|
new MineskinProviderConfig()
|
||||||
|
);
|
||||||
|
|
||||||
|
private MojangProviderConfig mojang;
|
||||||
|
private ElyByProviderConfig ely_by;
|
||||||
|
private MineskinProviderConfig mineskin;
|
||||||
|
|
||||||
|
public ProvidersConfig(MojangProviderConfig mojang, ElyByProviderConfig ely_by, MineskinProviderConfig mineskin) {
|
||||||
|
this.mojang = mojang;
|
||||||
|
this.ely_by = ely_by;
|
||||||
|
this.mineskin = mineskin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MojangProviderConfig mojang() {
|
||||||
|
return this.mojang;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ElyByProviderConfig ely_by() {
|
||||||
|
return this.ely_by;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MineskinProviderConfig mineskin() {
|
||||||
|
return this.mineskin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void gsonPostProcess() {
|
||||||
|
if (this.mojang == null) {
|
||||||
|
SkinRestorer.LOGGER.warn("Mojang provider config is null, using default");
|
||||||
|
this.mojang = ProvidersConfig.DEFAULT.mojang();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.ely_by == null) {
|
||||||
|
SkinRestorer.LOGGER.warn("Ely.By provider config is null, using default");
|
||||||
|
this.ely_by = ProvidersConfig.DEFAULT.ely_by();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.mineskin == null) {
|
||||||
|
SkinRestorer.LOGGER.warn("Mineskin provider config is null, using default");
|
||||||
|
this.mineskin = ProvidersConfig.DEFAULT.mineskin();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,187 @@
|
|||||||
|
package net.lionarius.skinrestorer.mineskin;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import com.google.gson.JsonParseException;
|
||||||
|
import org.mineskin.MineSkinClientImpl;
|
||||||
|
import org.mineskin.data.CodeAndMessage;
|
||||||
|
import org.mineskin.exception.MineSkinRequestException;
|
||||||
|
import org.mineskin.exception.MineskinException;
|
||||||
|
import org.mineskin.request.RequestHandler;
|
||||||
|
import org.mineskin.response.MineSkinResponse;
|
||||||
|
import org.mineskin.response.ResponseConstructor;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.InetSocketAddress;
|
||||||
|
import java.net.ProxySelector;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.http.HttpClient;
|
||||||
|
import java.net.http.HttpRequest;
|
||||||
|
import java.net.http.HttpRequest.BodyPublishers;
|
||||||
|
import java.net.http.HttpResponse;
|
||||||
|
import java.net.http.HttpResponse.BodyHandlers;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
// copy-pasted from https://github.com/InventivetalentDev/MineskinClient/blob/master/java11/src/main/java/org/mineskin/Java11RequestHandler.java
|
||||||
|
// with some modifications to support proxy
|
||||||
|
public class Java11RequestHandler extends RequestHandler {
|
||||||
|
|
||||||
|
private final Gson gson;
|
||||||
|
private final HttpClient httpClient;
|
||||||
|
|
||||||
|
public Java11RequestHandler(String userAgent, String apiKey, int timeout, Gson gson, InetSocketAddress proxy) {
|
||||||
|
super(userAgent, apiKey, timeout, gson);
|
||||||
|
this.gson = gson;
|
||||||
|
|
||||||
|
HttpClient.Builder clientBuilder = HttpClient.newBuilder()
|
||||||
|
.connectTimeout(java.time.Duration.ofMillis(timeout));
|
||||||
|
|
||||||
|
if (userAgent != null) {
|
||||||
|
clientBuilder.followRedirects(HttpClient.Redirect.NORMAL);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (proxy != null) {
|
||||||
|
clientBuilder.proxy(ProxySelector.of(proxy));
|
||||||
|
}
|
||||||
|
|
||||||
|
this.httpClient = clientBuilder.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
private <T, R extends MineSkinResponse<T>> R wrapResponse(HttpResponse<String> response, Class<T> clazz, ResponseConstructor<T, R> constructor)
|
||||||
|
throws IOException {
|
||||||
|
String rawBody = response.body();
|
||||||
|
try {
|
||||||
|
JsonObject jsonBody = gson.fromJson(rawBody, JsonObject.class);
|
||||||
|
R wrapped = constructor.construct(
|
||||||
|
response.statusCode(),
|
||||||
|
lowercaseHeaders(response.headers().map()),
|
||||||
|
jsonBody,
|
||||||
|
gson, clazz
|
||||||
|
);
|
||||||
|
if (!wrapped.isSuccess()) {
|
||||||
|
throw new MineSkinRequestException(
|
||||||
|
wrapped.getFirstError().map(CodeAndMessage::code).orElse("request_failed"),
|
||||||
|
wrapped.getFirstError().map(CodeAndMessage::message).orElse("Request Failed"),
|
||||||
|
wrapped
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return wrapped;
|
||||||
|
} catch (JsonParseException e) {
|
||||||
|
MineSkinClientImpl.LOGGER.log(Level.WARNING, "Failed to parse response body: " + rawBody, e);
|
||||||
|
throw new MineskinException("Failed to parse response", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<String, String> lowercaseHeaders(Map<String, java.util.List<String>> headers) {
|
||||||
|
return headers.entrySet().stream()
|
||||||
|
.collect(Collectors.toMap(
|
||||||
|
entry -> entry.getKey().toLowerCase(),
|
||||||
|
entry -> String.join(", ", entry.getValue())
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T, R extends MineSkinResponse<T>> R getJson(String url, Class<T> clazz, ResponseConstructor<T, R> constructor)
|
||||||
|
throws IOException {
|
||||||
|
MineSkinClientImpl.LOGGER.fine("GET " + url);
|
||||||
|
|
||||||
|
HttpRequest.Builder requestBuilder = HttpRequest.newBuilder()
|
||||||
|
.uri(URI.create(url))
|
||||||
|
.GET()
|
||||||
|
.header("User-Agent", this.userAgent);
|
||||||
|
HttpRequest request;
|
||||||
|
if (apiKey != null) {
|
||||||
|
request = requestBuilder
|
||||||
|
.header("Authorization", "Bearer " + apiKey)
|
||||||
|
.header("Accept", "application/json").build();
|
||||||
|
} else {
|
||||||
|
request = requestBuilder.build();
|
||||||
|
}
|
||||||
|
HttpResponse<String> response;
|
||||||
|
try {
|
||||||
|
response = this.httpClient.send(request, BodyHandlers.ofString());
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
return wrapResponse(response, clazz, constructor);
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T, R extends MineSkinResponse<T>> R postJson(String url, JsonObject data, Class<T> clazz, ResponseConstructor<T, R> constructor)
|
||||||
|
throws IOException {
|
||||||
|
MineSkinClientImpl.LOGGER.fine("POST " + url);
|
||||||
|
|
||||||
|
HttpRequest.Builder requestBuilder = HttpRequest.newBuilder()
|
||||||
|
.uri(URI.create(url))
|
||||||
|
.POST(BodyPublishers.ofString(gson.toJson(data)))
|
||||||
|
.header("Content-Type", "application/json")
|
||||||
|
.header("User-Agent", this.userAgent);
|
||||||
|
HttpRequest request;
|
||||||
|
if (apiKey != null) {
|
||||||
|
request = requestBuilder
|
||||||
|
.header("Authorization", "Bearer " + apiKey)
|
||||||
|
.header("Accept", "application/json").build();
|
||||||
|
} else {
|
||||||
|
request = requestBuilder.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
HttpResponse<String> response;
|
||||||
|
try {
|
||||||
|
response = this.httpClient.send(request, BodyHandlers.ofString());
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
return wrapResponse(response, clazz, constructor);
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T, R extends MineSkinResponse<T>> R postFormDataFile(String url, String key, String filename, InputStream in, Map<String, String> data, Class<T> clazz, ResponseConstructor<T, R> constructor)
|
||||||
|
throws IOException {
|
||||||
|
MineSkinClientImpl.LOGGER.fine("POST " + url);
|
||||||
|
|
||||||
|
String boundary = "mineskin-" + System.currentTimeMillis();
|
||||||
|
StringBuilder bodyBuilder = new StringBuilder();
|
||||||
|
|
||||||
|
// add form fields
|
||||||
|
for (Map.Entry<String, String> entry : data.entrySet()) {
|
||||||
|
bodyBuilder.append("--").append(boundary).append("\r\n")
|
||||||
|
.append("Content-Disposition: form-data; name=\"").append(entry.getKey()).append("\"\r\n\r\n")
|
||||||
|
.append(entry.getValue()).append("\r\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
// add file
|
||||||
|
byte[] fileContent = in.readAllBytes();
|
||||||
|
bodyBuilder.append("--").append(boundary).append("\r\n")
|
||||||
|
.append("Content-Disposition: form-data; name=\"").append(key)
|
||||||
|
.append("\"; filename=\"").append(filename).append("\"\r\n")
|
||||||
|
.append("Content-Type: image/png\r\n\r\n");
|
||||||
|
byte[] bodyStart = bodyBuilder.toString().getBytes();
|
||||||
|
byte[] boundaryEnd = ("\r\n--" + boundary + "--\r\n").getBytes();
|
||||||
|
byte[] bodyString = new byte[bodyStart.length + fileContent.length + boundaryEnd.length];
|
||||||
|
System.arraycopy(bodyStart, 0, bodyString, 0, bodyStart.length);
|
||||||
|
System.arraycopy(fileContent, 0, bodyString, bodyStart.length, fileContent.length);
|
||||||
|
System.arraycopy(boundaryEnd, 0, bodyString, bodyStart.length + fileContent.length, boundaryEnd.length);
|
||||||
|
|
||||||
|
HttpRequest.Builder requestBuilder = HttpRequest.newBuilder()
|
||||||
|
.uri(URI.create(url))
|
||||||
|
.POST(HttpRequest.BodyPublishers.ofByteArray(bodyString))
|
||||||
|
.header("Content-Type", "multipart/form-data; boundary=" + boundary)
|
||||||
|
.header("User-Agent", this.userAgent);
|
||||||
|
HttpRequest request;
|
||||||
|
if (apiKey != null) {
|
||||||
|
request = requestBuilder
|
||||||
|
.header("Authorization", "Bearer " + apiKey)
|
||||||
|
.header("Accept", "application/json").build();
|
||||||
|
} else {
|
||||||
|
request = requestBuilder.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
HttpResponse<String> response;
|
||||||
|
try {
|
||||||
|
response = this.httpClient.send(request, BodyHandlers.ofString());
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
return wrapResponse(response, clazz, constructor);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -27,13 +27,13 @@ public abstract class PlayerListMixin {
|
|||||||
|
|
||||||
@Inject(method = "remove", at = @At("TAIL"))
|
@Inject(method = "remove", at = @At("TAIL"))
|
||||||
private void remove(ServerPlayer player, CallbackInfo ci) {
|
private void remove(ServerPlayer player, CallbackInfo ci) {
|
||||||
SkinRestorer.getSkinStorage().removeSkin(player.getUUID());
|
SkinRestorer.Events.onPlayerDisconnect(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject(method = "removeAll", at = @At("HEAD"))
|
@Inject(method = "removeAll", at = @At("HEAD"))
|
||||||
private void removeAll(CallbackInfo ci) {
|
private void removeAll(CallbackInfo ci) {
|
||||||
for (ServerPlayer player : getPlayers()) {
|
for (var player : getPlayers()) {
|
||||||
SkinRestorer.getSkinStorage().removeSkin(player.getUUID());
|
SkinRestorer.Events.onPlayerDisconnect(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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().getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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,23 @@
|
|||||||
|
package net.lionarius.skinrestorer.platform;
|
||||||
|
|
||||||
|
import net.lionarius.skinrestorer.SkinRestorer;
|
||||||
|
import net.lionarius.skinrestorer.platform.services.CompatibilityHelper;
|
||||||
|
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);
|
||||||
|
public final static CompatibilityHelper COMPATIBILITY = load(CompatibilityHelper.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,8 @@
|
|||||||
|
package net.lionarius.skinrestorer.platform.services;
|
||||||
|
|
||||||
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
|
|
||||||
|
public interface CompatibilityHelper {
|
||||||
|
|
||||||
|
void skinShuffle_sendHandshake(ServerPlayer player);
|
||||||
|
}
|
||||||
@@ -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,63 @@
|
|||||||
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 reload() {
|
||||||
|
createCache();
|
||||||
|
}
|
||||||
|
|
||||||
|
private 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 +69,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 +106,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,33 +1,85 @@
|
|||||||
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.properties.Property;
|
import com.mojang.authlib.properties.Property;
|
||||||
|
import it.unimi.dsi.fastutil.Pair;
|
||||||
|
import net.lionarius.skinrestorer.SkinRestorer;
|
||||||
|
import net.lionarius.skinrestorer.mineskin.Java11RequestHandler;
|
||||||
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 org.mineskin.MineSkinClient;
|
||||||
|
import org.mineskin.data.Variant;
|
||||||
|
import org.mineskin.data.Visibility;
|
||||||
|
import org.mineskin.request.GenerateRequest;
|
||||||
|
import org.mineskin.response.QueueResponse;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.net.InetSocketAddress;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.net.http.HttpRequest;
|
import java.time.Duration;
|
||||||
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 {
|
||||||
|
|
||||||
public static final String PROVIDER_NAME = "web";
|
public static final String PROVIDER_NAME = "web";
|
||||||
|
|
||||||
private static final URI API_URI;
|
private static final URI API_URI;
|
||||||
|
private static MineSkinClient MINESKIN_CLIENT;
|
||||||
|
|
||||||
|
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 reload() {
|
||||||
|
var config = SkinRestorer.getConfig();
|
||||||
|
var configApiKey = config.providersConfig().mineskin().apiKey();
|
||||||
|
|
||||||
|
MINESKIN_CLIENT = MineSkinClient
|
||||||
|
.builder()
|
||||||
|
.userAgent(WebUtils.USER_AGENT)
|
||||||
|
.gson(JsonUtils.GSON)
|
||||||
|
.timeout((int) Duration.ofSeconds(config.requestTimeout()).toMillis())
|
||||||
|
.requestHandler((userAgent, apiKey, timeout, gson) -> new Java11RequestHandler(
|
||||||
|
userAgent,
|
||||||
|
apiKey,
|
||||||
|
timeout,
|
||||||
|
gson,
|
||||||
|
SkinRestorer.getConfig().proxy().map(proxy -> new InetSocketAddress(proxy.host(), proxy.port())).orElse(null)
|
||||||
|
))
|
||||||
|
.apiKey(configApiKey.isEmpty() ? null : configApiKey)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
createCache();
|
||||||
|
}
|
||||||
|
|
||||||
|
private 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,33 +91,39 @@ 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 body = ("{\"variant\":\"%s\",\"name\":\"%s\",\"visibility\":%d,\"url\":\"%s\"}")
|
var mineskinVariant = switch (variant) {
|
||||||
.formatted(variant.toString(), "none", 0, url);
|
case CLASSIC -> Variant.CLASSIC;
|
||||||
|
case SLIM -> Variant.SLIM;
|
||||||
|
};
|
||||||
|
|
||||||
var request = HttpRequest.newBuilder()
|
var request = GenerateRequest.url(uri)
|
||||||
.uri(MineskinSkinProvider.API_URI.resolve("generate/url"))
|
.variant(mineskinVariant)
|
||||||
.POST(HttpRequest.BodyPublishers.ofString(body))
|
.name("skinrestorer-skin")
|
||||||
.header("Content-Type", "application/json")
|
.visibility(Visibility.UNLISTED);
|
||||||
.build();
|
|
||||||
|
|
||||||
var response = WebUtils.executeRequest(request);
|
var skin = MINESKIN_CLIENT.queue().submit(request)
|
||||||
WebUtils.throwOnClientErrors(response);
|
.thenApply(QueueResponse::getJob)
|
||||||
|
.thenCompose(jobInfo -> jobInfo.waitForCompletion(MINESKIN_CLIENT))
|
||||||
|
.thenCompose(jobReference -> jobReference.getOrLoadSkin(MINESKIN_CLIENT))
|
||||||
|
.join();
|
||||||
|
|
||||||
if (response.statusCode() != 200)
|
return Optional.of(new Property(
|
||||||
throw new IllegalArgumentException("could not get mineskin skin");
|
PlayerUtils.TEXTURES_KEY,
|
||||||
|
skin.texture().data().value(),
|
||||||
return JsonUtils.parseJson(response.body());
|
skin.texture().data().signature()
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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,47 @@ 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 reload() {
|
||||||
|
createCache();
|
||||||
|
}
|
||||||
|
|
||||||
|
private 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 +91,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 +130,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 +148,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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,20 +1,31 @@
|
|||||||
package net.lionarius.skinrestorer.skin.provider;
|
package net.lionarius.skinrestorer.skin.provider;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.mojang.authlib.properties.Property;
|
import com.mojang.authlib.properties.Property;
|
||||||
import net.lionarius.skinrestorer.skin.SkinVariant;
|
import net.lionarius.skinrestorer.skin.SkinVariant;
|
||||||
import net.lionarius.skinrestorer.util.Result;
|
import net.lionarius.skinrestorer.util.Result;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public interface SkinProvider {
|
public interface SkinProvider {
|
||||||
EmptySkinProvider EMPTY = new EmptySkinProvider();
|
EmptySkinProvider EMPTY = new EmptySkinProvider();
|
||||||
MojangSkinProvider MOJANG = new MojangSkinProvider();
|
MojangSkinProvider MOJANG = new MojangSkinProvider();
|
||||||
ElyBySkinProvider ELY_BY = new ElyBySkinProvider();
|
ElyBySkinProvider ELY_BY = new ElyBySkinProvider();
|
||||||
MineskinSkinProvider MINESKIN = new MineskinSkinProvider();
|
MineskinSkinProvider MINESKIN = new MineskinSkinProvider();
|
||||||
|
SkinShuffleSkinProvider SKIN_SHUFFLE = new SkinShuffleSkinProvider();
|
||||||
|
|
||||||
|
Set<String> BUILTIN_PROVIDER_NAMES = ImmutableSet.of(
|
||||||
|
EmptySkinProvider.PROVIDER_NAME,
|
||||||
|
MojangSkinProvider.PROVIDER_NAME,
|
||||||
|
ElyBySkinProvider.PROVIDER_NAME,
|
||||||
|
MineskinSkinProvider.PROVIDER_NAME,
|
||||||
|
SkinShuffleSkinProvider.PROVIDER_NAME
|
||||||
|
);
|
||||||
|
|
||||||
String getArgumentName();
|
String getArgumentName();
|
||||||
|
|
||||||
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));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package net.lionarius.skinrestorer.skin.provider;
|
||||||
|
|
||||||
|
import com.mojang.authlib.properties.Property;
|
||||||
|
import net.lionarius.skinrestorer.skin.SkinVariant;
|
||||||
|
import net.lionarius.skinrestorer.util.Result;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public final class SkinShuffleSkinProvider implements SkinProvider {
|
||||||
|
|
||||||
|
public static final String PROVIDER_NAME = "skinshuffle";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getArgumentName() {
|
||||||
|
return "unsupported";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasVariantSupport() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result<Optional<Property>, Exception> fetchSkin(String argument, SkinVariant variant) {
|
||||||
|
return Result.error(new UnsupportedOperationException("SkinShuffle Provider does not support fetching skins"));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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,27 +18,31 @@ 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,7 +55,7 @@ public final class FileUtils {
|
|||||||
return StringUtils.readString(reader);
|
return StringUtils.readString(reader);
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
SkinRestorer.LOGGER.error("failed to read resource", e);
|
SkinRestorer.LOGGER.error("Failed to read resource", e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -62,7 +67,7 @@ public final class FileUtils {
|
|||||||
|
|
||||||
return Files.readString(file);
|
return Files.readString(file);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
SkinRestorer.LOGGER.error("failed to read file", e);
|
SkinRestorer.LOGGER.error("Failed to read file", e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -78,7 +83,7 @@ public final class FileUtils {
|
|||||||
|
|
||||||
Files.writeString(file, content);
|
Files.writeString(file, content);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
SkinRestorer.LOGGER.error("failed to write file", e);
|
SkinRestorer.LOGGER.error("Failed to write file", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,7 +92,7 @@ public final class FileUtils {
|
|||||||
if (Files.exists(file))
|
if (Files.exists(file))
|
||||||
Files.delete(file);
|
Files.delete(file);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
SkinRestorer.LOGGER.error("failed to delete file", e);
|
SkinRestorer.LOGGER.error("Failed to delete file", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,30 @@
|
|||||||
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 net.lionarius.skinrestorer.util.gson.PostProcessingEnabler;
|
||||||
|
|
||||||
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();
|
public static final Gson GSON = new GsonBuilder()
|
||||||
|
.registerTypeAdapterFactory(new PostProcessingEnabler())
|
||||||
|
.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 +45,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) {
|
||||||
@@ -42,7 +56,7 @@ public final class JsonUtils {
|
|||||||
|
|
||||||
return json;
|
return json;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
SkinRestorer.LOGGER.error(e.toString());
|
SkinRestorer.LOGGER.error("Could not parse skin property", e);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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, false));
|
player.connection.send(new ClientboundUpdateMobEffectPacket(player.getId(), effect, false));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package net.lionarius.skinrestorer.util.gson;
|
||||||
|
|
||||||
|
public interface GsonPostProcessable {
|
||||||
|
void gsonPostProcess();
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
package net.lionarius.skinrestorer.util.gson;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.TypeAdapter;
|
||||||
|
import com.google.gson.TypeAdapterFactory;
|
||||||
|
import com.google.gson.reflect.TypeToken;
|
||||||
|
import com.google.gson.stream.JsonReader;
|
||||||
|
import com.google.gson.stream.JsonWriter;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class PostProcessingEnabler implements TypeAdapterFactory {
|
||||||
|
@Override
|
||||||
|
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
|
||||||
|
var adapter = gson.getDelegateAdapter(this, type);
|
||||||
|
|
||||||
|
return new TypeAdapter<>() {
|
||||||
|
@Override
|
||||||
|
public void write(JsonWriter out, T value) throws IOException {
|
||||||
|
adapter.write(out, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public T read(JsonReader in) throws IOException {
|
||||||
|
var value = adapter.read(in);
|
||||||
|
|
||||||
|
if (value instanceof GsonPostProcessable postProcessable)
|
||||||
|
postProcessable.gsonPostProcess();
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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": "配置已重新載入"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,10 +5,10 @@
|
|||||||
"compatibilityLevel": "JAVA_8",
|
"compatibilityLevel": "JAVA_8",
|
||||||
"refmap": "${mod_id}.refmap.json",
|
"refmap": "${mod_id}.refmap.json",
|
||||||
"mixins": [
|
"mixins": [
|
||||||
|
"ChunkMapAccessor",
|
||||||
"PlayerListMixin",
|
"PlayerListMixin",
|
||||||
"ServerLoginPacketListenerImplMixin",
|
"ServerLoginPacketListenerImplMixin",
|
||||||
"ChunkMapAccessor",
|
"TrackedEntityAccessorInvoker"
|
||||||
"TrackedEntityMixin"
|
|
||||||
],
|
],
|
||||||
"injectors": {
|
"injectors": {
|
||||||
"defaultRequire": 1
|
"defaultRequire": 1
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
plugins {
|
plugins {
|
||||||
id 'multiloader-loader'
|
id 'multiloader-loader'
|
||||||
|
|
||||||
id 'fabric-loom'
|
id 'fabric-loom'
|
||||||
|
|
||||||
id 'multiloader-publish'
|
id 'multiloader-publish'
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
minecraft "com.mojang:minecraft:${minecraft_version}"
|
minecraft "com.mojang:minecraft:${minecraft_version}"
|
||||||
mappings loom.layered {
|
mappings loom.layered {
|
||||||
@@ -12,6 +13,10 @@ dependencies {
|
|||||||
parchment("org.parchmentmc.data:parchment-${parchment_minecraft}:${parchment_version}@zip")
|
parchment("org.parchmentmc.data:parchment-${parchment_minecraft}:${parchment_version}@zip")
|
||||||
}
|
}
|
||||||
modImplementation "net.fabricmc:fabric-loader:${fabric_loader_version}"
|
modImplementation "net.fabricmc:fabric-loader:${fabric_loader_version}"
|
||||||
|
|
||||||
|
modCompileOnly "net.fabricmc.fabric-api:fabric-api:${fabric_api_version}"
|
||||||
|
|
||||||
|
include implementation("org.mineskin:java-client:${mineskin_client_version}")
|
||||||
}
|
}
|
||||||
|
|
||||||
loom {
|
loom {
|
||||||
@@ -19,11 +24,11 @@ loom {
|
|||||||
if (aw.exists()) {
|
if (aw.exists()) {
|
||||||
accessWidenerPath.set(aw)
|
accessWidenerPath.set(aw)
|
||||||
}
|
}
|
||||||
|
|
||||||
mixin {
|
mixin {
|
||||||
defaultRefmapName.set("${mod_id}.refmap.json")
|
defaultRefmapName.set("${mod_id}.refmap.json")
|
||||||
}
|
}
|
||||||
|
|
||||||
runs {
|
runs {
|
||||||
client {
|
client {
|
||||||
client()
|
client()
|
||||||
|
|||||||
@@ -1,12 +1,19 @@
|
|||||||
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;
|
||||||
|
import net.lionarius.skinrestorer.compat.skinshuffle.SkinShuffleCompatibility;
|
||||||
|
import net.lionarius.skinrestorer.platform.Services;
|
||||||
|
|
||||||
public final class SkinRestorerFabric implements ModInitializer {
|
public final class SkinRestorerFabric implements ModInitializer {
|
||||||
|
|
||||||
|
public static final boolean FABRIC_API_LOADED = Services.PLATFORM.isModLoaded("fabric-api");
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onInitialize() {
|
public void onInitialize() {
|
||||||
SkinRestorer.onInitialize(FabricLoader.getInstance().getConfigDir());
|
SkinRestorer.onInitialize();
|
||||||
|
|
||||||
|
if (SkinShuffleCompatibility.shouldApply())
|
||||||
|
net.lionarius.skinrestorer.fabric.compat.skinshuffle.SkinShuffleCompatibility.initialize();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
package net.lionarius.skinrestorer.fabric.compat.skinshuffle;
|
||||||
|
|
||||||
|
import net.fabricmc.fabric.api.networking.v1.PayloadTypeRegistry;
|
||||||
|
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
|
||||||
|
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
|
||||||
|
import net.lionarius.skinrestorer.SkinRestorer;
|
||||||
|
import net.lionarius.skinrestorer.compat.skinshuffle.SkinShuffleHandshakePayload;
|
||||||
|
import net.lionarius.skinrestorer.compat.skinshuffle.SkinShuffleSkinRefreshPayload;
|
||||||
|
import net.lionarius.skinrestorer.compat.skinshuffle.SkinShuffleSkinRefreshV1Payload;
|
||||||
|
import net.lionarius.skinrestorer.compat.skinshuffle.SkinShuffleSkinRefreshV2Payload;
|
||||||
|
import net.lionarius.skinrestorer.fabric.SkinRestorerFabric;
|
||||||
|
|
||||||
|
public final class SkinShuffleCompatibility {
|
||||||
|
|
||||||
|
private SkinShuffleCompatibility() {}
|
||||||
|
|
||||||
|
public static void initialize() {
|
||||||
|
if (!SkinRestorerFabric.FABRIC_API_LOADED) {
|
||||||
|
SkinRestorer.LOGGER.warn("fabric-api is not loaded, SkinShuffle compatibility will not be available");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
PayloadTypeRegistry.playS2C().register(SkinShuffleHandshakePayload.PACKET_ID, SkinShuffleHandshakePayload.PACKET_CODEC);
|
||||||
|
PayloadTypeRegistry.playC2S().register(SkinShuffleSkinRefreshV1Payload.PACKET_ID, SkinShuffleSkinRefreshV1Payload.PACKET_CODEC);
|
||||||
|
PayloadTypeRegistry.playC2S().register(SkinShuffleSkinRefreshV2Payload.PACKET_ID, SkinShuffleSkinRefreshV2Payload.PACKET_CODEC);
|
||||||
|
|
||||||
|
ServerPlayConnectionEvents.JOIN.register((handler, sender, server) -> net.lionarius.skinrestorer.compat.skinshuffle.SkinShuffleCompatibility.onPlayerJoin(handler.getPlayer()));
|
||||||
|
|
||||||
|
ServerPlayNetworking.registerGlobalReceiver(SkinShuffleSkinRefreshV1Payload.PACKET_ID, SkinShuffleCompatibility::handleSkinRefreshPacket);
|
||||||
|
|
||||||
|
ServerPlayNetworking.registerGlobalReceiver(SkinShuffleSkinRefreshV2Payload.PACKET_ID, SkinShuffleCompatibility::handleSkinRefreshPacket);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void handleSkinRefreshPacket(SkinShuffleSkinRefreshPayload payload, ServerPlayNetworking.Context context) {
|
||||||
|
net.lionarius.skinrestorer.compat.skinshuffle.SkinShuffleCompatibility.handleSkinRefresh(context.player().getServer(), context.player(), payload);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package net.lionarius.skinrestorer.fabric.mixin;
|
package net.lionarius.skinrestorer.fabric.mixin;
|
||||||
|
|
||||||
import com.mojang.brigadier.CommandDispatcher;
|
import com.mojang.brigadier.CommandDispatcher;
|
||||||
import net.lionarius.skinrestorer.command.SkinCommand;
|
import net.lionarius.skinrestorer.SkinRestorer;
|
||||||
import net.minecraft.commands.CommandBuildContext;
|
import net.minecraft.commands.CommandBuildContext;
|
||||||
import net.minecraft.commands.CommandSourceStack;
|
import net.minecraft.commands.CommandSourceStack;
|
||||||
import net.minecraft.commands.Commands;
|
import net.minecraft.commands.Commands;
|
||||||
@@ -21,6 +21,6 @@ public abstract class CommandsMixin {
|
|||||||
@Inject(method = "<init>", at = @At(value = "INVOKE",
|
@Inject(method = "<init>", at = @At(value = "INVOKE",
|
||||||
target = "Lnet/minecraft/server/commands/AdvancementCommands;register(Lcom/mojang/brigadier/CommandDispatcher;)V"))
|
target = "Lnet/minecraft/server/commands/AdvancementCommands;register(Lcom/mojang/brigadier/CommandDispatcher;)V"))
|
||||||
private void init(Commands.CommandSelection environment, CommandBuildContext commandRegistryAccess, CallbackInfo ci) {
|
private void init(Commands.CommandSelection environment, CommandBuildContext commandRegistryAccess, CallbackInfo ci) {
|
||||||
SkinCommand.register(dispatcher);
|
SkinRestorer.Events.onCommandRegister(dispatcher);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,6 @@ public abstract class MinecraftServerMixin {
|
|||||||
@Inject(method = "runServer",
|
@Inject(method = "runServer",
|
||||||
at = @At(value = "INVOKE", target = "Lnet/minecraft/Util;getNanos()J", ordinal = 0))
|
at = @At(value = "INVOKE", target = "Lnet/minecraft/Util;getNanos()J", ordinal = 0))
|
||||||
private void onServerStarted(CallbackInfo ci) {
|
private void onServerStarted(CallbackInfo ci) {
|
||||||
SkinRestorer.onServerStarted((MinecraftServer) (Object) this);
|
SkinRestorer.Events.onServerStarted((MinecraftServer) (Object) this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package net.lionarius.skinrestorer.fabric.platform;
|
||||||
|
|
||||||
|
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
|
||||||
|
import net.lionarius.skinrestorer.compat.skinshuffle.SkinShuffleHandshakePayload;
|
||||||
|
import net.lionarius.skinrestorer.platform.services.CompatibilityHelper;
|
||||||
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
|
|
||||||
|
public final class FabricCompatibilityHelper implements CompatibilityHelper {
|
||||||
|
@Override
|
||||||
|
public void skinShuffle_sendHandshake(ServerPlayer player) {
|
||||||
|
ServerPlayNetworking.send(player, SkinShuffleHandshakePayload.INSTANCE);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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.FabricCompatibilityHelper
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
net.lionarius.skinrestorer.fabric.platform.FabricPlatformHelper
|
||||||
@@ -28,5 +28,8 @@
|
|||||||
"fabricloader": ">=${fabric_loader_version}",
|
"fabricloader": ">=${fabric_loader_version}",
|
||||||
"minecraft": ">=${minecraft_version}",
|
"minecraft": ">=${minecraft_version}",
|
||||||
"java": ">=${java_version}"
|
"java": ">=${java_version}"
|
||||||
|
},
|
||||||
|
"suggests": {
|
||||||
|
"fabric-api": "*"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ plugins {
|
|||||||
id 'multiloader-loader'
|
id 'multiloader-loader'
|
||||||
id 'idea'
|
id 'idea'
|
||||||
id 'eclipse'
|
id 'eclipse'
|
||||||
|
|
||||||
id 'net.minecraftforge.gradle'
|
id 'net.minecraftforge.gradle'
|
||||||
id 'org.parchmentmc.librarian.forgegradle'
|
id 'org.parchmentmc.librarian.forgegradle'
|
||||||
id 'org.spongepowered.mixin'
|
id 'org.spongepowered.mixin'
|
||||||
@@ -15,6 +15,14 @@ mixin {
|
|||||||
config "${mod_id}.mixins.json"
|
config "${mod_id}.mixins.json"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
jarJar.enable()
|
||||||
|
|
||||||
|
tasks.named('jarJar') {
|
||||||
|
archiveClassifier = ''
|
||||||
|
}
|
||||||
|
|
||||||
|
jar.finalizedBy('jarJar')
|
||||||
|
|
||||||
minecraft {
|
minecraft {
|
||||||
mappings channel: 'parchment', version: "${parchment_version}-${parchment_minecraft}"
|
mappings channel: 'parchment', version: "${parchment_version}-${parchment_minecraft}"
|
||||||
|
|
||||||
@@ -60,6 +68,10 @@ dependencies {
|
|||||||
|
|
||||||
annotationProcessor('org.spongepowered:mixin:0.8.5-SNAPSHOT:processor')
|
annotationProcessor('org.spongepowered:mixin:0.8.5-SNAPSHOT:processor')
|
||||||
implementation('net.sf.jopt-simple:jopt-simple:5.0.4') { version { strictly '5.0.4' } }
|
implementation('net.sf.jopt-simple:jopt-simple:5.0.4') { version { strictly '5.0.4' } }
|
||||||
|
|
||||||
|
minecraftLibrary(jarJar(group: 'org.mineskin', name: 'java-client', version: mineskin_client_version)) {
|
||||||
|
jarJar.ranged(it, "[${mineskin_client_version},)")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// for some reason mixin plugin does not add 'MixinConfigs' to MANIFEST.MF so we do it manually
|
// for some reason mixin plugin does not add 'MixinConfigs' to MANIFEST.MF so we do it manually
|
||||||
|
|||||||
@@ -1,31 +1,30 @@
|
|||||||
package net.lionarius.skinrestorer.forge;
|
package net.lionarius.skinrestorer.forge;
|
||||||
|
|
||||||
import net.lionarius.skinrestorer.SkinRestorer;
|
import net.lionarius.skinrestorer.SkinRestorer;
|
||||||
import net.lionarius.skinrestorer.command.SkinCommand;
|
import net.lionarius.skinrestorer.compat.skinshuffle.SkinShuffleCompatibility;
|
||||||
import net.minecraftforge.common.MinecraftForge;
|
|
||||||
import net.minecraftforge.event.RegisterCommandsEvent;
|
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)
|
||||||
public final class SkinRestorerForge {
|
public final class SkinRestorerForge {
|
||||||
|
|
||||||
public SkinRestorerForge() {
|
public SkinRestorerForge() {
|
||||||
MinecraftForge.EVENT_BUS.register(SkinRestorerForge.class);
|
SkinRestorer.onInitialize();
|
||||||
|
|
||||||
SkinRestorer.onInitialize(FMLPaths.CONFIGDIR.get());
|
if (SkinShuffleCompatibility.shouldApply())
|
||||||
|
net.lionarius.skinrestorer.forge.compat.skinshuffle.SkinShuffleCompatibility.initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public static void onCommandRegister(RegisterCommandsEvent event) {
|
public static void onCommandRegister(RegisterCommandsEvent event) {
|
||||||
SkinCommand.register(event.getDispatcher());
|
SkinRestorer.Events.onCommandRegister(event.getDispatcher());
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public static void onServerStarted(ServerStartedEvent event) {
|
public static void onServerStarted(ServerStartedEvent event) {
|
||||||
SkinRestorer.onServerStarted(event.getServer());
|
SkinRestorer.Events.onServerStarted(event.getServer());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package net.lionarius.skinrestorer.forge.compat.skinshuffle;
|
||||||
|
|
||||||
|
import net.minecraftforge.common.MinecraftForge;
|
||||||
|
|
||||||
|
public final class SkinShuffleCompatibility {
|
||||||
|
|
||||||
|
private SkinShuffleCompatibility() {}
|
||||||
|
|
||||||
|
public static void initialize() {
|
||||||
|
MinecraftForge.EVENT_BUS.register(SkinShuffleGameEventHandler.class);
|
||||||
|
|
||||||
|
SkinShufflePacketHandler.initialize();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package net.lionarius.skinrestorer.forge.compat.skinshuffle;
|
||||||
|
|
||||||
|
import net.lionarius.skinrestorer.compat.skinshuffle.SkinShuffleCompatibility;
|
||||||
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
|
import net.minecraftforge.event.entity.player.PlayerEvent;
|
||||||
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||||
|
|
||||||
|
public final class SkinShuffleGameEventHandler {
|
||||||
|
|
||||||
|
private SkinShuffleGameEventHandler() {}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public static void onPlayerLoggedIn(PlayerEvent.PlayerLoggedInEvent event) {
|
||||||
|
SkinShuffleCompatibility.onPlayerJoin((ServerPlayer) event.getEntity());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
package net.lionarius.skinrestorer.forge.compat.skinshuffle;
|
||||||
|
|
||||||
|
import net.lionarius.skinrestorer.SkinRestorer;
|
||||||
|
import net.lionarius.skinrestorer.compat.skinshuffle.SkinShuffleCompatibility;
|
||||||
|
import net.lionarius.skinrestorer.compat.skinshuffle.*;
|
||||||
|
import net.minecraft.network.Connection;
|
||||||
|
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
|
||||||
|
import net.minecraftforge.event.network.CustomPayloadEvent;
|
||||||
|
import net.minecraftforge.network.Channel;
|
||||||
|
import net.minecraftforge.network.ChannelBuilder;
|
||||||
|
|
||||||
|
public class SkinShufflePacketHandler {
|
||||||
|
private SkinShufflePacketHandler() {
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final Channel<CustomPacketPayload> INSTANCE = ChannelBuilder
|
||||||
|
.named(SkinRestorer.resourceLocation("skin_shuffle_compat"))
|
||||||
|
.optional()
|
||||||
|
.payloadChannel()
|
||||||
|
.any()
|
||||||
|
.clientbound()
|
||||||
|
.add(SkinShuffleHandshakePayload.PACKET_ID, SkinShuffleHandshakePayload.PACKET_CODEC, (payload, context) -> {
|
||||||
|
})
|
||||||
|
.serverbound()
|
||||||
|
.add(SkinShuffleSkinRefreshV1Payload.PACKET_ID, SkinShuffleSkinRefreshV1Payload.PACKET_CODEC, SkinShufflePacketHandler::handleSkinRefreshPacket)
|
||||||
|
.add(SkinShuffleSkinRefreshV2Payload.PACKET_ID, SkinShuffleSkinRefreshV2Payload.PACKET_CODEC, SkinShufflePacketHandler::handleSkinRefreshPacket)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
protected static void initialize() {
|
||||||
|
// NO-OP
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void sendHandshake(Connection connection) {
|
||||||
|
INSTANCE.send(SkinShuffleHandshakePayload.INSTANCE, connection);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void handleSkinRefreshPacket(SkinShuffleSkinRefreshPayload payload, CustomPayloadEvent.Context context) {
|
||||||
|
var sender = context.getSender();
|
||||||
|
|
||||||
|
if (!context.isServerSide() || sender == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
SkinShuffleCompatibility.handleSkinRefresh(sender.getServer(), sender, payload);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package net.lionarius.skinrestorer.forge.platform;
|
||||||
|
|
||||||
|
import net.lionarius.skinrestorer.forge.compat.skinshuffle.SkinShufflePacketHandler;
|
||||||
|
import net.lionarius.skinrestorer.platform.services.CompatibilityHelper;
|
||||||
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
|
|
||||||
|
public final class ForgeCompatibilityHelper implements CompatibilityHelper {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void skinShuffle_sendHandshake(ServerPlayer player) {
|
||||||
|
SkinShufflePacketHandler.sendHandshake(player.connection.getConnection());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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.ForgeCompatibilityHelper
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
net.lionarius.skinrestorer.forge.platform.ForgePlatformHelper
|
||||||
@@ -1,31 +1,32 @@
|
|||||||
# 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
|
||||||
java_version=21
|
java_version=21
|
||||||
|
|
||||||
# Common
|
# Common
|
||||||
minecraft_version=1.21
|
minecraft_version=1.21
|
||||||
minecraft_version_list=1.21
|
minecraft_version_list=1.21,1.21.1,1.21.2,1.21.3
|
||||||
minecraft_version_range=[1.21, 1.22)
|
minecraft_version_range=[1.21, 1.22)
|
||||||
mod_id=skinrestorer
|
mod_id=skinrestorer
|
||||||
mod_name=SkinRestorer
|
mod_name=SkinRestorer
|
||||||
mod_version=2.0.3
|
mod_version=2.2.0
|
||||||
mod_author=Lionarius
|
mod_author=Lionarius
|
||||||
mod_homepage=https://www.curseforge.com/minecraft/mc-mods/skinrestorer
|
mod_homepage=https://modrinth.com/mod/skinrestorer
|
||||||
mod_sources=https://github.com/Suiranoil/SkinRestorer
|
mod_sources=https://github.com/Suiranoil/SkinRestorer
|
||||||
mod_issues=https://github.com/Suiranoil/SkinRestorer/issues
|
mod_issues=https://github.com/Suiranoil/SkinRestorer/issues
|
||||||
license=MIT
|
license=MIT
|
||||||
credits=
|
credits=
|
||||||
description=A server-side mod for managing skins.
|
description=A server-side mod for managing skins.
|
||||||
|
|
||||||
|
mineskin_client_version=3.0.1-SNAPSHOT
|
||||||
|
|
||||||
# ParchmentMC mappings, see https://parchmentmc.org/docs/getting-started#choose-a-version for new versions
|
# ParchmentMC mappings, see https://parchmentmc.org/docs/getting-started#choose-a-version for new versions
|
||||||
parchment_minecraft=1.21
|
parchment_minecraft=1.21
|
||||||
parchment_version=2024.07.28
|
parchment_version=2024.11.10
|
||||||
|
|
||||||
# Fabric, see https://fabricmc.net/develop/ for new versions
|
# Fabric, see https://fabricmc.net/develop/ for new versions
|
||||||
fabric_loader_version=0.15.0
|
fabric_loader_version=0.15.0
|
||||||
|
fabric_api_version=0.100.1+1.21
|
||||||
|
fabric_optional_dependencies=fabric-api
|
||||||
|
|
||||||
# Forge, see https://files.minecraftforge.net/net/minecraftforge/forge/ for new versions
|
# Forge, see https://files.minecraftforge.net/net/minecraftforge/forge/ for new versions
|
||||||
forge_version=51.0.0
|
forge_version=51.0.0
|
||||||
|
|||||||
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Binary file not shown.
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,6 +1,6 @@
|
|||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
|
||||||
networkTimeout=10000
|
networkTimeout=10000
|
||||||
validateDistributionUrl=true
|
validateDistributionUrl=true
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
|
|||||||
5
gradlew
vendored
5
gradlew
vendored
@@ -15,6 +15,8 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
#
|
#
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
#
|
||||||
|
|
||||||
##############################################################################
|
##############################################################################
|
||||||
#
|
#
|
||||||
@@ -84,7 +86,8 @@ done
|
|||||||
# shellcheck disable=SC2034
|
# shellcheck disable=SC2034
|
||||||
APP_BASE_NAME=${0##*/}
|
APP_BASE_NAME=${0##*/}
|
||||||
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
||||||
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
|
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
|
||||||
|
' "$PWD" ) || exit
|
||||||
|
|
||||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||||
MAX_FD=maximum
|
MAX_FD=maximum
|
||||||
|
|||||||
2
gradlew.bat
vendored
2
gradlew.bat
vendored
@@ -13,6 +13,8 @@
|
|||||||
@rem See the License for the specific language governing permissions and
|
@rem See the License for the specific language governing permissions and
|
||||||
@rem limitations under the License.
|
@rem limitations under the License.
|
||||||
@rem
|
@rem
|
||||||
|
@rem SPDX-License-Identifier: Apache-2.0
|
||||||
|
@rem
|
||||||
|
|
||||||
@if "%DEBUG%"=="" @echo off
|
@if "%DEBUG%"=="" @echo off
|
||||||
@rem ##########################################################################
|
@rem ##########################################################################
|
||||||
|
|||||||
@@ -14,6 +14,26 @@ if (at.exists()) {
|
|||||||
minecraft.accessTransformers.file(at)
|
minecraft.accessTransformers.file(at)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
jarJar.enable()
|
||||||
|
|
||||||
|
tasks.named('jar') {
|
||||||
|
archiveClassifier = 'thin'
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.named('jarJar') {
|
||||||
|
archiveClassifier = ''
|
||||||
|
}
|
||||||
|
|
||||||
|
jar.finalizedBy('jarJar')
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation "net.neoforged:neoforge:${neoforge_version}"
|
||||||
|
|
||||||
|
implementation(jarJar(group: 'org.mineskin', name: 'java-client', version: mineskin_client_version)) {
|
||||||
|
jarJar.ranged(it, "[${mineskin_client_version},)")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
subsystems {
|
subsystems {
|
||||||
parchment {
|
parchment {
|
||||||
minecraftVersion = parchment_minecraft
|
minecraftVersion = parchment_minecraft
|
||||||
@@ -36,7 +56,3 @@ runs {
|
|||||||
workingDirectory = file('../run/server')
|
workingDirectory = file('../run/server')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
|
||||||
implementation "net.neoforged:neoforge:${neoforge_version}"
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,12 +1,10 @@
|
|||||||
package net.lionarius.skinrestorer.neoforge;
|
package net.lionarius.skinrestorer.neoforge;
|
||||||
|
|
||||||
import net.lionarius.skinrestorer.SkinRestorer;
|
import net.lionarius.skinrestorer.SkinRestorer;
|
||||||
import net.lionarius.skinrestorer.command.SkinCommand;
|
import net.lionarius.skinrestorer.compat.skinshuffle.SkinShuffleCompatibility;
|
||||||
import net.neoforged.bus.api.SubscribeEvent;
|
import net.neoforged.bus.api.SubscribeEvent;
|
||||||
import net.neoforged.fml.common.EventBusSubscriber;
|
import net.neoforged.fml.common.EventBusSubscriber;
|
||||||
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.event.RegisterCommandsEvent;
|
import net.neoforged.neoforge.event.RegisterCommandsEvent;
|
||||||
import net.neoforged.neoforge.event.server.ServerStartedEvent;
|
import net.neoforged.neoforge.event.server.ServerStartedEvent;
|
||||||
|
|
||||||
@@ -15,18 +13,19 @@ import net.neoforged.neoforge.event.server.ServerStartedEvent;
|
|||||||
public final class SkinRestorerNeoForge {
|
public final class SkinRestorerNeoForge {
|
||||||
|
|
||||||
public SkinRestorerNeoForge() {
|
public SkinRestorerNeoForge() {
|
||||||
NeoForge.EVENT_BUS.register(SkinRestorerNeoForge.class);
|
SkinRestorer.onInitialize();
|
||||||
|
|
||||||
SkinRestorer.onInitialize(FMLPaths.CONFIGDIR.get());
|
if (SkinShuffleCompatibility.shouldApply())
|
||||||
|
net.lionarius.skinrestorer.neoforge.compat.skinshuffle.SkinShuffleCompatibility.initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public static void onCommandRegister(RegisterCommandsEvent event) {
|
public static void onCommandRegister(RegisterCommandsEvent event) {
|
||||||
SkinCommand.register(event.getDispatcher());
|
SkinRestorer.Events.onCommandRegister(event.getDispatcher());
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public static void onServerStarted(ServerStartedEvent event) {
|
public static void onServerStarted(ServerStartedEvent event) {
|
||||||
SkinRestorer.onServerStarted(event.getServer());
|
SkinRestorer.Events.onServerStarted(event.getServer());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package net.lionarius.skinrestorer.neoforge.compat.skinshuffle;
|
||||||
|
|
||||||
|
import net.lionarius.skinrestorer.SkinRestorer;
|
||||||
|
import net.neoforged.fml.ModList;
|
||||||
|
import net.neoforged.neoforge.common.NeoForge;
|
||||||
|
|
||||||
|
public final class SkinShuffleCompatibility {
|
||||||
|
|
||||||
|
private SkinShuffleCompatibility() {}
|
||||||
|
|
||||||
|
public static void initialize() {
|
||||||
|
NeoForge.EVENT_BUS.register(SkinShuffleGameEventHandler.class);
|
||||||
|
|
||||||
|
final var mod = ModList.get().getModContainerById(SkinRestorer.MOD_ID).get();
|
||||||
|
mod.getEventBus().register(SkinShuffleModEventHandler.class);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package net.lionarius.skinrestorer.neoforge.compat.skinshuffle;
|
||||||
|
|
||||||
|
import net.lionarius.skinrestorer.compat.skinshuffle.SkinShuffleCompatibility;
|
||||||
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
|
import net.neoforged.bus.api.SubscribeEvent;
|
||||||
|
import net.neoforged.neoforge.event.entity.player.PlayerEvent;
|
||||||
|
|
||||||
|
public final class SkinShuffleGameEventHandler {
|
||||||
|
|
||||||
|
private SkinShuffleGameEventHandler() {}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public static void onPlayerLoggedIn(PlayerEvent.PlayerLoggedInEvent event) {
|
||||||
|
SkinShuffleCompatibility.onPlayerJoin((ServerPlayer) event.getEntity());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package net.lionarius.skinrestorer.neoforge.compat.skinshuffle;
|
||||||
|
|
||||||
|
import net.lionarius.skinrestorer.compat.skinshuffle.SkinShuffleCompatibility;
|
||||||
|
import net.lionarius.skinrestorer.compat.skinshuffle.*;
|
||||||
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
|
import net.neoforged.bus.api.SubscribeEvent;
|
||||||
|
import net.neoforged.neoforge.network.event.RegisterPayloadHandlersEvent;
|
||||||
|
import net.neoforged.neoforge.network.handling.IPayloadContext;
|
||||||
|
import net.neoforged.neoforge.network.registration.HandlerThread;
|
||||||
|
|
||||||
|
public final class SkinShuffleModEventHandler {
|
||||||
|
private SkinShuffleModEventHandler() {}
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public static void onRegisterPayloadHandlers(RegisterPayloadHandlersEvent event) {
|
||||||
|
final var registrar = event.registrar("1").optional().executesOn(HandlerThread.NETWORK);
|
||||||
|
|
||||||
|
registrar
|
||||||
|
.playToClient(SkinShuffleHandshakePayload.PACKET_ID, SkinShuffleHandshakePayload.PACKET_CODEC,
|
||||||
|
(payload, context) -> {})
|
||||||
|
.playToServer(SkinShuffleSkinRefreshV1Payload.PACKET_ID, SkinShuffleSkinRefreshV1Payload.PACKET_CODEC,
|
||||||
|
SkinShuffleModEventHandler::handleSkinRefreshPacket)
|
||||||
|
.playToServer(SkinShuffleSkinRefreshV2Payload.PACKET_ID, SkinShuffleSkinRefreshV2Payload.PACKET_CODEC,
|
||||||
|
SkinShuffleModEventHandler::handleSkinRefreshPacket);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void handleSkinRefreshPacket(SkinShuffleSkinRefreshPayload payload, IPayloadContext context) {
|
||||||
|
var player = (ServerPlayer) context.player();
|
||||||
|
SkinShuffleCompatibility.handleSkinRefresh(player.getServer(), player, payload);
|
||||||
|
}
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user