mirror of
https://github.com/Suiranoil/SkinRestorer.git
synced 2026-01-16 04:42:12 +00:00
Compare commits
2 Commits
da754aa830
...
v2.0.3+1.2
| Author | SHA1 | Date | |
|---|---|---|---|
|
49290171e2
|
|||
|
b72d0c1e85
|
90
.github/ISSUE_TEMPLATE/bug_report.yaml
vendored
90
.github/ISSUE_TEMPLATE/bug_report.yaml
vendored
@@ -1,90 +0,0 @@
|
|||||||
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
1
.github/ISSUE_TEMPLATE/config.yml
vendored
@@ -1 +0,0 @@
|
|||||||
blank_issues_enabled: true
|
|
||||||
52
.github/ISSUE_TEMPLATE/feature_request.yaml
vendored
52
.github/ISSUE_TEMPLATE/feature_request.yaml
vendored
@@ -1,52 +0,0 @@
|
|||||||
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,6 +4,8 @@ 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,5 +1,8 @@
|
|||||||
name: release
|
name: release
|
||||||
on:
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- "v*"
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
|||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -30,4 +30,3 @@ bin/
|
|||||||
|
|
||||||
.architectury-transformer/
|
.architectury-transformer/
|
||||||
run/
|
run/
|
||||||
scripts/
|
|
||||||
|
|||||||
78
CHANGELOG.md
78
CHANGELOG.md
@@ -4,84 +4,6 @@ All notable changes to this project will be documented in this file.
|
|||||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
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.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,3 +1,4 @@
|
|||||||
|
### Added
|
||||||
|
- Added `firstJoinSkinProvider` config option (see [wiki](https://github.com/Suiranoil/SkinRestorer/wiki/Config#firstjoinskinprovider))
|
||||||
### Fixed
|
### 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 ability to set config values to `null`
|
||||||
- Fixed server freeze when loading player head skin
|
|
||||||
|
|||||||
103
README.md
103
README.md
@@ -1,7 +1,7 @@
|
|||||||
# SkinRestorer
|
# SkinRestorer
|
||||||
|
|
||||||
<a href="https://modrinth.com/mod/skinrestorer"><img src="https://raw.githubusercontent.com/Suiranoil/badges/main/assets/minecraft/platform/modrinth/mini/badge.svg" alt="Modrinth"></a>
|
<a href="https://www.curseforge.com/minecraft/mc-mods/skinrestorer"><img src="https://raw.githubusercontent.com/Suiranoil/badges/main/assets/minecraft/platform/curseforge/mini/badge.svg" alt="CurseForge" height="32"></a>
|
||||||
<a 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 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 server-side mod for managing and restoring player skins.
|
A server-side mod for managing and restoring player skins.
|
||||||
|
|
||||||
@@ -9,36 +9,95 @@ 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
|
- **Set skins from URL**: Fetch and apply skins from any image URL, supporting both classic (Steve) and slim (Alex) skin models.
|
||||||
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/Config)).
|
||||||
- **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
|
||||||
|
|
||||||
For a detailed list of available commands and their usage, please visit
|
### Set Mojang skin
|
||||||
the [commands wiki page](https://github.com/Suiranoil/SkinRestorer/wiki/Commands).
|
|
||||||
|
|
||||||
## ❌ Known Incompatibilities
|
Fetch and apply skins using a valid Minecraft username.
|
||||||
|
|
||||||
- **[Arclight](https://github.com/IzzelAliz/Arclight) (<=1.20.1)**: Trials or older versions are not compatible due to
|
```
|
||||||
mixin conflicts.
|
/skin set mojang <username> [<targets>]
|
||||||
As an alternative, consider using the [SkinsRestorer](https://www.spigotmc.org/resources/skinsrestorer.2124/) plugin.
|
```
|
||||||
|
|
||||||
## 🪙 Donation
|
- **Parameters**
|
||||||
|
- `<username>`: Minecraft username to fetch the skin from.
|
||||||
|
- `[<targets>]`: (Optional, server operators only) Player(s) to apply the skin to.
|
||||||
|
|
||||||
If you enjoy using **SkinRestorer** and would like to support its development, you can contribute through the following
|
### Set Ely.by skin
|
||||||
platforms:
|
|
||||||
|
|
||||||
<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>
|
Fetch and apply skins using a valid [Ely.by](https://ely.by/) username.
|
||||||
|
|
||||||
<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>]
|
||||||
|
```
|
||||||
|
|
||||||
Bitcoin (BTC): `1Ndbwny8pxdnWXFgadp95fp97y5JqMJKTX`
|
- **Parameters**
|
||||||
USDT (TRC20): `TGXn8wrqku5KLzwPWQAeH7wgnV4UzwHEae`
|
- `<username>`: Ely.by username to fetch the skin from.
|
||||||
USDT (TON): `UQAQF18Xlmx-V1oZ90C2YOju5qI7q1LgrCP5QaIUhqIELmDS`
|
- `[<targets>]`: (Optional, server operators only) Player(s) to apply the skin to.
|
||||||
|
|
||||||
Thank you for your generosity!
|
### Set Web skin
|
||||||
|
|
||||||
|
Fetch and apply skins from any image URL, supporting both classic (Steve) and slim (Alex) skin models.
|
||||||
|
|
||||||
|
Uses [mineskin api](https://mineskin.org/) under the hood.
|
||||||
|
|
||||||
|
```
|
||||||
|
/skin set web (classic|slim) "<url>" [<targets>]
|
||||||
|
```
|
||||||
|
|
||||||
|
- **Parameters**
|
||||||
|
- `(classic|slim)`: Type of the skin model (`classic` for Steve model, `slim` for Alex model).
|
||||||
|
- `"<url>"`: URL pointing to the skin image file (ensure it follows Minecraft's skin size and format requirements).
|
||||||
|
- `[<targets>]`: (Optional, server operators only) Player(s) to apply the skin to.
|
||||||
|
|
||||||
|
### Refresh skin
|
||||||
|
|
||||||
|
Refetch and reapply the currently applied skins.
|
||||||
|
|
||||||
|
```
|
||||||
|
/skin refresh [<targets>]
|
||||||
|
```
|
||||||
|
|
||||||
|
- **Parameters**
|
||||||
|
- `[<targets>]`: (Optional, server operators only) Player(s) to refresh the skin for.
|
||||||
|
|
||||||
|
### Clear skin
|
||||||
|
|
||||||
|
Remove the currently applied skins.
|
||||||
|
|
||||||
|
```
|
||||||
|
/skin clear [<targets>]
|
||||||
|
```
|
||||||
|
|
||||||
|
- **Parameters**
|
||||||
|
- `[<targets>]`: (Optional, server operators only) Player(s) to clear the skin for.
|
||||||
|
|
||||||
|
### Reset skin
|
||||||
|
|
||||||
|
Reset to the default skin or remove any custom skin.
|
||||||
|
|
||||||
|
If [automatic skin fetching](https://github.com/Suiranoil/SkinRestorer/wiki/Config#fetchskinonfirstjoin) is enabled, a new skin will be fetched when the player rejoins the server.
|
||||||
|
|
||||||
|
```
|
||||||
|
/skin reset [<targets>]
|
||||||
|
```
|
||||||
|
|
||||||
|
- **Parameters**
|
||||||
|
- `[<targets>]`: (Optional, server operators only) Player(s) to reset the skin for.
|
||||||
|
|
||||||
|
### Notes
|
||||||
|
|
||||||
|
- If `targets` is not specified, the command will apply to the player executing the command.
|
||||||
|
|
||||||
|
### Examples
|
||||||
|
|
||||||
|
```
|
||||||
|
/skin set mojang Notch
|
||||||
|
/skin set web classic "https://example.com/skin.png"
|
||||||
|
/skin clear @a
|
||||||
|
```
|
||||||
|
|||||||
26
build.gradle
26
build.gradle
@@ -1,29 +1,13 @@
|
|||||||
plugins {
|
plugins {
|
||||||
// see https://fabricmc.net/develop/ for new versions
|
// see https://fabricmc.net/develop/ for new versions
|
||||||
id 'fabric-loom' version '1.11-SNAPSHOT' apply false
|
id 'fabric-loom' version '1.7-SNAPSHOT' apply false
|
||||||
// see https://projects.neoforged.net/neoforged/moddevgradle for new versions
|
// see https://projects.neoforged.net/neoforged/neogradle for new versions
|
||||||
id 'net.neoforged.moddev' version '2.0.+' apply false
|
id 'net.neoforged.gradle.userdev' version '7.0.153' apply false
|
||||||
// see https://files.minecraftforge.net/net/minecraftforge/gradle/ForgeGradle/ for new versions
|
// see https://files.minecraftforge.net/net/minecraftforge/gradle/ForgeGradle/ for new versions
|
||||||
id 'net.minecraftforge.gradle' version '6.0.+' apply false
|
id 'net.minecraftforge.gradle' version '6.0.26' 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.8.+' apply false
|
id 'me.modmuss50.mod-publish-plugin' version '0.6.3' 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}"
|
archivesName = "${mod_id}-${project.name}"
|
||||||
version = "${mod_version}+${minecraft_version}-${project.name}"
|
version = "${mod_version}+${minecraft_version}"
|
||||||
}
|
}
|
||||||
|
|
||||||
java {
|
java {
|
||||||
@@ -83,6 +83,7 @@ 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,
|
||||||
@@ -91,20 +92,16 @@ 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,17 +3,12 @@ plugins {
|
|||||||
}
|
}
|
||||||
|
|
||||||
publishMods {
|
publishMods {
|
||||||
file = project.layout.buildDirectory.file("libs/${project.archivesBaseName}-${project.version}.jar").map { it.asFile }.getOrNull()
|
if (project.name == 'fabric')
|
||||||
|
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}"
|
||||||
@@ -27,9 +22,6 @@ 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 {
|
||||||
@@ -39,8 +31,5 @@ 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,8 +11,6 @@ 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 {
|
||||||
@@ -20,7 +18,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,25 +1,18 @@
|
|||||||
package net.lionarius.skinrestorer;
|
package net.lionarius.skinrestorer;
|
||||||
|
|
||||||
import com.google.common.base.Throwables;
|
import com.mojang.authlib.GameProfile;
|
||||||
import com.mojang.brigadier.CommandDispatcher;
|
|
||||||
import net.lionarius.skinrestorer.command.SkinCommand;
|
|
||||||
import net.lionarius.skinrestorer.config.Config;
|
import net.lionarius.skinrestorer.config.Config;
|
||||||
import net.lionarius.skinrestorer.config.provider.BuiltInProviderConfig;
|
|
||||||
import net.lionarius.skinrestorer.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.*;
|
import net.lionarius.skinrestorer.util.FileUtils;
|
||||||
import net.minecraft.commands.CommandSourceStack;
|
import net.lionarius.skinrestorer.util.PlayerUtils;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.lionarius.skinrestorer.util.Result;
|
||||||
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;
|
||||||
|
|
||||||
@@ -37,8 +30,6 @@ 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() {}
|
||||||
|
|
||||||
@@ -58,99 +49,74 @@ 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 ResourceLocation resourceLocation(String name) {
|
public static void onInitialize(Path rootConfigDir) {
|
||||||
return ResourceLocation.fromNamespaceAndPath(SkinRestorer.MOD_ID, name);
|
SkinRestorer.configDir = rootConfigDir.resolve(SkinRestorer.MOD_ID);
|
||||||
}
|
|
||||||
|
|
||||||
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(SkinShuffleSkinProvider.PROVIDER_NAME, SkinProvider.SKIN_SHUFFLE, false);
|
SkinRestorer.providersRegistry.register(MojangSkinProvider.PROVIDER_NAME, SkinProvider.MOJANG);
|
||||||
|
SkinRestorer.providersRegistry.register(ElyBySkinProvider.PROVIDER_NAME, SkinProvider.ELY_BY);
|
||||||
SkinRestorer.registerDefaultSkinProvider(MojangSkinProvider.PROVIDER_NAME, SkinProvider.MOJANG, SkinRestorer.getConfig().providersConfig().mojang());
|
SkinRestorer.providersRegistry.register(MineskinSkinProvider.PROVIDER_NAME, SkinProvider.MINESKIN);
|
||||||
SkinRestorer.registerDefaultSkinProvider(ElyBySkinProvider.PROVIDER_NAME, SkinProvider.ELY_BY, SkinRestorer.getConfig().providersConfig().ely_by());
|
|
||||||
SkinRestorer.registerDefaultSkinProvider(MineskinSkinProvider.PROVIDER_NAME, SkinProvider.MINESKIN, SkinRestorer.getConfig().providersConfig().mineskin());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void registerDefaultSkinProvider(String defaultName, SkinProvider provider, BuiltInProviderConfig config) {
|
public static void onServerStarted(MinecraftServer server) {
|
||||||
var isDefaultName = config.name().equals(defaultName);
|
Path worldSkinDirectory = server.getWorldPath(LevelResource.ROOT).resolve(SkinRestorer.MOD_ID);
|
||||||
SkinRestorer.providersRegistry.register(defaultName, provider, config.enabled() && isDefaultName);
|
FileUtils.tryMigrateOldSkinDirectory(worldSkinDirectory);
|
||||||
|
|
||||||
if (!isDefaultName && !SkinProvider.BUILTIN_PROVIDER_NAMES.contains(config.name()))
|
SkinRestorer.skinStorage = new SkinStorage(new SkinIO(worldSkinDirectory));
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Collection<ServerPlayer> applySkin(MinecraftServer server, Iterable<ServerPlayer> targets, SkinValue value, boolean save) {
|
public static String resource(String name) {
|
||||||
|
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 player : targets) {
|
for (var profile : targets) {
|
||||||
var profile = player.getGameProfile();
|
if (!SkinRestorer.getSkinStorage().hasSavedSkin(profile.getId()))
|
||||||
var skin = PlayerUtils.getPlayerSkin(profile);
|
value = value.setOriginalValue(PlayerUtils.getPlayerSkin(profile));
|
||||||
|
|
||||||
if (!SkinRestorer.getSkinStorage().hasSavedSkin(profile.id()))
|
|
||||||
value = value.setOriginalValue(skin);
|
|
||||||
|
|
||||||
if (PlayerUtils.areSkinPropertiesEquals(value.value(), skin))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (save)
|
if (save)
|
||||||
SkinRestorer.getSkinStorage().setSkin(profile.id(), value);
|
SkinRestorer.getSkinStorage().setSkin(profile.getId(), value);
|
||||||
|
|
||||||
var newProfile = PlayerUtils.applyRestoredSkin(profile, value.value());
|
if (PlayerUtils.areSkinPropertiesEquals(value.value(), PlayerUtils.getPlayerSkin(profile)))
|
||||||
((PlayerAccessor) player).setGameProfile(newProfile);
|
continue;
|
||||||
|
|
||||||
if (player.connection == null)
|
PlayerUtils.applyRestoredSkin(profile, value.value());
|
||||||
|
|
||||||
|
var player = server.getPlayerList().getPlayer(profile.getId());
|
||||||
|
if (player == 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<ServerPlayer> targets, SkinValue value) {
|
public static Collection<ServerPlayer> applySkin(MinecraftServer server, Iterable<GameProfile> 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<ServerPlayer> targets,
|
Collection<GameProfile> targets,
|
||||||
SkinProviderContext context,
|
SkinProviderContext context,
|
||||||
boolean save
|
boolean save
|
||||||
) {
|
) {
|
||||||
return CompletableFuture.supplyAsync(
|
return CompletableFuture.supplyAsync(
|
||||||
() -> SkinRestorer.getProvider(context.name()).map(provider -> provider.fetchSkin(context.argument(), context.variant()))
|
() -> SkinRestorer.getProvider(context.name()).map(provider -> provider.getSkin(context.argument(), context.variant()))
|
||||||
)
|
)
|
||||||
.thenApplyAsync(result -> {
|
.thenApplyAsync(result -> {
|
||||||
if (result.isEmpty())
|
if (result.isEmpty())
|
||||||
@@ -158,7 +124,7 @@ public final class SkinRestorer {
|
|||||||
|
|
||||||
var skinResult = result.get();
|
var skinResult = result.get();
|
||||||
if (skinResult.isError())
|
if (skinResult.isError())
|
||||||
throw new TransparentException(Throwables.getRootCause(skinResult.getErrorValue()));
|
return Result.<Collection<ServerPlayer>, String>error(skinResult.getErrorValue().getMessage());
|
||||||
|
|
||||||
var skinValue = SkinValue.fromProviderContextWithValue(context, skinResult.getSuccessValue().orElse(null));
|
var skinValue = SkinValue.fromProviderContextWithValue(context, skinResult.getSuccessValue().orElse(null));
|
||||||
|
|
||||||
@@ -167,37 +133,8 @@ 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("Failed to set skin '{}:{}'", context.name(), context.argument(), e);
|
SkinRestorer.LOGGER.error(e.toString());
|
||||||
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,5 +1,6 @@
|
|||||||
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;
|
||||||
@@ -17,12 +18,10 @@ 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;
|
||||||
@@ -35,7 +34,7 @@ public final class SkinCommand {
|
|||||||
private SkinCommand() {}
|
private SkinCommand() {}
|
||||||
|
|
||||||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
|
public static void register(CommandDispatcher<CommandSourceStack> dispatcher) {
|
||||||
var base =
|
LiteralArgumentBuilder<CommandSourceStack> base =
|
||||||
literal("skin")
|
literal("skin")
|
||||||
.then(buildSetSubcommand("clear", SkinValue.EMPTY::toProviderContext))
|
.then(buildSetSubcommand("clear", SkinValue.EMPTY::toProviderContext))
|
||||||
.then(literal("reset")
|
.then(literal("reset")
|
||||||
@@ -45,19 +44,13 @@ public final class SkinCommand {
|
|||||||
)))
|
)))
|
||||||
.then(literal("refresh").executes(context -> refreshSubcommand(context.getSource())));
|
.then(literal("refresh").executes(context -> refreshSubcommand(context.getSource())));
|
||||||
|
|
||||||
var set = literal("set");
|
LiteralArgumentBuilder<CommandSourceStack> 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(
|
base.then(set);
|
||||||
literal("config")
|
|
||||||
.requires(commandSourceStack -> commandSourceStack.hasPermission(4))
|
|
||||||
.then(literal("reload").executes(SkinCommand::configReloadSubcommand))
|
|
||||||
);
|
|
||||||
|
|
||||||
dispatcher.register(base);
|
dispatcher.register(base);
|
||||||
}
|
}
|
||||||
@@ -73,41 +66,37 @@ public final class SkinCommand {
|
|||||||
|
|
||||||
SkinProviderContext context = null;
|
SkinProviderContext context = null;
|
||||||
var save = true;
|
var save = true;
|
||||||
if (!SkinRestorer.getSkinStorage().hasSavedSkin(profile.id())) {
|
if (!SkinRestorer.getSkinStorage().hasSavedSkin(profile.getId())) {
|
||||||
if (profile.properties().containsKey(PlayerUtils.TEXTURES_KEY)) {
|
if (profile.getProperties().containsKey(PlayerUtils.TEXTURES_KEY)) {
|
||||||
save = false;
|
save = false;
|
||||||
context = MojangSkinProvider.skinProviderContextFromProfile(profile);
|
context = MojangSkinProvider.skinProviderContextFromProfile(profile);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
context = SkinRestorer.getSkinStorage().getSkin(profile.id()).toProviderContext();
|
context = SkinRestorer.getSkinStorage().getSkin(profile.getId()).toProviderContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (context == null)
|
if (context == null)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return SkinCommand.setSubcommand(src, Collections.singleton(new NameAndId(profile)), context, save, false);
|
return SkinCommand.setSubcommand(src, Collections.singleton(profile), context, save, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int resetSubcommand(
|
private static int resetSubcommand(
|
||||||
CommandSourceStack src,
|
CommandSourceStack src,
|
||||||
Collection<NameAndId> targets,
|
Collection<GameProfile> targets,
|
||||||
boolean setByOperator
|
boolean setByOperator
|
||||||
) {
|
) {
|
||||||
var updatedPlayers = new HashSet<ServerPlayer>();
|
Collection<ServerPlayer> updatedPlayers = new HashSet<>();
|
||||||
for (var nameAndId : targets) {
|
for (var profile : targets) {
|
||||||
SkinValue skin = null;
|
SkinValue skin = null;
|
||||||
if (SkinRestorer.getSkinStorage().hasSavedSkin(nameAndId.id()))
|
if (SkinRestorer.getSkinStorage().hasSavedSkin(profile.getId()))
|
||||||
skin = SkinRestorer.getSkinStorage().getSkin(nameAndId.id()).replaceValueWithOriginal();
|
skin = SkinRestorer.getSkinStorage().getSkin(profile.getId()).replaceValueWithOriginal();
|
||||||
|
|
||||||
if (skin == null)
|
if (skin == null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
var player = src.getServer().getPlayerList().getPlayer(nameAndId.id());
|
var updatedPlayer = SkinRestorer.applySkin(src.getServer(), Collections.singleton(profile), skin, false);
|
||||||
if (player == null)
|
SkinRestorer.getSkinStorage().deleteSkin(profile.getId());
|
||||||
continue;
|
|
||||||
|
|
||||||
var updatedPlayer = SkinRestorer.applySkin(src.getServer(), Collections.singleton(player), skin, false);
|
|
||||||
SkinRestorer.getSkinStorage().deleteSkin(nameAndId.id());
|
|
||||||
|
|
||||||
updatedPlayers.addAll(updatedPlayer);
|
updatedPlayers.addAll(updatedPlayer);
|
||||||
}
|
}
|
||||||
@@ -123,24 +112,19 @@ public final class SkinCommand {
|
|||||||
if (src.getPlayer() == null)
|
if (src.getPlayer() == null)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return resetSubcommand(src, Collections.singleton(src.getPlayer().nameAndId()), false);
|
return resetSubcommand(src, Collections.singleton(src.getPlayer().getGameProfile()), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int setSubcommand(
|
private static int setSubcommand(
|
||||||
CommandSourceStack src,
|
CommandSourceStack src,
|
||||||
Collection<NameAndId> targets,
|
Collection<GameProfile> 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));
|
||||||
|
|
||||||
var profileTargets = targets.stream()
|
SkinRestorer.setSkinAsync(src.getServer(), targets, context, save).thenAccept(result -> {
|
||||||
.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,
|
||||||
@@ -159,7 +143,7 @@ public final class SkinCommand {
|
|||||||
|
|
||||||
private static int setSubcommand(
|
private static int setSubcommand(
|
||||||
CommandSourceStack src,
|
CommandSourceStack src,
|
||||||
Collection<NameAndId> targets,
|
Collection<GameProfile> targets,
|
||||||
SkinProviderContext context,
|
SkinProviderContext context,
|
||||||
boolean setByOperator
|
boolean setByOperator
|
||||||
) {
|
) {
|
||||||
@@ -173,17 +157,7 @@ public final class SkinCommand {
|
|||||||
if (src.getPlayer() == null)
|
if (src.getPlayer() == null)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return setSubcommand(src, Collections.singleton(src.getPlayer().nameAndId()), context, false);
|
return setSubcommand(src, Collections.singleton(src.getPlayer().getGameProfile()), context, false);
|
||||||
}
|
|
||||||
|
|
||||||
private static int configReloadSubcommand(CommandContext<CommandSourceStack> context) {
|
|
||||||
SkinRestorer.reloadConfig();
|
|
||||||
|
|
||||||
context.getSource().sendSuccess(() -> Translation.translatableWithFallback(
|
|
||||||
Translation.COMMAND_SKIN_CONFIG_RELOADED_KEY
|
|
||||||
), true);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void sendResponse(CommandSourceStack src, Collection<ServerPlayer> updatedPlayers, boolean setByOperator) {
|
private static void sendResponse(CommandSourceStack src, Collection<ServerPlayer> updatedPlayers, boolean setByOperator) {
|
||||||
@@ -209,7 +183,7 @@ public final class SkinCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static LiteralArgumentBuilder<CommandSourceStack> buildSetSubcommand(String name, SkinProvider provider) {
|
private static LiteralArgumentBuilder<CommandSourceStack> buildSetSubcommand(String name, SkinProvider provider) {
|
||||||
var action = literal(name);
|
LiteralArgumentBuilder<CommandSourceStack> action = literal(name);
|
||||||
|
|
||||||
if (provider.hasVariantSupport()) {
|
if (provider.hasVariantSupport()) {
|
||||||
for (SkinVariant variant : SkinVariant.values()) {
|
for (SkinVariant variant : SkinVariant.values()) {
|
||||||
@@ -266,7 +240,7 @@ public final class SkinCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static RequiredArgumentBuilder<CommandSourceStack, GameProfileArgument.Result> makeTargetsArgument(
|
private static RequiredArgumentBuilder<CommandSourceStack, GameProfileArgument.Result> makeTargetsArgument(
|
||||||
BiFunction<CommandContext<CommandSourceStack>, Collection<NameAndId>, Integer> consumer
|
BiFunction<CommandContext<CommandSourceStack>, Collection<GameProfile>, Integer> consumer
|
||||||
) {
|
) {
|
||||||
return argument("targets", GameProfileArgument.gameProfile())
|
return argument("targets", GameProfileArgument.gameProfile())
|
||||||
.requires(source -> source.hasPermission(2))
|
.requires(source -> source.hasPermission(2))
|
||||||
|
|||||||
@@ -1,55 +0,0 @@
|
|||||||
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());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
package net.lionarius.skinrestorer.compat.skinshuffle;
|
|
||||||
|
|
||||||
import com.mojang.authlib.properties.Property;
|
|
||||||
|
|
||||||
public interface SkinShuffleSkinRefreshPayload {
|
|
||||||
Property textureProperty();
|
|
||||||
}
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
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,68 +1,46 @@
|
|||||||
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 implements GsonPostProcessable {
|
public final class Config {
|
||||||
|
|
||||||
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 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;
|
||||||
|
|
||||||
private ProvidersConfig providers = ProvidersConfig.DEFAULT;
|
public String getLanguage() {
|
||||||
|
|
||||||
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 firstJoinSkinProvider() {
|
public FirstJoinSkinProvider getFirstJoinSkinProvider() {
|
||||||
return this.firstJoinSkinProvider;
|
return this.firstJoinSkinProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Optional<Proxy> proxy() {
|
public String getProxy() {
|
||||||
return Optional.ofNullable(this.parsedProxy);
|
return this.proxy;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long requestTimeout() {
|
public long getRequestTimeout() {
|
||||||
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);
|
||||||
|
|
||||||
@@ -76,50 +54,24 @@ public final class Config implements GsonPostProcessable {
|
|||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private void verifyAndFix() {
|
||||||
public void gsonPostProcess() {
|
if (this.language == null || this.language.isEmpty())
|
||||||
if (this.language == null || this.language.isEmpty()) {
|
|
||||||
SkinRestorer.LOGGER.warn("Language config is null or empty, defaulting to 'en_us'");
|
|
||||||
this.language = "en_us";
|
this.language = "en_us";
|
||||||
}
|
|
||||||
|
|
||||||
if (this.skinApplyDelayOnJoin < 0) {
|
if (this.firstJoinSkinProvider == null)
|
||||||
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.proxy.isEmpty()) {
|
if (this.requestTimeout <= 0)
|
||||||
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,21 +0,0 @@
|
|||||||
package net.lionarius.skinrestorer.config;
|
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
public record Proxy(@NotNull String host, int port) {
|
|
||||||
|
|
||||||
public static Proxy parse(@NotNull String proxy) {
|
|
||||||
var colonIndex = proxy.lastIndexOf(':');
|
|
||||||
if (colonIndex == -1)
|
|
||||||
throw new IllegalArgumentException("no port in hostname");
|
|
||||||
|
|
||||||
var port = Integer.parseInt(proxy.substring(colonIndex + 1));
|
|
||||||
|
|
||||||
if (port < 0 || port > 0xFFFF)
|
|
||||||
throw new IllegalArgumentException("port out of range: " + port);
|
|
||||||
|
|
||||||
var host = proxy.substring(0, colonIndex);
|
|
||||||
|
|
||||||
return new Proxy(host, port);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
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.enabled = true;
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
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 = "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
package net.lionarius.skinrestorer.config.provider;
|
|
||||||
|
|
||||||
import net.lionarius.skinrestorer.SkinRestorer;
|
|
||||||
import net.lionarius.skinrestorer.util.gson.GsonPostProcessable;
|
|
||||||
|
|
||||||
public final class ProvidersConfig implements GsonPostProcessable {
|
|
||||||
public static final ProvidersConfig DEFAULT = new ProvidersConfig(
|
|
||||||
new MojangProviderConfig(),
|
|
||||||
new ElyByProviderConfig(),
|
|
||||||
new MineskinProviderConfig()
|
|
||||||
);
|
|
||||||
|
|
||||||
private MojangProviderConfig mojang;
|
|
||||||
private ElyByProviderConfig ely_by;
|
|
||||||
private MineskinProviderConfig mineskin;
|
|
||||||
|
|
||||||
public ProvidersConfig(MojangProviderConfig mojang, ElyByProviderConfig ely_by, MineskinProviderConfig mineskin) {
|
|
||||||
this.mojang = mojang;
|
|
||||||
this.ely_by = ely_by;
|
|
||||||
this.mineskin = mineskin;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MojangProviderConfig mojang() {
|
|
||||||
return this.mojang;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ElyByProviderConfig ely_by() {
|
|
||||||
return this.ely_by;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MineskinProviderConfig mineskin() {
|
|
||||||
return this.mineskin;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void gsonPostProcess() {
|
|
||||||
if (this.mojang == null) {
|
|
||||||
SkinRestorer.LOGGER.warn("Mojang provider config is null, using default");
|
|
||||||
this.mojang = ProvidersConfig.DEFAULT.mojang();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.ely_by == null) {
|
|
||||||
SkinRestorer.LOGGER.warn("Ely.By provider config is null, using default");
|
|
||||||
this.ely_by = ProvidersConfig.DEFAULT.ely_by();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.mineskin == null) {
|
|
||||||
SkinRestorer.LOGGER.warn("Mineskin provider config is null, using default");
|
|
||||||
this.mineskin = ProvidersConfig.DEFAULT.mineskin();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,190 +0,0 @@
|
|||||||
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<TrackedEntityAccessorInvoker> getEntityMap();
|
Int2ObjectMap<Object> getEntityMap();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +0,0 @@
|
|||||||
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,7 +9,6 @@ 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;
|
||||||
@@ -28,35 +27,19 @@ 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.Events.onPlayerDisconnect(player);
|
SkinRestorer.getSkinStorage().removeSkin(player.getUUID());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject(method = "removeAll", at = @At("HEAD"))
|
@Inject(method = "removeAll", at = @At("HEAD"))
|
||||||
private void removeAll(CallbackInfo ci) {
|
private void removeAll(CallbackInfo ci) {
|
||||||
for (var player : getPlayers()) {
|
for (ServerPlayer player : getPlayers()) {
|
||||||
SkinRestorer.Events.onPlayerDisconnect(player);
|
SkinRestorer.getSkinStorage().removeSkin(player.getUUID());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@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), SkinRestorer.getSkinStorage().getSkin(player.getUUID()));
|
SkinRestorer.applySkin(server, Collections.singleton(player.getGameProfile()), SkinRestorer.getSkinStorage().getSkin(player.getUUID()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,65 +24,51 @@ 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;Lnet/minecraft/server/players/NameAndId;)Lnet/minecraft/network/chat/Component;"),
|
target = "Lnet/minecraft/server/players/PlayerList;canPlayerLogin(Ljava/net/SocketAddress;Lcom/mojang/authlib/GameProfile;)Lnet/minecraft/network/chat/Component;"),
|
||||||
cancellable = true)
|
cancellable = true)
|
||||||
public void waitForSkin(CallbackInfo ci) {
|
public void waitForSkin(CallbackInfo ci) {
|
||||||
if (skinrestorer$pendingSkin == null) {
|
if (skinrestorer_pendingSkin == null) {
|
||||||
skinrestorer$pendingSkin = CompletableFuture.supplyAsync(() -> {
|
skinrestorer_pendingSkin = CompletableFuture.supplyAsync(() -> {
|
||||||
final var profile = authenticatedProfile;
|
assert authenticatedProfile != null;
|
||||||
|
var originalSkin = PlayerUtils.getPlayerSkin(authenticatedProfile);
|
||||||
|
|
||||||
assert profile != null;
|
if (SkinRestorer.getSkinStorage().hasSavedSkin(authenticatedProfile.getId())) {
|
||||||
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(profile.id());
|
var value = SkinRestorer.getSkinStorage().getSkin(authenticatedProfile.getId());
|
||||||
SkinRestorer.getSkinStorage().setSkin(profile.id(), value.setOriginalValue(originalSkin));
|
SkinRestorer.getSkinStorage().setSkin(authenticatedProfile.getId(), 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()) {
|
if (originalSkin == null && SkinRestorer.getConfig().fetchSkinOnFirstJoin()) {
|
||||||
|
SkinRestorer.LOGGER.debug("Fetching {}'s skin", authenticatedProfile.getName());
|
||||||
|
|
||||||
var context = new SkinProviderContext(
|
var context = new SkinProviderContext(
|
||||||
SkinRestorer.getConfig().firstJoinSkinProvider().getName(),
|
SkinRestorer.getConfig().getFirstJoinSkinProvider().getName(),
|
||||||
profile.name(),
|
authenticatedProfile.getName(),
|
||||||
null
|
null
|
||||||
);
|
);
|
||||||
skinrestorer$fetchSkin(profile, context);
|
var result = SkinRestorer.getProvider(context.name()).map(
|
||||||
|
provider -> provider.getSkin(context.argument(), context.variant())
|
||||||
|
).orElse(Result.ofNullable(null));
|
||||||
|
|
||||||
|
if (!result.isError()) {
|
||||||
|
var value = SkinValue.fromProviderContextWithValue(context, result.getSuccessValue().orElse(null));
|
||||||
|
SkinRestorer.getSkinStorage().setSkin(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 TrackedEntityAccessorInvoker {
|
public interface TrackedEntityMixin {
|
||||||
|
|
||||||
@Accessor
|
@Accessor
|
||||||
Set<ServerPlayerConnection> getSeenBy();
|
Set<ServerPlayerConnection> getSeenBy();
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
package net.lionarius.skinrestorer.platform.services;
|
|
||||||
|
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
|
||||||
|
|
||||||
public interface CompatibilityHelper {
|
|
||||||
|
|
||||||
void skinShuffle_sendHandshake(ServerPlayer player);
|
|
||||||
}
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
package net.lionarius.skinrestorer.platform.services;
|
|
||||||
|
|
||||||
import java.nio.file.Path;
|
|
||||||
|
|
||||||
public interface PlatformHelper {
|
|
||||||
|
|
||||||
String getPlatformName();
|
|
||||||
|
|
||||||
boolean isModLoaded(String modId);
|
|
||||||
|
|
||||||
Path getConfigDirectory();
|
|
||||||
}
|
|
||||||
@@ -27,7 +27,9 @@ public class SkinIO {
|
|||||||
|
|
||||||
public SkinValue loadSkin(UUID uuid) {
|
public SkinValue loadSkin(UUID uuid) {
|
||||||
try {
|
try {
|
||||||
return SkinIO.loadSkin(savePath.resolve(SkinIO.uuidToFilename(uuid)));
|
var value = 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,22 +17,15 @@ 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, boolean cache) {
|
public SkinValue getSkin(UUID uuid) {
|
||||||
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,14 +3,11 @@ 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) implements GsonPostProcessable {
|
@Nullable Property value, @Nullable Property originalValue) {
|
||||||
|
|
||||||
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);
|
||||||
|
|
||||||
@@ -33,9 +30,4 @@ 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,63 +1,32 @@
|
|||||||
package net.lionarius.skinrestorer.skin.provider;
|
package net.lionarius.skinrestorer.skin.provider;
|
||||||
|
|
||||||
import com.google.common.cache.CacheBuilder;
|
import com.google.gson.JsonObject;
|
||||||
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";
|
||||||
@@ -69,32 +38,23 @@ public final class ElyBySkinProvider implements SkinProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Result<Optional<Property>, Exception> fetchSkin(String username, SkinVariant variant) {
|
public Result<Optional<Property>, Exception> getSkin(String username, SkinVariant variant) {
|
||||||
try {
|
try {
|
||||||
if (!StringUtil.isValidPlayerName(username))
|
var profile = ElyBySkinProvider.getElyByProfile(username);
|
||||||
throw new IllegalArgumentException("invalid username");
|
|
||||||
|
|
||||||
var usernameLowerCase = username.toLowerCase(Locale.ROOT);
|
var properties = profile.getAsJsonArray("properties");
|
||||||
|
var textures = PlayerUtils.findTexturesProperty(properties);
|
||||||
|
|
||||||
return Result.success(SKIN_CACHE.get(usernameLowerCase));
|
return Result.ofNullable(textures);
|
||||||
} 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 Optional<Property> loadSkin(String username) throws Exception {
|
private static JsonObject getElyByProfile(String username) throws IOException {
|
||||||
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()
|
||||||
@@ -106,6 +66,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.fromJson(response.body(), MinecraftProfilePropertiesResponse.class).profile();
|
return JsonUtils.parseJson(response.body());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,11 +21,11 @@ public final class EmptySkinProvider implements SkinProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Result<Optional<Property>, Exception> fetchSkin(String argument, SkinVariant variant) {
|
public Result<Optional<Property>, Exception> getSkin(String argument, SkinVariant variant) {
|
||||||
return this.fetchSkin();
|
return this.getSkin();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Result<Optional<Property>, Exception> fetchSkin() {
|
public Result<Optional<Property>, Exception> getSkin() {
|
||||||
return Result.ofNullable(null);
|
return Result.ofNullable(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,74 +1,31 @@
|
|||||||
package net.lionarius.skinrestorer.skin.provider;
|
package net.lionarius.skinrestorer.skin.provider;
|
||||||
|
|
||||||
import com.google.common.cache.CacheBuilder;
|
import com.google.gson.JsonObject;
|
||||||
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.net.InetSocketAddress;
|
import java.io.IOException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.time.Duration;
|
import java.net.URISyntaxException;
|
||||||
|
import java.net.http.HttpRequest;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
public final class MineskinSkinProvider implements SkinProvider {
|
public final class MineskinSkinProvider implements SkinProvider {
|
||||||
|
|
||||||
public static final String PROVIDER_NAME = "web";
|
public static final String PROVIDER_NAME = "web";
|
||||||
|
|
||||||
private static MineSkinClient MINESKIN_CLIENT;
|
private static final URI API_URI;
|
||||||
|
|
||||||
private static LoadingCache<Pair<URI, SkinVariant>, Optional<Property>> SKIN_CACHE;
|
static {
|
||||||
|
try {
|
||||||
public static void reload() {
|
API_URI = new URI("https://api.mineskin.org/");
|
||||||
var config = SkinRestorer.getConfig();
|
} catch (URISyntaxException e) {
|
||||||
var configApiKey = config.providersConfig().mineskin().apiKey();
|
throw new IllegalArgumentException(e);
|
||||||
|
}
|
||||||
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
|
||||||
@@ -82,39 +39,33 @@ public final class MineskinSkinProvider implements SkinProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Result<Optional<Property>, Exception> fetchSkin(String url, SkinVariant variant) {
|
public Result<Optional<Property>, Exception> getSkin(String url, SkinVariant variant) {
|
||||||
try {
|
try {
|
||||||
var uri = new URI(url);
|
var result = MineskinSkinProvider.uploadToMineskin(url, variant);
|
||||||
|
var texture = result.getAsJsonObject("data").getAsJsonObject("texture");
|
||||||
|
|
||||||
return Result.success(SKIN_CACHE.get(Pair.of(uri, variant)));
|
return Result.ofNullable(new Property(PlayerUtils.TEXTURES_KEY, texture.get("value").getAsString(), texture.get("signature").getAsString()));
|
||||||
} 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 Optional<Property> loadSkin(URI uri, SkinVariant variant) throws Exception {
|
private static JsonObject uploadToMineskin(String url, SkinVariant variant) throws IOException {
|
||||||
var mineskinVariant = switch (variant) {
|
var body = ("{\"variant\":\"%s\",\"name\":\"%s\",\"visibility\":%d,\"url\":\"%s\"}")
|
||||||
case CLASSIC -> Variant.CLASSIC;
|
.formatted(variant.toString(), "none", 0, url);
|
||||||
case SLIM -> Variant.SLIM;
|
|
||||||
};
|
|
||||||
|
|
||||||
var request = GenerateRequest.url(uri)
|
var request = HttpRequest.newBuilder()
|
||||||
.variant(mineskinVariant)
|
.uri(MineskinSkinProvider.API_URI.resolve("generate/url"))
|
||||||
.name("skinrestorer-skin")
|
.POST(HttpRequest.BodyPublishers.ofString(body))
|
||||||
.visibility(Visibility.UNLISTED);
|
.header("Content-Type", "application/json")
|
||||||
|
.build();
|
||||||
|
|
||||||
var skin = MINESKIN_CLIENT.queue().submit(request)
|
var response = WebUtils.executeRequest(request);
|
||||||
.thenApply(QueueResponse::getJob)
|
WebUtils.throwOnClientErrors(response);
|
||||||
.thenCompose(jobInfo -> jobInfo.waitForCompletion(MINESKIN_CLIENT))
|
|
||||||
.thenCompose(jobReference -> jobReference.getOrLoadSkin(MINESKIN_CLIENT))
|
|
||||||
.join();
|
|
||||||
|
|
||||||
return Optional.of(new Property(
|
if (response.statusCode() != 200)
|
||||||
PlayerUtils.TEXTURES_KEY,
|
throw new IllegalArgumentException("could not get mineskin skin");
|
||||||
skin.texture().data().value(),
|
|
||||||
skin.texture().data().signature()
|
return JsonUtils.parseJson(response.body());
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,100 +1,38 @@
|
|||||||
package net.lionarius.skinrestorer.skin.provider;
|
package net.lionarius.skinrestorer.skin.provider;
|
||||||
|
|
||||||
import com.google.common.cache.CacheBuilder;
|
import com.google.gson.JsonObject;
|
||||||
import com.google.common.cache.CacheLoader;
|
import com.mojang.authlib.GameProfile;
|
||||||
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 Environment ENVIRONMENT;
|
|
||||||
private static final URI SERVICES_SERVER_URI;
|
|
||||||
private static final URI SESSION_SERVER_URI;
|
|
||||||
private static final CachedUserNameToIdResolver PROFILE_CACHE;
|
|
||||||
|
|
||||||
private static LoadingCache<UUID, Optional<Property>> SKIN_CACHE;
|
private static final URI API_URI;
|
||||||
|
private static final URI SESSION_SERVER_URI;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
try {
|
try {
|
||||||
ENVIRONMENT = EnvironmentParser.getEnvironmentFromProperties().orElse(YggdrasilEnvironment.PROD.getEnvironment());
|
API_URI = new URI("https://api.mojang.com/");
|
||||||
|
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.name(), null);
|
return new SkinProviderContext(MojangSkinProvider.PROVIDER_NAME, gameProfile.getName(), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -108,34 +46,24 @@ public final class MojangSkinProvider implements SkinProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Result<Optional<Property>, Exception> fetchSkin(String username, SkinVariant variant) {
|
public Result<Optional<Property>, Exception> getSkin(String username, SkinVariant variant) {
|
||||||
try {
|
try {
|
||||||
if (!StringUtil.isValidPlayerName(username))
|
var uuid = MojangSkinProvider.getUuid(username);
|
||||||
throw new IllegalArgumentException("invalid username");
|
var profile = MojangSkinProvider.getMojangProfile(uuid);
|
||||||
|
|
||||||
var cachedProfile = MojangSkinProvider.PROFILE_CACHE.get(username);
|
var properties = profile.getAsJsonArray("properties");
|
||||||
if (cachedProfile.isEmpty())
|
var textures = PlayerUtils.findTexturesProperty(properties);
|
||||||
throw new IllegalArgumentException("no profile found for " + username);
|
|
||||||
|
|
||||||
return Result.success(SKIN_CACHE.get(cachedProfile.get().id()));
|
return Result.ofNullable(textures);
|
||||||
} 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 Optional<Property> loadSkin(UUID uuid) throws Exception {
|
private static String getUuid(final String name) throws IOException {
|
||||||
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.SERVICES_SERVER_URI
|
.uri(MojangSkinProvider.API_URI
|
||||||
.resolve("/minecraft/profile/lookup/name/")
|
.resolve("users/profiles/minecraft/")
|
||||||
.resolve(name)
|
.resolve(name)
|
||||||
)
|
)
|
||||||
.GET()
|
.GET()
|
||||||
@@ -147,14 +75,18 @@ 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);
|
||||||
|
|
||||||
return JsonUtils.fromJson(response.body(), NameAndId.class);
|
var profile = JsonUtils.parseJson(response.body());
|
||||||
|
if (profile == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return profile.get("id").getAsString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static GameProfile getProfileWithProperties(UUID uuid) throws IOException {
|
private static JsonObject getMojangProfile(String uuid) throws IOException {
|
||||||
var request = HttpRequest.newBuilder()
|
var request = HttpRequest.newBuilder()
|
||||||
.uri(MojangSkinProvider.SESSION_SERVER_URI
|
.uri(MojangSkinProvider.SESSION_SERVER_URI
|
||||||
.resolve("/session/minecraft/profile/")
|
.resolve("session/minecraft/profile/")
|
||||||
.resolve(UndashedUuid.toString(uuid) + "?unsigned=false")
|
.resolve(uuid + "?unsigned=false")
|
||||||
)
|
)
|
||||||
.GET()
|
.GET()
|
||||||
.build();
|
.build();
|
||||||
@@ -165,6 +97,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.fromJson(response.body(), MinecraftProfilePropertiesResponse.class).profile();
|
return JsonUtils.parseJson(response.body());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,31 +1,20 @@
|
|||||||
package net.lionarius.skinrestorer.skin.provider;
|
package net.lionarius.skinrestorer.skin.provider;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableSet;
|
|
||||||
import com.mojang.authlib.properties.Property;
|
import com.mojang.authlib.properties.Property;
|
||||||
import net.lionarius.skinrestorer.skin.SkinVariant;
|
import net.lionarius.skinrestorer.skin.SkinVariant;
|
||||||
import net.lionarius.skinrestorer.util.Result;
|
import net.lionarius.skinrestorer.util.Result;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public interface SkinProvider {
|
public interface SkinProvider {
|
||||||
EmptySkinProvider EMPTY = new EmptySkinProvider();
|
EmptySkinProvider EMPTY = new EmptySkinProvider();
|
||||||
MojangSkinProvider MOJANG = new MojangSkinProvider();
|
MojangSkinProvider MOJANG = new MojangSkinProvider();
|
||||||
ElyBySkinProvider ELY_BY = new ElyBySkinProvider();
|
ElyBySkinProvider ELY_BY = new ElyBySkinProvider();
|
||||||
MineskinSkinProvider MINESKIN = new MineskinSkinProvider();
|
MineskinSkinProvider MINESKIN = new MineskinSkinProvider();
|
||||||
SkinShuffleSkinProvider SKIN_SHUFFLE = new SkinShuffleSkinProvider();
|
|
||||||
|
|
||||||
Set<String> BUILTIN_PROVIDER_NAMES = ImmutableSet.of(
|
|
||||||
EmptySkinProvider.PROVIDER_NAME,
|
|
||||||
MojangSkinProvider.PROVIDER_NAME,
|
|
||||||
ElyBySkinProvider.PROVIDER_NAME,
|
|
||||||
MineskinSkinProvider.PROVIDER_NAME,
|
|
||||||
SkinShuffleSkinProvider.PROVIDER_NAME
|
|
||||||
);
|
|
||||||
|
|
||||||
String getArgumentName();
|
String getArgumentName();
|
||||||
|
|
||||||
boolean hasVariantSupport();
|
boolean hasVariantSupport();
|
||||||
|
|
||||||
Result<Optional<Property>, Exception> fetchSkin(String argument, SkinVariant variant);
|
Result<Optional<Property>, Exception> getSkin(String argument, SkinVariant variant);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ public final class SkinProviderRegistry {
|
|||||||
|
|
||||||
public void register(@NotNull String name, @NotNull SkinProvider provider, boolean isPublic) {
|
public void register(@NotNull String name, @NotNull SkinProvider provider, boolean isPublic) {
|
||||||
if (this.registry.containsKey(name))
|
if (this.registry.containsKey(name))
|
||||||
return;
|
throw new IllegalArgumentException("Skin provider with name " + name + " is already registered");
|
||||||
|
|
||||||
this.registry.put(name, new Entry(provider, isPublic));
|
this.registry.put(name, new Entry(provider, isPublic));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,27 +0,0 @@
|
|||||||
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,7 +19,6 @@ public final class Translation {
|
|||||||
public static final String COMMAND_SKIN_FAILED_KEY = "skinrestorer.command.skin.failed";
|
public static final String COMMAND_SKIN_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;
|
||||||
@@ -47,11 +46,11 @@ public final class Translation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void reloadTranslations() {
|
public static void reloadTranslations() {
|
||||||
translations = Translation.loadTranslationMap(SkinRestorer.getConfig().language());
|
translations = Translation.loadTranslationMap(SkinRestorer.getConfig().getLanguage());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ImmutableMap<String, String> loadTranslationMap(String lang) {
|
private static ImmutableMap<String, String> loadTranslationMap(String lang) {
|
||||||
var json = FileUtils.readResource(SkinRestorer.assetPath(String.format("lang/%s.json", lang)));
|
var json = FileUtils.readResource(SkinRestorer.resource(String.format("lang/%s.json", lang)));
|
||||||
|
|
||||||
var type = new TypeToken<Map<String, String>>() {}.getType();
|
var type = new TypeToken<Map<String, String>>() {}.getType();
|
||||||
Map<String, String> map = null;
|
Map<String, String> map = null;
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ 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;
|
||||||
@@ -18,31 +17,27 @@ public final class FileUtils {
|
|||||||
|
|
||||||
private FileUtils() {}
|
private FileUtils() {}
|
||||||
|
|
||||||
public static void tryMigrateOldSkinDirectory(Path oldDirectory, Path newDirectory) {
|
public static void tryMigrateOldSkinDirectory(Path newDirectory) {
|
||||||
try {
|
try {
|
||||||
try (var stream = Files.list(oldDirectory)) {
|
var configDirectory = SkinRestorer.getConfigDir();
|
||||||
|
try (var stream = Files.list(configDirectory)) {
|
||||||
var files = stream.filter(file -> {
|
var files = stream.filter(file -> {
|
||||||
var name = file.getFileName().toString();
|
var name = file.getFileName();
|
||||||
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) {
|
|
||||||
var newFile = newDirectory.resolve(file.getFileName());
|
for (var file : files)
|
||||||
if (!Files.exists(newFile))
|
Files.move(file, newDirectory.resolve(file.getFileName()), StandardCopyOption.REPLACE_EXISTING);
|
||||||
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,7 +50,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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -67,7 +62,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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -83,7 +78,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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,7 +87,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,28 +1,16 @@
|
|||||||
package net.lionarius.skinrestorer.util;
|
package net.lionarius.skinrestorer.util;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.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 {
|
||||||
|
|
||||||
public static final Gson GSON = new GsonBuilder()
|
private static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
|
||||||
.registerTypeAdapterFactory(new PostProcessingEnabler())
|
|
||||||
.registerTypeAdapter(UUID.class, new UUIDTypeAdapter())
|
|
||||||
.registerTypeAdapter(PropertyMap.class, new PropertyMap.Serializer())
|
|
||||||
.setPrettyPrinting()
|
|
||||||
.create();
|
|
||||||
|
|
||||||
private JsonUtils() {}
|
private JsonUtils() {}
|
||||||
|
|
||||||
@@ -43,7 +31,7 @@ public final class JsonUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static JsonObject parseJson(String json) {
|
public static JsonObject parseJson(String json) {
|
||||||
return GSON.fromJson(json, JsonObject.class);
|
return JsonParser.parseString(json).getAsJsonObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static JsonObject skinPropertyToJson(Property property) {
|
public static JsonObject skinPropertyToJson(Property property) {
|
||||||
@@ -54,7 +42,7 @@ public final class JsonUtils {
|
|||||||
|
|
||||||
return json;
|
return json;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
SkinRestorer.LOGGER.error("Could not parse skin property", e);
|
SkinRestorer.LOGGER.error(e.toString());
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,11 @@
|
|||||||
package net.lionarius.skinrestorer.util;
|
package net.lionarius.skinrestorer.util;
|
||||||
|
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.gson.JsonArray;
|
||||||
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;
|
||||||
@@ -40,7 +38,7 @@ public final class PlayerUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void refreshPlayer(ServerPlayer player) {
|
public static void refreshPlayer(ServerPlayer player) {
|
||||||
ServerLevel serverLevel = player.level();
|
ServerLevel serverLevel = player.serverLevel();
|
||||||
PlayerList playerList = serverLevel.getServer().getPlayerList();
|
PlayerList playerList = serverLevel.getServer().getPlayerList();
|
||||||
ChunkMap chunkMap = serverLevel.getChunkSource().chunkMap;
|
ChunkMap chunkMap = serverLevel.getChunkSource().chunkMap;
|
||||||
|
|
||||||
@@ -51,14 +49,14 @@ public final class PlayerUtils {
|
|||||||
)
|
)
|
||||||
));
|
));
|
||||||
|
|
||||||
var trackedEntity = ((ChunkMapAccessor) chunkMap).getEntityMap().get(player.getId());
|
var trackedEntity = (TrackedEntityMixin) ((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 = ((ChunkMapAccessor) chunkMap).getEntityMap().get(observer.getId());
|
var trackedObserverEntity = (TrackedEntityMixin) ((ChunkMapAccessor) chunkMap).getEntityMap().get(observer.getId());
|
||||||
if (trackedObserverEntity != null) {
|
if (trackedObserverEntity != null) {
|
||||||
trackedObserverEntity.invokeRemovePlayer(player);
|
trackedObserverEntity.invokeRemovePlayer(player);
|
||||||
trackedObserverEntity.invokeUpdatePlayer(player);
|
trackedObserverEntity.invokeUpdatePlayer(player);
|
||||||
@@ -87,39 +85,28 @@ public final class PlayerUtils {
|
|||||||
playerList.sendPlayerPermissionLevel(player);
|
playerList.sendPlayerPermissionLevel(player);
|
||||||
playerList.sendLevelInfo(player, serverLevel);
|
playerList.sendLevelInfo(player, serverLevel);
|
||||||
playerList.sendAllPlayerInfo(player);
|
playerList.sendAllPlayerInfo(player);
|
||||||
playerList.sendActivePlayerEffects(player);
|
PlayerUtils.sendActivePlayerEffects(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void sendActivePlayerEffects(ServerPlayer player) {
|
public 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 GameProfile cloneGameProfile(GameProfile profile) {
|
|
||||||
var newProfile = new GameProfile(profile.id(), profile.name());
|
|
||||||
newProfile.properties().putAll(profile.properties());
|
|
||||||
|
|
||||||
return newProfile;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Property getPlayerSkin(GameProfile profile) {
|
public static Property getPlayerSkin(GameProfile profile) {
|
||||||
return Iterables.getFirst(profile.properties().get(TEXTURES_KEY), null);
|
return profile.getProperties().get(TEXTURES_KEY).stream().findFirst().orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static GameProfile applyRestoredSkin(GameProfile profile, Property skin) {
|
public static void applyRestoredSkin(GameProfile profile, Property skin) {
|
||||||
var propertiesMap = profile.properties();
|
profile.getProperties().removeAll(TEXTURES_KEY);
|
||||||
|
|
||||||
var newProperties = LinkedHashMultimap.create(propertiesMap);
|
if (skin != null)
|
||||||
newProperties.removeAll(TEXTURES_KEY);
|
profile.getProperties().put(TEXTURES_KEY, skin);
|
||||||
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)
|
||||||
return true;
|
return true;
|
||||||
@@ -139,9 +126,24 @@ public final class PlayerUtils {
|
|||||||
return xJson.equals(yJson);
|
return xJson.equals(yJson);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static GameProfile toProfile(MinecraftProfilePropertiesResponse response) {
|
public static Property findTexturesProperty(JsonArray properties) {
|
||||||
final GameProfile profile = new GameProfile(response.id(), response.name());
|
Property textures = null;
|
||||||
profile.properties().putAll(response.properties());
|
for (var property : properties) {
|
||||||
return profile;
|
var propertyObject = property.getAsJsonObject();
|
||||||
|
if (propertyObject == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
try {
|
||||||
|
textures = JsonUtils.fromJson(propertyObject, Property.class);
|
||||||
|
break;
|
||||||
|
} catch (Exception e) {
|
||||||
|
// ignored
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (textures == null)
|
||||||
|
throw new IllegalStateException("no textures in profile");
|
||||||
|
|
||||||
|
return textures;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,18 +19,6 @@ 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;
|
||||||
}
|
}
|
||||||
@@ -81,4 +69,16 @@ 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,8 +17,4 @@ 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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,60 +0,0 @@
|
|||||||
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,39 +10,44 @@ 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 {
|
||||||
|
|
||||||
public static final String USER_AGENT;
|
private WebUtils() {}
|
||||||
|
|
||||||
private static HttpClient HTTP_CLIENT = null;
|
public static final String USER_AGENT;
|
||||||
|
|
||||||
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 {
|
||||||
builder.connectTimeout(Duration.of(SkinRestorer.getConfig().requestTimeout(), ChronoUnit.SECONDS));
|
if (proxy != null) {
|
||||||
|
var colonIndex = proxy.lastIndexOf(':');
|
||||||
|
if (colonIndex != -1) {
|
||||||
|
var host = proxy.substring(0, colonIndex);
|
||||||
|
var port = Integer.parseInt(proxy.substring(colonIndex + 1));
|
||||||
|
|
||||||
|
builder.proxy(ProxySelector.of(InetSocketAddress.createUnresolved(host, port)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
SkinRestorer.LOGGER.error("failed to parse proxy", e);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
builder.connectTimeout(Duration.of(SkinRestorer.getConfig().getRequestTimeout(), ChronoUnit.SECONDS));
|
||||||
} catch (IllegalArgumentException e) {
|
} 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));
|
||||||
}
|
}
|
||||||
|
|
||||||
return builder.build();
|
HTTP_CLIENT = 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)
|
||||||
@@ -62,16 +67,30 @@ public final class WebUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void throwOnClientErrors(HttpResponse<?> response) {
|
public static void throwOnClientErrors(HttpResponse<?> response) {
|
||||||
String message = switch (response.statusCode()) {
|
String message = null;
|
||||||
case 400 -> "bad request";
|
switch (response.statusCode()) {
|
||||||
case 401 -> "unauthorized";
|
case 400:
|
||||||
case 403 -> "forbidden";
|
message = "bad request";
|
||||||
case 404 -> "not found";
|
break;
|
||||||
case 405 -> "method not allowed";
|
case 401:
|
||||||
case 408 -> "request timeout";
|
message = "unauthorized";
|
||||||
case 429 -> "too many requests";
|
break;
|
||||||
default -> null;
|
case 403:
|
||||||
};
|
message = "forbidden";
|
||||||
|
break;
|
||||||
|
case 404:
|
||||||
|
message = "not found";
|
||||||
|
break;
|
||||||
|
case 405:
|
||||||
|
message = "method not allowed";
|
||||||
|
break;
|
||||||
|
case 408:
|
||||||
|
message = "request timeout";
|
||||||
|
break;
|
||||||
|
case 429:
|
||||||
|
message = "too many requests";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (message != null)
|
if (message != null)
|
||||||
throw new IllegalStateException(message);
|
throw new IllegalStateException(message);
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
package net.lionarius.skinrestorer.util.gson;
|
|
||||||
|
|
||||||
public interface GsonPostProcessable {
|
|
||||||
void gsonPostProcess();
|
|
||||||
}
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
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,6 +3,5 @@
|
|||||||
"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,6 +3,5 @@
|
|||||||
"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,6 +3,5 @@
|
|||||||
"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,6 +3,5 @@
|
|||||||
"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,6 +3,5 @@
|
|||||||
"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,6 +3,5 @@
|
|||||||
"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,6 +3,5 @@
|
|||||||
"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,6 +3,5 @@
|
|||||||
"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,6 +3,5 @@
|
|||||||
"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,6 +3,5 @@
|
|||||||
"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,6 +3,5 @@
|
|||||||
"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,6 +3,5 @@
|
|||||||
"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,6 +3,5 @@
|
|||||||
"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,6 +3,5 @@
|
|||||||
"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,6 +3,5 @@
|
|||||||
"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,6 +3,5 @@
|
|||||||
"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,6 +3,5 @@
|
|||||||
"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,6 +3,5 @@
|
|||||||
"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,6 +3,5 @@
|
|||||||
"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,6 +3,5 @@
|
|||||||
"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,6 +3,5 @@
|
|||||||
"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,6 +3,5 @@
|
|||||||
"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 +0,0 @@
|
|||||||
accessWidener v2 named
|
|
||||||
@@ -2,15 +2,13 @@
|
|||||||
"required": true,
|
"required": true,
|
||||||
"minVersion": "0.8",
|
"minVersion": "0.8",
|
||||||
"package": "net.lionarius.skinrestorer.mixin",
|
"package": "net.lionarius.skinrestorer.mixin",
|
||||||
"compatibilityLevel": "JAVA_17",
|
"compatibilityLevel": "JAVA_8",
|
||||||
"priority": 1100,
|
|
||||||
"refmap": "${mod_id}.refmap.json",
|
"refmap": "${mod_id}.refmap.json",
|
||||||
"mixins": [
|
"mixins": [
|
||||||
"ChunkMapAccessor",
|
|
||||||
"PlayerListMixin",
|
"PlayerListMixin",
|
||||||
"ServerLoginPacketListenerImplMixin",
|
"ServerLoginPacketListenerImplMixin",
|
||||||
"TrackedEntityAccessorInvoker",
|
"ChunkMapAccessor",
|
||||||
"PlayerAccessor"
|
"TrackedEntityMixin"
|
||||||
],
|
],
|
||||||
"injectors": {
|
"injectors": {
|
||||||
"defaultRequire": 1
|
"defaultRequire": 1
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
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 {
|
||||||
@@ -13,10 +12,6 @@ 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 {
|
||||||
@@ -24,11 +19,11 @@ loom {
|
|||||||
if (aw.exists()) {
|
if (aw.exists()) {
|
||||||
accessWidenerPath.set(aw)
|
accessWidenerPath.set(aw)
|
||||||
}
|
}
|
||||||
|
|
||||||
mixin {
|
mixin {
|
||||||
defaultRefmapName.set("${mod_id}.refmap.json")
|
defaultRefmapName.set("${mod_id}.refmap.json")
|
||||||
}
|
}
|
||||||
|
|
||||||
runs {
|
runs {
|
||||||
client {
|
client {
|
||||||
client()
|
client()
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
# 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,19 +1,12 @@
|
|||||||
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();
|
SkinRestorer.onInitialize(FabricLoader.getInstance().getConfigDir());
|
||||||
|
|
||||||
if (SkinShuffleCompatibility.shouldApply())
|
|
||||||
net.lionarius.skinrestorer.fabric.compat.skinshuffle.SkinShuffleCompatibility.initialize();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,37 +0,0 @@
|
|||||||
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.SkinRestorer;
|
import net.lionarius.skinrestorer.command.SkinCommand;
|
||||||
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) {
|
||||||
SkinRestorer.Events.onCommandRegister(dispatcher);
|
SkinCommand.register(dispatcher);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,12 +13,6 @@ public abstract class MinecraftServerMixin {
|
|||||||
@Inject(method = "runServer",
|
@Inject(method = "runServer",
|
||||||
at = @At(value = "INVOKE", target = "Lnet/minecraft/Util;getNanos()J", ordinal = 0))
|
at = @At(value = "INVOKE", target = "Lnet/minecraft/Util;getNanos()J", ordinal = 0))
|
||||||
private void onServerStarted(CallbackInfo ci) {
|
private void onServerStarted(CallbackInfo ci) {
|
||||||
SkinRestorer.Events.onServerStarted((MinecraftServer) (Object) this);
|
SkinRestorer.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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +0,0 @@
|
|||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
package net.lionarius.skinrestorer.fabric.platform;
|
|
||||||
|
|
||||||
import net.fabricmc.loader.api.FabricLoader;
|
|
||||||
import net.lionarius.skinrestorer.platform.services.PlatformHelper;
|
|
||||||
|
|
||||||
import java.nio.file.Path;
|
|
||||||
|
|
||||||
public final class FabricPlatformHelper implements PlatformHelper {
|
|
||||||
@Override
|
|
||||||
public String getPlatformName() {
|
|
||||||
return "fabric";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isModLoaded(String modId) {
|
|
||||||
return FabricLoader.getInstance().isModLoaded(modId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Path getConfigDirectory() {
|
|
||||||
return FabricLoader.getInstance().getConfigDir();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
net.lionarius.skinrestorer.fabric.platform.FabricCompatibilityHelper
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
net.lionarius.skinrestorer.fabric.platform.FabricPlatformHelper
|
|
||||||
@@ -24,13 +24,9 @@
|
|||||||
"${mod_id}.mixins.json",
|
"${mod_id}.mixins.json",
|
||||||
"${mod_id}.fabric.mixins.json"
|
"${mod_id}.fabric.mixins.json"
|
||||||
],
|
],
|
||||||
"accessWidener": "${mod_id}.accesswidener",
|
|
||||||
"depends": {
|
"depends": {
|
||||||
"fabricloader": ">=${fabric_loader_version}",
|
"fabricloader": ">=${fabric_loader_version}",
|
||||||
"minecraft": ">=${minecraft_version}",
|
"minecraft": ">=${minecraft_version}",
|
||||||
"java": ">=${java_version}"
|
"java": ">=${java_version}"
|
||||||
},
|
|
||||||
"suggests": {
|
|
||||||
"fabric-api": "*"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
"required": true,
|
"required": true,
|
||||||
"minVersion": "0.8",
|
"minVersion": "0.8",
|
||||||
"package": "net.lionarius.skinrestorer.fabric.mixin",
|
"package": "net.lionarius.skinrestorer.fabric.mixin",
|
||||||
"compatibilityLevel": "JAVA_17",
|
"compatibilityLevel": "JAVA_8",
|
||||||
"refmap": "${mod_id}.refmap.json",
|
"refmap": "${mod_id}.refmap.json",
|
||||||
"mixins": [
|
"mixins": [
|
||||||
"CommandsMixin",
|
"CommandsMixin",
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ plugins {
|
|||||||
id 'multiloader-loader'
|
id 'multiloader-loader'
|
||||||
id 'idea'
|
id 'idea'
|
||||||
id 'eclipse'
|
id 'eclipse'
|
||||||
|
|
||||||
id 'net.minecraftforge.gradle'
|
id 'net.minecraftforge.gradle'
|
||||||
id 'org.parchmentmc.librarian.forgegradle'
|
id 'org.parchmentmc.librarian.forgegradle'
|
||||||
id 'org.spongepowered.mixin'
|
id 'org.spongepowered.mixin'
|
||||||
@@ -15,16 +15,8 @@ mixin {
|
|||||||
config "${mod_id}.mixins.json"
|
config "${mod_id}.mixins.json"
|
||||||
}
|
}
|
||||||
|
|
||||||
jarJar.enable()
|
|
||||||
|
|
||||||
tasks.named('jarJar') {
|
|
||||||
archiveClassifier = ''
|
|
||||||
}
|
|
||||||
|
|
||||||
jar.finalizedBy('jarJar')
|
|
||||||
|
|
||||||
minecraft {
|
minecraft {
|
||||||
mappings channel: 'parchment', version: "${parchment_minecraft}-${parchment_version}-${minecraft_version}"
|
mappings channel: 'parchment', version: "${parchment_version}-${parchment_minecraft}"
|
||||||
|
|
||||||
copyIdeResources = true //Calls processResources when in dev
|
copyIdeResources = true //Calls processResources when in dev
|
||||||
|
|
||||||
@@ -33,17 +25,16 @@ minecraft {
|
|||||||
// Automatically enable forge AccessTransformers if the file exists
|
// Automatically enable forge AccessTransformers if the file exists
|
||||||
// This location is hardcoded in Forge and can not be changed.
|
// This location is hardcoded in Forge and can not be changed.
|
||||||
// https://github.com/MinecraftForge/MinecraftForge/blob/be1698bb1554f9c8fa2f58e32b9ab70bc4385e60/fmlloader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/ModFile.java#L123
|
// https://github.com/MinecraftForge/MinecraftForge/blob/be1698bb1554f9c8fa2f58e32b9ab70bc4385e60/fmlloader/src/main/java/net/minecraftforge/fml/loading/moddiscovery/ModFile.java#L123
|
||||||
def at = project(":common").file('src/main/resources/META-INF/accesstransformer.cfg')
|
def at = project(':common').file('src/main/resources/META-INF/accesstransformer.cfg')
|
||||||
if (at.exists()) {
|
if (at.exists()) {
|
||||||
accessTransformer = at
|
accessTransformer = at
|
||||||
}
|
}
|
||||||
|
|
||||||
runs {
|
runs {
|
||||||
client {
|
client {
|
||||||
workingDirectory rootProject.file('run/client')
|
workingDirectory file('../run/client')
|
||||||
ideaModule "${rootProject.name}.${project.name}.main"
|
ideaModule "${rootProject.name}.${project.name}.main"
|
||||||
taskName 'Client'
|
taskName 'Client'
|
||||||
property 'eventbus.api.strictRuntimeChecks', 'true'
|
|
||||||
mods {
|
mods {
|
||||||
modClientRun {
|
modClientRun {
|
||||||
source sourceSets.main
|
source sourceSets.main
|
||||||
@@ -52,10 +43,9 @@ minecraft {
|
|||||||
}
|
}
|
||||||
|
|
||||||
server {
|
server {
|
||||||
workingDirectory rootProject.file('run/server')
|
workingDirectory file('../run/server')
|
||||||
ideaModule "${rootProject.name}.${project.name}.main"
|
ideaModule "${rootProject.name}.${project.name}.main"
|
||||||
taskName 'Server'
|
taskName 'Server'
|
||||||
property 'eventbus.api.strictRuntimeChecks', 'true'
|
|
||||||
mods {
|
mods {
|
||||||
modServerRun {
|
modServerRun {
|
||||||
source sourceSets.main
|
source sourceSets.main
|
||||||
@@ -68,14 +58,8 @@ minecraft {
|
|||||||
dependencies {
|
dependencies {
|
||||||
minecraft "net.minecraftforge:forge:${forge_minecraft_version}-${forge_version}"
|
minecraft "net.minecraftforge:forge:${forge_minecraft_version}-${forge_version}"
|
||||||
|
|
||||||
annotationProcessor('net.minecraftforge:eventbus-validator:7.0-beta.7')
|
|
||||||
|
|
||||||
annotationProcessor('org.spongepowered:mixin:0.8.5-SNAPSHOT:processor')
|
annotationProcessor('org.spongepowered:mixin:0.8.5-SNAPSHOT:processor')
|
||||||
implementation('net.sf.jopt-simple:jopt-simple:5.0.4') { version { strictly '5.0.4' } }
|
implementation('net.sf.jopt-simple:jopt-simple:5.0.4') { version { strictly '5.0.4' } }
|
||||||
|
|
||||||
minecraftLibrary(jarJar(group: 'org.mineskin', name: 'java-client', version: mineskin_client_version)) {
|
|
||||||
jarJar.ranged(it, "[${mineskin_client_version},)")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// for some reason mixin plugin does not add 'MixinConfigs' to MANIFEST.MF so we do it manually
|
// for some reason mixin plugin does not add 'MixinConfigs' to MANIFEST.MF so we do it manually
|
||||||
@@ -92,7 +76,3 @@ sourceSets.each {
|
|||||||
it.output.resourcesDir = dir
|
it.output.resourcesDir = dir
|
||||||
it.java.destinationDirectory = dir
|
it.java.destinationDirectory = dir
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.named('processResources') {
|
|
||||||
duplicatesStrategy = DuplicatesStrategy.INCLUDE
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
# Forge, see https://files.minecraftforge.net/net/minecraftforge/forge/ for new versions
|
|
||||||
forge_version=59.0.0
|
|
||||||
forge_loader_version_range=[59,)
|
|
||||||
# Forge sometimes skips minor minecraft versions (like 1.20.5)
|
|
||||||
forge_minecraft_version=1.21.9
|
|
||||||
@@ -1,36 +1,31 @@
|
|||||||
package net.lionarius.skinrestorer.forge;
|
package net.lionarius.skinrestorer.forge;
|
||||||
|
|
||||||
import net.lionarius.skinrestorer.SkinRestorer;
|
import net.lionarius.skinrestorer.SkinRestorer;
|
||||||
import net.lionarius.skinrestorer.compat.skinshuffle.SkinShuffleCompatibility;
|
import net.lionarius.skinrestorer.command.SkinCommand;
|
||||||
|
import net.minecraftforge.common.MinecraftForge;
|
||||||
import net.minecraftforge.event.RegisterCommandsEvent;
|
import net.minecraftforge.event.RegisterCommandsEvent;
|
||||||
import net.minecraftforge.event.server.ServerStartedEvent;
|
import net.minecraftforge.event.server.ServerStartedEvent;
|
||||||
import net.minecraftforge.event.server.ServerStoppedEvent;
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||||
import net.minecraftforge.eventbus.api.listener.SubscribeEvent;
|
|
||||||
import net.minecraftforge.fml.common.Mod;
|
import net.minecraftforge.fml.common.Mod;
|
||||||
|
import net.minecraftforge.fml.loading.FMLPaths;
|
||||||
|
|
||||||
@Mod(SkinRestorer.MOD_ID)
|
@Mod(SkinRestorer.MOD_ID)
|
||||||
@Mod.EventBusSubscriber(modid = SkinRestorer.MOD_ID)
|
@Mod.EventBusSubscriber(modid = SkinRestorer.MOD_ID)
|
||||||
public final class SkinRestorerForge {
|
public final class SkinRestorerForge {
|
||||||
|
|
||||||
public SkinRestorerForge() {
|
public SkinRestorerForge() {
|
||||||
SkinRestorer.onInitialize();
|
MinecraftForge.EVENT_BUS.register(SkinRestorerForge.class);
|
||||||
|
|
||||||
if (SkinShuffleCompatibility.shouldApply())
|
SkinRestorer.onInitialize(FMLPaths.CONFIGDIR.get());
|
||||||
net.lionarius.skinrestorer.forge.compat.skinshuffle.SkinShuffleCompatibility.initialize();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public static void onCommandRegister(RegisterCommandsEvent event) {
|
public static void onCommandRegister(RegisterCommandsEvent event) {
|
||||||
SkinRestorer.Events.onCommandRegister(event.getDispatcher());
|
SkinCommand.register(event.getDispatcher());
|
||||||
}
|
}
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public static void onServerStarted(ServerStartedEvent event) {
|
public static void onServerStarted(ServerStartedEvent event) {
|
||||||
SkinRestorer.Events.onServerStarted(event.getServer());
|
SkinRestorer.onServerStarted(event.getServer());
|
||||||
}
|
|
||||||
|
|
||||||
@SubscribeEvent
|
|
||||||
public static void onServerStopped(ServerStoppedEvent event) {
|
|
||||||
SkinRestorer.Events.onServerStopped(event.getServer());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user