mirror of
https://github.com/Suiranoil/SkinRestorer.git
synced 2026-01-16 04:42:12 +00:00
Compare commits
170 Commits
v2.0.3+1.2
...
a0d8f3d518
| Author | SHA1 | Date | |
|---|---|---|---|
|
a0d8f3d518
|
|||
|
aa3cb3df09
|
|||
|
0524b5dab8
|
|||
|
301428147d
|
|||
|
2e655ce1f3
|
|||
|
7dcd1d4e81
|
|||
|
1aa606038e
|
|||
|
e832e02fd4
|
|||
|
ffd2a0dba7
|
|||
|
76e801c944
|
|||
|
da754aa830
|
|||
|
69a561f679
|
|||
|
f36390a3d5
|
|||
|
583205febc
|
|||
|
fb7a4d11e9
|
|||
|
1d8472e35c
|
|||
|
f604ac2c8b
|
|||
|
8d4c2e9f83
|
|||
|
84a06898a2
|
|||
|
11ecf88eb2
|
|||
|
01a045541c
|
|||
|
5bab96e269
|
|||
|
a0b557be51
|
|||
|
7fad7de710
|
|||
|
8af1dd8f12
|
|||
|
1c7f97551d
|
|||
|
a8cc81e570
|
|||
|
6ce3484824
|
|||
|
b518305028
|
|||
|
96ea077004
|
|||
|
91eead3d1f
|
|||
|
2ea4d3f3e7
|
|||
|
e65501e620
|
|||
|
1b8a6c2f5d
|
|||
|
4cc12e23dc
|
|||
|
28db1ee84c
|
|||
|
df58fe8c89
|
|||
|
2325b3b35c
|
|||
|
ad6d64e8d4
|
|||
|
07b4887f60
|
|||
|
30d21c9424
|
|||
|
1c51796409
|
|||
|
1b6afd5d6e
|
|||
|
7e05f1eec9
|
|||
|
81d05fe991
|
|||
|
757d46b231
|
|||
|
3b15f7b341
|
|||
|
38a2fd7214
|
|||
|
e4c9e1b3cd
|
|||
|
3ef3318ed3
|
|||
|
5b384c32d6
|
|||
|
8119a08c80
|
|||
|
6c159d6aa2
|
|||
|
760ac65ab3
|
|||
|
2e7a9edc20
|
|||
|
8457e6f4ab
|
|||
|
66a9c1fbbf
|
|||
|
e3754cda90
|
|||
|
100282d527
|
|||
|
4b48227eea
|
|||
|
100c1d5974
|
|||
|
26d4a5ef51
|
|||
|
ced2801d1c
|
|||
|
41b6a5d030
|
|||
|
10534b01a7
|
|||
|
088ad089ed
|
|||
|
6fbc53e38b
|
|||
|
364ca540be
|
|||
|
cec5bac608
|
|||
|
c70f780ec2
|
|||
|
ecdfff5dc7
|
|||
|
16ffeea4f3
|
|||
|
516601a899
|
|||
|
2e3b2649b3
|
|||
|
07d620ae2f
|
|||
|
ad2177848c
|
|||
|
8136354af1
|
|||
|
fee25d2d04
|
|||
|
33926b15e1
|
|||
|
226d3f7bcb
|
|||
|
c81adc7320
|
|||
|
583e59f9d8
|
|||
|
8081e443b9
|
|||
|
61e1ada760
|
|||
|
|
d04a3beecf | ||
|
|
89b06fcfc7 | ||
|
|
d7fffdab1b | ||
|
|
9e175ddabb | ||
|
|
74a571b62c | ||
|
|
8ae29eae89 | ||
|
|
9f0fac4b2a | ||
|
|
e68aa90953 | ||
|
6a7f5f2096
|
|||
|
4d6d4faafd
|
|||
|
823b2ea3f6
|
|||
|
a63b6c3867
|
|||
|
dfe6d7af42
|
|||
|
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
|
90
.github/ISSUE_TEMPLATE/bug_report.yaml
vendored
Normal file
90
.github/ISSUE_TEMPLATE/bug_report.yaml
vendored
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
name: Bug Report
|
||||||
|
description: Report a bug encountered with SkinRestorer
|
||||||
|
title: "[Bug]: "
|
||||||
|
labels: ["bug"]
|
||||||
|
body:
|
||||||
|
- type: markdown
|
||||||
|
attributes:
|
||||||
|
value: |
|
||||||
|
🐛 **Before submitting:**
|
||||||
|
- Ensure you're using the latest mod version
|
||||||
|
- Ensure this bug is reproducible consistently
|
||||||
|
- Check existing issues for duplicates
|
||||||
|
|
||||||
|
- type: input
|
||||||
|
id: mod-version
|
||||||
|
attributes:
|
||||||
|
label: SkinRestorer Version
|
||||||
|
description: Exact version of the mod
|
||||||
|
placeholder: e.g., 2.2.1
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
|
||||||
|
- type: input
|
||||||
|
id: minecraft-version
|
||||||
|
attributes:
|
||||||
|
label: Minecraft Version
|
||||||
|
description: Full Minecraft version
|
||||||
|
placeholder: e.g., 1.21.4
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
|
||||||
|
- type: input
|
||||||
|
id: loader-version
|
||||||
|
attributes:
|
||||||
|
label: Mod Loader & Version
|
||||||
|
description: Fabric/Quilt/Forge/NeoForge version
|
||||||
|
placeholder: e.g., Fabric 0.15.7
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
|
||||||
|
- type: input
|
||||||
|
id: java-version
|
||||||
|
attributes:
|
||||||
|
label: Java Version
|
||||||
|
placeholder: e.g. 17, 21
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
|
||||||
|
- type: textarea
|
||||||
|
id: description
|
||||||
|
attributes:
|
||||||
|
label: Bug Description
|
||||||
|
description: What happened vs what you expected to happen
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
|
||||||
|
- type: textarea
|
||||||
|
id: steps
|
||||||
|
attributes:
|
||||||
|
label: Reproduction Steps
|
||||||
|
description: Provide step-by-step instructions or a video showing how to reproduce the issue.
|
||||||
|
placeholder: |
|
||||||
|
1.
|
||||||
|
2.
|
||||||
|
3.
|
||||||
|
Or a video demonstrating the issue.
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
|
||||||
|
- type: textarea
|
||||||
|
id: logs
|
||||||
|
attributes:
|
||||||
|
label: Relevant Logs
|
||||||
|
description: |
|
||||||
|
Please provide any relevant logs, especially error logs from your server console or `latest.log` file.
|
||||||
|
**Important**: Paste the FULL log content. Use a service like [mclo.gs](https://mclo.gs/).
|
||||||
|
render: shell
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
|
||||||
|
- type: checkboxes
|
||||||
|
id: confirmations
|
||||||
|
attributes:
|
||||||
|
label: Confirmations
|
||||||
|
options:
|
||||||
|
- label: I've checked for existing issues
|
||||||
|
required: true
|
||||||
|
- label: This bug is reproducible consistently
|
||||||
|
required: true
|
||||||
|
- label: I've tested without other mods
|
||||||
1
.github/ISSUE_TEMPLATE/config.yml
vendored
Normal file
1
.github/ISSUE_TEMPLATE/config.yml
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
blank_issues_enabled: true
|
||||||
52
.github/ISSUE_TEMPLATE/feature_request.yaml
vendored
Normal file
52
.github/ISSUE_TEMPLATE/feature_request.yaml
vendored
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
name: Feature Request
|
||||||
|
description: Suggest a new feature for SkinRestorer
|
||||||
|
title: "[Feature Request]: "
|
||||||
|
labels: ["enhancement"]
|
||||||
|
body:
|
||||||
|
- type: markdown
|
||||||
|
attributes:
|
||||||
|
value: |
|
||||||
|
💡 **Before submitting:**
|
||||||
|
- Check existing feature requests for duplicates
|
||||||
|
- Be clear and concise
|
||||||
|
- Explain the *why* and the *how*
|
||||||
|
|
||||||
|
- type: textarea
|
||||||
|
id: description
|
||||||
|
attributes:
|
||||||
|
label: Feature Description
|
||||||
|
description: Detailed description of the feature
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
|
||||||
|
- type: textarea
|
||||||
|
id: motivation
|
||||||
|
attributes:
|
||||||
|
label: Motivation
|
||||||
|
description: Why is this feature needed? What problem does it solve?
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
|
||||||
|
- type: textarea
|
||||||
|
id: use-cases
|
||||||
|
attributes:
|
||||||
|
label: Use Cases
|
||||||
|
description: How would this feature be used and who would benefit?
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
|
||||||
|
- type: textarea
|
||||||
|
id: implementation-ideas
|
||||||
|
attributes:
|
||||||
|
label: Implementation Ideas (Optional)
|
||||||
|
description: Any thoughts on how it could be implemented?
|
||||||
|
validations:
|
||||||
|
required: false
|
||||||
|
|
||||||
|
- type: checkboxes
|
||||||
|
id: confirmations
|
||||||
|
attributes:
|
||||||
|
label: Confirmations
|
||||||
|
options:
|
||||||
|
- label: I've checked for existing feature requests
|
||||||
|
required: true
|
||||||
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:
|
||||||
|
|||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -30,3 +30,4 @@ bin/
|
|||||||
|
|
||||||
.architectury-transformer/
|
.architectury-transformer/
|
||||||
run/
|
run/
|
||||||
|
scripts/
|
||||||
|
|||||||
83
CHANGELOG.md
83
CHANGELOG.md
@@ -4,6 +4,89 @@ 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.5.0] - 2026-01-14
|
||||||
|
### Added
|
||||||
|
- Added collection skin provider (allows assigning random skins from a predefined set)
|
||||||
|
- Added `forceFirstJoinSkinFetch` config option to force skin fetch on first join even if player already has a skin
|
||||||
|
|
||||||
|
## [2.4.3] - 2025-07-25
|
||||||
|
### Fixed
|
||||||
|
- Fixed crash on client when loading player head skin (fixes [#63](https://github.com/Suiranoil/SkinRestorer/issues/63) and [#64](https://github.com/Suiranoil/SkinRestorer/issues/64))
|
||||||
|
- Fixed server freeze when loading player head skin
|
||||||
|
|
||||||
|
## [2.4.2] - 2025-07-13
|
||||||
|
### Fixed
|
||||||
|
- Fix crash when head profile name is null (fixes [#60](https://github.com/Suiranoil/SkinRestorer/issues/60) and [#61](https://github.com/Suiranoil/SkinRestorer/issues/61))
|
||||||
|
|
||||||
|
## [2.4.1] - 2025-07-09
|
||||||
|
### Changed
|
||||||
|
- Log full exception and argument when unable to fetch/set skin
|
||||||
|
### Fixed
|
||||||
|
- Fixed mojang provider using offline uuids when unable to fetch actual uuid resulting in `no profile with uuid` error
|
||||||
|
|
||||||
|
## [2.4.0] - 2025-07-05
|
||||||
|
### Fixed
|
||||||
|
- Added support for player heads
|
||||||
|
|
||||||
|
## [2.3.5] - 2025-06-21
|
||||||
|
### Fixed
|
||||||
|
- Fix mod not loading on client
|
||||||
|
|
||||||
|
## [2.3.4] - 2025-06-19
|
||||||
|
### Added
|
||||||
|
- Added support for minecraft 1.21.6
|
||||||
|
|
||||||
|
## [2.3.3] - 2025-06-01
|
||||||
|
### Fixed
|
||||||
|
- Fixed forge mixin crash (closes [#54](https://github.com/Suiranoil/SkinRestorer/issues/53))
|
||||||
|
### Removed
|
||||||
|
- Removed minecraft 1.19 support
|
||||||
|
|
||||||
|
## [2.3.2] - 2025-05-24
|
||||||
|
### Fixed
|
||||||
|
- Fixed mixin incompatibility with ModernFix (closes [#42](https://github.com/Suiranoil/SkinRestorer/issues/52))
|
||||||
|
|
||||||
|
## [2.3.1] - 2025-05-03
|
||||||
|
### Added
|
||||||
|
- Added support for minecraft 1.19-1.19.4
|
||||||
|
### Changed
|
||||||
|
- Use services and session server urls from environment
|
||||||
|
|
||||||
|
## [2.3.0] - 2025-03-27
|
||||||
|
### Added
|
||||||
|
- Added `skinApplyDelayOnJoin` config option (see [wiki](https://github.com/Suiranoil/SkinRestorer/wiki/Configuration#skinapplydelayonjoin))
|
||||||
|
### Changed
|
||||||
|
- Updated to 1.21.5
|
||||||
|
### Removed
|
||||||
|
- [NeoForge] Dropped support for NeoForge on Minecraft 1.20.5-1.20.6
|
||||||
|
|
||||||
|
## [2.2.1] - 2024-12-23
|
||||||
|
### Fixed
|
||||||
|
- Fixed game not closing because of mineskin working threads (closes [#41](https://github.com/Suiranoil/SkinRestorer/issues/41))
|
||||||
|
|
||||||
|
## [2.2.0] - 2024-12-02
|
||||||
|
### 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,3 @@
|
|||||||
### Added
|
### Added
|
||||||
- Added `firstJoinSkinProvider` config option (see [wiki](https://github.com/Suiranoil/SkinRestorer/wiki/Config#firstjoinskinprovider))
|
- Added collection skin provider (allows assigning random skins from a predefined set) (see [wiki](https://github.com/Suiranoil/SkinRestorer/wiki/Configuration#providerscollection))
|
||||||
### Fixed
|
- Added `forceFirstJoinSkinFetch` config option to force skin fetch on first join even if player already has a skin (see [wiki](https://github.com/Suiranoil/SkinRestorer/wiki/Configuration#forcefirstjoinskinfetch))
|
||||||
- Fixed ability to set config values to `null`
|
|
||||||
|
|||||||
103
README.md
103
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"></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"></a>
|
||||||
|
|
||||||
A server-side mod for managing and restoring player skins.
|
A server-side mod for managing and restoring player skins.
|
||||||
|
|
||||||
@@ -9,95 +9,36 @@ 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.
|
<a href="https://ko-fi.com/lionarius"><img src="https://raw.githubusercontent.com/Suiranoil/badges/main/assets/donation/kofi/mini/badge.svg" alt="Ko-fi" height="32"></a>
|
||||||
|
|
||||||
```
|
<a href="https://boosty.to/lionarius"><img src="https://raw.githubusercontent.com/Suiranoil/badges/main/assets/donation/boosty/mini/badge.svg" alt="Boosty" height="32"></a>
|
||||||
/skin set ely.by <username> [<targets>]
|
|
||||||
```
|
|
||||||
|
|
||||||
- **Parameters**
|
Bitcoin (BTC): `1Ndbwny8pxdnWXFgadp95fp97y5JqMJKTX`
|
||||||
- `<username>`: Ely.by username to fetch the skin from.
|
USDT (TRC20): `TGXn8wrqku5KLzwPWQAeH7wgnV4UzwHEae`
|
||||||
- `[<targets>]`: (Optional, server operators only) Player(s) to apply the skin to.
|
USDT (TON): `UQAQF18Xlmx-V1oZ90C2YOju5qI7q1LgrCP5QaIUhqIELmDS`
|
||||||
|
|
||||||
### Set Web skin
|
Thank you for your generosity!
|
||||||
|
|
||||||
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
|
|
||||||
```
|
|
||||||
|
|||||||
26
build.gradle
26
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.11-SNAPSHOT' apply false
|
||||||
// see https://projects.neoforged.net/neoforged/neogradle for new versions
|
// see https://projects.neoforged.net/neoforged/moddevgradle for new versions
|
||||||
id 'net.neoforged.gradle.userdev' version '7.0.153' apply false
|
id 'net.neoforged.moddev' version '2.0.+' 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.+' 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.+' 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 {
|
||||||
@@ -83,7 +83,6 @@ processResources {
|
|||||||
'group' : project.group, //Else we target the task's group.
|
'group' : project.group, //Else we target the task's group.
|
||||||
'minecraft_version' : minecraft_version,
|
'minecraft_version' : minecraft_version,
|
||||||
'minecraft_version_range' : minecraft_version_range,
|
'minecraft_version_range' : minecraft_version_range,
|
||||||
'fabric_loader_version' : fabric_loader_version,
|
|
||||||
'mod_name' : mod_name,
|
'mod_name' : mod_name,
|
||||||
'mod_author' : mod_author,
|
'mod_author' : mod_author,
|
||||||
'mod_id' : mod_id,
|
'mod_id' : mod_id,
|
||||||
@@ -92,16 +91,20 @@ processResources {
|
|||||||
'mod_issues' : mod_issues,
|
'mod_issues' : mod_issues,
|
||||||
'license' : license,
|
'license' : license,
|
||||||
'description' : project.description,
|
'description' : project.description,
|
||||||
'forge_version' : forge_version,
|
|
||||||
'forge_loader_version_range' : forge_loader_version_range,
|
|
||||||
'neoforge_version' : neoforge_version,
|
|
||||||
'neoforge_loader_version_range': neoforge_loader_version_range,
|
|
||||||
'credits' : credits,
|
'credits' : credits,
|
||||||
'java_version' : java_version
|
'java_version' : java_version,
|
||||||
|
|
||||||
|
// Loader specific properties
|
||||||
|
'fabric_loader_version' : project.hasProperty('fabric_loader_version') ? fabric_loader_version : '',
|
||||||
|
'forge_version' : project.hasProperty('forge_version') ? forge_version : '',
|
||||||
|
'forge_loader_version_range' : project.hasProperty('forge_loader_version_range') ? forge_loader_version_range : '',
|
||||||
|
'neoforge_version' : project.hasProperty('neoforge_version') ? neoforge_version : '',
|
||||||
|
'neoforge_loader_version_range': project.hasProperty('neoforge_loader_version_range') ? neoforge_loader_version_range : ''
|
||||||
]
|
]
|
||||||
|
|
||||||
filesMatching(['pack.mcmeta', 'fabric.mod.json', 'META-INF/mods.toml', 'META-INF/neoforge.mods.toml', '*.mixins.json']) {
|
filesMatching(['pack.mcmeta', 'fabric.mod.json', 'META-INF/mods.toml', 'META-INF/neoforge.mods.toml', '*.mixins.json']) {
|
||||||
expand expandProps
|
expand expandProps
|
||||||
}
|
}
|
||||||
|
|
||||||
inputs.properties(expandProps)
|
inputs.properties(expandProps)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,10 +3,10 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
configurations {
|
configurations {
|
||||||
commonJava{
|
commonJava {
|
||||||
canBeResolved = true
|
canBeResolved = true
|
||||||
}
|
}
|
||||||
commonResources{
|
commonResources {
|
||||||
canBeResolved = true
|
canBeResolved = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,12 +3,17 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
publishMods {
|
publishMods {
|
||||||
if (project.name == 'fabric')
|
file = project.layout.buildDirectory.file("libs/${project.archivesBaseName}-${project.version}.jar").map { it.asFile }.getOrNull()
|
||||||
file = remapJar.archiveFile
|
|
||||||
else
|
|
||||||
file = jar.archiveFile
|
|
||||||
|
|
||||||
modLoaders.add(project.name)
|
modLoaders.add(project.name)
|
||||||
|
|
||||||
|
if (project.hasProperty('additional_modloaders') && !additional_modloaders.isEmpty())
|
||||||
|
{
|
||||||
|
def loaders = additional_modloaders.split(',')
|
||||||
|
for (loader in loaders)
|
||||||
|
modLoaders.add(loader)
|
||||||
|
}
|
||||||
|
|
||||||
type = STABLE
|
type = STABLE
|
||||||
version = project.version
|
version = project.version
|
||||||
displayName = "[${project.name.capitalize()}] ${mod_name} ${mod_version}"
|
displayName = "[${project.name.capitalize()}] ${mod_name} ${mod_version}"
|
||||||
@@ -22,6 +27,9 @@ publishMods {
|
|||||||
|
|
||||||
minecraftVersions.addAll(minecraft_version_list.split(','))
|
minecraftVersions.addAll(minecraft_version_list.split(','))
|
||||||
serverRequired = true
|
serverRequired = true
|
||||||
|
|
||||||
|
if (project.hasProperty('optional_dependencies') && !optional_dependencies.isEmpty())
|
||||||
|
optional(optional_dependencies.split(','))
|
||||||
}
|
}
|
||||||
|
|
||||||
modrinth {
|
modrinth {
|
||||||
@@ -31,5 +39,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.hasProperty('optional_dependencies') && !optional_dependencies.isEmpty())
|
||||||
|
optional(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,18 +1,25 @@
|
|||||||
package net.lionarius.skinrestorer;
|
package net.lionarius.skinrestorer;
|
||||||
|
|
||||||
import com.mojang.authlib.GameProfile;
|
import com.google.common.base.Throwables;
|
||||||
|
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.exception.TransparentException;
|
||||||
|
import net.lionarius.skinrestorer.mixin.PlayerAccessor;
|
||||||
|
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;
|
||||||
import net.lionarius.skinrestorer.skin.provider.*;
|
import net.lionarius.skinrestorer.skin.provider.*;
|
||||||
import net.lionarius.skinrestorer.translation.Translation;
|
import net.lionarius.skinrestorer.translation.Translation;
|
||||||
import net.lionarius.skinrestorer.util.FileUtils;
|
import net.lionarius.skinrestorer.util.*;
|
||||||
import net.lionarius.skinrestorer.util.PlayerUtils;
|
import net.minecraft.commands.CommandSourceStack;
|
||||||
import net.lionarius.skinrestorer.util.Result;
|
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;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@@ -30,6 +37,8 @@ public final class SkinRestorer {
|
|||||||
private static SkinStorage skinStorage;
|
private static SkinStorage skinStorage;
|
||||||
private static Path configDir;
|
private static Path configDir;
|
||||||
private static Config config;
|
private static Config config;
|
||||||
|
private static TickedScheduler tickedScheduler;
|
||||||
|
private static MinecraftServer minecraftServer;
|
||||||
|
|
||||||
private SkinRestorer() {}
|
private SkinRestorer() {}
|
||||||
|
|
||||||
@@ -49,74 +58,101 @@ public final class SkinRestorer {
|
|||||||
return SkinRestorer.providersRegistry;
|
return SkinRestorer.providersRegistry;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static TickedScheduler getTickedScheduler() {
|
||||||
|
return SkinRestorer.tickedScheduler;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static @Nullable MinecraftServer getMinecraftServer() {
|
||||||
|
return SkinRestorer.minecraftServer;
|
||||||
|
}
|
||||||
|
|
||||||
public static Optional<SkinProvider> getProvider(String name) {
|
public static Optional<SkinProvider> getProvider(String name) {
|
||||||
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());
|
||||||
|
SkinRestorer.registerDefaultSkinProvider(CollectionSkinProvider.PROVIDER_NAME, SkinProvider.COLLECTION, SkinRestorer.getConfig().providersConfig().collection());
|
||||||
}
|
}
|
||||||
|
|
||||||
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();
|
||||||
|
|
||||||
|
MojangSkinProvider.reload();
|
||||||
|
ElyBySkinProvider.reload();
|
||||||
|
MineskinSkinProvider.reload();
|
||||||
|
CollectionSkinProvider.reload();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String resource(String name) {
|
public static Collection<ServerPlayer> applySkin(MinecraftServer server, Iterable<ServerPlayer> targets, SkinValue value, boolean save) {
|
||||||
return String.format("/assets/%s/%s", SkinRestorer.MOD_ID, name);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Collection<ServerPlayer> applySkin(MinecraftServer server, Iterable<GameProfile> targets, SkinValue value, boolean save) {
|
|
||||||
var acceptedPlayers = new HashSet<ServerPlayer>();
|
var acceptedPlayers = new HashSet<ServerPlayer>();
|
||||||
|
|
||||||
for (var profile : targets) {
|
for (var player : targets) {
|
||||||
if (!SkinRestorer.getSkinStorage().hasSavedSkin(profile.getId()))
|
var profile = player.getGameProfile();
|
||||||
value = value.setOriginalValue(PlayerUtils.getPlayerSkin(profile));
|
var skin = PlayerUtils.getPlayerSkin(profile);
|
||||||
|
|
||||||
if (save)
|
if (!SkinRestorer.getSkinStorage().hasSavedSkin(profile.id()))
|
||||||
SkinRestorer.getSkinStorage().setSkin(profile.getId(), value);
|
value = value.setOriginalValue(skin);
|
||||||
|
|
||||||
if (PlayerUtils.areSkinPropertiesEquals(value.value(), PlayerUtils.getPlayerSkin(profile)))
|
if (PlayerUtils.areSkinPropertiesEquals(value.value(), skin))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
PlayerUtils.applyRestoredSkin(profile, value.value());
|
if (save)
|
||||||
|
SkinRestorer.getSkinStorage().setSkin(profile.id(), value);
|
||||||
|
|
||||||
var player = server.getPlayerList().getPlayer(profile.getId());
|
var newProfile = PlayerUtils.applyRestoredSkin(profile, value.value());
|
||||||
if (player == null)
|
((PlayerAccessor) player).setGameProfile(newProfile);
|
||||||
|
|
||||||
|
if (player.connection == null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
PlayerUtils.refreshPlayer(player);
|
PlayerUtils.refreshPlayer(player);
|
||||||
acceptedPlayers.add(player);
|
acceptedPlayers.add(player);
|
||||||
|
|
||||||
|
SkinRestorer.getTickedScheduler().cancel(player.getUUID());
|
||||||
}
|
}
|
||||||
|
|
||||||
return acceptedPlayers;
|
return acceptedPlayers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Collection<ServerPlayer> applySkin(MinecraftServer server, Iterable<GameProfile> targets, SkinValue value) {
|
public static Collection<ServerPlayer> applySkin(MinecraftServer server, Iterable<ServerPlayer> targets, SkinValue value) {
|
||||||
return SkinRestorer.applySkin(server, targets, value, true);
|
return SkinRestorer.applySkin(server, targets, value, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static CompletableFuture<Result<Collection<ServerPlayer>, String>> setSkinAsync(
|
public static CompletableFuture<Result<Collection<ServerPlayer>, String>> setSkinAsync(
|
||||||
MinecraftServer server,
|
MinecraftServer server,
|
||||||
Collection<GameProfile> targets,
|
Collection<ServerPlayer> targets,
|
||||||
SkinProviderContext context,
|
SkinProviderContext context,
|
||||||
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())
|
||||||
@@ -124,7 +160,7 @@ public final class SkinRestorer {
|
|||||||
|
|
||||||
var skinResult = result.get();
|
var skinResult = result.get();
|
||||||
if (skinResult.isError())
|
if (skinResult.isError())
|
||||||
return Result.<Collection<ServerPlayer>, String>error(skinResult.getErrorValue().getMessage());
|
throw new TransparentException(Throwables.getRootCause(skinResult.getErrorValue()));
|
||||||
|
|
||||||
var skinValue = SkinValue.fromProviderContextWithValue(context, skinResult.getSuccessValue().orElse(null));
|
var skinValue = SkinValue.fromProviderContextWithValue(context, skinResult.getSuccessValue().orElse(null));
|
||||||
|
|
||||||
@@ -133,8 +169,37 @@ public final class SkinRestorer {
|
|||||||
return Result.<Collection<ServerPlayer>, String>success(acceptedPlayers);
|
return Result.<Collection<ServerPlayer>, String>success(acceptedPlayers);
|
||||||
}, server)
|
}, server)
|
||||||
.exceptionally(e -> {
|
.exceptionally(e -> {
|
||||||
SkinRestorer.LOGGER.error(e.toString());
|
SkinRestorer.LOGGER.error("Failed to set skin '{}:{}'", context.name(), context.argument(), e);
|
||||||
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));
|
||||||
|
SkinRestorer.tickedScheduler = new TickedScheduler(server);
|
||||||
|
server.addTickable(SkinRestorer.tickedScheduler);
|
||||||
|
|
||||||
|
SkinRestorer.minecraftServer = server;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void onServerStopped(MinecraftServer server) {
|
||||||
|
SkinRestorer.skinStorage = null;
|
||||||
|
SkinRestorer.tickedScheduler = null;
|
||||||
|
SkinRestorer.minecraftServer = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void onCommandRegister(CommandDispatcher<CommandSourceStack> dispatcher) {
|
||||||
|
SkinCommand.register(dispatcher);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void onPlayerDisconnect(ServerPlayer player) {
|
||||||
|
SkinRestorer.getSkinStorage().removeSkin(player.getUUID());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package net.lionarius.skinrestorer.command;
|
package net.lionarius.skinrestorer.command;
|
||||||
|
|
||||||
import com.mojang.authlib.GameProfile;
|
|
||||||
import com.mojang.brigadier.CommandDispatcher;
|
import com.mojang.brigadier.CommandDispatcher;
|
||||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||||
import com.mojang.brigadier.builder.ArgumentBuilder;
|
import com.mojang.brigadier.builder.ArgumentBuilder;
|
||||||
@@ -18,10 +17,12 @@ import net.lionarius.skinrestorer.util.PlayerUtils;
|
|||||||
import net.minecraft.commands.CommandSourceStack;
|
import net.minecraft.commands.CommandSourceStack;
|
||||||
import net.minecraft.commands.arguments.GameProfileArgument;
|
import net.minecraft.commands.arguments.GameProfileArgument;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
|
import net.minecraft.server.players.NameAndId;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
@@ -34,7 +35,7 @@ public final class SkinCommand {
|
|||||||
private SkinCommand() {}
|
private SkinCommand() {}
|
||||||
|
|
||||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
|
public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
|
||||||
LiteralArgumentBuilder<CommandSourceStack> base =
|
var base =
|
||||||
literal("skin")
|
literal("skin")
|
||||||
.then(buildSetSubcommand("clear", SkinValue.EMPTY::toProviderContext))
|
.then(buildSetSubcommand("clear", SkinValue.EMPTY::toProviderContext))
|
||||||
.then(literal("reset")
|
.then(literal("reset")
|
||||||
@@ -44,13 +45,19 @@ public final class SkinCommand {
|
|||||||
)))
|
)))
|
||||||
.then(literal("refresh").executes(context -> refreshSubcommand(context.getSource())));
|
.then(literal("refresh").executes(context -> refreshSubcommand(context.getSource())));
|
||||||
|
|
||||||
LiteralArgumentBuilder<CommandSourceStack> set = literal("set");
|
var set = literal("set");
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
@@ -66,37 +73,41 @@ public final class SkinCommand {
|
|||||||
|
|
||||||
SkinProviderContext context = null;
|
SkinProviderContext context = null;
|
||||||
var save = true;
|
var save = true;
|
||||||
if (!SkinRestorer.getSkinStorage().hasSavedSkin(profile.getId())) {
|
if (!SkinRestorer.getSkinStorage().hasSavedSkin(profile.id())) {
|
||||||
if (profile.getProperties().containsKey(PlayerUtils.TEXTURES_KEY)) {
|
if (profile.properties().containsKey(PlayerUtils.TEXTURES_KEY)) {
|
||||||
save = false;
|
save = false;
|
||||||
context = MojangSkinProvider.skinProviderContextFromProfile(profile);
|
context = MojangSkinProvider.skinProviderContextFromProfile(profile);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
context = SkinRestorer.getSkinStorage().getSkin(profile.getId()).toProviderContext();
|
context = SkinRestorer.getSkinStorage().getSkin(profile.id()).toProviderContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (context == null)
|
if (context == null)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return SkinCommand.setSubcommand(src, Collections.singleton(profile), context, save, false);
|
return SkinCommand.setSubcommand(src, Collections.singleton(new NameAndId(profile)), context, save, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int resetSubcommand(
|
private static int resetSubcommand(
|
||||||
CommandSourceStack src,
|
CommandSourceStack src,
|
||||||
Collection<GameProfile> targets,
|
Collection<NameAndId> targets,
|
||||||
boolean setByOperator
|
boolean setByOperator
|
||||||
) {
|
) {
|
||||||
Collection<ServerPlayer> updatedPlayers = new HashSet<>();
|
var updatedPlayers = new HashSet<ServerPlayer>();
|
||||||
for (var profile : targets) {
|
for (var nameAndId : targets) {
|
||||||
SkinValue skin = null;
|
SkinValue skin = null;
|
||||||
if (SkinRestorer.getSkinStorage().hasSavedSkin(profile.getId()))
|
if (SkinRestorer.getSkinStorage().hasSavedSkin(nameAndId.id()))
|
||||||
skin = SkinRestorer.getSkinStorage().getSkin(profile.getId()).replaceValueWithOriginal();
|
skin = SkinRestorer.getSkinStorage().getSkin(nameAndId.id()).replaceValueWithOriginal();
|
||||||
|
|
||||||
if (skin == null)
|
if (skin == null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
var updatedPlayer = SkinRestorer.applySkin(src.getServer(), Collections.singleton(profile), skin, false);
|
var player = src.getServer().getPlayerList().getPlayer(nameAndId.id());
|
||||||
SkinRestorer.getSkinStorage().deleteSkin(profile.getId());
|
if (player == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
var updatedPlayer = SkinRestorer.applySkin(src.getServer(), Collections.singleton(player), skin, false);
|
||||||
|
SkinRestorer.getSkinStorage().deleteSkin(nameAndId.id());
|
||||||
|
|
||||||
updatedPlayers.addAll(updatedPlayer);
|
updatedPlayers.addAll(updatedPlayer);
|
||||||
}
|
}
|
||||||
@@ -112,19 +123,24 @@ public final class SkinCommand {
|
|||||||
if (src.getPlayer() == null)
|
if (src.getPlayer() == null)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return resetSubcommand(src, Collections.singleton(src.getPlayer().getGameProfile()), false);
|
return resetSubcommand(src, Collections.singleton(src.getPlayer().nameAndId()), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int setSubcommand(
|
private static int setSubcommand(
|
||||||
CommandSourceStack src,
|
CommandSourceStack src,
|
||||||
Collection<GameProfile> targets,
|
Collection<NameAndId> targets,
|
||||||
SkinProviderContext context,
|
SkinProviderContext context,
|
||||||
boolean save,
|
boolean save,
|
||||||
boolean setByOperator
|
boolean setByOperator
|
||||||
) {
|
) {
|
||||||
src.sendSystemMessage(Translation.translatableWithFallback(Translation.COMMAND_SKIN_LOADING_KEY));
|
src.sendSystemMessage(Translation.translatableWithFallback(Translation.COMMAND_SKIN_LOADING_KEY));
|
||||||
|
|
||||||
SkinRestorer.setSkinAsync(src.getServer(), targets, context, save).thenAccept(result -> {
|
var profileTargets = targets.stream()
|
||||||
|
.map(nameAndId -> src.getServer().getPlayerList().getPlayer(nameAndId.id()))
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
SkinRestorer.setSkinAsync(src.getServer(), profileTargets, context, save).thenAccept(result -> {
|
||||||
if (result.isError()) {
|
if (result.isError()) {
|
||||||
src.sendFailure(Translation.translatableWithFallback(
|
src.sendFailure(Translation.translatableWithFallback(
|
||||||
Translation.COMMAND_SKIN_FAILED_KEY,
|
Translation.COMMAND_SKIN_FAILED_KEY,
|
||||||
@@ -143,7 +159,7 @@ public final class SkinCommand {
|
|||||||
|
|
||||||
private static int setSubcommand(
|
private static int setSubcommand(
|
||||||
CommandSourceStack src,
|
CommandSourceStack src,
|
||||||
Collection<GameProfile> targets,
|
Collection<NameAndId> targets,
|
||||||
SkinProviderContext context,
|
SkinProviderContext context,
|
||||||
boolean setByOperator
|
boolean setByOperator
|
||||||
) {
|
) {
|
||||||
@@ -157,7 +173,17 @@ public final class SkinCommand {
|
|||||||
if (src.getPlayer() == null)
|
if (src.getPlayer() == null)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return setSubcommand(src, Collections.singleton(src.getPlayer().getGameProfile()), context, false);
|
return setSubcommand(src, Collections.singleton(src.getPlayer().nameAndId()), 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) {
|
||||||
@@ -183,7 +209,7 @@ public final class SkinCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static LiteralArgumentBuilder<CommandSourceStack> buildSetSubcommand(String name, SkinProvider provider) {
|
private static LiteralArgumentBuilder<CommandSourceStack> buildSetSubcommand(String name, SkinProvider provider) {
|
||||||
LiteralArgumentBuilder<CommandSourceStack> action = literal(name);
|
var action = literal(name);
|
||||||
|
|
||||||
if (provider.hasVariantSupport()) {
|
if (provider.hasVariantSupport()) {
|
||||||
for (SkinVariant variant : SkinVariant.values()) {
|
for (SkinVariant variant : SkinVariant.values()) {
|
||||||
@@ -240,7 +266,7 @@ public final class SkinCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static RequiredArgumentBuilder<CommandSourceStack, GameProfileArgument.Result> makeTargetsArgument(
|
private static RequiredArgumentBuilder<CommandSourceStack, GameProfileArgument.Result> makeTargetsArgument(
|
||||||
BiFunction<CommandContext<CommandSourceStack>, Collection<GameProfile>, Integer> consumer
|
BiFunction<CommandContext<CommandSourceStack>, Collection<NameAndId>, Integer> consumer
|
||||||
) {
|
) {
|
||||||
return argument("targets", GameProfileArgument.gameProfile())
|
return argument("targets", GameProfileArgument.gameProfile())
|
||||||
.requires(source -> source.hasPermission(2))
|
.requires(source -> source.hasPermission(2))
|
||||||
|
|||||||
@@ -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),
|
||||||
|
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,74 @@
|
|||||||
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 int skinApplyDelayOnJoin = 0;
|
||||||
|
|
||||||
private boolean fetchSkinOnFirstJoin = true;
|
private boolean fetchSkinOnFirstJoin = true;
|
||||||
|
|
||||||
|
private boolean forceFirstJoinSkinFetch = false;
|
||||||
|
|
||||||
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 int skinApplyDelayOnJoin() {
|
||||||
|
return this.skinApplyDelayOnJoin;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean fetchSkinOnFirstJoin() {
|
public boolean fetchSkinOnFirstJoin() {
|
||||||
return this.fetchSkinOnFirstJoin;
|
return this.fetchSkinOnFirstJoin;
|
||||||
}
|
}
|
||||||
|
|
||||||
public FirstJoinSkinProvider getFirstJoinSkinProvider() {
|
public boolean forceFirstJoinSkinFetch() {
|
||||||
|
return this.forceFirstJoinSkinFetch;
|
||||||
|
}
|
||||||
|
|
||||||
|
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 +82,50 @@ 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.skinApplyDelayOnJoin < 0) {
|
||||||
|
SkinRestorer.LOGGER.warn("SkinApplyDelayOnJoin config is less than 0, defaulting to 0");
|
||||||
|
this.skinApplyDelayOnJoin = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package net.lionarius.skinrestorer.config;
|
package net.lionarius.skinrestorer.config;
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName;
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
import net.lionarius.skinrestorer.skin.provider.CollectionSkinProvider;
|
||||||
import net.lionarius.skinrestorer.skin.provider.ElyBySkinProvider;
|
import net.lionarius.skinrestorer.skin.provider.ElyBySkinProvider;
|
||||||
import net.lionarius.skinrestorer.skin.provider.MojangSkinProvider;
|
import net.lionarius.skinrestorer.skin.provider.MojangSkinProvider;
|
||||||
|
|
||||||
@@ -8,7 +9,9 @@ public enum FirstJoinSkinProvider {
|
|||||||
@SerializedName(value = "MOJANG", alternate = {"mojang"})
|
@SerializedName(value = "MOJANG", alternate = {"mojang"})
|
||||||
MOJANG(MojangSkinProvider.PROVIDER_NAME),
|
MOJANG(MojangSkinProvider.PROVIDER_NAME),
|
||||||
@SerializedName(value = "ELY.BY", alternate = {"ely.by", "ELY_BY", "ely_by"})
|
@SerializedName(value = "ELY.BY", alternate = {"ely.by", "ELY_BY", "ely_by"})
|
||||||
ELY_BY(ElyBySkinProvider.PROVIDER_NAME);
|
ELY_BY(ElyBySkinProvider.PROVIDER_NAME),
|
||||||
|
@SerializedName(value = "COLLECTION", alternate = {"collection"})
|
||||||
|
COLLECTION(CollectionSkinProvider.PROVIDER_NAME);
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|
||||||
|
|||||||
@@ -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,47 @@
|
|||||||
|
package net.lionarius.skinrestorer.config.provider;
|
||||||
|
|
||||||
|
import net.lionarius.skinrestorer.SkinRestorer;
|
||||||
|
import net.lionarius.skinrestorer.util.gson.GsonPostProcessable;
|
||||||
|
|
||||||
|
public abstract class BuiltInProviderConfig implements GsonPostProcessable {
|
||||||
|
protected boolean enabled;
|
||||||
|
protected String name;
|
||||||
|
protected CacheConfig cache;
|
||||||
|
|
||||||
|
|
||||||
|
public BuiltInProviderConfig(String name, CacheConfig cache) {
|
||||||
|
this(name, cache, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public BuiltInProviderConfig(String name, CacheConfig cache, boolean enabled) {
|
||||||
|
this.enabled = enabled;
|
||||||
|
this.name = name;
|
||||||
|
this.cache = cache;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean enabled() {
|
||||||
|
return enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String name() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CacheConfig cache() {
|
||||||
|
return cache;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void validate(String defaultName, CacheConfig defaultCache) {
|
||||||
|
if (this.name == null || this.name.isEmpty()) {
|
||||||
|
SkinRestorer.LOGGER.warn("Provider name is null or empty, defaulting to '{}'", defaultName);
|
||||||
|
this.name = defaultName;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.cache == null) {
|
||||||
|
SkinRestorer.LOGGER.warn("Provider cache is null, using default");
|
||||||
|
this.cache = defaultCache;
|
||||||
|
} else {
|
||||||
|
this.cache.validate(defaultCache);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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,16 @@
|
|||||||
|
package net.lionarius.skinrestorer.config.provider;
|
||||||
|
|
||||||
|
import net.lionarius.skinrestorer.skin.provider.ElyBySkinProvider;
|
||||||
|
|
||||||
|
public final class ElyByProviderConfig extends BuiltInProviderConfig {
|
||||||
|
private static final CacheConfig DEFAULT_CACHE_VALUE = new CacheConfig(true, 60);
|
||||||
|
|
||||||
|
public ElyByProviderConfig() {
|
||||||
|
super(ElyBySkinProvider.PROVIDER_NAME, DEFAULT_CACHE_VALUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void gsonPostProcess() {
|
||||||
|
super.validate(ElyBySkinProvider.PROVIDER_NAME, DEFAULT_CACHE_VALUE);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package net.lionarius.skinrestorer.config.provider;
|
||||||
|
|
||||||
|
import net.lionarius.skinrestorer.SkinRestorer;
|
||||||
|
import net.lionarius.skinrestorer.skin.provider.MineskinSkinProvider;
|
||||||
|
|
||||||
|
public final class MineskinProviderConfig extends BuiltInProviderConfig {
|
||||||
|
private static final CacheConfig DEFAULT_CACHE_VALUE = new CacheConfig(true, 300);
|
||||||
|
|
||||||
|
private String apiKey;
|
||||||
|
|
||||||
|
public MineskinProviderConfig() {
|
||||||
|
super(MineskinSkinProvider.PROVIDER_NAME, DEFAULT_CACHE_VALUE);
|
||||||
|
|
||||||
|
this.apiKey = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public String apiKey() {
|
||||||
|
return apiKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void gsonPostProcess() {
|
||||||
|
super.validate(MineskinSkinProvider.PROVIDER_NAME, 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,16 @@
|
|||||||
|
package net.lionarius.skinrestorer.config.provider;
|
||||||
|
|
||||||
|
import net.lionarius.skinrestorer.skin.provider.MojangSkinProvider;
|
||||||
|
|
||||||
|
public final class MojangProviderConfig extends BuiltInProviderConfig {
|
||||||
|
private static final CacheConfig DEFAULT_CACHE_VALUE = new CacheConfig(true, 60);
|
||||||
|
|
||||||
|
public MojangProviderConfig() {
|
||||||
|
super(MojangSkinProvider.PROVIDER_NAME, DEFAULT_CACHE_VALUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void gsonPostProcess() {
|
||||||
|
super.validate(MojangSkinProvider.PROVIDER_NAME, DEFAULT_CACHE_VALUE);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
package net.lionarius.skinrestorer.config.provider;
|
||||||
|
|
||||||
|
import net.lionarius.skinrestorer.SkinRestorer;
|
||||||
|
import net.lionarius.skinrestorer.config.provider.collection.CollectionProviderConfig;
|
||||||
|
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(),
|
||||||
|
new CollectionProviderConfig()
|
||||||
|
);
|
||||||
|
|
||||||
|
private MojangProviderConfig mojang;
|
||||||
|
private ElyByProviderConfig ely_by;
|
||||||
|
private MineskinProviderConfig mineskin;
|
||||||
|
private CollectionProviderConfig collection;
|
||||||
|
|
||||||
|
public ProvidersConfig(MojangProviderConfig mojang, ElyByProviderConfig ely_by, MineskinProviderConfig mineskin, CollectionProviderConfig collection) {
|
||||||
|
this.mojang = mojang;
|
||||||
|
this.ely_by = ely_by;
|
||||||
|
this.mineskin = mineskin;
|
||||||
|
this.collection = collection;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MojangProviderConfig mojang() {
|
||||||
|
return this.mojang;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ElyByProviderConfig ely_by() {
|
||||||
|
return this.ely_by;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MineskinProviderConfig mineskin() {
|
||||||
|
return this.mineskin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CollectionProviderConfig collection() {
|
||||||
|
return this.collection;
|
||||||
|
}
|
||||||
|
|
||||||
|
@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();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.collection == null) {
|
||||||
|
SkinRestorer.LOGGER.warn("Collection provider config is null, using default");
|
||||||
|
this.collection = ProvidersConfig.DEFAULT.collection();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package net.lionarius.skinrestorer.config.provider.collection;
|
||||||
|
|
||||||
|
import com.google.gson.annotations.JsonAdapter;
|
||||||
|
import net.lionarius.skinrestorer.config.provider.BuiltInProviderConfig;
|
||||||
|
import net.lionarius.skinrestorer.config.provider.CacheConfig;
|
||||||
|
import net.lionarius.skinrestorer.skin.provider.CollectionSkinProvider;
|
||||||
|
import net.lionarius.skinrestorer.util.gson.GsonPostProcessable;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public final class CollectionProviderConfig extends BuiltInProviderConfig implements GsonPostProcessable {
|
||||||
|
private static final CacheConfig DEFAULT_CACHE_VALUE = new CacheConfig(true, 604800);
|
||||||
|
|
||||||
|
@JsonAdapter(CollectionSkinSourceListDeserializer.class)
|
||||||
|
private List<CollectionSkinSource> sources = new ArrayList<>();
|
||||||
|
|
||||||
|
public CollectionProviderConfig() {
|
||||||
|
super(CollectionSkinProvider.PROVIDER_NAME, DEFAULT_CACHE_VALUE, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<CollectionSkinSource> sources() {
|
||||||
|
return this.sources;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void gsonPostProcess() {
|
||||||
|
if (this.sources == null) {
|
||||||
|
this.sources = new ArrayList<>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
package net.lionarius.skinrestorer.config.provider.collection;
|
||||||
|
|
||||||
|
import net.lionarius.skinrestorer.SkinRestorer;
|
||||||
|
import net.lionarius.skinrestorer.skin.SkinVariant;
|
||||||
|
import net.lionarius.skinrestorer.util.gson.GsonPostProcessable;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
|
||||||
|
public final class CollectionSkinFile implements CollectionSkinSource, GsonPostProcessable {
|
||||||
|
private String path = "";
|
||||||
|
private SkinVariant variant = SkinVariant.CLASSIC;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable URI uri() {
|
||||||
|
if (this.path.isEmpty())
|
||||||
|
return null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
var filePath = SkinRestorer.getConfigDir().resolve(this.path);
|
||||||
|
|
||||||
|
if (!Files.exists(filePath)) {
|
||||||
|
SkinRestorer.LOGGER.warn("Skin file does not exist: {}", this.path);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!Files.isRegularFile(filePath)) {
|
||||||
|
SkinRestorer.LOGGER.warn("Skin path is not a file: {}", this.path);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.path.toLowerCase().endsWith(".png")) {
|
||||||
|
SkinRestorer.LOGGER.warn("Skin file is not a PNG file: {}", this.path);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return filePath.toUri();
|
||||||
|
} catch (Exception e) {
|
||||||
|
SkinRestorer.LOGGER.warn("Invalid file path: {}", this.path, e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SkinVariant variant() {
|
||||||
|
return this.variant;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void gsonPostProcess() {
|
||||||
|
if (this.path == null) {
|
||||||
|
this.path = "";
|
||||||
|
}
|
||||||
|
if (this.variant == null) {
|
||||||
|
this.variant = SkinVariant.CLASSIC;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package net.lionarius.skinrestorer.config.provider.collection;
|
||||||
|
|
||||||
|
import net.lionarius.skinrestorer.skin.SkinVariant;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
|
||||||
|
public interface CollectionSkinSource {
|
||||||
|
@Nullable URI uri();
|
||||||
|
|
||||||
|
SkinVariant variant();
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package net.lionarius.skinrestorer.config.provider.collection;
|
||||||
|
|
||||||
|
import com.google.gson.*;
|
||||||
|
|
||||||
|
import java.lang.reflect.Type;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class CollectionSkinSourceListDeserializer implements JsonSerializer<List<CollectionSkinSource>>, JsonDeserializer<List<CollectionSkinSource>> {
|
||||||
|
@Override
|
||||||
|
public JsonElement serialize(List<CollectionSkinSource> src, Type typeOfT, JsonSerializationContext context) {
|
||||||
|
return context.serialize(src, List.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<CollectionSkinSource> deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
|
||||||
|
throws JsonParseException {
|
||||||
|
List<CollectionSkinSource> sources = new ArrayList<>();
|
||||||
|
|
||||||
|
if (json.isJsonArray()) {
|
||||||
|
for (JsonElement element : json.getAsJsonArray()) {
|
||||||
|
if (element.isJsonObject()) {
|
||||||
|
JsonObject obj = element.getAsJsonObject();
|
||||||
|
if (obj.has("url")) {
|
||||||
|
sources.add(context.deserialize(obj, CollectionSkinUrl.class));
|
||||||
|
} else if (obj.has("path")) {
|
||||||
|
sources.add(context.deserialize(obj, CollectionSkinFile.class));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return sources;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
package net.lionarius.skinrestorer.config.provider.collection;
|
||||||
|
|
||||||
|
import net.lionarius.skinrestorer.SkinRestorer;
|
||||||
|
import net.lionarius.skinrestorer.skin.SkinVariant;
|
||||||
|
import net.lionarius.skinrestorer.util.gson.GsonPostProcessable;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
|
||||||
|
public final class CollectionSkinUrl implements CollectionSkinSource, GsonPostProcessable {
|
||||||
|
private String url = "";
|
||||||
|
private SkinVariant variant = SkinVariant.CLASSIC;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @Nullable URI uri() {
|
||||||
|
try {
|
||||||
|
if (this.url.isEmpty())
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return new URI(this.url);
|
||||||
|
} catch (Exception e) {
|
||||||
|
SkinRestorer.LOGGER.warn("Invalid URI: {}", this.url, e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SkinVariant variant() {
|
||||||
|
return this.variant;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void gsonPostProcess() {
|
||||||
|
if (this.url == null) {
|
||||||
|
this.url = "";
|
||||||
|
}
|
||||||
|
if (this.variant == null) {
|
||||||
|
this.variant = SkinVariant.CLASSIC;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package net.lionarius.skinrestorer.exception;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
public class TransparentException extends RuntimeException {
|
||||||
|
public TransparentException(@NotNull Throwable cause) {
|
||||||
|
super(cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getMessage() {
|
||||||
|
return this.getCause().getMessage();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return this.getLocalizedMessage();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,190 @@
|
|||||||
|
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 baseUrl, String userAgent, String apiKey, int timeout, Gson gson, InetSocketAddress proxy) {
|
||||||
|
super(baseUrl, 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 {
|
||||||
|
url = this.baseUrl + url;
|
||||||
|
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 {
|
||||||
|
url = this.baseUrl + url;
|
||||||
|
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 {
|
||||||
|
url = this.baseUrl + url;
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,5 +9,5 @@ import org.spongepowered.asm.mixin.gen.Accessor;
|
|||||||
public interface ChunkMapAccessor {
|
public interface ChunkMapAccessor {
|
||||||
|
|
||||||
@Accessor
|
@Accessor
|
||||||
Int2ObjectMap<Object> getEntityMap();
|
Int2ObjectMap<TrackedEntityAccessorInvoker> getEntityMap();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package net.lionarius.skinrestorer.mixin;
|
||||||
|
|
||||||
|
import com.mojang.authlib.GameProfile;
|
||||||
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.Mutable;
|
||||||
|
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||||
|
|
||||||
|
|
||||||
|
@Mixin(Player.class)
|
||||||
|
public interface PlayerAccessor {
|
||||||
|
@Accessor("gameProfile")
|
||||||
|
@Mutable
|
||||||
|
void setGameProfile(GameProfile properties);
|
||||||
|
}
|
||||||
@@ -9,6 +9,7 @@ import net.minecraft.server.players.PlayerList;
|
|||||||
import org.spongepowered.asm.mixin.Final;
|
import org.spongepowered.asm.mixin.Final;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
import org.spongepowered.asm.mixin.Shadow;
|
import org.spongepowered.asm.mixin.Shadow;
|
||||||
|
import org.spongepowered.asm.mixin.Unique;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
@@ -27,19 +28,35 @@ 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject(method = "placeNewPlayer", at = @At("HEAD"))
|
@Inject(method = "placeNewPlayer", at = @At("HEAD"))
|
||||||
private void placeNewPlayer(Connection connection, ServerPlayer player, CommonListenerCookie cookie, CallbackInfo ci) {
|
private void placeNewPlayer(Connection connection, ServerPlayer player, CommonListenerCookie cookie, CallbackInfo ci) {
|
||||||
|
var delay = SkinRestorer.getConfig().skinApplyDelayOnJoin();
|
||||||
|
|
||||||
|
if (delay <= 0) {
|
||||||
|
skinrestorer$tryApplySkin(server, player);
|
||||||
|
} else {
|
||||||
|
var uuid = player.getUUID();
|
||||||
|
SkinRestorer.getTickedScheduler().schedule(() -> {
|
||||||
|
var actualPlayer = server.getPlayerList().getPlayer(uuid);
|
||||||
|
if (actualPlayer != null)
|
||||||
|
skinrestorer$tryApplySkin(server, actualPlayer);
|
||||||
|
}, delay, uuid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Unique
|
||||||
|
private static void skinrestorer$tryApplySkin(MinecraftServer server, ServerPlayer player) {
|
||||||
if (SkinRestorer.getSkinStorage().hasSavedSkin(player.getUUID()))
|
if (SkinRestorer.getSkinStorage().hasSavedSkin(player.getUUID()))
|
||||||
SkinRestorer.applySkin(server, Collections.singleton(player.getGameProfile()), SkinRestorer.getSkinStorage().getSkin(player.getUUID()));
|
SkinRestorer.applySkin(server, Collections.singleton(player), SkinRestorer.getSkinStorage().getSkin(player.getUUID()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package net.lionarius.skinrestorer.mixin;
|
|||||||
|
|
||||||
import com.mojang.authlib.GameProfile;
|
import com.mojang.authlib.GameProfile;
|
||||||
import net.lionarius.skinrestorer.SkinRestorer;
|
import net.lionarius.skinrestorer.SkinRestorer;
|
||||||
|
import net.lionarius.skinrestorer.config.FirstJoinSkinProvider;
|
||||||
import net.lionarius.skinrestorer.skin.SkinValue;
|
import net.lionarius.skinrestorer.skin.SkinValue;
|
||||||
import net.lionarius.skinrestorer.skin.provider.SkinProviderContext;
|
import net.lionarius.skinrestorer.skin.provider.SkinProviderContext;
|
||||||
import net.lionarius.skinrestorer.util.PlayerUtils;
|
import net.lionarius.skinrestorer.util.PlayerUtils;
|
||||||
@@ -24,51 +25,71 @@ 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;Lnet/minecraft/server/players/NameAndId;)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.id())) {
|
||||||
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.id());
|
||||||
SkinRestorer.getSkinStorage().setSkin(authenticatedProfile.getId(), value.setOriginalValue(originalSkin));
|
SkinRestorer.getSkinStorage().setSkin(profile.id(), value.setOriginalValue(originalSkin));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (SkinRestorer.getConfig().refreshSkinOnJoin()) {
|
||||||
|
var currentSkin = SkinRestorer.getSkinStorage().getSkin(profile.id());
|
||||||
|
var context = currentSkin.toProviderContext();
|
||||||
|
|
||||||
|
skinrestorer$fetchSkin(profile, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (originalSkin == null && SkinRestorer.getConfig().fetchSkinOnFirstJoin()) {
|
var config = SkinRestorer.getConfig();
|
||||||
SkinRestorer.LOGGER.debug("Fetching {}'s skin", authenticatedProfile.getName());
|
var provider = config.firstJoinSkinProvider();
|
||||||
|
|
||||||
|
var shouldFetch = (originalSkin == null && config.fetchSkinOnFirstJoin()) ||
|
||||||
|
(originalSkin != null && config.forceFirstJoinSkinFetch() && provider != FirstJoinSkinProvider.MOJANG);
|
||||||
|
|
||||||
|
if (shouldFetch) {
|
||||||
var context = new SkinProviderContext(
|
var context = new SkinProviderContext(
|
||||||
SkinRestorer.getConfig().getFirstJoinSkinProvider().getName(),
|
provider.getName(),
|
||||||
authenticatedProfile.getName(),
|
profile.name(),
|
||||||
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.name());
|
||||||
|
|
||||||
|
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.id(), value);
|
||||||
|
} else {
|
||||||
|
SkinRestorer.LOGGER.warn("Failed to fetch skin '{}:{}'", context.name(), context.argument(), result.getErrorValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import org.spongepowered.asm.mixin.gen.Invoker;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@Mixin(targets = "net.minecraft.server.level.ChunkMap$TrackedEntity")
|
@Mixin(targets = "net.minecraft.server.level.ChunkMap$TrackedEntity")
|
||||||
public interface TrackedEntityMixin {
|
public interface TrackedEntityAccessorInvoker {
|
||||||
|
|
||||||
@Accessor
|
@Accessor
|
||||||
Set<ServerPlayerConnection> getSeenBy();
|
Set<ServerPlayerConnection> getSeenBy();
|
||||||
@@ -0,0 +1,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 {
|
||||||
|
|
||||||
|
public final static PlatformHelper PLATFORM = load(PlatformHelper.class);
|
||||||
|
public final static CompatibilityHelper COMPATIBILITY = load(CompatibilityHelper.class);
|
||||||
|
|
||||||
|
private Services() {}
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
@@ -27,9 +27,7 @@ public class SkinIO {
|
|||||||
|
|
||||||
public SkinValue loadSkin(UUID uuid) {
|
public SkinValue loadSkin(UUID uuid) {
|
||||||
try {
|
try {
|
||||||
var value = SkinIO.loadSkin(savePath.resolve(SkinIO.uuidToFilename(uuid)));
|
return SkinIO.loadSkin(savePath.resolve(SkinIO.uuidToFilename(uuid)));
|
||||||
Objects.requireNonNull(value.provider());
|
|
||||||
return value;
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return SkinValue.EMPTY;
|
return SkinValue.EMPTY;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,15 +17,22 @@ public class SkinStorage {
|
|||||||
return this.skinMap.containsKey(uuid) || this.skinIO.skinExists(uuid);
|
return this.skinMap.containsKey(uuid) || this.skinIO.skinExists(uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SkinValue getSkin(UUID uuid) {
|
public SkinValue getSkin(UUID uuid, boolean cache) {
|
||||||
if (!skinMap.containsKey(uuid)) {
|
if (!skinMap.containsKey(uuid)) {
|
||||||
var skin = skinIO.loadSkin(uuid);
|
var skin = skinIO.loadSkin(uuid);
|
||||||
|
if (!cache)
|
||||||
|
return skin;
|
||||||
|
|
||||||
setSkin(uuid, skin);
|
setSkin(uuid, skin);
|
||||||
}
|
}
|
||||||
|
|
||||||
return skinMap.get(uuid);
|
return skinMap.get(uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public SkinValue getSkin(UUID uuid) {
|
||||||
|
return this.getSkin(uuid, true);
|
||||||
|
}
|
||||||
|
|
||||||
public void removeSkin(UUID uuid, boolean save) {
|
public void removeSkin(UUID uuid, boolean save) {
|
||||||
var skin = skinMap.remove(uuid);
|
var skin = skinMap.remove(uuid);
|
||||||
if (skin != null && save)
|
if (skin != null && save)
|
||||||
|
|||||||
@@ -3,11 +3,14 @@ package net.lionarius.skinrestorer.skin;
|
|||||||
import com.mojang.authlib.properties.Property;
|
import com.mojang.authlib.properties.Property;
|
||||||
import net.lionarius.skinrestorer.skin.provider.EmptySkinProvider;
|
import net.lionarius.skinrestorer.skin.provider.EmptySkinProvider;
|
||||||
import net.lionarius.skinrestorer.skin.provider.SkinProviderContext;
|
import net.lionarius.skinrestorer.skin.provider.SkinProviderContext;
|
||||||
|
import net.lionarius.skinrestorer.util.gson.GsonPostProcessable;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
public record SkinValue(@NotNull String provider, @Nullable String argument, @Nullable SkinVariant variant,
|
public record SkinValue(@NotNull String provider, @Nullable String argument, @Nullable SkinVariant variant,
|
||||||
@Nullable Property value, @Nullable Property originalValue) {
|
@Nullable Property value, @Nullable Property originalValue) implements GsonPostProcessable {
|
||||||
|
|
||||||
public static final SkinValue EMPTY = new SkinValue(EmptySkinProvider.PROVIDER_NAME, null, null, null);
|
public static final SkinValue EMPTY = new SkinValue(EmptySkinProvider.PROVIDER_NAME, null, null, null);
|
||||||
|
|
||||||
@@ -30,4 +33,9 @@ public record SkinValue(@NotNull String provider, @Nullable String argument, @Nu
|
|||||||
public SkinValue setOriginalValue(Property originalValue) {
|
public SkinValue setOriginalValue(Property originalValue) {
|
||||||
return new SkinValue(this.provider, this.argument, this.variant, this.value, originalValue);
|
return new SkinValue(this.provider, this.argument, this.variant, this.value, originalValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void gsonPostProcess() {
|
||||||
|
Objects.requireNonNull(this.provider);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
package net.lionarius.skinrestorer.skin;
|
package net.lionarius.skinrestorer.skin;
|
||||||
|
|
||||||
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
|
||||||
public enum SkinVariant {
|
public enum SkinVariant {
|
||||||
|
@SerializedName(value = "classic", alternate = {"CLASSIC"})
|
||||||
CLASSIC("classic"),
|
CLASSIC("classic"),
|
||||||
|
@SerializedName(value = "slim", alternate = {"SLIM"})
|
||||||
SLIM("slim");
|
SLIM("slim");
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|||||||
@@ -0,0 +1,91 @@
|
|||||||
|
package net.lionarius.skinrestorer.skin.provider;
|
||||||
|
|
||||||
|
import com.google.common.cache.CacheBuilder;
|
||||||
|
import com.google.common.cache.CacheLoader;
|
||||||
|
import com.google.common.cache.LoadingCache;
|
||||||
|
import com.google.common.util.concurrent.UncheckedExecutionException;
|
||||||
|
import com.mojang.authlib.properties.Property;
|
||||||
|
import it.unimi.dsi.fastutil.Pair;
|
||||||
|
import net.lionarius.skinrestorer.SkinRestorer;
|
||||||
|
import net.lionarius.skinrestorer.config.provider.collection.CollectionSkinSource;
|
||||||
|
import net.lionarius.skinrestorer.skin.SkinVariant;
|
||||||
|
import net.lionarius.skinrestorer.util.Result;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
public final class CollectionSkinProvider implements SkinProvider {
|
||||||
|
|
||||||
|
public static final String PROVIDER_NAME = "collection";
|
||||||
|
|
||||||
|
private static LoadingCache<Integer, Optional<Property>> SKIN_CACHE;
|
||||||
|
|
||||||
|
private static List<Pair<URI, SkinVariant>> COLLECTION_SKINS;
|
||||||
|
|
||||||
|
public static void reload() {
|
||||||
|
COLLECTION_SKINS = loadCollectionSkins();
|
||||||
|
|
||||||
|
createCache();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static List<Pair<URI, SkinVariant>> loadCollectionSkins() {
|
||||||
|
List<Pair<URI, SkinVariant>> skins = new ArrayList<>();
|
||||||
|
|
||||||
|
var config = SkinRestorer.getConfig().providersConfig().collection();
|
||||||
|
|
||||||
|
for (CollectionSkinSource source : config.sources()) {
|
||||||
|
var uri = source.uri();
|
||||||
|
if (uri != null) {
|
||||||
|
skins.add(Pair.of(uri, source.variant()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return skins;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void createCache() {
|
||||||
|
var config = SkinRestorer.getConfig().providersConfig().collection();
|
||||||
|
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 Integer key) throws Exception {
|
||||||
|
var skinEntry = COLLECTION_SKINS.get(key);
|
||||||
|
return MineskinSkinProvider.loadSkin(skinEntry.first(), skinEntry.second());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getArgumentName() {
|
||||||
|
return "seed";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasVariantSupport() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Result<Optional<Property>, Exception> fetchSkin(String argument, SkinVariant variant) {
|
||||||
|
if (COLLECTION_SKINS.isEmpty()) {
|
||||||
|
return Result.error(new IllegalStateException("No collection skins configured"));
|
||||||
|
}
|
||||||
|
|
||||||
|
var skinIndex = Math.abs(argument.hashCode()) % COLLECTION_SKINS.size();
|
||||||
|
|
||||||
|
try {
|
||||||
|
return Result.success(SKIN_CACHE.get(skinIndex));
|
||||||
|
} catch (UncheckedExecutionException e) {
|
||||||
|
return Result.error((Exception) e.getCause());
|
||||||
|
} catch (Exception e) {
|
||||||
|
return Result.error(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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).profile();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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,31 +1,76 @@
|
|||||||
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.nio.file.Files;
|
||||||
import java.net.http.HttpRequest;
|
import java.nio.file.Path;
|
||||||
|
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 MineSkinClient MINESKIN_CLIENT;
|
||||||
|
|
||||||
static {
|
private static LoadingCache<Pair<URI, SkinVariant>, Optional<Property>> SKIN_CACHE;
|
||||||
try {
|
|
||||||
API_URI = new URI("https://api.mineskin.org/");
|
public static void reload() {
|
||||||
} catch (URISyntaxException e) {
|
var config = SkinRestorer.getConfig();
|
||||||
throw new IllegalArgumentException(e);
|
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((baseUrl, userAgent, apiKey, timeout, gson) -> new Java11RequestHandler(
|
||||||
|
baseUrl,
|
||||||
|
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
|
||||||
@@ -39,33 +84,44 @@ 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 {
|
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 = "file".equals(uri.getScheme())
|
||||||
.uri(MineskinSkinProvider.API_URI.resolve("generate/url"))
|
? GenerateRequest.upload(Files.newInputStream(Path.of(uri)))
|
||||||
.POST(HttpRequest.BodyPublishers.ofString(body))
|
.variant(mineskinVariant)
|
||||||
.header("Content-Type", "application/json")
|
.name("skinrestorer-skin")
|
||||||
.build();
|
.visibility(Visibility.UNLISTED)
|
||||||
|
: GenerateRequest.url(uri)
|
||||||
|
.variant(mineskinVariant)
|
||||||
|
.name("skinrestorer-skin")
|
||||||
|
.visibility(Visibility.UNLISTED);
|
||||||
|
|
||||||
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,38 +1,100 @@
|
|||||||
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.mojang.authlib.GameProfile;
|
import com.google.common.cache.CacheLoader;
|
||||||
|
import com.google.common.cache.LoadingCache;
|
||||||
|
import com.google.common.util.concurrent.UncheckedExecutionException;
|
||||||
|
import com.mojang.authlib.*;
|
||||||
import com.mojang.authlib.properties.Property;
|
import com.mojang.authlib.properties.Property;
|
||||||
|
import com.mojang.authlib.yggdrasil.YggdrasilEnvironment;
|
||||||
|
import com.mojang.authlib.yggdrasil.response.MinecraftProfilePropertiesResponse;
|
||||||
|
import com.mojang.authlib.yggdrasil.response.NameAndId;
|
||||||
|
import com.mojang.util.UndashedUuid;
|
||||||
|
import net.lionarius.skinrestorer.SkinRestorer;
|
||||||
|
import net.lionarius.skinrestorer.exception.TransparentException;
|
||||||
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.CachedUserNameToIdResolver;
|
||||||
|
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 {
|
||||||
|
|
||||||
public static final String PROVIDER_NAME = "mojang";
|
public static final String PROVIDER_NAME = "mojang";
|
||||||
|
public static final String PROFILE_CACHE_FILENAME = "mojang_profile_cache.json";
|
||||||
private static final URI API_URI;
|
private static final Environment ENVIRONMENT;
|
||||||
|
private static final URI SERVICES_SERVER_URI;
|
||||||
private static final URI SESSION_SERVER_URI;
|
private static final URI SESSION_SERVER_URI;
|
||||||
|
private static final CachedUserNameToIdResolver PROFILE_CACHE;
|
||||||
|
|
||||||
|
private static LoadingCache<UUID, Optional<Property>> SKIN_CACHE;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
try {
|
try {
|
||||||
API_URI = new URI("https://api.mojang.com/");
|
ENVIRONMENT = EnvironmentParser.getEnvironmentFromProperties().orElse(YggdrasilEnvironment.PROD.getEnvironment());
|
||||||
SESSION_SERVER_URI = new URI("https://sessionserver.mojang.com/");
|
|
||||||
|
SERVICES_SERVER_URI = new URI(ENVIRONMENT.servicesHost());
|
||||||
|
SESSION_SERVER_URI = new URI(ENVIRONMENT.sessionHost());
|
||||||
} catch (URISyntaxException e) {
|
} catch (URISyntaxException e) {
|
||||||
throw new IllegalArgumentException(e);
|
throw new IllegalArgumentException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PROFILE_CACHE = new CachedUserNameToIdResolver(new GameProfileRepository() {
|
||||||
|
@Override
|
||||||
|
public void findProfilesByNames(String[] names, ProfileLookupCallback callback) {
|
||||||
|
for (var name : names) {
|
||||||
|
try {
|
||||||
|
var profile = MojangSkinProvider.getProfile(name);
|
||||||
|
callback.onProfileLookupSucceeded(profile.name(), profile.id());
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new TransparentException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Optional<NameAndId> findProfileByName(String name) {
|
||||||
|
try {
|
||||||
|
var profile = MojangSkinProvider.getProfile(name);
|
||||||
|
return Optional.of(new NameAndId(profile.id(), profile.name()));
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new TransparentException(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) {
|
||||||
return new SkinProviderContext(MojangSkinProvider.PROVIDER_NAME, gameProfile.getName(), null);
|
return new SkinProviderContext(MojangSkinProvider.PROVIDER_NAME, gameProfile.name(), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -46,24 +108,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().id()));
|
||||||
|
} 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 NameAndId getProfile(final String name) throws IOException {
|
||||||
var request = HttpRequest.newBuilder()
|
var request = HttpRequest.newBuilder()
|
||||||
.uri(MojangSkinProvider.API_URI
|
.uri(MojangSkinProvider.SERVICES_SERVER_URI
|
||||||
.resolve("users/profiles/minecraft/")
|
.resolve("/minecraft/profile/lookup/name/")
|
||||||
.resolve(name)
|
.resolve(name)
|
||||||
)
|
)
|
||||||
.GET()
|
.GET()
|
||||||
@@ -75,18 +147,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(), NameAndId.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 +165,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).profile();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,20 +1,33 @@
|
|||||||
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();
|
||||||
|
CollectionSkinProvider COLLECTION = new CollectionSkinProvider();
|
||||||
|
SkinShuffleSkinProvider SKIN_SHUFFLE = new SkinShuffleSkinProvider();
|
||||||
|
|
||||||
|
Set<String> BUILTIN_PROVIDER_NAMES = ImmutableSet.of(
|
||||||
|
EmptySkinProvider.PROVIDER_NAME,
|
||||||
|
MojangSkinProvider.PROVIDER_NAME,
|
||||||
|
ElyBySkinProvider.PROVIDER_NAME,
|
||||||
|
MineskinSkinProvider.PROVIDER_NAME,
|
||||||
|
CollectionSkinProvider.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,28 @@
|
|||||||
package net.lionarius.skinrestorer.util;
|
package net.lionarius.skinrestorer.util;
|
||||||
|
|
||||||
import com.google.gson.*;
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.GsonBuilder;
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
import com.mojang.authlib.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())
|
||||||
|
.setPrettyPrinting()
|
||||||
|
.create();
|
||||||
|
|
||||||
private JsonUtils() {}
|
private JsonUtils() {}
|
||||||
|
|
||||||
@@ -31,7 +43,7 @@ public final class JsonUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static JsonObject parseJson(String json) {
|
public static JsonObject parseJson(String json) {
|
||||||
return JsonParser.parseString(json).getAsJsonObject();
|
return GSON.fromJson(json, JsonObject.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static JsonObject skinPropertyToJson(Property property) {
|
public static JsonObject skinPropertyToJson(Property property) {
|
||||||
@@ -42,7 +54,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,13 @@
|
|||||||
package net.lionarius.skinrestorer.util;
|
package net.lionarius.skinrestorer.util;
|
||||||
|
|
||||||
import com.google.gson.JsonArray;
|
import com.google.common.collect.Iterables;
|
||||||
|
import com.google.common.collect.LinkedHashMultimap;
|
||||||
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.properties.PropertyMap;
|
||||||
|
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.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;
|
||||||
@@ -38,7 +40,7 @@ public final class PlayerUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void refreshPlayer(ServerPlayer player) {
|
public static void refreshPlayer(ServerPlayer player) {
|
||||||
ServerLevel serverLevel = player.serverLevel();
|
ServerLevel serverLevel = player.level();
|
||||||
PlayerList playerList = serverLevel.getServer().getPlayerList();
|
PlayerList playerList = serverLevel.getServer().getPlayerList();
|
||||||
ChunkMap chunkMap = serverLevel.getChunkSource().chunkMap;
|
ChunkMap chunkMap = serverLevel.getChunkSource().chunkMap;
|
||||||
|
|
||||||
@@ -49,14 +51,14 @@ public final class PlayerUtils {
|
|||||||
)
|
)
|
||||||
));
|
));
|
||||||
|
|
||||||
var trackedEntity = (TrackedEntityMixin) ((ChunkMapAccessor) chunkMap).getEntityMap().get(player.getId());
|
var trackedEntity = ((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 = ((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,23 +91,34 @@ 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 GameProfile cloneGameProfile(GameProfile profile) {
|
||||||
return profile.getProperties().get(TEXTURES_KEY).stream().findFirst().orElse(null);
|
var newProfile = new GameProfile(profile.id(), profile.name());
|
||||||
}
|
newProfile.properties().putAll(profile.properties());
|
||||||
|
|
||||||
public static void applyRestoredSkin(GameProfile profile, Property skin) {
|
|
||||||
profile.getProperties().removeAll(TEXTURES_KEY);
|
|
||||||
|
|
||||||
if (skin != null)
|
return newProfile;
|
||||||
profile.getProperties().put(TEXTURES_KEY, skin);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Property getPlayerSkin(GameProfile profile) {
|
||||||
|
return Iterables.getFirst(profile.properties().get(TEXTURES_KEY), null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static GameProfile applyRestoredSkin(GameProfile profile, Property skin) {
|
||||||
|
var propertiesMap = profile.properties();
|
||||||
|
|
||||||
|
var newProperties = LinkedHashMultimap.create(propertiesMap);
|
||||||
|
newProperties.removeAll(TEXTURES_KEY);
|
||||||
|
if (skin != null) {
|
||||||
|
newProperties.put(TEXTURES_KEY, skin);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new GameProfile(profile.id(), profile.name(), new PropertyMap(newProperties));
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean areSkinPropertiesEquals(Property x, Property y) {
|
public static boolean areSkinPropertiesEquals(Property x, Property y) {
|
||||||
if (x == y)
|
if (x == y)
|
||||||
@@ -126,24 +139,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.properties().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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,18 @@ public class Result<S, E> {
|
|||||||
this.errorValue = errorValue;
|
this.errorValue = errorValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static <S, E> Result<S, E> success(@NotNull S successValue) {
|
||||||
|
return new Result<>(successValue, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <S, E> Result<S, E> error(@NotNull E errorValue) {
|
||||||
|
return new Result<>(null, errorValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <S, E> Result<Optional<S>, E> ofNullable(S successValue) {
|
||||||
|
return Result.success(Optional.ofNullable(successValue));
|
||||||
|
}
|
||||||
|
|
||||||
public S getSuccessValue() {
|
public S getSuccessValue() {
|
||||||
return successValue;
|
return successValue;
|
||||||
}
|
}
|
||||||
@@ -69,16 +81,4 @@ public class Result<S, E> {
|
|||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hash(successValue, errorValue);
|
return Objects.hash(successValue, errorValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <S, E> Result<S, E> success(@NotNull S successValue) {
|
|
||||||
return new Result<>(successValue, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <S, E> Result<S, E> error(@NotNull E errorValue) {
|
|
||||||
return new Result<>(null, errorValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static <S, E> Result<Optional<S>, E> ofNullable(S successValue) {
|
|
||||||
return Result.success(Optional.ofNullable(successValue));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,60 @@
|
|||||||
|
package net.lionarius.skinrestorer.util;
|
||||||
|
|
||||||
|
import net.minecraft.server.MinecraftServer;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Queue;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.concurrent.PriorityBlockingQueue;
|
||||||
|
|
||||||
|
public class TickedScheduler implements Runnable {
|
||||||
|
private final MinecraftServer server;
|
||||||
|
private final Queue<TickTask> queue = new PriorityBlockingQueue<>();
|
||||||
|
private final Map<Integer, Integer> idMap = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
public TickedScheduler(MinecraftServer server) {
|
||||||
|
this.server = server;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void schedule(Runnable task, int delay) {
|
||||||
|
this.schedule(task, delay, task);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void schedule(Runnable task, int delay, Object id) {
|
||||||
|
var taskId = id.hashCode();
|
||||||
|
var serverTick = this.server.getTickCount();
|
||||||
|
this.idMap.merge(taskId, serverTick, Integer::max);
|
||||||
|
this.queue.add(new TickTask(serverTick, serverTick + delay, taskId, task));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void cancel(Object id) {
|
||||||
|
var taskId = id.hashCode();
|
||||||
|
this.idMap.remove(taskId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
TickTask nextTask;
|
||||||
|
while ((nextTask = this.queue.peek()) != null) {
|
||||||
|
if (nextTask.runOnTick() > this.server.getTickCount())
|
||||||
|
break;
|
||||||
|
|
||||||
|
var tickTask = this.queue.remove();
|
||||||
|
var lastTaskScheduledOnTick = this.idMap.get(tickTask.id());
|
||||||
|
|
||||||
|
if (lastTaskScheduledOnTick != null && lastTaskScheduledOnTick <= tickTask.scheduledOnTick()) {
|
||||||
|
this.idMap.remove(tickTask.id());
|
||||||
|
if (tickTask.task() != null)
|
||||||
|
tickTask.task().run();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private record TickTask(int scheduledOnTick, int runOnTick, int id, Runnable task) implements Comparable<TickTask> {
|
||||||
|
@Override
|
||||||
|
public int compareTo(@NotNull TickedScheduler.TickTask other) {
|
||||||
|
return Integer.compare(this.runOnTick, other.runOnTick);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,44 +10,39 @@ 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 {
|
||||||
|
|
||||||
private 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
private WebUtils() {}
|
||||||
|
|
||||||
|
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": "配置已重新載入"
|
||||||
}
|
}
|
||||||
|
|||||||
1
common/src/main/resources/skinrestorer.accesswidener
Normal file
1
common/src/main/resources/skinrestorer.accesswidener
Normal file
@@ -0,0 +1 @@
|
|||||||
|
accessWidener v2 named
|
||||||
@@ -2,13 +2,15 @@
|
|||||||
"required": true,
|
"required": true,
|
||||||
"minVersion": "0.8",
|
"minVersion": "0.8",
|
||||||
"package": "net.lionarius.skinrestorer.mixin",
|
"package": "net.lionarius.skinrestorer.mixin",
|
||||||
"compatibilityLevel": "JAVA_8",
|
"compatibilityLevel": "JAVA_17",
|
||||||
|
"priority": 1100,
|
||||||
"refmap": "${mod_id}.refmap.json",
|
"refmap": "${mod_id}.refmap.json",
|
||||||
"mixins": [
|
"mixins": [
|
||||||
|
"ChunkMapAccessor",
|
||||||
|
"PlayerAccessor",
|
||||||
"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()
|
||||||
|
|||||||
6
fabric/gradle.properties
Normal file
6
fabric/gradle.properties
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
# Fabric, see https://fabricmc.net/develop/ for new versions
|
||||||
|
fabric_loader_version=0.15.0
|
||||||
|
fabric_api_version=0.133.14+1.21.9
|
||||||
|
|
||||||
|
optional_dependencies=fabric-api
|
||||||
|
additional_modloaders=quilt
|
||||||
@@ -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(SkinRestorer.getMinecraftServer(), 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,12 @@ 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Inject(method = "runServer",
|
||||||
|
at = @At(value = "INVOKE", target = "Lnet/minecraft/server/MinecraftServer;onServerExit()V"))
|
||||||
|
private void onServerStopped(CallbackInfo ci) {
|
||||||
|
SkinRestorer.Events.onServerStopped((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);
|
||||||
|
}
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user